-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
52 lines (45 loc) · 1.27 KB
/
Copy pathscript.js
File metadata and controls
52 lines (45 loc) · 1.27 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
const tasks = []
console.log('tasks',tasks)
function addTask(){
console.log('add task')
const taskInput = document.getElementById('taskInput');
const priorityInput = document.getElementById('priorityInput');
const priority = parseInt(priorityInput.value);
const task = taskInput.value.trim();
console.log('task',task)
if(!task){
alert('Please enter a task');
return;
}
let importance = "";
if(priority <= 2){
importance = "high";
}else if (priority === 3){
importance = "medium";
}else{
importance = "low";
}
const newTask = {
'task' : task,
'priority' : priority,
'importance':importance
}
tasks.push(newTask);
taskInput.value = "";
renderTasks();
}
function renderTasks() {
// const arr = ['a','b','c'];
// console.log('arr length', arr.length)
// max index = arr.length - 1
const taskList = document.getElementById('taskList');
taskList.innerHTML = "";
for (let i = 0; i < tasks.length; i++) {
const item = tasks[i];
// tasks[0]
const div = document.createElement("div");
div.className = "task " + item.importance;
div.textContent = item.task + " (Priority " + item.priority + ")";
taskList.appendChild(div);
}
}