-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
36 lines (26 loc) · 962 Bytes
/
App.js
File metadata and controls
36 lines (26 loc) · 962 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
27
28
29
30
31
32
33
34
let main=document.querySelector("main");
let getApi= async()=>{
let res=await fetch("https://fakestoreapi.com/products");
let data=await res.json()
console.log(data);
data.map((ele)=>{
let div=document.createElement("div");
div.innerHTML=`<img src="${ele.image}" alt="">
<h1>Product name:${ele.title.slice(0,11)}</h1>
<h1>Product price:${ele.price}</h1>
<h1>Product rating:${ele.rating.rate}</h1>`;
div.classList.add("card");
main.appendChild(div)
let btn=document.getElementById("btn");
let inp=document.getElementById("sbar");
btn.addEventListener("click",(e)=>{
e.preventDefault();
div.style.display="none";
if (ele.title.toLowerCase().includes(inp.value.toLowerCase())) {
div.style.display="flex";
}
})
})
return data;
}
getApi();