I have to create a javascript file for a homework assignment

I have to create a javascript file for a homework assignment (what I came up with is under the question) and I am totally stumped. This is case problem 2 from Tutorial 12 in New Perspectives HTML5, CSS3, and Javascript Sixth Edition by Carey.

3. Add an event listener that runs the setupCart() function when the page is loaded.

4. Create the setupCart() function. The purpose of this function is is to define the event handlers for the Add to order Buttons on the page. Add the following commands to the function:

a. Create a variable named addButtons, which contains the collection of elements belonging to the addButton class.

b. Loop through the addButton collection and for each button, add an event handler that runs the addItem() function when the button is clicked.

5. Create the addItem() function, which adds items to the shoping cart on the page. Add the following commands to the function:

a. description of the food item is the next sibling element to the button that was clicked by the customer. use the nextElementSibling property to reference the next sibling

element to the target of the event object. Store the sibling element in the variable foodItem.

b. Create the foodID variable – contains the value of the id attribute for foodItem

c. Use the cloneNode() method to create a copy of the foodItem element and all of its descendants – store in foodDescription variable

d. shopping cart is stored in an aside element with the ID “cart” – store reference to this in variable named cartBox

The shopping cart needs to determine whether product ordered by customer has already been ordered = to do this, add span element to the top of each item in the cart containing

the # of items of each product ordered and update value when product order repeated. do following to create order counter for each product.

e. create variable duplicateOrder – set initial value to false

f. loop thru element child nodes of cartBox – for each node determine whether ID of element node equals foodID. If it does, previously placed that menu item in cart. Increase

value of the first element child of node by 1 to indicate an additional order and then break out of the for loop.

g. After the for loop has complete – test duplicateOrder is still false. if it is, declare a variable orderCount – storing span element node. set text content of the orderCount element

to 1. Insert orderCount as first child of foodDescription node structure and append foodDescription to cartBox as a new product order.


"Do you have an upcoming essay or assignment due?

If yes Order Similar Paper