Aliendreamer

timetowalk

Jan 17th, 2019
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function timeToWalk(steps,stepLength,speed){
  2.  
  3.         let distance=(steps*stepLength)/1000;
  4.         let extraRest=Math.floor((distance*1000)/500);
  5.  
  6.         // Hours, minutes and seconds
  7.         let timeInSeconds = Math.ceil((distance / speed) * 60 * 60) + (extraRest * 60);
  8.  
  9.         let hours = Math.floor(timeInSeconds / 3600);
  10.         let mins = Math.floor(timeInSeconds / 60);
  11.         timeInSeconds -= mins * 60;
  12.        
  13.         let result = ('0' + hours).slice(-2) + ':' + ('0' + mins).slice(-2) + ':' + ('0' + timeInSeconds).slice(-2);
  14.     return result;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment