13. Conclusion console.log help


#1

https://www.codecademy.com/en/courses/javascript-beginner-en-6LzGd/2/5?curriculum_id=506324b3a7dffd00020bf661

I can't get it to print the final results from the return function. I expected to be able to see the message return in the console.log or as a dialog box but see nothing. Whenever I try to add a console.log to return the compare results since they are not showing on their own it either breaks something in the code or causes other issues.


var userChoice = prompt("Do you choose rock, paper or scissors?");
console.log("User: " + userChoice);
var computerChoice = Math.random();
if(computerChoice < 0.34) {
computerChoice = "rock";
}
else if(computerChoice <= 0.67) {
    comuterChoice = "paper";
} else { 
    computerChoice = "scissors";
} 
console.log("Computer: " + computerChoice);

var compare = function (userChoice, computerChoice){
    if(userChoice===computerChoice){
        return "The result is a tie!";
}
else if(userChoice==="rock") {
    if(computerChoice==="scissors"){
        return "rock wins";
        } else {
            return "paper wins";}
}
else if(userChoice==="paper") {
    if (computerChoice==="rock") {
        return "paper wins";
} else 
    return "scissors wins";
}
};


#2

At this stage in the exercise we are not expected to output any results. However, if you wish to see the results, the log out the compare function return value.

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

#3

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