Please can some help with a 'SytaxError: Unexpected Token Else'


#1

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 ){
if(choice1 === choice2) {
    return "The result is a tie";
};
}
else if(choice1 === "rock") {

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

}

#2

You seem to be missing a { here. If you count. you have two { but only one }.


#3

*/ this could be the issue


#4

} console.log("Computer: " + computerChoice);*/


#5

Code academy puts the /* in to make that first bit of coding a comment.
hence
/*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);*/
is a comment.


#6

o have the same problem in the same moment. I cant see any bad in my 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"){
else if (choice2 === "scissors"){
return "rock wins";
}else {
return "paper wins";
}else if (choice1 === "paper"){

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

}
};

Do you see any mistakes here?


#7

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