Hi, i need help with my js scissors,rock and paper game


#1

Hi, im new at javascript and have fallen into some problems i cant solve.

I have problems with the stone , Scissors and Paper game. Its not printin out the conditions like "paper wins" or "The results are tie!" its just printing the computers choice. Im not sure why, even i have tested to read over and over the instructions to see what im missing here. Can some one help me out here and point me to right direction?

Best regards,
Matias

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

compare(userChoice,computerChoice);

`


#2

this line:

else if (choice2 === "scissors")

why use choice2? I would use choice1. Then choice scissors, you should be good. If not, return means something gets returned, not logged to the console, use console.log on the function call:

console.log(compare(userChoice,computerChoice));

#3

Thank you :), now it gives The result is a tie! at tie, thats good. but gives undefined at the rest two conditions, so something is wrong at if else conditions. I will try fix this. Thanks again.


#4

i put your code here, i don't see a problem? Yes, you still have to code choice1 for paper and rock, but what you coded so far is good