Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function carWash (input) {
- let value = 0;
- let soap = x => x + 10;
- let water = x => x + x * 0.2;
- let vacuum = x => x + x * 0.25;
- let mud = x => x - x * 0.10;
- for (let i = 0; i < input.length; i++){
- if (input[i] === 'soap') {
- soap(value);
- } else if (input[i] === 'water') {
- water(value);
- } else if (input[i] === 'vacuum cleaner') {
- vacuum(value);
- } else {
- mud(value);
- }
- }
- console.log(`The car is ${value.toFixed(2)}% clean.`);
- }
- carWash(['soap', 'soap', 'vacuum cleaner', 'mud', 'soap', 'water']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement