I need help on Sleep Calculator Exercise, PLEASE

I really need help, I have been working on this forever this evening. Any help or pointers is much appreciated


const getSleepHours = (day) => {
  switch (day) {
    case 'monday':
      return 8
      break
    case 'tuesday':
      return 7
      break
    case 'wednesday':
      return 6
      break
    case 'thursday':
      return 5
      break
    case 'friday':
      return 4
      break
    case 'saturday':
      return 3
      break
    case 'sunday':
      return 2
      break
    default:
      return 'error'
  
    
  }
}
const getActualSleepHours = () => {
  getSleepHours('monday')+getSleepHours('tuesday')+getSleepHours('wednesday')+getSleepHours('thursday')+getSleepHours('friday')+getSleepHours('saturday')+getSleepHours('sunday')
}
const getIdealSleepHours = () => {
  idealHours = 8
  return idealHours * 7
}
const actualSleepHours = getActualSleepHours()
const idealSleepHours = getIdealSleepHours()
leftovers = idealSleepHours - actualSleepHours
const calculateSleepDebt = () => {
  if (actualSleepHours === idealSleepHours) {
    console.log('Great!  You have the perfect amount of sleep!')
  
  } else if (actualSleepHours > idealSleepHours) {
    console.log('Wow!  You are sleeping more than you want to!  You can cut back on' + (leftovers) + 'hours of sleep!')
  
  } else {
    console.log("Whoa!  You are not getting enough sleep.  Get an additional" + (leftovers) + "additional hours of sleep to go back on track!")
  }
};
calculateSleepDebt()

I looked at parts of the code
and I found the following:

leftovers = idealSleepHours - actualSleepHours

should probably be

const leftovers = idealSleepHours - actualSleepHours;

Also, in

  console.log('Wow!  You are sleeping more than you want to!  You can cut back on' + (leftovers) + 'hours of sleep!')

You probably want extra spaces in the string before and after the + (leftovers) +

Also, leftovers would be a negative number here, so (leftovers) should be (-leftovers) to make it positive only on that line.

Also, in case you want your calculateSleepDebt function to return the sleep debt,
it should return the difference between idealSleepHours and actualSleepHours,
and with what you have so far, that would mean having

  return leftovers;

at the end of that function.

you are missing the return in the getActualSleepHours function.

In the getIdealSleepHours function,
idealHours = 8 should probably have a let or const in front of it.

https://www.codecademy.com/courses/introduction-to-javascript/projects/sleep-debt-calculator

There was another step added to the “Sleep Debt Calculator” for extra practice. I tried to use the hint, but I got an error. Here’s the last task and my code.

For extra practice, try these:

  • getActualSleepHours() could be implemented without calling getSleepHours() . Use literal numbers and the + operator to rewrite getActualSleepHours() . It should still return the total actual hours slept in the week.
  • Some people need to sleep longer than others. Rewrite getIdealSleepHours() so that you can pass it an argument, like getIdealSleepHours(8) where 8 is the ideal hours per night. Update the call to getIdealSleepHours() in calculateSleepDebt() too.

To see the solutions, open the hint.

const getSleepHours = day => { switch(day) { case 'monday': return 8 break; case 'tuesday': return 7 break; case 'wednesday': return 8 break; case 'thursday': return 5 break; case 'friday': return 8; break; case 'saturday': return 7 break; case 'sunday': return 8 break; default: return "Error!" } }; // const getActualSleepHours = () => // getSleepHours('monday') + // getSleepHours('tuesday') + // getSleepHours('wednesday') + getSleepHours('thursday') + // getSleepHours('friday') + // getSleepHours('friday') + // getSleepHours('saturday') + // getSleepHours('sunday'); const getActualSleepHours = () => 6 + 7 + 9 + 8 + 5 + 10 + 11; console.log(getSleepHours('monday')); console.log(getActualSleepHours()); // const getIdealSleepHours = () => { // let idealHours = 8; // return idealHours * 7; // }; const getIdealSleepHours = idealHours => idealHours * 7; // const calculateSleepDebt = () => { // const actualSleepHours = getActualSleepHours(); // const idealSleepHours = // getIdealSleepHours() // if(actualSleepHours === idealSleepHours) { // console.log("You've got the perfect amount of sleep!"); // } // else if(actualSleepHours > idealSleepHours) { // console.log("You've got more sleep than needed!"); // } // else if(actualSleepHours < idealSleepHours) { // console.log("You need more sleep!"); // } // else { // console.log("Error! Something went wrong, check your code."); // } const calculateSleepDebt = () => { const ideealSleepHours = getIdealSleepHours(8); } console.log(getActualSleepHours()); console.log(getIdealSleepHours()); calculateSleepDebt();