Petar_Matev

Untitled

Feb 1st, 2024
872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function exam (input) {
  2.   let hourOfExam = parseInt(input[0]);
  3.   let minuteOfExam = parseInt(input[1]);
  4.   let hourOfArrival = parseInt(input[2]);
  5.   let minuteOfArrival = parseInt(input[3]);
  6.  
  7.   let ExamTime = (hourOfExam * 60) + minuteOfExam;
  8.   let ArrivalTime = (hourOfArrival * 60) + minuteOfArrival;
  9.  
  10.   let diff = ExamTime - ArrivalTime;
  11.  
  12.   // Case 1: Where student is on time for this exam
  13.  
  14.   if (diff >= 0) {
  15.     if (diff <= 30) {
  16.       console.log("On Time")
  17.       if (diff <= 30 && diff != 0) {
  18.         console.log(`${diff} minutes before the start`)
  19.       }
  20.     } else if (diff > 30) {
  21.  
  22.       // Case 2: Where student is early for this exam
  23.  
  24.       console.log("Early")
  25.       if (diff < 60) {
  26.         console.log(`${diff} minutes before the start`)
  27.       } else {
  28.         let hour = Math.floor(diff / 60);
  29.         let minutes = diff % 60;
  30.         if (minutes <= 9) {
  31.           console.log(`${hour}:0${minutes} hours before the start`)
  32.         } else {
  33.           console.log(`${hour}:${minutes} hours before the start`)
  34.         }
  35.         }
  36.       }
  37.     } else {
  38.  
  39.       // Case 3: Where student is late for this exam
  40.  
  41.       console.log("Late")
  42.       let positiveDiff = diff * -1
  43.       if (positiveDiff <= 59) {
  44.         console.log(`${positiveDiff} minutes after the start`)
  45.       } else {
  46.         let hour = Math.floor(positiveDiff / 60);
  47.         let minutes = positiveDiff % 60;
  48.         if (minutes <= 9) {
  49.           console.log(`${hour}:0${minutes} hours after the start`)
  50.         } else {
  51.           console.log(`${hour}:${minutes} hours after the start`)
  52.       }
  53.     }
  54.   }
  55. }  
Advertisement
Add Comment
Please, Sign In to add comment