Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(examHour, examMinutes, arriveHour, arriveMinutes){
- examHour = Number(examHour);
- examMinutes = Number(examMinutes);
- arriveHour = Number(arriveHour);
- arriveMinutes = Number(arriveMinutes);
- let examInMinutes = examHour * 60 + examMinutes;
- let arriveInMinutes = arriveHour * 60 + arriveMinutes;
- let late = arriveInMinutes - examInMinutes;
- let early = examInMinutes - arriveInMinutes;
- let diff = Math.abs(late);
- let hours = parseInt(diff / 60); // взима целочислената част от делението
- let minutes = diff % 60;
- const zeroPad = (num, places) => String(num).padStart(places, '0')
- //https://stackoverflow.com/questions/2998784/how-to-output-numbers-with-leading-zeros-in-javascript
- if (late > 0){
- console.log(`Late`)
- if (late <= 59){
- console.log(`${late} minutes after the start`)
- }
- else{
- console.log(`${hours}:${zeroPad(minutes, 2)} hours after the start`)
- }
- }
- else if (early >= 0 && early <= 30){
- console.log(`On time`)
- if (early != 0){
- console.log(`${early} minutes before the start`)
- }
- }
- else if (early > 30){
- console.log(`Early`)
- if (early <= 59){
- console.log(`${early} minutes before the start`)
- }
- else{
- console.log(`${hours}:${zeroPad(minutes, 2)} hours before the start`)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement