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

Function lidToggle

09_05/script.js:11–31  ·  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
13 // Find the current backpack object in backpackObjectArray
14 let backpackObject = backpackObjectArray.find( ({ id }) => id === this.parentElement.id );
15
16 // Toggle lidOpen status
17 backpackObject.lidOpen == true
18 ? backpackObject.lidOpen = false
19 : backpackObject.lidOpen = true;
20
21 // Toggle button text
22 this.innerText == "Open lid"
23 ? this.innerText = "Close lid"
24 : this.innerText = "Open lid";
25
26 // Set visible property status text
27 let status = this.parentElement.querySelector(".backpack__lid span");
28 status.innerText == "closed"
29 ? (status.innerText = "open")
30 : (status.innerText = "closed");
31}
32
33/**
34 * - Loop through backpackObjectArray

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected