Why console.log in function compare don't print result, ex: rock wins or paper wins?


#1

Why console.log in function compare don't print result, ex: rock wins or paper wins?
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);
function compare(userChoice, computerChoice){
if(userChoice === computerChoice){
console.log("The result is a tie!");}
else if(userChoice === "rock"){
if(computerChoice === "scissors"){
console.log("rock wins");
} else{
console.log("paper wins");
}
}
}


#2

because functions only execute when calling them? Call the function:

 else{
                    console.log("paper wins");
                    }
            }
    }
compare(userChoice, computerChoice);

you can also use return instead, then just log the function call to the console


#3

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