Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onTimeForExam(hourExam, minExam, hourSchool, minSchool) {
- hourExam = +(hourExam);
- minExam = +(minExam);
- hourSchool = +(hourSchool);
- minSchool = +(minSchool);
- let examInMins = hourExam * 60 + minExam;
- let arrivalMins = hourSchool * 60 + minSchool;
- let diff = examInMins - arrivalMins;
- if (diff < 0) {
- console.log("Late");
- if (diff > -60) {
- console.log(`${Math.abs(diff)} minutes after the start`);
- }
- else {
- let hours = (Math.floor(Math.abs(diff) / 60));
- let min = Math.abs(diff % 60);
- if (min < 10) {
- console.log(`${hours}:0${min} hours after the start`);
- }
- else {
- console.log(`${hours}:${min} hours after the start`);
- }
- }
- }
- else if (diff <= 30) {
- console.log("On Time");
- if (diff > 0) {
- console.log(`${diff} minutes before the start`);
- }
- }
- else
- {
- console.log("Early");
- if (diff < 60) {
- console.log(`${diff} minutes before the start`);
- }
- else
- {
- let hours = Math.floor(diff / 60);
- let min = diff % 60;
- if (min < 10) {
- console.log(`${hours}:0${min} hours before the start`);
- }
- else {
- console.log(`${hours}:${min} hours before the start`);
- }
- }
- }
- }
- onTimeForExam(9, 30, 10, 50);
- onTimeForExam(9, 00, 8, 30);
- onTimeForExam(16, 00, 15, 00);
- onTimeForExam(9, 00, 9, 00);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement