Closed Nalini1998 closed 1 year ago
/* Completed by @Meow.Nalini98 */
// Use an if/else or switch statement to implement
const getSleepHours = (day) => {
// Use an switch statement to implement
switch(day) {
case 'monday':
return 2;
case 'tuesday':
return 8;
case 'wednesday':
return 4;
case 'thursday':
return 6;
case 'friday':
return 5;
case 'saturday':
return 3;
case 'sunday':
return 9;
}
}
/* Test the function by calling it multiple times */
// console.log(getSleepHours('friday'))
// console.log(getSleepHours('monday'))
// console.log(getSleepHours('tuesday'))
const getActualSleepHours = () => getSleepHours('monday') + getSleepHours('tuesday') + getSleepHours('wednesday')+ getSleepHours('thursday')+ getSleepHours('friday')+ getSleepHours('saturday')+ getSleepHours('sunday')
const getIdealSleepHours = () => {
const idealHours = 8;
return idealHours*7;
}
/* getActualSleepHours */
// console.log(getActualSleepHours());
// console.log(getIdealSleepHours());
const calculateSleepDebt = () => {
const actualSleepHours = getActualSleepHours();
const idealSleepHours = getIdealSleepHours();
if (actualSleepHours===idealSleepHours) {
console.log(`You got ${actualSleepHours} hour(s) this week. It's perfect amount of sleep!`)
} else if (actualSleepHours > idealSleepHours) {
console.log(`You got ${actualSleepHours-idealSleepHours} hour(s) more than you needed this week!`)
} else {
console.log(`You got ${idealSleepHours-actualSleepHours} hour(s) less than you needed this week. You should get some rest!`)
}
}
calculateSleepDebt()
The reference code was put at the comment below
In this project, we’ll calculate if you’re getting enough sleep each week using a sleep debt calculator.
The program will determine the actual and ideal hours of sleep for each night of the last week.
Finally, it will calculate, in hours, how far you are from your weekly sleep goal.