What If Choice 1 is paper? (Need help! Syntax is killing me)


#1


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


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


#2

It looks like you have an extra } just before your second else if.


#3

I tried that with no luck.

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


#4

Posting all of your code may reveal the true source of the error message.


#5

Okay, here goes.......

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


#6

You should move that semicolon to the end of your code to include all the else if statements in your compare function.


#7

Are you referring to moving the semi-colon that comes after "the result is a tie!"?


#8

The one after that one.


#9

I'm getting lost here. You want me to put a semi-colon on the last curly brace in the statement?


#10

I found the problem. I had an extra curly brace go figure. Thank you everyone


#11

So sorry! I meant curly brace, not semicolon :confounded:

I meant for that 2nd curly brace to be moved to the end of all of your code.


#12

No problem. It helped me greatly in understanding how to look at my code and come up with a solution.


#13

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.