Advertisement
Guest User

Untitled

a guest
Apr 18th, 2020
996
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function reportSystem(input) {
  2.     let requiredSum = Number(input.shift());
  3.  
  4.     let expectedSum = 0;
  5.     let counter = 1;
  6.     let cardTransactionSum = 0;
  7.     let cashTransactionSum = 0;
  8.     let cardCount = 0;
  9.     let cashCount = 0;
  10.  
  11.     while (true) {
  12.         let command = input.shift();
  13.         if (command === 'End') {
  14.             break;
  15.         }
  16.  
  17.         if (counter % 2 === 0) {
  18.             if (command < 10) {
  19.                 console.log('Error in transaction!');
  20.             } else {
  21.                 console.log('Product sold!');
  22.                 cardTransactionSum += Number(command);
  23.                 expectedSum += Number(command);
  24.                 cardCount++;
  25.             }
  26.         } else {
  27.             if (command > 100) {
  28.                 console.log('Error in transaction!');
  29.             } else {
  30.                 console.log('Product sold!');
  31.                 cashTransactionSum += Number(command);
  32.                 expectedSum += Number(command);
  33.                 cashCount++;
  34.             }
  35.         }
  36.  
  37.         if (expectedSum >= requiredSum) {
  38.             break;
  39.         }
  40.         counter++;
  41.     }
  42.     if (expectedSum >= requiredSum) {
  43.         let avrCash = cashTransactionSum / cashCount;
  44.         let avrCard = cardTransactionSum / cardCount;
  45.         console.log(`Average CS: ${avrCash.toFixed(2)}`);
  46.         console.log(`Average CC: ${avrCard.toFixed(2)}`);
  47.     } else {
  48.         console.log('Failed to collect required money for charity.');
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement