Codecademy Forums

Newbie stuck at sleepDebtCalculator

My code:

const getSleepHours = (day) => {
switch(day){
case ‘monday’:
return 8;
case ‘tuesday’:
return 8;
case ‘wednesday’:
return 8;
case ‘wednesday’:
return 8;
case ‘thursday’:
return 8;
case ‘friday’:
return 8;
case ‘saturday’:
return 8;
case ‘sunday’:
return 8;
default:
console.log(‘Error’);

}

}

const getActualSleepHours = () => {

return getSleepHours(‘monday’) + getSleepHours(‘tuesday’) + getSleepHours(‘wednesday’) + getSleepHours(‘thursday’) + getSleepHours(‘friday’) + getSleepHours(‘saturday’) + getSleepHours(‘sunday’);
}

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

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

if(actualSleepHours === idealSleepHours) {
log.console(‘You got the perfect amount of sleep’);}

else if(actualSleepHours > idealSleepHours){
log.console(‘You got’ + (actualSleepHours - idealSleepHours) + ‘more sleep then you needed’);}

else if(idealSleepHours > actualSleepHours){
log.console(‘You need to get some rest because u got’ + (actualSleepHours - ideaSleepHours) + ‘less sleep than u needed’);}
else {
log.console (‘Error’);
}
}

calculateSleepDebt();

Error: ReferenceError: log is not defined
at calculateSleepDebt
/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/sleepDebtCalculator.js:49:5)
at Object. (/home/ccuser/workspace/javascript_101_Unit_3/Unit_3/sleepDebtCalculator.js:58:1)
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)

I have watched the entire Get Help video and i have tried changing a lot of things but i get the same error for 2 hours now. I need your help.

First thing I noticed, there are two switch cases with the same trigger (case ‘wednesday’:).

case ‘tuesday’:
return 8;
case ‘wednesday’:
return 8;
case ‘wednesday’:
return 8;
case ‘thursday’:
return 8;

Second thing I noticed:

In the calculateSleepDebt function you are logging incorrectly. There are four instances of log.console(...) where it should be console.log(...).

Also might I suggest posting code in future topics using the </> button. This will keep the codes formatting and make it stand out of the normal text.

1 Like

Thank you!

For advice and for pointing out the solution.

1 Like