-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions-sleep-debt-calculator.js
More file actions
45 lines (40 loc) · 1.47 KB
/
Copy pathfunctions-sleep-debt-calculator.js
File metadata and controls
45 lines (40 loc) · 1.47 KB
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
const getSleepHours = day => {
if (day === 'monday') {
return 8;
} else if(day === 'tuesday') {
return 13;
} else if (day === 'wednesday') {
return 6;
} else if (day === 'thursday') {
return 12;
} else if (day === 'friday') {
return 9;
} else if (day === 'saturday') {
return 5;
} else if (day === 'sunday') {
return 9;
} else {
return "Error!";
}
};
const getActualSleepHours = () =>
getSleepHours('monday') + getSleepHours('tuesday') + getSleepHours('wednesday') + getSleepHours('thursday') + getSleepHours('friday') + getSleepHours('saturday') + getSleepHours('sunday');
const getIdealSleepHours = () => {
let idealHours = 8;
return idealHours * 7;
};
const calculateSleepDebt = () => {
const actualSleepHours = getActualSleepHours();
const idealSleepHours = getIdealSleepHours();
if(actualSleepHours === idealSleepHours) {
console.log("You've got the perfect amount of sleep!");
} else if(actualSleepHours > idealSleepHours){
console.log("You've got " + (actualSleepHours - idealSleepHours) + " more hours of sleep than needed this week.")
} else if(actualSleepHours < idealSleepHours) {
console.log("You should get some rest, because you slept " + (idealSleepHours - actualSleepHours) + " hours less than you should have this week.")
}
else {
console.log("Error! Something went wrong!")
}
}
calculateSleepDebt();