Lesson 12


#1


https://www.codecademy.com/courses/javascript-beginner-en-6LzGd/2/4?curriculum_id=506324b3a7dffd00020bf661

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

I dont now why but it gives me result "good sleep" even if I wont call the function with giving it number of Hours, for some reason it makes numH=10 from the begining

var sleepCheck = function(numH) {
    if (numH>=8) {console.log("good sleep");}
    else {console.log("sleep more");}
}


#2

when you need to return something, use the return keyword, also, you should return the strings provided by the exercise, not your own strings


#3

I still have problem
var sleepCheck = function(numH)
{ if (numH >= 8) {return console.log("You're getting plenty of sleep! Maybe even too much!");}
else
{
return console.log("Get some more shut eye");

}

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

and result is
You're getting plenty of sleep! Maybe even too much!
Get some more shut eye
You're getting plenty of sleep! Maybe even too much!
You're getting plenty of sleep! Maybe even too much!


#4

What is the difference between return and console.log if it used in brackets ??? becase it works with return but dont want to work with console.log


#5

return actually returns something, look:

var example = function(){
  return "i am being returned";
}
store = example();
console.log(store);

see how the string is being returned? the function literally gives you something in return/back. Where as console.log just logs something to the console

the exercise calls the function for validation purposes, passing 10 as argument, not much you can do about it


#6

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

}
};
var newsleep = sleepCheck(10);
console.log(newsleep);
why it saying like this "Check your if / else syntax and whether you're using the correct comparison operator." ???


#7

the first part of the error message is more interesting:

It looks like sleepCheck() isn't returning "You're getting plenty of sleep! Maybe even too much!"

strings returned need to be an exact match, in both your strings the exclamation mark at the end is missing


#8

can you be more specific! please ... because i cant get you :confused: @stetim94


#9

the strings you need to return should be an exact match of what the exercise expects of you. In your case for example, you have:

Maybe even too much

but this should be:

Maybe even too much!

you forgot the exclamation mark at the end, same for get some more shut eye(!)


#10

Thanx now its working ! :slight_smile: @stetim94 :yum:


#11