Hello! : )
I finished the course and tried to challenge myself by coding the course in a different way.
As you can see I use an array for the sleeptime of each day and a for loop to add the single sleeptimes to have a weekly sleeptime.
The if/else function in calculateSleepDebt() is shorthanded and everything else is like the code before.
It would be amazing, if someone can locate the code with me and please feel free to give me some tips and tricks if you recognize something. ; )
const day = [8,5,7,8,8,8,8];
let hours = 0;
for (let i = 0; i < 7; i++) {
hours += day[i];
};
const getIdealSleepHours = (i) => {
let idealHours = i;
return idealHours * 7;
};
const calculateSleepDebt = () => {
const ideal = getIdealSleepHours(6);
const more = ideal - hours;
const less = hours - ideal;
hours === ideal ? console.log('You\'ve slept good!')
: hours < ideal ? console.log(`Try to sleep ${more} hours more.`)
: console.log(`Try to sleep ${less} hours less.`);
};
console.log(calculateSleepDebt());