Building rock , paper scissors game , can anyone please help


#1

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

// i keep getting a syntax error saying undefined token else. tried many ways, can anyone please pass me the correct code.


#2

here:

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

you should have an else if to check for choice1:

else if (choice1){

}

then inside the else if nest a if and `else:

else if (choice1){
  if (choice2){
  
  }
  else {

  }
}

#3

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