7. What if choice1 is paper?


#1

it says syntax error unexpected keyword 'else' but I am not sure what I am doing wrong.


7/9 Rock Paper Scissors
#2

You have a closing curly bracket with a semicolon just before your 2nd else if statement. This effectively closes your compare function.


#3

I'm also ahving the same issues

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


#4

@cloudmaster82066 and @mackenzie.leonard

you should not have the else statement before the else if statement

(You have the else statement two times!)

(also (this is not a problem) you could make you code neater if you clicked the button (which looks like this: </> ) then it would look nicer so instead of this:
/*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"
}
else if(choice1 === "paper"){
if (choice2 === "rock"){
return "paper wins"
}
}else{
return "scissors wins"
}
};

this:

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

)

Hope this helps,

Steven


What if choice1 is scissors?
#5

Did you figure it out?

need to remove }; on line 23


#6

if statement under else if (choice1 === "rock") is missing an open curly brace and a close curly braces after return "rock wins";

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


#7

The correct syntax for an else if with a nested if would look something like this:

else if (condition) {
if (condition){
code code code
} else {
code code code
}
}

Use this as a template to debug your code. You're close to a solution.


#8

Should of seen that!:rage:


#9

wow that was a lot of responses. Actually, the exercise inserted the code and commented it out from the previous exercise.
The way the exercise #7 asks for the else and else if, is has us continually add to our existing code, so that is probably where I got confused. As follows:

Inside the compare() function under the existing code, write another else if statement where the condition is choice1 === "paper".
Inside this else if statement, write an if / else statement. If choice2 === "rock", return "paper wins". Else, return "scissors wins".


#10

Actually, from the previous exercises, functions are supposed to end with };. I was just following directions on that, and the code that came from exercise 6 didn't error out from it either.


#13

And you're right, end it with a semicolon. For exercise 7, you extended your code and so the ; had to be moved, because the computer is thinking your function ends at line 23 but you want it to keep going.


#14

Don't sweat it too much... had to look at mine multiple times before catching it...:sweat_smile:


#15

But on the other hand I spent like 15 min on it :cry: