8u

random number JavaScript HTML

8u
Dec 29th, 2021
168
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.47 KB | None | 1 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4. ​
  5. <h2>JavaScript Math.random()</h2>
  6. ​
  7. <p>Every time you click the button, getRndInteger(min, max) returns a random number between 0
  8. and 9 (both included):</p>
  9. ​
  10. <button onclick="document.getElementById('demo').innerHTML = getRndInteger(0,10)">Click Me</button>
  11. ​
  12. <p id="demo"></p>
  13. ​
  14. <script>
  15. function getRndInteger(min, max) {
  16.   return Math.floor(Math.random() * (max - min)) + min;
  17. }
  18. </script>
  19. ​
  20. </body>
  21. </html>
  22.  
  23. by 8u
Advertisement
Add Comment
Please, Sign In to add comment