I am trying to understand this Promise/fetch thing in js.
'use strict'
const list = document.querySelector('.list');
function test() {
return fetch('https://swapi.dev/api/films/', {
method: 'GET'
});
}
list.addEventListener('click', event => {
console.log('TEST');
alert("TEST");
});
test()
.then( function(response) {
return response.json();
})
.then(function(data) {
data.results.forEach(function(episode) {
const ul = document.createElement('ul');
ul.innerHTML = episode.title;
list.append(ul);
})
})
.list {
cursor: pointer;
}
<ul class="list"></ul>
I need to from a drop-down list, from all the STAR WARS episodes(done), and more of that (the part where the troubles start) by click on the episode it must return a list of ships, used in the episode.
As you can see from the link code above - I was able to return the list of episodes correctly, but I just don't know how to create the drop-down menu currently I'm out of ideas, should I make a ul-li list, where ul - episodes and ul - ships?
Kinda hard for me to figure this one out, please Obi-van, you are my last hope.