MCPcopy Create free account
hub / github.com/LinkedInLearning/javascript-essential-training-2832077 / lidToggle

Function lidToggle

09_05e/script.js:11–32  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9 * Add event listener to the lid-toggle button.
10 */
11const lidToggle = function () {
12 // Find the current backpack object in backpackObjectArray
13 let backpackObject = backpackObjectArray.find(
14 ({ id }) => id === this.parentElement.id
15 );
16
17 // Toggle lidOpen status
18 backpackObject.lidOpen == true
19 ? (backpackObject.lidOpen = false)
20 : (backpackObject.lidOpen = true);
21
22 // Toggle button text
23 this.innerText == "Open lid"
24 ? (this.innerText = "Close lid")
25 : (this.innerText = "Open lid");
26
27 // Set visible property status text
28 let status = this.parentElement.querySelector(".backpack__lid span");
29 status.innerText == "closed"
30 ? (status.innerText = "open")
31 : (status.innerText = "closed");
32};
33
34const backpackList = backpackObjectArray.map((backpack) => {
35 let backpackArticle = document.createElement("article");

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected