Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onTimeForTheExam(input) {
- let hourExam = Number(input[0]);
- let minuteExam = Number(input[1]);
- let arriveHours = Number(input[2]);
- let arriveMinutes = Number(input[3]);
- let timeExam = hourExam * 60 + minuteExam;
- let timeArrive = arriveHours * 60 + arriveMinutes;
- let difference = Math.abs(timeArrive - timeExam);
- let hour = Math.floor(difference / 60);
- let min = difference % 60;
- if (timeExam < timeArrive) {
- console.log(`Late`);
- if (difference >= 60) {
- if (min < 10) {
- console.log(`${hour}:0${min} hours after the start`);
- } else {
- console.log(`${hour}:${min} hours after the start`);
- }
- } else {
- console.log(`${difference} minutes after the start`);
- }
- } else if (timeArrive === timeExam || timeExam - timeArrive <= 30) {
- console.log(`On time`);
- if (difference !== 0) {
- console.log(`${difference} minutes before the start`);
- }
- } else {
- console.log(`Early`);
- if (difference >= 60) {
- if (min < 10) {
- console.log(`${hour}:0${min} hours before the start`);
- } else {
- console.log(`${hour}:${min} hours before the start`);
- }
- } else {
- console.log(`${difference} minutes before the start`);
- }
- }
- }
- onTimeForTheExam(["9", "30", "9", "50"])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement