12 - Can't find the mistake?


#1

var sleepCheck = function (numHours) {
if (numHours >= 8)
return ("Your're getting plenty of sleep! Maybe even too much!");
};
else {
return ("Get some more shut eye!");
};
console.log (sleepCheck(10));
console.log (sleepCheck(5));
console.log (sleepCheck(8));

the system returns that else is an unexpected token?


#2

your function missing its closing curly bracket (}), also closing curly brackets for if and else don't need semi-colons


#3

Hi,

Hope you have figured out that your closing curly braces "}" don't need a semicolon ";".. although It's been a long time but here's the code below for reference without any semicolons :slight_smile:
NOTE: only single statement within its block doesn't require ending semicolons as long they are separated by a new line character.

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!"

}
}

console.log(sleepCheck(5))
console.log("hi there");


#4