TZinovieva

Bills

Oct 6th, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function bills(input) {
  2.     let period = Number(input[0]);
  3.     let water = 20;
  4.     let internet = 15;
  5.  
  6.     let electricity = 0;
  7.     let totalElectricity = 0;
  8.     let others = 0;
  9.     let allOthers = 0;
  10.     for (let i = 1; i <= period; i++) {
  11.         electricity = Number(input[i]);
  12.        
  13.         totalElectricity += electricity;
  14.         others = (water + internet + electricity) +
  15.         (water + internet + electricity) * 20 / 100;
  16.         allOthers += others;
  17.  }
  18.     let costs = totalElectricity + (water + internet) * period + allOthers;
  19.     let averageCosts = costs / period;
  20.     console.log(`Electricity: ${totalElectricity.toFixed(2)} lv`);
  21.     console.log(`Water: ${(water * period).toFixed(2)} lv`);
  22.     console.log(`Internet: ${(internet * period).toFixed(2)} lv`);
  23.     console.log(`Other: ${allOthers.toFixed(2)} lv`);
  24.     console.log(`Average: ${averageCosts.toFixed(2)} lv`);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment