Advertisement
galink

Untitled

Jul 27th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. function exam([arg1, arg2, arg3, arg4]) {
  2.  
  3. let examHour = Number(arg1);
  4. let exanMin = Number(arg2);
  5. let arriveHour = Number(arg3);
  6. let arriveMin = Number(arg4);
  7.  
  8. let examTime = examHour * 60 + exanMin;
  9. let arriveTime = arriveHour * 60 + arriveMin;
  10.  
  11. let totalMinutesDifference = arriveTime - examTime;
  12. let secondDiff = examTime - arriveTime;
  13.  
  14. if (totalMinutesDifference <= 59 && totalMinutesDifference > 0) {
  15. console.log('Early');
  16. } else if (totalMinutesDifference >= 30) {
  17. console.log('On time');
  18. }
  19.  
  20. if (totalMinutesDifference != 0) {
  21. let hoursDifference = Math.abs(totalMinutesDifference / 60);
  22. let minutesDifference = Math.abs(totalMinutesDifference % 60);
  23.  
  24. if (minutesDifference > 0) {
  25. console.log(minutesDifference + ' minutes before the start');
  26. } else if (hoursDifference) {
  27. console.log(`${hoursDifference}:${minutesDifference}` + ' hours before the start');
  28.  
  29. }
  30. if (totalMinutesDifference < 0) {
  31. console.log(`${minutesDifference}` + ' minutes after the start');
  32. } else {
  33. console.log(`${hoursDifference}:${minutesDifference}` + ' hours after the start');
  34. }
  35.  
  36. }
  37.  
  38. exam(['9', '30', '9', '50']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement