Calling Codecademy squadrons across the interwebz, please help!


#1


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


Hey Codecademy squad, can y'all please help me out with this code? I'm getting a "SyntaxError: Illegal return statement" message.

Been doing pretty well until now, just can't seem to figure out what's wrong with this code for the Rock, Paper, Scissors game.


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

var computerChoice = Math.random();

console.log(computerChoice);

if (comptuerChoice < 0.33) {
    return "rock";  
} else if (computerChoice <= 0.34 && computerChoice <= 0.66) {
    return "paper";
} else {
    return "scissors";
}


#2

I think for this question you need to assign your strings rock/paper/scissors to computer choice after your if and else if statements.

You also need to put your if and else if statements inside computer choice's curly brackets.

Your finished code should look like this.

var userChoice = "Do you choose rock, paper or scissors?"

prompt(userChoice)

var computerChoice = Math.random(3){
    console.log(computerChoice){
}
if (computerChoice <= 0.33) {
    computerChoice = "rock";
} else if (computerChoice <= 0.66) {
    computerChoice = "paper";
} else {
    computerChoice = "scissors";
}
}

Study this code and look at the differences. If that helped please mark my reply as the solution.


#3

This is your code. Lets find out what mistakes you really made!!

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

var computerChoice = Math.random();

console.log(computerChoice);

if (comptuerChoice < 0.33) {
    return "rock";  
} else if (computerChoice <= 0.34 && computerChoice <= 0.66) {
    return "paper";
} else {
    return "scissors";
}

first line

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

  1. Asked user a question by prompting a promptBox like below.

    .. Alright its work fine.

next...

var computerChoice = Math.random();

console.log(computerChoice);

1.created a variable computerChoice that creates random numbers between 0 - 1.
and printed it using console.log().

next...

if (comptuerChoice < 0.33) {
    return "rock";

1.Created an if statement and if condition satisfies it will return "rock" ?

Wait what?

return keyword inside if statements???

return only goes inside the function..
If there is no function you can't use return keyword

one more thing..

You spelt computerChoice as comptuerChoice !

solution --
Read the instruction..

It says you to do something like this..
.
computerChoice = "rock";

next...

You did same mistakes in next lines of code,
You should not use return keyword but assign corresponding values to computerChoice.


#4

You absolute LEGEND. Thanks very much. I was kinda tired and just saw that typo. Thank you!!! I have now seen the error of my ways. Danke.


#5

Ahh brilliant thanks very much for the help, it worked. I don't think I read the question properly but this has really helped. Cheers


#6

Keep up the good work! :thumbsup:


#7

cheers man! i'm trying


#8

that's the spirit :slight_smile:


#9

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