-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (24 loc) · 879 Bytes
/
Copy pathscript.js
File metadata and controls
28 lines (24 loc) · 879 Bytes
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
let todos = [
{id: 1, task: 'first Todo'},
{id: 2, task: 'second Todo'},
{id: 3, task: 'thord Todo'},
{id: 4, task: 'fourth Todo'}
]
const todoList = document.getElementById("todoList")
function showTodos(){
todos.forEach(function (todo, index){
const todoItem = document.createElement('li')
todoItem.textContent = todo.task
// console.log('run ho rha')
todoList.appendChild(todoItem)
})
}
showTodos()
function addTodo(){
let invalue = document.getElementById("invalue").value
const newTodo = {id:5, task: invalue} // creating the new todo obj
todos.push(newTodo) // pushing the new todo in the array
todoList.textContent = '' // making empty that ul tag in html
document.getElementById("invalue").value = ''
showTodos() // showing the new array of all todo
}