Skip to content

Instantly share code, notes, and snippets.

@Vincent-gv
Last active November 5, 2018 11:44
Show Gist options
  • Save Vincent-gv/2b27c02e183ee9c55263d9cce859a62d to your computer and use it in GitHub Desktop.
Save Vincent-gv/2b27c02e183ee9c55263d9cce859a62d to your computer and use it in GitHub Desktop.
Sleep Debt Calculator
const getSleepHours = day => {
if (day === 'lundi') {return 8;}
if (day === 'mardi') {return 7;}
if (day === 'mercredi') {return 6;}
if (day === 'jeudi') {return 5;}
if (day === 'vendredi') {return 10;}
if (day === 'samedi') {return 9;}
if (day === 'dimanche') {return 13;}
};
const getActualSleepHours = () =>
getSleepHours('lundi') + getSleepHours('mardi') + getSleepHours('mercredi') + getSleepHours('jeudi') + getSleepHours('vendredi') + getSleepHours('samedi') + getSleepHours('dimanche');
const getIdealSleepHours = () => {
const idealHours = 8;
return idealHours*7;
};
const calculateSleepDebt = () => {
const actualSleepHours = getActualSleepHours();
const idealSleepHours = getIdealSleepHours();
if (actualSleepHours===idealSleepHours) {console.log('You\'ve got ' + idealSleepHours + ' hours of sleep. Perfect amount of sleep.')}
if (actualSleepHours>idealSleepHours) {console.log('You sleep ' + (actualSleepHours - idealSleepHours) + ' hours more than needed')}
if (actualSleepHours<idealSleepHours) {
console.log('You got ' + (idealSleepHours - actualSleepHours) + ' hour(s) less sleep than you needed this week. Get some rest.');
}
};
calculateSleepDebt();
@Vincent-gv
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment