Anyone know what is wrong with my code? Please tell me!


#1

Anyone know what is wrong with my code? Please tell me!

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 {
            returns "scissors wins";
        }


}

What if choice 1 is Paper? - Unexpected Else token?
#2

Hi this part you closed the else if statement statement before you should close it after the else statement

else if(choice1 === "rock") {
    if(choice2 === "scissors") {
        return "rock wins";
    }
} <== remove this one 
    else { 
        return "paper wins";
    } 
} <== add one here

Then here you forgot to close the compare function

else if(choice1 === "paper") {
    if(choice2 === "rock") {
        return "paper wins";
    }
    else {
        returns "scissors wins";
    }
}
}<== add one here

#3

Thanks! Many have tried to help me solve this issue but have not explained it properly. So thank you for explaining this in such detail. I am so grateful!


#4

You guys should help me. I'm supposed to be a video game designer when I go to college after next year. But I suck at coding.:disappointed:


#5

Is that something that you want to do or are you being pushed into it?

"I suck at coding" is a bit vague at this point. Do you mean JavaScript or are there other languages that you've tried.

At this point we are just taking baby steps, learning the ABCs. If you don't understand it then ask a specific question and someone will explain how it works.

Also, learning a language isn't magic, you have to spend time at it. If today you don't understand comparison operators or if/else statements, practice using them at a place like https://repl.it/languages/javascript -- make them do what you want them to do -- and ASK QUESTIONS.


#6

Thank you. I will get back to you on this.