Illegal return statement


SyntaxError: Illegal return statement

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


if (computerChoice <=.33) {
    return "rock";
} else if (computerChoice <=.66) {
    return "paper";
} else (computerChoice <= 1) {
    return "scissors";


The return statement ends function execution and specifies a value to be returned to the function caller.

You have no function or function caller. Either create a function to put your if statements in, or assign the strings "rock", "paper", and "scissors" to an existing or new variable.

In the respective code blocks, change the value of computerChoice based on the rules stated above.

Since the instructions ask to assign it to computerChoice, do so:

computerChoice = "rock";


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