Created
July 28, 2019 09:03
-
-
Save debonx/d7e7f1a099c1a351f23e178a821bef49 to your computer and use it in GitHub Desktop.
Javascript ES6 basic script to calculate sleep hours.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getSleepHours = day => 8; | |
const getActualSleepHours = () => getSleepHours('Monday') + getSleepHours('Tuesday') + getSleepHours('Wednesday') + getSleepHours('Thursday') + getSleepHours('Friday') + getSleepHours('Saturday') + getSleepHours('Sunday'); | |
const getIdealSleepHours = () => { | |
let idealHours = 8; | |
return idealHours * 7; | |
} | |
const calculateSleepDebt = () => { | |
let actualSleepHours = getActualSleepHours(); | |
let idealSleepHours = getIdealSleepHours(); | |
if( actualSleepHours === idealSleepHours ){ | |
console.log('You should be perfectly rested with '+ actualSleepHours); | |
} else if( actualSleepHours > idealSleepHours ) { | |
console.log('Wake up dude. You slept '+ (actualSleepHours - idealSleepHours) +' hours.'); | |
} else { | |
console.log('Rest more. You still need '+ (idealSleepHours - actualSleepHours) +' hours.') | |
} | |
} | |
calculateSleepDebt(); | |
//console.log(getIdealSleepHours()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment