Sleep Debt Calc idealSleepHOurs error

Hi can someone help me im on the sleep debt calc and keep getting a syntax error saying idealSleepHours is not defined.
ive used this code and checked it again the video not sure whats wrong

const getIdealSleepHours = () => {

const idealHours = 7.5;

return idealHours * 7;

};

thanks

Hi can you copy and paste your whole code in a codebyte, also a screenshot of the error so that I can try to help you.

const getSleepHours = day => {

switch (day){
case ‘Monday’:
return 8
break;
case ‘Tuesday’:
return 7
break;
case ‘Wednesday’:
return 8
break;
case ‘Thursday’:
return 5
break;
case ‘Friday’:
return 8
break;
case ‘Saturday’:
return 7
break;
case ‘Sunday’:
return 8
break;
default:
return ‘Error!’
}
};

const getActualSleepHours = () =>
getSleepHours(‘Monday’) +
getSleepHours(‘Tuesday’) +
getSleepHours(‘Wednesday’) +
getSleepHours(‘Thursday’) +
getSleepHours(‘Friday’)+
getSleepHours(‘Saturday’)+
getSleepHours(‘Sunday’);

console.log(getSleepHours(‘Monday’));
console.log(getActualSleepHours());

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

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

if (actualSleepHours === idealSleepHours)
{
condole.log(‘You got the perfect amount of sleep’);
}
else if(actualSleepHours){
console.log(‘You got more sleep than you needed.’);
}
else if (actualSleepHours < idealSleepHours) {
console.log(‘you should get some rest’);
}

else{ console.log(‘something went wrong you should check your code’);
}
};
calculateSleepDebt();

Thank You for your help

Hi @matthewshaw082770225, so first of all you simply forgot to define your idealSleepHours in your calculateSleepDebt() function. Try using let instead of const to define your idealHours variable. Also be careful with the type errors, in your first if statement you wrote condole.log() instead of console.log().
So just add const idealSleepHours = getIdealSleepHours(); to your calculateSleepDebt function and use let idealHours = 7.5; instead of const idealHours = 7.5;.
Let me know if this works for you.

Hi Chris thanks very much for your help

1 Like

No worries, so did you manage to fix it ?