Why is the output undefined?


Currently finished the sleep debt calculator project here:


I did manage to get it working, but after it calculates the sleep debt, I also get an “undefined” output.

I was hoping someone could let me know why that is happening. thanks!

Here is my code:

let getSleepHours = day => {
  switch (day) {
          case 'Sunday':
          return 6
          case 'Monday':
          return 6
          case 'Tuesday':
          return 6
          case 'Wednesday':
          return 8
          case 'Thursday':
          return 7
          case 'Friday':
          return 8
          case 'Saturday':
          return 8
          return 'Invalid Day'

const getActualSleepHours = () => 
  getSleepHours('Sunday') +
  getSleepHours('Monday') +
  getSleepHours('Tuesday') +
  getSleepHours('Wednesday') +
  getSleepHours('Thursday') +
  getSleepHours('Friday') +

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

const calculateSleepDebt = () => {
  const actualSleepHours = getActualSleepHours()
  const idealSleepHours = getIdealSleepHours()
  const missingSleep = idealSleepHours - actualSleepHours
  const surplusSleep = actualSleepHours - idealSleepHours
  if (actualSleepHours === idealSleepHours) {
    console.log('You got the perfect amount of sleep')
  } else if (actualSleepHours < idealSleepHours) {
    console.log(`You need ${missingSleep} more  hours of sleep`)
  } else {
    console.log(`You got ${surplusSleep} more  hours of sleep than you needed`)


i don’t get any output at all, did you call calculateSleepDebt?


sorry, I forgot to add the last bit of code which is:



If you call console.log more times than you expect output then … I don’t need to say any more than that do I


okay I think I follow. I called console.log within the function and out in the global scope, which was unnecessary. Correct?


You’ll write something each time you call console.log. Whether something should happen or not is for the programmer, you, to decide. Correct is relative to your expectations.