desito07

On Time for the Exam

Mar 3rd, 2020
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. function Exam(input) {
  2. let startHExam = Number(input.shift());
  3. let startMExam = Number(input.shift());
  4. let arriveH = Number(input.shift());
  5. let arriveM = Number(input.shift());
  6.  
  7. let examTimeInMin = startHExam * 60 + startMExam;
  8. let studentTimeInMin = arriveH * 60 + arriveM;
  9.  
  10. let diff = examTimeInMin - studentTimeInMin;
  11.  
  12. let h = Math.floor(Math.abs(diff) / 60);
  13. let m = Math.abs(diff % 60);
  14.  
  15. if (m < 10) {
  16. m = "0" + m;
  17. }
  18. if (diff < 0) {
  19. console.log("Late");
  20. if (Math.abs(diff) < 60) {
  21. console.log(`${m} minutes after the start`);
  22. } else {
  23. console.log(`${h}:${m} hours after the start`);
  24. }
  25. } else if (diff === 0 || diff <= 30) {
  26. console.log("On time");
  27. if (diff % 60 !== 0) {
  28. console.log(`${diff % 60} minutes before the start`);
  29. }
  30. } else {
  31. console.log("Early");
  32. if (Math.abs(diff) < 60) {
  33. console.log(`${m} minutes before the start`);
  34. } else {
  35. console.log(`${h}:${m} hours before the start`);
  36. }
  37. }
  38. }
  39. Exam(["9", "30", "9", "50"]);
  40. Exam(["9", "00", "8", "30"]);
  41. Exam(["16", "00", "15", "00"]);
  42. Exam(["9", "00", "10", "30"]);
Advertisement
Add Comment
Please, Sign In to add comment