12 Functions & if / else


#1

**Please help! I don't know what I'm doing wrong!
this is what I have.

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);

It keeps returning 'Oops try again. There was a problem with your syntax.'


#2

No semicolons after conditions:


if(numHours >= 8); <---

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

#3

now i was looking through things and i found something that might help but its still doing the same thing

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


#4

nm just figured it out


#5

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

console.log(sleepCheck(10));
console.log(sleepCheck(5));
console.log(sleepCheck(8));

for all of those out there having trouble with this one


#6

it didn't work for me :frowning: I copy and pasted your code! I get a " unterminated string constant " error.


#7

Yes there is a closing " missing at the end of Maybe even too much!;


#8

// Write your function below.
// Don't forget to call your function!
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!");
}
};
console.log(sleepCheck(10));
console.log(sleepCheck(5));
console.log(sleepCheck(8));


#9

I am getting the proper response when runniing my code. That is, the text displays correct response when calling the function.
However, I am still getting the following:

"Oops, try again. It looks like sleepCheck() isn't returning "You're getting plenty of sleep! Maybe even too much!" when numHours is 10. Check your if / else syntax and whether you're using the correct comparison operator."

Here is my code:

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)


#10

you forgot the capital 'Y' in "You're". it needs to be accurate otherwise it won't see it as the right string


#11

The syntax seems to be ok so I'd guess it's a typo and I just see that @perrtdegerrt already found it.


#12

Thanks a bunch. Should have copied/paste!


#13

My code below returns "Oops, try again. It looks like sleepCheck() isn't returning "You're getting plenty of sleep! Maybe even too much!" when numHours is 10. Check your if / else syntax and whether you're using the correct comparison operator." Any help?

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

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

#14

You're the rest is correct from what I can see.


#15

Oh man, that's embarassing. Thanks so much!

Now i'm getting the same error except for "Get some shut eye" for 5.


#16

Guess it's a missing more. Don't bother that much about it, as long as your syntax is correct.


#17

on line 4 take away the ";"