-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
35 lines (25 loc) · 957 Bytes
/
app.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
// app.js
import { fetchData } from './fetchData.js';
async function displayData() {
const url = 'https://jsonplaceholder.typicode.com/posts';
const data = await fetchData(url);
if (!data) {
console.error('No data received');
return;
}
const container = document.getElementById('data-container');
container.innerHTML = ''; // Clear any existing content
data.forEach(post => {
const postElement = document.createElement('div');
postElement.classList.add('post');
const titleElement = document.createElement('h2');
titleElement.textContent = post.title;
const bodyElement = document.createElement('p');
bodyElement.textContent = post.body;
postElement.appendChild(titleElement);
postElement.appendChild(bodyElement);
container.appendChild(postElement);
});
console.log('Data displayed successfully'); // Debugging statement
}
document.addEventListener('DOMContentLoaded', displayData);