-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
24 lines (19 loc) · 844 Bytes
/
Copy pathscripts.js
File metadata and controls
24 lines (19 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
document.addEventListener('DOMContentLoaded', function () {
// Function to fetch data from the API
function fetchData() {
fetch('https://pokeapi.co/api/v2/pokemon/ditto')
.then(response => response.json())
.then(data => displayData(data))
.catch(error => console.error('Error fetching data:', error));
}
// Function to display data in the HTML document
function displayData(data) {
const container = document.getElementById('data-container');
// Manipulate the data as needed and create HTML elements
const dataList = data.map(item => `<p>${item.name}: ${item.value}</p>`).join('');
// Insert the HTML into the container
container.innerHTML = dataList;
}
// Call the fetchData function when the page loads
fetchData();
});