Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function timeExam(input) {
- let hourExamStart = Number(input[0]);
- let minExamStart = Number(input[1]);
- let hourArrive = Number(input[2]);
- let minArrive = Number(input[3]);
- let timeExam = hourExamStart * 60 + minExamStart;
- let timeArrive = hourArrive * 60 + minArrive;
- if (timeArrive > timeExam) {
- console.log("Late");
- if (timeArrive - timeExam < 60) {
- console.log(`${timeArrive - timeExam} minutes after the start`);
- } else {
- let diff = timeArrive - timeExam;
- let h = Math.floor(diff / 60);
- let m = diff % 60;
- if (m < 10) {
- console.log(`${h}:0${m} hours after the start`);
- } else {
- console.log(`${h}:${m} hours after the start`);
- }
- }
- } else if (timeArrive <= timeExam && timeExam - timeArrive <= 30) {
- console.log("On time");
- if (timeExam - timeArrive !== 0) {
- console.log(`${timeExam - timeArrive} minutes before the start`);
- }
- } else {
- console.log("Early");
- let diff = timeExam - timeArrive;
- let h = Math.floor(diff / 60);
- let m = diff % 60;
- if ( h === 0) {
- console.log(`${m} minutes before the start`);
- }
- if (diff<60) {
- console.log(`${diff} minutes before the start`);
- } else if (m < 10) {
- console.log(`${h}:0${m} hours before the start`);
- } else {
- console.log(`${h}:${m} hours before the start`);
- }
- }
- }
Add Comment
Please, Sign In to add comment