-
Notifications
You must be signed in to change notification settings - Fork 0
/
sleepdebtcalculator.js
44 lines (40 loc) · 1.3 KB
/
sleepdebtcalculator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const getSleepHours = day => {
day = day.toLowerCase();
switch (day) {
case 'monday':
return 8;
case 'tuesday':
return 9;
case 'wednesday':
return 7;
case 'thursday':
return 8;
case 'friday':
return 9;
case 'saturday':
return 6;
case 'sunday':
return 10;
}
};
const getActualSleepHours = () => {
return getSleepHours('Monday') + getSleepHours('Tuesday') + getSleepHours('Wednesday') + getSleepHours('Thursday') + getSleepHours('Friday') + getSleepHours('Saturday') + getSleepHours('Sunday');
};
const getIdealSleepHours = () => {
const idealHours = 8;
return idealHours * 7;
};
const calculateSleepDebt = () => {
console.log('You slept ' + getActualSleepHours() + ' hours this week.');
console.log('Ideally, you sleep ' + getIdealSleepHours() + ' hours in a week.')
const actualSleepHours = getActualSleepHours();
const idealSleepHours = getIdealSleepHours();
if (actualSleepHours === idealSleepHours) {
console.log('You have no sleep debt!');
} else if (actualSleepHours > idealSleepHours) {
console.log('You got ' + (getActualSleepHours() - getIdealSleepHours()) + ' hour(s) extra sleep than needed.');
} else {
console.log('You should sleep ' + (getIdealSleepHours() - getActualSleepHours()) + ' hour(s) more.');
}
};
calculateSleepDebt();