Exercise 8: "What if choice1 is scissors?" Stuck on this particular exercise


#1

JavaScript Project: "Build Rock, Paper, Scissors" // EXERCISE 8: What if choice1 is scissors?

Hello, I'm kind of stuck since I have no idea of what I'm doing wrong, since it obviously worked the previous times.
I probably overlooked some curled brace or some semicolon, but I can't seem to find a wrong one.

Can anyone help me?

P.S. I didn't include the function call just yet, as this is clearly a fault in the code.

Error message: SyntaxError: Unexpected token else

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

#2

Your syntax is incorrect. else works like this:

else {
//something
}

#3

Tried that, but it didn't work. Still gave me a SyntaxError

This is what I have done:

else {
return "scissors wins";
}

instead of this:

`
{
else return "scissors wins"
}


#4

I didn't look at all the code earlier besides that error you have more.

These two semi colons after the conditions need to go !


Make sure you are closing else if after the else, should look like this the syntax:

else if(something === "something") {
        
    if(something === "something") {
        return "something";
    }
    else {
        return "something";
    }
 } //close elseif

If you still getting an error paste in your updated code


#5

Yes! I already saw the two semicolons behind the conditions, so I removed them.

The extra curled braces closing the whole "else if" statement seemed to do the trick.

Thanks for the help!


#6

Welcome :green_heart:


#7