const notes = [{},{
title: 'Learn to code',
body: 'I would like to be good at javascript'
}, {
title: 'Build Muscle',
body: 'Exercise. Eating better'
}, {
title: 'Gaming PC',
body: 'Build the new parts of my pc'
}]
const filters = {
searchText: ''
}
const renderNotes = function (notes, filters){
const filteredNotes = notes.filter(function(note){
return note.title.toLowerCase().includes(filters.searchText.toLowerCase())
})
console.log(filteredNotes);
}
renderNotes(notes, filters)
document.querySelector('#create-note').addEventListener('click', function(e){
e.target.textContent = 'The button was clicked'
})
document.querySelector('#remove-all').addEventListener('click', function(){
document.querySelectorAll('.note').forEach(function( note){
note.remove()
})
})
document.querySelector('#search-text').addEventListener('input', function(e){
filters.searchText = e.target.value
renderNotes(notes, filters)
})
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>notes</title>
</head>
<body>
<h1>Notes app</h1>
<h2>Take notes and never forget</h2>
<input id="search-text" type="text" placeholder="Enter">
<p class="note">App was made by Mani</p>
<p class="note">KFC is peng</p>
<button id="create-note">Click Here</button>
<button id="remove-all">Remove All Notes</button>
<script src="notes-app.js"></script>
</body>
</html>
我似乎找不到问题,我确定我没有遗漏任何东西。我确保正确放置了括号,并正确键入了函数中的所有内容。我是一个初学者,因此很抱歉这是一个基本问题-有人可以帮忙吗?
答案 0 :(得分:1)
您应该删除代码中的第一个空对象
const notes = [{},{
const notes = [{