Correct Code. No Results Displaying


#1

My code is working correctly and I complete the exercise but nothing logs in the console to display the results. A winner is not displayed or the winning choices aren't shown. Any help figuring out how to display the results is greatly appreciated. Thanks!

var userChoice = prompt("Do you choose rock, paper or scissors?");
console.log("User Choice:" + " " + userChoice);
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";
        }
    }
    
     else if (choice1 === "scissors"){
        if(choice2 === "paper") {
            return "scissors wins";
        }
        else {
            return "rock wins";
        }
    }
    
    compare(userChoice,computerChoice);
    console.log(compare);
    
    
    
    }

#2

The call to the function should not be inside the function body. Move down to below the closing brace of the function.

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

#3

awesome. Thanks. This worked!


#4

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