Top 5 searches

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();

}
}

Hello @cesar_fitch

could you share your full code on https://codepen.io/ or https://jsfiddle.net/ or any other site so it be easier to detect the issue

and have a nice day :slight_smile:

Same Problem here. How to resolve this problem ?

Hello @Himansu_Naik

could you please give me the link to the task and also a link to your code on any site like codepen or jsfiddle

and have a nice day :slight_smile: