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

[ad_1]

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.

Don't use plagiarized sources. Get Your Custom Essay on
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
Just from $13/Page
Order Essay

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.

This is my code – if you could tell me what I’ve done wrong that would be hugely appreciated! (Sorry doesn’t copy and paste with all the proper indentations and such :S

window.addEventListener(“load”, setupCart);

function setupCart() {

var addButtons = document.querySelectorAll(“addButton”);

for (var i = 0; i < addButtons.length; i++) {

addButtons[i].onclick = addItem();

}

}

function addItem(e) {

var foodItem = e.target.nextElementSibling;

var foodID = foodItem.getAttribute(“id”).value;

var foodDescription = foodItem.cloneNode(true);

var cartBox = document.getElementById(“cart”);

var duplicateOrder = false;

// Add duplicate items to cartBox

for (var i = 0; i < cartBox.childNodes.length; i++) {

if (cartBox.childNodes[i].id === foodID.id) {

cartBox.firstElementChild.value + 1;

break; //stop processing the for loop

}

}

// Add new items to cartBox

if (duplicateOrder === false) {

var orderCount = document.createElement(“span”);

orderCount.textContent = 1;

foodDescription.appendChild(orderCount);

cartBox.appendChild(foodDescription);

}

}



[ad_2]

Source link

Place your order
(550 words)

Approximate price: $22

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more

Order your essay today and save 15% with the discount code BANANA