Bug in course 11: "Functions and if else"


I've come across this problem before, where the course engine appears to be "very clearly incorrect". Let me know if this error is out of place or my (very simple) code is no good:


I love the UI of Codecademy but this is the second time I've had the engine not let me pass what seems to be a correct piece of code.



Hello @nick.walt.

Call the function with 10 hours of sleep, like this: sleepCheck(10);
Call the function with 5 hours of sleep.
Call the function with 8 hours of sleep.

It seems that you need to call them all at onece in youre code. Like this:



The text string for your else statement returns:

 "Get some more shut-eye"!

The text string you need to use is:

"Get some more shut eye!"


Haha, yeah I should learn to question my own code (ugh, and to check for typos) before I question Codecademy :slight_smile: Thanks for responding, biff.

Although, just reading the error message again, it mentions checking syntax and whether I'm using the correct operator, which isn't at all good feedback. I don't know why Codecademy doesn't also check the string and either:

  1. just ignore the string in the code; or
  2. warn that the string doesn't match the required input.


The tweaked code to provide more granularity. Is there a better way to write this?

function sleepCheck (numHours) {
    let plenty = "You're getting plenty of sleep!";
    let much = "Maybe even too much!";
    let more = "Get some more shut eye!";
    if (numHours >= 8 && numHours <= 9) {
        return plenty;
    } else if (numHours > 9){
        return plenty + " " + much;
    } else {
        return more;
sleepCheck (10);


Better in what sense?


Maybe a way that doesn't use if else. Not sure if this can be done using a hash. I guess it is too simple to distill down to anything else. Cheers


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