Intro to function in JS & if/else


#1

Need some fresh eyes to review this code and find the error, thanks!


https://www.codecademy.com/en/courses/javascript-beginner-en-6LzGd/2/4?curriculum_id=506324b3a7dffd00020bf661#


SyntaxError: Unexpected token else


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


#2

No starting curly brace.


#3

Actually, it ended up being curly brackets, but 'elsewhere' - :wink: . This is the code that worked:
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(8);

Basically, I removed the curly brackets from around the else


#4

I use curly brace/brackets interchangeably, sorry for confusion! :slight_smile: