Functions & If/else error message unexpected token


#1

Hi! I'm working on the part 12 (functions and if/else) of the intro to functions in JS lesson and I can't get it to work no matter what I try. My code looks like this:

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

Whenever I hit save and submit, it gives me the following error message: SyntaxError: Unexpected token else

I have no idea what's going on here. If anyone can help me, I'd appreciate it.


#2

Else statements never take a condition. Remove it and try your code again. Also, make sure you have curly braces exactly where you want them to be.


#3

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