Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///function
- function checker(recipe) {
- let counter = 0;
- for (let j = 0; j < quantity; j++) {
- for (const property in recipe.ingredient) {
- let currentPropertyValue = recipe.ingredient[property];
- let propertyValueInMicroElementObject = microElementsObject[property];
- if (propertyValueInMicroElementObject == NaN) {
- return `Error: not enough ${property} in stock`;
- }
- else if (propertyValueInMicroElementObject > currentPropertyValue) {
- microElementsObject[property] -= currentPropertyValue;
- counter++;
- }
- }
- let ingredients = Object.keys(apple.ingredient);
- let countOfIngredients = ingredients.length;
- if (counter == countOfIngredients) {
- return 'Success';
- }
- }
- }
- if (command === 'prepare') {
- let recipe = currentCommand[1];
- let quantity = Number(currentCommand[2]);
- if (recipe === 'apple') {
- function checker(recipe);
- } else if (recipe === 'lemonade') {
- let checker = checker(recipe);
- } else if (recipe === 'burger') {
- let checker = checker(recipe);
- } else if (recipe === 'eggs') {
- let checker = checker(recipe);
- } else if (recipe === 'turkey') {
- let checker = checker(recipe);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement