Exercise 12 introduction to functions in JS, unexpected token else


#1

// Write your function below.
// Don't forget to call your function!
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);

It shows SyntaxError : unexpected token else


#2

your else is missing its curly opening bracket ({), and else can't have a condition, given the fact that it is everything else


#3

the closing curly brackets of if and else don't require semi-colons:

if (numHours >= 8) {
    return"You're getting plenty of sleep! Maybe even too; much!";
}; <- unnecessary semi-colon

the string returned should be an exact match, which it is not in your case

and a space between the return keyword and the string would also be a good idea


#4

Did that and now it shows "It looks like sleepCheck() isn't returning "You're getting plenty of sleep! Maybe even too much!" when numHours is 10. Check your if / else syntax and whether you're using the correct comparison operator."

Thanks though


#5

already covered that one:


#6

Got it now, removed the semi colon. Didn't read your 2nd reply earlier, sorry about that.
Anyway thanks for the help. It worked