-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
239e93e
commit aede208
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const todoForm = document.getElementById('todo-form'); | ||
const todoList = document.getElementById('todo-list'); | ||
const newTaskInput = document.getElementById('new-task'); | ||
const taskDeadlineInput = document.getElementById('task-deadline'); | ||
|
||
todoForm.addEventListener('submit', (e) => { | ||
e.preventDefault(); | ||
addTask(newTaskInput.value, taskDeadlineInput.value); | ||
newTaskInput.value = ''; | ||
taskDeadlineInput.value = ''; | ||
}); | ||
|
||
function addTask(task, deadline) { | ||
if (task.trim() === '' || deadline.trim() === '') return; | ||
|
||
const listItem = document.createElement('li'); | ||
listItem.innerHTML = `<span>${task}</span><br><small>Deadline: ${deadline}</small>`; | ||
listItem.dataset.deadline = deadline; | ||
|
||
const controls = document.createElement('div'); | ||
controls.classList.add('task-controls'); | ||
|
||
const completeBtn = document.createElement('button'); | ||
completeBtn.textContent = 'Completed'; | ||
completeBtn.classList.add('complete-btn'); | ||
completeBtn.addEventListener('click', () => { | ||
listItem.classList.toggle('completed'); | ||
}); | ||
|
||
const deleteBtn = document.createElement('button'); | ||
deleteBtn.textContent = 'X'; | ||
deleteBtn.classList.add('delete-btn'); | ||
deleteBtn.addEventListener('click', () => listItem.remove()); | ||
|
||
controls.appendChild(completeBtn); | ||
controls.appendChild(deleteBtn); | ||
listItem.appendChild(controls); | ||
todoList.appendChild(listItem); | ||
|
||
checkDeadline(listItem); | ||
setInterval(() => checkDeadline(listItem), 1000); | ||
} | ||
|
||
function checkDeadline(listItem) { | ||
const deadline = new Date(listItem.dataset.deadline); | ||
const now = new Date(); | ||
if (now >= deadline) { | ||
listItem.classList.add('expired'); | ||
} | ||
} | ||
}); |