Advertisement
-Enigmos-

workout.js

Oct 25th, 2021
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function workout(input) {
  2.     let index = 0;
  3.     let days = Number(input[index]);
  4.     index++;
  5.     let startDistance = Number(input[index]);
  6.     index++;
  7.     let distance = startDistance;
  8.  
  9.     for (let i = 0; i < days; i++) {
  10.         let dailyNormInc = Number(input[index]) / 100;
  11.         index++;
  12.         startDistance += (startDistance * dailyNormInc);
  13.         distance += startDistance;
  14.     }
  15.  
  16.     if (distance >= 1000) {
  17.         console.log(`You've done a great job running ${Math.ceil(distance - 1000)} more kilometers!`);
  18.    } else {
  19.        console.log(`Sorry Mrs. Ivanova, you need to run ${Math.ceil(1000 - distance)} more kilometers`);
  20.    }
  21. }
  22.  
  23. workout(["4", "100", "30", "50", "60", "80"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement