Advertisement
Guest User

Report System

a guest
Dec 20th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. function reportSystem(arr) {
  2.  
  3. let neededMoney = Number(arr[0]);
  4. let action = 0;
  5. let cashSum = 0;
  6. let transActionSum = 0;
  7. let sum = 0;
  8. let peopleCash = 0;
  9. let peopleTransaction = 0;
  10.  
  11. let index = 1;
  12. let current = arr[index];
  13.  
  14. while( current !== "End") {
  15.  
  16. if(sum <= neededMoney ) {
  17.  
  18. }
  19.  
  20. action += 1;
  21.  
  22.  
  23. current = Number(arr[index]);
  24.  
  25. if( action % 2 !== 0){
  26. if( current > 100) {
  27. console.log(`Error in transaction!`);
  28.  
  29. } else {
  30. console.log(`Product sold!`)
  31. cashSum += current;
  32. sum += cashSum;
  33. peopleCash += 1;
  34.  
  35. }
  36.  
  37. }else {
  38. if( current < 10) {
  39. console.log(`Error in transaction!`);
  40.  
  41. } else {
  42. console.log(`Product sold!`)
  43. transActionSum += current;
  44. sum += transActionSum;
  45. peopleTransaction += 1;
  46.  
  47. }
  48. }
  49. index++;
  50. current = arr[index];
  51.  
  52. }
  53. if( current == "End") {
  54. console.log(`Failed to collect required money for charity.`)
  55. break;
  56. }
  57.  
  58.  
  59. console.log(`Average CS: ${(cashSum / peopleCash).toFixed(2)}`);
  60. console.log(`Average CC: ${(transActionSum / peopleTransaction).toFixed(2)}`);
  61.  
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement