Advertisement
Spocoman

Running In The Park

Sep 24th, 2023
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function runningInThePark(input) {
  2.     let totalMinutes = 0, totalDistance = 0, totalCalories = 0;
  3.     let n = Number(input[0]);
  4.  
  5.     for (let i = 1; i < n * 3; i += 3) {
  6.         let dayMinutes = Number(input[i]);
  7.         let dayDistance = Number(input[i + 1]);
  8.         let distanceUnit = input[i + 2];
  9.         if (distanceUnit == "m")
  10.             dayDistance *= 0.001;
  11.  
  12.         totalMinutes += dayMinutes;
  13.         totalDistance += dayDistance;
  14.         totalCalories += dayMinutes * 400 / 20;
  15.     }
  16.  
  17.     console.log(`He ran ${totalDistance.toFixed(2)}km for ${totalMinutes} minutes and burned ${totalCalories} calories.`);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement