Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please add commentary of what is happening in each section - line. Thanks Welcome to the Shirt Company Please enter your name and order details.

Please add commentary of what is happening in each section - line. Thanks

Welcome to the Shirt Company

Please enter your name and order details.

Name: First Name : LastName:

Cotton shirt

Price: 20/each

Cotton Tie

Price: 12/each

Select customer status

script.js:

(function () { "use strict"; var state = document.getElementById('s-state');

document.addEventListener('DOMContentLoaded', function () { document.getElementById('cart-hplus').addEventListener('submit', estimateTotal); var btnEstimate = document.getElementById('btn-estimate'); btnEstimate.disabled = true; state.addEventListener('change', function () { if (state.value === '') { btnEstimate.disabled = true; } else { btnEstimate.disabled = false; } }); });

function estimateTotal(event) { event.preventDefault(); if (state.value === '') { alert('Please choose your customer state.'); state.focus(); } var itemshirt = parseInt(document.getElementById('cottonshirt').value, 10) || 0, itemtie = parseInt(document.getElementById('cottontie').value, 10) || 0, customerState = state.value, deliveryMethod = document.querySelector('[name=r_method]:checked').value || ""; var totalQty = itemshirt + itemtie, deliveryCostPer, deliveryCost, discountFactor = 0, estimate, total, discount, totalItemPrice = (20 * itemshirt) + (12 * itemtie);

if (customerState === "RC") { discountFactor = 1.10; //Need to minus 10% from total amount (estimate). please.help } else if (customerState === "TC") { discountFactor = 1.20; //Need to minus 20% from total amount(estimate). please.help } else { discountFactor = 1;

} switch (deliveryMethod) { case "7-days": deliveryCostPer = 2; break;

case "3-days": deliveryCostPer = 3; break; case "next-day": deliveryCostPer = 5; break; }

if (checkforNameInputs()) { deliveryCost = deliveryCostPer * totalQty; //you are saying delivery cost per order, so don't multiply with total quantity if you mean to per order. discount = ((discountFactor - 1) * totalItemPrice).toFixed(2); //Here I calculated discount Separately estimate = '' + (totalItemPrice + deliveryCost); // so estimate = (totalItemPrice) + deliveryCost total = ((totalItemPrice + deliveryCost) - discount); //Subtracted discount from total item price + delivery cost

document.getElementById('txt-estimate').value = estimate; var fname = document.getElementById('first').value; var last = document.getElementById('last').value; var results = document.getElementById('results'); var shirtMsg = "shirt"; var tieMsg = "tie"; if (itemshirt > 1) { shirtMsg = "Shirts"; }

if (itemtie > 1) { tieMsg = "ties"; }

results.innerHTML = 'hello ' + fname + " " + last + ' ' + 'You have selected: ' + itemshirt + ' ' + shirtMsg +' @ 20 each. ' + ' Subtotal = ' + (20 * itemshirt) + ' ' + itemtie + ' ' + tieMsg + ' @ 12 each' + ' Subtotal =' + (12 * itemtie); results.innerHTML += ' ' + 'Total cost of delivery: ' + deliveryCost + ' '; results.innerHTML += 'Total cost ' + estimate + " "; // Moved estimate below Delivery cost results.innerHTML += 'Discount: ' + ((discountFactor - 1) * 100).toFixed(2) + '% (' + customerState + ')' + ' '; results.innerHTML += 'Cost discount included: ' + total + ' ' + "If you're happy with that, please go ahead and place the order. Have an awesome day"; } }

})();

function checkforNameInputs() { var firstName = document.getElementById('first').value; var lastName = document.getElementById('last').value; if (firstName == "") { window.alert("Please enter firstname"); return false; } else if (lastName == "") { window.alert("Please enter lastname"); return false; } return true; }

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

Data Infrastructure For Medical Research In Databases

Authors: Thomas Heinis ,Anastasia Ailamaki

1st Edition

1680833480, 978-1680833485

More Books

Students also viewed these Databases questions