Choice1 is scissors SyntaxError: Unexpected identifier


#1


What if choice1 is scissors
i am getting SyntaxError: Unexpected identifier and i cannot figure out why... please help


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


#2

Spelling mistake here,

You typed in choise2 instead of choice2

Here as well,


#3

Thank you very much, i've just changed it, but its still coming up SyntaxError: Unexpected identifier


#4

You need one more closing bracket after the last one here,

And one more here,


#5

It's still not working, and i've checked others peoples completed versions to mine, and they look identical, should i just start again?


#6

Starting again is a bit of a leap. Could you please show me your updated code so I can see what else is still amiss. :slight_smile:


#7

...
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 === "rock") {
return "rock wins";}
}
else {
return "scissors wins";}
}
}

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

...

    Thank you, sorry for being a pain

#8

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