Advertisement
ShadowEmbrace

Time for Walk

Jan 22nd, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(steps, footprintLength, speed) {
  2.     let s = +steps * +footprintLength; //m
  3.     let time = (s / ((speed * 1000) / 3600)) + Math.floor(s / 500) * 60;
  4.     let sec = Math.round(time % 60);
  5.     let min = Math.floor(time / 60) % 60;
  6.     let hours = Math.floor(time / 60 / 60) % 60;
  7.  
  8.     console.log(formatTheOutput(hours, min, sec));
  9.  
  10.     function formatTheOutput(hours, min, sec) {
  11.         if (hours < 10) {
  12.             hours = '0' + hours;
  13.         }
  14.         if (min < 10) {
  15.             min = '0' + min;
  16.         }
  17.         if (sec < 10) {
  18.             sec = '0' + sec;
  19.         }
  20.         time = `${hours}:${min}:${sec}`;
  21.         return time;
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement