What if choice1 is paper? Help


#1
> `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";
>         };
>         };
> }`

SyntaxError: Unexpected token else

What am I doing wrong here?


#2

First of all have a look at this on how to format your code:


the > is just meant for short inputs and pseudo quotes I guess and you only need one per section:

This is just a test ...
still a test
and going on testing

is done by:

> This is just a test ... 
still a test
and going on testing

But to the topic:
My first guess would be the use of semicolons in conditions:


#3

Alright, changing semicolons does nothing.

Same errors.


#4

Could you post the updated code? I meant at least 7 semicolons.


#5

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

SyntaxError: Unexpected token {

Wouldnt surprise me if its an semicolon issues, the Javascript tutorial is ■■■■ at explaining the importance or semicolons or lack there of.


#6

No the semicolons should be fine for now (maybe add one after the last } that closes your function). The problem seems to be this line:

if (choice2 === "rock"{

where a closing ) is missing.

And on semicolons see my post and maybe this blog article:
https://www.codecademy.com/blog/1707


#7

Ah, of course. Maybe I'm just blind...

Thanks for your help