7/9 Oops, try again. Your code returned 'paper wins' instead of 'scissors wins' when the inputs are paper and scissors


#1

Been away from this for a few weeks and after coming back to it i cant work out why this wont work.

any help much appretiated.

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


#2

your line of:

if (choice1 === "paper") {

should be:

else if (choice1 === "paper") {

#3

Hi, thanks for that. I have made the change and am now getting:

SyntaxError: Unexpected token else

below is the updated code.

/*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

You seem to have a comment /* at the top of your code.
`

Should be an else if.

As with,

Lastly,

Is very jumbled.


#5

@cadecodes Actualy only the choice1 statements should be "else if's" @crooky3005 you are now missing a { at the end of:

and a } at the end of the else if:


#6

@vinceknight thanks, managed to get it resolved now. It was just missing curly brackets!!


#7

no problem glad I could be of service