Functions & if/ else


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!");
    (numHours < 8);
    return ("Get some more shut eye!");

12. Functions & if / else


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.


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


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!";


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


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.

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



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