Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function carWash(array = []) {
- let sum = 0;
- function addNumber(n) {
- sum += n;
- return sum;
- }
- function addPercentage(percent) {
- let value = (sum * percent) / 100;
- sum += value;
- return sum;
- }
- function removePercentage(percent) {
- let value = (sum * percent) / 100;
- sum -= value;
- return sum;
- }
- let result = array.slice();
- for (let i = 0; i < result.length; i++) {
- let command = result[i];
- switch (command) {
- case "soap":
- addNumber(10);
- break;
- case "water":
- addPercentage(20);
- break;
- case "vacuum cleaner":
- addPercentage(25);
- break;
- case "mud":
- removePercentage(10);
- break;
- default:
- break;
- }
- }
- console.log(`The car is ${sum.toFixed(2)}% clean.`);
- }
- carWash(["soap", "soap", "vacuum cleaner", "mud", "soap", "water"]);
Advertisement
Add Comment
Please, Sign In to add comment