What if choice1 is paper?


#1

This i my code from beginning to now I can't seem to find any errors. Please help!

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

}
}
};


#2

@typer55 Have you figured this out?! I am stuck as well


#3

I believe you've got an extra closing bracket " } " before your second else if statement.

else {
 return "paper wins";
}
}
}; //<---- Get rid of this line and you'll be good to go!

#4

It gives me this:

SyntaxError: Unexpected keyword 'else'


#5

Could you post your new code, sir?


#6

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


#7

I think this is what I had when I moved on. I've been off the site for a while and forgot.


#8

this is my code ive been stuck for quite a while help pls.
it gives me this error message

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

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") {
console.log('its a tie');
}
else if (choice2 === "rock") {
if (choice2 === "rock")
console.log('paper wins');
}
else {
console.log('scissors wins');
}
}


#9

I am stuck on this as well, here is my code:
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";
}
}


#10

Hi first you should put open and close {} to your first if statemnt this one

if ('choice1 === choice2')
return "The result is a tie!"

should be like that

if (condition) {//open the if statement 

}//close the if statemnt

and you should remove the' ' around the choice1 === choice2 inside the if condition
then you should add a } at the end for closing the compare function


#11

Woohoo, it worked, thanks for your help!