Build rock paper scissors 7/13


#1

/*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 (choice_1, choice_2) {
if (choice_1 === choice_2) {
return "The result is a tie!";
} else if (choice_1 === "rock") {
    if (choice_2 === "scissors") {
        return "rock wins";
    }
} else {
    return "paper wins";
} else if(choice_1 === "paper") {
if(choice_2 ==="rock") {
return "paper wins";
}
else {
return "scissors wins";
}
}
};

this is my code but its displaying unexpected token 'else;

please somebody help


#2

sorry 7/9
please somebody help! please:slight_smile:


#3

@naman05,
You are closing the ELSE-IF as you used 1 closing-curly-bracket-} to many...

if (choice_1 === choice_2) {
    return "The result is a tie!";
} 
else if (choice_1 === "rock") {
    if (choice_2 === "scissors") {
       return "rock wins";
    }
}

Please read
http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b
and concentrate on:

  • the creation of the compare function
  • the truth-table
  • the build of the IF ELSE-IF statement structure as part of the compare FUNCTION-BODY
  • the execution of the compare function (keeping in mind that the return statement is used )

#4

this bit off code:

else if (choice_1 === "rock") {
    if (choice_2 === "scissors") {
        return "rock wins";
    }
} else {
    return "paper wins";

the else should be inside the else if, and don't forget to close your else if before starting the next else if choice1 is paper


#5

here the choice 1 is paper


#6

if you say so, but if the code before choice1 is paper is incorrect, choice1 is paper is never going to work...


#7

ya
please send your code


#8

but the code before choice1 paper wasn't wrong


#9

i am out, i don't give full answers.

Okay, well the code i am looking at (your code, before choice1 is paper) it is wrong, so i suggest you fix it like leo and i suggest