Advertisement
PavelIvanov

Untitled

May 28th, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. function reportSystem(input) {
  2. let finalAmout = Number(input.shift());
  3. let cashPayment = 0;
  4. let cardPayment = 0;
  5. let currentTransaction = Number(input.shift());
  6. let numOfCurrentTransaction = 0;
  7. let sum1 = 0;
  8. let sum2 = 0;
  9. let total = 0;
  10. let countCashPayment=0;
  11. let countCardPayment=0;
  12.  
  13. while (finalAmout > total || currentTransaction === "End") {
  14.  
  15. if (currentTransaction === "End") {
  16. console.log("Failed to collect required money for charity.");
  17. break;
  18. }
  19. if (numOfCurrentTransaction % 2 == 0) {
  20. cashPayment = Number(currentTransaction);
  21. if (cashPayment > 100) {
  22. console.log("Error in transaction!");
  23.  
  24. } else {
  25. console.log("Product sold!");
  26. countCashPayment++;
  27. sum1 += cashPayment;
  28. }
  29. } else {
  30. cardPayment = Number(currentTransaction);
  31. if (cardPayment < 10) {
  32. console.log("Error in transaction!");
  33.  
  34. } else {
  35. console.log("Product sold!");
  36. countCardPayment++
  37. sum2 += cardPayment;
  38. }
  39. }
  40. total = sum1 + sum2;
  41. numOfCurrentTransaction++;
  42. currentTransaction = input.shift();
  43. }
  44.  
  45. if (total >= finalAmout) {
  46. console.log(`Average CS: ${(sum1 / countCashPayment).toFixed(2)}`);
  47. console.log(`Average CC: ${(sum2 / countCardPayment).toFixed(2)}`);
  48.  
  49. }
  50.  
  51. }
  52. reportSystem(
  53. [
  54. '500', '120',
  55. '8', '63',
  56. '256', '78',
  57. '317'
  58. ]
  59.  
  60. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement