Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function reportSystem(arr) {
- let neededMoney = Number(arr[0]);
- let action = 0;
- let cashSum = 0;
- let transActionSum = 0;
- let sum = 0;
- let peopleCash = 0;
- let peopleTransaction = 0;
- let index = 1;
- let current = arr[index];
- while( current !== "End") {
- if(sum <= neededMoney ) {
- }
- action += 1;
- current = Number(arr[index]);
- if( action % 2 !== 0){
- if( current > 100) {
- console.log(`Error in transaction!`);
- } else {
- console.log(`Product sold!`)
- cashSum += current;
- sum += cashSum;
- peopleCash += 1;
- }
- }else {
- if( current < 10) {
- console.log(`Error in transaction!`);
- } else {
- console.log(`Product sold!`)
- transActionSum += current;
- sum += transActionSum;
- peopleTransaction += 1;
- }
- }
- index++;
- current = arr[index];
- }
- if( current == "End") {
- console.log(`Failed to collect required money for charity.`)
- break;
- }
- console.log(`Average CS: ${(cashSum / peopleCash).toFixed(2)}`);
- console.log(`Average CC: ${(transActionSum / peopleTransaction).toFixed(2)}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement