-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathmain.js
More file actions
26 lines (24 loc) · 820 Bytes
/
main.js
File metadata and controls
26 lines (24 loc) · 820 Bytes
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
const data = [
{ title: 'Notebook', id: 1, price: 2000 },
{ title: 'Keyboard', id: 2, price: 200 },
{ title: 'Mouse', id: 3, price: 100 },
{ title: 'Gamepad', id: 4, price: 87 },
{ title: 'Новый Товар', id: 5 }
];
const renderProduct = (title, id, price = 'Цена товара', img = "https://placehold.it//150x100") => {
return `
<div class="product-item">
<img src = "${img}" alt = "${title}">
<div>
<h3>${title}</h3>
<p>${price}</p>
<button>Купить</button>
</div>
</div>
`
};
const render = (products) => {
document.querySelector('.products').innerHTML = products.map(item => renderProduct(item.title, item.id, item.price)).join('');
};
render(data);
console.log(data)