In: Computer Science
/* Complete this javascript file according to the individual instructions given in the comments. */ //1) Create an Object using an Object Literal (the easiest way) // Name your object Breakfast // Your object should have 3 key:value pairs // The three keys should be: breakfast, lunch, dinner // Put your food choice for each as the value // 2) Display the keys of your Breakfast object in the // console. We have learned two ways to do this.. either // works here! // 3) With the object you created above, use dot notation to change // the value of the lunch property to "grilled cheese". // Add a method to your object named "digIn" that returns "Chomp!" // Call the method on the Breakfast object and send the output // to the console. // 4) Create an object constructor named Pizza. // Pizza should require a parameter called size. // size should be a property of Pizza. // // Create a new Pizza called LargePizza and // pass "large" as the parameter of the new Pizza. // Next, add a slices property to your LargePizza object. // Set the slices equal to 12. // // Finally, create a child object of LargePizza named // Hawaiian. Add a property called toppings to Hawaiian. // Set the toppings equal to an array with these values: // green peppers, pineapple, canadian bacon // // Send the slices property of Hawaiian to the console // Send Hawaiian's full array property of toppings to // the console also. // 5) With the objects created in Problem #4, // utilize prototype to add a method to the Pizza constructor. // Name the method bake and have it return "Ready in 10 minutes!" // // Create another child object of LargePizza named // TacoPizza. Call the bake method on TacoPizza and // log the result to the console.
Hi,Please find the solution. Everything is given in questioin. Thanks. please follow line by line.
let breakfast = {breakfast:"Bread",lunch:"Pizza",dinner :"SomeDinner"}; for (let [key, value] of Object.entries(breakfast)) { console.log(`${key}`); } breakfast.lunch = "grilled cheese"; function digIn() { return "Chomp!"; } breakfast.some = digIn(); console.log(breakfast.some); function pizza(size) { this.size = size; } let largePizza = new pizza("large"); largePizza.slices = 12; let hawaiian = Object.getPrototypeOf(breakfast); hawaiian.toppings = ["green peppers","pineapple","canadian bacon"]; console.log(hawaiian.toppings); function bake(){ return "Ready in 10 minutes!"; } let x = Object.getPrototypeOf(largePizza); x.bak = bake(); console.log(x.bak); let tacoPizza = Object.getPrototypeOf(largePizza); console.log(tacoPizza.bak);
Sample out: