So lost in computer choice 2

var userChoice = prompt("Do you choose rock, paper or scissors?")
var computerChoice = Math.random()
if (computerChoice < 0.33) {
    return rock
} else if (computerChoice < 0.66) {
    return paper
} else {
    return scissors

SyntaxError: Illegal return statement

huh huh huh :disappointed_relieved:


You need semicolons after every expression.

This means not after conditionals if or brackets {.

Add semicolons and try again.

Beyond that, you can't return rock,paper, orscissors, because thoseObjects don't exist **and** because you're not in afunction. You can'treturn in a normal conditional.

Console.log(), rather than return, them as strings "rock", "paper", "scissors".


The if statement in not inside a function body so we cannot use return. Instead, assign a new value to computerChoice

computerChoice = "rock";

Remember to quote string primitives else they look like variable names (identifiers).


Solved it myself... 10 minutes ago


I need help with this too, I don't know how to tell the system to only accept numbers between 34 and 66, so that way the pc can choose scissors -_- plz help


^ Just leave the scissors conditional blank, like so:

if (computerChoice < 0.33) {
computerChoice = "rock";
else if (computerChoice < 0.66) {
computerChoice = "paper";
else {
computerChoice = "scissors";


Um, I haven't been looking at this particular course yet, but wouldn't those branch options mean that something could be both rock and paper at the same time?
Although I guess that it could be a true/false condition situation so if the first condition is meet then the language won't even look what the second condition is even if that would also have a "true" outcome, no?

(I'll probably get around to the JavaScript part later, looking at stuff like Python right now.)


now it it telling me that else is an unexpected token.....


You are right. I copied the code from the OP. The second condition should be:

else if (computerChoice > 0.66) {
computerChoice = "paper";


If it's more then 66 it should presumably be scissors with paper being the fall-back option I guess.
But thanks, glad to see I wasn't just imagining things. =)


This can't be right since any number over 0.66 could result in being scissors while numbers less than 0.66, including those less than 0.33, could also be called "paper." I AM TOTALLY LOST ON THIS EXERCISE AND REALLY JUST NEED TO SEE THE CORRECT CODE TO SEE WHAT I AM DOING WRONG!! HAVE BEEN STUCK FOR THE PAST 30 MINUTES!!