What is wrong with my syntax?


#1

var sleepCheck = function(numHours) {
return numHours >= 8;

}

if ( numHours >= 8) {
return "You're getting plenty of sleep!";
}
else ( numHours <= 8) {
return "Get some more shut eye!";
}
sleepCheck(10);


#2

Since else is a default clause, it does not take a conditional expression, or any parameter. It is a fallback code block, only.

else {
    return "Get some more shut eye!";
}
var sleepCheck = function(numHours) {
   return numHours >= 8;

}

The above function body is closed and has only one conditional that returns true or false, and not the string expressions expected by the lesson checker.


#3

ok i took out (numHours <= 8) however i got SyntaxError: return statements are only valid inside functions. I thought the top part of my code was correct...


#4

The fix will be to insert the if statement in the function, and remove the statement that is there at present.

var sleepCheck =  function (numHours) {
    if (numHours >= 8) {
        return ...
    } else {
        return ...
    }
};

Now the return is inside the function body.


#5

I thought I was in the clear but no...
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);


I received this msg:
Oops, try again. It looks like sleepCheck() isn't returning "You're getting plenty of sleep! Maybe even too much!" when numHours is 10. Check your if / else syntax and whether you're using the correct comparison operator.


#6

Add that last exclamation point to match the expected text.


#7

gosh im a n00b thanks haha


#8

Welcome to the club where we all make mistakes, and typos are frequent among them.