Build "Rock, Paper, Scissors 7


#1



SyntaxError: expected expression, got keyword 'else'


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"
    }
}


#2

to determine a winner, you are going to build 3 else ifs to check for choice1, so for example:

else if(choice1 === "rock") {


}

inside the else if you nest an if and a else to determine choice2:

else if(choice1 === "rock") {
   if(condition){
       // return winner
   } else {
       // return winner
   }  
}
// next else if here for other user choice

take a good look at how i places all the curly brackets, there are a few missing in your case

if you need more help, post an updated version of your code


#3

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