-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·62 lines (55 loc) · 1.37 KB
/
script.js
File metadata and controls
executable file
·62 lines (55 loc) · 1.37 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
/**
* Create a Backpack object, populate some HTML to display its properties.
*/
// Single line comment
/* Multi-line comment
See! this line is also commented out! */
/**
* function updateBackpack()
* Outputs HTML
* @param {string} update
*/
const updateBackpack = (update) => {
let main = document.querySelector("main"); // main is an element
main.innerHTML = markup(backpack);
console.info(update);
};
const backpack = {
name: "Everyday Backpack",
volume: 30,
color: "grey",
pocketNum: 15,
strapLength: {
left: 26,
right: 26,
},
lidOpen: false,
toggleLid: function (lidStatus) {
this.lidOpen = lidStatus;
updateBackpack(`Lid status changed.`);
},
newStrapLength: function (lengthLeft, lengthRight) {
this.strapLength.left = lengthLeft;
this.strapLength.right = lengthRight;
updateBackpack(`Strap lengths updated.`);
},
};
const markup = (backpack) => {
return `
<div>
<h3>${backpack.name}</h3>
<ul>
<li>Volume: ${backpack.volume}</li>
<li>Color: ${backpack.color}</li>
<li>Number of pockets: ${backpack.pocketNum}</li>
<li>Strap lengths: L: ${backpack.strapLength.left}, R: ${
backpack.strapLength.right
} </li>
<li>Top lid: ${backpack.lidOpen ? "Open" : "Closed"}</li>
</ul>
</div>
`;
};
const main = document.createElement("main");
main.innerHTML = markup(backpack);
document.body.appendChild(main);