Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function timeToWalk(steps, footprintLength, speed)
- {
- let distance = steps * footprintLength;
- let breaks = 0;
- for (let index = 500; index < distance + 1; index+= 500) {
- breaks++;
- }
- let time = (distance / 1000) / speed;
- let hr = 0;
- let min = 0;
- let sec = 0;
- //HOURS
- if (time < 1) {
- hr = 0
- }
- else{
- let wholeHrs = time.toString();
- wholeHrs = wholeHrs[0];
- parseInt(wholeHrs);
- hr = wholeHrs;
- time -= wholeHrs;
- }
- //MINUTES
- if (time * 60 < 1) {
- min = 0;
- }
- else{
- min = time*60;
- min = Math.floor(min);
- time -= min/60
- if (min + breaks >= 60) {
- hr++;
- min = min + breaks - 60;
- }
- else
- {
- min += breaks;
- }
- }
- //SECONDS
- sec = time * 3600;
- sec = Math.round(sec);
- console.log(`${('0' + hr).slice(-2)}:${('0' + min).slice(-2)}:${('0' + sec).slice(-2)}`)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement