I'm having an issue with an app in JavaScript.
I seem to randomly have an issue with my array not showing up in JavaScript - I've tried remaking the program several times and sometimes it works, sometimes it doesn't. This is a sample of my latest failed attempt. Could anyone tell me exactly why the array is not appearing in the browser? I've tried to set up a filter and form. I'm trying to create a list with a filter objects in the array.
<!DOCTYPE html>
<html>
<head>
<title>Work</title>
</head>
<body>
<h1>Todos</h1>
<todo class="tddiv"></todo>
<input type="text" class="todo" placeholder="type here">
<form class="todo-form">
<input type="text" placeholder="input-todo-text" name="addTodo">
<button>Submit Text</button>
</form>
<script src="script.js"></script>
</body>
</html>
JavaScript
let todos = [{
text: 'Order cat food',
completed: false
}, {
text: 'Clean kitchen',
completed: true
}, {
text: 'Buy food',
completed: true
}, {
text: 'Do work',
completed: false
}, {
text: 'Exercise',
completed: true
}]
const filters = {
searchText: ''
}
const renderTodos = function(todos, filters) {
const filter = todos.filter(function(todo) {
return
todo.text.toLowerCase().includes(filters.searchText.toLowerCase())
})
document.querySelector('.tddiv').innerHTML = ''
filter.forEach(function(a) {
const add = document.createElement('p')
add.textContent = a.text
document.querySelector('.tddiv').appendChild(add)
})
}
renderTodos(todos, filters)
document.querySelector('.text').addEventListener('input', function(e) {
filters.searchText = e.target.value
renderTodos(todos, filters)
})
eventobject doesn't have aelementsproperty. Did you mean to access theelementsproperty of the form element?textcheck this linedocument.querySelector('.text')