What if choice1 === "scissors"?


#1


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


it's giving me "SyntaxError: Unexpected end of input" and I have no idea where I messed up at.


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


#2

All your else if blocks need an extra curl brackets after closing the if block. }


#3

Thanks! However, now it's telling me that I have an "Syntax Error: Unexpected token else". Did I add an unneeded else somewhere in my code or did I not introduce it improperly?


#4

Some of your if, else and else if statements are in correctly coded
Remember the syntax:

else if (condition) {
  if (condition) {
    // do something 
  } 
  else {
    // do something else
  }
}

#5

I'm stuck too: this is my code:
https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/4?curriculum_id=506324b3a7dffd00020bf661#


#7

I've solved the problem already. Thank you for the help everyone!


#8

I keep getting syntax error


#9

I need help :pensive:


#10

May I see your code please?


#11

yh theres a link above that shows my code


#12

The link will send me to the problem, alongside the answer I provided. I will not see your code, but instead mine.


#13

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


#14

well first off,
else {
return "paper wins";
}
that should be an else if function


#15

actually just delete that part of the code entirely because it isn't needed


#16

ok, now what should I do


#17

This isn't my best area when it comes to JavaScript, so forgive me if this sounds improper. But you should only make statements for each possible win only once. Meaning only one statement for paper win, rock win, or scissor win. It would probably be easier if you reset your code and try again because you'll be looking for the error for a long time. At least that's what I did. Once again this isn't my expertise and you should probably find help elsewhere if you still don't understand.


#18

ok thanks for your help anyways :grinning:


#19