๐Ÿ”’ Closed Javascript Random Number

Status
Not open for further replies.

SUNRAI

Eternal Poster
Anyone paano ko kaya ililimit yung random number na nampipili then i change sya into a whole number


<!DOCTYPE html> <html> <body style="text-align : center;"> <h>Pick Random Number</h> <br> <button onclick="myFunction()">Click Me</button> <h1 id="demo"></h> <script> function myFunction() { document.getElementById("demo").innerHTML = Math.random(); } </script> </body> </html>
 
Math.floor(Math.random() * (number na ililimit mo))

ex. Math.floor(Math.random() * 100).

so 0 to 100 ang result.

math.floor lang ginamit ko pero pwede ka pa gumamit ng ibang method. like math.round. math.ceil.
 
sir mali bato?


Code:
<!DOCTYPE html>
<html>
<body style="text-align : center;">

   <h>Pick Random Number</h>
   <br>
   <button onclick="showNum()">Click Me</button>

   <h1 id="num"></h>

<script>
   function showNum() {
  
   Math.floor(Math.random() * 20);
  
   document.getElementById("num").innerHTML =   Math.random();
   }
</script>

</body>
</html>
 
Status
Not open for further replies.

About this Thread

  • 6
    Replies
  • 305
    Views
  • 3
    Participants
Last reply from:
xinfernox

Online now

Members online
974
Guests online
1,174
Total visitors
2,148

Forum statistics

Threads
2,276,177
Posts
28,968,075
Members
1,231,155
Latest member
4rchiv3s
Back
Top