12. Functions & If / else | Undefined Error


12. Functions & If / else

I believe I have defined my function correctly, yet I keep getting this sleepCheck undefined error.

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


Heya, your code is actually perfectly fine, you just have a typo in your first declaration. The K in sleepCheck is capitalized when it shouldn't be, so just change that to a lowercase and your code should run just fine.


well the thing is i tried the same code but it doesnt work look:
var sleepCheck = function(numHours) {
if ( numHours >= 8) {
return "You're getting plenty of sleep! Maybe even too much!";
else {
return "Get some more shut eyes!";
and then the thing it prints out:
Oops, try again. It looks like your function doesn't return "Get some more shut eye!" when numHours is 5. Check your if / else syntax and whether you're using the correct comparison operator.


I believe you are missing a semicolon after your else statement.

else {
return "Get some more shut eyes!";
}; <-- Right There


:joy:oohw wel ■■■■ i dindt saw that there:sweat_smile: thnx man


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.