12. Functions and if/else


#1

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

My code keeps coming up with following error: "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 operation."

Any suggestions?


#2

HI your else statement should return

return "Get some more shut eye!"

instaed of

return "Get some more shut eyes!"

eye insyead of eyes


#3

Problem solved. Thank you for your help!


#4

you have missed the semicolon over here
else{
return "get some more shut eye!";}
};


#5

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


#6

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