Sleep Debt Calculator - Correct result but also Undefined

Hey. First question here since I started the Web Development path (so far so good :slight_smile:).

While doing the Sleep Debt calculator project i came across this “undefined” console error message and can’t figure out what I did wrong.

Code here: https://codepen.io/gabec123/pen/JjYyWGd

If you call calculateSleepDebt() you will get the correct result, and an “undefined” on a new line. What am I missing?

I added a function call. No undefined.

we get undefined when a function doesn’t return anything but we do log the returned result.

Hmm…This is what I get

Like that. I wouldn’t worry about that, its something codepen specific. The returned value (or rather, lack of returned value) is also logged.

Okay, maybe not codepen specific. But quite useful to see the returned value in the console. So something you see more common when using the console to call a function.

if you call the function from within the script, you don’t get undefined.

Ah, so not an issue. Thanks :slight_smile: I was keep checking and checking what could have been wrong.