12. Functions & 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 eye!";
}
};
sleepCheck(10);
sleepCheck(5);
sleepCheck(8);

I have no idea what my mistake is. I would appreciate if someone could help me. Thank you.


12. Functions & if/else. What's missing?
#2

Did you close your sleepCheck function?


#3

what do you mean "close my sleepCheck function"?


#4

@biff75 He did close it I believe.

@erador Have you tried printing the sleepCheck() function to the console?


#5

you mean console.log(sleepCheck(10));? it does not work. It says "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

Your code works fine for me, have you trade refreshing or changing browsers?


#7

yes i tried both but it does not work.


#8

What is the exact error you're getting?


#9

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.


#10

Have you changed anything of your code?
If so, could you post your updated code here?


#11

okay i found y mistake! there was a double space in "You're getting plenty of sleep! Maybe even too much!". Thank you everyone for your help.


#12

Not sure what I'm doing wrong with my code? Every time I run it I get this error. 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.

Here is my code.

var sleepCheck= function (numHours){
if (numHours >= 8)
{
return "You're getting plently of sleep! Maybe even too much!";

}
     else {       return "Get some more shut eye!";}

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


#13

Actually never mind I just found my error. I had misspelled plenty ha


#14

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