Choice 1 is paper SyntaxError


#1


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


SyntaxError: missing before statement


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


Replace this line with your code.

I believe my else if for "paper is in the incorrect spot" but not sure. I don't know what to make of the error message as it doesn't reference anything. Thanks.


#2

You don't need two closing brackets after the return statement.


#3

Thanks. I tried removing one of them and still have the error though.

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

I cut and pasted the else if for (choice 1 === paper) which worked and just changed the values so confused why I was fine using } in the rock wins scenario.


#4

You made the same error here. The 2nd curly brace after "rock wins" closes your else if.


#5

here is the right 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";
}
}

hope thats help you :slight_smile:


#6

Thanks. I figured it out but will update the board.


#7

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