Проблем със задача 05. Accordion от Asynchronous Programming - Exercise
Здравейте, получавам 33/100 и последния бутон не работи, някой може ли да ми помогне ?
Благодаря :)
задача: https://judge.softuni.org/Contests/Practice/Index/3466#4
код:
async function solution() {
const main = document.getElementById('main');
const url = `http://localhost:3030/jsonstore/advanced/articles/list`;
const response = await fetch(url);
const data = await response.json();
data.forEach(x => {
const divAccordion = document.createElement('div')
divAccordion.setAttribute('class', 'accordion')
divAccordion.innerHTML += `
<div class="head">
<span>${x.title}</span>
<button id="${x._id}">More</button>
</div>
<div class="extra">
<p></p>
</div>
`
document.querySelectorAll('button').forEach(x => x.addEventListener('click', toggle));
main.appendChild(divAccordion)
});
async function toggle(event) {
const accordion = event.target.parentNode.parentNode;
const id = event.target.id;
const p = accordion.children[1].firstChild;
const extra = accordion.children[1];
const url = `http://localhost:3030/jsonstore/advanced/articles/details/${id}`;
const response = await fetch(url);
const data = await response.json();
p.textContent = data.content;
const inHidden = event.target.textContent == 'More';
extra.style.display = inHidden ? 'block' : 'none';
event.target.textContent = inHidden ? 'Less' : 'More';
}
}
solution();
Благодаря !