Last active
October 24, 2020 11:32
-
-
Save RaynZayd/42d0be21be983d5011c51366ff646289 to your computer and use it in GitHub Desktop.
This project calculates if you’re getting enough sleep each week using a sleep debt calculator. The program determines actual and ideal hours of sleep for each night of the last week. It also calculates, in hours, how far you are from your weekly sleep goal.
This file contains 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
/*Sleep Debt Calculator*/ | |
/*This project calculates if you’re getting enough sleep each week using a sleep debt calculator. | |
The program determines actual and ideal hours of sleep for each night of the last week. | |
It also calculates, in hours, how far you are from your weekly sleep goal.*/ | |
//Determins how many hours of sleep you got each night of the week. | |
const getSleepHours = day => { | |
if(day === 'monday'){ | |
return 8; | |
}else if(day === 'tuesday'){ | |
return 8; | |
}else if(day === 'wednesday'){ | |
return 10; | |
}else if(day === 'thursday'){ | |
return 8; | |
}else if(day === 'friday'){ | |
return 8; | |
}else if(day === 'saturday'){ | |
return 9; | |
}else if(day === 'sunday'){ | |
return 8; | |
} | |
} | |
//Test function by calling it multiple times | |
//console.log(getSleepHours('monday')); | |
//console.log(getSleepHours('wednesday')); | |
//console.log(getSleepHours('friday')); | |
//Total sleep hours that you actually slept | |
const getActualSleepHours = () => { | |
return getSleepHours('monday') + | |
getSleepHours('tuesday') + | |
getSleepHours('wednesday')+ | |
getSleepHours('thursday')+ | |
getSleepHours('friday')+ | |
getSleepHours('saturday')+ | |
getSleepHours('sunday'); | |
} | |
//Ideal sleep hours preferred | |
const getIdealSleepHours = () => { | |
var idealHours = 8;//Ideal hours per night | |
return idealHours * 7//Total hours prefered per week | |
} | |
//Testing functions | |
//console.log(getIdealSleepHours()); | |
//console.log(getIdealSleepHours()); | |
//Calculates sleep debt | |
const calculateSleepDebt = () => { | |
actualSleepHours = getActualSleepHours(); | |
idealSleepHours = getIdealSleepHours(); | |
if(actualSleepHours === idealSleepHours){ | |
console.log(`You had the perfect amount of sleep. \n Over Ideal Sleep: ${actualSleepHours - idealSleepHours} \n Under Ideal Sleep: ${idealSleepHours - actualSleepHours}`); | |
}else if(actualSleepHours > idealSleepHours){ | |
console.log(`You slept more than needed. \n Over Ideal Sleep: ${actualSleepHours - idealSleepHours} \n Under Ideal Sleep: ${idealSleepHours - actualSleepHours}`); | |
}else if(actualSleepHours < idealSleepHours){ | |
console.log(`You should get some rest. \n Over Ideal Sleep: ${actualSleepHours - idealSleepHours} \n Under Ideal Sleep: ${idealSleepHours - actualSleepHours}`); | |
}else{ | |
console.log('Unknown!'); | |
} | |
} | |
calculateSleepDebt(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment