Why getActualSleepHours result in 0?


#1

Can anyone explain how I can correctly test the two functions (
getSleepHours and getActualSleepHours) in the code below?

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 8;
      break;
     case 'sunday':
      return 8;
      break;
     default:
      return 0;
      break;
          }
}

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

// Test to see if the above code works
getActualSleepHours();
const hoursTotal = getSleepHours();
console.log(`Sleep hours are ${hoursTotal}`);

In my console I get the value of 0 returned. But I don’t understand why. As far as I understand, I call the getActualSleepHours function, which runs the getSleepHours function 7 times with each day of the week as an argument, right? But where is this result stored? I’m confused :slight_smile:


#2

It’s not stored but it should be a return value…

const getActualSleepHours = () => {
  return getSleepHours('monday') + ...;