Sleep Debt Calculator Idea

This is pretty simple but I just wanted to share. I thought the code would be more useful/reusable if it took parameters instead of having pre-assigned values for each of the days.

sleepDebtCalculator = (m,t,w,th,f,sa,su,ideal) => {
let actual = m+t+w+th+f+sa+su;
let idealHours = ideal * 7;
let result = idealHours - actual;
if (result > 0) {
return You got ${result} hour(s) less sleep than you need this week. Get some rest.;
} else {
return You got enough sleep this week. Great job!
}

I figure you could have input boxes for each day and your ideal hours and then feed those into the function. Anyway, just felt proud of figuring something out and wanted to share.

1 Like