Changed around line 1
+ const searchInput = document.getElementById('search-input');
+ const suggestionsDiv = document.getElementById('suggestions');
+ const searchButton = document.getElementById('search-button');
+ const resultsDiv = document.getElementById('results');
+
+ const dummySuggestions = [
+ 'JavaScript tutorials',
+ 'CSS animations',
+ 'HTML5 features',
+ 'Web development trends',
+ 'Responsive design techniques',
+ 'Frontend frameworks',
+ 'Backend development',
+ 'Full stack development',
+ 'Web accessibility guidelines',
+ 'Progressive web apps'
+ ];
+
+ const dummyResults = [
+ {
+ title: 'JavaScript Tutorial - W3Schools',
+ url: '#',
+ snippet: 'JavaScript is the programming language of the Web. JavaScript is easy to learn. This tutorial will teach you JavaScript from basic to advanced.'
+ },
+ {
+ title: 'Learn JavaScript - freeCodeCamp',
+ url: '#',
+ snippet: 'Learn JavaScript and Javascript arrays to build interactive websites and pages that adapt to every device. Add dynamic behavior, store information, and handle requests and responses.'
+ },
+ {
+ title: 'The Modern JavaScript Tutorial',
+ url: '#',
+ snippet: 'How it\'s done now. From the basics to advanced topics with simple, but detailed explanations. Main course contains 2 parts which cover JavaScript as a programming language and working with a browser.'
+ }
+ ];
+
+ searchInput.addEventListener('input', () => {
+ const query = searchInput.value.toLowerCase();
+ if (query.length > 0) {
+ const filteredSuggestions = dummySuggestions.filter(suggestion =>
+ suggestion.toLowerCase().includes(query)
+ );
+ showSuggestions(filteredSuggestions);
+ } else {
+ hideSuggestions();
+ }
+ });
+
+ function showSuggestions(suggestions) {
+ suggestionsDiv.innerHTML = suggestions
+ .map(suggestion => `
${suggestion}
`)
+ .join('');
+ suggestionsDiv.style.display = 'block';
+ }
+
+ function hideSuggestions() {
+ suggestionsDiv.style.display = 'none';
+ }
+
+ suggestionsDiv.addEventListener('click', (e) => {
+ if (e.target.classList.contains('suggestion-item')) {
+ searchInput.value = e.target.textContent;
+ hideSuggestions();
+ performSearch();
+ }
+ });
+
+ searchButton.addEventListener('click', performSearch);
+
+ function performSearch() {
+ const query = searchInput.value;
+ if (query) {
+ // Simulate search results
+ resultsDiv.innerHTML = dummyResults
+ .map(result => `
+ `)
+ .join('');
+ } else {
+ resultsDiv.innerHTML = '
Please enter a search term.
';
+ }
+ }