-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
79 lines (63 loc) · 2.3 KB
/
script.js
File metadata and controls
79 lines (63 loc) · 2.3 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const inputArea = document.getElementById("InputArea");
const listContainer = document.getElementById("ListContainer");
const addBtn = document.getElementById("addBtn");
function addTask() {
const taskText = inputArea.value.trim();
if (taskText === "") {
alert("Please enter a valid task!");
return;
}
const li = document.createElement("li");
const taskSpan = document.createElement("span");
taskSpan.textContent = taskText;
li.appendChild(taskSpan);
const prioritySelect = document.createElement("select");
const priorities = ["Low", "Medium", "High"];
priorities.forEach(priority => {
const option = document.createElement("option");
option.value = priority;
option.textContent = priority;
prioritySelect.appendChild(option);
});
li.appendChild(prioritySelect);
const dueDateInput = document.createElement("input");
dueDateInput.type = "date";
li.appendChild(dueDateInput);
const editBtn = document.createElement("button");
editBtn.textContent = "Edit";
editBtn.classList.add("editBtn");
li.appendChild(editBtn);
const deleteBtn = document.createElement("button");
deleteBtn.textContent = "Delete";
deleteBtn.classList.add("deleteBtn");
li.appendChild(deleteBtn);
listContainer.appendChild(li);
inputArea.value = "";
editBtn.addEventListener("click", () => editTask(li, taskSpan, prioritySelect, dueDateInput));
deleteBtn.addEventListener("click", () => deleteTask(li));
}
function editTask(li, taskSpan, prioritySelect, dueDateInput) {
const newTaskText = prompt("Edit your task:", taskSpan.textContent);
if (newTaskText !== null) {
taskSpan.textContent = newTaskText;
}
const newPriority = prompt("Edit priority (Low, Medium, High):", prioritySelect.value);
if (newPriority && ["Low", "Medium", "High"].includes(newPriority)) {
prioritySelect.value = newPriority;
}
const newDueDate = prompt("Edit due date (YYYY-MM-DD):", dueDateInput.value);
if (newDueDate) {
dueDateInput.value = newDueDate;
}
}
function deleteTask(li) {
if (confirm("Are you sure you want to delete this task?")) {
li.remove();
}
}
addBtn.addEventListener("click", addTask);
inputArea.addEventListener("keydown", (e) => {
if (e.key === "Enter") {
addTask();
}
});