forked from Kalvium-Program/kidz-world-static
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
137 lines (128 loc) · 2.45 KB
/
script.js
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
let cartvalue = document.getElementById("cart-value");
let carticon = document.getElementById("cart");
let updateButton = document.getElementsByClassName("button");
let items = [
{
name: "This was our pact",
number: 0,
dollars: 7,
cents: 49,
},
{
name: "The famous five",
number: 0,
dollars: 4,
cents: 59,
},
{
name: "Matilda",
number: 0,
dollars: 6,
cents: 80,
},
{
name: "Harry Potter",
number: 0,
dollars: 10,
cents: 0,
},
{
name: "For Young Readers",
number: 0,
dollars: 7,
cents: 29,
},
{
name: "Wimpy Kid - DIY",
number: 0,
dollars: 4,
cents: 99,
},
{
name: "Dart Board",
number: 0,
dollars: 17,
cents: 49,
},
{
name: "Connect Four",
number: 0,
dollars: 19,
cents: 99,
},
{
name: "Jenga",
number: 0,
dollars: 20,
cents: 99,
},
{
name: "Monopoly",
number: 0,
dollars: 19,
cents: 49,
},
{
name: "Bookmarks",
number: 0,
dollars: 12,
cents: 49,
},
{
name: "Birthday Card",
number: 0,
dollars: 12,
cents: 49,
},
{
name: "Stuffed toys",
number: 0,
dollars: 15,
cents: 99,
},
{
name: "Dream catcher drawing",
number: 0,
dollars: 18,
cents: 49,
},
];
function updateCart() {
let cart = 0;
for (index = 0; index < items.length; index++) {
cart = cart + items[index].number;
}
cartvalue.innerHTML = cart;
}
for (let i = 0; i < updateButton.length; i++) {
updateButton[i].onclick = (e) => {
items[i].number++;
updateCart();
};
}
let totalDollars = 0;
let totalcents = 0;
function updatePrice() {
let totalinCents = 0;
for (index = 0; index < items.length; index++) {
totalinCents =
totalinCents +
items[index].number * (items[index].dollars * 100 + items[index].cents);
}
totalDollars = Math.floor(totalinCents / 100);
totalcents = totalinCents % 100;
}
// Whatsapp message update
carticon.onclick = () => {
updatePrice();
let orderDetails = "";
for (let index = 0; index < items.length; index++) {
if (items[index].number !== 0) {
orderDetails +=
`${items[index].name}: ${items[index].number} | `;
}
}
const whatsappMessage = `Order Details:\n${orderDetails}\nTotal Amount: $${totalDollars}.${totalcents}`;
const whatsappLink = `https://wa.me/9042315687?text=${(whatsappMessage)}`;
window.open(whatsappLink);
};