Btwonu

Bitcoin Mining

May 23rd, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. function bitcoinMining(arr) {
  4.   let bitcoin = 11949.16;
  5.   let gold = 67.51;
  6.   let bitcoinValueInGold = bitcoin / gold;
  7.   let bitcoinBought = false;
  8.   let bitcoinsMined = 0;
  9.   let firstBitcoinDay;
  10.  
  11.  
  12.   let i = 0;
  13.   let day = 0;
  14.   let minedTotal = 0;
  15.  
  16.   while (i < arr.length) {
  17.     let minedToday = arr[i];
  18.     day++;
  19.  
  20.     if (day === 3) {
  21.       minedToday -= minedToday * 0.3;
  22.       day = 0;
  23.     }
  24.  
  25.     minedTotal += minedToday;
  26.  
  27.     //Can we afford Bitcoin
  28.     if (minedTotal >= bitcoinValueInGold) {
  29.       let bitcoins = Math.floor(minedTotal / bitcoinValueInGold);
  30.       minedTotal -= bitcoinValueInGold * bitcoins;
  31.       bitcoinsMined += bitcoins;
  32.       bitcoinBought = true;
  33.      
  34.       !firstBitcoinDay ? firstBitcoinDay = day : null;
  35.     }
  36.  
  37.    
  38.     i++;
  39.   }
  40.  
  41.   let moneyLeft = minedTotal * gold;
  42.  
  43.   //Output
  44.   console.log(`Bought bitcoins: ${bitcoinsMined}`);
  45.   bitcoinBought ? console.log(`Day of the first purchased bitcoin: ${firstBitcoinDay}`) : null;
  46.   console.log(`Left money: ${moneyLeft.toFixed(2)} lv.`);
  47. }
  48.  
  49. bitcoinMining([3124.15, 504.212, 2511.124, 333]);
Add Comment
Please, Sign In to add comment