Advertisement
Guest User

Untitled

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