I have started studying Javascript one month ago and I have a doubt. I'm programming a simple game that thinks of a random number and you have to guess it before you run out of attempts. To determine if the player guessed right or wrong the number, I have done the following (reduced code):
start(){
num=documentGetElementById("num").value;
attempts=10;
}
try(){
attempts=attempts-1;
if(num==random)documentGetElementById("message").innerHTML="You have won.";
if(attempts==0)documentGetElementById("message").innerHTML="You have lost.";
}
What happens here is that when you guess the number in the last attempt (1 attempt left) it says you have lost. So my question is: how to give priority to the if(num==random)...?
Aucun commentaire:
Enregistrer un commentaire