4.7/9 Incorrect console.log output


#1

https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/4?curriculum_id=506324b3a7dffd00020bf661#


I am getting a completed exercise, but my console.logs are not what I want them to say. I just get the computer's choice. I know that I added some redundancies on the bottom. I was just trying to figure out if there was a combination that worked better.

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(userChoice, computerChoice) {
if (userChoice === ComputerChoice)            
{
    return console.log("The result is a tie!"); } 
else if (userChoice === "rock")
    { 
        if (ComputerChoice === "paper") {
            return console.log("paper wins!");
    }   else {
            return console.log("rock wins!");} 
    }   
};

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

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

#2

Perhaps you should only include the part that you're asking about. Make it clear what you're asking about.
What output did you get? What did you expect instead? Show exactly what happened so that it's abundantly clear what you want it to do differently.

Do you mean that it should also display the user's choice? If so, you would need code for that, is there any such code?

--

I'm sure you don't need me to state the obvious!


#3

When I run the code it gives me "Computer: rock" in the log. and that is it. Even when I had a reduced version of the current code, it was giving me that same issue. It's like it's ignoring my entire second set of function.


#4

What else should happen? Did you write code that does that?
You're saying you've written a function? And you want it to run? Then you'd write code to invoke the function.


#5

It should log something like "paper wins, rock wins, its a tie etc. As described in the second part of the function. It is not, so I'm unsure why.


#6

Would you expect this to print something?

function hello() {
    console.log("Hello world!");
}

All that does is to create a function. It will not print anything. Creating a function does not have the side-effect of executing it.


#7

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