PowerCell46

Bitcoin mining task JS

Nov 5th, 2022
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function bitcoinMining(input) {
  2.     let index = 0;
  3.     let gramsForADay = Number(input[index]);
  4.  
  5.     let bitcoinPrice = 11949.16;
  6.     let gramOfGoldPrice = 67.51;
  7.  
  8.     let currentDay = 0;
  9.     let moneyForTheDay = 0;
  10.     let totalmoney = 0;
  11.     let boughtBitcoins = 0;
  12.     let dayOfTheFirstPurchase = 0;
  13.  
  14.     while (index < input.length) {
  15.         currentDay++;
  16.         moneyForTheDay = gramsForADay * gramOfGoldPrice;
  17.  
  18.         if (currentDay % 3 === 0) {
  19.             moneyForTheDay -= ((moneyForTheDay / 100) * 30);
  20.         }
  21.  
  22.         totalmoney += moneyForTheDay;
  23.  
  24.         if (totalmoney >= bitcoinPrice) {
  25.             boughtBitcoins++;
  26.             totalmoney -= bitcoinPrice;
  27.             if (boughtBitcoins === 1) {
  28.             dayOfTheFirstPurchase = currentDay;
  29.             }
  30.         }
  31.  
  32.         index++;
  33.         gramsForADay = Number(input[index]);
  34.     }
  35.  
  36.     if (totalmoney > bitcoinPrice) {
  37.         while (totalmoney >= bitcoinPrice) {
  38.             totalmoney -= bitcoinPrice;
  39.             boughtBitcoins++;
  40.         }
  41.     }
  42.  
  43.     console.log(`Bought bitcoins: ${boughtBitcoins}`);
  44.     if (boughtBitcoins > 0) {
  45.         console.log(`Day of the first purchased bitcoin: ${dayOfTheFirstPurchase}`);
  46.     }
  47.     console.log(`Left money: ${totalmoney.toFixed(2)} lv.`);
  48. }
Add Comment
Please, Sign In to add comment