Everyday Backpack
+-
+
- Volume: 30l +
- Color: grey +
- Age: 684 days old +
- + Number of pockets: 15 + +
- + Left strap length: 26 inches + + +
- + Right strap length: 26 inches + + +
- Lid status: closed +
diff --git a/.eslintrc.js b/.eslintrc.js index b9a064fe..f4585458 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,15 +1,12 @@ module.exports = { - "env": { - "browser": true, - "es2021": true - }, - "extends": [ - "standard" - ], - "parserOptions": { - "ecmaVersion": 12, - "sourceType": "module" - }, - "rules": { - } + env: { + browser: true, + es2021: true, + }, + extends: "eslint:recommended", + parserOptions: { + ecmaVersion: 12, + sourceType: "module", + }, + rules: {}, }; diff --git a/09_05e/script.js b/09_05e/script.js index 91740b64..cd22ec04 100755 --- a/09_05e/script.js +++ b/09_05e/script.js @@ -9,29 +9,29 @@ 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 ); - + let backpackObject = backpackObjectArray.find( + ({ id }) => id === this.parentElement.id + ); + // Toggle lidOpen status - backpackObject.lidOpen == true - ? backpackObject.lidOpen = false - : backpackObject.lidOpen = true; + backpackObject.lidOpen == true + ? (backpackObject.lidOpen = false) + : (backpackObject.lidOpen = true); // Toggle button text - this.innerText == "Open lid" - ? this.innerText = "Close lid" - : this.innerText = "Open lid"; + 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); @@ -64,11 +64,11 @@ const backpackList = backpackObjectArray.map((backpack) => { `; - + let button = backpackArticle.querySelector(".lid-toggle"); // Add event listener - button.addEventListener("click", lidToggle) + button.addEventListener("click", lidToggle); return backpackArticle; }); @@ -79,5 +79,3 @@ const main = document.querySelector(".maincontent"); backpackList.forEach((backpack) => { main.append(backpack); }); - - diff --git a/Practice/03_07 - making objects/script.js b/Practice/03_07 - making objects/script.js deleted file mode 100755 index 691dce02..00000000 --- a/Practice/03_07 - making objects/script.js +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Practice: Making objects - * - * - Pick real-life objects. - * - Give each object an identifiable name. - * - Create properties to describe the objects and set their values. - * - Create a nested object. - * - Test your objects in the browser console by accessing the entire object and its specific properties. - */ diff --git a/Practice/03_07 - making objects/index.html b/Practice/03_07/index.html similarity index 100% rename from Practice/03_07 - making objects/index.html rename to Practice/03_07/index.html diff --git a/Practice/03_07/script.js b/Practice/03_07/script.js new file mode 100755 index 00000000..7c19b174 --- /dev/null +++ b/Practice/03_07/script.js @@ -0,0 +1,10 @@ +/** + * Practice: Building functions + * + * - Create a basic function declaration - you’ll remember that’s where we say “function” followed by the name of the function. + * - In the body of the function declaration, do something to an element in the DOM. For this you can use any of the techniques we’ve covered earlier - finding an element using querySelector, adding a class, whatever you like. + * - Call the function declaration so the action takes place. + * - Create a basic function expression - that’s when you define a variable and place an anonymous function inside + * - Do the same as above - find an element, make a change to it, call the function, make sure it works. + * - Finally, create an arrow function, make it do something, and call it. + */ diff --git a/Practice/03_09 - making methods/index.html b/Practice/03_09/index.html similarity index 100% rename from Practice/03_09 - making methods/index.html rename to Practice/03_09/index.html diff --git a/Practice/03_09 - making methods/script.js b/Practice/03_09/script.js similarity index 100% rename from Practice/03_09 - making methods/script.js rename to Practice/03_09/script.js diff --git a/Practice/03_12/Backpack.js b/Practice/03_12/Backpack.js new file mode 100755 index 00000000..cca45eb3 --- /dev/null +++ b/Practice/03_12/Backpack.js @@ -0,0 +1,40 @@ +/** + * Creating classes: + * + * Class declaration: class Name {} + * Class expression: const Name = class {} + */ + +class Backpack { + constructor( + // Defines parameters: + name, + volume, + color, + pocketNum, + strapLengthL, + strapLengthR, + lidOpen + ) { + // Define properties: + this.name = name; + this.volume = volume; + this.color = color; + this.pocketNum = pocketNum; + this.strapLength = { + left: strapLengthL, + right: strapLengthR, + }; + this.lidOpen = lidOpen; + } + // Add methods like normal functions: + toggleLid(lidStatus) { + this.lidOpen = lidStatus; + } + newStrapLength(lengthLeft, lengthRight) { + this.strapLength.left = lengthLeft; + this.strapLength.right = lengthRight; + } +} + +export default Backpack; diff --git a/Practice/03_12/index.html b/Practice/03_12/index.html new file mode 100755 index 00000000..a082a72d --- /dev/null +++ b/Practice/03_12/index.html @@ -0,0 +1,11 @@ + + +
+ + ++ 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. +
+