Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onTimeForTheExam(input) {
- let hourOfExam = Number(input.shift());
- let minutesOfExam = Number(input.shift());
- let hoursOfArriving = Number(input.shift());
- let minutesOfArriving = Number(input.shift());
- let totalMinutesOfExam = hourOfExam * 60 + minutesOfExam;
- let totalMinutesOfArriving = hoursOfArriving * 60 + minutesOfArriving;
- if (totalMinutesOfArriving > totalMinutesOfExam) {
- console.log("Late");
- let timeLate = totalMinutesOfArriving - totalMinutesOfExam;
- if (timeLate < 60) {
- console.log(`${timeLate} minutes after the start`);
- } else {
- let hours = Math.floor(timeLate / 60);
- let minutes = timeLate % 60;
- if (minutes < 10) {
- console.log(`${hours}:0${minutes} hours after the start`);
- } else {
- console.log(`${hours}:${minutes} hours after the start`);
- }
- }
- } else if (totalMinutesOfExam - totalMinutesOfArriving <= 30) {
- console.log("On time");
- let early = totalMinutesOfExam - totalMinutesOfArriving;
- if (early !== 0) {
- console.log(`${early} minutes before the start`);
- }
- } else if (totalMinutesOfExam - totalMinutesOfArriving > 30) {
- console.log("Early");
- let earlyMinutes = totalMinutesOfExam - totalMinutesOfArriving;
- let hours = Math.floor(earlyMinutes / 60);
- let minutes = earlyMinutes % 60;
- if (earlyMinutes < 60) {
- console.log(`${minutes} minutes before the start`);
- } else {
- if (minutes < 10) {
- console.log(`${hours}:0${minutes} hours before the start`);
- } else {
- console.log(`${hours}:${minutes} hours before the start`);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement