Nalini1998 / Project_Public

MIT License
2 stars 0 forks source link

Sleep Debt Calculator Project #504

Closed Nalini1998 closed 1 year ago

Nalini1998 commented 1 year ago

The reference code was put at the comment below

Nalini1998 commented 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()