I'm a beginner in Javascript so I am currently attempting to code a random "machine" that takes a two parameters, tha minimal value and the maximal value, which the user types in an input="number", and displays a random number between those values, but the problem is that the random number doesn't display on the screen when I hit the button "Generate"
<form>
<div id="minimal_num">
<label for="min">Minimal Value</label>
<input type="number" name="min" required>
</div>
<p id="rnum"></p>
<div id="maximal_num">
<label for="max">Maximal Value</label>
<input type="number" name="max" required>
</div>
<br style="clear: both;">
<button id="generator" onclick="random_number()">Generate</button>
</form>
</div>
<script type="text/javascript">
function random_number() {
document.getElementById("rnum").innerHTML = Math.floor(Math.random() * min) + max;
}
</script>
Aucun commentaire:
Enregistrer un commentaire