Functions & if/ else


#1


https://www.codecademy.com/en/courses/javascript-beginner-en-6LzGd/2/4?curriculum_id=506324b3a7dffd00020bf661

Oops, try again. There was a problem with your syntax.
SyntaxError: Illegal return statement


Replace this line with your code. 
var sleepCheck = function (numHours){
}
if (numHours > 8); {
    return ("You're getting plenty of sleep! Maybe even too much!");
};
else
{
    (numHours < 8);
    return ("Get some more shut eye!");
}
sleepCheck(10);
sleepCheck(5);
sleepCheck(8):


12. Functions & if / else
#2

@abrashm

There are 3 corrections to be made, try and see if you can find it.

First, check your { } curly brackets

var sleepCheck = function (numHours) {

   //runs the code (the if/else statements are inside here)

}

Second and third, your if/else statements should follow this syntax:

if (condition1) {
    return "some string";
}
else {
    return "another string";
}

See if you have added something else (extra) and take notice of the symbol " " and the ; semicolon, where you should place it, otherwise the code will not run.

:slight_smile:

If you want more reading, you can refer here as well:


#3

var sleepCheck = function (numHours){
if (numHours > 8)
return "You're getting plenty of sleep! Maybe even too much!";
}
else {
return "Get some more shut eye!";
}

sleepCheck(10);
sleepCheck(5);
sleepCheck(8);

I have tried to follow your instructions, everything seems to be fine but the else statement the system says expected an identifier and instead saw "else". Missing ; before statement


#4

You didn't try properly, you still miss out on the { } curly brackets. Try go through the codes one by one @abrashm

You need to have three pairs { } curly brackets in your code, but now you only have two pairs { }, thus throwing error.

At least you got your semicolon placement correct this time.

Hint:
1. Check if you have closed your function or not
2. Check the if/else syntax, what symbol comes after the if (condition)

:slight_smile:


#5

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