Сообщество IT-специалистов
Ответы на любые вопросы об IT
Профессиональное развитие в IT
Удаленная работа для IT-специалистов
const URL = 'https://ajax.test-danit.com/api/swapi/'; const root = document.querySelector('#root'); class Requests { constructor(url) { this.url = url; } getEntity(entity) { return fetch(this.url + `${entity}`).then(response => { return response.json(); }); } // getDeepEntity(entity, keyword) { // return fetch(this.url + `${entity}?search=${keyword}`).then(response => { // return response.json(); // }); // } } class StarWars { constructor(root) { this.root = root; } renderEntity(data) { const infoEntity = document.createElement('div'); const infoItems = data.map(({ name, episodeId, openingCrawl, characters }) => { const entityContainer = document.createElement('div'); const title = document.createElement('h4'); title.textContent = `Film name: "${name}"`; // const people = characters.map(elem => { // console.log(elem); // }); const id = document.createElement('p'); id.textContent = `Episode: ${episodeId}`; id.style.fontStyle = 'italic'; const description = document.createElement('p'); description.textContent = `Description:${openingCrawl}`; entityContainer.append(title, starWarsChar, id, description); return entityContainer; }); infoEntity.append(...infoItems); this.root.append(infoEntity); } } class StarWarsChar { renderChar(data) { const listChar = document.createElement('ul'); data.forEach(elem => { //console.log(elem.name); let li = document.createElement('li'); li.textContent = elem.name; listChar.append(li); console.log(listChar); }); } } const request = new Requests(URL); const starWars = new StarWars(root); const starWarsChar = new StarWarsChar(); // request // .getEntity('films') // .then(data => { // console.log(data); // starWars.renderEntity(data); // }) // .catch(e => { // console.log(e); // }); request.getEntity('films').then(data => { //console.log(data); starWars.renderEntity(data); //console.log(starWarsChar.renderChar(data)); }); request.getEntity('people').then(data => { console.log(data); starWarsChar.renderChar(data); });
<div class="btns"> <button class="stop" >Stop</button> <button class="continue" >Continue</button> </div>
document.querySelector('.stop').addEventListener('click', function() { clearInterval(timer) }) stop.disabled = true