-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomment.js
More file actions
23 lines (21 loc) · 740 Bytes
/
comment.js
File metadata and controls
23 lines (21 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function loadComment() {
fetch('https://jsonplaceholder.typicode.com/comments')
.then(response => response.json())
.then(data => displayComment(data))
}
function displayComment(comments) {
const commentContainer = document.getElementById('comment-container');
for (const comment of comments) {
console.log(comment);
const commentDiv = document.createElement('div');
commentDiv.classList.add('comment');
commentDiv.innerHTML = `
<h4>ID: ${comment.id}</h4>
<h2>Name: ${comment.name}</h2>
<h3>Email: ${comment.email}</h3>
<p>Body: ${comment.body}</p>
`;
commentContainer.appendChild(commentDiv);
}
}
loadComment();