Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 1st Function - Determines the sleep Hours per day
- function getSleepHours(day){
- // I will suppose that the hours of sleeping
- // each day of a week is stable for every
- // single week and I am the one that decides
- // for that with specific numbers with this // function
- switch(day){
- case "Monday":
- return 8;
- break;
- case "Tuesday":
- return 7;
- break;
- case "Wednesday":
- return 5;
- break;
- case "Thursday":
- return 6;
- break;
- case "Friday":
- return 8;
- break;
- case "Saturday":
- return 6;
- break;
- case "Sunday":
- return 10;
- break;
- default:
- console.log(day + " is not a name of a week's day...");
- } // End of switch
- }
- // 2nd Function - Calculates the actual hours of sleeping per week
- // Concise way of declaring a function
- const getActualSleepHours = () => { return getSleepHours("Monday") +
- getSleepHours("Tuesday") + getSleepHours("Wednesday") + getSleepHours("Thursday") + getSleepHours("Friday") + getSleepHours("Saturday") + getSleepHours("Sunday")
- };
- // 3rd Function - Calculates the ideal hours of sleeping per week
- function getIdealSleepHours(){
- const idealHours = 8;
- return 7 * idealHours;
- }
- // 4th Function - Calculates the sleep Debt
- function calculateSleepDebt(){
- actualSleepHours = getActualSleepHours();
- idealSleepHours = getIdealSleepHours();
- // If-else-cases
- if(actualSleepHours === idealSleepHours){
- console.log("You got the perfect amount of sleeping this week (" + getIdealSleepHours() + ").");
- }
- else if(actualSleepHours > idealSleepHours){
- console.log("You slept " + actualSleepHours + " hours. It's too much for this week.");
- console.log("You got " + (actualSleepHours-idealSleepHours) + " more than the normal " + getIdealSleepHours() + " hours per week.");
- }
- else{
- console.log("This week you slept " + actualSleepHours + " hours. It's less than the ideal sleep hours needed.");
- console.log("You got " + (idealSleepHours-actualSleepHours) + " less than the normal " + getIdealSleepHours() + " hours per week.");
- }
- }
- // Main part of the project
- calculateSleepDebt();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement