How can I console.log the final result


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

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";



Hi this line


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


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



just that line


should be like that

console.log(compare(userChoice, computerChoice))


By replacing the code I get this printed:

"I chose paper
Computer scissors

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

"I chose paper
Computer scissors
rock wins"

Can you help?


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?


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

Thanks for the help!


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