I'm stuck on : What if choice1 is scissors?


#1

Hi, i've been stuck on this excercise for a while now and would like some help....

This is a link to the excercise:
https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/4?curriculum_id=506324b3a7dffd00020bf661#

These are the error messages i'm getting:
SyntaxError: Unexpected token else

This is 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") {
    
    if (choice2 === "scissors") {
        return "rock wins";
    }
    else {
        return "paper wins";
    }
}   
};
else if (choice1 === "scissors") {
    
    if (choice2 === "paper") {
        return "scissors wins"
    }
    else {
        return "rock wins"
    }
};

#2

What is the function of the semicolon in your code, in the line just above
else if (choice1 === scissors). I feel this is giving you the error


#3

i just fixed it sorry bruh


#4

It's fine. I'm glad that you managed to resolve your problem though. Keep posting to the forums in times of doubt.

Regards,
Barry Allen


#5

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