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
Binary file added .DS_Store
Binary file not shown.
11 changes: 7 additions & 4 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>My Store</title>
<meta name="viewport" content="width=device-width, initial-scale=1">

</head>
<body>
<script src="products.js"></script>
<script src="index.js"></script>
<input type="text" id="search" value="">
<button onclick='search()'>Search</button>
<button onclick='hideProducts()'>Hide Products</button>
<div id='hi'></div>
<script src="products.js"></script>
<script src="index.js"></script>
</body>
</html>
</html>
44 changes: 44 additions & 0 deletions public/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

let data = {
products,
search: document.getElementById('search').value,
};

function hideProducts() {
let products = document.getElementById('products');
products.style = 'display: none;';
}

function getProductsList() {
let data = '<div id="products">';
products.forEach(p => {
data += `name: ${p.name}<br>${p.description}<br>
rating: ${p.rating}<br>
<img src="${p.imgUrl}"/><br>
price: ${p.price}<br>
category: ${p.category}<br>
${getReviews(p.reviews)}`;
});
data += '</div>';
return data;
}

function getReviews(review) {
let reviews = '';
review.forEach(r => {
reviews += `<br>${r.description}<br>${r.rating}`;
});
return reviews;
}

function search() {
console.log(data.search);
}

function main() {
let showProducts = true;
let x = document.getElementById('hi');
document.write(getProductsList());
}

main()