12. Functions & if/else


#1

Hey, I am having trouble figuring out what is wrong. I have tried putting curly braces and nothing is happening.

Here is the error message I am getting.
SyntaxError: Unexpected keyword 'if'. Expected an opening '{' at the start of a function body.

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));

#2

Hi you forgot to open and close the function sleepCheck()

var sleepCheck = function() { #open the sleepCheck function

#here pu the if and else statement

}#close the sleepCheck function

#3

I still can't figure out why its not working. Ive tried this way...
var sleepCheck=function(numHours);
{
if (numHours >=8)
}
{
return "You're getting plenty of sleep! Maybe even too much!";
};

Ive tried this way....

{
if (numHours >=8)

return "You're getting plenty of sleep! Maybe even too much!";
};


#4

The code you post before you just need to add

var sleepCheck=function(numHours)
{ #this one { open the sleepCheck function
    if (numHours >=8)
    {
        return "You're getting plenty of sleep! Maybe even too much!";
    }
    else
    {
    return "Get some more shut eye!";
    };
}; #add } this for closing the sleepCheck function

Read the comment


#5

sorry I guess I'm still not understanding. I think I tried it the way you said. Here are the two ways I tried...

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));
};

AND....

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));


#6

Sorry I just figured it out.....

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));


#7

Don't worry I'm glad to help you ..
The first you made

var sleepCheck=function(numHours)
{
if (numHours >=8)
}
return "You're getting plenty of sleep! Maybe even too much!";
}
{ # remove this { 
else {#add one { here
return "Get some more shut eye!";
};
}#add one } for closing the sleepCheck function
console.log(sleepCheck(10));
console.log(sleepCheck(5));
console.log(sleepCheck(8));
};

the other one

var sleepCheck=function(numHours)
{
if (numHours >=8)
}
return "You're getting plenty of sleep! Maybe even too much!";
}
{ #remove this { 
else {#add one { here
return "Get some more shut eye!";
}
};
console.log(sleepCheck(10));
console.log(sleepCheck(5));
console.log(sleepCheck(8))

read the comment ,