async function getArticles(){
const response = await fetch('https://gorest.co.in/public/v1/posts');
const responses = await response.json()
responses.data.forEach((article) => {//console.log(article.title)
let titles = article.title
console.log(titles)
return titles
});
}
getArticles()
let ul = document.createElement('ul');
document.body.append(ul);
for(x=0; x<20; x++){
const art = document.createElement('li');
ul.append(art);
const name = document.createElement('a')
art.append(name)
}
fetch('https://gorest.co.in/public/v1/posts')
.then(r => r.json())
.then(r => {
// собираем разметку
document.body.insertAdjacentHTML('beforeend', `
<ul>${r.data.map(n => `
<li>
<a>${n.title}</a>
</li>`).join('')}
</ul>
`);
// или, создаём элементы напрямую
const ul = document.createElement('ul');
ul.append(...r.data.map(n => {
const li = document.createElement('li');
const a = document.createElement('a');
a.textContent = n.title;
li.append(a);
return li;
}));
document.body.append(ul);
});
const newLink = document.createElement('a');
newLink.href = '//google.com';
newLink.textContent = 'гугл';
newLink.title = 'поисковая система гугл';
document.body.append(newLink);