What if choice1 is scissors?


#1


I believe I have a { missing or in the wrong space if someone could let me know where it is it will be much appreciated.


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 if(choice1 === "scissors")
    {
        if ( choice2 === "rock"){
            return "rock wins";}
        else (choice2 === "paper"){
            return "scissors wins";}
    }
     };


#2

Can't have a conditional statement like else (random condition) {Do something}. Should be else {Do something}.
In your last else statement, remove the (choice2 === "paper").

else (choice2 === "paper"){ 
            return "scissors wins";}
    }
     };

#3

It still returns as a SyntaxError: Unexpected token {


#4

hmm...strange, getting rid of that (choice2 === "paper") after else seems to work for me. Perhaps you added a bracket somewhere else.
What does your code look like now?


#5

Do not know if this will help but this is the basic formatting for my code for the last two parts. Depending on your style it might not work but it might help you to identify what you might have extra or reformat your code if need be

else if( ) {
if( ) {
return  ;
}}
else if( ) {
    if( ) {
    return  ;
}
}
}

#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.