Lesson 12 - I'm stuck?


#1



It says its not returning the correct response for number 10, but it is.


Replace this line with your code. 
// 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);
sleepCheck(5);
sleepCheck(8);


#2

NVM, it didn't show up on the code, but it did when I posted, there were spaces in it, which is odd as it didn't show up in the editor! D:


#3

There are spaces so that would be the wrong response.

EDIT: You figured it out on your own, nice.


#4

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

I got error which I can't see it ? anyone can help me ?


#5

return "You're getting plenty of sleep! Maybe even too much!";

I pasted your code into my window and found the word 'sleep!' Missing a space after it.

 sleep! **there is a space** Maybe

#6

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.

but I got this result after do the code .. I also put space at (sleep !) still have error


#7

I think you have to call the function inside the if condition like this:

if (sleepCheck(4)>= 8){
console.log("You're getting plenty of sleep! Maybe even too much!");
}else{
console.log("Get some more shut eye!");
}

P.S: Remove
sleepCheck(10);
sleepCheck(5);
sleepCheck(8);

This is my code:

function sleepCheck(numHours){

if(sleepCheck(2)>= 8){
    console.log("You're getting plenty of sleep! Maybe even too  much!");
}else{
    console.log("Get some more shut eye!");
}

};


#8

Please help! here's my code so far:
// Write your function below.
// Don't forget to call your function!
var sleepCheck = function(numHours) {
if (numHours >= 8) {;
console.log( "You're getting plenty of sleep! Maybe even too much!");
{;
else };
return"Get some more shut eye!";
};

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

And here is the error message:

SyntaxError: Unexpected token else

I have tried removing curly brackets, removing semi-colons, and every combination I can think of. Can somebody drop a hint as to what I'm doing wrong?


#9

if-else syntax:

if (condition) {
   // code block;
} else {
   // code block;
}

In your case:

```
var sleepCheck = function(numHours) {
if (numHours >= 8) {; // should be without ;
console.log( "You're getting plenty of sleep! Maybe even too much!");
{; // should be } (without ; )
else }; // should be { (without ; )
return"Get some more shut eye!";
};

#10

Thank-you SOO much your help! I found a couple other things I needed to fix as well after that was fixed.


#11

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