-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·86 lines (76 loc) · 1.91 KB
/
script.js
File metadata and controls
executable file
·86 lines (76 loc) · 1.91 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* Loops Aplenty!
* @link https://developer.mozilla.org/en-US/docs/Glossary/Callback_function
*/
const stuff = ["piggy", "headlamp", "pen", "pencil", "eraser", "water bottle"];
const nestedObjects = {
item01: {
name: "piggy",
type: "toy",
weight: 30,
},
item02: {
name: "headlamp",
type: "equipment",
weight: 120,
},
item03: {
name: "pen",
type: "tool",
weight: 30,
},
item04: {
name: "pencil",
type: "tool",
weight: 30,
},
item05: {
name: "eraser",
type: "tool",
weight: 40,
},
item03: {
name: "water bottle",
type: "equipment",
weight: 1300,
},
};
const article = document.querySelector("article");
let stuffList = document.createElement("ul");
/**
* for loop
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for
*/
for (let i = 0; i < stuff.length; i++) {
let listItem = document.createElement("li");
listItem.innerHTML = stuff[i];
stuffList.append(listItem);
}
/**
* for...of loop and arrays
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of
*/
// for (const item of stuff) {
// let listItem = document.createElement("li");
// listItem.innerHTML = item;
// stuffList.append(listItem);
// }
/**
* foreach array method
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
*/
// stuff.forEach((item) => {
// let listItem = document.createElement("li");
// listItem.innerHTML = item;
// stuffList.append(listItem);
// });
/**
* for...in loop and objects
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in
*/
// for (const singleObject in nestedObjects) {
// let listItem = document.createElement("li");
// listItem.innerHTML = `Name: ${nestedObjects[singleObject].name}`;
// stuffList.append(listItem);
// }
article.append(stuffList);