Question: please help me. This code is not working. i have put in the correct variables but it is not working. For example the the total
please help me. This code is not working. i have put in the correct variables but it is not working. For example the the total qty variable is not working etc. please help.
Welcome to The Shirt Company (Est 2016)
Please enter your name and place your order.
Name
Items
Select customer status
Check order
please click here
var button = document.getElementById("button");
button.addEventListener("click", clickHandler);
function clickHandler()
{
var input = document.getElementById("input");
var output = document.getElementById("output");
function clickHandler(event) {
event.preventDefault();
// validate that you have selected a valid customer state from the dropdown menu
if (state.value === '') {
// If you have not selected anything, the state drop-down will be focused
alert('Please choose your customer state.');
state.focus();
}
// Now, parse the input fields of Cotton Shirt and Tie to determine the respective quantities
var itemshirt = parseInt(document.getElementById('cottonshirt').value, 10) || 0,
itemtie = parseInt(document.getElementById('cottontie').value, 10) || 0,
// parse the customer state
customerState = state.value,
// parse the delivery method
deliveryMethod = document.querySelector('[name=r_method]:checked').value || "";
var totalQty = cottonshirt + silktie,
deliveryCostPer,
deliveryCost,
discountFactor = 1,
estimate,
total,
discount,
// calculate the total price of all the shirts and ties
totalItemPrice = (20 * cottonshirt) + (12 * silktie);
var isDiscounted = false;
if (customerState === "RC") {
discountFactor = 1.10; // minus 10% from total amount (estimate).
isDiscounted = true;
} else if (customerState === "TC") {
discountFactor = 1.20; // minus 20% from total amount(estimate).
isDiscounted = true;
}
//Now, add to the total cost based on the delivery method
switch (deliveryMethod) {
case "7-days":
deliveryCostPer = 2;
break;
// 7 days delivery: Add delivery of 2 per order
case "3-days":
deliveryCostPer = 3;
break;
// 3 days delivery: Add delivery of 3 per order
case "next-day":
deliveryCostPer = 5;
break;
// next day delivery: Add delivery of 5 per order
}
// If the user has entered a valid name, go to the if condition
if (output()) {
if(totalQty >0){
deliveryCost = deliveryCostPer; //you are saying delivery cost per order, so don't multiply with total quantity if you mean to per order.
}
else
deliveryCost=0;
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
var shirtMsg = "shirt";
var tieMsg = "tie";
if (itemshirt > 1)
{
shirtMsg = "Shirts";
}
if (itemtie > 1) {
tieMsg = "ties";
}
}
}
// this function is used to validate that you have not entered an empty name
output.innerHTML = "hello " + input.value + " " + input1.value + " You have selectected: " + " " +
"you have chosen one shirtsubtotal " + cottonshirt + (20 *cottonshirt) + "" + shirtMsg + " subtotal " + silktie+" YOU HAVE :" + totalQty;
}
})();
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
