Unexpected token else


#1

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

SyntaxError: unexpected token else


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){
//This is an if statement to declare a tie.
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 "paper wins"
    }
};


#2

Please post a link to the exercise you're on, paste all of the code you have written so far and any error messages that came up when you tried to submit your code.


#3

ok let me edit it i will try to do that i am new to this so ?


#4

ok I am now done with requirements you needed to help me thx


#5

Check your else if statements and if statements for proper syntax. The instructions give you a good idea for what your code should look like for each else if statement.

Example:

else if (choice1 code){ //start of else if statement
if (choice2 code){
return "code wins";
} else {
return "code2 wins";
}
} // end of else if statement

Once you're done with the else if statements, make sure to close the compare function.


#6

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