actualSleepHours not defined


#1

I’m getting ReferenceError: actualSleepHours is not defined, I’ve rechecked my code and even compared it to the video help but I still can’t figure it out.

const getSleepHours = day => {
  switch(day) {
    case 'monday':
      return 8
      break;
    case 'tuesday':
      return 4
      break;
    case 'wednesday':
      return 9
      break;
    case 'thursday':
      return 7
      break;
    case 'friday':
      return 5
      break;
    case 'saturday':
      return 9
      break;
    case 'sunday':
      return 4
      break;
    default:
      return 'Error'
      break;
  }
};

const getActualSleepHours = () =>
  getSleepHours('monday') +
  getSleepHours('tuesday') +
  getSleepHours('wednesday') +
  getSleepHours('thursday') +
  getSleepHours('friday') +
  getSleepHours('saturday') +
  getSleepHours('sunday');

console.log(getSleepHours('monday'));
console.log(getActualSleepHours());

const getIdealSleepHours = () => {
  let idealHours = 12;
  return idealHours * 7;
};

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

if (actualSleepHours === idealSleepHours){
  console.log('perfect');
} else if (actualSleepHours > idealSleepHours){
  console.log('too much');
} else {
  console.log('rest');
};

calculateSleepDebt();

If anyone could help me with this problem, it would be very much appreciated!


#2

As we see, that variable is in function scope, and cannot be seen outside of the function body.

Did you intend for the conditional to be inside that same function? Looks like it.


#3

I can’t believe I didn’t notice that, it’s working now. Thank you!