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


#1

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
    };
    console.log(
        nameString("Han")
        )

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!";
     }else
        { 
            return "Get some more shut eye!";
        }
        
    };
    sleepCheck(10)

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 ??


#2

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.


#3

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

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

};
nameString("Ben")

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