georgiev955

task 5

Sep 14th, 2023
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. function timeToWalk(steps, footprintLength, speed) {
  2. let distance = Number(steps) * Number(footprintLength);
  3. let breaksCount = Math.floor(distance / 500);
  4. let distanceInKm = distance / 1000;
  5. let timeForOneKM = 60 / speed;
  6. let totalTime = timeForOneKM * distanceInKm + breaksCount;
  7. let hours = Math.trunc(totalTime / 60);
  8. let minutes = Math.trunc(totalTime - hours * 60);
  9. let seconds = (totalTime - hours * 60 - minutes) * 60;
  10.  
  11. console.log(`${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${Math.ceil(seconds).toString().padStart(2, '0') }`);
  12.  
  13. }
Advertisement
Add Comment
Please, Sign In to add comment