Advertisement
desito07

Dishwasher

Apr 16th, 2020
1,111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. function dishwasher(input) {
  2. let bottlesWithdetergent = Number(input.shift());
  3. let DetergentOwned = bottlesWithdetergent * 750;
  4. let DetergentNeeded = 0;
  5. let plates = 0;
  6. let pots = 0;
  7. let counter = 1;
  8.  
  9. while (true) {
  10. let command = input.shift();
  11. if (command === "End") {
  12. break;
  13. }
  14. if (counter % 3 === 0) {
  15. DetergentNeeded += command * 15;
  16. } else {
  17. DetergentNeeded += command * 5;
  18. }
  19. if (DetergentNeeded > DetergentOwned) {
  20. break;
  21. }
  22. if (counter % 3 === 0) {
  23. pots += Number(command);
  24. } else {
  25. plates += Number(command);
  26. }
  27. counter++;
  28. }
  29. if (DetergentNeeded <= DetergentOwned) {
  30. console.log(`Detergent was enough!`);
  31. console.log(`${plates} dishes and ${pots} pots were washed.`);
  32. console.log(
  33. `Leftover detergent ${Math.abs(DetergentOwned - DetergentNeeded)} ml.`
  34. );
  35. } else {
  36. console.log(
  37. `Not enough detergent, ${Math.abs(
  38. DetergentNeeded - DetergentOwned
  39. )} ml. more necessary!`
  40. );
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement