Sleep Debt Calculator Help

Hello, Everyone!

I am currently working on this project and it’s driving me crazy! I followed the instructions as best as I could but when I got to step 9 I called the function and nothing happens. When I log it to the console it just says “Undefined”.

Can someone show me what I am doing wrong?

const getSleepHours = day => {
  if (day === 'monday') {
    return 8;
  } else if (day === 'tuesday') {
    return 7;
  } else if (day === 'wednesday') {
    return 5;
  } else if (day === 'thursday') {
    return 6;
  } else if (day === 'friday') {
    return 3;
  } else if (day === 'saturday') {
    return 9;
  } else if (day === 'sunday') {
    return 4;
  } else {
    console.log('Check Code.');
  }
};

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

const getIdealSleepHours = () => {
  let idealHours = 8;
  return idealHours * 7;
};
 
const calculateSleepDebt = () => {
  const actualSleepHours = getActualSleepHours();
  const idealSleepHours = getIdealSleepHours();
  if (actualSleepHours === idealSleepHours) {
    console.log('You got the perfect amount of sleep!');
  } else if (actualSleepHours > idealSleepHours) {
    console.log('You got more sleep than needed!');
  } else if (actualSleepHours < idealSleepHours) {
    console.log('You got less sleep that you needed. Get some rest!');
  } 
};

calculateSleepDebt();
1 Like

getActualSleepHours() needs a return statement in it. At the moment it’s not returning anything, so it’s giving back ‘undefined’.

Thank You! This is definitely what was wrong. Something so small too smh

1 Like