didkoslawow

Untitled

Jan 14th, 2023
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. function bitcoinMining(gramsOfgold) {
  2. const bitcoinPrice = 11949.16;
  3. const goldPrice = 67.51;
  4.  
  5. let goldMined = null;
  6. let firstBitcoinPurchaseDay = null;
  7. let shiftDay = null;
  8. let totalGoldPrice = null;
  9. let bitcoinPurchased = 0;
  10. let totalShifts = gramsOfgold.length;
  11.  
  12. for (let i = 0; i < totalShifts; i++) {
  13. shiftDay = i + 1;
  14. if (shiftDay % 3 !== 0) {
  15. goldMined = gramsOfgold[i];
  16. } else {
  17. goldMined = gramsOfgold[i] * 0.7;
  18. }
  19. totalGoldPrice += goldMined * goldPrice;
  20.  
  21. while (totalGoldPrice >= bitcoinPrice) {
  22. bitcoinPurchased++;
  23. if (bitcoinPurchased == 1) {
  24. firstBitcoinPurchaseDay = i + 1;
  25. }
  26. totalGoldPrice -= bitcoinPrice;
  27. }
  28. }
  29. console.log(`Bought bitcoins: ${bitcoinPurchased}`);
  30. if (bitcoinPurchased !== 0) {
  31. console.log(
  32. `Day of the first purchased bitcoin: ${firstBitcoinPurchaseDay}`
  33. );
  34. }
  35. console.log(`Left money: ${totalGoldPrice.toFixed(2)} lv.`);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment