Intro to func. # 12


#1

it says in the console: "syntaxError: expected expression got keyword 'if' "
here is my code:

// Write your function below.
// Don't forget to call your function!
var sleepCheck = function(numHours)
if (numHours < 8){
return "You're gettin very little sleep, get more sleep!";
}
else
if (numHours > 8){
return "You're gettin very little sleep, get more sleep!";
}


#2

Hi! This is Cristóbal, from Spain.

I think you have forgotten to write curly brackets before the if statement (twice). Try adding them.

// Write your function below.
// Don't forget to call your function!
var sleepCheck = function(numHours) {
if (numHours < 8){
return ("You're gettin very little sleep, get more sleep!");
}
else
{
if (numHours > 8){
return ("You're gettin very little sleep, get more sleep!");
}
}
I always write brackets in the return statement, but I'm not sure if I need them


#3

The () around the return statement are not necessary but the {} around the stuff that belongs to your function really are necessary!

Also it seems that you missed one as well :smile:


#4

I didn't try the code inside my answer, so I couldn't realize I was wrong. Thanks!


#5
> // Write your function below.
// Don't forget to call your function!
sleepCheck = function (numHours)
    {
    if (numHours >= 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);