#8 tie result not working


#1


Replace this line with your code.


#2

Could you please copy and paste your code?


#3

Here is my code:
var userChoice = prompt("Do you choose rock, paper or scissors?");
console.log("User chooses: " + userChoice);
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
}
else if(computerChoice <= 0.67) {
computerChoice = "paper";
}
else {
computerChoice = "scissors";
}
console.log("Computer chooses: " + 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 === "paper") {
return "scissors win";
}
else {
return "rock wins";
}
}
};

compare(userChoice);
compare(computerChoice);

  1. **The results for the tie is not working, it gives a return value of rock, paper or scissors, instead of "This is a tie".
  2. And also sometimes when the userChoice picks a parameter and the computerChoice picks another parameter, instead of giving a winner from the two selections, it says the third choice is the winner instead of one of the two selections made.
    Can anyone help with this** Much appreciated in advance

#4

Are you getting any reference errors?


#5

I think when you call your compare function you have to give it both parameters. I'm not sure if you can give the parameters one at a time.


#6

There are not any reference errors, it passes. But if you run the code a few times, the output is always the third parameter.


#7

That was it, thank you.


#8

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