+ You can write JavaScript directly inside an HTML document using the
+ script element. The element can be added in the
+ head section or inside the body element.
+
+ If you're carrying a heavy load, you can't find a better tool than a
+ backpack. Distributing the weight evenly across your shoulders, back,
+ and hips, the backpack lets you use the natural frame of your body to
+ literally shoulder the weight while your legs do the
+ carrying.
+
+
+
+
+
+
diff --git a/05_09/script.js b/05_09/script.js
new file mode 100755
index 00000000..31e52a1b
--- /dev/null
+++ b/05_09/script.js
@@ -0,0 +1,53 @@
+/**
+ * Traverse the DOM tree using querySelector() and querySelectorAll()
+ * @link https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelector
+ * @link https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelectorAll
+ */
+
+import Backpack from "./Backpack.js";
+
+const everydayPack = new Backpack(
+ "Everyday Backpack",
+ 30,
+ "grey",
+ 15,
+ 26,
+ 26,
+ false,
+ "December 5, 2018 15:00:00 PST",
+ "../assets/images/everyday.svg"
+);
+
+const content = `
+
+
+
+
+
${everydayPack.name}
+
+
Volume: ${
+ everydayPack.volume
+ }l
+
Color: ${
+ everydayPack.color
+ }
+
Age: ${everydayPack.backpackAge()} days old
+
Number of pockets: ${
+ everydayPack.pocketNum
+ }
+
Left strap length: ${
+ everydayPack.strapLength.left
+ } inches
+
Right strap length: ${
+ everydayPack.strapLength.right
+ } inches
+ If you're carrying a heavy load, you can't find a better tool than a
+ backpack. Distributing the weight evenly across your shoulders, back,
+ and hips, the backpack lets you use the natural frame of your body to
+ literally shoulder the weight while your legs do the
+ carrying.
+
+
+
+
+
+
diff --git a/05_09e/script.js b/05_09e/script.js
new file mode 100755
index 00000000..83db8e65
--- /dev/null
+++ b/05_09e/script.js
@@ -0,0 +1,58 @@
+/**
+ * Traverse the DOM tree using querySelector() and querySelectorAll()
+ * @link https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelector
+ * @link https://developer.mozilla.org/en-US/docs/Web/API/Element/querySelectorAll
+ */
+
+import Backpack from "./Backpack.js";
+
+const everydayPack = new Backpack(
+ "Everyday Backpack",
+ 30,
+ "grey",
+ 15,
+ 26,
+ 26,
+ false,
+ "December 5, 2018 15:00:00 PST",
+ "../assets/images/everyday.svg"
+);
+
+const content = `
+
+
+
+
+
${everydayPack.name}
+
+
Volume: ${
+ everydayPack.volume
+ }l
+
Color: ${
+ everydayPack.color
+ }
+
Age: ${everydayPack.backpackAge()} days old
+
Number of pockets: ${
+ everydayPack.pocketNum
+ }
+
Left strap length: ${
+ everydayPack.strapLength.left
+ } inches
+
Right strap length: ${
+ everydayPack.strapLength.right
+ } inches
+ If you're carrying a heavy load, you can't find a better tool than a
+ backpack. Distributing the weight evenly across your shoulders, back,
+ and hips, the backpack lets you use the natural frame of your body to
+ literally shoulder the weight while your legs do the
+ carrying.
+
+
+
+
+
+
diff --git a/05_10/script.js b/05_10/script.js
new file mode 100755
index 00000000..84768771
--- /dev/null
+++ b/05_10/script.js
@@ -0,0 +1,62 @@
+/**
+ * Challenge: Add a new element
+ * - In JavaScript, create a new element to hold a navigation menu
+ * - Add an unordered list and a series of no less than five links to the list
+ * - Use single words like “home”, “about”, etc for the list items and set the src attribute to # for simplicity
+ * - Add the new navigation element to the DOM directly after the header
+ * - Write basic CSS and add classes as necessary to create a horizontal layout for the menu.
+ * - A tip: Use either display flex or display grid to create the horizontal menu.
+ */
+
+import Backpack from "./Backpack.js";
+
+const everydayPack = new Backpack(
+ "Everyday Backpack",
+ 30,
+ "grey",
+ 15,
+ 26,
+ 26,
+ false,
+ "December 5, 2018 15:00:00 PST",
+ "../assets/images/everyday.svg"
+);
+
+const content = `
+
+
+
+
+
Everyday Backpack
+
+
Volume: ${
+ everydayPack.volume
+ }l
+
Color: ${
+ everydayPack.color
+ }
+
Age: ${everydayPack.backpackAge()} days old
+
Number of pockets: ${
+ everydayPack.pocketNum
+ }
+
Left strap length: ${
+ everydayPack.strapLength.left
+ } inches
+
Right strap length: ${
+ everydayPack.strapLength.right
+ } inches
+ If you're carrying a heavy load, you can't find a better tool than a
+ backpack. Distributing the weight evenly across your shoulders, back,
+ and hips, the backpack lets you use the natural frame of your body to
+ literally shoulder the weight while your legs do the
+ carrying.
+
+
+
+
+
+
diff --git a/05_11/script.js b/05_11/script.js
new file mode 100755
index 00000000..5878fd8c
--- /dev/null
+++ b/05_11/script.js
@@ -0,0 +1,81 @@
+/**
+ * Solution: Add a new element
+ * - In JavaScript, create a new element to hold a navigation menu
+ * - Add an unordered list and a series of no less than five links to the list
+ * - Use single words like “home”, “about”, etc for the list items and set the src attribute to # for simplicity
+ * - Add the new navigation element to the DOM directly after the header
+ * - Write basic CSS and add classes as necessary to create a horizontal layout for the menu.
+ * - A tip: Use either display flex or display grid to create the horizontal menu.
+ */
+
+import Backpack from "./Backpack.js";
+
+const everydayPack = new Backpack(
+ "Everyday Backpack",
+ 30,
+ "grey",
+ 15,
+ 26,
+ 26,
+ false,
+ "December 5, 2018 15:00:00 PST",
+ "../assets/images/everyday.svg"
+);
+
+const content = `
+
+
+
+
+
Everyday Backpack
+
+
Volume: ${
+ everydayPack.volume
+ }l
+
Color: ${
+ everydayPack.color
+ }
+
Age: ${everydayPack.backpackAge()} days old
+
Number of pockets: ${
+ everydayPack.pocketNum
+ }
+
Left strap length: ${
+ everydayPack.strapLength.left
+ } inches
+
Right strap length: ${
+ everydayPack.strapLength.right
+ } inches
+
Lid status: ${
+ everydayPack.lidOpen
+ }
+
+
+`;
+
+const main = document.querySelector(".maincontent");
+
+const newArticle = document.createElement("article");
+newArticle.classList.add("backpack");
+newArticle.setAttribute("id", "everyday");
+newArticle.innerHTML = content;
+
+main.append(newArticle);
+
+/**
+ * Add a navigation section to the DOM
+ */
+const navContent = `
+
+ If you're carrying a heavy load, you can't find a better tool than a
+ backpack. Distributing the weight evenly across your shoulders, back,
+ and hips, the backpack lets you use the natural frame of your body to
+ literally shoulder the weight while your legs do the
+ carrying.
+
+
+
+
+
+
diff --git a/08_11/script.js b/08_11/script.js
new file mode 100755
index 00000000..45560f38
--- /dev/null
+++ b/08_11/script.js
@@ -0,0 +1,56 @@
+/**
+ * Create a new element and append it to the element.
+ * @link https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement
+ * @link https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/append
+ */
+
+import Backpack from "./Backpack.js";
+
+const everydayPack = new Backpack(
+ "Everyday Backpack",
+ 30,
+ "grey",
+ 15,
+ 26,
+ 26,
+ false,
+ "December 5, 2018 15:00:00 PST",
+ "../assets/images/everyday.svg"
+);
+
+const content = `
+
+
+
+
${everydayPack.name}
+
+
Volume: ${
+ everydayPack.volume
+ }l
+
Color: ${
+ everydayPack.color
+ }
+
Age: ${everydayPack.backpackAge()} days old
+
Number of pockets: ${
+ everydayPack.pocketNum
+ }
+
Left strap length: ${
+ everydayPack.strapLength.left
+ } inches
+
Right strap length: ${
+ everydayPack.strapLength.right
+ } inches
+ If you're carrying a heavy load, you can't find a better tool than a
+ backpack. Distributing the weight evenly across your shoulders, back,
+ and hips, the backpack lets you use the natural frame of your body to
+ literally shoulder the weight while your legs do the
+ carrying.
+
+
+
+
+
+
diff --git a/08_11e/script.js b/08_11e/script.js
new file mode 100755
index 00000000..1bb9447f
--- /dev/null
+++ b/08_11e/script.js
@@ -0,0 +1,56 @@
+/**
+ * Create a new element and append it to the element.
+ * @link https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement
+ * @link https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/append
+ */
+
+import Backpack from "./Backpack.js";
+
+const everydayPack = new Backpack(
+ "Everyday Backpack",
+ 30,
+ "grey",
+ 15,
+ 26,
+ 26,
+ false,
+ "December 5, 2018 15:00:00 PST",
+ "../assets/images/everyday.svg"
+);
+
+const content = `
+
+
+
+
${everydayPack.name}
+
+
Volume: ${
+ everydayPack.volume
+ }l
+
Color: ${
+ everydayPack.color
+ }
+
Age: ${everydayPack.backpackAge()} days old
+
Number of pockets: ${
+ everydayPack.pocketNum
+ }
+
Left strap length: ${
+ everydayPack.strapLength.left
+ } inches
+
Right strap length: ${
+ everydayPack.strapLength.right
+ } inches
+ If you're carrying a heavy load, you can't find a better tool than a
+ backpack. Distributing the weight evenly across your shoulders, back,
+ and hips, the backpack lets you use the natural frame of your body to
+ literally shoulder the weight while your legs do the
+ carrying.
+
+
+
+
+
+
diff --git a/08_12/script.js b/08_12/script.js
new file mode 100755
index 00000000..3fa728d7
--- /dev/null
+++ b/08_12/script.js
@@ -0,0 +1,62 @@
+/**
+ * Create a new element and append it to the element.
+ * @link https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement
+ * @link https://developer.mozilla.org/en-US/docs/Web/API/ParentNode/append
+ */
+
+import Backpack from "./Backpack.js";
+
+const everydayPack = new Backpack(
+ "Everyday Backpack",
+ 30,
+ "grey",
+ 15,
+ 26,
+ 26,
+ false,
+ "December 5, 2018 15:00:00 PST",
+ "../assets/images/everyday.svg"
+);
+
+const content = `
+
+
+
+
${everydayPack.name}
+
+
Volume: ${
+ everydayPack.volume
+ }l
+
Color: ${
+ everydayPack.color
+ }
+
Age: ${everydayPack.backpackAge()} days old
+
Number of pockets: ${
+ everydayPack.pocketNum
+ }
+
Left strap length: ${
+ everydayPack.strapLength.left
+ } inches
+
Right strap length: ${
+ everydayPack.strapLength.right
+ } inches
+ If you're carrying a heavy load, you can't find a better tool than a
+ backpack. Distributing the weight evenly across your shoulders, back,
+ and hips, the backpack lets you use the natural frame of your body to
+ literally shoulder the weight while your legs do the
+ carrying.
+
+ If you're carrying a heavy load, you can't find a better tool than a
+ backpack. Distributing the weight evenly across your shoulders, back,
+ and hips, the backpack lets you use the natural frame of your body to
+ literally shoulder the weight while your legs do the
+ carrying.
+
+stuffItems.forEach((item) => {
+ stuffList.append(item);
+});
+
+// Append stuffList to the
+article.append(stuffList);
diff --git a/08_16/components/Backpack.js b/08_16/components/Backpack.js
new file mode 100755
index 00000000..65236404
--- /dev/null
+++ b/08_16/components/Backpack.js
@@ -0,0 +1,45 @@
+// Set up the Backpack class
+class Backpack {
+ constructor(
+ id,
+ name,
+ volume,
+ color,
+ pocketNum,
+ strapLengthL,
+ strapLengthR,
+ lidOpen,
+ dateAcquired,
+ image
+ ) {
+ this.id = id;
+ this.name = name;
+ this.volume = volume;
+ this.color = color;
+ this.pocketNum = pocketNum;
+ this.strapLength = {
+ left: strapLengthL,
+ right: strapLengthR,
+ };
+ this.lidOpen = lidOpen;
+ this.dateAcquired = dateAcquired;
+ this.image = image;
+ }
+ toggleLid(lidStatus) {
+ this.lidOpen = lidStatus;
+ }
+ newStrapLength(lengthLeft, lengthRight) {
+ this.strapLength.left = lengthLeft;
+ this.strapLength.right = lengthRight;
+ }
+ backpackAge() {
+ let now = new Date();
+ let acquired = new Date(this.dateAcquired);
+ let elapsed = now - acquired; // elapsed time in milliseconds
+ let daysSinceAcquired = Math.floor(elapsed / (1000 * 3600 * 24));
+ return daysSinceAcquired;
+ }
+}
+
+// Export the Backpack class to be used by other files
+export default Backpack;
diff --git a/08_16/components/data.js b/08_16/components/data.js
new file mode 100755
index 00000000..4c16376f
--- /dev/null
+++ b/08_16/components/data.js
@@ -0,0 +1,36 @@
+// Import the Backpack class so we can make new Backpack objects.
+import Backpack from "./Backpack.js";
+
+// Create new Backpack object
+const everydayPack = new Backpack(
+ "pack01",
+ "Everyday Backpack",
+ 30,
+ "grey",
+ 15,
+ 26,
+ 26,
+ false,
+ "December 5, 2018 15:00:00 PST",
+ "../assets/images/everyday.svg"
+);
+
+// Create new Backpack object
+const frogPack = new Backpack(
+ "pack02",
+ "Frog Backpack",
+ 8,
+ "green",
+ 3,
+ 10,
+ 10,
+ false,
+ "October 16, 2019 15:00:00 PST",
+ "../assets/images/frog.svg"
+);
+
+// Add Backpack objects into an array
+const backpackObjectArray = [everydayPack, frogPack];
+
+// Export the array to be used in other files
+export default backpackObjectArray;
diff --git a/08_16/index.html b/08_16/index.html
new file mode 100755
index 00000000..c3c0235f
--- /dev/null
+++ b/08_16/index.html
@@ -0,0 +1,45 @@
+
+
+
+
+
+ BackpackPacker
+
+
+
+
+
+
+
+
+
BackpackPacker
+
All backpack packing, all the time.
+
+
+
+
A pack for every purpose
+
+ If you're carrying a heavy load, you can't find a better tool than a
+ backpack. Distributing the weight evenly across your shoulders, back,
+ and hips, the backpack lets you use the natural frame of your body to
+ literally shoulder the weight while your legs do the
+ carrying.
+
+
+
+
+
+
diff --git a/08_16/script.js b/08_16/script.js
new file mode 100755
index 00000000..3b166464
--- /dev/null
+++ b/08_16/script.js
@@ -0,0 +1,60 @@
+/**
+ * Challenge: Create an advanced function.
+ * - Loop through backpackObjectArray to create an article with the class "backpack".
+ * - Give the article the ID of the current backpack object.
+ * - Set the inner HTML of the article to the existing HTML output provided in const content.
+ * - Append each backpack object to the element.
+ */
+import Backpack from "./components/Backpack.js";
+
+const everydayPack = new Backpack(
+ "pack01",
+ "Everyday Backpack",
+ 30,
+ "grey",
+ 15,
+ 26,
+ 26,
+ false,
+ "December 5, 2018 15:00:00 PST",
+ "../assets/images/everyday.svg"
+);
+
+const content = `
+
+
+
+
+
${everydayPack.name}
+
+
Volume: ${
+ everydayPack.volume
+ }l
+
Color: ${
+ everydayPack.color
+ }
+
Age: ${everydayPack.backpackAge()} days old
+
Number of pockets: ${
+ everydayPack.pocketNum
+ }
+
Left strap length: ${
+ everydayPack.strapLength.left
+ } inches
+
Right strap length: ${
+ everydayPack.strapLength.right
+ } inches
+
+`;
+
+const main = document.querySelector(".maincontent");
+
+const newArticle = document.createElement("article");
+newArticle.classList.add("backpack");
+newArticle.setAttribute("id", "everyday");
+newArticle.innerHTML = content;
+
+main.append(newArticle);
diff --git a/08_17/components/Backpack.js b/08_17/components/Backpack.js
new file mode 100755
index 00000000..65236404
--- /dev/null
+++ b/08_17/components/Backpack.js
@@ -0,0 +1,45 @@
+// Set up the Backpack class
+class Backpack {
+ constructor(
+ id,
+ name,
+ volume,
+ color,
+ pocketNum,
+ strapLengthL,
+ strapLengthR,
+ lidOpen,
+ dateAcquired,
+ image
+ ) {
+ this.id = id;
+ this.name = name;
+ this.volume = volume;
+ this.color = color;
+ this.pocketNum = pocketNum;
+ this.strapLength = {
+ left: strapLengthL,
+ right: strapLengthR,
+ };
+ this.lidOpen = lidOpen;
+ this.dateAcquired = dateAcquired;
+ this.image = image;
+ }
+ toggleLid(lidStatus) {
+ this.lidOpen = lidStatus;
+ }
+ newStrapLength(lengthLeft, lengthRight) {
+ this.strapLength.left = lengthLeft;
+ this.strapLength.right = lengthRight;
+ }
+ backpackAge() {
+ let now = new Date();
+ let acquired = new Date(this.dateAcquired);
+ let elapsed = now - acquired; // elapsed time in milliseconds
+ let daysSinceAcquired = Math.floor(elapsed / (1000 * 3600 * 24));
+ return daysSinceAcquired;
+ }
+}
+
+// Export the Backpack class to be used by other files
+export default Backpack;
diff --git a/08_17/components/data.js b/08_17/components/data.js
new file mode 100755
index 00000000..4c16376f
--- /dev/null
+++ b/08_17/components/data.js
@@ -0,0 +1,36 @@
+// Import the Backpack class so we can make new Backpack objects.
+import Backpack from "./Backpack.js";
+
+// Create new Backpack object
+const everydayPack = new Backpack(
+ "pack01",
+ "Everyday Backpack",
+ 30,
+ "grey",
+ 15,
+ 26,
+ 26,
+ false,
+ "December 5, 2018 15:00:00 PST",
+ "../assets/images/everyday.svg"
+);
+
+// Create new Backpack object
+const frogPack = new Backpack(
+ "pack02",
+ "Frog Backpack",
+ 8,
+ "green",
+ 3,
+ 10,
+ 10,
+ false,
+ "October 16, 2019 15:00:00 PST",
+ "../assets/images/frog.svg"
+);
+
+// Add Backpack objects into an array
+const backpackObjectArray = [everydayPack, frogPack];
+
+// Export the array to be used in other files
+export default backpackObjectArray;
diff --git a/08_17/index.html b/08_17/index.html
new file mode 100755
index 00000000..c3c0235f
--- /dev/null
+++ b/08_17/index.html
@@ -0,0 +1,45 @@
+
+
+
+
+
+ BackpackPacker
+
+
+
+
+
+
+
+
+
BackpackPacker
+
All backpack packing, all the time.
+
+
+
+
A pack for every purpose
+
+ If you're carrying a heavy load, you can't find a better tool than a
+ backpack. Distributing the weight evenly across your shoulders, back,
+ and hips, the backpack lets you use the natural frame of your body to
+ literally shoulder the weight while your legs do the
+ carrying.
+
+
+
+
+
+
diff --git a/08_17/script.js b/08_17/script.js
new file mode 100755
index 00000000..298740cf
--- /dev/null
+++ b/08_17/script.js
@@ -0,0 +1,49 @@
+/**
+ * Solution: Create an advanced function.
+ * - Loop through backpackObjectArray to create an article with the class "backpack".
+ * - Give the article the ID of the current backpack object.
+ * - Set the inner HTML of the article to the existing HTML output provided in const content.
+ * - Append each backpack object to the element.
+ */
+import backpackObjectArray from "./components/data.js";
+
+const main = document.querySelector(".maincontent");
+
+const content = backpackObjectArray.map((backpack) => {
+ let backpackArticle = document.createElement("article");
+ backpackArticle.classList.add("backpack");
+ backpackArticle.setAttribute("id", backpack.id);
+
+ backpackArticle.innerHTML = `
+
+
+
+
${backpack.name}
+
+
Volume: ${
+ backpack.volume
+ }l
+
Color: ${
+ backpack.color
+ }
+
Age: ${backpack.backpackAge()} days old
+
Number of pockets: ${
+ backpack.pocketNum
+ }
+
Left strap length: ${
+ backpack.strapLength.left
+ } inches
+
Right strap length: ${
+ backpack.strapLength.right
+ } inches
+
+
+
+
diff --git a/09_02/script.js b/09_02/script.js
new file mode 100755
index 00000000..9c0e4e92
--- /dev/null
+++ b/09_02/script.js
@@ -0,0 +1,40 @@
+/**
+ * Events aplenty.
+ * @link https://developer.mozilla.org/en-US/docs/Web/Events
+ */
+
+const container = document.querySelector(".container");
+const button = document.querySelector(".cta-button");
+const posX = document.querySelector(".posX span");
+const posY = document.querySelector(".posY span");
+
+// Log when the button is clicked in the console.
+button.addEventListener("click", () => {
+ button.classList.toggle("active");
+ console.log("Button was clicked!");
+}, false);
+
+// Update the x and y displays to show the current mouse position.
+const mousePosition = (event) => {
+ posX.innerText = event.pageX;
+ posY.innerText = event.pageY;
+};
+
+window.addEventListener("mousemove", mousePosition, false);
+
+// Change the color of the box when the mouse enters.
+container.addEventListener(
+ "mouseenter",
+ () => {
+ container.classList.add("blue");
+ },
+ false
+);
+
+container.addEventListener(
+ "mouseleave",
+ () => {
+ container.classList.remove("blue");
+ },
+ false
+);
diff --git a/09_03/components/Backpack.js b/09_03/components/Backpack.js
new file mode 100755
index 00000000..65236404
--- /dev/null
+++ b/09_03/components/Backpack.js
@@ -0,0 +1,45 @@
+// Set up the Backpack class
+class Backpack {
+ constructor(
+ id,
+ name,
+ volume,
+ color,
+ pocketNum,
+ strapLengthL,
+ strapLengthR,
+ lidOpen,
+ dateAcquired,
+ image
+ ) {
+ this.id = id;
+ this.name = name;
+ this.volume = volume;
+ this.color = color;
+ this.pocketNum = pocketNum;
+ this.strapLength = {
+ left: strapLengthL,
+ right: strapLengthR,
+ };
+ this.lidOpen = lidOpen;
+ this.dateAcquired = dateAcquired;
+ this.image = image;
+ }
+ toggleLid(lidStatus) {
+ this.lidOpen = lidStatus;
+ }
+ newStrapLength(lengthLeft, lengthRight) {
+ this.strapLength.left = lengthLeft;
+ this.strapLength.right = lengthRight;
+ }
+ backpackAge() {
+ let now = new Date();
+ let acquired = new Date(this.dateAcquired);
+ let elapsed = now - acquired; // elapsed time in milliseconds
+ let daysSinceAcquired = Math.floor(elapsed / (1000 * 3600 * 24));
+ return daysSinceAcquired;
+ }
+}
+
+// Export the Backpack class to be used by other files
+export default Backpack;
diff --git a/09_03/components/data.js b/09_03/components/data.js
new file mode 100755
index 00000000..4c16376f
--- /dev/null
+++ b/09_03/components/data.js
@@ -0,0 +1,36 @@
+// Import the Backpack class so we can make new Backpack objects.
+import Backpack from "./Backpack.js";
+
+// Create new Backpack object
+const everydayPack = new Backpack(
+ "pack01",
+ "Everyday Backpack",
+ 30,
+ "grey",
+ 15,
+ 26,
+ 26,
+ false,
+ "December 5, 2018 15:00:00 PST",
+ "../assets/images/everyday.svg"
+);
+
+// Create new Backpack object
+const frogPack = new Backpack(
+ "pack02",
+ "Frog Backpack",
+ 8,
+ "green",
+ 3,
+ 10,
+ 10,
+ false,
+ "October 16, 2019 15:00:00 PST",
+ "../assets/images/frog.svg"
+);
+
+// Add Backpack objects into an array
+const backpackObjectArray = [everydayPack, frogPack];
+
+// Export the array to be used in other files
+export default backpackObjectArray;
diff --git a/09_03/index.html b/09_03/index.html
new file mode 100755
index 00000000..c3c0235f
--- /dev/null
+++ b/09_03/index.html
@@ -0,0 +1,45 @@
+
+
+
+
+
+ BackpackPacker
+
+
+
+
+
+
+
+
+
BackpackPacker
+
All backpack packing, all the time.
+
+
+
+
A pack for every purpose
+
+ If you're carrying a heavy load, you can't find a better tool than a
+ backpack. Distributing the weight evenly across your shoulders, back,
+ and hips, the backpack lets you use the natural frame of your body to
+ literally shoulder the weight while your legs do the
+ carrying.
+
+
+ `;
+
+ return backpackArticle;
+});
+
+const main = document.querySelector(".maincontent");
+
+backpackList.forEach((backpack) => {
+ main.append(backpack);
+});
diff --git a/09_03e/components/Backpack.js b/09_03e/components/Backpack.js
new file mode 100755
index 00000000..65236404
--- /dev/null
+++ b/09_03e/components/Backpack.js
@@ -0,0 +1,45 @@
+// Set up the Backpack class
+class Backpack {
+ constructor(
+ id,
+ name,
+ volume,
+ color,
+ pocketNum,
+ strapLengthL,
+ strapLengthR,
+ lidOpen,
+ dateAcquired,
+ image
+ ) {
+ this.id = id;
+ this.name = name;
+ this.volume = volume;
+ this.color = color;
+ this.pocketNum = pocketNum;
+ this.strapLength = {
+ left: strapLengthL,
+ right: strapLengthR,
+ };
+ this.lidOpen = lidOpen;
+ this.dateAcquired = dateAcquired;
+ this.image = image;
+ }
+ toggleLid(lidStatus) {
+ this.lidOpen = lidStatus;
+ }
+ newStrapLength(lengthLeft, lengthRight) {
+ this.strapLength.left = lengthLeft;
+ this.strapLength.right = lengthRight;
+ }
+ backpackAge() {
+ let now = new Date();
+ let acquired = new Date(this.dateAcquired);
+ let elapsed = now - acquired; // elapsed time in milliseconds
+ let daysSinceAcquired = Math.floor(elapsed / (1000 * 3600 * 24));
+ return daysSinceAcquired;
+ }
+}
+
+// Export the Backpack class to be used by other files
+export default Backpack;
diff --git a/09_03e/components/data.js b/09_03e/components/data.js
new file mode 100755
index 00000000..4c16376f
--- /dev/null
+++ b/09_03e/components/data.js
@@ -0,0 +1,36 @@
+// Import the Backpack class so we can make new Backpack objects.
+import Backpack from "./Backpack.js";
+
+// Create new Backpack object
+const everydayPack = new Backpack(
+ "pack01",
+ "Everyday Backpack",
+ 30,
+ "grey",
+ 15,
+ 26,
+ 26,
+ false,
+ "December 5, 2018 15:00:00 PST",
+ "../assets/images/everyday.svg"
+);
+
+// Create new Backpack object
+const frogPack = new Backpack(
+ "pack02",
+ "Frog Backpack",
+ 8,
+ "green",
+ 3,
+ 10,
+ 10,
+ false,
+ "October 16, 2019 15:00:00 PST",
+ "../assets/images/frog.svg"
+);
+
+// Add Backpack objects into an array
+const backpackObjectArray = [everydayPack, frogPack];
+
+// Export the array to be used in other files
+export default backpackObjectArray;
diff --git a/09_03e/index.html b/09_03e/index.html
new file mode 100755
index 00000000..c3c0235f
--- /dev/null
+++ b/09_03e/index.html
@@ -0,0 +1,45 @@
+
+
+
+
+
+ BackpackPacker
+
+
+
+
+
+
+
+
+
BackpackPacker
+
All backpack packing, all the time.
+
+
+
+
A pack for every purpose
+
+ If you're carrying a heavy load, you can't find a better tool than a
+ backpack. Distributing the weight evenly across your shoulders, back,
+ and hips, the backpack lets you use the natural frame of your body to
+ literally shoulder the weight while your legs do the
+ carrying.
+
+
+ `;
+
+ const button = backpackArticle.querySelector(".lid-toggle")
+ const status = backpackArticle.querySelector(".backpack__lid span")
+
+ button.addEventListener("click", (event) => {
+ console.log(event)
+ status.innerText === "open" ? status.innerText = "closed" : status.innerText = "open"
+ })
+
+ return backpackArticle;
+});
+
+const main = document.querySelector(".maincontent");
+
+backpackList.forEach((backpack) => {
+ main.append(backpack);
+});
diff --git a/09_05/components/Backpack.js b/09_05/components/Backpack.js
new file mode 100755
index 00000000..65236404
--- /dev/null
+++ b/09_05/components/Backpack.js
@@ -0,0 +1,45 @@
+// Set up the Backpack class
+class Backpack {
+ constructor(
+ id,
+ name,
+ volume,
+ color,
+ pocketNum,
+ strapLengthL,
+ strapLengthR,
+ lidOpen,
+ dateAcquired,
+ image
+ ) {
+ this.id = id;
+ this.name = name;
+ this.volume = volume;
+ this.color = color;
+ this.pocketNum = pocketNum;
+ this.strapLength = {
+ left: strapLengthL,
+ right: strapLengthR,
+ };
+ this.lidOpen = lidOpen;
+ this.dateAcquired = dateAcquired;
+ this.image = image;
+ }
+ toggleLid(lidStatus) {
+ this.lidOpen = lidStatus;
+ }
+ newStrapLength(lengthLeft, lengthRight) {
+ this.strapLength.left = lengthLeft;
+ this.strapLength.right = lengthRight;
+ }
+ backpackAge() {
+ let now = new Date();
+ let acquired = new Date(this.dateAcquired);
+ let elapsed = now - acquired; // elapsed time in milliseconds
+ let daysSinceAcquired = Math.floor(elapsed / (1000 * 3600 * 24));
+ return daysSinceAcquired;
+ }
+}
+
+// Export the Backpack class to be used by other files
+export default Backpack;
diff --git a/09_05/components/data.js b/09_05/components/data.js
new file mode 100755
index 00000000..4c16376f
--- /dev/null
+++ b/09_05/components/data.js
@@ -0,0 +1,36 @@
+// Import the Backpack class so we can make new Backpack objects.
+import Backpack from "./Backpack.js";
+
+// Create new Backpack object
+const everydayPack = new Backpack(
+ "pack01",
+ "Everyday Backpack",
+ 30,
+ "grey",
+ 15,
+ 26,
+ 26,
+ false,
+ "December 5, 2018 15:00:00 PST",
+ "../assets/images/everyday.svg"
+);
+
+// Create new Backpack object
+const frogPack = new Backpack(
+ "pack02",
+ "Frog Backpack",
+ 8,
+ "green",
+ 3,
+ 10,
+ 10,
+ false,
+ "October 16, 2019 15:00:00 PST",
+ "../assets/images/frog.svg"
+);
+
+// Add Backpack objects into an array
+const backpackObjectArray = [everydayPack, frogPack];
+
+// Export the array to be used in other files
+export default backpackObjectArray;
diff --git a/09_05/index.html b/09_05/index.html
new file mode 100755
index 00000000..c3c0235f
--- /dev/null
+++ b/09_05/index.html
@@ -0,0 +1,45 @@
+
+
+
+
+
+ BackpackPacker
+
+
+
+
+
+
+
+
+
BackpackPacker
+
All backpack packing, all the time.
+
+
+
+
A pack for every purpose
+
+ If you're carrying a heavy load, you can't find a better tool than a
+ backpack. Distributing the weight evenly across your shoulders, back,
+ and hips, the backpack lets you use the natural frame of your body to
+ literally shoulder the weight while your legs do the
+ carrying.
+
+
+
+
+
+
diff --git a/09_05/script.js b/09_05/script.js
new file mode 100755
index 00000000..0f1dc9f0
--- /dev/null
+++ b/09_05/script.js
@@ -0,0 +1,87 @@
+/**
+ * Event listeners
+ * @link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
+ * @link https://developer.mozilla.org/en-US/docs/Web/Events
+ */
+import backpackObjectArray from "./components/data.js";
+
+/**
+ * Add event listener to the lid-toggle button.
+ */
+const lidToggle = function () {
+
+ // Find the current backpack object in backpackObjectArray
+ let backpackObject = backpackObjectArray.find( ({ id }) => id === this.parentElement.id );
+
+ // Toggle lidOpen status
+ backpackObject.lidOpen == true
+ ? backpackObject.lidOpen = false
+ : backpackObject.lidOpen = true;
+
+ // Toggle button text
+ this.innerText == "Open lid"
+ ? this.innerText = "Close lid"
+ : this.innerText = "Open lid";
+
+ // Set visible property status text
+ let status = this.parentElement.querySelector(".backpack__lid span");
+ status.innerText == "closed"
+ ? (status.innerText = "open")
+ : (status.innerText = "closed");
+}
+
+/**
+ * - Loop through backpackObjectArray
+ * - create article for each entry
+ * - add articles back to backpackList array
+ */
+const backpackList = backpackObjectArray.map((backpack) => {
+ let backpackArticle = document.createElement("article");
+ backpackArticle.classList.add("backpack");
+ backpackArticle.setAttribute("id", backpack.id);
+
+ backpackArticle.innerHTML = `
+
+
+
+
${backpack.name}
+
+
Volume: ${
+ backpack.volume
+ }l
+
Color: ${
+ backpack.color
+ }
+
Age: ${backpack.backpackAge()} days old
+
Number of pockets: ${
+ backpack.pocketNum
+ }
+
Left strap length: ${
+ backpack.strapLength.left
+ } inches
+
Right strap length: ${
+ backpack.strapLength.right
+ } inches
+
+ `;
+
+ const button = backpackArticle.querySelector(".lid-toggle")
+ const status = backpackArticle.querySelector(".backpack__lid span")
+
+ button.addEventListener("click", (event) => {
+ console.log(event)
+ status.innerText === "open" ? status.innerText = "closed" : status.innerText = "open"
+ })
+
+ return backpackArticle;
+});
+
+const main = document.querySelector(".maincontent");
+
+backpackList.forEach((backpack) => {
+ main.append(backpack);
+});
diff --git a/09_05e/components/Backpack.js b/09_05e/components/Backpack.js
new file mode 100755
index 00000000..65236404
--- /dev/null
+++ b/09_05e/components/Backpack.js
@@ -0,0 +1,45 @@
+// Set up the Backpack class
+class Backpack {
+ constructor(
+ id,
+ name,
+ volume,
+ color,
+ pocketNum,
+ strapLengthL,
+ strapLengthR,
+ lidOpen,
+ dateAcquired,
+ image
+ ) {
+ this.id = id;
+ this.name = name;
+ this.volume = volume;
+ this.color = color;
+ this.pocketNum = pocketNum;
+ this.strapLength = {
+ left: strapLengthL,
+ right: strapLengthR,
+ };
+ this.lidOpen = lidOpen;
+ this.dateAcquired = dateAcquired;
+ this.image = image;
+ }
+ toggleLid(lidStatus) {
+ this.lidOpen = lidStatus;
+ }
+ newStrapLength(lengthLeft, lengthRight) {
+ this.strapLength.left = lengthLeft;
+ this.strapLength.right = lengthRight;
+ }
+ backpackAge() {
+ let now = new Date();
+ let acquired = new Date(this.dateAcquired);
+ let elapsed = now - acquired; // elapsed time in milliseconds
+ let daysSinceAcquired = Math.floor(elapsed / (1000 * 3600 * 24));
+ return daysSinceAcquired;
+ }
+}
+
+// Export the Backpack class to be used by other files
+export default Backpack;
diff --git a/09_05e/components/data.js b/09_05e/components/data.js
new file mode 100755
index 00000000..4c16376f
--- /dev/null
+++ b/09_05e/components/data.js
@@ -0,0 +1,36 @@
+// Import the Backpack class so we can make new Backpack objects.
+import Backpack from "./Backpack.js";
+
+// Create new Backpack object
+const everydayPack = new Backpack(
+ "pack01",
+ "Everyday Backpack",
+ 30,
+ "grey",
+ 15,
+ 26,
+ 26,
+ false,
+ "December 5, 2018 15:00:00 PST",
+ "../assets/images/everyday.svg"
+);
+
+// Create new Backpack object
+const frogPack = new Backpack(
+ "pack02",
+ "Frog Backpack",
+ 8,
+ "green",
+ 3,
+ 10,
+ 10,
+ false,
+ "October 16, 2019 15:00:00 PST",
+ "../assets/images/frog.svg"
+);
+
+// Add Backpack objects into an array
+const backpackObjectArray = [everydayPack, frogPack];
+
+// Export the array to be used in other files
+export default backpackObjectArray;
diff --git a/09_05e/index.html b/09_05e/index.html
new file mode 100755
index 00000000..c3c0235f
--- /dev/null
+++ b/09_05e/index.html
@@ -0,0 +1,45 @@
+
+
+
+
+
+ BackpackPacker
+
+
+
+
+
+
+
+
+
BackpackPacker
+
All backpack packing, all the time.
+
+
+
+
A pack for every purpose
+
+ If you're carrying a heavy load, you can't find a better tool than a
+ backpack. Distributing the weight evenly across your shoulders, back,
+ and hips, the backpack lets you use the natural frame of your body to
+ literally shoulder the weight while your legs do the
+ carrying.
+
+
+
+
+
+
diff --git a/09_05e/script.js b/09_05e/script.js
new file mode 100755
index 00000000..91740b64
--- /dev/null
+++ b/09_05e/script.js
@@ -0,0 +1,83 @@
+/**
+ * Event listeners
+ * @link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
+ * @link https://developer.mozilla.org/en-US/docs/Web/Events
+ */
+import backpackObjectArray from "./components/data.js";
+
+/**
+ * Add event listener to the lid-toggle button.
+ */
+const lidToggle = function () {
+
+ // Find the current backpack object in backpackObjectArray
+ let backpackObject = backpackObjectArray.find( ({ id }) => id === this.parentElement.id );
+
+ // Toggle lidOpen status
+ backpackObject.lidOpen == true
+ ? backpackObject.lidOpen = false
+ : backpackObject.lidOpen = true;
+
+ // Toggle button text
+ this.innerText == "Open lid"
+ ? this.innerText = "Close lid"
+ : this.innerText = "Open lid";
+
+ // Set visible property status text
+ let status = this.parentElement.querySelector(".backpack__lid span");
+ status.innerText == "closed"
+ ? (status.innerText = "open")
+ : (status.innerText = "closed");
+}
+
+const backpackList = backpackObjectArray.map((backpack) => {
+
+ let backpackArticle = document.createElement("article");
+ backpackArticle.classList.add("backpack");
+ backpackArticle.setAttribute("id", backpack.id);
+
+ backpackArticle.innerHTML = `
+
+
+
+
${backpack.name}
+
+
Volume: ${
+ backpack.volume
+ }l
+
Color: ${
+ backpack.color
+ }
+
Age: ${backpack.backpackAge()} days old
+
Number of pockets: ${
+ backpack.pocketNum
+ }
+
Left strap length: ${
+ backpack.strapLength.left
+ } inches
+
Right strap length: ${
+ backpack.strapLength.right
+ } inches
+
+ `;
+
+ let button = backpackArticle.querySelector(".lid-toggle");
+
+ // Add event listener
+ button.addEventListener("click", lidToggle)
+
+ return backpackArticle;
+});
+
+// Append each backpack item to the main
+const main = document.querySelector(".maincontent");
+
+backpackList.forEach((backpack) => {
+ main.append(backpack);
+});
+
+
diff --git a/09_06/components/Backpack.js b/09_06/components/Backpack.js
new file mode 100755
index 00000000..65236404
--- /dev/null
+++ b/09_06/components/Backpack.js
@@ -0,0 +1,45 @@
+// Set up the Backpack class
+class Backpack {
+ constructor(
+ id,
+ name,
+ volume,
+ color,
+ pocketNum,
+ strapLengthL,
+ strapLengthR,
+ lidOpen,
+ dateAcquired,
+ image
+ ) {
+ this.id = id;
+ this.name = name;
+ this.volume = volume;
+ this.color = color;
+ this.pocketNum = pocketNum;
+ this.strapLength = {
+ left: strapLengthL,
+ right: strapLengthR,
+ };
+ this.lidOpen = lidOpen;
+ this.dateAcquired = dateAcquired;
+ this.image = image;
+ }
+ toggleLid(lidStatus) {
+ this.lidOpen = lidStatus;
+ }
+ newStrapLength(lengthLeft, lengthRight) {
+ this.strapLength.left = lengthLeft;
+ this.strapLength.right = lengthRight;
+ }
+ backpackAge() {
+ let now = new Date();
+ let acquired = new Date(this.dateAcquired);
+ let elapsed = now - acquired; // elapsed time in milliseconds
+ let daysSinceAcquired = Math.floor(elapsed / (1000 * 3600 * 24));
+ return daysSinceAcquired;
+ }
+}
+
+// Export the Backpack class to be used by other files
+export default Backpack;
diff --git a/09_06/components/data.js b/09_06/components/data.js
new file mode 100755
index 00000000..4c16376f
--- /dev/null
+++ b/09_06/components/data.js
@@ -0,0 +1,36 @@
+// Import the Backpack class so we can make new Backpack objects.
+import Backpack from "./Backpack.js";
+
+// Create new Backpack object
+const everydayPack = new Backpack(
+ "pack01",
+ "Everyday Backpack",
+ 30,
+ "grey",
+ 15,
+ 26,
+ 26,
+ false,
+ "December 5, 2018 15:00:00 PST",
+ "../assets/images/everyday.svg"
+);
+
+// Create new Backpack object
+const frogPack = new Backpack(
+ "pack02",
+ "Frog Backpack",
+ 8,
+ "green",
+ 3,
+ 10,
+ 10,
+ false,
+ "October 16, 2019 15:00:00 PST",
+ "../assets/images/frog.svg"
+);
+
+// Add Backpack objects into an array
+const backpackObjectArray = [everydayPack, frogPack];
+
+// Export the array to be used in other files
+export default backpackObjectArray;
diff --git a/09_06/index.html b/09_06/index.html
new file mode 100755
index 00000000..c3c0235f
--- /dev/null
+++ b/09_06/index.html
@@ -0,0 +1,45 @@
+
+
+
+
+
+ BackpackPacker
+
+
+
+
+
+
+
+
+
BackpackPacker
+
All backpack packing, all the time.
+
+
+
+
A pack for every purpose
+
+ If you're carrying a heavy load, you can't find a better tool than a
+ backpack. Distributing the weight evenly across your shoulders, back,
+ and hips, the backpack lets you use the natural frame of your body to
+ literally shoulder the weight while your legs do the
+ carrying.
+
+
+
+
+
+
diff --git a/09_06/script.js b/09_06/script.js
new file mode 100755
index 00000000..024ac3e6
--- /dev/null
+++ b/09_06/script.js
@@ -0,0 +1,88 @@
+/**
+ * Event listeners
+ * @link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
+ * @link https://developer.mozilla.org/en-US/docs/Web/Events
+ */
+import backpackObjectArray from "./components/data.js";
+
+/**
+ * Add event listener to the lid-toggle button.
+ */
+const lidToggle = function (event, button, newArg) {
+ console.log(event)
+ console.log(newArg)
+
+ // Find the current backpack object in backpackObjectArray
+ let backpackObject = backpackObjectArray.find( ({ id }) => id === button.parentElement.id );
+
+ // Toggle lidOpen status
+ backpackObject.lidOpen == true
+ ? backpackObject.lidOpen = false
+ : backpackObject.lidOpen = true;
+
+ // Toggle button text
+ button.innerText == "Open lid"
+ ? button.innerText = "Close lid"
+ : button.innerText = "Open lid";
+
+ // Set visible property status text
+ let status = button.parentElement.querySelector(".backpack__lid span");
+ status.innerText == "closed"
+ ? (status.innerText = "open")
+ : (status.innerText = "closed");
+}
+
+const backpackList = backpackObjectArray.map((backpack) => {
+
+ let backpackArticle = document.createElement("article");
+ backpackArticle.classList.add("backpack");
+ backpackArticle.setAttribute("id", backpack.id);
+
+ backpackArticle.innerHTML = `
+
+
+
+
${backpack.name}
+
+
Volume: ${
+ backpack.volume
+ }l
+
Color: ${
+ backpack.color
+ }
+
Age: ${backpack.backpackAge()} days old
+
Number of pockets: ${
+ backpack.pocketNum
+ }
+
Left strap length: ${
+ backpack.strapLength.left
+ } inches
+
Right strap length: ${
+ backpack.strapLength.right
+ } inches
+
+ `;
+
+ let button = backpackArticle.querySelector(".lid-toggle");
+ let newArg = "The argument I want to pass to the callback function!"
+
+ // Add event listener
+ button.addEventListener("click", (event) => {
+ lidToggle(event, button, newArg)
+ })
+
+ return backpackArticle;
+});
+
+// Append each backpack item to the main
+const main = document.querySelector(".maincontent");
+
+backpackList.forEach((backpack) => {
+ main.append(backpack);
+});
+
+
diff --git a/09_07/components/Backpack.js b/09_07/components/Backpack.js
new file mode 100755
index 00000000..65236404
--- /dev/null
+++ b/09_07/components/Backpack.js
@@ -0,0 +1,45 @@
+// Set up the Backpack class
+class Backpack {
+ constructor(
+ id,
+ name,
+ volume,
+ color,
+ pocketNum,
+ strapLengthL,
+ strapLengthR,
+ lidOpen,
+ dateAcquired,
+ image
+ ) {
+ this.id = id;
+ this.name = name;
+ this.volume = volume;
+ this.color = color;
+ this.pocketNum = pocketNum;
+ this.strapLength = {
+ left: strapLengthL,
+ right: strapLengthR,
+ };
+ this.lidOpen = lidOpen;
+ this.dateAcquired = dateAcquired;
+ this.image = image;
+ }
+ toggleLid(lidStatus) {
+ this.lidOpen = lidStatus;
+ }
+ newStrapLength(lengthLeft, lengthRight) {
+ this.strapLength.left = lengthLeft;
+ this.strapLength.right = lengthRight;
+ }
+ backpackAge() {
+ let now = new Date();
+ let acquired = new Date(this.dateAcquired);
+ let elapsed = now - acquired; // elapsed time in milliseconds
+ let daysSinceAcquired = Math.floor(elapsed / (1000 * 3600 * 24));
+ return daysSinceAcquired;
+ }
+}
+
+// Export the Backpack class to be used by other files
+export default Backpack;
diff --git a/09_07/components/data.js b/09_07/components/data.js
new file mode 100755
index 00000000..4c16376f
--- /dev/null
+++ b/09_07/components/data.js
@@ -0,0 +1,36 @@
+// Import the Backpack class so we can make new Backpack objects.
+import Backpack from "./Backpack.js";
+
+// Create new Backpack object
+const everydayPack = new Backpack(
+ "pack01",
+ "Everyday Backpack",
+ 30,
+ "grey",
+ 15,
+ 26,
+ 26,
+ false,
+ "December 5, 2018 15:00:00 PST",
+ "../assets/images/everyday.svg"
+);
+
+// Create new Backpack object
+const frogPack = new Backpack(
+ "pack02",
+ "Frog Backpack",
+ 8,
+ "green",
+ 3,
+ 10,
+ 10,
+ false,
+ "October 16, 2019 15:00:00 PST",
+ "../assets/images/frog.svg"
+);
+
+// Add Backpack objects into an array
+const backpackObjectArray = [everydayPack, frogPack];
+
+// Export the array to be used in other files
+export default backpackObjectArray;
diff --git a/09_07/index.html b/09_07/index.html
new file mode 100755
index 00000000..c3c0235f
--- /dev/null
+++ b/09_07/index.html
@@ -0,0 +1,45 @@
+
+
+
+
+
+ BackpackPacker
+
+
+
+
+
+
+
+
+
BackpackPacker
+
All backpack packing, all the time.
+
+
+
+
A pack for every purpose
+
+ If you're carrying a heavy load, you can't find a better tool than a
+ backpack. Distributing the weight evenly across your shoulders, back,
+ and hips, the backpack lets you use the natural frame of your body to
+ literally shoulder the weight while your legs do the
+ carrying.
+
+
+
+
+
+
diff --git a/09_07/script-advanced.js b/09_07/script-advanced.js
new file mode 100755
index 00000000..f2415652
--- /dev/null
+++ b/09_07/script-advanced.js
@@ -0,0 +1,92 @@
+/**
+ * Challenge: Create an event listener
+ * - Find each element with the .backpack__strap class
+ * - Create function to iterate through above elements
+ * - Use the data-side attribute to identify what strap you are working on
+ * - Create form with a number input and a submit button
+ * - Add event listener to each of the strap length forms.
+ * - Update strap length value with value submitted from form.
+ */
+import backpackObjectArray from "./components/data.js";
+
+/**
+ * Add event listener to the lid-toggle button.
+ */
+const lidToggle = function (event, button, newArg) {
+ console.log(event)
+ console.log(newArg)
+
+ // Find the current backpack object in backpackObjectArray
+ let backpackObject = backpackObjectArray.find( ({ id }) => id === button.parentElement.id );
+
+ // Toggle lidOpen status
+ backpackObject.lidOpen == true
+ ? backpackObject.lidOpen = false
+ : backpackObject.lidOpen = true;
+
+ // Toggle button text
+ button.innerText == "Open lid"
+ ? button.innerText = "Close lid"
+ : button.innerText = "Open lid";
+
+ // Set visible property status text
+ let status = button.parentElement.querySelector(".backpack__lid span");
+ status.innerText == "closed"
+ ? (status.innerText = "open")
+ : (status.innerText = "closed");
+}
+
+const backpackList = backpackObjectArray.map((backpack) => {
+
+ let backpackArticle = document.createElement("article");
+ backpackArticle.classList.add("backpack");
+ backpackArticle.setAttribute("id", backpack.id);
+
+ backpackArticle.innerHTML = `
+
+
+
+
${backpack.name}
+
+
Volume: ${
+ backpack.volume
+ }l
+
Color: ${
+ backpack.color
+ }
+
Age: ${backpack.backpackAge()} days old
+
Number of pockets: ${
+ backpack.pocketNum
+ }
+
Left strap length: ${
+ backpack.strapLength.left
+ } inches
+
Right strap length: ${
+ backpack.strapLength.right
+ } inches
+
+ `;
+
+ let strapLengths = backpackArticle.querySelectorAll(".backpack__strap")
+ newStrapLength(strapLengths)
+
+ let button = backpackArticle.querySelector(".lid-toggle");
+ let newArg = "The argument I want to pass to the callback function!"
+
+ // Add event listener
+ button.addEventListener("click", (event) => {
+ lidToggle(event, button, newArg)
+ })
+
+ return backpackArticle;
+});
+
+// Append each backpack item to the main
+const main = document.querySelector(".maincontent");
+
+backpackList.forEach((backpack) => {
+ main.append(backpack);
+});
+
+
diff --git a/09_08/components/Backpack.js b/09_08/components/Backpack.js
new file mode 100755
index 00000000..65236404
--- /dev/null
+++ b/09_08/components/Backpack.js
@@ -0,0 +1,45 @@
+// Set up the Backpack class
+class Backpack {
+ constructor(
+ id,
+ name,
+ volume,
+ color,
+ pocketNum,
+ strapLengthL,
+ strapLengthR,
+ lidOpen,
+ dateAcquired,
+ image
+ ) {
+ this.id = id;
+ this.name = name;
+ this.volume = volume;
+ this.color = color;
+ this.pocketNum = pocketNum;
+ this.strapLength = {
+ left: strapLengthL,
+ right: strapLengthR,
+ };
+ this.lidOpen = lidOpen;
+ this.dateAcquired = dateAcquired;
+ this.image = image;
+ }
+ toggleLid(lidStatus) {
+ this.lidOpen = lidStatus;
+ }
+ newStrapLength(lengthLeft, lengthRight) {
+ this.strapLength.left = lengthLeft;
+ this.strapLength.right = lengthRight;
+ }
+ backpackAge() {
+ let now = new Date();
+ let acquired = new Date(this.dateAcquired);
+ let elapsed = now - acquired; // elapsed time in milliseconds
+ let daysSinceAcquired = Math.floor(elapsed / (1000 * 3600 * 24));
+ return daysSinceAcquired;
+ }
+}
+
+// Export the Backpack class to be used by other files
+export default Backpack;
diff --git a/09_08/components/data.js b/09_08/components/data.js
new file mode 100755
index 00000000..4c16376f
--- /dev/null
+++ b/09_08/components/data.js
@@ -0,0 +1,36 @@
+// Import the Backpack class so we can make new Backpack objects.
+import Backpack from "./Backpack.js";
+
+// Create new Backpack object
+const everydayPack = new Backpack(
+ "pack01",
+ "Everyday Backpack",
+ 30,
+ "grey",
+ 15,
+ 26,
+ 26,
+ false,
+ "December 5, 2018 15:00:00 PST",
+ "../assets/images/everyday.svg"
+);
+
+// Create new Backpack object
+const frogPack = new Backpack(
+ "pack02",
+ "Frog Backpack",
+ 8,
+ "green",
+ 3,
+ 10,
+ 10,
+ false,
+ "October 16, 2019 15:00:00 PST",
+ "../assets/images/frog.svg"
+);
+
+// Add Backpack objects into an array
+const backpackObjectArray = [everydayPack, frogPack];
+
+// Export the array to be used in other files
+export default backpackObjectArray;
diff --git a/09_08/index.html b/09_08/index.html
new file mode 100755
index 00000000..c3c0235f
--- /dev/null
+++ b/09_08/index.html
@@ -0,0 +1,45 @@
+
+
+
+
+
+ BackpackPacker
+
+
+
+
+
+
+
+
+
BackpackPacker
+
All backpack packing, all the time.
+
+
+
+
A pack for every purpose
+
+ If you're carrying a heavy load, you can't find a better tool than a
+ backpack. Distributing the weight evenly across your shoulders, back,
+ and hips, the backpack lets you use the natural frame of your body to
+ literally shoulder the weight while your legs do the
+ carrying.
+
+
+
+
+
+
diff --git a/09_08/script.js b/09_08/script.js
new file mode 100755
index 00000000..198926dc
--- /dev/null
+++ b/09_08/script.js
@@ -0,0 +1,133 @@
+/**
+ * Solution: Create an event listener
+ * - Add event listeners to each of the strap length forms.
+ * - Update strap length value with value submitted from form.
+ */
+import backpackObjectArray from "./components/data.js";
+
+/**
+ * Add event listener to the lid-toggle button.
+ */
+const lidToggle = function (event, button, newArg) {
+ console.log(event)
+ console.log(newArg)
+
+ // Find the current backpack object in backpackObjectArray
+ let backpackObject = backpackObjectArray.find( ({ id }) => id === button.parentElement.id );
+
+ // Toggle lidOpen status
+ backpackObject.lidOpen == true
+ ? backpackObject.lidOpen = false
+ : backpackObject.lidOpen = true;
+
+ // Toggle button text
+ button.innerText == "Open lid"
+ ? button.innerText = "Close lid"
+ : button.innerText = "Open lid";
+
+ // Set visible property status text
+ let status = button.parentElement.querySelector(".backpack__lid span");
+ status.innerText == "closed"
+ ? (status.innerText = "open")
+ : (status.innerText = "closed");
+}
+
+/**
+ * Strap length functionality
+ */
+const newStrapLength = (strapArray) => {
+
+ // Loop through each element on the list
+ strapArray.forEach( listElement => {
+
+ // Get what side we are working with
+ let side = listElement.getAttribute("data-side")
+
+ // Create a new form element
+ const lengthForm = document.createElement("form")
+ lengthForm.classList.add(`${side}length`)
+
+ // Populate form with an input and a button
+ lengthForm.innerHTML = `
+
+
+ `;
+
+ // Add event listener to the form submit action
+ lengthForm.addEventListener("submit", (e) => {
+
+ // Stop form from reloading the page
+ e.preventDefault()
+
+ // Get the value from the form input
+ let newValue = lengthForm.querySelector("input").value
+
+ // Set the value of the field
+ listElement.querySelector("span").innerHTML = `${newValue} inches`
+
+ // Clear the form input
+ lengthForm.querySelector("input").value = ""
+ })
+
+ // Add form to the end of the list element
+ listElement.append(lengthForm)
+ })
+}
+
+const backpackList = backpackObjectArray.map((backpack) => {
+
+ let backpackArticle = document.createElement("article");
+ backpackArticle.classList.add("backpack");
+ backpackArticle.setAttribute("id", backpack.id);
+
+ backpackArticle.innerHTML = `
+
+
+
+
${backpack.name}
+
+
Volume: ${
+ backpack.volume
+ }l
+
Color: ${
+ backpack.color
+ }
+
Age: ${backpack.backpackAge()} days old
+
Number of pockets: ${
+ backpack.pocketNum
+ }
+
Left strap length: ${
+ backpack.strapLength.left
+ } inches
+
Right strap length: ${
+ backpack.strapLength.right
+ } inches