<p>Random number between 0 and 1.</p>
<button onclick="myFunction()">Try It</button>
<p id="randomnumber"></p>
<script>
function myFunction() {
document.getElementById("randomnumber").innerHTML = Math.random();
}
</script>
<p>Random integer between 1 and 10 (both included).</p>
<button onclick="document.getElementById('demo').innerHTML = getRndInteger(1,10)">Try It</button>
<p id="demo"></p>
<script>
function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
</script>
<!-- reference: w3schools -->
button {
padding: 6px 8px;
color: gray;
font-family: "arial";
text-align: center;
margin: auto;
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.