Sleep Debt Calculator : Adding { .... } makes my sum undefined, taking {...} away gives me the correct answer. Any idea why?

Hi! I’m having a little bit of trouble and I can’t figure out why.

So I’m currently taking care of the Sleep Debt calculator -

and I can’t figure out why I’m getting this error.

In an attempt to get the sum of my sleep debt hours, I’m running the code:

const getActualSleepHours = () =>
getSleepHours(‘monday’) +
getSleepHours(‘tuesday’) +
getSleepHours(‘wednesday’) +
getSleepHours(‘thursday’) +
getSleepHours(‘friday’) +
getSleepHours(‘saturday’) +

When I run this code, I get the right answer.

However, I thought with a zero parameter function you needed to include something along the lines of const getActualSleepHours = () => { (INSERT CONTENT HERE)
}. emphasis on the curly brackets When I run this code though, it prints “undefined”.

Later when I use another zero parameter function, I have to use the {…} or else I don’t get the right answer. I’m simply confused why in one instance I don’t need to use the curly brackets and it gives me the wrong answer, but when I use it later I have to use it or it doesn’t give me the right answer.

Anyone have any thoughts?

When curly braces are used, return must be written explicitly in the function.

Thanks so much! What should I make it return?

I tried adding simply:
return getActualSleepHours();

but still am getting undefined.

Thank you again for your help!!

1 Like

The sum total of all the days (nights) sleep hours. As the entire code is one expression, just insert return before the first line (second if we count the signature line).

const foo = () => {
  return bar('a') +
         bar('b') +