7. What is choice1 is paper- help


#1

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

It says syntax error what is wrong please help


#2

I believe that in an "else if" statement, you cannot use the comma here:

else if (choice1 === "rock", choice2 === "scissors"){

You don't need the choice2 === "scissors" partbecause of the if statement you put right here:

if (choice2 === "scissors") {


#3

same thing it says syntax error


#4

There is a semicolon missing, I added it below (after "rock wins"):

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


#5

@lesteri16

else if (choice1 === "rock", choice2 === "scissors")

Take a look at that and then look at what you do here:

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

I am sure things will become clearer. I think you just made an error copying and pasting.


#6

Thank you that's gonna help me


#7

Hey still the same thing


#8

Post your new code, let's have a look


#9

Oh the problem was this } that I added it by mistake thank u it worked