vikkktor

timeExam

May 23rd, 2021 (edited)
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function timeExam(input) {
  2.     let hourExamStart = Number(input[0]);
  3.     let minExamStart = Number(input[1]);
  4.     let hourArrive = Number(input[2]);
  5.     let minArrive = Number(input[3]);
  6.    
  7.     let timeExam = hourExamStart * 60 + minExamStart;
  8.     let timeArrive = hourArrive * 60 + minArrive;
  9.  
  10.     if (timeArrive > timeExam) {
  11.         console.log("Late");
  12.  
  13.         if (timeArrive - timeExam < 60) {
  14.             console.log(`${timeArrive - timeExam} minutes after the start`);
  15.  
  16.         } else {
  17.             let diff = timeArrive - timeExam;
  18.             let h = Math.floor(diff / 60);
  19.             let m = diff % 60;
  20.             if (m < 10) {
  21.                 console.log(`${h}:0${m} hours after the start`);
  22.             } else {
  23.                 console.log(`${h}:${m} hours after the start`);
  24.             }
  25.         }
  26.  
  27.     } else if (timeArrive <= timeExam && timeExam - timeArrive <= 30) {
  28.         console.log("On time");
  29.         if (timeExam - timeArrive !== 0) {
  30.             console.log(`${timeExam - timeArrive} minutes before the start`);
  31.         }
  32.  
  33.     } else {
  34.         console.log("Early");
  35.         let diff = timeExam - timeArrive;
  36.         let h = Math.floor(diff / 60);
  37.         let m = diff % 60;
  38.         if ( h === 0) {
  39.             console.log(`${m} minutes before the start`);
  40.         }
  41.         if (diff<60) {
  42.             console.log(`${diff} minutes before the start`);
  43.         } else if (m < 10) {
  44.             console.log(`${h}:0${m} hours before the start`);
  45.         } else {
  46.             console.log(`${h}:${m} hours before the start`);
  47.         }
  48.     }
  49.  
  50. }
Add Comment
Please, Sign In to add comment