Lesson 12, JS - Help or i'll implode


#1

What's wrong with my code?

Getting this error: SyntaxError: Unexpected EOF


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(9);


#2

here:

return "You're getting plenty of sleep! Maybe even too much!;

missing " to mark the end of the string

You close your function to early, else should also be part of your function content.


#3

arhh... what a relief. Thanks mate


#4

all problems resolved now?


#5

Yes problem solved!

But I really don't understand why there only has to be a ; after the second last }

Why not after the other } ????

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(9);


#6

never add semi-colons to the closing curly brackets of if, else if and else

You can add them to the closing curly bracket of a function:

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

that is fine


#7

Okay understood. The tutorial actually gave me a " lesson complete" even though i added it to the second last bracket, therefore my confusion.


#8

The exercise validates if your code runs correctly, even with a misplaced semi-colon it will work (sometimes), never trust the exercise to tell you where semi-colons are wrong/correctly placed


#10

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