-
-
Save codecademydev/35bbe463fd023b91b5101e8661efc0d5 to your computer and use it in GitHub Desktop.
Codecademy export
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
const getSleepHours = (day) => { | |
switch(day){ | |
case 'monday' : | |
return 8; | |
break; | |
case 'tuesday' : | |
return 7; | |
break; | |
case 'wednesday' : | |
return 7.5; | |
break; | |
case 'thursday' : | |
return 8; | |
break; | |
case 'friday' : | |
return 6; | |
break; | |
case 'saturday' : | |
return 4; | |
break; | |
case 'sunday' : | |
return 8; | |
break; | |
} | |
}; | |
const getActualSleepHours = () => | |
getSleepHours('monday') + | |
getSleepHours('tuesday') + | |
getSleepHours('wednesday') + | |
getSleepHours('thursday') + | |
getSleepHours('friday') + | |
getSleepHours('saturday') + | |
getSleepHours('sunday'); | |
const getIdealSleepHours = () => { | |
const idealHours = 8; | |
return idealHours * 7; | |
}; | |
console.log(getActualSleepHours()); | |
console.log(getIdealSleepHours()); | |
const calculateSleepDebt = () => { | |
const actualSleepHours = getActualSleepHours(); | |
const idealSleepHours = getIdealSleepHours(); | |
if(actualSleepHours === idealSleepHours){ | |
console.log('Perfect amount of sleep!'); | |
} | |
else if(actualSleepHours > idealSleepHours){ | |
console.log('You got ' + (actualSleepHours - idealSleepHours) + 'more hours sleep than needed') | |
} | |
else { | |
console.log('You got ' + (idealSleepHours - actualSleepHours) + 'less hours of sleep than needed...' ) | |
} | |
} | |
calculateSleepDebt(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment