This is my code:
<!DOCTYPE html>
<html>
<head>
<title>Random Number Generator</title>
</head>
<body>
<h1>
Random Number Generator
</h1>
<p>
Minimum:
<input type="number" id="min" />
</p>
<p>
Maximum:
<input type="number" id="max" />
</p>
<button onclick="go()">
Go
</button>
<p id="ran"></p>
<script>var min, max;
function go() {
min = document.getElementById("min").value;
max = document.getElementById("max").value;
document.getElementById("ran").innerHTML = Math.floor(
Math.random() * (max - min + 1) + min
);
}
</script>
</body>
</html>
It is a random number generator. My problem is that the result is less than the minimum. I'm positive that the problem is with the input because one time I replaced max and min with numbers and it came up with a number between them.
Aucun commentaire:
Enregistrer un commentaire