-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassignment.js
50 lines (41 loc) · 1.31 KB
/
assignment.js
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
const url = 'https://jsonplaceholder.typicode.com/posts/1/comments';
async function getPost() {
const res = await fetch(url);
const data = await res.json();
return data;
}
async function displayingThe_Posts() {
const posts = await getPost();
const cardContainer = document.getElementById('card-container');
posts.forEach(post => {
const card = document.createElement('div');
card.className = 'col';
card.innerHTML = `
<div class="card h-100">
<div class="card-body">
<h5 class="card-title">${post.name}</h5>
<p class="card-text">${post.body}</p>
</div>
<div class="card-footer">
<small class="text-body-secondary">Last updated 3 mins ago by ${post.email}</small>
</div>
</div>
`;
cardContainer.appendChild(card);
});
}
displayingThe_Posts();
// async function getPost2(){
// try{
// const res = await fetch (url)
// if(!res.ok){
// throw new Error("Something Definetelly Went Wrong!!!!")
// }else{
// const data = await res.json()
// console.log(data);
// }
// } catch (error) {
// console.log(error);
// }
// }
// getPost2()