//How to make a constructor var recipes = { constructor: function(ingredients,…
- User
//How to make a constructor var recipes = { constructor: function(ingredients, optionalIngredients, time, ovenTime, temp) { return {ingredients: ingredients, optionalIngredients: optionalIngredients, time: time, ovenTime: ovenTime, temp: temp}; }, cake: { ingredients: ["Butter", "Sugar", "Egg", "Flour", "Milk"], optionalIngredients: ["Vanilla", "Cinnamon"], time: 20, ovenTime: 40, temp: 180 }, bread: { ingredients: ["Flour", "Water", "Yeast"], optionalIngredients: ["Sunflower Oil"], time: 120, ovenTime: 30, temp: 180 }, jam_tart: { ingredients: ["Butter", "Flour", "Water", "Salt", "Jam"], optionalIngredients: [], time: 40, ovenTime: 30, temp: 180 }, patty: { ingredients: ["Butter", "Flour", "Water", "Salt", "Turmeric", "Curry Powder", "Mince"], optionalIngredients: ["Onions", "Garlic"], time: 90, ovenTime: 30, temp: 180 } }; var applePie = recipes.constructor(["Butter", "Flour", "Water", "Salt", "Apples"], ["Cinnamon", "Sugar"], 40, 30, 180);
Assistant
To make a constructor in JavaScript, you can define a function that initializes and returns an object with specific properties. In your code example, you have a
recipesobject that contains recipe information and a constructor function. However, the constructor function is not correctly defined as a constructor.Here's how you can modify your code to create a constructor function:
javascript