Created
October 19, 2017 00:08
-
-
Save khayyamsaleem/86f481e995942d0d32853f37da0d858f to your computer and use it in GitHub Desktop.
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
//Get user sleep hours per day | |
function getSleepHours (day) { | |
switch (day) { | |
case'monday': | |
return 8; | |
case'tuesday': | |
return 8; | |
case'wednesday': | |
return 8; | |
case'thursday': | |
return 8; | |
case'friday': | |
return 8; | |
case'saturday': | |
return 10; | |
case'sunday': | |
return 10; | |
} | |
} | |
//Sum all actual days | |
const getActualSleepHours = () => getSleepHours('monday') + getSleepHours('tuesday') + getSleepHours('wednesday') + getSleepHours('thursday') + getSleepHours('friday') + getSleepHours('saturday') + getSleepHours('sunday'); | |
//Get the ideal sleep hours | |
const getIdealSleepHours = () => { | |
let idealHours = 8; | |
// Multiply by 7 days | |
return idealHours * 7; | |
} | |
//calculate the difference on sleeping hours | |
const calculateSleepDebt = () => { | |
let actualSleepHours = getActualSleepHours(); | |
let idealSleepHours = getIdealSleepHours(); | |
//calculate the hour difference | |
const totalAmout = Math.abs(actualSleepHours - idealSleepHours); | |
//compare and get the result | |
if (actualSleepHours === idealSleepHours) { | |
console.log("You have the perfect time!") | |
} else if (actualSleepHours > idealSleepHours) { | |
console.log(`You are sleeping more than you should! You have to sleep less ${totalAmout} hours.`); | |
} else { | |
console.log(`You Should Sleep more! You have to sleep more ${totalAmout} hours.`); | |
} | |
} | |
calculateSleepDebt(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment