Build "Rock, Paper, Scissors" lessons 8/9 and 9/9 - taking out {} fixes the problem?


#1

From 8/9 my last else if code will only pass if I take out all of the {} from it. Why is this?

Passing code:

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";
        }
    }
    else if (choice1 === "scissors") 
        if (choice2 === "rock") 
            return "rock wins";
        
        else (choice2 === "paper") 
            return "scissors wins";
}

Not passing code:

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

Consequently, this makes it difficult to try out the tasks in 9/9.

So I deleted the last else if statement to try out code for wrong inputs into the game. This code worked perfectly fine with a bracketed else statement returning to the user that the input was not rock, paper, or scissors. But I have no idea how to get the code to reprompt the game without the cyclical problem of reentering the functions. At least I think?

This javascript lesson has been very challenging to me, so any input as to why my problems exist or how to solve them would be greatly appreciated!


#2

It is not working in the second one maybe because with else you don't give it a check, for that you else if, or just remove the check.