Advertisement
vladovip

Car Wash

Feb 7th, 2021
452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function carWash (input) {
  2.     let value = 0;
  3.     let soap = x => x + 10;
  4.     let water = x => x + x * 0.2;
  5.     let vacuum = x => x + x * 0.25;
  6.     let mud = x => x - x * 0.10;
  7.     for (let i = 0; i < input.length; i++){  
  8.       if (input[i] === 'soap') {
  9.         value = soap(value);
  10.       } else if (input[i] === 'water') {
  11.         value = water(value);
  12.       } else if (input[i] === 'vacuum cleaner') {
  13.         value = vacuum(value);
  14.       } else {
  15.         value = mud(value);
  16.       }
  17.     }
  18.     console.log(`The car is ${value.toFixed(2)}% clean.`);
  19.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement