Both Choices are the Same


#1

I tried using this code but it did not work how do i fix it?

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!";
}
};
if(choice1 === "rock") {

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


#2

var compare = function(choice1,choice2) {

if (choice1 === choice2) {

return "The result is a tie!";
}
}; //don't close the function here

you have to close the function at the end.

and here

if(choice1 === "rock") {

it should be

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


#3

thank you for helping out. :smile:


#4

var compare = function(choice1, choice2) {
if(choice1 === choice2) {
return "The result is tie";
}
};

what is wrong with my code? The answer is:
Oops, try again. Your compare function does not return 'The result is a tie!' when there is a tie.

:frowning:


#5

You forgot to put exclamation mark at the end of the sentence: "The result is tie!"


#6

Also an "a". 'The result is a tie!'


#7

Thanks for your help :slight_smile:


#8

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