Functions & if/else


#1



This is a link to the exercise that I am stuck on: https://www.codecademy.com/courses/javascript-beginner-en-6LzGd/2/4?curriculum_id=506324b3a7dffd00020bf661#


When I submit the code, it says there is a syntax error.

This is the code that I have written:

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!";
}

sleepCheck(10);


#2

I believe you have forgotten something that goes just after (numHours) and something else that goes after your last }. Also, don't forget to have sleepCheck evaluate for the other 2 numHours in the instructions.


#3

In the above code,you called a function with a it variable name i.e sleepCheck>= 8 in the second line of your code.
Call that function with its name you defined in function(name) that is numHours
And the second problem is you didnt wrote Curly braces after function i.e
function(numHours) {
and you have to close these braces as well on the end of the function after end statement braces

So write the code like this:

        var sleepCheck = function(numHours) {
// you're doing a mistake here in the line below.I corrected it

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

#4

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