If you look at the solution code, you'll find one way of creating this functionality. Let's break it down.
Just like in our Pokémon game, we'll use a class. Its constructor will store a few various pieces of information, as well as add an event listener to the Go button:
class SWAPI {
constructor() {
this.loader = document.querySelector('#loader')
this.people = []
document.querySelector('.go').addEventListener('click', (e) => {
this.getPerson(document.querySelector('#peopleSelector').value)
})
}
Next, as we know we'll be making multiple calls to SWAPI, we can make ourselves a helper function to facilitate this work. It may take four arguments: the SWAPI API URL, an array of previous results (useful if we're paginating!), and Promise-like resolve and reject parameters:
fetchThis(url, arr, resolve, reject) {
fetch(url)
.then((response) => {
return response.json()
...