-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
48 lines (39 loc) · 1.47 KB
/
index.js
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
function updateDateTime() {
const now = new Date();
const dateTimeString = now.toLocaleString();
document.getElementById("date-time").textContent = "Date & Time: " + dateTimeString;
}
function addTask() {
const taskInput = document.getElementById("task-input");
const taskText = taskInput.value.trim();
if (taskText === "") {
alert("Please enter a task.");
return;
}
const taskList = document.getElementById("task-list");
const taskDiv = document.createElement("div");
taskDiv.className = "task";
const checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.className = "box";
const label = document.createElement("label");
label.textContent = taskText;
const taskDateTime = document.createElement("span");
taskDateTime.className = "task-date-time";
taskDateTime.textContent = ` (Added: ${new Date().toLocaleString()})`;
const removeButton = document.createElement("button");
removeButton.textContent = "Remove";
removeButton.className = "remove-button";
removeButton.onclick = function() {
taskList.removeChild(taskDiv);
};
taskDiv.appendChild(checkbox);
taskDiv.appendChild(label);
taskDiv.appendChild(taskDateTime);
taskDiv.appendChild(removeButton);
taskList.appendChild(taskDiv);
taskInput.value = "";
}
document.getElementById("add-task").addEventListener("click", addTask);
setInterval(updateDateTime, 1000);
updateDateTime();