所以一切正常,除了我的 if 语句 >=largeOrder 它不会打折。对于作为承包商的员工也不会。我们必须在那里做出决定,给每个人最好的折扣,如果员工是承包商,他会得到承包商折扣。但是,如果声明是完美的并且工作正常,则常规承包商。所有输出都是正确的。所以我用我的嵌套 if 语句猜测它的东西......
//assumptions
var employeeDiscount = .1;
var largeOrder = 800;
var largeOrderDiscount = .05;
var smallOrderDiscount = 0;
var contractorDiscount = .2;
var salesTax = .08;
var seniorTax = 0;
var seniorAge = 90;
var tax, typeOfCustomer, orderAmount, employeeContractor;
var discount, discountAmount, subtotal, finalPrice, taxTotal;
//input
age = prompt("How old is the customer", "");
age = parseInt(age);
orderAmount = prompt("How much is the order", "");
orderAmount = parseInt(orderAmount);
typeOfCustomer = prompt("What type of customer is it, regular, employee, or contractor", "");
//calculations
if (age >= seniorAge) {
tax = seniorTax;
} else {
tax = salesTax;
}
if (typeOfCustomer == "regular") {
if (orderAmount >= largeOrder) {
discount = largeOrderDiscount;
} else {
discount = smallOrderDiscount;
}
}
if (typeOfCustomer == "employee") {
employeeContractor = prompt("is the employee a contractor?", "");
if (employeeContractor == "yes") {
discount = contractorDiscount;
} else {
discount = employeeDiscount;
}
}
if (typeOfCustomer == "contractor") {
discount = contractorDiscount;
} else {
discount = smallOrderDiscount;
}
taxTotal = orderAmount * tax;
discountAmount = orderAmount * discount;
subtotal = orderAmount - discountAmount;
finalPrice = subtotal + taxTotal;
//output
document.write("Order amount: $" + orderAmount);
document.write("<br>Discount amount: $" + discountAmount);
document.write("<br>Subtotal: $" + subtotal);
document.write("<br>Taxes: $" + taxTotal);
document.write("<br>Final Price is: $" + finalPrice);
// -->
</script>