Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created January 9, 2017 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save codecademydev/08230a4dfbcc4ffc7a55b26d47ddb4ee to your computer and use it in GitHub Desktop.
Save codecademydev/08230a4dfbcc4ffc7a55b26d47ddb4ee to your computer and use it in GitHub Desktop.
Codecademy export
function getSleepHours(day) {
var hours=prompt('How many hours of sleep did you get on '+ day + '?');
return(Number(hours));
}
function getActualSleepHours() {
var total = (getSleepHours('Sunday') +
getSleepHours('Monday') +
getSleepHours('Tuesday') +
getSleepHours('Wednesday') +
getSleepHours('Thursday') +
getSleepHours('Friday') +
getSleepHours('Saturday'));
return total;
}
function getIdealSleepHours() {
var idealHours = prompt('How many hours of sleep per night is ideal?');
return Number(idealHours) * 7;
}
function calculatesSleepDebt() {
var actualSleepHours=getActualSleepHours();
var idealSleepHours=getIdealSleepHours();
if (idealSleepHours === actualSleepHours) {
console.log('You got the perfect amount of sleep.');
} else if (idealSleepHours < actualSleepHours) {
console.log('You got too much sleep.');
} else {
console.log('You need to get more sleep.');
}
console.log(' Compared to your ideal number of ' + idealSleepHours + ' sleep hours you got ' + (actualSleepHours-idealSleepHours) + ' hours of sleep.');
}
console.log(calculatesSleepDebt());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment