Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function exam (input) {
- let hourOfExam = parseInt(input[0]);
- let minuteOfExam = parseInt(input[1]);
- let hourOfArrival = parseInt(input[2]);
- let minuteOfArrival = parseInt(input[3]);
- let ExamTime = (hourOfExam * 60) + minuteOfExam;
- let ArrivalTime = (hourOfArrival * 60) + minuteOfArrival;
- let diff = ExamTime - ArrivalTime;
- // Case 1: Where student is on time for this exam
- if (diff >= 0) {
- if (diff <= 30) {
- console.log("On Time")
- if (diff <= 30 && diff != 0) {
- console.log(`${diff} minutes before the start`)
- }
- } else if (diff > 30) {
- // Case 2: Where student is early for this exam
- console.log("Early")
- if (diff < 60) {
- console.log(`${diff} minutes before the start`)
- } else {
- let hour = Math.floor(diff / 60);
- let minutes = diff % 60;
- if (minutes <= 9) {
- console.log(`${hour}:0${minutes} hours before the start`)
- } else {
- console.log(`${hour}:${minutes} hours before the start`)
- }
- }
- }
- } else {
- // Case 3: Where student is late for this exam
- console.log("Late")
- let positiveDiff = diff * -1
- if (positiveDiff <= 59) {
- console.log(`${positiveDiff} minutes after the start`)
- } else {
- let hour = Math.floor(positiveDiff / 60);
- let minutes = positiveDiff % 60;
- if (minutes <= 9) {
- console.log(`${hour}:0${minutes} hours after the start`)
- } else {
- console.log(`${hour}:${minutes} hours after the start`)
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment