Function & if/else


#1



https://www.codecademy.com/courses/javascript-beginner-en-6LzGd/2/4?curriculum_id=506324b3a7dffd00020bf661#

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.

i can not figure out what is wrong with my coding below, please help! the thing is i can get the correct output but still getting this error message to stop me going further

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);


#2

@jinpower

Remove the space between ( and numHours


#3

just tried, still does not work :frowning:


#4

@jinpower

There shouldn't be spaces between " and Y. There also shouldn't be spaces between much and !


#5

i just removed the space you reminded me and realised i also need to remove the space in front of " Get" !! now it runs correctly ! thanks a lot !


#6

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);

This was my code, I am getting the same error message as you. I followed the advice and had no extra spaces, but it's still telling me that sleepCheck isn't returning "You're getting plenty of sleep" when numHours is 10. When I test the code, it works perfectly except for the message popping up telling me that it's not working. @jinpower I read that you were able to get yours to work once you took out all spaces, but mine doesn't have that problem. Any suggestions on how to fix this?


#7

I have tried it with and without the parantheses around "You're getting plenty of sleep", and I looked at @jinpower code to try and make mine look like that, still not working.


#8

HI it's the string which give you the error..
yours

" You're getting plenty of sleep! Maybe even too much !"

the on you should return

"You're getting plenty of sleep! Maybe even too much!";