9/9: Not returning the result of the game


#1

Hey!

So the code is "correct", but my console log is just saying "Computer: scissors (or rock or paper)", not "scissors wins", etc.

Here is my code...

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 (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"
 }
}
}

#2

Well you say that it should do so right above your compare function and you do not call your compare function so from what I can see everything is just like it should be, shouldn't it?


#3

well yes, but insted of returning "Rock wins" or "the result is a tie" it simply tells me what the computer choice was


#4

Again:

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); <-- This line is the reason you
                                                  see your computerChoice
                                                  printed on the screen

and the reason you don't see the result of your compare function is because you do not call this function.