Advertisement
Spocoman

03. Time + 15 Minutes

Dec 16th, 2021 (edited)
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function timePlus15(input) {
  2.     let inputHours = Number(input[0]);
  3.     let inputMinutes = Number(input[1]);
  4.     let totalMinutes = inputHours * 60 + inputMinutes + 15;
  5.     let hours = Math.floor(totalMinutes / 60) % 24;
  6.     //let hours = parseInt(totalMinutes / 60) % 24;
  7.     let minutes = totalMinutes % 60;
  8.  
  9.     // a) РЕШЕНИЕ С IF-ELSE:
  10.     if (minutes < 10) {
  11.         console.log(`${hours}:0${minutes}`);
  12.     } else {
  13.         console.log(`${hours}:${minutes}`);
  14.     }
  15.  
  16.     //b) РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
  17.     console.log(`${hours}:${minutes % 60 < 10? '0' : ''}${minutes}`);
  18.  
  19.     //c) РЕШЕНИЕ С МЕТОДИТЕ toString() и padStart():
  20.     console.log(`${hours}:${minutes.toString().padStart(2, '0')}`);
  21. }
  22.  
  23. ИЛИ ЛЕКО ТАРИКАТСКАТА:)
  24.  
  25. function timePlus15(input) {
  26.     let totalMinutes = Number(input[0]) * 60 + Number(input[1]) + 15;
  27.  
  28.     console.log(`${parseInt(totalMinutes / 60) % 24}:${(totalMinutes % 60).toString().padStart(2, '0')}`);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement