Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function examTime([hoursE, minE, hoursA, minA]) {
- [hoursE, minE, hoursA, minA] = [hoursE, minE, hoursA, minA].map(x => parseInt(x));
- let totalMinE = (hoursE * 60) + minE;
- let totalMinA = hoursA * 60 + minA;
- let time = totalMinE - totalMinA;
- let h = parseInt(Math.abs(time) / 60);
- let min = parseInt(Math.abs(time) % 60);
- if (time < 0 && h <= 0) {
- console.log("Late");
- console.log(`${min} minutes after the start`);
- }
- else if (time < 0 && h >= 0 && min < 10) {
- console.log("Late");
- console.log(`${h}:0${min} hours after the start`);
- }
- else if (time < 0 && h >= 0 && min > 10) {
- console.log("Late");
- console.log(`${h}:${min} hours after the start`);
- }
- else if (time == 0)
- console.log("On time");
- else if (time <= 30 ) {
- console.log("On time");
- console.log(`${min} minutes before the start `)
- }
- else if (time > 30 && h <= 0 ) {
- console.log("Early");
- console.log(`${min} minutes before the start`);
- }
- else if (time > 30 && h > 0 && min>=10) {
- console.log("Early");
- console.log(`${h}:${min} hours before the start`);
- }
- else if (time > 30 && h > 0 && min < 10) {
- console.log("Early");
- console.log(`${h}:0${min} hours before the start`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement