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
2 changes: 2 additions & 0 deletions 2-copy-of-code/lesson-18/data/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ class Product {
name;
rating;
priceCents;
keywords;

constructor(productDetails) {
this.id = productDetails.id;
this.image = productDetails.image;
this.name = productDetails.name;
this.rating = productDetails.rating;
this.priceCents = productDetails.priceCents;
this.keywords = productDetails.keywords;
}

getStarsUrl() {
Expand Down
11 changes: 10 additions & 1 deletion 2-copy-of-code/lesson-18/scripts/amazon.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ function renderProductsGrid() {
// filter the products that match the search.
if (search) {
filteredProducts = products.filter((product) => {
return product.name.includes(search);
let matchingKeyword = false;

product.keywords.forEach((keyword) => {
if (keyword.toLowerCase().includes(search.toLowerCase())) {
matchingKeyword = true;
}
});

return matchingKeyword ||
product.name.toLowerCase().includes(search.toLowerCase());
});
}

Expand Down