Rock, Paper, scissors


#1

I have managed to sucessfully do the following:

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";
    }
}
}

However, when i go to do the next bit:

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

it comes up witht he error "SyntaxError: expected expression, got keyword 'else'.

why is this happening?


#2

What lesson number is this?


#3

Its for : 7. what if choice 1 is paper?


#4
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";
        }
    } // remove
} // remove
  1. You have too many ending curly braces.

  2. if(choice2 === "rock"; is wrong. Do you see the issue?

  3. Add one closing curly brace at the end of all your code.


#5

@sampattinson could you post the full code that gives you the error?

@jaaakee First of all sorry for messing up your code, normally it looks better with 3 backticks instead of one but in this case it made it worse. Anyway 2. is correct but 1. should be ok, one for the else if and one for the function.


#6

This is what i have now however, it says that there is an unexpected token?? 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(choice2 === "scissors") {
        return "rock wins";
    }
    else {
        return "paper wins";
    }
else if(choice1 === "paper") {
    if(choice2 === "rock") {
        return "paper wins";
    }
    else {
        return "scissors wins";
    }
}

#7

your missing a } before the second else if.


#8

Hi I think you missing also another one for closing the compare function after your second else if statement