Part 6 - Too Many Brackets!


#1

JavaScript > Unit 2: Functions > Lesson: Build "Rock, Paper, Scissors" > Compare Function > 6. What if choice1 is rock?


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

Error message just says there's a problem with the syntax. I looked over all the opening/closing brackets and things like that but I can't find a solution...


#2

@dat_dog_star,
Do not use a semi-colon-; in you IF ELSE-IF statement structure.....
A semi-colon-; is an End-of-Statement indicator in Javascript.....

Please read
http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b
and concentrate on:

  • the creation of the compare function
  • the truth-table
  • the build of the IF ELSE-IF statement structure as part of the compare FUNCTION-BODY
  • the execution of the compare function (keeping in mind that the return statement is used )

http://stackoverflow.com/questions/17036135/why-is-it-that-semicolons-are-not-used-after-if-else-statements
http://stackoverflow.com/questions/25101936/why-does-adding-a-semicolon-sometimes-break-an-if-statement


#3

Thanks for the advice and many references! Very detailed and helpful :slight_smile:
I'll try the exercise again...