Hey,
I’m doing the Web Development course and I’m stuck on the Sleep Debt Calculator. I’m new with JavaScript and I really can’t get any further. When I click on save I get:
8
52.5
You got NaN hour(s) sleep. What is wrong with you go back to bed!
The entire script look like this:
const getSleepHours = day => {
switch (day) {
case 'monday':
return 8
break;
case 'tuesday':
return 5
break;
case 'wednesday':
return 7
break;
case 'thursday':
return 7
break;
case 'friday':
return 7
break;
case 'saturday':
return 9
break;
case 'sunday':
return 9
}
};
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;
};
const calculateSleepDebt = () => {
const actualSleepHours = getActualSleepHours();
const idealSleepHours = getIdealSleepHours ();
if (actualSleepHours === idealSleepHours) {
console.log('You got ' + (idealSleepHours - actualSleepHours) + ' hour(s) less sleep than you needed this week. Get some rest.');
} else if (actualSleepHours < idealSleepHours) {
console.log('You got ' + (idealSleepHours - actualSleepHours) + ' hour(s) sleep that you really needed. Enjoy the day.');
} else {
console.log('You got ' + (idealSleepHours - actualSleepHours) + ' hour(s) sleep. What is wrong with you go back to bed!');
}
};
console.log(getSleepHours('monday'));
console.log(getIdealSleepHours());
calculateSleepDebt();
I appreciate any type of help I can get
Best