Advertisement
Elpida3006

on time

Apr 5th, 2020
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function onTimeForExam(hourExam, minExam, hourSchool, minSchool) {
  2.  
  3.  
  4. hourExam = +(hourExam);
  5. minExam = +(minExam);
  6. hourSchool = +(hourSchool);
  7. minSchool = +(minSchool);
  8.  
  9.  
  10. let examInMins = hourExam * 60 + minExam;
  11. let arrivalMins = hourSchool * 60 + minSchool;
  12. let diff = examInMins - arrivalMins;
  13.  
  14. if (diff < 0) {
  15.     console.log("Late");
  16.     if (diff > -60) {
  17.         console.log(`${Math.abs(diff)} minutes after the start`);
  18.     }
  19.         else {
  20.      
  21.             let hours = (Math.floor(Math.abs(diff) / 60));
  22.             let min = Math.abs(diff % 60);
  23.             if (min < 10) {
  24.                 console.log(`${hours}:0${min} hours after the start`);
  25.                 }
  26.                 else {
  27.                     console.log(`${hours}:${min} hours after the start`);
  28.                 }
  29.         }
  30.     }
  31.  
  32.  
  33.                     else if (diff <= 30) {
  34.                              console.log("On Time");
  35.                              if (diff > 0) {
  36.                                
  37.                                 console.log(`${diff} minutes before the start`);
  38.                              }
  39.                             }
  40. else
  41. {
  42.     console.log("Early");
  43.  
  44.     if (diff < 60) {
  45.     console.log(`${diff} minutes before the start`);
  46.     }
  47.     else  
  48.     {
  49.         let hours = Math.floor(diff / 60);
  50.         let min = diff % 60;
  51.         if (min < 10) {
  52.         console.log(`${hours}:0${min} hours before the start`);
  53.         }
  54.         else {
  55.             console.log(`${hours}:${min} hours before the start`);
  56.         }
  57.     }
  58. }
  59.  
  60.  
  61.  
  62. }
  63. onTimeForExam(9, 30, 10, 50);
  64. onTimeForExam(9, 00, 8, 30);
  65. onTimeForExam(16, 00, 15, 00);
  66. onTimeForExam(9, 00, 9, 00);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement