Skip to content

Instantly share code, notes, and snippets.

@crisgon
Created March 27, 2018 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crisgon/6e3cd1958a9e4a2034cbff53f8179485 to your computer and use it in GitHub Desktop.
Save crisgon/6e3cd1958a9e4a2034cbff53f8179485 to your computer and use it in GitHub Desktop.
Wikipedia FreeCodeCamp
(function(win, doc){
'use strict';
const $ = document.querySelector.bind(document);
const $url = "https://en.wikipedia.org/w/api.php?&origin=*&action=opensearch&namespace=0&limit=50&search=";
const $input_search = $('.input-search');
const $button_search = $('.button-search');
const $result_list = $('.results');
let results = [];
$button_search.addEventListener('click', function(event){
event.preventDefault();
startSearch($input_search.value);
});
async function startSearch(nameSearch){
let conect = await fetch($url + nameSearch);
let response = await conect.json();
await response.forEach(function(result){
results.push(...result)
});
console.log(results);
}
}(window, document));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment