Functions and If/Else where is the error in this syntax


#1

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

}

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

Ive checked over and over again would some be able to explain to me the error in the syntax


#2

You have the sentences wrong, they need to be exactly right.
"You're getting plenty of sleep! Maybe even too much"
"Get some more shut eye!"


#3

Did you figure it out? I'm completely stuck on this one and the one right before it.


#4

nope it still indicates an error Ive rewritten the sentences and it still isn't going through


#5

Post your code and the instructions please.


#6

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

}

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

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.


#7

You need an exclamation point on "Maybe even too much!"


#8

it's still giving me an error message maybe its a glitch in the website's source code i dont know is there a way to bypass the ui button (submit button) in the google developer tools


#9

If you know it is right, then A.) Copy correct code from other posts B.) Refresh Page C.) Refresh Browser


#10

You didn't close your function with semicolons . Put a semicolon } after your closing semicolon to close your function.


#11

I struggled with this one for an hour, but it's all about having only 1 curly bracket. Here's the correct answer:

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!";
}
sleepCheck(10);
sleepCheck(8);
sleepCheck(5);


#12

You could also have more, see this as an explanation why this works:


and what limits it has.