Part 6 - Too Many Brackets!


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...


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
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 )


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