audipower

Cookie Factory js

Feb 18th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. function cookieFactory(input) {
  2.  
  3. let batches = Number(input.shift());
  4. let countBatches = 0;
  5. let flourCom = false;
  6. let eggsCom = false;
  7. let sugarCom = false;
  8. let command = input.shift();
  9.  
  10. while (countBatches < batches) {
  11. if (command === "flour") {
  12. flourCom = true;
  13. } else if (command === "eggs") {
  14. eggsCom = true;
  15. } else if (command === "sugar") {
  16. sugarCom = true;
  17. }
  18. if (command === "Bake!" && (flourCom === false || eggsCom === false || sugarCom === false)) {
  19. console.log(`The batter should contain flour, eggs and sugar!`);
  20. }
  21. if (command === "Bake!" && flourCom === true && eggsCom === true && sugarCom === true) {
  22. countBatches++;
  23. console.log(`Baking batch number ${countBatches}...`);
  24. flourCom = false;
  25. eggsCom = false;
  26. sugarCom = false;
  27. }
  28. command = input.shift();
  29. }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment