JavaScript Sleep Debt Calculator

Hey there! If anyone could help me I would be really grateful. I got stuck in the project Sleep Debt Calculator. I’m doing everything following the instructions but it still shows me “undefined” when I try to add every day sleep.

const getSleepHours = day => {
  switch(day) {
    case 'monday':
      return 8;
      break;
    case 'tuesday':
      return 8;
      break;
    case 'wednesday':
      return 9;
      break;
    case 'thursday':
      return 9;
      break;
    case 'friday':
      return 7;
      break;
    case 'saturday':
      return 10;
      break;
    case 'sunday':
      return 9;
      break;
   }    
  };
// there is a problem here:`
 const getActualSleepHours = () => {
     getSleepHours('monday') +
     getSleepHours('tuesday') +
     getSleepHours('wednesday') +
     getSleepHours('thursday') +
     getSleepHours('friday') +
     getSleepHours('saturday') +
     getSleepHours('sunday');
           
     
     
  };
const getIdealSleepHours = () => {
  const idealHours = 8.5;
  return idealHours * 7;
};
console.log(getActualSleepHours());
console.log(getIdealSleepHours());

console is printing
undefined,
and then 59.5 (so it works with console.log(getIdealSleepHours());
here is the link to my task:
https://www.codecademy.com/courses/introduction-to-javascript/projects/sleep-debt-calculator

1 Like

You should follow this next time you post your code. How do I format code in my posts?

There’s an important keyword you are missing in your getActualSleepHours() function. You have it in your getIdealSleepHours() and getSleepHours()functions so compare and see what’s missing in getActualSleepHours().

Thank you for answer. In this task Codecademy wanted to not include return statement. I’ve just forgot also to omit curly braces.

Looks like you’re right. That step calls for an implicit return. You would remove the curly braces to accomplish that.