Sleep Debt Calculator-Only getting 'perfect' returned

Hello!
I have been looking at this for a bit but I can’t find the issue. It is only returning ‘perfect’ even when i adjust the hours to being over or under the ideal. What am I missing?
Thanks!

const getSleepHours = day => { switch(day) { case 'Monday': return 8 break; case 'Tuesday': return 8 break; case 'Wednesday': return 8 break; case 'Thursday': return 8 break; case 'Friday': return 8 break; case 'Saturday': return 12 break; case 'Sunday': return 8 break; default: return "error!" } }; const getActualSleepHours = () => getSleepHours('Monday') + getSleepHours('Tuesday') + getSleepHours('Wednesday') + getSleepHours('Thursday') + getSleepHours('Friday') + getSleepHours('Saturday') + getSleepHours('Sunday'); console.log(getSleepHours('Saturday')); console.log(getActualSleepHours()); const getIdealSleepHours = () => { let idealHours = 8; return idealHours * 7; }; const calculateSleepDebt = () => { let actualSleepHours = getActualSleepHours(); const idealSleepHours = getIdealSleepHours(); if (actualSleepHours = idealSleepHours) { console.log('Perfect'); } else if (actualSleepHours > idealSleepHours) { console.log('You slept' + (idealSleepHours - actualSleepHours) + 'hours more than needed') } else if (actualSleepHours < idealSleepHours) { console.log('Get' + (idealSleepHours - actualSleepHours) + 'more sleep'); } else { console.log('error'); } }; calculateSleepDebt();

Double check this code

 if (actualSleepHours = idealSleepHours) {
    console.log('Perfect');
  }
3 Likes

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