Having trouble with code in sleep debt calculator

solved
Hey guys, so I’m trying to figure out what exactly is wrong with my code. I’ve stared at it for way too long, and can’t find any issues, so it’s probably something simple. It says that I haven’t defined actualSleepHours, but I’ve checked the hint and my code seems to be correct. What is the issue?

const getSleepHours = day => {
if(day === 'monday') {
  return 8;
   }
  else if(day === 'tuesday') {
  return 7;  }
  else if (day === 'wednesday') {
    return 6;
  } else if (day === 'thursday') {
    return 8;
  } else if (day === 'friday') {
      return 7.5;
  } else if (day === 'saturday') {
    return 10;  }
    else if (day === 'sunday') {
      return 9;
    } else {return `that's not an actual day m8.`};
}; 
const getActualSleepHours = () => getSleepHours('monday') + getSleepHours('tuesday') + getSleepHours('wednesday') + getSleepHours('thursday') + getSleepHours('friday') + getSleepHours('saturday') + getSleepHours('sunday');
const getIdealSleepHours = () => {
  let idealHours = 8
  return idealHours *7 };

  const calculateSleepDebt = () => {
    let actualSleepHours = getActualSleepHours();
    const idealSleepHours = getIdealSleepHours();
  };

Hi,
this is not a syntax error but an error thrown by the Codecademy validation, right?
You’ve defined actualSleepHours in a function that doesn’t return anything, so your program doesn’t do anything yet.
It would be best if you post a link to the lesson and the exact step at which you’re stuck.

1 Like

I’ve managed to figure it out. I was at the step of the lesson where I had to use the last defined variables to figure out the sleep debt. The mistake I made was that I didn’t put the next statements within the function calculateSleepDebt, so since actualSleepHours and idealSleepHours are not global variables (if my terminology is correct). They weren’t defined for the program, and therefore produced an error message. Thanks for helping out though!

1 Like