I’m stuck can someone help?
const list = document.querySelector(’.output ul’);
const searchInput = document.querySelector(’.output input’);
const searchBtn = document.querySelector(’.output button’);
list.innerHTML = ‘’;
let myHistory = [];
searchBtn.onclick = function() {
// we will only allow a term to be entered if the search input isn’t empty
if (searchInput.value !== ‘’) {
// number 1
searchInput.value.unshift();
// empty the list so that we don’t display duplicate entries
// the display is regenerated every time a search term is entered.
list.innerHTML = ‘’;
// loop through the array, and display all the search terms in the list
for (let i = 0; i < myHistory.length; i++) {
itemText = myHistory[i];
const listItem = document.createElement('li');
listItem.textContent = itemText;
list.appendChild(listItem);
}
// If the array length is 5 or more, remove the oldest search term
if (myHistory.length >= 5) {
// number 2
**myHistory.pop();**
}
// empty the search input and focus it, ready for the next term to be entered
searchInput.value = '';
searchInput.focus();
}
}