Build Rock, Paper, Scissors Part 1


SyntaxError: Unexpected identifier

Replace this line with your code. 

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


Why is your console.log inside { }? Try taking them out. :slight_smile:


Ok did that and still I get syntax error???



consider these logic

Doesn't look right.

Hint: In the first quoted code, doing

if(computerChoice <= 0.33)

makes more sense.

Also, you've got Illegal return statements.

Hint: You may want to do,

computerChoice = "rock";

for instance


The first issue is both of your if conditions should be inside of parentheses:

if (condition) {
code executing if condition is met goes here;

The second issue is you are not following the instructions for the conditions. In the first if condition, the computerChoice should be compared to values between 0 and 0.33. Since Math.random() returns a random number between 0 and 1, you can look for values below 0.34 or

computerChoice < 0.34.

Your second if condition should check for values over 0.33 and less than 0.66.

There is no need to use modulo in your conditions. Running 0%0.33 in javascript returns 0.33. You are basically checking for only that value instead of the range between 0 and 0.33.


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