Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
body {
display: grid;
place-items: center;
}
</style>
<body>
<button id="fetch-api-button">Click To Fetch</button>
<div class="append-titles">
<h1>API Titles</h1>
</div>


<script src="./script.js"></script>
</body>
</html>
22 changes: 22 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
async function fetchTodo() {
try {
const response = await fetch('https://jsonplaceholder.typicode.com/todos');
if (!response.ok) {
throw new Error('Network response was not ok');
}
const json = await response.json();
json.forEach((item) => {
const container = document.querySelector('.append-titles')
const newTitle = document.createElement('span')
newTitle.innerHTML = item.title;
container.appendChild(newTitle)

});
} catch (error) {
console.error('There was a problem with the fetch operation:', error);
}
}


const button = document.getElementById('fetch-api-button');
button.addEventListener('click', () => fetchTodo())