This is my code so far for the exercise:
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 6;
} else if (day === ‘friday’) {
return 8;
} else if (day === ‘saturday’) {
return 10;
} else if (day === ‘sunday’) {
return 8;
}
}
console.log(getSleepHours(‘tuesday’));
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(getActualSleepHours());
console.log(getIdealSleepHours());
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 {
console.log(‘You should get some rest’);
};
This is the error that shows up for last if statement:
/home/ccuser/workspace/sleep-debt-calculator/sleepDebtCalculator.js:44
if (actualSleepHours === idealSleepHours) {
^
ReferenceError: actualSleepHours is not defined
at Object. (/home/ccuser/workspace/sleep-debt-calculator/sleepDebtCalculator.js:44:5)
at Module._compile (module.js:571:32)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)
at bootstrap_node.js:542:3
I don’t know what to do, I don’t know why actualSleepHours is undefined when it is on the previous line. Please help