Rock,Paper,Scissors No Output


#1

Each time it runs successfully but there is no output other than "Computer: "rock"" [or whatever choice is the computer]. Why is it not running my compare function? When both players choose the same the compare function works fine

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


#2

Hi in all your statemnt I saw that you put only one = instead of ===


#3

yeah i realized that after posting, i corrected that but still get the same output :frowning: . its driving me insane, cant figure out why it works but wont work right....


#4

This is the updated code by the way...still same output

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


#5


#6

try to put that at the end console.log(compare(userChoice,computerChoice));


#7

thank you for the advice, i have tried this too and still get the same output. I appreciate all the help but at this point i think im just gonna accept that it accepted and that i wont know why and continue on.


#8

look at the Stuck? Get a hint link for section 6 "What if choice1 is rock?" you are using if when you should be using else if. try to make you code look like the example here. This helped me get mine to work.