scrimba
JavaScript Challenges
Build a Search Bar: Comparing the search query vs. the DOM names
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Build a Search Bar: Comparing the search query vs. the DOM names
AboutCommentsNotes
Build a Search Bar: Comparing the search query vs. the DOM names
Expand for more info
index.js
run
preview
console
/*
Task: Comparing the search query vs. the DOM names
1. Create a conditional that checks if currentName is equal to the user's search query!
2. If our conditional returns true, set the display style on 'allNamesDOMCollection[counter]' to be a block element
3. If our conditional falls into the else, we have no match! So set the display style to 'none'

Helpers: use the methods 'includes' for objective 1
- The includes() method determines whether one string may be found within another string, returning true or false as appropriate.
*/
document.getElementById("searchInput").addEventListener("keyup", function(event) {
let searchQuery = event.target.value.toLowerCase();
let allNamesDOMCollection = document.getElementsByClassName('name');

for (let counter = 0; counter < allNamesDOMCollection.length; counter++) {
const currentName = allNamesDOMCollection[counter].textContent.toLowerCase();
console.log(currentName);
}
});
Console
/index.html
-4:54