Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function reportSystem(input) {
- let sum = Number(input[0]);
- let cash = 0;
- let card = 0;
- let cashC = 0;
- let cardC = 0;
- let counter = 1;
- while (true) {
- let count = input[counter];
- if (count !== 'End') {
- let money = Number(count);
- if ((cash + card) >= sum) {
- console.log(`Average CS: ${(cash / cashC).toFixed(2)}`);
- console.log(`Average CS: ${(card / cardC).toFixed(2)}`);
- break;
- }
- if (counter % 2 !== 0) {
- if (money > 0 && money <= 100) {
- cash += money;
- console.log('Product sold!');
- cashC++;
- } else {
- console.log('Error in transaction!');
- }
- } else {
- if (money > 10) {
- card += money;
- console.log('Product sold!');
- cardC++;
- } else {
- console.log('Error in transaction!');
- }
- }
- } else {
- console.log('Failed to collect required money for charity.');
- break;
- }
- if ((cash + card) >= sum) {
- console.log(`Average CS: ${(cash / cashC).toFixed(2)}`);
- console.log(`Average CC: ${(card / cardC).toFixed(2)}`);
- break;
- }
- counter++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement