12 Functions & if / else


#1


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.


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

Not exactly sure what I've been doing wrong, please help! I've been stuck on this problem for so long @_@


#2

the string return should be an exact match, copy it from the instructions. I see one mistake, you have two spaces between sleep! and Maybe, this should be one space


#3

Got it! Haha, I can't believe that that's all I needed to do :joy: Thank you so much for your help!!


#4

if codecademy is so anal about spacing then the error box should be more specific, just sayin cause ive been stuck on this problem for 30 min and its returning the right values, kinda turning me off from this site to be honest


#5

That is why we have a forum so you can be helped :slight_smile: Well, since strings returned isn't the most important, you can also just copy them. And now you know that this is crucial, so you will double check it next time.

Well, to find all additional spaces/characters and exactly tell which is missing is difficult. The error message does tell you, your string is incorrect. These error messages are still human friendly, if you get one from a compiler or interpreter, they can be even more cryptic.


#6

hi guys, what's wrong in here?

var sleepCheck = function(numHours) {
if (sleepCheck >= 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))


#7

and I get this: Ops, tente outra vez. 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.


#8

you compare your function with the hours of sleep:

if (sleepCheck >= 8)

which is false, this should be numHours instead of sleepCheck, the parameter you have in the function


#9

my bad! thnx a lot!!!