-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava1.js
More file actions
executable file
·53 lines (47 loc) · 2.06 KB
/
java1.js
File metadata and controls
executable file
·53 lines (47 loc) · 2.06 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
const itemsList = document.getElementById('itemsList');
const searchBar = document.getElementById('searchBar');
let hpItems = [];
searchBar.addEventListener('keyup', (e) => {
const searchString = e.target.value.toLowerCase();
const filteredItems = hpItems.filter((item) => {
return (
item.category.toLowerCase().includes(searchString) || item.description.toLowerCase().includes(searchString) || item.title.toLowerCase().includes(searchString)
);
});
displayItems(filteredItems);
});
const loadItems = async () => {
try {
const res = await fetch('product_dummy_data.txt');
hpItems = await res.json();
displayItems(hpItems);
} catch (err) {
console.error(err);
}
};
const displayItems = (items) => {
const htmlString = items
.map((item) => {
return `
<div class="container-lg">
<div class="row my-10 align-items-center justify-content-center g-0">
<div class="col-8 col-lg-3 col-xl-3" style="width:85%;">
<div class="card border-primary rounded-5" style="height: 30rem; position:relative;">
<div class="card-body text-center py-10 my-20">
<h4 class="card-title">${item.title}</h4>
<p class="lead card-subtitle" ><img src="${item.thumbnail}" class="my-images card-img-top" style="max-width:70%; max-height:20%; position : absolute; left:48px; top:78px;"></p>
<p class="disply-5 my-10 text-secondary" style = "position : absolute; top:250px; "> ${item.description}</p><br>
<p class="disply-5 my-10" style = "position : absolute; top:350px; left:32%; "> Ratings: ${item.rating}/5.00</p><br>
<p class="lead card-subtitle" style = " position: absolute; bottom:75px; left:42%;"><strong>$ ${item.price}</strong></p>
<a href="#" class="btn btn-outline-primary btn-lg mb-3 text-right" style = "position : absolute; bottom:0px; left:34%; ">Buy Now</a>
</div>
</div>
</div>
</div>
</div>
`;
})
.join('');
itemsList.innerHTML = htmlString;
};
loadItems();