Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function timePlus15(input) {
- let inputHours = Number(input[0]);
- let inputMinutes = Number(input[1]);
- let totalMinutes = inputHours * 60 + inputMinutes + 15;
- let hours = Math.floor(totalMinutes / 60) % 24;
- //let hours = parseInt(totalMinutes / 60) % 24;
- let minutes = totalMinutes % 60;
- // a) РЕШЕНИЕ С IF-ELSE:
- if (minutes < 10) {
- console.log(`${hours}:0${minutes}`);
- } else {
- console.log(`${hours}:${minutes}`);
- }
- //b) РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- console.log(`${hours}:${minutes % 60 < 10? '0' : ''}${minutes}`);
- //c) РЕШЕНИЕ С МЕТОДИТЕ toString() и padStart():
- console.log(`${hours}:${minutes.toString().padStart(2, '0')}`);
- }
- ИЛИ ЛЕКО ТАРИКАТСКАТА:)
- function timePlus15(input) {
- let totalMinutes = Number(input[0]) * 60 + Number(input[1]) + 15;
- console.log(`${parseInt(totalMinutes / 60) % 24}:${(totalMinutes % 60).toString().padStart(2, '0')}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement