Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. function examTime([hoursE, minE, hoursA, minA]) {
  2.  
  3. [hoursE, minE, hoursA, minA] = [hoursE, minE, hoursA, minA].map(x => parseInt(x));
  4. let totalMinE = (hoursE * 60) + minE;
  5. let totalMinA = hoursA * 60 + minA;
  6. let time = totalMinE - totalMinA;
  7. let h = parseInt(Math.abs(time) / 60);
  8. let min = parseInt(Math.abs(time) % 60);
  9.  
  10. if (time < 0 && h <= 0) {
  11.  
  12. console.log("Late");
  13. console.log(`${min} minutes after the start`);
  14. }
  15. else if (time < 0 && h >= 0 && min < 10) {
  16. console.log("Late");
  17. console.log(`${h}:0${min} hours after the start`);
  18. }
  19. else if (time < 0 && h >= 0 && min > 10) {
  20. console.log("Late");
  21. console.log(`${h}:${min} hours after the start`);
  22. }
  23. else if (time == 0)
  24. console.log("On time");
  25. else if (time <= 30 ) {
  26. console.log("On time");
  27. console.log(`${min} minutes before the start `)
  28. }
  29.  
  30. else if (time > 30 && h <= 0 ) {
  31. console.log("Early");
  32. console.log(`${min} minutes before the start`);
  33.  
  34. }
  35.  
  36. else if (time > 30 && h > 0 && min>=10) {
  37. console.log("Early");
  38. console.log(`${h}:${min} hours before the start`);
  39.  
  40. }
  41. else if (time > 30 && h > 0 && min < 10) {
  42. console.log("Early");
  43. console.log(`${h}:0${min} hours before the start`);
  44.  
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement