Help me avoid syntax error: unexpected token else. PLEASE!


#1

Hi there, for most complex challenges, I keep on getting a:
syntax error: unexpected token else
First of all, please tell me why this happens so I can avoid it in the future. Use this as an example:

var sleepCheck = function(numHours) {
if(numHours>8)
console.log("You're getting plenty of sleep! Maybe even too much")

};
else {
console.log("Get some more shut eye!");
};
sleepCheck(10);
sleepCheck(5);
SleepCheck(8);

Why does this always return a syntax error? Please help me!


#2

its your { and } brackets, they are not properly formatted, keep track of what your functions need to wrap in a bracket.

also your if(numHours>8) statement needs to have a bracket too
if(test condition){ block of code } else { block of code }
this should be wrapped up by

var sleepCheck = function( input ) { block of code };

hope that helps

mind your capitalization, sleepCheck isn't the same as SleepCheck


#3

Thanks for that! I'll make sure to apply this in the future!