Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created January 14, 2023 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/654aef9c23edb1333bbccd951c8b171d to your computer and use it in GitHub Desktop.
Save codecademydev/654aef9c23edb1333bbccd951c8b171d to your computer and use it in GitHub Desktop.
Codecademy export
const getSleepHours = (day) => {
if (day === 'monday')
return 8
if (day === 'tuesday')
return 8
if (day === 'wednesday')
return 8
if (day === 'thursday')
return 8
if (day === 'friday')
return 8
if (day === 'saturday')
return 12
if (day === 'sunday')
return 12
}
const getActualSleepHours = () =>
getSleepHours('monday') + getSleepHours('tuesday') + getSleepHours('wednesday') + getSleepHours('thursday') + getSleepHours('friday') + getSleepHours('saturday') + getSleepHours('sunday');
// Alternate way || Choose a value for each day
//const getActualSleepHours = () => 8 + 8 + 8 + 8 + 8 + 8 + 8;
const getIdealSleepHours = () => {
const idealHours = 8
return idealHours * 7
};
// Alternate way || Remember to put value in () debt function
//const getIdealSleepHours = idealHours => idealHours * 7;
const calculateSleepDebt = () => {
const actualSleepHours = getActualSleepHours();
const idealSleepHours = getIdealSleepHours();
console.log(actualSleepHours, idealSleepHours)
// console.log(calculateSleepDebt(actualSleepHours, idealSleepHours)) <- this behaves strange and logs to console like a thousand times
if (idealSleepHours === actualSleepHours)
return 'The perfect amount of sleep :)'
if (idealSleepHours > actualSleepHours) {
return ('You should get more rest, You got ' + (actualSleepHours - idealSleepHours) + ' less hours sleep than you should have.')
}
if (idealSleepHours < actualSleepHours) {
return ('More sleep than needed. You got ' + (actualSleepHours - idealSleepHours) + ' more hours sleep than you should have.')
}
}
console.log(calculateSleepDebt())
//calculateSleepDebt(); <- This doesnt work
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment