Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
34 changes: 34 additions & 0 deletions code/web-api-assignment-2copy/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const toDoList = document.getElementById("to-do-list");

const getToDoList = async () => {
const res = await fetch("https://jsonplaceholder.typicode.com/todos?userId=1");
const data = await res.json();
// console.log(data);

//loop through todo item and create li element
data.forEach((todo) => {
const liElement = document.createElement("li");
liElement.textContent = todo.title;
toDoList.appendChild(liElement);

//If todo is completed, style it accordingly
if (todo.completed) {
liElement.style.textDecoration = "line-through";
liElement.style.color = "red";
}

//Check off more items on the list
//Use a button element to checkoff items
const button = document.createElement('button');
button.textContent = 'Complete';

button.addEventListener('click', () => {
liElement.style.textDecoration = 'line-through'; // Add line-through style
liElement.style.color = 'gray'; // Change the color to gray
});
//append button to li element
liElement.appendChild(button);
});
};
getToDoList();

12 changes: 12 additions & 0 deletions code/web-api-assignment-2copy/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>To Do list</title>
<script src="app.js" defer></script>
</head>
<body>
<ul id="to-do-list"></ul>
</body>
</html>