Ivankooo1

washCar2

Feb 10th, 2020
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(carWash){
  2.    let result = 0;
  3.    for(let i = 0;i < carWash.length;i++){
  4.       let command = carWash[i];
  5.       let func = null;
  6.  
  7.       switch(command){
  8.          case "soap":
  9.           func = a => 10 + a;
  10.          
  11.          ;break;
  12.          case 'water':
  13.           func = a => a + (a * 0.20);
  14.      
  15.          ;break;
  16.          case 'vacuum cleaner':
  17.  
  18.           func = a => a + (a * 0.25);
  19.          
  20.          ;break;
  21.          case 'mud':
  22.             func = a => a - (a * 0.10);
  23.            
  24.          ;break;
  25.       }
  26.       result = func(result);
  27.  
  28.    }
  29.    
  30.  
  31.    console.log(`The car is ${result.toFixed(2)}% clean.`);
  32.  
  33. }
  34. solve(['soap','soap','vacuum cleaner','mud','soap','water']);
Advertisement
Add Comment
Please, Sign In to add comment