-
Notifications
You must be signed in to change notification settings - Fork 0
/
06-Sleep-Debt-Calculator.js
54 lines (50 loc) · 1.46 KB
/
06-Sleep-Debt-Calculator.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
45
46
47
48
49
50
51
52
53
54
// getting hours of sleep per day
const getSleepHours = day => {
switch (day) {
case 'Monday':
return 8;
case 'Tuesday':
return 7;
case 'Wednesday':
return 8;
case 'Thursday':
return 6;
case 'Friday':
return 7;
case 'Saturday':
return 10;
case 'Sunday':
return 8;
}
}
// getting total sleep hours
const getActualSleepHours = () => {
return getSleepHours('Monday') +
getSleepHours('Tuesday') +
getSleepHours('Wednesday') +
getSleepHours('Thursday') +
getSleepHours('Friday') +
getSleepHours('Saturday') +
getSleepHours('Sunday');
}
// getting ideal sleep hours per day
const getIdealSleepHours = () => {
let idealHours = 8;
return idealHours * 7;
}
// calculating sleep debt
const calculateSleepDebt = () => {
const actualSleepHours = getActualSleepHours();
const idealSleepHours = getIdealSleepHours();
if (actualSleepHours === idealSleepHours) {
console.log('You got the perfect amount of sleep.');
} else if (actualSleepHours > idealSleepHours) {
console.log('You got ' + (actualSleepHours - idealSleepHours) + ' hour(s) more sleep than you needed.');
} else if (actualSleepHours < idealSleepHours) {
console.log('You got ' + (idealSleepHours - actualSleepHours) + ' hour(s) less sleep than you needed. Get some rest!');
} else {
console.log('Error!');
}
}
// starting the program
calculateSleepDebt();