Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- function bitcoinMining(arr) {
- let bitcoin = 11949.16;
- let gold = 67.51;
- let bitcoinValueInGold = bitcoin / gold;
- let bitcoinBought = false;
- let bitcoinsMined = 0;
- let firstBitcoinDay;
- let i = 0;
- let day = 0;
- let minedTotal = 0;
- while (i < arr.length) {
- let minedToday = arr[i];
- day++;
- if (day === 3) {
- minedToday -= minedToday * 0.3;
- day = 0;
- }
- minedTotal += minedToday;
- //Can we afford Bitcoin
- if (minedTotal >= bitcoinValueInGold) {
- let bitcoins = Math.floor(minedTotal / bitcoinValueInGold);
- minedTotal -= bitcoinValueInGold * bitcoins;
- bitcoinsMined += bitcoins;
- bitcoinBought = true;
- !firstBitcoinDay ? firstBitcoinDay = day : null;
- }
- i++;
- }
- let moneyLeft = minedTotal * gold;
- //Output
- console.log(`Bought bitcoins: ${bitcoinsMined}`);
- bitcoinBought ? console.log(`Day of the first purchased bitcoin: ${firstBitcoinDay}`) : null;
- console.log(`Left money: ${moneyLeft.toFixed(2)} lv.`);
- }
- bitcoinMining([3124.15, 504.212, 2511.124, 333]);
Add Comment
Please, Sign In to add comment