-1
The exercise is as follows:
Create a jokenpo game.
Each round the player sees the menu "Choose your move: 1-Paper, 2-Stone, 3-Scissors". The game reads the player’s option and checks if it is valid. If invalid, the player loses the round and the game ends. If valid, the computer chooses a random response, which is shown to the player.
If the player wins, he can play one more round and his score increases. The game ends when the player loses a round. The total score is shown at the end of the game.
Follows my code:
<html>
<head>
</head>
<body>
<script>
var opcao=parseInt(prompt("Qual e a opcao 1 - Papel 2 - Pedra 3 - Tesoura"));
var resposta=Math.floor((Math.random() * 3) + 1);
var opcaoe+="";
var verificador=true;
while(verificador==true){
if(resposta==1){
opcaoe+="a resposta e papel";
}
else if(resposta==2){
opcaoe+="a resposta e pedra";
}
else if(resposta==3){
opcaoe+="a resposta e tesoura";
}
if(opcao===resposta){
alert("a resposta e invalida"+opcaoe+".");
return verificador=false;
}else if(opcao==1 && resposta==2){
alert("a resposta e valida"+opcaoe+".");
return verificador=true;
}else if(opcao==2 && resposta==1){
alert("a resposta e invalida"+opcaoe+".");
return verificador=false;
}else if(opcao==3 && resposta==1){
alert("a resposta e valida"+opcaoe+".");
return verificador=true;
}else if(opcao==3 && resposta==2){
alert("a resposta e invalida"+opcaoe+".");
return verificador=false;
}else if(opcao==2 && resposta==3){
alert("a resposta e valida"+opcaoe+".");
return verificador=true;
}}else if(opcao==1 && resposta==3){
alert("a resposta e invalida"+opcaoe+".");
return verificador=false;
}
}
</script>
</body>
</html>
Doubt: Code does not work.
And what is your doubt?
– Leo Nogueira
The doubt is that the exercise does not speak
– Diogo
OK Diogo, pass more details, what error you are presenting, or what was the expected result and did not happen, etc.... https://answall.com/help/how-to-ask
– Leo Nogueira
I don’t see anything on the page and I think the problem is in the prompt because I don’t see the prompt box but I already tried to replace parseint by Parsefloat and still don’t give
– Diogo
What appears in the browser console?
– Lucas Henrique
Check the opening and closing of the if and while structures, and in the returns remove the "checker=" https://jsfiddle.net/y4mauehp/
– Leo Nogueira