I am trying to add the array named ingredients to the object named addIngredients so that when the method displayRecipe() is called it will display both the myFavoriteRecipe() object and also the array by showing it in the console window. I am getting an error message saying displayRecipe() is not defined. Why and how can I fix this?
var ingredients = [];
function myFavoriteRecipe() {
"use strict";
this.title = "guacamole";
this.serves = 8;
}
function addIngredients(items) {
"use strict";
//CREATING INSTANCE
var foodItems = new myFavoriteRecipe ();
//Pushing ingredients to food items
ingredients.push(foodItems);
return items;
}
addIngredients("3 Avocados");
addIngredients("1 Lime");
addIngredients("1 TSP salt");
addIngredients("1/2 Cup Onion");
addIngredients("3 Tablespoons of Cilantro");
addIngredients("2 Diced Tomatoes");
addIngredients("1 pinch Ground Pepper");
addIngredients.prototype.displayRecipe = function() {
"use strict";
for (var items in addIngredients) {
return addIngredients[items];
}
}
window.console.log(displayRecipe());
displayRecipeis a property of anaddIngredientsinstance, not a standalone function...