-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
52 lines (48 loc) · 1.27 KB
/
Copy pathscript.js
File metadata and controls
52 lines (48 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const VAT_RATE = 0.07;
let totalPrice = 0;
function addToProductList() {
const total = $("#total");
if (total.hasClass("hidden")) {
total.removeClass("hidden");
}
const accessory = $("#accessory").val();
const amount = $("#amount").val();
const price = calculatePrice(accessory) * amount;
$("#productList").append(
"<tr ><td class='border-2 border-black '>" +
accessory +
"</td><td class='border-2 border-black '>" +
amount +
"</td><td class='border-2 border-black '>$" +
price +
"</td></tr>",
);
updateTotalPrice(price);
}
function calculatePrice(accessory) {
// Add your own logic to calculate the price based on the selected accessory
switch (accessory) {
case "p111":
return 10;
case "p222":
return 20;
case "p333":
return 30;
case "p444":
return 40;
// Add more cases as
default:
return 0;
}
}
function calculateVAT() {
const vatAmount = (totalPrice * VAT_RATE).toFixed(2);
const netPrice = (parseFloat(totalPrice) + parseFloat(vatAmount)).toFixed(2);
$("#vat").text(`VAT: ${vatAmount}`);
$("#netPrice").text(`Net Price: ${netPrice}`);
}
function updateTotalPrice(price) {
totalPrice += price;
$("#totalPrice").text(totalPrice.toFixed(2));
calculateVAT();
}