2
I am creating a game "Stone, Paper and scissors", I am at the final moment, but my code is with an error that I cannot identify.
var userChoice = prompt("Voce escolhe pedra, papel ou tesoura?");
var computerChoice = Math.random(1);
if (computerChoice < 0.34) {
computerChoice = "pedra";
} else if(computerChoice <= 0.67) {
computerChoice = "papel";
} else {
computerChoice = "tesoura";
} console.log("Computer: " + computerChoice);
var compare = function (choice1, choice2){
if(choice1 === choice2) {
return "O resultado e um empate";
}
else if(choice1 === "pedra") {
if(choice2 === "tesoura") {
return "pedra vence";
}
else {
return "papel vence";
}
}
else if(choice1 === "papel") {
if(choice2 === "pedra")
return "papel vence";
}
else {
return "tesoura vence";
};
else if(choice1 === "tesoura") {
if(choice2 === "pedra")
return "papel vence";
};
};
What is the mistake? What you expected to happen, and what actually happens?
– user25930
Obg by the attention, then I have to create a game "stone, paper and scissors", then by prompt I will ask the user (player) which he chooses, from cryo a Macht.Andom giving me a random value from 0 to 1, dai define a value example 0.34 = stone, Finally comes the part where the dispute takes place, where the player defines who wins or loses, used the if Else with another if Else inside, but at the time of executing the following error: "Syntaxerror: Unexpected token Else"
– Allan Santos
I recommend making more descriptive titles friend and only use the snippets if adding an example for execution.
– Guilherme Nascimento
@Guilhermenascimento Thanks for the recommendations, I’m new here, so I’m still learning.
– Allan Santos