-6

Hi, I would appreciate helping me with this question:

A company awards its customers a discount based on their value of purchases and number of children in the family according to the following specifications:
• If the value of purchases is $5000 or more, and number of children in the family is more than 7, the discount is 30% of the value of purchases.
• If the value of purchases is $5000 or more and number of children in the family is more than 4, the discount is 22% of the value of purchases.
• If the value of purchases is less than or equal to $2500, the discount is 10%

For example, a customer pays $5000, and gets 30% of 5000, i.e.
(30/100) * 5000 = $1500.

1. Using nested if statements, write a JavaScript code which will work according to the following specifications:
• Read the amount of purchases for a customer and number of children in the family
• Calculate the discount for that customer according to the above description
• Calculate and then print the final price of the value of purchases after the discount

4

1 回答 1

0
var purchaseValue = 7000;
var children = 10;
var discount = 0;
if(purchaseValue >= 5000){
  if(children > 4){
    discount = 22;
  }
  else if(children > 7){
    discount = 30;
  }
}
else if(purchaseValue <= 2500){
   discount = 10;
}
var amount = (discount/100) * purchaseValue;
于 2013-07-23T10:49:58.747 回答