-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
34 lines (27 loc) · 1.22 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const blogContainer = document.getElementById('maincon');
const apiUrl = "https://dev.to/api/articles?username=uthsob_cb";
fetch(apiUrl)
.then((res) => res.json())
.then((data) => {
data.forEach((article) => {
// Create elements for each article
const articleElement = document.createElement('div');
articleElement.classList.add('card');
const titleElement = document.createElement('a');
titleElement.href = article.url;
titleElement.classList.add('blog-title');
titleElement.textContent = article.title;
const dateElement = document.createElement('small');
dateElement.classList.add('blog-footer');
dateElement.textContent = new Date(article.published_at).toLocaleDateString();
const descriptionElement = document.createElement('p');
descriptionElement.textContent = article.description;
articleElement.appendChild(titleElement);
articleElement.appendChild(dateElement);
articleElement.appendChild(descriptionElement);
blogContainer.appendChild(articleElement);
});
})
.catch((err) => {
console.log(err);
});