Advertisement
Spocoman

Exam Schedule

Oct 12th, 2023
1,068
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function examSchedule(input) {
  2.     let hours = Number(input[0]);
  3.     let minutes = Number(input[1]);
  4.     let dayPart = input[2];
  5.     let hoursAdded = Number(input[3]);
  6.     let minutesAdded = Number(input[4]);
  7.  
  8.     let result = (hours + hoursAdded) * 60 + minutes + minutesAdded;
  9.     let totalHours = parseInt(result / 60 % 24);
  10.     let totalMinutes = result % 60;
  11.  
  12.     dayPart = totalHours >= 12 ? (dayPart == "AM" ? "PM" : "AM") : dayPart;
  13.     totalHours -= totalHours > 12 ? 12 : 0;
  14.  
  15.     console.log(`${totalHours.toString().padStart(2, '0')}:${totalMinutes.toString().padStart(2, '0')}:${dayPart}`);
  16.  
  17.     return;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement