What if choice1 is scissors? please help!


#1

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

Hi,
I keep getting an error message that reads "SyntaxError: Unexpected token {". Can someone please look at my code and let me know what's wrong?

Thank you!!!

M


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

console.log(computerChoice + userChoice);


#2

Error on this line space between choice and 2. :grin:


#3

Here as well you're supposed to pass them as arguments,

(userChoice, computerChoice)

#4

Thank you!!

I fixed those two issues and I'm still getting "SyntaxError: Unexpected token {"

Also in the end I typed "console.log(compare(userChoice, computerChoice));" because I found that somewhere else in the forum. Is that correct?


#5

You made the same spacebar mistake here as well.

And on this line after correcting the spacebar error you need to look at it again because you else statement syntax is wrong concerning the way you are trying to execute this statement,

I would suggest just writing,

else {
            return "scissors wins";
        }

Your code will still work. :slight_smile:


#6

That solved the problem. Thank you so much!!! :smiley:


#7

You're welcome. :grin:


#8

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