Why is my code not working? When I enter a number correctly, it doesn't show me the window.alert that it was right.
Here is the problem: Write a program that chooses a random number between 1 and 10. Give the user 5 guesses (use a loop) to guess the number. If they are wrong, tell them so. If they are right, tell them so and exit the loop. At the end of the program, show them the actual number.
<script>
var num = Math.floor(Math.random()*10 + 1);
var guess = parseInt(window.prompt("Enter a number!"));
for (var x=1; x<=5; x++) {
if (num == guess) {
window.alert("You are right!");
break;
}
else {
window.prompt("You were wrong, try again!");
continue;
}
}
document.write("The number was "+num);
</script>