I made a random number guessing game in which you can determine the maximum value and the minimum value. I checked my entire code twice but can't seem to find a solution to why it won't work. I made this script linked to a HTML file that explains the document.getElementById("randNum").innerHTML part. I also want to say I am very new to coding so I might've overlooked something simple. Anyways, here's my code.
var max = prompt("Max guessing number?");
if (max <= 2) {
document.getElementById("randNum").innerHTML = "Invalid entry";
} else {
var min = prompt("Wat is het kleinste nummer dat je kan raden?");
if (min >= (max - 1) || min <= 0) {
document.getElementById("randNum").innerHTML = "Invalid entry";
} else {
number = Math.floor((Math.random() * max) + min);
guess = prompt("What's your guess?");
if (guess > max || guess < min) {
document.getElementById("randNum").innerHTML = "Invalid entry";
} else if (guess == number) {
document.getElementById("randNum").innerHTML = "Good job! You guessed the number!";
} else {
document.getElementById("randNum").innerHTML = "Wrong! The answer was " + number + "!";
}
}
}
Aucun commentaire:
Enregistrer un commentaire