Introduction to Functions in JS - Please help! 12/13


#1

I've been working hard on codecademy. But this kills my brain.

Write a function named sleepCheck that takes the parameter numHours
Inside the function, write an if statement where if the number of hours of sleep is greater than or equal to 8, the computer will return "You're getting plenty of sleep! Maybe even too much!";.
Otherwise (else) if the number of hours of sleep is less than 8, have the computer return "Get some more shut eye!";
Then call the function with different hours of sleep

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.

function sleepCheck(numHour);
if (>= 8){
    return "You're gettin plenty of sleep! Maybe even too much!"
    }
    else {
        return "Get some more shut eyes!"
        }
        
        sleepCheck(10);
        sleepCheck(5);
        sleepCheck(8);

Seems to be wrong..


#2
function sleepCheck(numHour);
if (>= 8){
return "You're gettin plenty of sleep! Maybe even too much!"
}
else {
return "Get some more shut eyes!"
}

A couple of minor tweaks:

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

#3

Thanks so much for this! I was struggling with the syntax. However, there is a small typo in the last line. Make sure it says "Get some more shut eye!", not "shut eyes!". The tutorial won't accept it otherwise.


#4

Fixed the error in my reply. Thanks.


#5

The tutorial is very sensitive...I typed a lower case "maybe even too much!" and kept getting an "Oops, try again" error...when I changed it to an uppercase "Maybe even too much!" it was accepted.

I'm just saying, fifteen minutes of banging my head against the wall and search the forum was a little frustrating for case-sensitivity in the instructions. I understand following instructions, but is there a way to inspect the code and give a little slack for capitalization? Or maybe that is why I'm learning to code...to learn to follow instructions to the capital letter...


#6

I thought the same thing at first too Brett24, got frustrated with missing an exclamation point here, or a period there, but then I realized, this is exactly the kind of thing people need help with - editing the code so it's correct. Debugging I think it would be considered. So yea, I feel you - I bang my head against the desk for 15 minutes too then get so relieved when I see it was just missing an exclamation point! :smile: If anything, I wish the tutorial could say "specifically" what was wrong with our code instead of just a general statement.


#8

@coursesurfer47498, thanks for the reply. The Code Academy simulator/tutorial can only get more intelligent as we point out these small things that "bug" us... but I agree, more realistic error reporting will be appreciated by future head-bangers...I mean future-coders...


#9

Write a function named sleepCheck that takes the parameter numHours. Inside the function, write an if statement where if the number of hours of sleep is greater than or equal to 8, the computer will return "You're getting plenty of sleep! Maybe even too much!";. Otherwise (else) if the number of hours of sleep is less than 8, have the computer return "Get some more shut eye!";

If I'm not mistaken, the error message includes the exact phrases that are expected (and as given in the instructions). Is that not enough indication of what might be wrong in the code? In my opinion, instructions are meant to be followed as closely as possible. The author cannot possibly anticipate all the variants in deviation by the learner so is forced to write error messages that stay grounded in what the instructions ask for.


#10

hello mtf
could you kindly check the following code

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

I am being tired of being stuck here for second day!


#11

Did you write the three calls as asked in the instructions?

sleepCheck(10);
sleepCheck(5);
sleepCheck(8);

#12

As mentioned above - tutorial is very sensitive - actually, it's way TOO sensitive - I kept failing a lesson even though the code was working - I finally figured out that it was because where I typed the message "You're getting plenty of sleep! Maybe even too much!", I had put 2 spaces between the first & last sentences. The problem was that I was only supposed to put 1 space.

I'm compiling a mental checklist of things to check when I get an error for my code for things like this, even though it's technically correct.