-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (33 loc) · 1.18 KB
/
script.js
File metadata and controls
39 lines (33 loc) · 1.18 KB
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
36
37
38
39
const addTaskButton = document.getElementById('addTask');
const taskList = document.getElementById('taskList');
addTaskButton.addEventListener('click', async () => {
const description = document.getElementById('description').value;
const deadline = document.getElementById('deadline').value;
const response = await fetch('http://localhost:3000/tasks', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ description, deadline }),
});
if (response.ok) {
document.getElementById('description').value = '';
document.getElementById('deadline').value = '';
loadTasks();
}
});
const loadTasks = async () => {
const response = await fetch('http://localhost:3000/tasks');
const tasks = await response.json();
displayTasks(tasks);
};
const displayTasks = (tasks) => {
taskList.innerHTML = '';
tasks.forEach(task => {
const taskDiv = document.createElement('div');
taskDiv.classList.add('task');
taskDiv.textContent = `${task.description} - ${task.deadline}`;
taskList.appendChild(taskDiv);
});
};
window.onload = loadTasks;