Skip to content

Commit d748447

Browse files
committed
create the add task and delete task functionality
1 parent c6be96b commit d748447

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Source-Code/ToDoList/module/main.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export function addTask(taskInput, categorySelect, taskList) {
2+
const taskText = taskInput.value.trim();
3+
const category = categorySelect.value;
4+
5+
if (taskText === '' || category === '') {
6+
alert('Please enter a task and select a category.');
7+
return;
8+
}
9+
10+
const li = document.createElement('li');
11+
li.classList.add('task-item');
12+
li.innerHTML = `
13+
<span class="task-text">${taskText} (${category})</span>
14+
<button class="delete-btn">Delete</button>
15+
`;
16+
17+
taskList.appendChild(li);
18+
19+
// Clear input fields
20+
taskInput.value = '';
21+
categorySelect.value = '';
22+
}
23+
24+
export function deleteTask(button) {
25+
const taskList = document.getElementById('task-list');
26+
taskList.removeChild(button.parentElement);
27+
}

0 commit comments

Comments
 (0)