12. Functions & if / else


#1

My code:

var sleepCheck = function(numHours) {
if (numHours < 8) {
return "You're getting plenty of sleep! Mayber even too much!";
} else {
return "Get some more shut eye!";
}
}

sleepCheck(10);
sleepCheck(5);
sleepCheck(8);

Dont know whats wrong, please help


#2

not sure what your working on exactly but from the way i read it you have your comparison backwards should be:
var sleepCheck = function(numHours) {
if (numHours >= 8) {
return "You're getting plenty of sleep! Mayber even too much!";
} else {
return "Get some more shut eye!";
}
}
that way if your getting 8 hours or more of sleep you will be getting enough or too much.


#3

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