-
Notifications
You must be signed in to change notification settings - Fork 0
/
SleepDebt.js
49 lines (41 loc) · 1.68 KB
/
SleepDebt.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
// set hours per day of week
const getSleepHours = (day) => {
if (day === 'monday' || day === 'tuesday') {
return 10;
} else if (day === 'wednesday') {
return 9;
} else if (day === 'thursday' || day ==='friday') {
return 8;
} else if (day === 'saturday' || day === 'sunday') {
return 7;
}
}
console.log(`You slept ${getSleepHours('sunday')} hours.`);
// total hours slept
const getActualSleepHours = () => {
return getSleepHours('monday') + getSleepHours('tuesday') + getSleepHours('wednesday') + getSleepHours('thursday') + getSleepHours('friday') + getSleepHours('saturday') + getSleepHours('sunday');
}
console.log(`This week, you slept ${getActualSleepHours()} hours.`);
// ideal hours slept
const getIdealSleepHours = () => {
let idealHours = 9;
return idealHours*7;
}
console.log(`Ideally, you want to get ${getIdealSleepHours()} hours of sleep.`);
// sleep debt
const calculateSleepDebt = () => {
let actualSleepHours = getActualSleepHours();
let idealSleepHours = getIdealSleepHours();
if (actualSleepHours === idealSleepHours) {
console.log(`You' are caught up on sleep'. Good job!`);
} else if (actualSleepHours > idealSleepHours) {
let calculateSleepDebt = actualSleepHours - idealSleepHours;
console.log(`You have overslept by ${calculateSleepDebt}.`);
return calculateSleepDebt;
} else if (actualSleepHours < idealSleepHours) {
let calculateSleepDebt = idealSleepHours - actualSleepHours;
console.log(`You have not slept enough. Sleep ${calculateSleepDebt} to feel better.`);
return calculateSleepDebt;
}
}
calculateSleepDebt();