Untitled

mail@pastecode.io avatar
unknown
plain_text
25 days ago
1.7 kB
7
Indexable
Never
function onTmeForExam (input){

    let examHour = Number(input[0]);
    let examMinute = Number(input[1]);
    let arrivingHour = Number(input[2]);
    let arrivingMinute = Number(input[3]);

    let examTotalMinutes = examMinute + examHour*60;
    let arrivingTotalMinutes = arrivingMinute + arrivingHour*60;
    let minutesDifference = examTotalMinutes - arrivingTotalMinutes;

    if( minutesDifference<= 30 && minutesDifference >=0){
        console.log("On time");
    } else if(minutesDifference> 30 ){
        console.log("Early");
        } else if(minutesDifference < 0) {
        console.log("Late");
    }

    if(minutesDifference >= 1 && minutesDifference < 60){
        console.log(`${minutesDifference} minutes before the start`)
    } else if(minutesDifference >= 60){
        let hoursEarlier = Math.floor(minutesDifference/60);
        let minutesEarlier = minutesDifference % 60;
        if (minutesEarlier <10){
            console.log(`${hoursEarlier}:0${minutesEarlier} hours before the start`);
        } else {
            console.log(`${hoursEarlier}:${minutesEarlier} hours before the start`);
        }
        } else if (minutesDifference <= -1 && minutesDifference > -60){
        console.log(`${-minutesDifference} minutes after the start`)
    } else if ( minutesDifference <= -60){
        let hoursLate = Math.floor(-minutesDifference/60);
        let minutesLate = -minutesDifference%60;
        if (minutesLate <10){
            console.log(`${hoursLate}:0${minutesLate} hours after the start`);
        } else {
            console.log(`${hoursLate}:${minutesLate} hours after the start`);
        }
    }
}
Leave a Comment