Sleep Debt Calculator

Hi guys,
could you please help me?. I’ve been working on this for some time but still receiving an error message.

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

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

console.log(getActualSleep())
// This will print out the amount of hours slept during the week from the figures above
const getIdealSleepHours = ()=> {
   idealHours = 8
  return idealHours * 7
 }
//console.log(getIdealSleepHours())
// this will print the ideal amountof hours that an indiviudal would want to sleep during the week

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

  if (actualSleepHours === idealSleepHours){
    console.log('You have the perfect amount of sleep.');
  } 
  else if (actualSleepHours > idealSleepHours){
    console.log('You have slept more than necessary. Get your life together.')
  }
  else if (actualSleepHours < idealSleepHours){
    console.log('You should have some rest. Seems like you really need it.')
  }
  else {
    console.log('Error! Something went wrong. Please try again.')
  }
}
calculateSleepDebt()

This is the error message I keep getting:
/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/sleepDebtCalculator.js:49
const actualSleepHours = getActualSleepHours();
^

ReferenceError: getActualSleepHours is not defined
at calculateSleepDebt

you named this function getActualSleep:

const getActualSleep = () =>

then when attempt to call it:

const actualSleepHours = getActualSleepHours();

so either change the function declaration/definition or the function call.

1 Like

Thank you so much. It finally worked.

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