Issues with Sleep Debt project

I’m having some issues with the sleep debt project where I am getting a return of: actualSleepHours is not defined.

Below is the code that I wrote out, in some instances watching the help video and writing the exact code down, and I can’t seem to get it to work. Any and all help would be very much appreciated.

const getSleepHours = (day) => {
if (day === ‘monday’) {
return 8;
} else if (day === ‘tuesday’) {
return 6;
} else if (day === ‘wednesday’) {
return 7;
} else if (day === ‘thursday’) {
return 8;
} else if (day === ‘friday’) {
return 7;
} else if (day === ‘saturday’) {
return 8;
} else {
return 8;
}
};

const getActualSleepHours = () => getSleepHours(‘monday’) + getSleepHours(‘tuesday’) + getSleepHours(‘wednesday’) + getSleepHours(‘thursday’) + getSleepHours(‘friday’) + getSleepHours(‘saturday’) + getSleepHours(‘sunday’);

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

console.log(getIdealSleepHours());
console.log(getActualSleepHours());

const calculateSleepDebt = () => {
const actualSleepHours = getActualSleepHours();
const idealSleepHours = getIdealSleepHours();
};

if(actualSleepHours === idealSleepHours) {
console.log(‘You got the perfect amount of sleep this week!’);
} else if(actualSleepHours > idealSleepHours) {
console.log(‘You got ’ + (actualSleepHours - idealSleepHours) + ’ extra hours of sleep this week!’);
} else {
console.log(‘You got ’ + (idealSleepHours - actualSleepHours) + ’ hours of rest than you need this week!’);
};

calculateSleepDebt();

Thank you!

The variable is defined inside a function, so not accessible in outside scope. Perhaps you meant to write the rest of the code inside that same function?

1 Like

Thank you very much!

2 Likes