Need help, in cursera task by js, you need to display the correct time, when adding an interval.

module.exports = function(hours, minutes, interval) { if (hours >= 0, hours <= 23, minutes >= 0, minutes <= 59) { if (minutes + interval >= 60) { hours = hours + 1; minutes = (minutes + interval - 60) } else { minutes = minutes + interval }; if (minutes.length = 1) { miutes = '0' + minutes }; return hours + ':' + minutes } else {}; }; 

The bottom line is that I can’t figure out how to do it so that instead of 1, 01 comes to a conclusion. There was a hint on the site:

To perform this task, you may need methods from the global Math object. For example, the floor method.

  • if the interval is minutes, then I would, if I were you, everything that happened would lead to minutes, and then separate the hours. - teran
  • wait and this is the only problem? everything else works? - Igor
  • 2
    return ('00' + hours).slice(-2) + ':' + ('00' + minutes).slice(-2); - Rostyslav Kuzmovych
  • @RostyslavKuzmovych Such content is usually written in response - tutankhamun

3 answers 3

String.prototype.padStart() fills the current string with another string (several times, if necessary) so that the resulting string reaches the specified length. Filling is carried out at the beginning (left) of the current line.

Here is the finished function:

 function padNum(var num) { return num.toString().padStart(2,0); } 

     console.log([0, 1, 9, 10, 59].map(x => ("0"+x).slice(-2)).join(" ")) 

      You can use this function:

       function MakeTwoDigits(num) { if( num >= 0 && num <= 9) { return "0" + num; } else { return "" + num; } }