12. Functions & If / else | Undefined Error


#1


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!";
    }
};
sleepChecK(10);
sleepCheck(5);
sleepCheck(8);.


#2

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.


#3

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!";
}
};
console.log(sleepCheck(10));
console.log(sleepCheck(5));
console.log(sleepCheck(8));
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.


#4

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

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


#5

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


#6

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