Stuck on lesson 12 Functions if / else


What is wrong with my code. I’ve tried it with the console.log and without it.
I always get the same 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 operator.

But in the results window I’m seeing all 3 results:
You’re getting plenty of sleep! Maybe even too much!
Get some more shuteye!
You’re getting plenty of sleep! Maybe even too much!

Code below:

var sleepCheck = function(numHours)
if (numHours >= 8)
return “You’re getting plenty of sleep! Maybe even too much!”;
return “Get some more shuteye!”;


Hello dfabianke,


You are calling the function ‘sleepCheck’ 3 times, with different parameters (10,5 and 8) respectively, and whatever the function returns, will be ‘printed’ in the console. So, if you would like to only check what the function returns for 5 hours of sleep, delete the other 2 calls to the function. That should do the trick.

Hope this helps!


Hi @dfabianke,

Your code is working fine.

It’s just that your code doesn’t print the exact match of sentence the instruction wanted.

Instruction from lesson:

if the number of hours of sleep is less than 8, have the computer return "Get some more shut eye!";

Notice the shut eye with a space. So your code should be:

return "Get some more shut eye!";

Copy the sentences exactly from the instruction in future lesson, it will avoid any unwanted hindrance.

Note: It will be good to provide a link to your exercise next time, so people would not have to search manually for the lesson you’re mentioning.

Happy Coding! Cheers :slight_smile:


thank you so much! I bet I looked at this for over an hour and it was something so silly. I appreciate it!


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