-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex2.html
49 lines (38 loc) · 1.52 KB
/
index2.html
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Articles</h1>
<div id="articleList">
</div>
<script>
const url = "https://mock-data-api.firebaseio.com/news/articles.json"
const articleListElement = document.getElementById("articleList")
function renderArticleItem(articleItem) {
const articleItemElement = document.createElement("div")
const titleElement = document.createElement("h2")
const descriptionElement = document.createElement("p")
const imageElement = document.createElement("img")
titleElement.innerText = articleItem.title
descriptionElement.innerText = articleItem.description
imageElement.src = articleItem.urlToImage
imageElement.alt = articleItem.title
articleItemElement.appendChild(imageElement)
articleItemElement.appendChild(titleElement)
articleItemElement.appendChild(descriptionElement)
articleListElement.appendChild(articleItemElement)
}
function renderArticleList(articleList) {
articleList.forEach(articleItem => {
renderArticleItem(articleItem)
})
}
fetch(url)
.then(response => response.json())
.then(data => {
renderArticleList(data)
})
</script>
</body>
</html>