Problem with Report System // PB More Exercises
Can anybody help me with mu solution?
VS Code give me problem with : break;
Here is my solution:
Thank you!
Can anybody help me with mu solution?
VS Code give me problem with : break;
Here is my solution:
Thank you!
Hmm, couple of problems and code-logic was not fully implemented. I have revised your solution but do analyse the changes that were implemented. The break error came from the following line, since you used break statement ouside of the while-loop:
if (current == "End") {
console.log(`Failed to collect required money for charity.`)
break;
}
Best,
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") {
while (index < arr.length) {
if (current === "End") {
console.log(`Failed to collect required money for charity.`)
break;
}
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;
sum += current;
peopleCash += 1;
}
} else {
if (current < 10) {
console.log(`Error in transaction!`);
} else {
console.log(`Product sold!`)
transActionSum += current;
// sum += transActionSum;
sum += current;
peopleTransaction += 1;
}
}
if (sum >= neededMoney) {
console.log(`Average CS: ${(cashSum / peopleCash).toFixed(2)}`);
console.log(`Average CC: ${(transActionSum / peopleTransaction).toFixed(2)}`);
break;
}
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)}`);
}
Thanks!
Best,