Functions and if/else


#1

// Write your function below.
// Don't forget to call your function!

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)
sleepCheck(5)
sleepCheck(8)

What's wrong with this?

Instructions:
Write a function named sleepCheck that takes the parameter numHours
02. 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!";.
03. 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
01. Call the function with 10 hours of sleep, like this: sleepCheck(10);
02. Call the function with 5 hours of sleep.
03. Call the function with 8 hours of sleep.


#2

Take off the first = sign, and add the opening curly bracket. Hope this helped :slight_smile:


#3

I get a syntax error it says: SyntaxError: Expected '{'


#4

Remove the = sign before the >= and try make it a habit to put your if statements in parentheses it helps for easier reading of large amounts of code. Also you are missing an opening bracket for your if statement

so your if and else block would look like.


#5

it still gives me the same output: SyntaxError: Expected '{'


#6

Lemme see your code now with the fixed errors


#7

im strucked on same code.
how to do it correctly?
here's my code:-
// Write your function below.
// Don't forget to call your function!
var sleepCheck = function (numHours){
if (sleepCheck >=8);
return ("You're getting plenty of sleep")
};
else {
return ("Get some more sleep");
};

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


#8

Remove the semi colon that is after your if statement and put one after your return statement,

if (sleepCheck >=8) {      
    return ("You're getting plenty of sleep");  
}

#9

You also forgot one more closing bracket after your function


#10


this is what it shows now


#11

This is all my code:
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);
sleepCheck(5);
sleepCheck(8);


#12

First of all:

declare numHour <<<< like this
Not "numhour"

you wrote it wrong.Its syntax is

 if (sleepCheck>=8){
    }

After the else statement,DONT FORGET to close the function tag.The code will look like this:

else {
return "Get some more shut eye!";
}
}

after it call a function once.Not again and again
WRONG:

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

CORRECT:

sleepCheck(5);


#13

Why are you asking him to declare an argument as a string?


#14

I'm a girl, and I've done that now


#15

What is the correct code?


#16

Done what? I'm not following :hushed:


#17

String is declared like this ("String") (IN quotes)
Function name is declared like this :
if(numHours>=8)


#18

You need a semi colon after your last bracket };


#19

please give the correct code


#20

i'm confused what should I do?