Hello everyone, tell me, please, where is the error nothing works for me

Programming Task: Adding an Interval to a Time

Conditions:

  1. At the input, the function takes 3 parameters: hours, minutes, the interval in minutes, for which you need to change the time.
  2. It is guaranteed that any of the 3 parameters is a positive integer.
  3. The clock parameter takes a value in the range [0, 23] .
  4. The minute parameter takes a value in the range [0, 59] .
  5. The added interval may be more than 60 minutes.
  6. The transition to the next day should be processed correctly.
  7. The function should return correctly formatted time: 1: 2 -> 01:02
 module.exports = function (hours, minutes, interval) { if ((hours >= 0 && hours <=23) && (minutes >= 0 && minutes <=59)) { var newMinutes = (minutes+interval) % 60 ; var newHours = (hours + math.floor((minutes+interval) / 60)) % 24 ; if ((newHours / 10) < 1 ) { newHours = '0' + newHours; } if ((newMinutes / 10) < 1 ) { newMinutes = '0' + newMinutes; } return `${newHours}:${newMinutes}`; } } 
  • What is the problem? - Suvitruf
  • @suvitruf code does not work at all. 0 passed tests of 13 - Lisa2111
  • And how do you call it and what arguments do you pass? Show this code. - Suvitruf
  • @Suvitruf ** * DOGparam {Number} hours * DOGparam {Number} minutes * DOGparam {Number} interval * DOGreturns {String} * / - Lisa2111
  • 2
    But do the tests support the new javascript buns? Maybe you need to write code on some ES3? - andreymal

2 answers 2

As already said in the comments, the code is working.

 var module = {}; module.exports = function(hours, minutes, interval) { if ((hours >= 0 && hours <= 23) && (minutes >= 0 && minutes <= 59)) { var newMinutes = (minutes + interval) % 60; var newHours = (hours + Math.floor((minutes + interval) / 60)) % 24; if (newHours < 10) { newHours = '0' + newHours; } if (newMinutes < 10) { newMinutes = '0' + newMinutes; } return newHours + ':' + newMinutes } } console.log(module.exports(19, 5, 278)); 

    You can also try a more beautiful solution to this problem using the popular library of moment.js:

     const moment = require('moment'); module.exports = function (hours, minutes, interval) { return moment().hours(hours).minutes(minutes).add(interval, 'minutes').format('HH:mm'); }