Skip to content

Commit 9a015c3

Browse files
committed
fetch example - 15
Added base HTML, CSS reset, and a JavaScript file that fetches product data from fakestoreapi.com and logs it to the console. This sets up the project structure and demonstrates basic API interaction.
1 parent 15e0db6 commit 9a015c3

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

Collage Code 0/15/css/style.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*{
2+
padding: 0;
3+
margin: 0;
4+
box-sizing: border-box;
5+
}

Collage Code 0/15/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
</head>
8+
<body>
9+
<script src="js/script.js"></script>
10+
</body>
11+
</html>

Collage Code 0/15/js/script.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// let name = "amin"
2+
3+
// let nakxcnd = kcndakcn
4+
5+
// let name2 = "amin2"
6+
7+
// console.log(nakxcnd)
8+
9+
async function fetchProduct() {
10+
try {
11+
const response = await fetch("https://fakestoreapi.com/products")
12+
if (!response.ok) {
13+
throw new Error("fetching data was unsuccessful!")
14+
}
15+
const data = await response.json();
16+
console.log("Products:", data)
17+
} catch (error) {
18+
console.log("Error:", error.massage)
19+
}
20+
}
21+
22+
fetchProduct()

0 commit comments

Comments
 (0)