171k views
3 votes
Write an if/else statement for the following: if total is greater than $150 set tax to 5%. Otherwise, set tax to 10%. Compute the total amount of sale.

a) Set tax to 5%
b) Set tax to 10%
c) Compute total sale
d) None of the above

User Upio
by
8.3k points

1 Answer

5 votes

Final answer:

An if/else statement can be used to set the tax based on the value of the total. The tax rate can be set to 5% if the total is greater than $150, and 10% otherwise. Using JavaScript, the total sale can be computed by multiplying the total by the tax rate and adding it to the total.

Step-by-step explanation:

An if/else statement can be used to set the tax based on the value of the total. Here is an example of how it can be written in JavaScript:

let total = 200;

let tax;

if (total > 150) {
tax = 0.05;
} else {
tax = 0.1;
}

let salesTax = total * tax;

let totalSale = total + salesTax;

console.log(totalSale); // Output: 210

In this example, the total is set to 200. Since 200 is greater than 150, the tax rate is set to 5% (0.05). The sales tax is then computed by multiplying the total by the tax rate. The total sale is calculated by adding the total and the sales tax. The output is 210.

User Joey J
by
8.5k points