6. What is choice 1 is rock?


#1


The link


Oops, try again. There was a problem with your syntax.
SyntaxError: Unexpected token else

/*var userChoice = prompt("Do you choose rock, paper or scissors?");
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";
    }
   
    }


#2

You're missing two closing }s. One for your tie case and one for the function.


#3

tie case? and the function?


#4

if(choice1 === choice2) {
        return "The result is a tie!";
    else if(choice1 === "rock") {

the if is not closed by the } so the else comes unexpected.

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

As you can see the else if and else have their matching {}s but the compare function lacks a closing } at the very end. I highly recommend that you format your code in an appropriate way so that it is obvious what curly braces are matching.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.