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


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) {
console.log("You're getting plenty of sleep! Maybe even too much")

else {
console.log("Get some more shut eye!");

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


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


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