Advertisement
Spocoman

Workout

Feb 16th, 2022 (edited)
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function workout(input) {
  2.     let days = Number(input[0]);
  3.     let kilometers = Number(input[1]);
  4.     let totalKilometers = kilometers;
  5.  
  6.     for (let i = 2; i < days + 2; i++) {
  7.         let percentage = Number(input[i]);
  8.         kilometers *= (100.0 + percentage) / 100;
  9.         totalKilometers += kilometers;
  10.     }
  11.  
  12.     if (totalKilometers < 1000) {
  13.         console.log(`Sorry Mrs.Ivanova, you need to run ${1000 - Math.floor(totalKilometers)} more kilometers`);
  14.     } else {
  15.         console.log(`You've done a great job running ${Math.ceil(totalKilometers) - 1000} more kilometers!`);
  16.    }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement