vladovip

JavaScript- BitcoinMining_BasicSyntax_Exercise

Dec 19th, 2021
1,242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arrayShifts) {
  2.  
  3.  
  4.     let totalCollectedMoney = 0;
  5.     let bitcoinPurchased = 0;
  6.     let day = 0;
  7.     let currentDay = 0;
  8.  
  9.  
  10.     for (let i = 0; i < arrayShifts.length; i++) {
  11.  
  12.         let currentGold = arrayShifts[i];
  13.         day++;
  14.  
  15.         if (day % 3 == 0) {
  16.             currentGold *= 0.70;
  17.         }
  18.  
  19.         totalCollectedMoney += (67.51 * currentGold);
  20.  
  21.         if (totalCollectedMoney >= 11949.16) {
  22.             if (currentDay == 0) {
  23.                 currentDay = day;
  24.             }
  25.             bitcoinPurchased += parseInt(totalCollectedMoney / 11949.16);
  26.             totalCollectedMoney -= parseInt(totalCollectedMoney / 11949.16) * 11949.16;
  27.         }
  28.     }
  29.  
  30.     if (bitcoinPurchased >= 1) {
  31.         console.log(`Bought bitcoins: ${bitcoinPurchased}`);
  32.         console.log(`Day of the first purchased bitcoin: ${currentDay}`);
  33.     } else {
  34.         console.log(`Bought bitcoins: ${bitcoinPurchased}`);
  35.     }
  36.     console.log(`Left money: ${totalCollectedMoney.toFixed(2)} lv.`);
  37.  
  38.  
  39. }
  40. solve([3124.15, 504.212, 2511.124]);
  41.  
  42.  
  43. /* 1 Bitcoin =  11949.16 lv ;
  44. 1 g of gold =   67.51 lv.
  45.  
  46. Output:
  47. ·  First line prints the total amount of bought bitcoins:
  48.  "Bought bitcoins: {count}"
  49. ·  Second line prints which day you bought your first bitcoin:
  50.  "Day of the first purchased bitcoin: {day}"
  51. In case you did not purchase any bitcoins, do not print the second line.
  52. ·  Third line prints the amount of money that’s left after the bitcoin purchases rounded by the second digit after the decimal point:
  53.  "Left money: {money} lv."
  54.  
  55. */
Advertisement
Add Comment
Please, Sign In to add comment