How can I console.log the final result


#1


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

I would like to view the string with the final resulta when making a console.log at the end, but int's not printing the string.
Instead I get this:

"I chose paper
Computer chose paper
[Function]"


var userChoice = prompt("Do you choose rock, paper or scissors?");

console.log("I chose" + " " + userChoice)


var computerChoice = Math.random();
    if (computerChoice < 0.34) {
        computerChoice = "rock";
    } else if(computerChoice <= 0.67) {
        computerChoice = "paper";
    } else {
        computerChoice = "scissors";
    } 
    
    
console.log("Computer chose" + " " + 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 if (choice1 === "scissors"){
        if (choice2 === "paper") {
            return"scissors wins";
        }
    }
}

console.log(compare)


#2

Hi this line

console.log(compare)

your function compare have two argument so when you call it you should put as argument userChoice and computerChoice


#3

Can you show me the correct code so I can see the return string to be printed?

thanks!


#4

just that line

console.log(compare)

should be like that

console.log(compare(userChoice, computerChoice))

#5

By replacing the code I get this printed:

"I chose paper
Computer scissors
undefined"

What I would like to see printed was something like this:

"I chose paper
Computer scissors
rock wins"

Can you help?


#6

when I run your code with this line

console.log(compare(userChoice, computerChoice))

at the end I get

I chose rock
Computer chose paper
paper wins

if you add it and didn't get it right can you post your update code?


#7

You're right! The code is functioning correctly! I guess I have inserted a missed spelled word like "sissor".

Thanks for the help!


#8

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