Advertisement
Iv555

Untitled

Feb 26th, 2023
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. function bitcoinMining(gramsEachDay) {
  2. const bitcoinPrice = 11949.16;
  3. const gramGoldPrice = 67.51;
  4. let currentAmount = 0;
  5. let bitcoinsCount = 0;
  6. let daysCount = 0;
  7. let dayFirstBitCoin = 0;
  8.  
  9. for (let grams of gramsEachDay) {
  10. daysCount++;
  11. if (daysCount % 3 === 0) {
  12. grams *= 0.70;
  13. }
  14. currentAmount += grams * gramGoldPrice;
  15.  
  16. while (currentAmount >= bitcoinPrice) {
  17. currentAmount -= bitcoinPrice;
  18. bitcoinsCount++;
  19. if (bitcoinsCount === 1) {
  20. dayFirstBitCoin = daysCount;
  21. }
  22. }
  23.  
  24. }
  25. let output = `Bought bitcoins: ${bitcoinsCount}\n`;
  26. if (bitcoinsCount !== 0) {
  27. output += `Day of the first purchased bitcoin: ${dayFirstBitCoin}\n`;
  28. }
  29. output += `Left money: ${currentAmount.toFixed(2)} lv.`;
  30. console.log(output);
  31. }
  32.  
  33. bitcoinMining([100, 200, 300]);
  34. bitcoinMining([50, 100]);
  35. bitcoinMining([3124.15, 504.212, 2511.124]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement