sleepDeptCalculator.js course | I'm looking for the code, that log undefined to the console

Hello! : )
I finished the course and tried to challenge myself by coding the course in a different way.
As you can see I use an array for the sleeptime of each day and a for loop to add the single sleeptimes to have a weekly sleeptime.
The if/else function in calculateSleepDebt() is shorthanded and everything else is like the code before.

It would be amazing, if someone can locate the code with me and please feel free to give me some tips and tricks if you recognize something. ; )

const day = [8,5,7,8,8,8,8]; let hours = 0; for (let i = 0; i < 7; i++) { hours += day[i]; }; const getIdealSleepHours = (i) => { let idealHours = i; return idealHours * 7; }; const calculateSleepDebt = () => { const ideal = getIdealSleepHours(6); const more = ideal - hours; const less = hours - ideal; hours === ideal ? console.log('You\'ve slept good!') : hours < ideal ? console.log(`Try to sleep ${more} hours more.`) : console.log(`Try to sleep ${less} hours less.`); }; console.log(calculateSleepDebt());

Hi,
Ask yourself what the last line of code is doing.

You’re asking it to log to the screen the return value of calling the calculateSleepDebt function. But it doesn’t return anything - hence undefined.

Hope that helps

2 Likes

Hello, thanks a lot! : )
Now I understand it and thank you for giving me at first just a hint.

I hope you have a great day and someone will help you like you did to me. ; )

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.