Question: I need the JS code thank you in advance! In this project, you will create objects to describe the contents of a pizza and the
I need the JS code thank you in advance!
In this project, you will create objects to describe the contents of a pizza and the contents of a shopping cart. Each pizza is described by its size, crust, and list of toppings. An interface that allows customers to build their pizza by selecting items from a web form has been created for you. Your job will be to write the object code to work with this interface, storing data about the pizzas the customers build. A preview of the completed project is shown in Figure
Size in
Pizza Crust
Toppings
$ ea
Pepperoni
Ham
Sausage
Chicken
Mushrooms
Green Peppers
Onions
Tomatoes
Jalapenos
H
Do the following:
Use your code editor to open the projecttxthtml and projecttxtjs files from the js project folder. Enter your name and the date in the comment section of each file and save them as projecthtml and projectjs respectively.
Go to the projecthtml file in your code editor and link the page to the projectjs file, deferring the script until after the page loads. Take some time to study the contents and structure of the web from which customers will make their selections. Close the file, saving your changes.
Return to the projectjs file in your code editor. Directly below the Object Code comment create an object literal named cart. The cart object has a single property named itemscontaining an empty array and a single method named addItemfoodItem Add the command this.items.pushfoodItem to this method.
Create a constructor function for the Pizza object class containing a size and crust property with no initial values and a toppings property containing an empty array.
Create a constructor function for the Topping object class containing the name and side property to store the name of the topping and whether covers the entire pizza or is limited to the pizzas left or right side. Do not enter initial values for these properties.
Add the addToCartcart method to the Pizza prototype. Within the method run the command cart.items.pushthis to add the pizza to the items array of a shopping cart.
Add the summarize method to the Pizza prototype to create a text string summarizing the content of the pizza. Within the function do the following:
Declare a variable named summary with the initial value Pizza:
Add the value of this.size and this.crust to the value of summary. Separate the size and crust values with a blank space.
Create a for loop that iterates through the this.toppings array. For each item in the array add the text string name side to the summary variable, where name is the value of the this.toppingsiname property and side is the value of the this.toppingsiside property.
After the for loop, return the value of the summary variable.
Scroll down to the buildPizza function. This function builds a pizza object based on selections made on the web form. Add the following code to the function.
Create an instance of a Pizza object storing it in myPizza.
Set the value of myPizza.size to pizzaSizeBox.value. Set the value of myPizza.crust to pizzaCrustBox.value.
Add the selected toppings to the pizza by creating a for loop that iterates through the contents of the checkedToppings node list. Within the loop,
create an instance of a Topping object named myTopping;
set myTopping.name equal to checkedToppingsiname and myTopping.side equal to checkedToppingsivalue;
apply the addToppingmyTopping method to myPizza.
After the for loop, return the value of myPizza.
Go to the updateCart function, which adds the pizza to the shopping cart. Add the following commands to the function:
Run the buildPizza function, storing the result in the myPizza variable.
Apply the addItemmyPizza method to the cart object.
Run the console.logcart method to write the contents of the cart object to the debugger console.
Create a paragraph element containing the value of summarizemyPizza Use the appendChild method to append the paragraph to the cartBox element.
Reset the page for the next pizza by running the clearPizzaImage function followed by the clearToppings function.
JAVASCRIPT:
"use strict";
JavaScript th Edition
Chapter
Project
Project to build a pizza using object oriented programming
Author:
Date:
Filename: projectjs
Object Code
Interface Code
let pizzaPreviewBox document.getElementByIdpreviewBox; pizza image
let pizzaSizeBox document.getElementByIdpizzaSize; pizza size selection
let pizzaCrustBox document.getElementByIdpizzaCrust; pizza crust selection
let toppingOptions document.querySelectorAllinputtopping"; pizza topping option buttons
let addToCart document.getElementByIdad
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
