Need help stuck on step 7


#1

here is my code, not sure what im doing wrong need help!! !keep getting the unexpected token error.

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 {
        (choice2 === "scissors") {
        return "scissors win";
        }
    }
    }
}
}

#2

Watch your {} it seems like your nesting your second else if inside of the first one and so on. Also this:

else {
            (choice2 === "scissors") {

seems to lack an if or is not necessary when you use else.


#3

can you elaborate a little im still stumped


#4

else if (choice1 === "rock") { // opening else if 
    
    if (choice2 === "scissors") { //opening if
        return "rock wins";
    }  // closing if
    else { //opening else
        return "paper wins";
    } // closing else
    // still inside of the the ELSE IF (caps to not trigger keywords :) )
    else if (choice1 === "paper")

and the other this is that in your second else if:

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

you have this else:

else {
    (choice2 === "scissors") {

which doesn't make this much sense. Else is the default case so it doesn't need a condition, so if you want one use else if instead. Also thiss way you have 2 opening { for the else which probably gives you an array for an unmatched or badly matched {} as well.


#5

did the adjustments using the code pasted below and still getting error :anguished:

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


#6
if(condition){
    code
}
else if(condition2){
    code2
}
... // as many else ifs as you like
else{
    code
}

#7

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";
}
}
};
compare("paper","scissors")