Rock,paper scissors, what if choice1 was paper?


#1



https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/3?curriculum_id=506324b3a7dffd00020bf661#


It says Syntax Error, not sure what is wrong


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


#2

Hi in the first else if statement it's missing the if statement

else if (condition) { // open the else if statement
    if (condition) { //open the if statement
    
    } // close the if statement
    else { //open the else statement

    } // close the else statement
} //close the else if statement

#3

Can you just please copy and paste the whole program with the necessary correction. I'm unable to locate the mistake.


#4

This part its missing the if statement

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

should be

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

#5

Still says syntax error : unexpected token else. Here is the updated code.

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

};


#6

here you have more } than you need

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

} <== remove this one

#7

Solved. There was an extra bracket. Thank you @wizmarco