Confused on "Functions & if / else". Introduction to Functions in JS


#1

Introduction to Functions in JS
Functions & if / else

Hi I am confused on the subect "Functions & if / else" on "Introduction to Functions in JS"

Updated Error:

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.

Updated Code:

// Write your function below. 
// Don't forget to call your function!
var sleepCheck = function( numHours ) {
        if ( sleepCheck >= 10 ) {
                return "You're getting plenty of sleep! Maybe even too much!";
        }
        else ( sleepCheck < 10 ); {
                return "Get some more shut eye!";
        }
};

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

Updated Output:

"Get some more shut eye!"

Link:

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

while this post is up, I will be trying to figure it out.


Help on "Functions & if / else"
#2

You didn't use the parameter named numHours in your function.you just took it as parameter. you are checking
if ( sleepCheck >= 10 )

what's sleepCheck?
and here

else ( sleepCheck < 10 );

else doesn't allow to have a condition.you don't need it too.


#3

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