Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created January 28, 2021 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codecademydev/35bbe463fd023b91b5101e8661efc0d5 to your computer and use it in GitHub Desktop.
Save codecademydev/35bbe463fd023b91b5101e8661efc0d5 to your computer and use it in GitHub Desktop.
Codecademy export
const getSleepHours = (day) => {
switch(day){
case 'monday' :
return 8;
break;
case 'tuesday' :
return 7;
break;
case 'wednesday' :
return 7.5;
break;
case 'thursday' :
return 8;
break;
case 'friday' :
return 6;
break;
case 'saturday' :
return 4;
break;
case 'sunday' :
return 8;
break;
}
};
const getActualSleepHours = () =>
getSleepHours('monday') +
getSleepHours('tuesday') +
getSleepHours('wednesday') +
getSleepHours('thursday') +
getSleepHours('friday') +
getSleepHours('saturday') +
getSleepHours('sunday');
const getIdealSleepHours = () => {
const idealHours = 8;
return idealHours * 7;
};
console.log(getActualSleepHours());
console.log(getIdealSleepHours());
const calculateSleepDebt = () => {
const actualSleepHours = getActualSleepHours();
const idealSleepHours = getIdealSleepHours();
if(actualSleepHours === idealSleepHours){
console.log('Perfect amount of sleep!');
}
else if(actualSleepHours > idealSleepHours){
console.log('You got ' + (actualSleepHours - idealSleepHours) + 'more hours sleep than needed')
}
else {
console.log('You got ' + (idealSleepHours - actualSleepHours) + 'less hours of sleep than needed...' )
}
}
calculateSleepDebt();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment