What if choice1 is scissors?


#1


Still getting syntax error messages, guessing it's something with my curly brace count, but I just need someone else's eyes to look at this and tell me what's wrong.

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


#2

else 
    return "scissors wins"; }
}
// missing } to close else if choice1 is paper
 else if(choice1 === "scissors") {

see comment in code above


#3

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

Is this what you meant? I'm still getting the syntax error message.


#4

can you undo what i just suggested? I saw it wrong. My apologizes.

the problem is actually here:

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

if misses the {} to mark start and end of the if clause

i am still missing something, give me a second

i found it, same bit of code, else is missing the { to mark the start of the else clause

if you need more help, post an updated version of your code


#5

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

Here is my updated code, now it tells me that there is an "Expected '}'", after undoing your first comment


#6

so close now:

 }
  // missing } to close the function
 compare(userChoice,computerChoice);

then you should be good :slight_smile:


#7

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