I'm trying to display a list of songs my band plays on a new website. The user enters a song name (in the input tag called "liveSearchBox") and clicks the "findSong" button. If we play the song, I want to alert "Yes, we play it!". If we don't, I want to alert "Sorry, we don't play it." I've been trying for hours to figure out the solution, but am not advanced enough yet. Thanks for any help!
Here's my HTML code:
<div class="live-search-list">
<input type="text" id="liveSearchBox" placeholder=" Search Songs or Artist">
<button id="findSong"> Click to Find!</button>
<ul id="songList">
<li class="song"> Margaritaville</li>
<li class="song"> Boys of Summer</li>
<li class="song"> Somebody Like You</li>
</ul>
</div>
And here's my Javascript:
var songList = ["Margaritaville","Boys of Summer","Somebody Like You"];
var findButton = document.getElementById("findSong");
var songQuery = document.getElementById("liveSearchBox");
var songListItem = document.getElementsByClassName("song");
findButton.onclick = function(){
for (var i = 0; i<songList.length; i++){
if (songQuery.value === songList[i]){
alert('Yes, we play "' + songQuery.value + '"!');
} else {
i++;
}
}
};