Advertisement
Spocoman

01. Black Flag

Feb 7th, 2024
745
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function blackFlag(input) {
  2.     let days = Number(input[0]);
  3.     let dailyPlunder = Number(input[1]);
  4.     let expectedPlunder = Number(input[2]);
  5.     let totalPlunder = 0;
  6.  
  7.     for (let i = 1; i <= days; i++) {
  8.         totalPlunder += dailyPlunder;
  9.         if (i % 3 == 0) {
  10.             totalPlunder += dailyPlunder * 0.5;
  11.         }
  12.         if (i % 5 == 0) {
  13.             totalPlunder *= 0.7;
  14.         }
  15.     }
  16.  
  17.     if (totalPlunder >= expectedPlunder) {
  18.         console.log(`Ahoy! ${totalPlunder.toFixed(2)} plunder gained.`);
  19.     } else {
  20.         console.log(`Collected only ${(totalPlunder / expectedPlunder * 100).toFixed(2)}% of the plunder.`);
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement