marian74

Untitled

May 19th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function bitcoinMining(arr) {
  2.     let allMoney = 0;
  3.     let bitcoins = 0;
  4.     let bitcoinPrice = 11949.16;
  5.     let dayOfBought = 0;
  6.     let counter = 0;
  7.    
  8.     for (let i = 0; i < arr.length; i++) {
  9.         let gold = arr[i];
  10.        
  11.         if ((i + 1) % 3 == 0) {
  12.             gold = gold * 0.7;
  13.         }
  14.         let money = gold * 67.51;
  15.         allMoney += money;
  16.        
  17.         if (allMoney >= bitcoinPrice) {
  18.             let currentBitcoins = Math.floor(allMoney / bitcoinPrice);
  19.             bitcoins += currentBitcoins;
  20.             allMoney -= bitcoinPrice * currentBitcoins;
  21.             counter++;
  22.             if (counter == 1) {
  23.                 dayOfBought = i + 1;
  24.             }
  25.         }
  26.     }
  27.     console.log(`Bought bitcoins: ${bitcoins}`);
  28.     if (bitcoins > 0) {
  29.         console.log(`Day of the first purchased bitcoin: ${dayOfBought}`);
  30.     }
  31.     console.log(`Left money: ${allMoney.toFixed(2)} lv.`);
  32.    
  33. }
Add Comment
Please, Sign In to add comment