12. Functions & if/else


#1

Can anyone help me? I have no idea what is wrong with this code :frowning:
Introduction to Functions in JS.
Function & if/else

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);
console.log(sleepCheck(5));
console.log(sleepCheck(8));
Oops, try again. It looks like your function doesn't return "Get some more shut eye!" when numHours is 5. Check your if / else syntax and whether you're using the correct comparison operator.


#2

Hi. I'm newbie like you but 5 minutes ago I finished the same activity.

I think you need to change the number 10 by 5 and 8 on code line

and delete next code:

I hope to help you


#3

I'm continuing to get an error that says "Oops! There's a problem with your syntax!"

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

So...What's the problem with my syntax?


#4

You are forgetting the sleepCheck(10) before the console.logs. Try this:

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


#5

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

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


#6

I got the same problem here. I did what you have suggested, but it keeps saying error.


#8

you have 2 }'s towards the end and check the space inbetween (numHourse){


#9

I'm so confused...


#10

Hi Eddie,

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

You are close, you need curly braces after if(numHours >= 8) {

}


#11

Thanks so much! I really appreciate it!


#12

no problem, i have a habit of forgetting those curly braces too


#13

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.