12 Functions & If/Else


#1

My page says, "Way to go! Start next lesson", but my code isn't returning anything anywhere ... I tried refresh several times, but nothing changed. Any ideas?

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

@jmadala you have the three lines where you call the function embedded in the function itself. If you take

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

and put it below the last closed curly brace (}) your code should run and display the results.


#3

@freginold - It worked! Thank you for the correction on the placement.


#4

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

When I ran this the answer was given only for the first function sleepCheck(10) , but I was able to get to the next lesson . I was wondering whether there was a way to get the answer to all three?


#5

The problem is that you're not using any output statements like console.log. So what you see is just the console feature that echoes the last value in your code (in case it is not undefined) in your case sleepCheck(8);

Also if you have a question not concerning the original one please open look if there is already one answered and if not post it on your own with a meaningful title. This keeps question threads short and readable and allows people to find already answered questions.