Functions and if / else


#1

THE FOLLOWING ARE THE INSTRUCTIONS : 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.
THIS IS WHAT I HAVE SO FAR , PLEASE TELL ME WHAT I'M DOING WRONG : // Write your function below.
// Don't forget to call your function!
var sleepCheck = function(numHours) {
if (the number of hours of sleep is >= 8) {
return "You're getting plenty of sleep! Maybe even too much!";
} else {
return "Get some more shut eye!";
}


#2

HI!

From what I can see of the above, the code you have so far is what I have with the exception of one {

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

Having said that, I wrote the below:

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

and am getting a 'SyntaxError: Unexpected token if' error message. I think thoughts on this one would be greatly appreciated!


#3
var sleepCheck = function (numHours) { // missing this brace
    if (numHours >= 8) {
        return "You're getting plenty of sleep! Maybe even too much!";
    } 
    else {
        return "Get some more shut eye!";
    }
}; // and missing this brace and semi-colon

#4

Remember you're using a function, so make the best of what the function is being used for.

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

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

try fixing this line from

if(the number of hours of sleep is >= 8){

to

 if(numHours >= 8){

so

var sleepCheck = function(numHours) {
                            v
       /--------------------/
       v

if(numHours >= 8){