Advertisement
Todorov_Stanimir

09. On Time for the Exam

Apr 23rd, 2020
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function student (...input) {
  2.  
  3.     let hourOfExamen=Number(input.shift());
  4.     let minuteOfExamen=Number(input.shift());
  5.     let hourOfArraving=Number(input.shift());
  6.     let minuteofArraving=Number(input.shift());
  7.  
  8.     let timeOfExamen=hourOfExamen*60+minuteOfExamen;
  9.     let timeOfArriving=hourOfArraving*60+minuteofArraving;
  10.     let time=timeOfExamen-timeOfArriving;
  11.     let differenthour=Math.abs(~~(time/60));
  12.     let differentminutes=Math.abs(time % 60);
  13.    
  14.     if (differenthour>0 && differentminutes<10) {
  15.         differentminutes='0'+differentminutes
  16.     }
  17.  
  18.     if (time==0) {
  19.         console.log('On time');
  20.     } else if (time>0 && time<=30) {
  21.         console.log('On time');
  22.         console.log(`${differentminutes} minutes before the start`)
  23.  
  24.     } else if (time>30 && time<=59){
  25.         console.log('Early');
  26.         console.log(`${differentminutes} minutes before the start`);
  27.     } else if (time>59) {
  28.         console.log('Early');
  29.         console.log(`${differenthour}:${differentminutes} hours before the start`);
  30.     }
  31.     else if (time>=-59 && time<0) {
  32.         console.log('Late');
  33.         console.log(`${differentminutes} minutes after the start`);
  34.     } else if (time<-59) {
  35.         console.log('Late');
  36.         console.log(`${differenthour}:${differentminutes} hours after the start`);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement