Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onTimeForTheExam(input) {
- let hourExam = parseInt(input[0]);
- let minuteExam = parseInt(input[1]);
- let hoursStudent = parseInt(input[2]);
- let minuteStudent = parseInt(input[3]);
- let examMinutes = hourExam * 60 + minuteExam;
- let studentMinutes = hoursStudent * 60 + minuteStudent;
- let time = Math.abs(studentMinutes - examMinutes);
- if (studentMinutes > examMinutes) {
- console.log("Late");
- if (time < 60) {
- console.log(`${time} minutes after the start`);
- } else if (time % 60 < 10) {
- console.log(`${parseInt(time / 60)}:0${time % 60} hours after the start`);
- } else {
- console.log(`${parseInt(time / 60)}:${time % 60} hours after the start`);
- }
- } else {
- if (time <= 30) {
- console.log("On time");
- } else {
- console.log("Early");
- }
- if (time !== 0) {
- if (time < 60) {
- console.log(`${time} minutes before the start`);
- } else if (time >= 60 && time % 60 < 10) {
- console.log(`${parseInt(time / 60)}:0${time % 60} hours before the start`);
- } else if (time !== 0) {
- console.log(`${parseInt(time / 60)}:${time % 60} hours before the start`);
- }
- }
- }
- }
- РЕШЕНИЕ СЪС String() И PadStart():
- function onTimeForTheExam(input) {
- let hourExam = parseInt(input[0]);
- let minuteExam = parseInt(input[1]);
- let hoursStudent = parseInt(input[2]);
- let minuteStudent = parseInt(input[3]);
- let examMinutes = hourExam * 60 + minuteExam;
- let studentMinutes = hoursStudent * 60 + minuteStudent;
- let time = Math.abs(studentMinutes - examMinutes);
- if (studentMinutes > examMinutes) {
- console.log("Late");
- if (time < 60) {
- console.log(`${time} minutes after the start`);
- } else {
- console.log(`${parseInt(time / 60)}:${String(time % 60).padStart(2, '0')} hours after the start`);
- }
- } else {
- if (time <= 30) {
- console.log("On time");
- } else {
- console.log("Early");
- }
- if (time !== 0) {
- if (time < 60) {
- console.log(`${time} minutes before the start`);
- } else {
- console.log(`${parseInt(time / 60)}:${String(time % 60).padStart(2, '0')} hours before the start`);
- }
- }
- }
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- function onTimeForTheExam(input) {
- let hourExam = parseInt(input[0]);
- let minuteExam = parseInt(input[1]);
- let hoursStudent = parseInt(input[2]);
- let minuteStudent = parseInt(input[3]);
- let examMinutes = hourExam * 60 + minuteExam;
- let studentMinutes = hoursStudent * 60 + minuteStudent;
- let time = Math.abs(studentMinutes - examMinutes);
- console.log(studentMinutes > examMinutes ? "Late" : time <= 30 ? "On time" : "Early");
- console.log(time !== 0 ? (time < 60 ? `${time} minutes ${studentMinutes > examMinutes ? 'after' : 'before'} the start` :
- `${parseInt(time / 60)}:${time % 60 < 10 ? '0' : ''}${time % 60} hours ${studentMinutes > examMinutes ? 'after' : 'before'} the start`) : '');
- }
- И ЛЕКО ТАРИКАТСКАТА:)
- function onTimeForTheExam(input) {
- let examMinutes = parseInt(input[0]) * 60 + parseInt(input[1]);
- let studentMinutes = parseInt(input[2]) * 60 + parseInt(input[3]);
- let time = Math.abs(studentMinutes - examMinutes);
- console.log(studentMinutes > examMinutes ? "Late" : time <= 30 ? "On time" : "Early");
- console.log(time !== 0 ? (time < 60 ? `${time} minutes ${studentMinutes > examMinutes ? 'after' : 'before'} the start` :
- `${parseInt(time / 60)}:${time % 60 < 10 ? '0' : ''}${time % 60} hours ${studentMinutes > examMinutes ? 'after' : 'before'} the start`) : '');
- }
Add Comment
Please, Sign In to add comment