"Functions recap" VS. "Functions & if / else"


Both tasks were not that hard, but I do have little thing I don't understand.
It would be nice if someone can clarify it for me .

This is from Unit 3 "Function recap":

    var nameString = function (name ) {
    	return "Hi, I am " + name

Here it works regardless of console.log()
but it still work with console.log()

This is from Unit 3 "Functions &if /else":

    // 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!";
            return "Get some more shut eye!";

Last line just calls the function , and if I use console.log ()
it causes error, not like the previous example.

Why is this like this?
in my inexperienced mind, the 2nd example should work with console.log(sleepCheck(10))
If I have to guess, is it because if /else statement?
can anyone clarify this for me ??


Ok that's strange if it works without the console.log it should work with the console.log as well. Could you give more information about the error message? Maybe refresh the page and try again solves it.


It will recognize the code as being correct if you print it as fallows

var nameString = function (name) {
return "Hi, I am" + " " + name


console.log("Hi, I am" + " " + name)

But if you do it this way it wont recognize the name function and wont input that into the console.log... so I'm slightly confused aswell