ALSAVOV

Untitled

Mar 1st, 2023
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.40 KB | Source Code | 0 0
  1. function repsys(input) {
  2.     let index = 0;
  3.  
  4.     let sumAll = 0;
  5.     let sumAllCash = 0;
  6.     let sumAllCard = 0;
  7.     let cashCounter = 0;
  8.     let cardCounter = 0;
  9.  
  10.     let sum = Number(input[index]);
  11.     index++;
  12.  
  13.     let command = input[index];
  14.     index++;
  15.  
  16.     while (command !== "End") {
  17.         let currentCashSum = Number(command);
  18.  
  19.         let currentCardSum = Number(input[index]);
  20.         index++;
  21.  
  22.         if (currentCashSum >= 100) {
  23.             console.log("Error in transaction!");
  24.         } else {
  25.             cashCounter++;
  26.             sumAllCash += currentCashSum;
  27.             sumAll += currentCashSum;
  28.             console.log("Product sold!");
  29.         }
  30.  
  31.         if (currentCardSum <= 10) {
  32.             console.log("Error in transaction!");
  33.         } else {
  34.             cardCounter++;
  35.             sumAllCard += currentCardSum;
  36.             sumAll += currentCardSum;
  37.             console.log("Product sold!");
  38.         }
  39.  
  40.         if (sumAll >= sum) {
  41.             console.log(`Average CS: ${(sumAllCash / cashCounter).toFixed(2)}`);
  42.             console.log(`Average CC: ${(sumAllCard / cardCounter).toFixed(2)}`);
  43.             break;
  44.         }
  45.  
  46.         command = input[index];
  47.         index++;
  48.     }
  49.  
  50.     if (command === "End") {
  51.         console.log("Failed to collect required money for charity.");
  52.         //console.log(`The collected money are ${sumAll}`);
  53.     }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment