Choice 1 = scissors, compare on line 38, everything above that has been "passed"


#1


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

Oops, try again. There was a problem with your syntax.


correct code

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==="paper"){
        return "scissors wins";
    }
    }
    else {
        return"rock wins";
    }
};    
     console.log(compare(userChoice,computerChoice));


#2

On your last else if syntax. The position of your closing curly braces on this part

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

remove the other curly brace { on this line:

then add another closing curly brace here:

so your last else if will go like this:

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

#3

Thank you.

How do I handle the compare?
I have:
}
{
console.log(compare(userChoice,computerChoice));
}

Get syntax error. Where is my error??


#4

On this part:

Wrong position of closing curly brace. you should write it like this:

};    
     console.log(compare(userChoice,computerChoice));

For your better understanding how important curly braces are.


#5

Thank you for explaining the correct placement of the curly brackets to open and close.