-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
46 lines (35 loc) · 1.1 KB
/
script.js
File metadata and controls
46 lines (35 loc) · 1.1 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
const PRODUCT_URL = 'https://dummyjson.com/products';
// function getProducts(url) {
// fetch(url)
// .then((response)=>(response.json()))
// .then((data)=>(console.log(data)))
// .catch((error)=>console.log(error));
// }
const getProducts = async(url) => {
try{
const response = await fetch(url);
const data = await response.json();
// console.log(data);
displayProduct(data.products)
} catch(error){
console.log(error);
}
}
getProducts(PRODUCT_URL);
const productDiv = document.querySelector(".productContainer")
function displayProduct(products) {
products.forEach((product) => {
const {price,description,title,images} = product;
console.log(price);
console.log(images);
productDiv.innerHTML +=`
<div>
<img src="${images[0]}" alt="">
<div class = "titlePrice">
<span>${title}</span>
<span>price ₦ ${price}</span>
</div>
<span>${description}</span>
</div>`
});
}