<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Gerald Clark on Medium]]></title>
        <description><![CDATA[Stories by Gerald Clark on Medium]]></description>
        <link>https://medium.com/@geraldclarkaudio?source=rss-de99fe8e1b8b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8EcKwlyMnYeFpUf7eCvIRA.jpeg</url>
            <title>Stories by Gerald Clark on Medium</title>
            <link>https://medium.com/@geraldclarkaudio?source=rss-de99fe8e1b8b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 16:56:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@geraldclarkaudio/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[JavaScript: Bootstrap Basics]]></title>
            <link>https://geraldclarkaudio.medium.com/javascript-bootstrap-basics-f165e79a6679?source=rss-de99fe8e1b8b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f165e79a6679</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[pokemon]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Gerald Clark]]></dc:creator>
            <pubDate>Sun, 19 Jan 2025 21:01:13 GMT</pubDate>
            <atom:updated>2025-01-19T21:01:13.627Z</atom:updated>
            <content:encoded><![CDATA[<p>This one is going to be long. So buckle up. The idea here is to learn some basic interaction with libraries like Bootstrap while keeping the focus on JavaScript concepts.</p><p>I’ll be walking through the process of making a basic Pokemon quiz . It will be a simple web page that displays 4 questions. Answering the questions will be multiple choice. At the end of the quiz you will submit your answer and get a score. Lets go!</p><p><strong>What is Bootstrap?</strong></p><p>Bootstrap is a CSS and JavaScript library that makes creating nice looking websites easy. Instead of writing a ton of custom CSS, Bootstrap is here to save the day. I won’t really be digging much into the JavaScript side of it, but the concepts for ho to interact with it will be plainly talked about.</p><p><strong>How to link Bootstrap to your project:</strong></p><p>Theres a few ways. The easiest way is to go to <a href="http://www.getbootstrap.com/">www.getbootstrap.com</a> and navigate to this section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*jJHC-WNJGlmSDY4zXiYo8A.png" /></figure><p>Simply copy that and paste it into the &lt;head&gt; of your HTML document.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WGVWqYj3umNjOc1EetilCw.png" /></figure><p>This means we can now use the built-in CSS classes in Bootstrap.</p><p>So lets get right into coding now.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*T33WHBfTj6twogF-j35znA.png" /></figure><p>In the body of my HTML I’ve created a div. I’ve given it the class “intro” I’ve also used some bootstrap here. “py-3” is padding of strength 3 on the Y axis. “bg-white” tells it to make the background white. “text-center” centers the text within this div. Beneath that, I’ve created another div with the class of “container”. This is meant to just keep the text within it in a central column. Within that I’m displaying an h2 with a class of “text-primary”. This makes it a blue color. “display-3” means the text will be a display text and “my-4” gives the text and up and down margin strength of 4. The end result looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vq-pPYZfhpzbBa8scsfQ4Q.png" /></figure><p>Much like I did for the top section, I’ll sart off the quiz section with a div. Then open up another div within that to hold an h2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*Cdbp98ELKXMvOhQbqb-txw.png" /></figure><p>To help visualize what these divs are doing, I made the background color of this one blue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nvHSDDWVoQfj9LWz4l7YhQ.png" /></figure><p>SETTING UP THE HTML TEMPLATE:</p><p>Like I’ve said, I want to mostly focus on JavaScript, but understanding some HTML is obviously crucial for understanding how we communicate with browsers. So below is the HTML to display the question section.</p><p>This is question 1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Ws26mKHXUzO4EG0djWOOg.png" /></figure><p>After that, all I did was copy and paste everything within the &lt;div class=&quot;my-5&quot;&gt; .</p><p>Like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UCVpemxZt7Ke3W6J1aBdWw.png" /></figure><p>I’ll explain how question 1 is working now.</p><p>So first I’ve got the div with a class of “my-5”. This is bootstrap. Its just setting a y margin. Now everything within that div will have this applied. After that the p tag is using the “lead font-weight-normal” class to make the text appear a certain way. Next I made a div for each of the answers. The “text-white-75” is saying to make the text white with an opacity of 75 so they appear slightly lighter than the question text. Within that I have an input field of type “radio” so that it displays as a multiple-choice selection, I’m assigning it a name, in this case “q1” and a value of either A or B. I want A to alwasy be automatically checked, so thats why it says “checked” after the value. Next is the label where I put the text for that choice. The class of “form-check-label” is more Bootstrap styling.</p><p>After the questions I made a simple button to submit the answers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*w1mJCOrW2hYOAOtKfefgTg.png" /></figure><p>The end result there looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k8XBccBra05K_txHTNodMw.png" /></figure><p>Great. Now that our webpage is set up looking the way we want it, its time to get into interacting with it.</p><p>I’m going to be working in the app.js file now. The first order of business is to create an array to store the correct answers.</p><p>I’ll make a const called correctAnswers and set it equal to [] for now. The next step is to figure out what the correct answer is for each question. In my case my correct answers are A for question 1, B for 2, B for 3, and A for 4. So I’ll actually say const correctAnswers = [&#39;A&#39;,&#39;B&#39;,&#39;B&#39;, &#39;A&#39;]; If you’re following along, but didn’t use A, B, etc, you simply need to feed the value to the array for each question that correlates to the correct answer.</p><p>Now I want to be able to check the user’s answers. So when they click the submit button is when I’ll do that. To do this, I’ll need to get access to the form. Then I’ll need to add and event listener to the form and have it look for a submit event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*NUBbxOKtoQeGSFK8t6FQUg.png" /></figure><p>Now that the callback function has been established for the submit event, the first thing to do is to prevent the default action, which is to refresh the page. After that I want to create a variable for score and set it equal to 0. Then I’ll make another array to store the user’s answers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*ITk7xa244zeFaVbGSZQI2g.png" /></figure><p>I’ve set the elements of this array to be form.q1.value for example. What this is doing is getting the form, then getting a reference to the name of the input field and then the value the user has chosen (A or B).</p><p>After that I want to loop through the user’s answers and see if they match the correctAnswers values. If the values match I’m going to add 25 to the score. If there were more than 4 questions I could just do some simple percentage calculations to set the score properly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*9uQ1PLqBAi5WaowVDNj23w.png" /></figure><p>The callback function is taking 2 arguments. The answer and the index. So if the currently checked answer is the same as the correctAnswers[index] we have a correct answer. To further elaborate, if the user choses A for question 1, that value matches the first element of the correctAnswers array. When the values match the score gets 25 added to it.</p><p>In the code, I’m just logging the score to the console, but what I really want to do is display the score in the browser. So in the HTML I need to create a section for it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*9IY44h_Y5NXoY4TJMtCRuw.png" /></figure><p>Here, I’m using a little bit of Bootstrap. So I’ve created another div. I’ve given it a class of “result” in case I want to access this div later. “py-4” is Bootstrap. Its simply giving it some padding with a strength of 4. “d-none” is important. By default, I dont want this section to be visible. I only want it to be visible after the user clicks the submit button. “d-none” is basically saying it has a display type of none. “bg-light” and “text-center” are things I’ve already gone over.</p><p>So now I want to work on the JavaScript side of this. First I’ll need a handle to the result class.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*94gLj8pJ4HcVwMKC9dmPKQ.png" /></figure><p>Then, where I had my console.log earlier I want to set up the logic for displaying the score.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*UznTwrZV7cHQbSBcgqGchA.png" /></figure><p>Here I am using the querySelector method to gain access to the span tag inside that class. I’m grabbing the textContent property and setting it equal to a template string ${score}%. So that just means I’m feeding the string a variable and then appending it with the % symbol.</p><p>After that I’m getting access to the class list and simply removing the “d-none” class from the result. So now when I answer some questions and click submit, the score appears at the top of the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rN9DLqW2bvEwmc5QSLmXVQ.png" /></figure><p>If you’re following along, you may have noticed that when you click submit, the page doesn’t automatically scroll up to the top. I think it would make sense to have this happen. Some users may not think to do that. SO this requires that I talk about the Window Object!</p><h3><strong>THE WINDOW OBJECT:</strong></h3><p>The window object is the golabl object in front end JavaScript. The Mother of all objects so to speak. Pretty much everything we do in front-end JavaScript is stored on this window object.</p><p>To showcase this I’ll hop over into the dev tools using F12.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*lLrUvFjDtmu5F9OoYI3vaw.png" /></figure><p>I’ve typed “window” in the console and an enormous amount of stuff pops up. I wont cover all of it, but to check out a few things:</p><p>If I say window.outerWidth, it will show me the width of the window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/290/1*HxQAMWy1DFda-fiRC45jDQ.png" /></figure><p>The same goes for the outerHeight. Changing the size of the window will obviously change this value.</p><p>So far, everything I’ve done sort of hinges on the window object. console.log() for example could also be written as window.console.log() and work the exact same way. I don’t HAVE to type window because its inferred. So I want to use a method from the window object called scrollTo(). This method takes an x and a y coordinate. If I want to go right to the top of the page, I’ll just say scrollTo(0,0,);</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*7xkpGnTXA-C1k7XT5yNmdw.png" /></figure><p>Now when I select answers and click submit, it scrolls me to the top of the page. The next thing I want to cover is how to animate the numbers to look like they’re counting up to the final score. To do this, I’m going to use another method stored on the window object called SetInterval.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/695/1*0MT-IoGVYBLGV1TSQAyeQA.png" /></figure><p>So what I;ve done here is created a local variable called output. Then I created another variable called timer. timer is equal to the setInterval(). The callback function is where I’m handling the text content change now. I simply moved that line down. Now, instead of changing the text content to match the score, I have it match the output. output is being incremented every time this setInterval() gets called. the 10 at the end of the callback is basically saying that every 10 milliseconds the value of output will need to be checked. The if statement checking if output is equal to the score is where we break out of this setInterval method. Once the score and output value reaches the same number it will stop. Doing this allows me to see the numbers count up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CIx69-UzvwiGp9ohV9VKLA.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f165e79a6679" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript — Submit Events]]></title>
            <link>https://geraldclarkaudio.medium.com/javascript-submit-events-94ea8bea78db?source=rss-de99fe8e1b8b------2</link>
            <guid isPermaLink="false">https://medium.com/p/94ea8bea78db</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Gerald Clark]]></dc:creator>
            <pubDate>Thu, 08 Aug 2024 06:44:07 GMT</pubDate>
            <atom:updated>2024-08-08T06:44:07.712Z</atom:updated>
            <content:encoded><![CDATA[<h3>JavaScript — Submit Events</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H3bILxJQ3rFw7q7LezXifQ.png" /></figure><p>I’ve created some basic HTML to give me an input field and a submit button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*BvC_Md3R-3jm5X9QhA2lsg.png" /></figure><p>The &lt;input type=&quot;submit value=&quot;submit&gt; line here gives me a button that, when clicked, will fire off a submit event.</p><p>In previous articles I’ve covered setting up event listeners. What I’ve been doing is getting a reference to the object I click and adding a listener to it that looks for a click event. In this scenario, I don’t want to do that. I don’t want to add an event listener to the submit button itself. Instead I want to attach it to the form. That way, when I click the submit button, the form is looking for that event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*IhohhTcXXT_q7mlPbcFj7Q.png" /></figure><p>Here I’ve gained a reference to the .signup-form class and added a listener that takes the event data as a parameter. The default behavior for a submit event is to refresh the page. I don’t want the page to refresh.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*mYMWqZxwYaaBrhnliYSkeQ.gif" /></figure><p>You can see a super quick flicker there. lol</p><p>To stop the page from refreshing I can use this method:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*T22INeEYHHodnjFUaKs_Eg.png" /></figure><p>Now if I submit, the page doesn’t refresh.</p><p>SO now what?</p><p>Lets figure out how to get the data from the form field. In order to do this I need a reference to the username field. Theres a few ways to go about it. Heres one way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*ofwtiH4mSBeFM1JOGjH3Lg.png" /></figure><p>This (&#39;#username) thing is new. I’m getting this string from the id I gave the username field in the HTML.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/745/1*jRO7u8CqEoo_iV5LTo1nuQ.png" /></figure><p>Now, I want to get the data from the input field, so I’ll need to check the input field’s value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*yhMCctPq_Q0xoRP5uMUKug.png" /></figure><p>To do that I can simply check the value property. So when I fill in the username field and submit, I’ll get the value of the input field. Like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yvRIfRYN3X-oapWOAsKziw.gif" /></figure><p>There is an easier way to get a reference to the username though. Since the username is an input that is nested within the form, it can be accessed through dot notation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*RmCVAJNb7mezZCit-KyFXg.png" /></figure><p>This way I don’t need to store a reference to the username in a const.</p><p>The next logical step is to check whether the value of the username field is valid or not. In the next article I’ll cover how to do that! See ya there!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94ea8bea78db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript — Building A Pop Up]]></title>
            <link>https://geraldclarkaudio.medium.com/javascript-building-a-pop-up-bae68ea0055b?source=rss-de99fe8e1b8b------2</link>
            <guid isPermaLink="false">https://medium.com/p/bae68ea0055b</guid>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Gerald Clark]]></dc:creator>
            <pubDate>Fri, 02 Aug 2024 03:59:10 GMT</pubDate>
            <atom:updated>2024-08-02T03:59:10.755Z</atom:updated>
            <content:encoded><![CDATA[<h3>JavaScript — Building A Pop Up</h3><p>This article will cover my process for building a simple pop up in a web browser. This article will cover some basic HTML and CSS in a little more depth than I have been. My intentiojn is to mostly cover JavaScript, but sometimes things entertwine a little more than I can ignore. SO! Here we go!!</p><p>First, here is a little snapshot of the final product:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tABAIBCeszBPDBBsUd3acg.gif" /></figure><p>The HTML:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LLjrRHXhbL2pyCmQY23k7w.png" /></figure><p>In the body, I have a button that says “Click Me”. I have a few divs. I have all these set up this way so I can assign each of them a class. The reason for the classes is so that my CSS document can style the pop up when I click the button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*DzSVZtMlcMuiM5g_U1s_NQ.png" /></figure><p>The style sheet is also being referenced in the top of the HTML doc. As you can see, each class has CSS properties. This is why the pop up is centered, and the close button is in the top right and so on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*Qzjq5Aux7Lb9AL_Gk9zPyA.png" /></figure><p>Heres the JavaScript. The button const references the button. I have an event listener looking for a click event. When the button gets clicked, I change the style of the popup const to ‘block’. This is basically changing the CSS display property of the popup-wrapper. This makes the element visible on the screen as a block level element. That way it’ll take up the full width available and start on a new line.</p><p>As you can see in the CSS, the display property of the popup-wrapper class is set to none by default. Thats why it isn’t visible from the start.</p><p>The close const is getting the close button. When its clicked, we set the display property to none again. I also have the popup itself look for a click event to turn off the pop up as well.</p><p>Thats all there is too it!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bae68ea0055b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript — More Fun With DOM Events]]></title>
            <link>https://geraldclarkaudio.medium.com/javascript-more-fun-with-dom-events-24db1c43bd5c?source=rss-de99fe8e1b8b------2</link>
            <guid isPermaLink="false">https://medium.com/p/24db1c43bd5c</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Gerald Clark]]></dc:creator>
            <pubDate>Sun, 21 Jul 2024 19:55:35 GMT</pubDate>
            <atom:updated>2024-07-21T19:55:35.450Z</atom:updated>
            <content:encoded><![CDATA[<h3>JavaScript — More Fun With DOM Events</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H3bILxJQ3rFw7q7LezXifQ.png" /></figure><p>In the last article I covered a few events and in this one I want to cover a few more and talk about some useful ways to interact with the browser. Lets go!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*CPu0OlFHNezNce77URGtXQ.png" /></figure><p>Here is a super basic HTML document. In the body I have a p tag with a class called “copy-me”, a div with a class of “box, and several other p tags. Up in the head I have a basic style set up for anything with the box class. This style creates a box on the web page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*QkxniptIsMgWunNaAXsyWA.png" /></figure><p>So the reason I called the first p tag’s class “copy-me” is because I want to cover the copy event first. This happens when we highlight something on the web page, right click and then select “copy”.</p><p>First I have to gain access to that element via the document.querySelector() and then simply add a listener that is looking for the ‘copy’ event.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*QKaZRtgvtizgM9XLKD8Zkw.png" /></figure><p>So doing this, should print out the console.log message I put in the callback function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*5XRXVhHiwjRy8AVO7LLSaQ.gif" /></figure><p>Next I’ll cover the ‘mouse move’ event. I’m gonna move my mouse around in this box I made. Every time the mouse moves it will print out the X and Y coordinates of the mouse within that box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*srvXhF3mO-1HbyMmJ2hFnw.png" /></figure><p>Here I’ve gained access to the element with the box class. Set up the event listener to use the event data (e) and I’m just logging that to the console. So when the mouse moves inside the box, a message should print in the console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*2y9KtyW86Itsqet8Hg6GgQ.gif" /></figure><p>You can see that its basically constantly printing new messages. So now I want some of the information inside that event object. So if I go down to the offsetY and offsetX you’ll see some values. Those values represent the mouse’s position WITHIN THE BOX. The offsetX is the mouse’s position from the left side of the box and the offsetY is the mouse’s position from the top of the box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*1OJZCspAVVE0INk6PFeDgA.png" /></figure><p>So now I want to output those values inside the box. This is why I wanted the event data in the callback function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*mTgaddHi-JHEaU6ZXlYg8w.png" /></figure><p>SO now I can log e.offsetY and X.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*zhAXrEIvMuPx-gqk9eQ-eQ.gif" /></figure><p>You’ll see here that as my mouse gets closer to the top left corner the values decrease and as I approach the bottom right they increase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*YvaU86d2h9hoW7BVenxbPw.png" /></figure><p>This bit of code allows me to output the values within the box. I’m accessing the textContent property. This is actually</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*YPWS2KYQF6jTEJpVBvv4xQ.png" /></figure><p>at first, but I’m overriding it once the mouse moves within the box. Like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*01Hupr5dFGNfvJ253JCasQ.gif" /></figure><p>So now if you ever need to track where the user’s cursor is on the webpage, this is how you can do that.</p><p>The next event is going to be the scroll wheel event. I have added a lot more p tags to the document so I can get a scroll bar on the side.</p><p>To do this I won’t be accessing a specific element on the web page, but instead I’ll be accessing the document itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/507/1*WVAbm-RlVGO1D5DhK2u9wQ.png" /></figure><p>I’ve done the same thing I’ve done for the elements here. Im logging the event data to the console every time a ‘wheel’ event happens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*U56s86inxnRs4Ns0o1BGHQ.gif" /></figure><p>Inside these WheelEvent objects you’ve got some properties you can use. For this demonstration I’ll be using the pageX and pageY. This acts just like the offsetX and offsetY of the box we used earlier. The only difference is that the values are relative to the entire page.</p><p>So I can log out the position of the mouse relative to the entire page using the scroll event like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*rKfe70A9kNuoPj-xVcpk8w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*3ENXgXuMb0kVIJDxSI7bNA.gif" /></figure><p>As you can see here, as the page scrolls, my Y value will change even if it is the same spot on the screen. This is because it has technically moved down on the page. Here is a link to a huge list of events we can use for future reference. <a href="https://developer.mozilla.org/en-US/docs/Web/Events#Mouse_events">https://developer.mozilla.org/en-US/docs/Web/Events#Mouse_events</a></p><p>The next article will cover how I will go about creating a pop up on a web page. See ya there!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24db1c43bd5c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript — Event Bubbling and Delegation]]></title>
            <link>https://geraldclarkaudio.medium.com/javascript-event-bubbling-and-delegation-93cd177176df?source=rss-de99fe8e1b8b------2</link>
            <guid isPermaLink="false">https://medium.com/p/93cd177176df</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Gerald Clark]]></dc:creator>
            <pubDate>Sun, 14 Jul 2024 03:34:39 GMT</pubDate>
            <atom:updated>2024-07-14T03:34:39.547Z</atom:updated>
            <content:encoded><![CDATA[<h3>JavaScript — Event Bubbling and Delegation</h3><p>This article is one the more important ones. This is something that you could easily turn a blind eye to when learning JavaScript, but it WILL come back to bite you later. So lets get it learned!</p><p>When an event occurs… that element becomes the event target. When that happens, JavaScript will basically check to see if there are any event listeners attached to that element.. if there are, the callback function gets fired off.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*LHPf4BukMLZ-cH4wCz640w.png" /></figure><p>In this example, each li element gets an event listener added that is looking for click events when the page loads. This isnt the end of the stroy though..</p><p>After the callback function fires off, the event “bubbles up” to the parent element. In this case, the ul. If the ul has an event listener added, this event will be fired off too.. This isn’t what you always want. So to see this in action..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*ogCEaozRMCG0NH29qWdEfg.png" /></figure><p>Here I have added an event listener to each of the li tags and an event listener to the ul. When I run this and click one of the li elements, the ul log will print out as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*ZClud96MDVoYXTHDhu2-tA.gif" /></figure><p>So if we don’t want this to happen we can stop it from happening using the stopPropogation(). Like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*-9kY3nqxMdTRvXM80WFgyg.png" /></figure><p>Now the ul&#39;s event wont fire off.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*61nrXuF19XGPBmcOadRWAQ.gif" /></figure><p>So this is event bubbling. Its something to be aware of when you sdtart getting trigger happy with your event listeners. Another thing pretty closely related to event bubbling is event delegation:</p><p>If there were multiple lis I wanted to be able to click, it would get pretty cumbersome to assign event listeners to each set of them. Its not great practice and it could effect the performance of our program, SO</p><p>I’ve removed the event listeners from the li tags. I’ve only got a single event listener on the ul.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*TWCjzJT5lBhtQ19k09n5oQ.png" /></figure><p>When I click a li, the e.target should print out which one I clicked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*hwyH-aeNdWsMAcTBzFUUSg.gif" /></figure><p>In the last article I mentioned that we needed to figure out a way to add event listners to each of the NEW li tags that appear when we click the button:</p><p>Code in case you don’t have it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*cisJWfbKkML0Y448PJzg8Q.png" /></figure><p>The problem we faced before was that each element with an li tag was assigned an event listener when the page loads. The new ones wouldn’t get event listeners though. Adding the event listener to the ul solves this because the eventListener isn’t actually ON the li element. So the e.target is printed regardless.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*IXumXnLNxAjE_foQT3K2nA.gif" /></figure><p>So if I want to remove the li tag I just clicked I can use the e.target.tagName property.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*I3CnWcLnIeNWsICtn6bSrQ.png" /></figure><p>Now, if I click a li element it will be removed. When I click the button a new one is added to the list. This newly added li is also clickable and will be removed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*cIqxJwvX-mdQjqU4ZmarrA.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93cd177176df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript — Creating and Removing HTML Elements]]></title>
            <link>https://geraldclarkaudio.medium.com/javascript-creating-and-removing-html-elements-44e1c150d210?source=rss-de99fe8e1b8b------2</link>
            <guid isPermaLink="false">https://medium.com/p/44e1c150d210</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Gerald Clark]]></dc:creator>
            <pubDate>Thu, 11 Jul 2024 03:51:24 GMT</pubDate>
            <atom:updated>2024-07-11T03:51:24.309Z</atom:updated>
            <content:encoded><![CDATA[<h3>JavaScript — Creating and Removing HTML Elements</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H3bILxJQ3rFw7q7LezXifQ.png" /></figure><p>In the previous article I covered how to add event listeners to differnt elements in a web page. When we would select one of the tasks on the to-do list, it would just strike it out with a line. I want to cover how to actually remove and add elements through JavaScript in this one. Lets go!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/533/1*HjlAkiLDFe4KXLQHpOSRUg.png" /></figure><p>Here I have this &lt;ul&gt;. I’m going to simply gain a reference to it, then use the remove() to remove it. Like so,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/1*xVPmXGNdx_VBHUMGVBucnQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*ia4aAkF4zLNHKWSIRex8Jg.png" /></figure><p>Now that list of things is gone!</p><p>In the last article I set up a forEach loop that cycles through the list of li tags. I can use this logic to remove a specific list element like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*ayD86Jel-mecK1-2c_cJvA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*w_c8Mnci_lXwuh_fS2eT3g.gif" /></figure><p>Easy peezy. Now lets add some stuff.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*H6MFkPJ6wk_VaVsCja9pgA.png" /></figure><p>In my HTML document, I’ve changed the text on my button to say “Add new To Do!”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*CNyFkT7LiaSnZFlzX0BJsA.png" /></figure><p>Here I’ve gotten a reference to my button, then added a click event listener on it and in the call back function, I’ve said to append the innerHTML of the ul. I’m just appending a new list element every time I click the button. Each list element will say “Something new.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*n-XF_EOwgTCotjVXgp5Iyg.gif" /></figure><p>So thats all good, but.. theres another way!</p><p>the document has a method called createElement(). This allows you to create an element and then assign new text to it like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*rlOrZ9FS6nBaOz3gVsFE1g.png" /></figure><p>Here I’m creating a const called li and setting it equal to the createElement method. Then I access the textContent property of that element and set it to “Something new to do.” After that, I’m accessing the parent object (the ul) and using the append method. Now when I click the button, I get new li elements, just like before. <strong><em>The append method puts the newly created/appended element at the bottom of the parent.</em></strong></p><p>We can also use the prepend method. This will add that element to the TOP of the parent. Like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Lpkgcgo1OXs_lmrpXAf_KQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*XHsG9Siy3ABNDmtOBs8Vyg.gif" /></figure><p>So if you’ve been following along, you may have tried clicking on your newly added li tags and nothing is happening. This is because we assigned the eventListeners on the original tags at the start. When the new ones are created, they arent being given event listeners. SO in the next article, I’ll be covering how to combat this using event delegation! See ya there!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44e1c150d210" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript — Click Events]]></title>
            <link>https://geraldclarkaudio.medium.com/javascript-click-events-da5a48b8b7a9?source=rss-de99fe8e1b8b------2</link>
            <guid isPermaLink="false">https://medium.com/p/da5a48b8b7a9</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[javascript-development]]></category>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Gerald Clark]]></dc:creator>
            <pubDate>Mon, 08 Jul 2024 04:30:14 GMT</pubDate>
            <atom:updated>2024-07-08T04:30:14.111Z</atom:updated>
            <content:encoded><![CDATA[<h3>JavaScript — Click Events</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H3bILxJQ3rFw7q7LezXifQ.png" /></figure><p>Super important article ahead! <br>In this one, I’m finally going to get around to interacting with the web page! FINALLY. We’re only like… 50 articles in :)</p><p>So… here is my new html document.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*tk-LDXonQVolQpL6DeNdZg.png" /></figure><p>I have a list of things to do and a button. First I’ll go over how to interact with a button.</p><p>When I run this in Live Server the page looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*lCeZFexSA3ZWNfIL8SMYTQ.png" /></figure><p>When I click the button, I want to print something to the console. To do this, you guessed it, we have to use querySelector() to gain access to the button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/1*wkEKie-43qsAmEjmdJg0dw.png" /></figure><p>Next I have to add an event listener to the button. There is a HUGE list of events you can listen for, but in this situation I want to listen for the “click” event.</p><p>The addEventListener method looks for 2 parameters.</p><ol><li>Which event to listen for</li><li>a callback function.</li></ol><p>Here I am feeding it the ‘click’ event and the call back function is just an in-line log that says “you clicked the button.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*4r9F1tIK0GIN0uw_ojxcBQ.png" /></figure><p>So now, when I click the button, it prints that message in the console. Easy peezy.</p><p>Now I want to knock out this to do list.</p><p>When I click the item in the list I want to just put a line through it for now to signify I have completed that task.</p><p>Doing this would be easy to do with a forEach loop! SO I’m going to use the querySelectorAll() to get access to all the li tags.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*wUwtogSev8hBtZdb8HAnVA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*Ws4ZHYwgxasW7McMpMX69A.png" /></figure><p>Here I am iterating through each item in the listItem. for each one, I’m going to add an event listener that is looking for the click event. For the callback function I want to use a parameter. I’ll just call it e. I’m using the e.target.style.textDecoration property and then setting it equal to ‘line-through’.</p><p>The end result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*io_6XEAiXiuHjlii9u9XCQ.gif" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da5a48b8b7a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unity Physics — Physics Materials]]></title>
            <link>https://geraldclarkaudio.medium.com/unity-physics-physics-materials-fe4710893315?source=rss-de99fe8e1b8b------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe4710893315</guid>
            <category><![CDATA[made-with-unity]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[gamedev]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[unity3d]]></category>
            <dc:creator><![CDATA[Gerald Clark]]></dc:creator>
            <pubDate>Sat, 06 Jul 2024 04:17:26 GMT</pubDate>
            <atom:updated>2024-07-06T04:17:26.123Z</atom:updated>
            <content:encoded><![CDATA[<h3>Unity Physics — Physics Materials</h3><p>Physics materials are an asset we can apply to a collider and give it physical properties. For example, we can add a physics material to a collider that will make it have the same physical properties as ice. By adjusting the friction value we can simulate what it would be like to glide along the surface.</p><p>To create a physics material, simply right click in your project view and select Physics Material.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*WlUjPJO8w7pRXclAdNL37g.png" /></figure><p>Here I have a default physics material. I called it “Smooth.” Lets go over these properties real fast.</p><p><strong>Dynamic Friction</strong> = The friction used when already moving. Usually a value from 0 to 1. A value of zero feels like ice, a value of 1 will make it come to rest very quickly unless a lot of force or gravity pushes the object.</p><p><strong>Static Friction</strong> = The friction used when an object is laying still on a surface. Usually a value from 0 to 1. A value of zero feels like ice, a value of 1 will make it very hard to get the object moving.</p><p><strong>Bounciness</strong> = How bouncy the surface is.</p><p><strong>Friction Combine</strong> = How the friction of two colliding objects is combined.</p><p>There are a few different options here:</p><ul><li><em>Average</em> = The two friction values are averaged.</li><li><em>Minimum</em> = The smallest of the two values is used.</li><li><em>Maximum</em> = The largest of the two values is used.</li><li><em>Multiply </em>= The friction values are multiplied with each other.</li></ul><p><strong>Bounciness Combine</strong> = How the bounciness of two colliding objects is combined. It has the same modes as Friction Combine Mode.</p><p>Took all this from the Unity Manual! <a href="https://docs.unity3d.com/2021.2/Documentation/Manual/class-PhysicMaterial.html">Unity — Manual: Physic Material (unity3d.com)</a></p><p>So heres an example:</p><p>When I have this cube drop, look what happens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E5jH7jYYIokJlHUHUYiHAw.gif" /></figure><p>If I want it to slide down the ramp, I’ll need to add a physics material to both and adjust the values to simulate the kind of physics I want to happen. Since these are both metallic objects, I won’t make it slide down as if it were sliding on ice. Instead, I’ll give it a little bit of friction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FhOuPbDmC2aQ-dFKMdylNw.gif" /></figure><p>I created a physics material for the ramp. It’s values are as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*ESyqnOm5BXFyyeYxGxAiZg.png" /></figure><p>I also created a physics material for the container that falls:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*GslVqQUajKHpsfd-Pv0cmg.png" /></figure><p>This set up allows us to really tweak and adjust the values, not only on the physics material, but the rigidbody as well! You can get pretty in-depth with this stuff and make some really convincing phyics simulations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe4710893315" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unity Physics — Triggers]]></title>
            <link>https://geraldclarkaudio.medium.com/unity-physics-triggers-930cc455ca6a?source=rss-de99fe8e1b8b------2</link>
            <guid isPermaLink="false">https://medium.com/p/930cc455ca6a</guid>
            <category><![CDATA[made-with-unity]]></category>
            <category><![CDATA[gamedevhq]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Gerald Clark]]></dc:creator>
            <pubDate>Fri, 05 Jul 2024 22:20:49 GMT</pubDate>
            <atom:updated>2024-07-05T22:20:49.983Z</atom:updated>
            <content:encoded><![CDATA[<h3>Unity Physics — Triggers</h3><p>I’ve covered triggers in my past articles but this is a little deeper dive. Just for clarity&lt; I have a trigger collider set up with a Trigger.cs script attached to it.</p><p>So OnTriggerEnter fires when a collider with a rigidbody comes into contact with a tigger collider. We’ve all seen this before:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*M0dR1uLhFjZIvfVOgjEogA.png" /></figure><p>Here I’m getting the Renderer of whatever object passes through the trigger collider and then changing the color of the material to blue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VMADSb_cQIWlpWdORJ15rg.gif" /></figure><p>This scenario shows a red barrel turn blue when it collides with the trigger object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SBBDjDPwnLpuLCEHkStdbw.png" /></figure><p>Now I’m going to get a little deeper into some of the Material class properties. Instead of accessing the material.color, I’m actually using the SetColor method of the Material class to access the “_EmissionColor” and then set it to green and then I’m multiplying that value by 10 to exaggerate the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tceAYTzVT2a6dYD38QuswA.gif" /></figure><p>So you can do a lot of stuff with trigger collision in Unity.</p><p>The OnTriggerExit method does the exact opposite thing the OnTriggerEnter method does. When something leaves thee trigger collider, the OnExit method is called.</p><p>The On TriggerStay method is something that is used generally when an object has entered and hasnt left yet. This is called once every physics update. (FixedUpdate).</p><p>So it isnt the most reliable thing to use if you need something to be checked every frame. For things that need to be a little more accurate, I like to use a bool and set it when you enter and then set it to the other value when you leave. For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/604/1*uF-lMXbi3vnGZbq5OvJ8cg.png" /></figure><p>Now whatever the hasABarrelInIt variable drives can be a little more precise with WHEN things enter and exit the collider.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=930cc455ca6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript — Parents, Children and Siblings]]></title>
            <link>https://geraldclarkaudio.medium.com/javascript-parents-children-and-siblings-78357ddce5bd?source=rss-de99fe8e1b8b------2</link>
            <guid isPermaLink="false">https://medium.com/p/78357ddce5bd</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript-development]]></category>
            <dc:creator><![CDATA[Gerald Clark]]></dc:creator>
            <pubDate>Fri, 05 Jul 2024 21:43:22 GMT</pubDate>
            <atom:updated>2024-07-05T21:43:22.577Z</atom:updated>
            <content:encoded><![CDATA[<h3>JavaScript — Parents, Children and Siblings</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H3bILxJQ3rFw7q7LezXifQ.png" /></figure><p>In the past several articles I’ve covered how to manipulate html elements, how to query the DOM, and much more. I’d love to cover another fundamental topic before I move on into some more complicated stuff. Lets go!</p><p>Lets talk about node relations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*kMEhXPrORbGfeBRU.jpeg" /></figure><p>Here you can see a simple node tree. A simple representation of the DOM.</p><p>Take a look at the h1, and 2 div nodes on the right side. You can see they all have the same direct parent. These nodes are sibling nodes. The p tags coming off the div node would also be siblings, while the div node would be their parent.</p><p>So these are 2 different kinds of node relations. I’m going to go over some examples of how we can traverse the DOM using these node relationships to gain access to a wider variety of elements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*_vrrZoSXiHwEYo-6RWxzSg.png" /></figure><p>Heres a simple html page. I have an article tag that has a bunch of p tags and a div inside it. Lets gain access to all the elements within this article and then assign a class to each element through JavaScript.</p><p>We already know how to do this the long way. We could make 3 separate queries to the DOM. One for the h2, one for the p tags and one for the div, but thats just writing WAY more code than we really need to in this situation. This is also limiting us when it comes down to dynamically changing elements. What if we don’t actually KNOW what the elements are that we want to retrieve?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*CtZLekEycAPqbcuALWszrA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*cXxCaVF4rHzjNYA03UXq4g.png" /></figure><p>Using the .children property gives us an HTML collection that lists all the elements inside the article.</p><p>Like I’ve said in previous articles, you can’t use forEach on an HTMLCollection. So how do we cycle through these elements?</p><p>I could convert the elements to an array by doing this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*X4kbQPV_Y-Xpd9AvvVs0Qw.png" /></figure><p>Using the Array.from() will turn this into an array for us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/1*5cRXSfPQOk2SQmifXhaliw.png" /></figure><p>Cool. This is no long an HTMLCollection so we can use forEach.</p><p><em>SIDE NOTE: using the Array.from() does not actually change the original value of the article.children. Its NON destructive. SO if I were to log the articleParent.children after this line, it would still return an HTMLCollection.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*0U5_SCxEwnVENvVSKiy76Q.png" /></figure><p>here I’m cycling through the array and assigning an ‘article-elemtn’ class to each child.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/1*ZDWgRh8gbg_iuKkvk__dzQ.png" /></figure><p>So this is a good use of the relationship between the article node and the nodes within it (children).</p><p>Now just to show you the other way around:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*dU-Sg691t6U256UtRrjGkQ.png" /></figure><p>I want to find the parent of the h2, so I use the .parentElement property.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*PMIXMkA9N0Y6APKUxK0P9Q.png" /></figure><p>This will log out the article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*GBgItjFoneYbwq-PzTFo8A.png" /></figure><p>What do you think will be output in the console with THIS line?</p><p>If you guessed the body, you are correct!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/1*WXkFNeMcIo2kDGwffXdKjQ.png" /></figure><p>Now the sibling relationship:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*nDH9jjAPqlBr2_HKzlcAoA.png" /></figure><p>This line gets the eleement next to the one you’ve queried. In this case, the h2. So I should get a p tag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*XlF6Soi56g0jhorMIl7X0w.png" /></figure><p>hayoooooo</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*mRGl_U-CPcuVOQmsSPD9hQ.png" /></figure><p>This gets the sibling in the opposite direction. Since my h2 doesn’t have a previous sibling, it returns null, BUT if it did, it would return it.</p><p>So this is a pretty versitile way to traverse the DOM. With one query to the DOM, I’m able to access everything within that aricle tag.</p><p>In the next article, I’m going to cover some event basics. We’re gonna actually be interacting with a web page we develop! See ya there!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78357ddce5bd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>