sleepDebtCalculator help

I don’t know what’s wrong with my calculator, my code is flagging this line:

} else (actualSleepHours < idealSleepHours) {

Here is the code:

const getSleepHours = (day) => {
  switch (day){
    case 'Monday':
      return 8;
      break;
    case 'Tuesday':
      return 7;
      break;
    case 'Wednesday':
      return 9;
      break;
    case 'Thursday':
      return 7;
      break;
    case 'Friday':
      return 9;
      break;
    case 'Saturday':
      return 6;
      break;
    case 'Sunday':
      return 8;
      break;
    default:
      console.log('Error!')
  };
}
const getActualSleepHours = () => 
getSleepHours('Monday')+
getSleepHours('Tuesday')+
getSleepHours('Wednesday')+
getSleepHours('Thursday')+
getSleepHours('Friday')+
getSleepHours('Saturday')+
getSleepHours('Sunday');
;

const getIdealSleepHours = () =>{
const idealHours = 8;
return idealHours * 7;
}
const calculateSleepDebt = () => {
  const actualSleepHours = getActualSleepHours();
  const idealSleepHours = getIdealSleepHours();

if (actualSleepHours === idealSleepHours) {
  console.log('You slept perfectly')
} else if (actualSleepHours > idealSleepHours) {
  console.log('You overslept'+ (actualSleepHours - idealSleepHours) + 'hours')
} else (actualSleepHours < idealSleepHours) {
  console.log ('You slept'+ (actualSleepHours - idealSleepHours) + 'so you need rest')
};
}
calculateSleepDebt()

The else clause takes no condition.

1 Like