Created
March 27, 2018 01:51
-
-
Save crisgon/6e3cd1958a9e4a2034cbff53f8179485 to your computer and use it in GitHub Desktop.
Wikipedia FreeCodeCamp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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