<html>
<head>
<title>generate random integer in javascript</title>
</head>
<body>
<p>Click the button to test:</p>
<button onclick="myFunction()">Generate random integer</button>
</br>
<textarea style="width: 400px;height: 200px;"id="demo"></textarea>
<script>
function myFunction() {
document.getElementById("demo").innerHTML =generateRandomInt(1,10);
}
//generate a random number between min(include) and max(include)
function generateRandomInt(min,max) {
return Math.floor((Math.random() * max) + min);
}
</script>
</body>
</html>
Comments
Post a Comment