Illegal Return Statement


#1

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

It looks right, but it says "Illegal return statement". What can I do to fix this?

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

#2

return only makes sense inside a function.

Back to instruction.

If computerChoice is between 0 and 0.33, make computerChoice equal to "rock".
If computerChoice is between 0.34 and 0.66, make computerChoice equal to "paper".
If computerChoice is between 0.67 and 1, make computerChoice equal to "scissors"

What it tells you do is to assign "rock"/"paper" / "scissors" to computerChoice depending on the conditions.

Like one of the lines says this...

If computerChoice is between 0 and 0.33, make computerChoice equal to "rock".

It means to do this..

if (computerChoice < 0.34) {
    computerChoice = "rock";
}

You have to do same thing for other cases!!
I hope it helps!


#3

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