-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.js
65 lines (60 loc) · 1.97 KB
/
cart.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
let carditem = document.getElementById("items");
let actuvalPrice = document.getElementById("cardPrice");
let price = document.getElementById("cost");
let tax = document.getElementById("Tax");
let amount = document.getElementById("bill");
let quntity = document.getElementById("quantity");
let cost = 0;
let itmes = JSON.parse(localStorage.getItem("addingToCart"));
// console.log(itmes)
render(itmes);
// <------------rendering---------------->
function render(data) {
console.log(data);
let cards = data
.map((ele) => {
let card = Createcard(ele.img, ele.title, ele.brand, ele.price);
return card;
})
.join("");
console.log(cards);
carditem.innerHTML = cards;
}
// <------card creating ---------->
function Createcard(image, titel, brand, price, size) {
cost += +price;
let card = `
<div class="card">
<div class="image">
<img src=${image} alt="image" />
</div>
<div class="details">
<p>${titel}</p>
<p>${brand}</p>
<p id="cardPrice">Price:${price}</p>
<p>
Quntity:
<select id="quantity">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</p>
<button id="delete">Delete</button>
</div>
</div>
`;
return card;
}
price.innerText = cost;
tax.innerText = cost * 0.15;
amount.innerText = cost + cost * 0.15;
let buy = document.getElementById("buy");
buy.addEventListener("click", () => {
localStorage.setItem("amount", JSON.stringify(amount.innerText));
window.location.assign("adress.html");
});
let logoimg = document.getElementById("logoimg");
logoimg.addEventListener("click", () => {
window.location.assign("./index.html");
});