Advertisement
vborislavova

09. On Time for the Exam - Conditional Statements Advanced

Feb 24th, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function onTimeForTheExam(input) {
  2. let hourOfExam = Number(input.shift());
  3.     let minutesOfExam = Number(input.shift());
  4.     let hoursOfArriving = Number(input.shift());
  5.     let minutesOfArriving = Number(input.shift());
  6.  
  7.     let totalMinutesOfExam = hourOfExam * 60 + minutesOfExam;
  8.     let totalMinutesOfArriving = hoursOfArriving * 60 + minutesOfArriving;
  9.  
  10.     if (totalMinutesOfArriving > totalMinutesOfExam) {
  11.         console.log("Late");
  12.         let timeLate = totalMinutesOfArriving - totalMinutesOfExam;
  13.         if (timeLate < 60) {
  14.             console.log(`${timeLate} minutes after the start`);
  15.         } else {
  16.             let hours = Math.floor(timeLate / 60);
  17.             let minutes = timeLate % 60;
  18.             if (minutes < 10) {
  19.                 console.log(`${hours}:0${minutes} hours after the start`);
  20.             } else {
  21.                 console.log(`${hours}:${minutes} hours after the start`);
  22.             }
  23.         }
  24.     } else if (totalMinutesOfExam - totalMinutesOfArriving <= 30) {
  25.         console.log("On time");
  26.         let early = totalMinutesOfExam - totalMinutesOfArriving;
  27.         if (early !== 0) {
  28.             console.log(`${early} minutes before the start`);
  29.         }
  30.     } else if (totalMinutesOfExam - totalMinutesOfArriving > 30) {
  31.         console.log("Early");
  32.         let earlyMinutes = totalMinutesOfExam - totalMinutesOfArriving;
  33.         let hours = Math.floor(earlyMinutes / 60);
  34.         let minutes = earlyMinutes % 60;
  35.  
  36.         if (earlyMinutes < 60) {
  37.             console.log(`${minutes} minutes before the start`);
  38.         } else {
  39.             if (minutes < 10) {
  40.                 console.log(`${hours}:0${minutes} hours before the start`);
  41.             } else {
  42.                 console.log(`${hours}:${minutes} hours before the start`);
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement