It says this is correct but is it?


#1

Hi,

I have completed part 8 of the Build "Rock, Paper, Scissors" lesson, and it says it worked (code below). Here is the exercise just to be clear:
https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/1/4?curriculum_id=506324b3a7dffd00020bf661#

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 "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";
        }
    }
    
    else if (userChoice === "scissors") {
        if (computerChoice === "rock") {
            return "rock wins";
        } else {
            return "scissors wins";
        }
    }
};

compare(userChoice,computerChoice);

However I am not sure I have done it absolutely right. I was expecting to see the "rock wins" etc text displayed in the console.log. Can someone put my mind at ease?

Best regards,

Oliver


#2

it should display this?

To be absolute sure, do the following:

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

this will log what the function returns to the console


#3

Thanks stetim94.

I think I tried this but it failed. However I may have missed a bit of the syntax.

Best regards,

Oliver


#4

so i put your code in a bin, only added a console.log to the function call, and everything is fine


#5

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