Sleep Debt Calculator- ccalculateSleepDebt

https://www.codecademy.com/workspaces/61f6b476a4b5b8752e7561ee

I am trying to work through The sleep debt calculator project and I cannot figure out where I have gone wrong.

When I am calling

calculateSleepDebt()

it returns as if the two variables are equal although they are not. If I log them individually they show the actual numbers which are different.

I was wondering if anyone could help me identify where the mistake was?

Then your function does not return the correct validation. We can only help you if you post your code.

I linked to the forked website but I can copy and past it as well if thats easier. Thanks

const getSleepHours = (day) => {
  if (day === 'monday') {
    return 8;
  } else if (day === "tuesday") {
    return 7;
  } else if (day === "wednesday") {
    return 8;
  } else if (day === "thursday") {
    return 7;
  } else if (day === "friday") {
    return 9;
  } else if (day === "saturday") {
    return 5;
  } else if (day === "sunday") {
    return 8;
  } else {
    return "error";
  }
};

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

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

const calculateSleepDebt = () => {
  const actualSleepHours = getSleepHours();
  const idealSleepHours = getIdealSleepHours();

  if (actualSleepHours > idealSleepHours) {
    console.log("You got more sleep than you needed this week. You got" + (actualHoursofSleep - idealSleepHours) + "hours(s) more than you needed");
  } else if (actualSleepHours < idealSleepHours) {
    console.log('You did not get enough sleep. You should have ' +
        (idealSleepHours - actualSleepHours) + 'hour(s) more per week');
  } else {
    console.log('You got the perfect amount of sleep');
  };
};


calculateSleepDebt();

Where did you add the console?
Try adding a console in the function calculateSleepDebt and log the variables actualSleepHours and idealSleepHours…

in my last function

const actualSleepHours = getSleepHours();

it should have been written

const actualSleepHours = getActualSleepHours();

when logged inside the last function it came up as undefined. I was logging them separately outside of the function.

Thank you for your help!

1 Like