{"componentChunkName":"component---src-templates-legacy-tutorial-page-js","path":"/oa/tutorials/ecommerce-tutorial-wd8/connect-shopping-cart-with-ecommerce/","result":{"pageContext":{"tutorial":{"id":"T0E6OlR1dG9yaWFsLTM0Ng==","slug":"ecommerce-tutorial-wd8","title":"Mood Shop","previewText":"Build an ecommerce site with HTML/CSS/JS!\n","heroImagePath":"https://raw.githubusercontent.com/MakeSchool-Tutorials/ecommerce-tutorial/master/cover.png","heroImageFile":{"childImageSharp":{"gatsbyImageData":{"layout":"constrained","placeholder":{"fallback":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAEq0lEQVQ4y0WU2U9UZxjGz01vetX/oP9Cr0ya9KI3rW2aprUKAqJtvbDaFDWNxiWWmtiqKahUlEWEmWEZWRRZqugwmywjKMvACCMFmQUYZ4ZhZlhnOed8v+acadMvefMl38Uvz/u87/NJTscQdns3wdcScIXsW6DFgmixI5pt0DkMfS9hahH8YUTPCKLJBk02lJVVsghS6RSd0Vmaw9NIYy/HmJ2Zwev+HIgj/zUOjf2Ie04Y8SICUYgmYWMbEpuIAQ/C1K8Ds0sRZKES2UoyFPfz3VwXks1mIxKO0Pu4E2V6EUz9ujq6XIjEFiS3QLsTmzmFdjei0QqNVuSlKCoQ3k7yaHWOB9FZpIYGAwF/gAZDI55yI3QMo2pQrU1FhUji//KFEU/Hcy2brGQDYbJCJbgRo2JphLLgMJLhTj0T4xMMjrioOXEBOkdQjBbon0A/wSiE1nSYplb0juS8NfUj+0IoQGAnwdXgEHne+0hlhlqmJ91E1mKc+aEERWvXZEXYJkFWIBCB5dVcaS3fcyDMDlTDE4hs4Pa+5vL1cq6tjHB8oQ/pa+Nl/HMLuphzZ88zf/MetDxDdbhhxg9vQjA8oyvWYGjTN9sRjU6YmaSprozKyhouuR9z3G9Byu+uJBFZ1YHlFRU8Kr0O7cMoXcOIjgFotkPbM3gwhHjuRVgnESYLtLpIVX+Cq/EU7leLlDyp5+yKEynPUkNydU0Hmtvbqfu5FB48130Uj0bB4wNvEFaTupdidBaMgyhNf7JT/i4u4zHck3McaLjCH5FRpC9s1Sz5AzrQNvCMsh9P54Dars2vQGw9N5jNHYQGHHyle5yu+pS04R1mxop4MeBhz6WT5Pu7kT623sQz5dGBY1NuLh45AR0uFLMD4X4DswGIb+ZgyU1weFEbbrN9433UKQmfbzfeqWUOnimhamkUaZflGvahQR046fFw5vAxaH2GaLYjZgIQTuSWe/EtYi0JXRNkq06San8PdiReTRSR2obKuirOj3cj7bJXcLfdrAOtTgc/FR9G0aZp7Ee4ZiEcz3m3vIqYWgDjEJk7BSjzEihHedpnQ85mmV9Y4OJoN9KHripOlf2uA1va2jhSeIhUUz+YnYhQDJZWEZq6v5fBMYlocKE4PkBJfYksQ2tbB9vbW8RiMZ6MP0f6yGNk37kS1iMxqmprObi3gHVjH7QPonqDCOc0PHQhWp1gsiB6x1G3fkPOhlFVMBoa2NzcIr2TwmTtRfo++Jjd1b9w6VwpR44e41DBAaJ3e3Qf9Uw3WvWoaenQPwRfiIzIkklnkeUMNdW1bGxsoGZlzD0PkW6GRvnshYGvigvJ/yaPbw8cInSnC1oHUM120KatfWUmK6rdTVZVyGY0WJZ0Os2tW7dZX98AIWhua0V6EQ9S6Othb8UFivfkU1RUzHJtZw6oxezfuGklRxP/AjPIskwqlaLiRgXxeFyfQX1dPZL2eHrZjhbB/Xvy2F9QiL/6PrQN6kCtTYwWlOk3ZFSFTDpNJpPRS1N45fJVQqGQDqyuqUESssLA5hJHR1spLD7Ivrx8Fqs7ckDNu6djKIEIsqrq66Ep+6+EEPxaehGfz5eLbouZfwB3wD/eZa0vZAAAAABJRU5ErkJggg=="},"images":{"fallback":{"src":"/mediabook/static/8071b0c27a9f4eb3460265eec8460940/5aead/cover.png","srcSet":"/mediabook/static/8071b0c27a9f4eb3460265eec8460940/e9fba/cover.png 50w,\n/mediabook/static/8071b0c27a9f4eb3460265eec8460940/15e42/cover.png 100w,\n/mediabook/static/8071b0c27a9f4eb3460265eec8460940/5aead/cover.png 200w,\n/mediabook/static/8071b0c27a9f4eb3460265eec8460940/d6138/cover.png 400w","sizes":"(min-width: 200px) 200px, 100vw"},"sources":[{"srcSet":"/mediabook/static/8071b0c27a9f4eb3460265eec8460940/b79cb/cover.avif 50w,\n/mediabook/static/8071b0c27a9f4eb3460265eec8460940/6d0de/cover.avif 100w,\n/mediabook/static/8071b0c27a9f4eb3460265eec8460940/f2685/cover.avif 200w,\n/mediabook/static/8071b0c27a9f4eb3460265eec8460940/4ff31/cover.avif 400w","type":"image/avif","sizes":"(min-width: 200px) 200px, 100vw"},{"srcSet":"/mediabook/static/8071b0c27a9f4eb3460265eec8460940/dbc4a/cover.webp 50w,\n/mediabook/static/8071b0c27a9f4eb3460265eec8460940/d8057/cover.webp 100w,\n/mediabook/static/8071b0c27a9f4eb3460265eec8460940/2e34e/cover.webp 200w,\n/mediabook/static/8071b0c27a9f4eb3460265eec8460940/416c3/cover.webp 400w","type":"image/webp","sizes":"(min-width: 200px) 200px, 100vw"}]},"width":200,"height":200}}},"pages":{"nodes":[{"id":"T0E6OlBhZ2UtMjIzOA==","title":"Getting Started","slug":"getting-started","sections":{"nodes":[{"id":"T0E6OlNlY3Rpb24tMTEzMDE=","title":"Getting Started","htmlContent":"<h2>Overview</h2><p><a href=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P01-Getting-Started/assets/01_getting-started_mood.gif\" target=\"_blank\">\n          <img src=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P01-Getting-Started/assets/01_getting-started_mood.gif\" alt=\"Mood Gif\" title=\"Mood Gif\">\n        </a></p><p>Did you know your emotions can change how you taste food?  I think everyone agrees that they would want their foods to taste good! </p><p>&#129367;&#127828;&#127829;&#127815;&#128523; </p><p>Imagine if there was a place where you could go to and buy any type of mood you want. Well guess what? We're going to build that! Well&hellip; sort of. Join me as we go deep into the world of HTML, CSS and Javascript and build The Mood Shop!</p><p><a href=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P01-Getting-Started/assets/02_getting-started_items-display.png\" target=\"_blank\">\n          <img src=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P01-Getting-Started/assets/02_getting-started_items-display.png\" alt=\"End product\" title=\"End product\">\n        </a></p>"},{"id":"T0E6OlNlY3Rpb24tMTEzMDI=","title":"Why Is This Important","htmlContent":"<p>The web is the biggest software platform and growing. The foundation material covered in this tutorial is at the core of all web technologies. Having a strong foundation is important to becoming a strong developer. &#128170;&#128187;</p>"},{"id":"T0E6OlNlY3Rpb24tMTEzMDM=","title":"Prerequisites:","htmlContent":"<p>None</p>"},{"id":"T0E6OlNlY3Rpb24tMTEzMDQ=","title":"Learning Outcomes","htmlContent":"<p>By the end of this tutorial, you should be able to...</p><ol>\n<li>Write valid and semantic HTML</li>\n<li>Apply CSS styles to control the appearance of your web applications</li>\n<li>Using Flex Box, Grid, Font styles, Border styles to change the appearance of your web page</li>\n<li>Use JavaScript to create dynamic content and handle user interactions in your web applications</li>\n<li>Create variables, handle events on the web page, and write javascript functions</li>\n</ol>"},{"id":"T0E6OlNlY3Rpb24tMTEzMDU=","title":"Using Git/GitHub","htmlContent":"<p>As you go through this tutorial, you will also be making commits after completing milestones. This is a requirement, you must make a commit whenever the tutorial prompts you. This not only further enforces best practices for software engineering, but also will help you more easily figure out where a bug originated from if you break your progress up into discrete, trackable chunks.</p><p>When prompted to commit, you'll see a sample commit message. Feel free to use your own message, so long as it clearly and concisely covers the work done.</p><p>Lastly, the commit prompts in this tutorial should be the minimum amount of times you commit. If you want to do more commits, breaking your chunks into even smaller chunks, that is totally fine!</p>"},{"id":"T0E6OlNlY3Rpb24tMTEzMDY=","title":"Git Setup","htmlContent":"<div class=\"action\">\n<p> Start by creating your project folder with the name <strong>mood-shop</strong>.</p>\n<pre>mkdir mood-shop\n</pre>\n<p>go into your project folder</p>\n<pre><span class=\"nb\">cd</span> mood-shop\n</pre>\n<p>create an index.html file</p>\n<pre>touch index.html\n</pre>\n</div>"},{"id":"T0E6OlNlY3Rpb24tMTEzMDc=","title":"Set Up Git/GitHub","htmlContent":"<p>Set up your repo!</p><div class=\"action\">\n<p>\nMake your first commit</p>\n<pre>$ git init\n$ git add .\n$ git commit -m <span class=\"s1\">'project init'</span>\n</pre>\n</div><p>Now Go to GitHub and create a public repository called mood-shop, and now associate it as a remote for your local git project and then push to it.</p><div class=\"action\">\n<p>\nPush it!</p>\n<pre>$ git remote add origin GITHUB-REPO-URL\n$ git push origin main -u\n</pre>\n</div>"}]},"next":{"id":"T0E6OlBhZ2UtMjIzOQ==","slug":"html-semantics","title":"HTML Semantics"},"previous":{"id":"T0E6OlBhZ2UtMjIzOQ==","slug":"html-semantics","title":"HTML Semantics"}},{"id":"T0E6OlBhZ2UtMjIzOQ==","title":"HTML Semantics","slug":"html-semantics","sections":{"nodes":[{"id":"T0E6OlNlY3Rpb24tMTEzNTY=","title":"HTML Semantics","htmlContent":"<p>In this Chapter we will be using: <strong>HTML</strong> and <strong>CSS</strong></p><h2>What is HTML?</h2><p>HTML is short for \"HyperText Markup Language\". That may sound scary, but it simply means it is a language for describing web-pages using ordinary text.</p><h2>What is an HTML tag?</h2><p>HTML tags are the hidden keywords within a web page that define how your web browser must format and display the content.</p><p>Most tags must have two parts, an opening and a closing part. For example, <strong><code>&lt;html&gt;</code></strong> is the opening tag and <strong><code>&lt;/html&gt;</code></strong> is the closing tag. Note that the closing tag has the same text as the opening tag, but has an additional forward-slash ( / ) character.</p><h2>What are tag attributes?</h2><p>Attributes allow you to customize a tag, and are defined within the opening tag, for example: <code>&lt;img src=\"image1.jpg\"&gt;</code> or <code>&lt;p class=\"lead\"&gt; ... &lt;/p&gt;</code>. Here for <strong>img</strong> tag, the attribute is <strong>src</strong>, which defines where the source file of the image is located. For the <strong>p</strong> tag the attribute <strong>class</strong> defines the name of the style group that should be applied to this elemwnt. To learn more about HTML tags click on this link : <a href=\"http://www.simplehtmlguide.com/whatishtml.php\" target=\"_blank\">HTML tags</a></p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNTc=","title":"Let's start by making the landing (shopping) page for our website.","htmlContent":"<p>First, let's have the basic outline/boilerplate for HTML.</p><p>You can learn more about the outline here: <a href=\"https://www.sitepoint.com/a-basic-html5-template/\" target=\"_blank\">HTML template</a></p><pre><span class=\"cp\">&lt;!DOCTYPE html&gt;</span>\n<span class=\"p\">&lt;</span><span class=\"nt\">html</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;</span><span class=\"nt\">head</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;</span><span class=\"nt\">title</span><span class=\"p\">&gt;</span>Title of the document<span class=\"p\">&lt;/</span><span class=\"nt\">title</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;/</span><span class=\"nt\">head</span><span class=\"p\">&gt;</span>\n\n<span class=\"p\">&lt;</span><span class=\"nt\">body</span><span class=\"p\">&gt;</span>\n  The content of the document......\n<span class=\"p\">&lt;/</span><span class=\"nt\">body</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;/</span><span class=\"nt\">html</span><span class=\"p\">&gt;</span>\n</pre><p>The first line, <code>&lt;!DOCTYPE&gt;</code> is called <strong>Document Type Declaration</strong>. It tells the browser what kind of document it's looking at. In our case, it's telling the browser that our document is an Html file.</p><p>Next is the <code>&lt;html&gt;</code> tag which contains the head tag and body tag.</p><p>The head tag contains the title of our page, <code>&lt;title&gt;</code>. This is also the place where we would link up an external stylesheet. (Which we will be doing later on in the upcoming chapters).</p><p>The <code>&lt;body&gt;</code> element contains all the contents of an HTML document, such as headings, paragraphs, <strong>images</strong>, <strong>hyperlinks</strong>, <strong>tables</strong>, <strong>lists</strong>, etc. We also link our <strong>javascript</strong> file here. </p><p>The head tag contains information about the document, while the body tag contains everything that you'll see in the browser. </p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNTg=","title":"Displaying our 'Hello World'","htmlContent":"<p>Let's start by displaying 'Hello World' in our browser.</p><div class=\"action\">\n<p></p>\n\n<p>In <code>index.html</code>, add a paragraph tag (<code>&lt;p&gt;</code>) inside the body tag. Inside the paragraph tag, write, Hello World!</p>\n<pre><span class=\"p\">&lt;</span><span class=\"nt\">p</span><span class=\"p\">&gt;</span> Hello World <span class=\"p\">&lt;/</span><span class=\"nt\">p</span><span class=\"p\">&gt;</span>\n</pre>\n<p>open your file in the browser now. Let's assume you're using Chrome. Do open the file in your browser, follow the steps below:</p>\n\n<ol>\n<li>Choose File from the Chrome ribbon menu.</li>\n<li>Then select Open File.</li>\n<li>Navigate to your HTML file location, highlight the document and click Open.</li>\n<li>You will see your file open in a new tab.</li>\n</ol>\n\n<p>You should see 'Hello World'.</p>\n</div><p>Congratulations! &#127881; You just displayed text in your browser.</p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNTk=","title":"Update progress on Github","htmlContent":"<div class=\"action\">\n<p> save and push your progress on github</p>\n<pre>git add .\ngit commit -m <span class=\"s1\">'displayed hello world'</span>\ngit push\n</pre>\n</div>"}]},"next":{"id":"T0E6OlBhZ2UtMjI0MA==","slug":"header-and-navbar","title":"Header and Navbar"},"previous":{"id":"T0E6OlBhZ2UtMjI0MA==","slug":"header-and-navbar","title":"Header and Navbar"}},{"id":"T0E6OlBhZ2UtMjI0MA==","title":"Header and Navbar","slug":"header-and-navbar","sections":{"nodes":[{"id":"T0E6OlNlY3Rpb24tMTEzNjA=","title":"Header and Navbar","htmlContent":"<p>Now that we have seen how html works, let's go ahead and start with working on our website.</p><p>Let's start by displaying the <strong>name</strong> of our website and <strong>navbar</strong>.\nWe will put these two inside a <code>&lt;header&gt;</code> tag.</p><div class=\"info\">\n<p> To learn more about header tag: <a href=\"https://www.w3schools.com/tags/tag_header.asp\" target=\"_blank\">Header tag</a></p>\n</div><p>Inside our header tag, we will have <code>&lt;h4&gt;</code> tag and <code>&lt;nav&gt;</code> tag.</p><p><code>&lt;h1&gt;...&lt;h6&gt;</code> tags are used to define html headings.</p><p><code>&lt;h1&gt;</code> defines the most important heading. <code>&lt;h6&gt;</code> defines the least important heading.</p><p>We will use the <code>&lt;nav&gt;</code> element to define a set of navigation links.</p><div class=\"info\">\n<p>To learn more about nav tag: <a href=\"https://www.w3schools.com/tags/tag_nav.asp\" target=\"_blank\">nav tag</a></p>\n</div><p>Since we will be using lists of navigation, we will have a list tag.</p><div class=\"info\">\n<p>To learn more about list tag: <a href=\"https://www.w3schools.com/html/html_lists.asp\" target=\"_blank\">list tag</a></p>\n</div><p>The <code>&lt;ul&gt;</code> tag defines an unordered (bulleted) list.</p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNjE=","title":"Adding the Header","htmlContent":"<div class=\"action\">\n<p></p>\n\n<p>Inside your <code>index.html</code>, delete the <code>&lt;p&gt;</code> tag that contains 'Hello World' ,and instead add the header element along with the navbar containing the 3 links as below.</p>\n\n<p>Use the <code>&lt;ul&gt;</code> tag together with the <code>&lt;li&gt;</code> tag to create unordered lists.</p>\n\n<p>Instead of copying and pasting the given code, type it out. This will give you more practice. &#129299;</p>\n<pre><span class=\"p\">&lt;</span><span class=\"nt\">header</span> <span class=\"na\">class</span><span class=\"o\">=</span><span class=\"s\">'page-header'</span><span class=\"p\">&gt;</span>\n    <span class=\"p\">&lt;</span><span class=\"nt\">h4</span><span class=\"p\">&gt;</span>The Mood Shop<span class=\"p\">&lt;/</span><span class=\"nt\">h4</span><span class=\"p\">&gt;</span>\n    <span class=\"p\">&lt;</span><span class=\"nt\">nav</span><span class=\"p\">&gt;</span>\n      <span class=\"p\">&lt;</span><span class=\"nt\">ul</span><span class=\"p\">&gt;</span>\n        <span class=\"p\">&lt;</span><span class=\"nt\">li</span><span class=\"p\">&gt;&lt;</span><span class=\"nt\">a</span> <span class=\"na\">href</span><span class=\"o\">=</span><span class=\"s\">\"#\"</span><span class=\"p\">&gt;</span>Home<span class=\"p\">&lt;/</span><span class=\"nt\">a</span><span class=\"p\">&gt;&lt;/</span><span class=\"nt\">li</span><span class=\"p\">&gt;</span>\n        <span class=\"p\">&lt;</span><span class=\"nt\">li</span><span class=\"p\">&gt;&lt;</span><span class=\"nt\">a</span> <span class=\"na\">href</span><span class=\"o\">=</span><span class=\"s\">\"#\"</span><span class=\"p\">&gt;</span>About<span class=\"p\">&lt;/</span><span class=\"nt\">a</span><span class=\"p\">&gt;&lt;/</span><span class=\"nt\">li</span><span class=\"p\">&gt;</span>\n        <span class=\"p\">&lt;</span><span class=\"nt\">li</span><span class=\"p\">&gt;&lt;</span><span class=\"nt\">a</span> <span class=\"na\">href</span><span class=\"o\">=</span><span class=\"s\">\"#\"</span><span class=\"p\">&gt;</span>Cart<span class=\"p\">&lt;/</span><span class=\"nt\">a</span><span class=\"p\">&gt;&lt;/</span><span class=\"nt\">li</span><span class=\"p\">&gt;</span>\n      <span class=\"p\">&lt;/</span><span class=\"nt\">ul</span><span class=\"p\">&gt;</span>\n    <span class=\"p\">&lt;/</span><span class=\"nt\">nav</span><span class=\"p\">&gt;</span>\n  <span class=\"p\">&lt;/</span><span class=\"nt\">header</span><span class=\"p\">&gt;</span>\n</pre>\n</div><!-- --><div class=\"action\">\n<p> Now refresh your html page.</p>\n</div><p>Yay! You should see the name of your site, <strong>The Mood Shop</strong>, and 3 links.</p><p><a href=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P03-Header-and-Navbar/assets/01_header-navbar_unstyled-navbar.png\" target=\"_blank\">\n          <img src=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P03-Header-and-Navbar/assets/01_header-navbar_unstyled-navbar.png\" alt=\"Navbar No style\" title=\"Navbar no style\">\n        </a></p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNjI=","title":"Update Progress on Github","htmlContent":"<div class=\"action\">\n<p> Now is a great time to commit your progress.</p>\n<pre>git add .\ngit commit -m <span class=\"s1\">'made navbar skeleton'</span>\ngit push\n</pre>\n</div>"}]},"next":{"id":"T0E6OlBhZ2UtMjI0MQ==","slug":"styling-header","title":"Styling Header"},"previous":{"id":"T0E6OlBhZ2UtMjI0MQ==","slug":"styling-header","title":"Styling Header"}},{"id":"T0E6OlBhZ2UtMjI0MQ==","title":"Styling Header","slug":"styling-header","sections":{"nodes":[{"id":"T0E6OlNlY3Rpb24tMTEzNjM=","title":"Styling Header","htmlContent":"<h2>Styling the header</h2><p>Currently, our header and navbar don't really look like a header or navbar at the moment. We need to add some styles to it.</p><p>This folder will hold your css, javascript and image files.</p><div class=\"quote\">\n<p>Create a file named <code>styles.css</code>. This is where all your element styles would go to.</p>\n<pre>touch styles.css\n</pre>\n<p>Now, open the <code>styles.css</code> file.</p>\n</div><h2>Reference elements in a stylesheet</h2><p>There are different ways on how to reference elements in a stylesheet.</p><ol>\n<li>by the element tag name.</li>\n<li>by the class name.</li>\n<li>by id name<br>\n</li>\n</ol><p>To learn more about selectors, visit <a href=\"https://www.w3schools.com/css/css_selectors.asp\" target=\"_blank\">CSS selectors</a></p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNjQ=","title":"Styling the body element","htmlContent":"<p>The body is the first thing we want to style.\nWe're going to start by styling the <strong>font family</strong> and <strong>font size</strong>.</p><p><strong>Line height</strong> - to increase spacing between lines (1.5 - 1.6) is recommended</p><p><strong>Font family</strong> - there are different font families. Here we will be using\n Helvetica font.</p><p><strong>Font size</strong> - 16 px.</p><div class=\"action\">\n<p></p>\n\n<p>Open your styles.css file and add the following line of code.</p>\n<pre><span class=\"nt\">body</span> <span class=\"p\">{</span>\n  <span class=\"k\">font-family</span><span class=\"p\">:</span> <span class=\"n\">Helvetica</span><span class=\"p\">;</span>\n  <span class=\"k\">font-size</span><span class=\"p\">:</span> <span class=\"mi\">16</span><span class=\"kt\">px</span><span class=\"p\">;</span>\n  <span class=\"k\">line-height</span><span class=\"p\">:</span> <span class=\"mf\">1.5</span><span class=\"p\">;</span>\n  <span class=\"k\">margin</span><span class=\"p\">:</span> <span class=\"mi\">0</span><span class=\"p\">;</span>\n<span class=\"p\">}</span>\n</pre>\n<p>Now refresh your browser.</p>\n</div><p>Hmm, we were expecting to see some change but don't see any. &#129300;</p><p>Can you guess why?</p><div class=\"solution\">\n<p></p>\n\n<p>That's because we haven't linked our stylesheet in our HTML file.\nWe need to use a <code>&lt;link&gt;</code> tag inside the <code>&lt;head&gt;</code> element to link our css file.</p>\n</div><!--  --><div class=\"action\">\n<p> Navigate to <code>index.html</code>. Inside the <code>&lt;head&gt;</code> element of your <code>index.html</code>, add the <code>&lt;link&gt;</code> element.</p>\n<pre><span class=\"p\">&lt;</span><span class=\"nt\">link</span> <span class=\"na\">rel</span><span class=\"o\">=</span><span class=\"s\">'stylesheet'</span> <span class=\"na\">href</span><span class=\"o\">=</span><span class=\"s\">'styles.css'</span><span class=\"p\">&gt;</span>\n</pre>\n<p>Now go ahead and refresh your page.</p>\n</div><p>Sweet! We see some font change!</p><p>We want our website name to be on the left side and the navigation links (Home, about, cart) to be on the other side. For this, we will use <strong>flexbox layout</strong>.</p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNjU=","title":"What is flexbox?","htmlContent":"<p>Flexbox helps to position elements inside a container.\nWe set flex properties on the parent element (container) to make elements inside the container move.</p><div class=\"info\">\n<p></p>\n\n<p>To learn more about flexbox: <a href=\"https://www.w3schools.com/css/css3_flexbox.asp\" target=\"_blank\">Flexbox</a></p>\n</div><p>The flex container becomes flexible by setting the <strong>display</strong> property to flex.</p><p><code>&lt;Header&gt;</code> is our container so we will be setting the display property of header to flex. In order to refer to our header inside the css file we will be using it's class name.</p><p>The class name for header is '<strong>page-header</strong>'.\nwe use dot (.) before the name when referring to class names in css files.</p><p>For example:  <strong>.page-header</strong></p><div class=\"action\">\n<p></p>\n\n<p>Inside your <code>styles.css</code> file, add the styles for page-header.</p>\n<pre><span class=\"p\">.</span><span class=\"nc\">page-header</span> <span class=\"p\">{</span>\n    <span class=\"k\">display</span><span class=\"p\">:</span> <span class=\"kc\">flex</span><span class=\"p\">;</span>\n    <span class=\"k\">flex-direction</span><span class=\"p\">:</span> <span class=\"kc\">row</span><span class=\"p\">;</span>\n    <span class=\"k\">justify-content</span><span class=\"p\">:</span> <span class=\"kc\">space-between</span><span class=\"p\">;</span>\n  <span class=\"k\">background-color</span><span class=\"p\">:</span> <span class=\"kc\">bisque</span><span class=\"p\">;</span>\n<span class=\"p\">}</span>\n</pre>\n<p>Refresh your web page again. You should see the title and navbar lists in rows.</p>\n</div><p>The navbar itself is not in rows, because the lists are inside the <code>&lt;ul&gt;</code> container. Hence we need to use flexbox on it to display the elements in rows.</p><div class=\"info\">\n<p> To select the <code>&lt;ul&gt;</code> tag, we can use <strong>.page-header ul</strong>\nThis will select <code>&lt;ul&gt;</code> elements inside the page-header class.</p>\n</div><!--  --><div class=\"action\">\n<p> Inside your <code>styles.css</code> file, add this code to style the navbar lists.</p>\n<pre><span class=\"p\">.</span><span class=\"nc\">page-header</span> <span class=\"nt\">ul</span> <span class=\"p\">{</span>\n  <span class=\"k\">display</span><span class=\"p\">:</span> <span class=\"kc\">flex</span><span class=\"p\">;</span>\n  <span class=\"k\">flex-direction</span><span class=\"p\">:</span> <span class=\"kc\">row</span><span class=\"p\">;</span>\n  <span class=\"k\">justify-content</span><span class=\"p\">:</span> <span class=\"kc\">space-between</span><span class=\"p\">;</span>\n  <span class=\"k\">list-style</span><span class=\"p\">:</span> <span class=\"kc\">none</span><span class=\"p\">;</span>\n<span class=\"p\">}</span>\n</pre>\n<p>Refresh your page again. You should now see the lists in rows.</p>\n</div><p>To remove the bullet points in each list, we can set the property list-style to none in the <code>&lt;ul&gt;</code> tag.</p><div class=\"action\">\n<p> Modify your <strong>.page-header ul</strong> rule in <code>styles.css</code></p>\n<pre><span class=\"p\">.</span><span class=\"nc\">page-header</span> <span class=\"nt\">ul</span> <span class=\"p\">{</span>\n  <span class=\"k\">display</span><span class=\"p\">:</span> <span class=\"kc\">flex</span><span class=\"p\">;</span>\n  <span class=\"k\">flex-direction</span><span class=\"p\">:</span> <span class=\"kc\">row</span><span class=\"p\">;</span>\n  <span class=\"k\">justify-content</span><span class=\"p\">:</span> <span class=\"kc\">space-between</span><span class=\"p\">;</span>\n  <span class=\"k\">list-style</span><span class=\"p\">:</span> <span class=\"kc\">none</span><span class=\"p\">;</span>\n<span class=\"p\">}</span>\n</pre>\n<p>The last style we need to add to the navbar is</p>\n\n<ol>\n<li>adding spaces between the nav links</li>\n<li>removing the underlines (text decorations) on the <code>&lt;a&gt;</code> tags.</li>\n</ol>\n<pre><span class=\"p\">.</span><span class=\"nc\">page-header</span> <span class=\"nt\">a</span> <span class=\"p\">{</span>\n  <span class=\"k\">display</span><span class=\"p\">:</span> <span class=\"kc\">block</span><span class=\"p\">;</span>\n  <span class=\"k\">padding</span><span class=\"p\">:</span><span class=\"mf\">0.5</span><span class=\"kt\">em</span><span class=\"p\">;</span>\n  <span class=\"k\">text-decoration</span><span class=\"p\">:</span><span class=\"kc\">none</span><span class=\"p\">;</span>\n<span class=\"p\">}</span>\n</pre>\n</div><p><a href=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P04-Styling-Header/assets/01_styling-header_navbar-example.png\" target=\"_blank\">\n          <img src=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P04-Styling-Header/assets/01_styling-header_navbar-example.png\" alt=\"Navbar Example\" title=\"Navbar example\">\n        </a></p><p>Congrats! You have just made a decent looking navbar using CSS.</p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNjY=","title":"Update progress on Github","htmlContent":"<p>Now is a good time to update your progress on Github.</p><pre>git add .\ngit commit -m <span class=\"s1\">'styled the header and navbar'</span>\ngit push\n</pre>"},{"id":"T0E6OlNlY3Rpb24tMTEzNjc=","title":"Stretch Challenge","htmlContent":"<div class=\"challenge\">\n<p></p>\n\n<ul>\n<li>Change the background color of the navbar</li>\n<li>Customize the navbar by changing the font size and font family to your desired choice.</li>\n</ul>\n</div>"}]},"next":{"id":"T0E6OlBhZ2UtMjI0Mg==","slug":"displaying-moods","title":"Displaying Moods"},"previous":{"id":"T0E6OlBhZ2UtMjI0Mg==","slug":"displaying-moods","title":"Displaying Moods"}},{"id":"T0E6OlBhZ2UtMjI0Mg==","title":"Displaying Moods","slug":"displaying-moods","sections":{"nodes":[{"id":"T0E6OlNlY3Rpb24tMTEzNjg=","title":"Displaying Moods","htmlContent":"<p>This chapter will focus on displaying all moods on our page. Currently our page has only a navbar.</p><p>At the end of this chapter, we will be able to have something like this.</p><p><a href=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P05-Displaying-Moods/assets/01_displaying-moods_items-display.png\" target=\"_blank\">\n          <img src=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P05-Displaying-Moods/assets/01_displaying-moods_items-display.png\" alt=\"Items display\" title=\"Items Display\">\n        </a></p><p>The first thing we need are the images to display for each mood.</p><p>The next thing we will need to do is get the json data that holds all the information about each mood including the name, image url, description and price.</p><p>The json data that we will be using is located in <code>data.js</code> file.</p><div class=\"action\">\n<p></p>\n\n<p>Both the images folder and the data.js file are located inside this Github repo : <a href=\"https://github.com/MakeSchool-Tutorials/ecommerce-tutorial-files\" target=\"_blank\">ecommerce-tutorial-files</a></p>\n\n<p>Navigate to the github link and download the repo as a zip file.</p>\n\n<p><a href=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P05-Displaying-Moods/assets/02_displaying-moods_download-zip.png\" target=\"_blank\">\n          <img src=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P05-Displaying-Moods/assets/02_displaying-moods_download-zip.png\" alt=\"Download zip\" title=\"Download zip\">\n        </a></p>\n</div><p>Now navigate to your resources folder.</p><div class=\"action\">\n<p></p>\n\n<p>Move the <strong>images</strong> folder that's located in the repo you've just downloaded into your project folder.</p>\n\n<p>Move the <code>data.js</code> into your project folder.  </p>\n</div><p>If you open your <code>data.js</code> file, you will see an array of JSON data.</p><pre><span class=\"kr\">const</span> <span class=\"nx\">data</span> <span class=\"o\">=</span> <span class=\"p\">[{</span>\n  <span class=\"s2\">\"id\"</span><span class=\"o\">:</span> <span class=\"mi\">1</span><span class=\"p\">,</span>\n  <span class=\"s2\">\"name\"</span><span class=\"o\">:</span> <span class=\"s2\">\"happy\"</span><span class=\"p\">,</span>\n  <span class=\"s2\">\"image\"</span><span class=\"o\">:</span> <span class=\"s2\">\"./resources/images/happy_spongebob.gif\"</span><span class=\"p\">,</span>\n  <span class=\"s2\">\"desc\"</span><span class=\"o\">:</span> <span class=\"s2\">\"Happiness lies in the joy of achievement and the thrill of creative effort.\"</span><span class=\"p\">,</span>\n  <span class=\"s2\">\"price\"</span><span class=\"o\">:</span> <span class=\"mf\">5.99</span>\n<span class=\"p\">},</span> <span class=\"p\">{</span>\n  <span class=\"s2\">\"id\"</span><span class=\"o\">:</span> <span class=\"mi\">2</span><span class=\"p\">,</span>\n  <span class=\"s2\">\"name\"</span><span class=\"o\">:</span> <span class=\"s1\">'sad'</span><span class=\"p\">,</span>\n  <span class=\"s2\">\"image\"</span><span class=\"o\">:</span> <span class=\"s1\">'./resources/images/sad_spongebob.gif'</span><span class=\"p\">,</span>\n  <span class=\"s2\">\"desc\"</span><span class=\"o\">:</span> <span class=\"s2\">\"Tears are words that can't be explained.\"</span><span class=\"p\">,</span>\n  <span class=\"s2\">\"price\"</span><span class=\"o\">:</span> <span class=\"mf\">5.99</span>\n<span class=\"p\">}</span>\n<span class=\"p\">...</span>\n</pre>"},{"id":"T0E6OlNlY3Rpb24tMTEzNjk=","title":"What exactly is a JSON data? 🤔","htmlContent":"<p>AKA JavaScript Object Notation</p><p>A JSON object contains data in the form of key/value pairs:</p><ul>\n<li>The key and value pairs are separated by a colon(:)</li>\n<li>Located left of the colon is the key, and on the right is it's value.</li>\n</ul><div class=\"info\">\n<p></p>\n\n<p>Here are a few links to learn more about json objects.</p>\n\n<ul>\n<li>\n<a href=\"https://www.copterlabs.com/json-what-it-is-how-it-works-how-to-use-it/\" target=\"_blank\">Intro to JSON</a> - the first few chapters gives a good introduction to JSON</li>\n<li>\n<a href=\"https://www.javatpoint.com/json-example\" target=\"_blank\">JSON example</a>,</li>\n<li><a href=\"https://restfulapi.net/introduction-to-json/\" target=\"_blank\">JSON short Tutorial</a></li>\n</ul>\n</div><p>Now that we have a good understanding of JSON, we can better understand what the file we are looking at is. The <code>data.js</code> file contains an array of objects. Each object contains the data for each mood to be displayed. This data consists of <strong>id, name, image, price</strong> and <strong>description</strong> as a <strong>key:value</strong> pair.</p><div class=\"action\">\n<p></p>\n\n<p>Navigate to <code>index.html</code> file</p>\n\n<p>Below our header element in our <code>index.html</code> file, let's add another element called <strong>main</strong>. This will hold all the mood items.</p>\n<pre><span class=\"p\">&lt;</span><span class=\"nt\">main</span> <span class=\"na\">class</span><span class=\"o\">=</span><span class=\"s\">'items'</span> <span class=\"na\">id</span><span class=\"o\">=</span><span class=\"s\">'items'</span><span class=\"p\">&gt;</span>\n    <span class=\"c\">&lt;!-- Display moods here --&gt;</span>\n<span class=\"p\">&lt;/</span><span class=\"nt\">main</span><span class=\"p\">&gt;</span>\n</pre>\n</div><p>We will be using javascript to dynamically display all the items for the mood shop. We will use a <strong>for loop</strong> to loop through each object inside the <code>data.js</code> array and assign image as the image source tag, description as the paragraph to describe the image and price to show the price for each mood.</p><div class=\"action\">\n<p>\nCreate a new file called <code>scripts.js</code>. This file will hold all your javascript logic to display the items, and future steps like adding them to the cart and removing them from the cart.</p>\n\n<p>Open <code>scripts.js</code>. First we need to get the reference to the containers where all the items will be in.</p>\n</div><p>All items will be in the main tag. The main tag has an id of <code>items</code>. We can get this element using its id name. In order to do this, we can use the <code>document.getElementbyID</code> function. Then pass the id of the element to the function.</p><div class=\"action\">\n<p></p>\n\n<p>Add this at the top of your <code>script.js</code> file:</p>\n\n<p><code>const itemsContainer = document.getElementById('items')</code></p>\n</div><p>We also need to import the json file into the <code>script.js</code>.</p><div class=\"action\">\n<p></p>\n\n<p>Add this import statement at the top of your <code>script.js</code> file.</p>\n\n<p><code>import data from './data.js'</code></p>\n</div><p>Now that we have access to the json array, we can loop through the array and make image elements out of it.</p><p>If you open <code>data.js</code> and see the image <strong>key:value</strong> pairs, the values are a reference to the source file of corresponding mood gifs located in the images folder. We will be using these values in the <code>img</code> <code>src</code> tag to display the images.</p><div class=\"info\">\n<p></p>\n\n<p>For those curious - <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement\" target=\"_blank\">How to create an element in javascript</a></p>\n</div><!--  -->"},{"id":"T0E6OlNlY3Rpb24tMTEzNzA=","title":"Creating the for-loop","htmlContent":"<div class=\"action\">\n<p></p>\n\n<p>Now let's loop over each element inside each object and display their images. This for-loop goes inside the <code>scripts.js</code> file.</p>\n<pre><span class=\"c1\">// the length of our data determines how many times this loop goes around</span>\n<span class=\"k\">for</span> <span class=\"p\">(</span><span class=\"kd\">let</span> <span class=\"nx\">i</span> <span class=\"o\">=</span> <span class=\"mi\">0</span><span class=\"p\">;</span> <span class=\"nx\">i</span> <span class=\"o\">&lt;</span> <span class=\"nx\">data</span><span class=\"p\">.</span><span class=\"nx\">length</span><span class=\"p\">;</span> <span class=\"nx\">i</span> <span class=\"o\">+=</span> <span class=\"mi\">1</span><span class=\"p\">)</span> <span class=\"p\">{</span>\n    <span class=\"c1\">// create a new div element and give it a class name</span>\n    <span class=\"kr\">const</span> <span class=\"nx\">newDiv</span> <span class=\"o\">=</span> <span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">createElement</span><span class=\"p\">(</span><span class=\"s1\">'div'</span><span class=\"p\">);</span>\n    <span class=\"nx\">newDiv</span><span class=\"p\">.</span><span class=\"nx\">className</span> <span class=\"o\">=</span> <span class=\"s1\">'item'</span>\n    <span class=\"c1\">// create an image element</span>\n    <span class=\"kr\">const</span> <span class=\"nx\">img</span> <span class=\"o\">=</span> <span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">createElement</span><span class=\"p\">(</span><span class=\"s1\">'img'</span><span class=\"p\">);</span>\n    <span class=\"c1\">// this will change each time we go through the loop. Can you explain why?</span>\n    <span class=\"nx\">img</span><span class=\"p\">.</span><span class=\"nx\">src</span> <span class=\"o\">=</span> <span class=\"nx\">data</span><span class=\"p\">[</span><span class=\"nx\">i</span><span class=\"p\">].</span><span class=\"nx\">image</span>\n    <span class=\"nx\">img</span><span class=\"p\">.</span><span class=\"nx\">width</span> <span class=\"o\">=</span> <span class=\"mi\">300</span>\n    <span class=\"nx\">img</span><span class=\"p\">.</span><span class=\"nx\">height</span> <span class=\"o\">=</span> <span class=\"mi\">300</span>\n    <span class=\"c1\">// Add the image to the div</span>\n    <span class=\"nx\">newDiv</span><span class=\"p\">.</span><span class=\"nx\">appendChild</span><span class=\"p\">(</span><span class=\"nx\">img</span><span class=\"p\">)</span>\n    <span class=\"nx\">console</span><span class=\"p\">.</span><span class=\"nx\">log</span><span class=\"p\">(</span><span class=\"nx\">img</span><span class=\"p\">)</span>\n<span class=\"p\">}</span>\n</pre>\n</div><p>Let's break down the above code:</p><h2>Breaking Down The JavaScript</h2><p>Here we are looping through each object and for each of them, we create a <code>div</code> element:</p><pre><span class=\"kr\">const</span> <span class=\"nx\">newDiv</span> <span class=\"o\">=</span> <span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">createElement</span><span class=\"p\">(</span><span class=\"s1\">'div'</span><span class=\"p\">);</span>\n</pre><p>This will create an html div element.</p><pre><span class=\"p\">&lt;</span><span class=\"nt\">div</span><span class=\"p\">&gt;</span> <span class=\"p\">&lt;/</span><span class=\"nt\">div</span><span class=\"p\">&gt;</span>\n</pre><p>The second line assigns a class name to the div we just created</p><pre><span class=\"nx\">newDiv</span><span class=\"p\">.</span><span class=\"nx\">className</span> <span class=\"o\">=</span> <span class=\"s1\">'item'</span>\n</pre>\n<pre><span class=\"p\">&lt;</span><span class=\"nt\">div</span> <span class=\"na\">class</span><span class=\"o\">=</span><span class=\"s\">'item'</span><span class=\"p\">&gt;</span> <span class=\"p\">&lt;/</span><span class=\"nt\">div</span><span class=\"p\">&gt;</span>\n</pre><p>We want this div we created to hold the image, description and price of each item.\nLet's start with the image.\nWe can create the image tag using <code>document.createElement('img')</code></p><pre><span class=\"kr\">const</span> <span class=\"nx\">img</span> <span class=\"o\">=</span> <span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">createElement</span><span class=\"p\">(</span><span class=\"s1\">'img'</span><span class=\"p\">);</span>\n</pre><p>Each attribute that we want to add to the image could be added using <code>img.attributeName</code>, which is how we added the src, width and height of the image:</p><pre><span class=\"nx\">img</span><span class=\"p\">.</span><span class=\"nx\">src</span> <span class=\"o\">=</span> <span class=\"nx\">data</span><span class=\"p\">[</span><span class=\"nx\">i</span><span class=\"p\">].</span><span class=\"nx\">image</span>\n<span class=\"nx\">img</span><span class=\"p\">.</span><span class=\"nx\">width</span> <span class=\"o\">=</span> <span class=\"mi\">300</span>\n<span class=\"nx\">img</span><span class=\"p\">.</span><span class=\"nx\">height</span> <span class=\"o\">=</span> <span class=\"mi\">300</span>\n</pre><h2>Connecting <code>scripts.js</code> with <code>index.html</code>\n</h2><p>Just like we connected our <code>css</code> file with our <code>index.html</code>, we also need to connect our <code>scripts.js</code> file with <code>index.html</code>.</p><div class=\"action\">\n<p></p>\n\n<p>Add this code right above the ending body tag (<code>&lt;/body&gt;</code>) in <code>index.html</code>.</p>\n<pre>  <span class=\"o\">&lt;</span><span class=\"nx\">script</span> <span class=\"nx\">src</span><span class=\"o\">=</span><span class=\"s1\">'scripts.js'</span> <span class=\"nx\">type</span><span class=\"o\">=</span><span class=\"s2\">\"module\"</span><span class=\"o\">&gt;&lt;</span><span class=\"err\">/script&gt;</span>\n</pre>\n</div><p><code>console.log</code> is a way to print our progress. Once we make the image, we are printing it to the console to see if it's being created. It is a good way to make sure if your code is working the way it's supposed to.</p><div class=\"action\">\n<p></p>\n\n<p>On your browser, right click and select inspect element. Navigate to console. You should see image tags.</p>\n\n<p><a href=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P05-Displaying-Moods/assets/03_displaying-moods_console-log-img.png\" target=\"_blank\">\n          <img src=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P05-Displaying-Moods/assets/03_displaying-moods_console-log-img.png\" alt=\"Console log img\" title=\"Console log img\">\n        </a></p>\n</div><p>Now that we have created the image, we can append it to the <code>div</code> element we created. We want our html result to be:</p><pre><span class=\"p\">&lt;</span><span class=\"nt\">div</span><span class=\"p\">&gt;</span>\n  <span class=\"p\">&lt;</span><span class=\"nt\">img</span> <span class=\"na\">src</span><span class=\"o\">=</span><span class=\"s\">'images/...'</span> <span class=\"na\">width</span><span class=\"o\">=</span><span class=\"s\">300</span> <span class=\"na\">height</span><span class=\"o\">=</span><span class=\"s\">300</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;/</span><span class=\"nt\">div</span><span class=\"p\">&gt;</span>\n</pre><p>To create the above code, we use <code>appendChild()</code> to append the image element into a div element.\nHere's what the javascript code looks like:</p><pre><span class=\"nx\">newDiv</span><span class=\"p\">.</span><span class=\"nx\">appendChild</span><span class=\"p\">(</span><span class=\"nx\">img</span><span class=\"p\">)</span>\n</pre>"},{"id":"T0E6OlNlY3Rpb24tMTEzNzE=","title":"Append To Container","htmlContent":"<div class=\"action\">\n<p></p>\n\n<p>Now that we have the <code>div</code> with the image, let's go ahead and append it to the main container, so that we could display it on our page. This will be done in the <code>scripts.js</code> file.</p>\n<pre><span class=\"nx\">itemsContainer</span><span class=\"p\">.</span><span class=\"nx\">appendChild</span><span class=\"p\">(</span><span class=\"nx\">newDiv</span><span class=\"p\">)</span>\n</pre>\n</div><p>Our javascript code should look like this at the end:</p><pre><span class=\"c1\">// the length of our data determines how many times this loop goes around</span>\n<span class=\"k\">for</span> <span class=\"p\">(</span><span class=\"kd\">let</span> <span class=\"nx\">i</span> <span class=\"o\">=</span> <span class=\"mi\">0</span><span class=\"p\">;</span> <span class=\"nx\">i</span> <span class=\"o\">&lt;</span> <span class=\"nx\">data</span><span class=\"p\">.</span><span class=\"nx\">length</span><span class=\"p\">;</span> <span class=\"nx\">i</span> <span class=\"o\">+=</span> <span class=\"mi\">1</span><span class=\"p\">)</span> <span class=\"p\">{</span>\n    <span class=\"c1\">// create a new div element and give it a class name</span>\n    <span class=\"kr\">const</span> <span class=\"nx\">newDiv</span> <span class=\"o\">=</span> <span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">createElement</span><span class=\"p\">(</span><span class=\"s1\">'div'</span><span class=\"p\">);</span>\n    <span class=\"nx\">newDiv</span><span class=\"p\">.</span><span class=\"nx\">className</span> <span class=\"o\">=</span> <span class=\"s1\">'item'</span>\n    <span class=\"c1\">// create an image element</span>\n    <span class=\"kr\">const</span> <span class=\"nx\">img</span> <span class=\"o\">=</span> <span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">createElement</span><span class=\"p\">(</span><span class=\"s1\">'img'</span><span class=\"p\">);</span>\n    <span class=\"c1\">// this will change each time we go through the loop. Can you explain why?</span>\n    <span class=\"nx\">img</span><span class=\"p\">.</span><span class=\"nx\">src</span> <span class=\"o\">=</span> <span class=\"nx\">data</span><span class=\"p\">[</span><span class=\"nx\">i</span><span class=\"p\">].</span><span class=\"nx\">image</span>\n    <span class=\"nx\">img</span><span class=\"p\">.</span><span class=\"nx\">width</span> <span class=\"o\">=</span> <span class=\"mi\">300</span>\n    <span class=\"nx\">img</span><span class=\"p\">.</span><span class=\"nx\">height</span> <span class=\"o\">=</span> <span class=\"mi\">300</span>\n    <span class=\"c1\">// Add the image to the div</span>\n    <span class=\"nx\">newDiv</span><span class=\"p\">.</span><span class=\"nx\">appendChild</span><span class=\"p\">(</span><span class=\"nx\">img</span><span class=\"p\">)</span>\n    <span class=\"c1\">// put new div inside items container</span>\n    <span class=\"nx\">itemsContainer</span><span class=\"p\">.</span><span class=\"nx\">appendChild</span><span class=\"p\">(</span><span class=\"nx\">newDiv</span><span class=\"p\">)</span>\n<span class=\"p\">}</span>\n</pre>\n<div class=\"action\">\n<p></p>\n\n<p>This part you'll do on your own! Inside the for loop, create a paragraph element for both description and price to be displayed</p>\n\n<p><strong><em>Hint</em></strong>: After you create the element, use <code>element.InnerText</code> to add the text description and price.</p>\n\n<p>This is what we want our js to make:</p>\n<pre><span class=\"p\">&lt;</span><span class=\"nt\">div</span><span class=\"p\">&gt;</span>\n  <span class=\"p\">&lt;</span><span class=\"nt\">img</span> <span class=\"na\">src</span><span class=\"o\">=</span><span class=\"s\">'/resource...'</span> <span class=\"na\">width</span><span class=\"o\">=</span><span class=\"s\">300</span> <span class=\"na\">height</span><span class=\"o\">=</span><span class=\"s\">300</span><span class=\"p\">&gt;</span>\n  <span class=\"p\">&lt;</span><span class=\"nt\">p</span><span class=\"p\">&gt;</span>description of mood<span class=\"p\">&lt;/</span><span class=\"nt\">p</span><span class=\"p\">&gt;</span>\n  <span class=\"p\">&lt;</span><span class=\"nt\">p</span><span class=\"p\">&gt;</span>5.99<span class=\"p\">&lt;/</span><span class=\"nt\">p</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;/</span><span class=\"nt\">div</span><span class=\"p\">&gt;</span>\n</pre>\n</div><!--  --><p>Solution to the above is here, but try it on your own first!</p><div class=\"solution\">\n<p>  </p>\n<pre><span class=\"c1\">// create a paragraph element for a description</span>\n<span class=\"kr\">const</span> <span class=\"nx\">desc</span> <span class=\"o\">=</span> <span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">createElement</span><span class=\"p\">(</span><span class=\"s1\">'P'</span><span class=\"p\">)</span>\n<span class=\"c1\">// give the paragraph text from the data</span>\n<span class=\"nx\">desc</span><span class=\"p\">.</span><span class=\"nx\">innerText</span> <span class=\"o\">=</span> <span class=\"nx\">data</span><span class=\"p\">[</span><span class=\"nx\">i</span><span class=\"p\">].</span><span class=\"nx\">desc</span>\n<span class=\"c1\">// append the paragraph to the div</span>\n<span class=\"nx\">newDiv</span><span class=\"p\">.</span><span class=\"nx\">appendChild</span><span class=\"p\">(</span><span class=\"nx\">desc</span><span class=\"p\">)</span>\n<span class=\"c1\">// do the same thing for price</span>\n<span class=\"kr\">const</span> <span class=\"nx\">price</span> <span class=\"o\">=</span> <span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">createElement</span><span class=\"p\">(</span><span class=\"s1\">'P'</span><span class=\"p\">)</span>\n<span class=\"nx\">price</span><span class=\"p\">.</span><span class=\"nx\">innerText</span> <span class=\"o\">=</span> <span class=\"nx\">data</span><span class=\"p\">[</span><span class=\"nx\">i</span><span class=\"p\">].</span><span class=\"nx\">price</span>\n<span class=\"nx\">newDiv</span><span class=\"p\">.</span><span class=\"nx\">appendChild</span><span class=\"p\">(</span><span class=\"nx\">price</span><span class=\"p\">)</span>\n</pre>\n</div><p>If you open your browser, you should now be able to see something like this. &#127881;&#127882;</p><p><a href=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P05-Displaying-Moods/assets/04_displaying-moods_display-without-button.png\" target=\"_blank\">\n          <img src=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P05-Displaying-Moods/assets/04_displaying-moods_display-without-button.png\" alt=\"Display without button\" title=\"display without button\">\n        </a></p><h2>Stretch challenge:</h2><div class=\"challenge\">\n<p></p>\n\n<p>Use the ES6 javascript syntax forEach loop instead of the normal for loop.\n<a href=\"https://gomakethings.com/looping-through-arrays-the-es6-way/\" target=\"_blank\">ES6 for each loop</a></p>\n</div>"},{"id":"T0E6OlNlY3Rpb24tMTEzNzI=","title":"Add to Cart","htmlContent":"<p>The next thing to do would be adding an <code>Add To Cart</code> button for each of the moods.</p><p>We will be adding a button element using javascript. This will be in the same for loop we used to create the image, description and prices.</p><div class=\"action\">\n<p></p>\n\n<p>After the line where you created the price, add a line to create a button element.</p>\n<pre><span class=\"c1\">// Make a button </span>\n<span class=\"kr\">const</span> <span class=\"nx\">button</span> <span class=\"o\">=</span> <span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">createElement</span><span class=\"p\">(</span><span class=\"s1\">'button'</span><span class=\"p\">)</span>\n</pre>\n</div><p>We should also make the <code>id</code> of each button unique.</p><div class=\"action\">\n<p></p>\n\n<p>To do this we will assign the <code>id</code> to the name of the mood.</p>\n<pre><span class=\"c1\">// add an  id name to the button</span>\n<span class=\"nx\">button</span><span class=\"p\">.</span><span class=\"nx\">id</span> <span class=\"o\">=</span> <span class=\"nx\">data</span><span class=\"p\">[</span><span class=\"nx\">i</span><span class=\"p\">].</span><span class=\"nx\">name</span>\n</pre>\n</div><p>There needs to be a way to access the price of each Mood when their \"Add to Cart\" button is clicked. &#129300;</p><p>We will use a <strong><em>custom data attribute</em></strong> to store the price for each mood on the button. &#128161;</p><div class=\"info\">\n<p></p>\n\n<p>Read up on <a href=\"https://www.w3schools.com/tags/att_data-.asp\" target=\"_blank\">data- attributes</a> and <a href=\"http://html5doctor.com/html5-custom-data-attributes/\" target=\"_blank\">custom data attributes</a></p>\n</div><p>Here's an example of the code we would use to achieve this:</p><pre><span class=\"c1\">// creates a custom attribute called data-price. That will hold price for each element in the button</span>\n<span class=\"nx\">button</span><span class=\"p\">.</span><span class=\"nx\">dataset</span><span class=\"p\">.</span><span class=\"nx\">price</span> <span class=\"o\">=</span> <span class=\"nx\">data</span><span class=\"p\">[</span><span class=\"nx\">i</span><span class=\"p\">].</span><span class=\"nx\">price</span>\n<span class=\"nx\">button</span><span class=\"p\">.</span><span class=\"nx\">innerHTML</span> <span class=\"o\">=</span> <span class=\"s2\">\"Add to Cart\"</span>\n<span class=\"nx\">newDiv</span><span class=\"p\">.</span><span class=\"nx\">appendChild</span><span class=\"p\">(</span><span class=\"nx\">button</span><span class=\"p\">)</span>\n</pre>\n<div class=\"action\">\n<p></p>\n\n<p>At this point, our for loop should create image, description, price and an 'Add to Cart' button for each mood in the data array. Make sure it matches the following:</p>\n<pre><span class=\"c1\">// the length of our data determines how many times this loop goes around</span>\n<span class=\"k\">for</span> <span class=\"p\">(</span><span class=\"kd\">let</span> <span class=\"nx\">i</span> <span class=\"o\">=</span> <span class=\"mi\">0</span><span class=\"p\">;</span> <span class=\"nx\">i</span> <span class=\"o\">&lt;</span> <span class=\"nx\">data</span><span class=\"p\">.</span><span class=\"nx\">length</span><span class=\"p\">;</span> <span class=\"nx\">i</span> <span class=\"o\">+=</span> <span class=\"mi\">1</span><span class=\"p\">)</span> <span class=\"p\">{</span>\n    <span class=\"c1\">// create a new div element and give it a class name</span>\n    <span class=\"kr\">const</span> <span class=\"nx\">newDiv</span> <span class=\"o\">=</span> <span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">createElement</span><span class=\"p\">(</span><span class=\"s1\">'div'</span><span class=\"p\">);</span>\n    <span class=\"nx\">newDiv</span><span class=\"p\">.</span><span class=\"nx\">className</span> <span class=\"o\">=</span> <span class=\"s1\">'item'</span>\n    <span class=\"c1\">// create an image element</span>\n    <span class=\"kr\">const</span> <span class=\"nx\">img</span> <span class=\"o\">=</span> <span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">createElement</span><span class=\"p\">(</span><span class=\"s1\">'img'</span><span class=\"p\">);</span>\n    <span class=\"c1\">// this will change each time we go through the loop. Can you explain why?</span>\n    <span class=\"nx\">img</span><span class=\"p\">.</span><span class=\"nx\">src</span> <span class=\"o\">=</span> <span class=\"nx\">data</span><span class=\"p\">[</span><span class=\"nx\">i</span><span class=\"p\">].</span><span class=\"nx\">image</span>\n    <span class=\"nx\">img</span><span class=\"p\">.</span><span class=\"nx\">width</span> <span class=\"o\">=</span> <span class=\"mi\">300</span>\n    <span class=\"nx\">img</span><span class=\"p\">.</span><span class=\"nx\">height</span> <span class=\"o\">=</span> <span class=\"mi\">300</span>\n    <span class=\"c1\">// Add the image to the div</span>\n    <span class=\"nx\">newDiv</span><span class=\"p\">.</span><span class=\"nx\">appendChild</span><span class=\"p\">(</span><span class=\"nx\">img</span><span class=\"p\">)</span>\n    <span class=\"c1\">// put new div inside items container</span>\n    <span class=\"nx\">itemsContainer</span><span class=\"p\">.</span><span class=\"nx\">appendChild</span><span class=\"p\">(</span><span class=\"nx\">newDiv</span><span class=\"p\">)</span>\n    <span class=\"c1\">// create a paragraph element for a description</span>\n    <span class=\"kr\">const</span> <span class=\"nx\">desc</span> <span class=\"o\">=</span> <span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">createElement</span><span class=\"p\">(</span><span class=\"s1\">'P'</span><span class=\"p\">)</span>\n    <span class=\"c1\">// give the paragraph text from the data</span>\n    <span class=\"nx\">desc</span><span class=\"p\">.</span><span class=\"nx\">innerText</span> <span class=\"o\">=</span> <span class=\"nx\">data</span><span class=\"p\">[</span><span class=\"nx\">i</span><span class=\"p\">].</span><span class=\"nx\">desc</span>\n    <span class=\"c1\">// append the paragraph to the div</span>\n    <span class=\"nx\">newDiv</span><span class=\"p\">.</span><span class=\"nx\">appendChild</span><span class=\"p\">(</span><span class=\"nx\">desc</span><span class=\"p\">)</span>\n    <span class=\"c1\">// do the same thing for price</span>\n    <span class=\"kr\">const</span> <span class=\"nx\">price</span> <span class=\"o\">=</span> <span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">createElement</span><span class=\"p\">(</span><span class=\"s1\">'P'</span><span class=\"p\">)</span>\n    <span class=\"nx\">price</span><span class=\"p\">.</span><span class=\"nx\">innerText</span> <span class=\"o\">=</span> <span class=\"nx\">data</span><span class=\"p\">[</span><span class=\"nx\">i</span><span class=\"p\">].</span><span class=\"nx\">price</span>\n    <span class=\"nx\">newDiv</span><span class=\"p\">.</span><span class=\"nx\">appendChild</span><span class=\"p\">(</span><span class=\"nx\">price</span><span class=\"p\">)</span>\n    <span class=\"c1\">// Make a button </span>\n    <span class=\"kr\">const</span> <span class=\"nx\">button</span> <span class=\"o\">=</span> <span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">createElement</span><span class=\"p\">(</span><span class=\"s1\">'button'</span><span class=\"p\">)</span>\n    <span class=\"c1\">// add an  id name to the button</span>\n    <span class=\"nx\">button</span><span class=\"p\">.</span><span class=\"nx\">id</span> <span class=\"o\">=</span> <span class=\"nx\">data</span><span class=\"p\">[</span><span class=\"nx\">i</span><span class=\"p\">].</span><span class=\"nx\">name</span>\n    <span class=\"c1\">// creates a custom attribute called data-price. That will hold price for each element in the button</span>\n    <span class=\"nx\">button</span><span class=\"p\">.</span><span class=\"nx\">dataset</span><span class=\"p\">.</span><span class=\"nx\">price</span> <span class=\"o\">=</span> <span class=\"nx\">data</span><span class=\"p\">[</span><span class=\"nx\">i</span><span class=\"p\">].</span><span class=\"nx\">price</span>\n    <span class=\"nx\">button</span><span class=\"p\">.</span><span class=\"nx\">innerHTML</span> <span class=\"o\">=</span> <span class=\"s2\">\"Add to Cart\"</span>\n    <span class=\"nx\">newDiv</span><span class=\"p\">.</span><span class=\"nx\">appendChild</span><span class=\"p\">(</span><span class=\"nx\">button</span><span class=\"p\">)</span>\n<span class=\"p\">}</span>\n</pre>\n</div><p>Your page should now show each mood, with description, price and button.</p><p><a href=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P05-Displaying-Moods/assets/05_displaying-moods_display-with-button.png\" target=\"_blank\">\n          <img src=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P05-Displaying-Moods/assets/05_displaying-moods_display-with-button.png\" alt=\"Display with button\" title=\"display with button\">\n        </a></p><p><strong>Congrats! You have just learned how to display items dynamically using javascript.</strong> &#127881;&#127882;</p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNzM=","title":"Update progress on Github","htmlContent":"<div class=\"action\">\n<p></p>\n\n<p>Now is a good time to update your progress on Github.</p>\n<pre>git add .\ngit commit -m <span class=\"s1\">'displayed moods with button using javascript'</span>\ngit push\n</pre>\n</div>"}]},"next":{"id":"T0E6OlBhZ2UtMjI0Mw==","slug":"styling-moods-display","title":"Styling Moods Display"},"previous":{"id":"T0E6OlBhZ2UtMjI0Mw==","slug":"styling-moods-display","title":"Styling Moods Display"}},{"id":"T0E6OlBhZ2UtMjI0Mw==","title":"Styling Moods Display","slug":"styling-moods-display","sections":{"nodes":[{"id":"T0E6OlNlY3Rpb24tMTEzMjM=","title":"Styling Moods Display","htmlContent":"<p>This chapter will focus on styling our page using CSS grid system. Currently our page has items displaying but they have not been styled yet.</p><p>At the end of this chapter, we will be able to have something like this.</p><p><a href=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P06-Styling-Moods-Display/assets/01_styling-moods-display_items-display.png\" target=\"_blank\">\n          <img src=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P06-Styling-Moods-Display/assets/01_styling-moods-display_items-display.png\" alt=\"Items display\" title=\"Items Display\">\n        </a></p><p>Our goal is display 4 items on each row and make a card style for each card.</p><p>We will use CSS grid properties to position each item in the page.</p><div class=\"info\">\n<p></p>\n\n<p>Follow these links to learn about CSS grids:</p>\n\n<ul>\n<li>\n<a href=\"https://www.w3schools.com/css/css_grid.asp\" target=\"_blank\">W3 CSS grid</a>,</li>\n<li><a href=\"https://css-tricks.com/snippets/css/complete-guide-grid/\" target=\"_blank\">CSS grid guide</a></li>\n</ul>\n</div><p>Inside our <code>index.html</code>, The <code>&lt;main&gt;</code> tag holds all the <code>div</code>s displayed in the page. So we should add the grid style on the <code>&lt;main&gt;</code> tag so its children could be aligned in a grid manner.</p><p>We will use its class name to access main.</p><div class=\"action\">\n<p></p>\n\n<p>add this to your <code>styles.css</code> file below the code you've written so far:</p>\n<pre><span class=\"p\">.</span><span class=\"nc\">items</span> <span class=\"p\">{</span>\n  <span class=\"k\">width</span><span class=\"p\">:</span> <span class=\"mi\">80</span><span class=\"kt\">%</span><span class=\"p\">;</span>\n  <span class=\"k\">margin</span><span class=\"p\">:</span> <span class=\"kc\">auto</span><span class=\"p\">;</span>\n</pre>\n</div><p>display: grid;\n  grid-template-columns: repeat(4, 1fr);\n  grid-gap: 1em;\n}\n```</p><p>These styles says that main.items should be 80% the width of it's parent (<code>width: 80%</code>) and centered since the margin on the left and right will be equal (<code>margin: auto</code>). It should arrange it's children in a grid (<code>display: grid</code>) and grid will have 4 equal sized columns (<code>grid-template-columns: repeat(4, 1fr)</code>) with a gap of 1em between columns and rows (<code>grid-gap: 1em</code>). </p><p>Earlier in Chapter 4, when we were making each <code>div</code> using the <code>for</code> loop, we gave it a class name of <code>item</code>. We can use this class name to style the <code>div</code>.</p><p>Add another style to target each image in the items and size them to fit their grid cell.</p><pre><span class=\"p\">.</span><span class=\"nc\">items</span> <span class=\"nt\">img</span> <span class=\"p\">{</span>\n  <span class=\"k\">width</span><span class=\"p\">:</span> <span class=\"mi\">100</span><span class=\"kt\">%</span><span class=\"p\">;</span>\n  <span class=\"k\">height</span><span class=\"p\">:</span> <span class=\"kc\">auto</span><span class=\"p\">;</span>\n<span class=\"p\">}</span>\n</pre><p>This rule targets img tags inside of elements with the class name: item. it syas their width chould 100% (<code>width: 100%</code>) that makes the images match the width of .item, and height should stay proportional to the width (<code>height: auto</code>). </p><p>Your page should now look something like this:</p><p><a href=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P06-Styling-Moods-Display/assets/02_styling-moods-display_items-display.png\" target=\"_blank\">\n          <img src=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P06-Styling-Moods-Display/assets/02_styling-moods-display_items-display.png\" alt=\"Items display in grid\" title=\"\">\n        </a></p><p>Now all that's left to do is style each item as a card.\nWe can add a border on each div so it will look like a card.</p><p>Add some styles of your own to customize the content of the grid cells. The contents are: </p><ul>\n<li>image</li>\n<li>description text </li>\n<li>price </li>\n<li>add to cart button</li>\n</ul><p>You can target each of these using these selectors: </p><p>Style the entire card: </p><pre><span class=\"p\">.</span><span class=\"nc\">item</span> <span class=\"p\">{</span> <span class=\"err\">...</span> <span class=\"p\">}</span>\n</pre><p>Style the image in the card: </p><pre><span class=\"p\">.</span><span class=\"nc\">item</span> <span class=\"nt\">img</span> <span class=\"p\">{</span> <span class=\"err\">...</span> <span class=\"p\">}</span>\n</pre><p>Style style both paragraphs in the card. This would be the description and the price: </p><pre><span class=\"p\">.</span><span class=\"nc\">item</span> <span class=\"nt\">p</span> <span class=\"p\">{</span> <span class=\"err\">...</span> <span class=\"p\">}</span>\n</pre><p>Target the first or the second paragraph in a card. The first p is the description and the second is the price: </p><pre><span class=\"p\">.</span><span class=\"nc\">item</span> <span class=\"nt\">p</span><span class=\"p\">:</span><span class=\"nd\">nth-child</span><span class=\"o\">(</span><span class=\"nt\">1</span><span class=\"o\">)</span> <span class=\"p\">{</span> <span class=\"err\">...</span> <span class=\"p\">}</span>\n<span class=\"p\">.</span><span class=\"nc\">item</span> <span class=\"nt\">p</span><span class=\"p\">:</span><span class=\"nd\">nth-child</span><span class=\"o\">(</span><span class=\"nt\">2</span><span class=\"o\">)</span> <span class=\"p\">{</span> <span class=\"err\">...</span> <span class=\"p\">}</span>\n</pre><p>Style the add to cart button: </p><pre><span class=\"p\">.</span><span class=\"nc\">item</span> <span class=\"nt\">button</span> <span class=\"p\">{</span> <span class=\"err\">...</span> <span class=\"p\">}</span>\n</pre><h2>Stretch Challenge:</h2><div class=\"challenge\">\n<p></p>\n\n<ul>\n<li>Make the \"Add To Cart\" button appear on the middle of each card</li>\n<li>Give your button element a background color and some padding</li>\n<li>Style your button</li>\n</ul>\n</div>"},{"id":"T0E6OlNlY3Rpb24tMTEzMjQ=","title":"Feedback and Review - 2 minutes","htmlContent":"<p><strong>We promise this won't take longer than 2 minutes!</strong></p><p>Please take a moment to rate your understanding of the learning outcomes from this tutorial, and how we can improve it via our <a href=\"https://forms.gle/BrEWZioQ566MSXMH6\" target=\"_blank\">tutorial feedback form</a></p><p>This allows us to get feedback on how well the students are grasping the learning outcomes, and tells us where we can improve the tutorial experience.</p>"},{"id":"T0E6OlNlY3Rpb24tMTEzMjU=","title":"Update progress on Github","htmlContent":"<div class=\"action\">\n<p></p>\n\n<p>Now is a good time to update your progress on Github.</p>\n<pre>git add .\ngit commit -m <span class=\"s1\">'styled items displayed using grid css'</span>\ngit push\n</pre>\n</div>"}]},"next":{"id":"T0E6OlBhZ2UtMjI0NA==","slug":"shopping-cart-tutorial","title":"Shopping Cart Tutorial"},"previous":{"id":"T0E6OlBhZ2UtMjI0NA==","slug":"shopping-cart-tutorial","title":"Shopping Cart Tutorial"}},{"id":"T0E6OlBhZ2UtMjI0NA==","title":"Shopping Cart Tutorial","slug":"shopping-cart-tutorial","sections":{"nodes":[{"id":"T0E6OlNlY3Rpb24tMTEzMjY=","title":"Shopping Cart Tutorial","htmlContent":"<p>This chapter along with the remaining chapters will guide you through how to make your ecommerce website functional. We will be adding a shopping cart functionality where users can add and remove items from their cart.</p><p>For simplicity, we will have the shopping cart page on the same page where the moods are displayed.</p>"},{"id":"T0E6OlNlY3Rpb24tMTEzMjc=","title":"Adding Items to Cart","htmlContent":"<p>Our shopping cart will be located in the footer of our ecommerce page.</p><p>We will add a footer element in our html.</p><div class=\"action\">\n<p>\nAdd a footer element after the main element inside your <code>index.html</code> file</p>\n<pre><span class=\"p\">&lt;</span><span class=\"nt\">footer</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;/</span><span class=\"nt\">footer</span><span class=\"p\">&gt;</span>\n</pre>\n</div><p>Your HTML markup should now look like this:</p><pre><span class=\"p\">&lt;</span><span class=\"nt\">html</span> <span class=\"na\">lang</span><span class=\"o\">=</span><span class=\"s\">\"en\"</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;</span><span class=\"nt\">head</span><span class=\"p\">&gt;</span>\n  <span class=\"p\">&lt;</span><span class=\"nt\">meta</span> <span class=\"na\">charset</span><span class=\"o\">=</span><span class=\"s\">\"UTF-8\"</span><span class=\"p\">&gt;</span>\n  <span class=\"p\">&lt;</span><span class=\"nt\">meta</span> <span class=\"na\">name</span><span class=\"o\">=</span><span class=\"s\">\"viewport\"</span> <span class=\"na\">content</span><span class=\"o\">=</span><span class=\"s\">\"width=device-width, initial-scale=1.0\"</span><span class=\"p\">&gt;</span>\n  <span class=\"p\">&lt;</span><span class=\"nt\">title</span><span class=\"p\">&gt;</span>Groceries<span class=\"p\">&lt;/</span><span class=\"nt\">title</span><span class=\"p\">&gt;</span>\n  <span class=\"p\">&lt;</span><span class=\"nt\">link</span> <span class=\"na\">rel</span><span class=\"o\">=</span><span class=\"s\">'stylesheet'</span> <span class=\"na\">href</span><span class=\"o\">=</span><span class=\"s\">'./resources/css/styles.css'</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;/</span><span class=\"nt\">head</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;</span><span class=\"nt\">body</span><span class=\"p\">&gt;</span>\n  <span class=\"p\">&lt;</span><span class=\"nt\">header</span> <span class=\"na\">class</span><span class=\"o\">=</span><span class=\"s\">'page-header'</span><span class=\"p\">&gt;</span>\n    <span class=\"p\">&lt;</span><span class=\"nt\">h4</span><span class=\"p\">&gt;</span>The Mood Shop<span class=\"p\">&lt;/</span><span class=\"nt\">h4</span><span class=\"p\">&gt;</span>\n    <span class=\"p\">&lt;</span><span class=\"nt\">nav</span><span class=\"p\">&gt;</span>\n      <span class=\"p\">&lt;</span><span class=\"nt\">ul</span><span class=\"p\">&gt;</span>\n        <span class=\"p\">&lt;</span><span class=\"nt\">li</span><span class=\"p\">&gt;&lt;</span><span class=\"nt\">a</span> <span class=\"na\">href</span><span class=\"o\">=</span><span class=\"s\">\"#\"</span><span class=\"p\">&gt;</span>Home<span class=\"p\">&lt;/</span><span class=\"nt\">a</span><span class=\"p\">&gt;&lt;/</span><span class=\"nt\">li</span><span class=\"p\">&gt;</span>\n        <span class=\"p\">&lt;</span><span class=\"nt\">li</span><span class=\"p\">&gt;&lt;</span><span class=\"nt\">a</span> <span class=\"na\">href</span><span class=\"o\">=</span><span class=\"s\">\"#\"</span><span class=\"p\">&gt;</span>About<span class=\"p\">&lt;/</span><span class=\"nt\">a</span><span class=\"p\">&gt;&lt;/</span><span class=\"nt\">li</span><span class=\"p\">&gt;</span>\n        <span class=\"p\">&lt;</span><span class=\"nt\">li</span><span class=\"p\">&gt;&lt;</span><span class=\"nt\">a</span> <span class=\"na\">href</span><span class=\"o\">=</span><span class=\"s\">\"#\"</span><span class=\"p\">&gt;</span>Cart<span class=\"p\">&lt;/</span><span class=\"nt\">a</span><span class=\"p\">&gt;&lt;/</span><span class=\"nt\">li</span><span class=\"p\">&gt;</span>\n      <span class=\"p\">&lt;/</span><span class=\"nt\">ul</span><span class=\"p\">&gt;</span>\n    <span class=\"p\">&lt;/</span><span class=\"nt\">nav</span><span class=\"p\">&gt;</span>\n  <span class=\"p\">&lt;/</span><span class=\"nt\">header</span><span class=\"p\">&gt;</span>\n  <span class=\"p\">&lt;</span><span class=\"nt\">main</span> <span class=\"na\">class</span><span class=\"o\">=</span><span class=\"s\">'items'</span> <span class=\"na\">id</span><span class=\"o\">=</span><span class=\"s\">'items'</span><span class=\"p\">&gt;</span>\n    <span class=\"c\">&lt;!--</span>\n<span class=\"c\">      Display moods here</span>\n<span class=\"c\">     --&gt;</span>\n  <span class=\"p\">&lt;/</span><span class=\"nt\">main</span><span class=\"p\">&gt;</span>\n  <span class=\"p\">&lt;</span><span class=\"nt\">footer</span><span class=\"p\">&gt;</span>\n  <span class=\"p\">&lt;/</span><span class=\"nt\">footer</span><span class=\"p\">&gt;</span>\n  <span class=\"p\">&lt;</span><span class=\"nt\">script</span> <span class=\"na\">src</span><span class=\"o\">=</span><span class=\"s\">'./resources/js/scripts.js'</span> <span class=\"na\">type</span><span class=\"o\">=</span><span class=\"s\">\"module\"</span><span class=\"p\">&gt;&lt;/</span><span class=\"nt\">script</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;/</span><span class=\"nt\">body</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;/</span><span class=\"nt\">html</span><span class=\"p\">&gt;</span>\n</pre><p>Follow this shopping cart tutorial to add the shopping cart functionality.</p><p>The tutorial is slightly different, but we're essentially using the same functionality of the shopping cart tutorial.</p><p>In the video tutorial, all code is written inside <code>index.html</code>. But since we have a separate <code>scripts.js</code> file, we'll write the javascript code in there instead of inside the <code>&lt;script&gt;</code> tag.</p><p>You can write the javascript functions below the code you wrote for displaying moods in <code>scripts.js</code> file.</p><div class=\"action\">\n<p></p>\n\n<p><strong>ONE MORE TIME, AS THIS IS IMPORTANT:</strong></p>\n\n<p>In the video tutorial, <strong>all code is written inside <code>index.html</code>.</strong> But since we have a separate <code>scripts.js</code> file, <strong>we'll write the javascript code in there instead of inside the <code>&lt;script&gt;</code> tag.</strong></p>\n\n<p>You can write the javascript functions below the code you wrote for displaying moods in <code>scripts.js</code> file.</p>\n</div>"},{"id":"T0E6OlNlY3Rpb24tMTEzMjg=","title":"1st video (start at 5:25 - end)","htmlContent":"<p>This first video will walk you through how to add and show items on your console by writing the functions <code>addItem()</code> and <code>showItems()</code>.</p><p>Follow the video <strong>starting at 5:25</strong> until the end.</p><p><iframe width=\"640\" height=\"360\" src=\"https://www.youtube.com/embed/oMTO0LbBGLA\" frameborder=\"0\" allowfullscreen></iframe></p>"},{"id":"T0E6OlNlY3Rpb24tMTEzMjk=","title":"2nd video","htmlContent":"<p>In this video, we'll be discussing how to use objects to add items into an array. Follow the full video.</p><p><iframe width=\"640\" height=\"360\" src=\"https://www.youtube.com/embed/yUfbzeKol04\" frameborder=\"0\" allowfullscreen></iframe></p>"},{"id":"T0E6OlNlY3Rpb24tMTEzMzA=","title":"Update progress on Github","htmlContent":"<div class=\"action\">\n<p></p>\n\n<p>Now is a good time to update your progress on Github.</p>\n<pre>git add .\ngit commit -m <span class=\"s1\">'add item and show item functions working'</span>\ngit push\n</pre>\n</div>"}]},"next":{"id":"T0E6OlBhZ2UtMjI0NQ==","slug":"displaying-cart-in-console","title":"Displaying Cart In Console"},"previous":{"id":"T0E6OlBhZ2UtMjI0NQ==","slug":"displaying-cart-in-console","title":"Displaying Cart In Console"}},{"id":"T0E6OlBhZ2UtMjI0NQ==","title":"Displaying Cart In Console","slug":"displaying-cart-in-console","sections":{"nodes":[{"id":"T0E6OlNlY3Rpb24tMTEzMzE=","title":"Displaying Cart In Console","htmlContent":"<p>In this chapter there will be 3 videos that will guide you in: </p><ul>\n<li><p>Displaying cart items in the console using a for loop</p></li>\n<li><p>Displaying the total amount of price for our cart</p></li>\n<li><p>Displaying the number of items we have in our cart</p></li>\n</ul>"},{"id":"T0E6OlNlY3Rpb24tMTEzMzI=","title":"3rd Video","htmlContent":"<p>This video will walk you through on how to use a <strong>for-loop</strong> to loop through items in an array and display them in the console.</p><p><iframe width=\"640\" height=\"360\" src=\"https://www.youtube.com/embed/m2dAe0aHOlQ\" frameborder=\"0\" allowfullscreen></iframe></p>"},{"id":"T0E6OlNlY3Rpb24tMTEzMzM=","title":"4th Video","htmlContent":"<p>In this video you will calculate the total quantity of items in the cart and the total cost of all items by using a loop to iterate over all items in the cart.</p><p><iframe width=\"640\" height=\"360\" src=\"https://www.youtube.com/embed/oTnd2lx5c-8\" frameborder=\"0\" allowfullscreen></iframe></p>"},{"id":"T0E6OlNlY3Rpb24tMTEzMzQ=","title":"5th Video","htmlContent":"<p>Here you'll look over the code and make some syntactic improvements. We will also talk about returning values from functions to make them more useful. </p><p><iframe width=\"640\" height=\"360\" src=\"https://www.youtube.com/embed/oCNlmeh310c\" frameborder=\"0\" allowfullscreen></iframe></p>"},{"id":"T0E6OlNlY3Rpb24tMTEzMzU=","title":"Update progress on Github","htmlContent":"<div class=\"action\">\n<p></p>\n\n<p>Now is a good time to update your progress on Github.</p>\n<pre>git add .\ngit commit -m <span class=\"s1\">'displayed cart items on console'</span>\ngit push\n</pre>\n</div>"}]},"next":{"id":"T0E6OlBhZ2UtMjI0Ng==","slug":"remove-item-from-cart","title":"Remove Item From Cart"},"previous":{"id":"T0E6OlBhZ2UtMjI0Ng==","slug":"remove-item-from-cart","title":"Remove Item From Cart"}},{"id":"T0E6OlBhZ2UtMjI0Ng==","title":"Remove Item From Cart","slug":"remove-item-from-cart","sections":{"nodes":[{"id":"T0E6OlNlY3Rpb24tMTEzMzY=","title":"Remove Item From Cart","htmlContent":"<p>In this chapter there will be 2 videos that will guide you in: </p><ul>\n<li><p>Removing item from the cart</p></li>\n<li><p>Removing 1 quantity of an item</p></li>\n<li><p>Removing all quantity of an item</p></li>\n</ul><p>We will work on making the removeItem() function. </p><p>We are still working on the <code>scripts.js</code> file! </p>"},{"id":"T0E6OlNlY3Rpb24tMTEzMzc=","title":"6th Video","htmlContent":"<p>This video covers removing items from the cart. Here you will use the Array.splice() method.</p><p><iframe width=\"640\" height=\"360\" src=\"https://www.youtube.com/embed/pJfQIrMEnBc\" frameborder=\"0\" allowfullscreen></iframe></p>"},{"id":"T0E6OlNlY3Rpb24tMTEzMzg=","title":"7th Video","htmlContent":"<p>Here we will take another look at the remove item function and use a default parameter to remove all or just one item from the cart.</p><p><iframe width=\"640\" height=\"360\" src=\"https://www.youtube.com/embed/GLxT2MCffAw\" frameborder=\"0\" allowfullscreen></iframe></p>"},{"id":"T0E6OlNlY3Rpb24tMTEzMzk=","title":"Update progress on Github","htmlContent":"<div class=\"action\">\n<p></p>\n\n<p>Now is a good time to update your progress on Github.</p>\n<pre>git add .\ngit commit -m <span class=\"s1\">'added removeItem function'</span>\ngit push\n</pre>\n</div>"}]},"next":{"id":"T0E6OlBhZ2UtMjI0Nw==","slug":"connect-shopping-cart-with-ecommerce","title":"Connect Shopping Cart with E-commerce"},"previous":{"id":"T0E6OlBhZ2UtMjI0Nw==","slug":"connect-shopping-cart-with-ecommerce","title":"Connect Shopping Cart with E-commerce"}},{"id":"T0E6OlBhZ2UtMjI0Nw==","title":"Connect Shopping Cart with E-commerce","slug":"connect-shopping-cart-with-ecommerce","sections":{"nodes":[{"id":"T0E6OlNlY3Rpb24tMTEzNDA=","title":"Connect Shopping Cart with E-commerce","htmlContent":"<p>Now that we have written the functions of a shopping cart, it is time to display our results in the browser instead of the console.</p><p>Inside the <code>&lt;footer&gt;</code> element we created in <code>index.html</code>, we need to make a <code>&lt;ul&gt;</code> element to store the list of cart items we have.</p><div class=\"action\">\n<p></p>\n\n<p>Add the <code>&lt;ul&gt;</code> element to the footer</p>\n<pre><span class=\"p\">&lt;</span><span class=\"nt\">footer</span><span class=\"p\">&gt;</span>\n    <span class=\"p\">&lt;</span><span class=\"nt\">ul</span> <span class=\"na\">id</span><span class=\"o\">=</span><span class=\"s\">'item-list'</span><span class=\"p\">&gt;</span>\n      <span class=\"c\">&lt;!-- cart items --&gt;</span>\n    <span class=\"p\">&lt;/</span><span class=\"nt\">ul</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;/</span><span class=\"nt\">footer</span><span class=\"p\">&gt;</span>\n</pre>\n</div><p>We can access this <code>ul</code> element in our javascript file using its id <strong>item-list</strong>.</p><div class=\"action\">\n<p>\nOn top of your <code>scripts.js</code> file, add a variable called <code>itemList</code> that will hold the reference to the <code>ul</code> element.</p>\n<pre><span class=\"kr\">const</span> <span class=\"nx\">itemList</span> <span class=\"o\">=</span> <span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">getElementById</span><span class=\"p\">(</span><span class=\"s1\">'item-list'</span><span class=\"p\">)</span>\n</pre>\n</div><p>You can check if it's getting the <code>ul</code> element by printing it into the console.</p><div class=\"action\">\n<p>\nAdd <code>console.log(itemList)</code> into your <code>scripts.js</code> file to check.</p>\n</div><p>You should now see</p><pre><span class=\"p\">&lt;</span><span class=\"nt\">ul</span> <span class=\"na\">id</span><span class=\"o\">=</span><span class=\"s\">'item-list'</span><span class=\"p\">&gt;</span>\n  <span class=\"c\">&lt;!-- cart items --&gt;</span>\n<span class=\"p\">&lt;/</span><span class=\"nt\">ul</span><span class=\"p\">&gt;</span>\n</pre><p>in your console.</p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNDE=","title":"Writing inside the ul element","htmlContent":"<p>We can use the property <code>innerHTML</code> to write in the <code>ul</code> tag.</p><div class=\"action\">\n<p>\nIn your <code>scripts.js</code> file, right after you declared the <code>itemList</code> variable, add:</p>\n<pre><span class=\"nx\">itemList</span><span class=\"p\">.</span><span class=\"nx\">innerHTML</span> <span class=\"o\">=</span> <span class=\"s1\">'&lt;li&gt; Hello World&lt;/li&gt;'</span>\n</pre>\n</div><p>This will add a <code>&lt;li&gt;</code> element named <strong>Hello World</strong> inside our <code>&lt;ul&gt;</code> element.</p><p>If you refresh your page now, you should see a list element named <strong>Hello World</strong>.</p><p><a href=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P10-Connect-Shopping-Cart-With-Ecommerce/assets/01_connect-footer_hello-world.png\" target=\"_blank\">\n          <img src=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P10-Connect-Shopping-Cart-With-Ecommerce/assets/01_connect-footer_hello-world.png\" alt=\"Connect footer\" title=\"Connect footer\">\n        </a></p><h2>Using itemList.innerHTML to display items in cart</h2><p>In order to display items in the cart, we need to use <code>itemList.innerHTML</code> inside our <code>showItems()</code> function in <code>scripts.js</code>.</p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNDI=","title":"8th Video (Start from 5:40 - end)","htmlContent":"<p>Follow this video <strong>starting at 5:40</strong> to refactor the <code>showItems()</code> function.</p><p>Work on the challenges that were mentioned at the end of the video.</p><p><iframe width=\"640\" height=\"360\" src=\"https://www.youtube.com/embed/Z5bypy7hHno\" frameborder=\"0\" allowfullscreen></iframe></p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNDM=","title":"Displaying quantity and total price of your items in cart","htmlContent":"<p>Follow video 9 to display quantity of items</p><div class=\"action\">\n<p></p>\n\n<p><strong>Note</strong>: In the video, to display the cart, the <code>div</code> and <code>ul</code> element goes into the <code>body</code> tag, but for our project, <strong>we're going to put these elements inside the <code>&lt;footer&gt; &lt;/footer&gt;</code> element.</strong></p>\n<pre><span class=\"p\">&lt;</span><span class=\"nt\">footer</span><span class=\"p\">&gt;</span>\n    <span class=\"p\">&lt;</span><span class=\"nt\">div</span> <span class=\"na\">id</span><span class=\"o\">=</span><span class=\"s\">'cart-qty'</span><span class=\"p\">&gt;</span>\n      <span class=\"c\">&lt;!-- cart qty here --&gt;</span>\n    <span class=\"p\">&lt;/</span><span class=\"nt\">div</span><span class=\"p\">&gt;</span>\n    <span class=\"p\">&lt;</span><span class=\"nt\">ul</span> <span class=\"na\">id</span><span class=\"o\">=</span><span class=\"s\">'item-list'</span><span class=\"p\">&gt;</span>\n      <span class=\"c\">&lt;!-- cart items --&gt;</span>\n    <span class=\"p\">&lt;/</span><span class=\"nt\">ul</span><span class=\"p\">&gt;</span>\n    <span class=\"p\">&lt;</span><span class=\"nt\">div</span> <span class=\"na\">id</span><span class=\"o\">=</span><span class=\"s\">'cart-total'</span><span class=\"p\">&gt;</span>\n      <span class=\"c\">&lt;!-- cart total --&gt;</span>\n    <span class=\"p\">&lt;/</span><span class=\"nt\">div</span><span class=\"p\">&gt;</span>\n  <span class=\"p\">&lt;/</span><span class=\"nt\">footer</span><span class=\"p\">&gt;</span>\n</pre>\n</div>"},{"id":"T0E6OlNlY3Rpb24tMTEzNDQ=","title":"9th Video","htmlContent":"<p>In this video you'll print the quantity and total of all items in the shopping cart.</p><p><iframe width=\"640\" height=\"360\" src=\"https://www.youtube.com/embed/g0oRBqqk-Kk\" frameborder=\"0\" allowfullscreen></iframe></p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNDU=","title":"Update progress on Github","htmlContent":"<div class=\"action\">\n<p></p>\n\n<p>Now is a good time to update your progress on Github.</p>\n<pre>git add .\ngit commit -m <span class=\"s1\">'connect cart to footer'</span>\ngit push\n</pre>\n</div>"}]},"next":{"id":"T0E6OlBhZ2UtMjI0OA==","slug":"connect-add-to-cart-button-with-shopping-cart","title":"Connect Add to Cart button with Shopping Cart"},"previous":{"id":"T0E6OlBhZ2UtMjI0OA==","slug":"connect-add-to-cart-button-with-shopping-cart","title":"Connect Add to Cart button with Shopping Cart"}},{"id":"T0E6OlBhZ2UtMjI0OA==","title":"Connect Add to Cart button with Shopping Cart","slug":"connect-add-to-cart-button-with-shopping-cart","sections":{"nodes":[{"id":"T0E6OlNlY3Rpb24tMTEzNDY=","title":"Connect Add to Cart button with Shopping Cart","htmlContent":"<p>Now that we can show the shopping cart in the footer of our page, the next\nstep would be to connect our 'Add to Cart' buttons on the items to the cart.\nThis way, when a user clicks on 'Add to Cart', the item will be displayed inside\nthe cart!</p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNDc=","title":"Using querySelectorAll function","htmlContent":"<p>The first thing we need to do is get all the buttons from the page. Currently all the buttons on our page are the 'Add to Cart' buttons.</p><p>To select all buttons, we will use the <code>document.querySelectorAll</code> function.</p><p>This function gives you all the elements in the document that matches the query.</p><p><strong>For example</strong>: if we pass <code>document.querySelectorAll('button')</code>, we will get a node list of all the buttons in our document/page.</p><div class=\"info\">\n<p></p>\n\n<p>To learn more about <code>document.querySelectorAll</code> :\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll\" target=\"_blank\">querySelectorAll info</a></p>\n</div><!--  --><div class=\"action\">\n<p></p>\n\n<p>Use <code>querySelectorAll</code> to select all buttons and assign it to a variable named <code>all_items_button</code></p>\n\n<p>Navigate to your <code>scripts.js</code> file. Add this code below the for loop you wrote to display items in the page</p>\n<pre><span class=\"kr\">const</span> <span class=\"nx\">all_items_button</span> <span class=\"o\">=</span> <span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">querySelectorAll</span><span class=\"p\">(</span><span class=\"s2\">\"button\"</span><span class=\"p\">)</span>\n</pre>\n</div><p>If we print <code>all_items_button</code> to our console, we'll see that this gives us a node list of all the buttons in the document.</p><p><a href=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P11-Connect-AddToCart-Button-With-Cart/assets/01_connect-addtocart_nodeList-buttons.png\" target=\"_blank\">\n          <img src=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P11-Connect-AddToCart-Button-With-Cart/assets/01_connect-addtocart_nodeList-buttons.png\" alt=\"Node list of buttons\" title=\"Node list of buttons\">\n        </a></p><p>We need to convert this into an array. This will make it easier to loop through each button and assign it the <code>addItem</code> function.</p><div class=\"info\">\n<p>\nCheck out more on <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from\" target=\"_blank\">Array.from info</a></p>\n</div><!--  --><div class=\"action\">\n<p>\nModify the variable <code>all_items_button</code> using <code>Array.from</code> to convert the node lists into an array:</p>\n<pre><span class=\"kr\">const</span> <span class=\"nx\">all_items_button</span> <span class=\"o\">=</span> <span class=\"nb\">Array</span><span class=\"p\">.</span><span class=\"nx\">from</span><span class=\"p\">(</span><span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">querySelectorAll</span><span class=\"p\">(</span><span class=\"s2\">\"button\"</span><span class=\"p\">))</span>\n</pre>\n</div><p>If you check your console again, you should see array instead of lists.</p><p><a href=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P11-Connect-AddToCart-Button-With-Cart/assets/02_connect-addtocart_arrayList-buttons.png\" target=\"_blank\">\n          <img src=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P11-Connect-AddToCart-Button-With-Cart/assets/02_connect-addtocart_arrayList-buttons.png\" alt=\"Array list of buttons\" title=\"Array list of buttons\">\n        </a></p><p>Now that we have access to all the buttons, we can connect it to the <code>addItem()</code> and <code>showItems()</code> function when the button is clicked.</p><p>We'll use another <code>for</code> loop to</p><ol>\n<li>loop through the buttons</li>\n<li>check if it's clicked or not</li>\n<li>if clicked, add the item to the cart.</li>\n</ol>"},{"id":"T0E6OlNlY3Rpb24tMTEzNDg=","title":"Adding event listener","htmlContent":"<div class=\"info\">\n<p></p>\n\n<p>More info on how to add an <a href=\"https://www.w3schools.com/jsref/met_element_addeventlistener.asp\" target=\"_blank\">Event listener</a></p>\n</div><p>We'll add an event listener for each button, to listen to a click event.</p><p>The event listener takes 2 parameters:</p><ol>\n<li>an event</li>\n<li>a callback function</li>\n</ol><p>Here our event is a click event, and our callback function will be to add the clicked item to the shopping cart.</p><p>We'll use <code>addItem()</code> and once the item gets added, call <code>showItems()</code> function to rerun the <code>showItems()</code> to include the added item in the footer.</p><p>The <code>addItem</code> function takes 2 arguments, which are <strong>name</strong> and <strong>price</strong>.</p><p>We'll get the name of the item from the <strong>button id</strong> and the price from the custom attribute <strong>data-price</strong>.</p><p>We'll use <code>getAttribute</code> function to get the attributes <code>id</code> and <code>data-price</code>.</p><div class=\"info\">\n<p></p>\n\n<p>More info on <a href=\"https://www.w3schools.com/jsref/met_element_getattribute.asp\" target=\"_blank\">getAttribute</a></p>\n</div><!--  --><div class=\"action\">\n<p></p>\n\n<p>Inside your <code>scripts.js</code> file, add this <code>forEach</code> loop below your <code>all_items_button</code> variable</p>\n<pre><span class=\"nx\">all_items_button</span><span class=\"p\">.</span><span class=\"nx\">forEach</span><span class=\"p\">(</span><span class=\"nx\">elt</span> <span class=\"p\">=&gt;</span> <span class=\"nx\">elt</span><span class=\"p\">.</span><span class=\"nx\">addEventListener</span><span class=\"p\">(</span><span class=\"s1\">'click'</span><span class=\"p\">,</span> <span class=\"p\">()</span> <span class=\"p\">=&gt;</span> <span class=\"p\">{</span>\n  <span class=\"nx\">addItem</span><span class=\"p\">(</span><span class=\"nx\">elt</span><span class=\"p\">.</span><span class=\"nx\">getAttribute</span><span class=\"p\">(</span><span class=\"s1\">'id'</span><span class=\"p\">),</span> <span class=\"nx\">elt</span><span class=\"p\">.</span><span class=\"nx\">getAttribute</span><span class=\"p\">(</span><span class=\"s1\">'data-price'</span><span class=\"p\">))</span>\n  <span class=\"nx\">showItems</span><span class=\"p\">()</span>\n<span class=\"p\">}))</span>\n</pre>\n</div><p>Now refresh your browser and try adding some items to your shopping cart by clicking on any of the 'Add to Cart' buttons.</p><p><a href=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P11-Connect-AddToCart-Button-With-Cart/assets/03_connect-addtocart_cart-connected.png\" target=\"_blank\">\n          <img src=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P11-Connect-AddToCart-Button-With-Cart/assets/03_connect-addtocart_cart-connected.png\" alt=\"Button connected with cart\" title=\"button connected with cart\">\n        </a></p><p>Woo hoo!! &#127881;&#127882; Our cart is finally connected with the \"Add to Cart\" button!!</p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNDk=","title":"Update progress on Github","htmlContent":"<div class=\"action\">\n<p></p>\n\n<p>Now is a good time to update your progress on Github.</p>\n<pre>git add .\ngit commit -m <span class=\"s1\">'add button connected to cart'</span>\ngit push\n</pre>\n</div>"}]},"next":{"id":"T0E6OlBhZ2UtMjI0OQ==","slug":"shopping-cart-features","title":"Shopping Cart Features"},"previous":{"id":"T0E6OlBhZ2UtMjI0OQ==","slug":"shopping-cart-features","title":"Shopping Cart Features"}},{"id":"T0E6OlBhZ2UtMjI0OQ==","title":"Shopping Cart Features","slug":"shopping-cart-features","sections":{"nodes":[{"id":"T0E6OlNlY3Rpb24tMTEzNTA=","title":"Shopping Cart Features","htmlContent":"<p>In this last chapter, we will be finishing up the shopping cart functionality.</p><p>So far our cart has been connected with the e-commerce page and 'Add to cart' buttons attached to each items.</p><p>It would also be nice if we can update the quantity of selected item, and remove an item from our cart.</p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNTE=","title":"Adding \"Remove items\" button to our Shopping Cart","htmlContent":"<h2>11th Video (Start from 2:25 - end)</h2><p>Follow this video <strong>starting at 2:25</strong> implement \"Remove items\" button to our shopping cart. Here you will create a remove item button for each item displayed in the cart.</p><p>At the start the video is slightly different but you will be implementing the same functionality throughout the video.</p><p><iframe width=\"640\" height=\"360\" src=\"https://www.youtube.com/embed/l2M5q2te234\" frameborder=\"0\" allowfullscreen></iframe></p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNTI=","title":"Adding \"add one\" and \"remove one\" buttons for each items inside shopping cart","htmlContent":"<h2>12th Video</h2><p>Here we'll add a button to remove one item from the cart.</p><p><iframe width=\"640\" height=\"360\" src=\"https://www.youtube.com/embed/SjV6pdFV6aI\" frameborder=\"0\" allowfullscreen></iframe></p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNTM=","title":"Updating items in shopping cart","htmlContent":"<h2>13th Video</h2><p>Here you will add an input that allows you to set the number of items in the cart. To do this you'll listen for an on change event.</p><p><iframe width=\"640\" height=\"360\" src=\"https://www.youtube.com/embed/saizM7bVaTo\" frameborder=\"0\" allowfullscreen></iframe></p><p>Now our page should look like this:</p><p><a href=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P12-Shopping-Cart-Features/assets/01_shopping-cart-features_fully-functional.png\" target=\"_blank\">\n          <img src=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P12-Shopping-Cart-Features/assets/01_shopping-cart-features_fully-functional.png\" alt=\"Cart fully functional\" title=\"cart fully functional\">\n        </a></p><h2>Stretch Challenge:</h2><div class=\"challenge\">\n<p></p>\n\n<ul>\n<li>Style the shopping cart (CSS)</li>\n<li>Style all the buttons inside the shopping cart (CSS)</li>\n<li>Remove the dots on the list of items in the shopping cart (CSS)</li>\n<li>Customize your Mood Shop by changing the theme of the navbar, body and footer (CSS)</li>\n<li>In the navbar, there is a link called 'cart'. Currently if you click on it, it doesn't do anything. Connect the link to the shopping cart so that when a user clicks on cart, it takes them to the footer where the cart is located.</li>\n</ul>\n</div>"},{"id":"T0E6OlNlY3Rpb24tMTEzNTQ=","title":"Feedback and Review - 2 minutes","htmlContent":"<p><strong>If you haven't filled out the tutorial survey, please do so now!</strong></p><p><strong>We promise this won't take longer than 2 minutes!</strong></p><p>Please take a moment to rate your understanding of the learning outcomes from this tutorial, and how we can improve it via our <a href=\"https://forms.gle/BrEWZioQ566MSXMH6\" target=\"_blank\">tutorial feedback form</a></p><p>This allows us to get feedback on how well the students are grasping the learning outcomes, and tells us where we can improve the tutorial experience.</p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNTU=","title":"Congrats!!","htmlContent":"<div class=\"action\">\n<p></p>\n\n<p>Now is a good time to update your progress on Github.</p>\n<pre>git add .\ngit commit -m <span class=\"s1\">'cart fully functional'</span>\ngit push\n</pre>\n</div><p><strong>CONGRATS on completing the Mood Shop tutorial!</strong> You should now have a better understanding on how to use HTML, CSS, and JS together!</p>"}]},"next":null,"previous":null}]}},"page":{"id":"T0E6OlBhZ2UtMjI0Nw==","title":"Connect Shopping Cart with E-commerce","slug":"connect-shopping-cart-with-ecommerce","sections":{"nodes":[{"id":"T0E6OlNlY3Rpb24tMTEzNDA=","title":"Connect Shopping Cart with E-commerce","htmlContent":"<p>Now that we have written the functions of a shopping cart, it is time to display our results in the browser instead of the console.</p><p>Inside the <code>&lt;footer&gt;</code> element we created in <code>index.html</code>, we need to make a <code>&lt;ul&gt;</code> element to store the list of cart items we have.</p><div class=\"action\">\n<p></p>\n\n<p>Add the <code>&lt;ul&gt;</code> element to the footer</p>\n<pre><span class=\"p\">&lt;</span><span class=\"nt\">footer</span><span class=\"p\">&gt;</span>\n    <span class=\"p\">&lt;</span><span class=\"nt\">ul</span> <span class=\"na\">id</span><span class=\"o\">=</span><span class=\"s\">'item-list'</span><span class=\"p\">&gt;</span>\n      <span class=\"c\">&lt;!-- cart items --&gt;</span>\n    <span class=\"p\">&lt;/</span><span class=\"nt\">ul</span><span class=\"p\">&gt;</span>\n<span class=\"p\">&lt;/</span><span class=\"nt\">footer</span><span class=\"p\">&gt;</span>\n</pre>\n</div><p>We can access this <code>ul</code> element in our javascript file using its id <strong>item-list</strong>.</p><div class=\"action\">\n<p>\nOn top of your <code>scripts.js</code> file, add a variable called <code>itemList</code> that will hold the reference to the <code>ul</code> element.</p>\n<pre><span class=\"kr\">const</span> <span class=\"nx\">itemList</span> <span class=\"o\">=</span> <span class=\"nb\">document</span><span class=\"p\">.</span><span class=\"nx\">getElementById</span><span class=\"p\">(</span><span class=\"s1\">'item-list'</span><span class=\"p\">)</span>\n</pre>\n</div><p>You can check if it's getting the <code>ul</code> element by printing it into the console.</p><div class=\"action\">\n<p>\nAdd <code>console.log(itemList)</code> into your <code>scripts.js</code> file to check.</p>\n</div><p>You should now see</p><pre><span class=\"p\">&lt;</span><span class=\"nt\">ul</span> <span class=\"na\">id</span><span class=\"o\">=</span><span class=\"s\">'item-list'</span><span class=\"p\">&gt;</span>\n  <span class=\"c\">&lt;!-- cart items --&gt;</span>\n<span class=\"p\">&lt;/</span><span class=\"nt\">ul</span><span class=\"p\">&gt;</span>\n</pre><p>in your console.</p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNDE=","title":"Writing inside the ul element","htmlContent":"<p>We can use the property <code>innerHTML</code> to write in the <code>ul</code> tag.</p><div class=\"action\">\n<p>\nIn your <code>scripts.js</code> file, right after you declared the <code>itemList</code> variable, add:</p>\n<pre><span class=\"nx\">itemList</span><span class=\"p\">.</span><span class=\"nx\">innerHTML</span> <span class=\"o\">=</span> <span class=\"s1\">'&lt;li&gt; Hello World&lt;/li&gt;'</span>\n</pre>\n</div><p>This will add a <code>&lt;li&gt;</code> element named <strong>Hello World</strong> inside our <code>&lt;ul&gt;</code> element.</p><p>If you refresh your page now, you should see a list element named <strong>Hello World</strong>.</p><p><a href=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P10-Connect-Shopping-Cart-With-Ecommerce/assets/01_connect-footer_hello-world.png\" target=\"_blank\">\n          <img src=\"https://cdn.jsdelivr.net/gh/MakeSchool-Tutorials/ecommerce-tutorial@814a53f7dd63e9a10b48d3db077d9dd6dd570de1/P10-Connect-Shopping-Cart-With-Ecommerce/assets/01_connect-footer_hello-world.png\" alt=\"Connect footer\" title=\"Connect footer\">\n        </a></p><h2>Using itemList.innerHTML to display items in cart</h2><p>In order to display items in the cart, we need to use <code>itemList.innerHTML</code> inside our <code>showItems()</code> function in <code>scripts.js</code>.</p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNDI=","title":"8th Video (Start from 5:40 - end)","htmlContent":"<p>Follow this video <strong>starting at 5:40</strong> to refactor the <code>showItems()</code> function.</p><p>Work on the challenges that were mentioned at the end of the video.</p><p><iframe width=\"640\" height=\"360\" src=\"https://www.youtube.com/embed/Z5bypy7hHno\" frameborder=\"0\" allowfullscreen></iframe></p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNDM=","title":"Displaying quantity and total price of your items in cart","htmlContent":"<p>Follow video 9 to display quantity of items</p><div class=\"action\">\n<p></p>\n\n<p><strong>Note</strong>: In the video, to display the cart, the <code>div</code> and <code>ul</code> element goes into the <code>body</code> tag, but for our project, <strong>we're going to put these elements inside the <code>&lt;footer&gt; &lt;/footer&gt;</code> element.</strong></p>\n<pre><span class=\"p\">&lt;</span><span class=\"nt\">footer</span><span class=\"p\">&gt;</span>\n    <span class=\"p\">&lt;</span><span class=\"nt\">div</span> <span class=\"na\">id</span><span class=\"o\">=</span><span class=\"s\">'cart-qty'</span><span class=\"p\">&gt;</span>\n      <span class=\"c\">&lt;!-- cart qty here --&gt;</span>\n    <span class=\"p\">&lt;/</span><span class=\"nt\">div</span><span class=\"p\">&gt;</span>\n    <span class=\"p\">&lt;</span><span class=\"nt\">ul</span> <span class=\"na\">id</span><span class=\"o\">=</span><span class=\"s\">'item-list'</span><span class=\"p\">&gt;</span>\n      <span class=\"c\">&lt;!-- cart items --&gt;</span>\n    <span class=\"p\">&lt;/</span><span class=\"nt\">ul</span><span class=\"p\">&gt;</span>\n    <span class=\"p\">&lt;</span><span class=\"nt\">div</span> <span class=\"na\">id</span><span class=\"o\">=</span><span class=\"s\">'cart-total'</span><span class=\"p\">&gt;</span>\n      <span class=\"c\">&lt;!-- cart total --&gt;</span>\n    <span class=\"p\">&lt;/</span><span class=\"nt\">div</span><span class=\"p\">&gt;</span>\n  <span class=\"p\">&lt;/</span><span class=\"nt\">footer</span><span class=\"p\">&gt;</span>\n</pre>\n</div>"},{"id":"T0E6OlNlY3Rpb24tMTEzNDQ=","title":"9th Video","htmlContent":"<p>In this video you'll print the quantity and total of all items in the shopping cart.</p><p><iframe width=\"640\" height=\"360\" src=\"https://www.youtube.com/embed/g0oRBqqk-Kk\" frameborder=\"0\" allowfullscreen></iframe></p>"},{"id":"T0E6OlNlY3Rpb24tMTEzNDU=","title":"Update progress on Github","htmlContent":"<div class=\"action\">\n<p></p>\n\n<p>Now is a good time to update your progress on Github.</p>\n<pre>git add .\ngit commit -m <span class=\"s1\">'connect cart to footer'</span>\ngit push\n</pre>\n</div>"}]},"next":{"id":"T0E6OlBhZ2UtMjI0OA==","slug":"connect-add-to-cart-button-with-shopping-cart","title":"Connect Add to Cart button with Shopping Cart"},"previous":{"id":"T0E6OlBhZ2UtMjI0OA==","slug":"connect-add-to-cart-button-with-shopping-cart","title":"Connect Add to Cart button with Shopping Cart"}}}},"staticQueryHashes":[]}