12/13 Critique my code?


#1

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

A error message pops up saying "StynaxError: Unexpected token if"
Any help is appreciated


#2

You need to wrap your function in {}


#3

{var sleepcheck = function(numHours)}

?


#4

Hey, You didn't use the correct syntax for your function.

Here is the correct Syntax

var functionName = function(parameters) {
    // Your code goes here;
};

So, according to the Syntax above, your function should look like this

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

Check the working script I gave you and verify your mistakes, also try to make your code look good so it is easy to understand, :smiley:


#5

Thank you for your help!


#6

@heyyoushutup Welcome Even I am learning JS :smile:


#7

Thanks for completing my answer. Just some remarks, I guess its numHours >= 8 and you don't need the () around the stuff after return (it's not a function just a keyword).


#8

Yes i have seen that. Forgot to tell ya xD