Sleep debt calculator


#1

const getSleepHours = day =>{
switch (day) {
case 0:
day = ‘monday’;
return 8;
case 1:
day = ‘tuesday’;
return 2;
case 2:
day = ‘wednesday’;
return 8;
case 3:
day = ‘thursday’;
return 8;
case 4:
day = ‘friday’;
return 4;
case 5:
day = ‘saturday’;
return 8;
case 6:
day = ‘sunday’;
return 3;

}
};

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

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

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

if (actualSleepHours === idealSleepHours){
	console.log('You got the perfect amount of sleep.')

};

if (actualSleepHours < idealSleepHours){
	console.log('Yeesh. You missed the mark by ' + (idealSleepHours - actualSleepHours) + ' hours. Not enough sleep this week. Maybe take a nap.')

};

		if (actualSleepHours > idealSleepHours){
	console.log('Maybe overdoing it with the sleep thing.')

};

};

calculateSleepDebt();

I am kind of at a loss of what I am doing wrong someone please help?


#2

day is a string, so,

switch (day.toLowerCase()) {
    case 'monday': return 8;
    // ...
    default: return NaN;
}

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.