Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone look over my JS code? I can't seem to get the 'order' portion to display. thanks Create a function with the name processFood().

Can someone look over my JS code? I can't seem to get the 'order' portion to display. thanks

Create a function with the name processFood(). Within the function, do the following:

  • a. Declare five local variables: prop; crustOpt, which references the elements with the name crust; toppings, which has a value of 0; toppingBoxes, which references the elements with the name toppings; and instr, which references the element with the id value instructions.
  • b. Add an if/else statement that checks if the first item in the crustOpt array is checked. If so, the crust property of the foodInfo object should be assigned the value of the first item in the crustOptarray; otherwise, the crust property of the foodInfo object should be assigned the value of the second item in the crustOpt array.
  • c. Add a statement that assigns the value of the element with the id value size as the value of the size property of the foodInfo object.
  • d. Create a for statement that sets a counter variable to 0, repeats the loop as long as the counter is less than the length of the toppingBoxes array, and increments the counter variable by one after each loop. Within the for statement, add an if statement that checks if the element of the toppingBoxes array at the index of the counter variable is checked. If the condition is true, increment the toppings variable by 1, and create a new property in the foodInfo object using the name topping plus the value of the toppings variable, and set the new property's value to the value of the current element in the toppingBoxes array.
  • e. Add an if statement that checks if the element referenced by the instr variable has any content, and if so, creates an instructions property for the foodInfo object and sets its value to the value of the element referenced by the instr variable.
  • html
  • Hands-on Project 7-5

    Pizza Order Form

    Delivery Information Name Street Address City Email Phone

    Order

    Crust Thin Crust Deep Dish

    Size SmallMediumLargeExtra Large

    Topping(s) Pepperoni Sausage Green Peppers Onions Extra Cheese Special Instructions

    Order Summary

    Deliver to

    Order

  • JS---

    */ "use strict";

    var delivInfo = []; var delivSummary = document.getElementById("deliverTo"); var foodInfo = []; var foodSummary = document.getElementById("order");

    function processDeliveryInfo() { var prop; delivInfo.name = document.getElementById("nameinput").value; delivInfo.addr = document.getElementById("addrinput").value; delivInfo.city = document.getElementById("cityinput").value; delivInfo.email = document.getElementById("emailinput").value; delivInfo.phone = document.getElementById("phoneinput").value; for (prop in delivInfo) { delivSummary.innerHTML += "

    " + delivInfo[prop] + "

    "; } }

    function previewOrder() { processDeliveryInfo(); processFood(); document.getElementById("deliverTo").style.display = "block"; }

    function processFood() { var prop; var crustOpt = document.getElementById("crust"); var toppings = 0; var toppingBoxes = document.getElementById("toppings"); var instr = document.getElementById("instructions").value; //radio box checked for crust if (document.getElementById('thin').checked) { foodInfo.crust = document.getElementById('thin').value; } else if (document.getElementById('thick').checked) { foodInfo.crust = document.getElementById('thick').value; }

    foodInfo.size = document.getElementById('size').value;

    //Storing all the values which are checked

    for (var i=0, n=toppings.length;i if (toppingBoxes[i].checked){ toppingBoxes += ","+toppingBoxes[i].value; } } foodInfo = toppingBoxes; // add instr foodSummary.innerHTML += "

    Crust : " + foodInfo.crust + "

    "; foodSummary.innerHTML += "

    Size : " + foodInfo.size + "

    "; foodSummary.innerHTML += "

    Topping (s) : " + "

    "; foodSummary.innerHTML += "
    • "; for (var i = 1; i < 6; i++) { if (foodInfo["toppings" + i]) { foodSummary.innerHTML +="
    • " + foodInfo["toppings" + i] + "
    • "; } } foodSummary.innerHTML += "
    "; foodSummary.innerHTML += "

    Instructions: " + foodInfo.instructions; document.getElementById("order").style.display = "block"; }

    function createEventListener() { var previewButton = document.getElementById("previewBtn"); if (previewButton.addEventListener) { previewButton.addEventListener("click", previewOrder, false); } else if (previewButton.attachEvent) { previewButton.attachEvent("onclick", previewOrder); } } if (window.addEventListener) { window.addEventListener("load", createEventListener, false); } else if (window.attachEvent) { window.attachEvent("onload", createEventListener); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions