I am working on an assignment and I am having difficulty writing up the function to get a random number between two variables.
Basically what I want is the script to prompt you for the first number followed by the second then give me a random number in between those two.
How do I get a random whole number in between two user inputted variables? What I am doing wrong? Here's my code:
var age = prompt("How old are you?");
var videogames = prompt("How many hours of video games have you played last month?");
function getRndInteger(age, videogames) {
return Math.floor(Math.random() * (videogames - age)) + age;
}
document.write(getRndInteger(age, videogames));
Aucun commentaire:
Enregistrer un commentaire