Advertisement
vladovip

Car Wash - JS Fundamentals_More Ex

Feb 5th, 2022
1,574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function carWash(commandsArray) {
  2.   let currentCarCondition = 0;
  3.   for (let index = 0; index < commandsArray.length; index++) {
  4.     switch (commandsArray[index]) {
  5.       case "soap":
  6.         currentCarCondition += 10;
  7.         break;
  8.       case "vacuum cleaner":
  9.         currentCarCondition += 0.25 * currentCarCondition;
  10.         break;
  11.       case "mud":
  12.         currentCarCondition -= 0.1 * currentCarCondition;
  13.         break;
  14.       case "water":
  15.         currentCarCondition += 0.2 * currentCarCondition;
  16.         break;
  17.       default:
  18.         break;
  19.     }
  20.   }
  21.   console.log(`The car is ${currentCarCondition.toFixed(2)}% clean.`);
  22. }
  23.  
  24. carWash(["soap", "water", "mud", "mud", "water", "mud", "vacuum cleaner"]);
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement