Advertisement
Guest User

Untitled

a guest
Apr 16th, 2020
1,424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. function exam(examHour, examMin, arriveHour, arriveMin) {
  2.  
  3. examHour = Number(examHour);
  4. examMin = Number(examMin);
  5. arriveHour = Number(arriveHour);
  6. arriveMin = Number(arriveMin);
  7.  
  8. let examTime =(examHour * 60) + examMin;
  9. let arrivalTime =(arriveHour * 60) + arriveMin;
  10.  
  11. let timeDifference = examTime - arrivalTime;
  12.  
  13. let earlyHour;
  14. let earlyMin;
  15. let lateHour;
  16. let lateMin;
  17.  
  18.  
  19. if (timeDifference >= 0 && timeDifference <= 30) { // on time
  20.  
  21. if (timeDifference == 0){
  22. console.log("On time");
  23.  
  24. } else {
  25. console.log("On time");
  26. console.log(`${timeDifference} minutes before the start`);
  27. }
  28.  
  29. }
  30.  
  31. else if (timeDifference > 30 ) { // Early
  32.  
  33. earlyHour = Math.floor(timeDifference / 60);
  34. earlyMin = timeDifference % 60;
  35.  
  36.  
  37. if (timeDifference > 30 && timeDifference <= 59) {
  38. console.log("Early");
  39. console.log(`${timeDifference} minutes before the start`);
  40. }
  41. else if (timeDifference == 60){
  42.  
  43. console.log("Early");
  44. console.log(`${earlyHour}:0${earlyMin} hours before the start`);
  45. }
  46. else {
  47.  
  48. console.log("Early");
  49. console.log(`${earlyHour}:${earlyMin} hours before the start`);
  50. }
  51.  
  52. }
  53.  
  54. else { // Late
  55.  
  56. timeDifference = Math.abs(timeDifference);
  57. lateHour = Math.floor(timeDifference / 60);
  58. lateMin = timeDifference % 60;
  59.  
  60. if (timeDifference <= 59) {
  61. console.log("Late");
  62. console.log(`${timeDifference} minutes after the start`);
  63.  
  64. }
  65. else if (timeDifference == 60){
  66.  
  67. console.log("Late");
  68. console.log(`${lateHour}:0${lateMin} hours after the start`);
  69. }
  70. else {
  71. console.log("Late");
  72. console.log(`${lateHour}:${lateMin} hours after the start`);
  73.  
  74. }
  75.  
  76.  
  77.  
  78. }
  79.  
  80.  
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement