Question 7 choice1 = paper, and choice2 = rock


#1

This is the code I used for the question I have reviewed the hint and did everything even reviewed from the very beginning of the course, and changed around the brackets. The computer says SyntaxError: expected expression, got keyword 'else'. I looked in the glossary syntax usually means the order isn't right. Please help!

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

#2

Try this. Hope it helps...

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

};


#3

You forgot to post the rest of it (the start of the compare function). But one problem at least seems to be the direct closing of the else if:

else if(choice1 === "paper") {
} // no need to close it here
    if(choice2 === "rock") {
        return "paper wins";
    }
    else {
        return "scissors wins";
    }
  } // it will be closed here!
};

#5

Same problem for me. I don't understand why the syntax error unexpected else appears

/*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(userChoice, computerChoice) 
{
    if (userChoice === computerChoice)
    {
    return "The result is a tie!";
    }
    else if (userChoice === "rock") 
        {
        if (computerChoice === "scissors")
        return "rock wins";
        }
        else {
            return "paper wins";
        } 
    else if (userChoice === "paper") 
        {
        if (computerChoice === "rock")
        return "paper wins";
        }
        
        else {
            return "scissors wins";
        } 
    }

#6

HI on your second and third if statement you didn't open the {

here
you didn't closded the else if statement

   else if (userChoice === "rock") 
        {
        if (computerChoice === "scissors") { //open the if statement
        return "rock wins";
        }
        else {
            return "paper wins";
        }
} <== add one here for closing the else if statement

then here
you should add one } for closing the compare function

 else if (userChoice === "paper") 
        {
        if (computerChoice === "rock") { #here too add the open {
        return "paper wins";
        }
        
        else {
            return "scissors wins";
        } 
    }
} <== #add one } for closing the compare function

#7

Wooohoo... you are a genius :wink: thx


#8

sorry this is question 6

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

please what is wrong?


#9

Hi next time it's better if you create a new topic with your code..

Then

you just need to add a } at the end for closing the compare function


#12