-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL5T3.js
More file actions
63 lines (58 loc) · 1.9 KB
/
L5T3.js
File metadata and controls
63 lines (58 loc) · 1.9 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
53
54
55
56
57
58
59
60
61
62
63
"use strict";
let basketItem = {
render(item) {
return `<div class="basket_list">
<div>Наименование: <b>${item.name}</b></div>
<tr><td>Количество: <b>${item.quantity}</b></td>
<td>Цена за шт.: <b>${item.price}</b></td>
<td>Стоимость: <b>${item.quantity * item.price}</b></td></tr>
</div><br/>`;
}
}
let basket = {
basketList: null,
basketItem,
products: [
{
id: 1,
category: ['выпечка', 1],
manufacturer: 'Фили Бэйкер',
name: 'торт',
price: 420,
quantity: 1
},
{
id: 2,
category: ['алкоголь', 2],
manufacturer: 'Koor',
name: 'вино',
price: 750,
quantity: 3
},
{
id: 3,
category: ['товары для дома', 3],
manufacturer: 'Да будет свет!',
name: 'свечи',
price: 59,
quantity: 5
},],
init() {
this.basketList = document.querySelector('.basket');
this.render(this.products);
},
render() {
if (this.products.length) {
this.products.forEach(item => {
this.basketList.insertAdjacentHTML('beforeEnd', this.basketItem.render(item));
});
this.basketList.insertAdjacentHTML('beforeEnd', `<br/>Стоимость вашей корзины = <b>${this.countBasketPrice()} руб.</b>`)
} else {
this.basketList.textContent = 'В корзине нет товаров';
}
},
countBasketPrice() {
return this.products.reduce((totalAmount, basketElem) => totalAmount += basketElem.price * basketElem.quantity, 0);
}
}
basket.init();