Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The code is nearly complete but i want the form to have an alert window(add window.alert) if the first or last name is not filled

The code is nearly complete but i want the form to have an alert window(add window.alert) if the first or last name is not filled in. And also in the select customer section: the state drop down menu, the registered customer has 10% discount from the overall cost and the trade customer has 20 % discount and non registered has no discount. When putting all the data in, the total cost with discount dont add up. please look at the results.innerHTML section aswel as the if/else customerstate conditional in the js file. finally, in the result.innerHTML section in the js file it says " You have selected: 1shirt @ 20 each. Subtotal = 20 1tie @ 12 each Subtotal =12" here i want the the word " tie" and "shirt" to be "ties" and "shirts" when there is more than 1 of each shirt and tie etc. please fix the problem. thanks.

Welcome to the Shirt Company

Please enter your name and order details.

Name: First Name : LastName:

Cotton shirt

Price: 20/pair

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 = 1, estimate, total, 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; } deliveryCost = deliveryCostPer * totalQty; estimate = '' + ((totalItemPrice * discountFactor) + deliveryCost); total = ((totalItemPrice + deliveryCost)- discountFactor); document.getElementById('txt-estimate').value = estimate; var fname=document.getElementById('first').value; var last=document.getElementById('last').value; var results = document.getElementById('results'); results.innerHTML = 'hello '+fname+" "+last + ' ' + 'You have selected: ' + itemshirt + 'shirt @ 20 each. ' + ' Subtotal = ' + (20 * itemshirt) + ' ' + itemtie + 'tie @ 12 each' + ' Subtotal =' + (12 * itemtie) + ' ' + 'total cost ' + estimate + " "; results.innerHTML += 'Total cost of delivery: ' + deliveryCost + ' '; 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"; // total items // total delivery cost // discount } })();

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_2

Step: 3

blur-text-image_3

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

Statistical And Scientific Database Management International Working Conference Ssdbm Rome Italy June 21 23 1988 Proceedings Lncs 339

Authors: Maurizio Rafanelli ,John C. Klensin ,Per Svensson

1st Edition

354050575X, 978-3540505754

More Books

Students also viewed these Databases questions