Advertisement
Didart

On Time for the Exam

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