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


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,

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




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:



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.


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