Advertisement
vladovip

Black Flag JS FUND MIDEX PREP

Aug 19th, 2022
584
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function flag(input) {
  2.     let days = Number(input.shift());
  3.     //console.log(days);
  4.     let plunderForDay = Number(input.shift());
  5.     //console.log(plunderForDay);
  6.     let expectedPlunder = Number(input.shift());
  7.     //console.log(expectedPlunder);
  8.     let total= 0;
  9.     for (let i = 1; i <= days; i++) {
  10.         total += plunderForDay;
  11.         if (i % 3 === 0) {
  12.             total += plunderForDay * 0.5;
  13.         }
  14.         if (i % 5 === 0) {
  15.             total -= total * 0.3;
  16.         }
  17.     }
  18.     if (total >= expectedPlunder) {
  19.         console.log(`Ahoy! ${total.toFixed(2)} plunder gained.`);
  20.     } else {
  21.         let percentage = total / expectedPlunder * 100;
  22.         console.log(`Collected only ${percentage.toFixed(2)}% of the plunder.`);
  23.     }
  24. }
  25.  
  26. flag (["5",
  27. "40",
  28. "100"]);
  29.  
  30. console.log(`***********`);
  31.  
  32. flag  (["10",
  33. "20",
  34. "380"]);
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement