Build "Rock, Paper, Scissors" game What if choice1 = rock


#1

Hi
there is a link to the coding exercise
https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/2?curriculum_id=506324b3a7dffd00020bf661#

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

What have I done to make it return the error message "SyntaxError: Unexpected end of input"


#2

you are missing two closing curly bracket at the end, one to close the else if statement, and one to close your function


#3

Hi.

I am more than stuck....

/*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!";
}};

this is my code

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

SyntaxError: Unexpected keyword 'else'

can't make this run....help!


#4

#5

please read the guidelines, go here, create a new topic, fill in the template, and someone will help you.

Thank you :slight_smile: