Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Generate a Random Integer</title> </head> <body> <script> document.write(Math.random() + "<br>"); // Expected output: a number between 0 and 1 // Function to create random integer function getRandomInt(max) { return Math.floor(Math.random() * max); } document.write(getRandomInt(3) + "<br>"); // Expected output: 0, 1 or 2 document.write(getRandomInt(1)); // Expected output: 0 </script> <p><strong>Note:</strong> Refresh the output by clicking the "Show Output" button to see how random numbers are generated.</p> </body> </html>