12 if/else


#1


Replace this line with your code. 
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));

Error: 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.


#2

I don't think the error is a matter of you coding something wrong, I think codecademy is being picky that you don't have the exact string in your first return statement (Notice that you don't put two spaces after your exclamation point). Make sure the string they want is what you have word for word.


#3

i tried it but still the same error.


#4

I missed a charachter within the return comment originally, and was getting the same error. I'd advise calling the function without console.log, that doesn't seem to work. Try one function at a time too. Hope that helps.


#5

I was having the same problem until I just copy pasted what they said to write into my if/else.


#6

ya... i copy and paste from other user that exactly the same code but it does work.strange~


#7

Please remember to use the correct brackets {} quantity. Probably the error is due to that.


#8

Code like this it works:-

// Write your function below.
// Don't forget to call your function!
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));

I DONOT GET ANY ERROR!
I ONLY WANT TO SOLVE YOUR PROBLEM AND NOTHING ELSE.


#9

Thank you to all who take time to explain this. as i do not share the same patience. :slight_smile:


#10

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