Finished calculator seems to work, but it's also logging undefined


#1

This is my first post, so I apologize if the formatting is off. I got to the last step where I call the calculateSleepDebt() function, and the console.log works like I want it too, the math is correct, etc. However, it also logs a random “undefined” after the sentence. I’ve spent the last half hour reading and tweaking my code and I cannot get it to go away. Any help would be appreciated. Thank you

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


const getActualSleepHours = () => {
  return getSleepHours('Monday') +
    getSleepHours('Tuesday') +
    getSleepHours('Wednesday') +
    getSleepHours('Thursday') +
    getSleepHours('Friday') +
    getSleepHours('Saturday') +
    getSleepHours('Sunday'); 
};

const getIdealSleepHours = () =>{
  var idealHours = 8;
  return idealHours * 7;
};

const calculateSleepDebt = () => {
  var actualSleepHours = getActualSleepHours();
  var idealSleepHours = getIdealSleepHours();
  if (actualSleepHours===idealSleepHours){
    console.log('Perfect amount of sleep.');
  } else if (actualSleepHours > idealSleepHours){
    console.log(`Too much sleep. You should sleep ${actualSleepHours - idealSleepHours} hours less.`);
  } else if (actualSleepHours < idealSleepHours){
    console.log(`You need to sleep ${idealSleepHours - actualSleepHours} hours more.`);
  };
};
      
console.log(calculateSleepDebt());

#2

There is no need to log out the return value of calculateSleepDebt() because there is none. The results are logged by the function, itself.


#3

Oh man, thank you! I kept playing around with the functions trying to solve it, never occurred to me that it was the call itself that was messing it up. Thanks


#4

The other option is to the return the results, then logging the call will be sensible (and required if you want to see the output).