-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
47 lines (39 loc) · 1.31 KB
/
script.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
const classNames = {
TODO_ITEM: 'todo-container',
TODO_CHECKBOX: 'todo-checkbox',
TODO_TEXT: 'todo-text',
TODO_DELETE: 'todo-delete',
}
const list = document.getElementById('todo-list')
const itemCountSpan = document.getElementById('item-count')
const uncheckedCountSpan = document.getElementById('unchecked-count')
uncheckedCountSpan_int = 0
itemCountSpan_int = 0
var todos = []
function newTodo() {
//alert('New TODO button clicked!')
var li = document.createElement("li")
var text = prompt('Please, enter TODO title: ', 'Do shit')
if (text != "" && text != null) {
li.appendChild(document.createTextNode(text))
checkbox = document.createElement("INPUT")
li.appendChild(checkbox)
todos.push(checkbox)
checkbox.setAttribute('type', 'checkbox')
checkbox.setAttribute('class', classNames.TODO_CHECKBOX)
checkbox.setAttribute('onclick', 'check()')
li.setAttribute('class', classNames.TODO_ITEM)
list.append(li)
uncheckedCountSpan_int += 1
uncheckedCountSpan.innerHTML = uncheckedCountSpan_int
itemCountSpan_int += 1
itemCountSpan.innerHTML = itemCountSpan_int
}
}
function check() {
uncheckedCountSpan_int = 0
for (let i = 0; i < todos.length; i++) {
if (todos[i].checked == false) uncheckedCountSpan_int += 1
}
uncheckedCountSpan.innerHTML = uncheckedCountSpan_int
}