What is wrong with my code?


#1

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


#2

you should nest your if and else inside your else if


#3

Can you post the coding for it??Thanks....


#4

You should post all of your code to this point. There may be other errors.


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


#6

In the hint for this lesson, you are supplied with a format for your else if statements that have if/else statements inside them.

Ex:

else if (choice1 code){
if (choice2 code){
return "something wins";
} else {
return "other wins";
}
}

You should have 2 else if statements that follow this format in your compare function. Hope this helps :slight_smile:


#7

Thanks for you help bro!!


#8

Thank @stetim94 also, his advice was the same.


#9