Help! I can't finish the game


#1



It keeps giving me "SyntaxError: Unexpected token {"



var userChoice = prompt("Do you choose rock, paper or scissors?");

var computerChoice = Math.random();
if (computerChoice < 0.34) {
	computerChoice = "rock";
} else if(computerChoice <= 0.67) {
	computerChoice = "paper";
} else {
	computerChoice = "scissors";
} console.log("Computer: " + computerChoice);

var compare = function(choice1, choice2) {
    if (choice1 === choice2) {
        return ("The result is a tie!");
    }
    else if (choice1 === "rock") {
        if (choice2 === "scissors") {
            return ("rock wins");
            }
        else {return ("paper wins");
        }
    }
    else if (choice1 === "paper") {
        if (choice2 === "rock") {return ("paper wins");
        }
        else {return ("scissors wins");
        }
    }
    else (choice1 === "scissors") {
        if (choice 2 === "rock") {return ("rock wins");
        }
        else {return ("scissors wins");
        }
    }
}
console.log (compare (userChoice, computerChoice));


#2

More verbose error message, produced by running your code with nodejs

$ node betapro87119.js 
/tmp/js/betapro87119.js:33
    else (choice1 === "scissors") {
                                  ^
SyntaxError: Unexpected token {

#3

taking out that bracket didn't help. any other ideas?


#4

That was your idea, not mine or node's. I just dropped off a better error message.

It points at where there is no longer any valid interpretation of your code. It's saying nothing about what exactly you want to change, only you can determine that.

Ask yourself what you mean to happen there, and what that is supposed to look like.


#5

This is mine.
It's passed. Hope it helps.

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);

var compare = function(choice1, choice2){
if(choice1 === choice2){
return "The result is a tie!";
}
else if(choice1 === "rock"){
if(choice2 === "scissors"){
return "rock wins";
}
else{
return "paper wins";
}
}
else if(choice1 === "paper"){
if(choice2 === "rock"){
return "paper wins";
}
else{
return "scissors wins";
}
}
else(choice1 = "scissors");
{
if(choice2 === "rock"){
return "rock wins";
}
else{
return "scissors wins";
}
}
};
console.log (compare (userChoice, computerChoice));


#8