-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateelement-3.html
66 lines (48 loc) · 1.84 KB
/
createelement-3.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Workshop: CreateElement</title>
<style>
div#pets {
}
</style>
</head>
<body>
<div id="pets"></div>
<script>
const kids = [
{ 'petName': 'Wattled crane', 'owner': 'Bryant' },
{ 'petName': 'Devil, tasmanian', 'owner': 'Alejandro' },
{ 'petName': 'Mynah, common', 'owner': 'Nelie' },
{ 'petName': 'Dolphin, common', 'owner': 'Mariele' },
{ 'petName': 'Gray duiker', 'owner': 'Maddalena' },
{ 'petName': 'Crab (unidentified)', 'owner': 'Lucine' },
{ 'petName': 'Ant (unidentified)', 'owner': 'Lorianna' },
{ 'petName': 'Bison, american', 'owner': 'Tommie' },
{ 'petName': 'Yellow mongoose', 'owner': 'Vivyan' },
{ 'petName': 'Carpet snake', 'owner': 'Veda' },
{ 'petName': 'Lesser mouse lemur', 'owner': 'Isidor' },
];
let petsDiv = document.getElementById('pets');
for(let i = 0; i< kids.length;i++){
let article = document.createElement('article');
let owner = document.createElement('h3');
let pet = document.createElement('p');
owner.textContent = kids[i].owner;
pet.textContent = kids[i].petName;
article.appendChild(owner);
article.appendChild(pet);
petsDiv.appendChild(article);
}
</script>
<!-- You can work in the html or in a separate js file. Like:
1) Create an <article> element for each kid
2) Create a <h3> and a <p> element for each article and append them as a child to the <article>
- The H3 should contain the owner's name
- The p should contain the pet's name
3) Add the article to the pets div.
OR
<script src="createelement-3.js"></script> -->
</body>
</html>