Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.header {
display: flex;
flex-direction: row-reverse;
max-width: 1300px;
margin: 20px auto;
background-color: #fffab1;
}

.products {
max-width: 1300px;
margin: 0 auto;
display: flex;
justify-content: space-evenly;
flex-wrap: wrap;
}

.product-item {
width: 20%;
box-sizing: border-box;
background-color: #e2e2e2;
padding: 10px;
border: #e2e2e2 solid;
border-radius: 5px;
}

.btn-cart {
background-color: #7c5fff;
border-radius: 5px;
color: #ffffff;
}
22 changes: 22 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/style.css">
<title>Document</title>
</head>


<body>
<header class="header">
<button class="btn-cart">Cart</button>
</header>
<main>
<div class="products"></div>
</main>
<script src="js/main.js"></script>
</body>

</html>
23 changes: 23 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@


const products = [
{ id: 1, title: 'Notebook', price: 2000 },
{ id: 2, title: 'Keyboard', price: 200 },
{ id: 3, title: 'Mouse', price: 100 },
{ id: 4, title: 'Gamepad', price: 87 },
];


const renderProduct = (title = 'Товар отсутствует', price = 0) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отлично, как раз аргументы по умолчанию отлично подходят в тех случаях, когда какое-то свойство товара у нас по каким-то причинам потерялось

return `<div class="product-item">
<h3>${title}</h3>
<p>${price}</p>
</div>`
};

const render = productsList => {
const productsElements = productsList.map(item => renderProduct(item.title, item.price));
document.querySelector('.products').innerHTML = productsElements.join('');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

совершенно верно, решение правильное

};

render(products);