<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Hroney</title>
    <description>The latest articles on Forem by Hroney (@hroney).</description>
    <link>https://forem.com/hroney</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1165359%2Fa53877e2-8360-4254-bb11-a1533f42197a.jpeg</url>
      <title>Forem: Hroney</title>
      <link>https://forem.com/hroney</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/hroney"/>
    <language>en</language>
    <item>
      <title>No Script Needed: CSSing is Believing</title>
      <dc:creator>Hroney</dc:creator>
      <pubDate>Thu, 08 Aug 2024 19:13:24 +0000</pubDate>
      <link>https://forem.com/hroney/no-script-needed-cssing-is-believing-20h0</link>
      <guid>https://forem.com/hroney/no-script-needed-cssing-is-believing-20h0</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;CSS, or Cascading Style Sheets, is the unsung hero of web development. It’s the tool that transforms plain, unstyled HTML into the visually appealing and user-friendly interfaces we interact with daily. While HTML structures content and JavaScript brings it to life, CSS breathes beauty into the mix. Over time, CSS has evolved from a simple styling language to one capable of handling more complex tasks, some of which previously required JavaScript. This blog will explore the basics of CSS and then delve into some clever tricks that allow you to create interactive UI elements with CSS alone, minimizing your reliance on JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Basics of CSS
&lt;/h2&gt;

&lt;p&gt;Before diving into advanced tricks, let’s revisit the core of CSS. Understanding these basics is crucial as they serve as the foundation for more complex techniques.&lt;/p&gt;

&lt;h3&gt;
  
  
  Selectors and Properties
&lt;/h3&gt;

&lt;p&gt;CSS selectors are the means by which you target HTML elements to apply styles. Whether you’re styling a specific element, a class of elements, or using advanced selectors to target elements based on their attributes, knowing how to effectively select elements is key.&lt;/p&gt;

&lt;p&gt;For example, the difference between a class selector (&lt;code&gt;.class-name&lt;/code&gt;) and an ID selector (&lt;code&gt;#id-name&lt;/code&gt;) is important, as is understanding combinators like the child (&lt;code&gt;&amp;gt;&lt;/code&gt;), adjacent sibling (&lt;code&gt;+&lt;/code&gt;), and general sibling (&lt;code&gt;~&lt;/code&gt;) selectors.&lt;/p&gt;

&lt;p&gt;Properties, on the other hand, define what styles you want to apply to those elements. Properties like &lt;code&gt;color&lt;/code&gt;, &lt;code&gt;font-size&lt;/code&gt;, &lt;code&gt;background-color&lt;/code&gt;, and &lt;code&gt;border&lt;/code&gt; are some of the most commonly used, but there are hundreds of properties available, each with their own quirks and nuances.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Box Model
&lt;/h3&gt;

&lt;p&gt;The box model is a critical concept in CSS. Every HTML element is essentially a rectangular box, and understanding the box model helps you control the space around these boxes.&lt;/p&gt;

&lt;p&gt;The box model consists of the following parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Content&lt;/strong&gt;: The actual content of the box, like text or images.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Padding&lt;/strong&gt;: The space between the content and the border.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Border&lt;/strong&gt;: The edge surrounding the padding (and content).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Margin&lt;/strong&gt;: The space outside the border, separating the element from its neighbors.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Understanding how to manipulate these properties allows you to fine-tune your layouts, ensuring elements are spaced and aligned exactly how you want them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Positioning
&lt;/h3&gt;

&lt;p&gt;Positioning is how elements are placed in relation to their surrounding elements or the viewport. CSS provides several ways to position elements:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Static&lt;/strong&gt;: The default positioning, where elements follow the normal flow of the document.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Relative&lt;/strong&gt;: Elements are positioned relative to their normal position.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Absolute&lt;/strong&gt;: Elements are positioned relative to their nearest positioned ancestor.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fixed&lt;/strong&gt;: Elements are positioned relative to the viewport, staying in place even when the page is scrolled.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sticky&lt;/strong&gt;: A hybrid that toggles between relative and fixed, based on the user’s scroll position.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These positioning techniques are foundational for more advanced layouts, like creating sticky headers, footers, or complex page designs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Flexbox and Grid
&lt;/h3&gt;

&lt;p&gt;Flexbox and Grid are two layout modules that have revolutionized responsive design. Before their introduction, developers relied heavily on floats and inline-blocks, which were often tricky to manage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Flexbox&lt;/strong&gt; is a one-dimensional layout method for laying out items in rows or columns. It simplifies the process of aligning items within a container, evenly distributing space, and handling dynamic sizes.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;space-between&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Grid&lt;/strong&gt; is a two-dimensional layout system, providing a grid-based layout with rows and columns. Grid is more powerful when it comes to creating complex layouts, allowing for both horizontal and vertical alignment in a single container.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;repeat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="py"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both Flexbox and Grid are essential tools for creating responsive designs that adapt seamlessly to different screen sizes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Going Beyond the Basics with CSS
&lt;/h2&gt;

&lt;p&gt;Now that we’ve covered the basics, let’s explore some more advanced features of CSS. These tools allow you to add interactivity and animations to your websites without relying on JavaScript.&lt;/p&gt;

&lt;h3&gt;
  
  
  Transitions and Animations
&lt;/h3&gt;

&lt;p&gt;CSS transitions and animations bring your designs to life with smooth, dynamic effects. While JavaScript can also create animations, CSS does so with less overhead and often with simpler code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Transitions&lt;/strong&gt; allow you to change property values smoothly (over a given duration). For example, you can create a hover effect that gradually changes the background color of a button:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#3498db&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;background-color&lt;/span&gt; &lt;span class="m"&gt;0.3s&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#2ecc71&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Animations&lt;/strong&gt; take things a step further, allowing you to define keyframes that specify the start and end states of the animation, as well as any intermediate points:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@keyframes&lt;/span&gt; &lt;span class="n"&gt;slidein&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nt"&gt;from&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-100%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nt"&gt;to&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.element&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;animation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;slidein&lt;/span&gt; &lt;span class="m"&gt;1s&lt;/span&gt; &lt;span class="n"&gt;ease-in-out&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With animations, you can create complex sequences that run automatically, or trigger based on user interaction.&lt;/p&gt;

&lt;h3&gt;
  
  
  Hover Effects
&lt;/h3&gt;

&lt;p&gt;Hover effects are a common way to indicate interactivity on web elements like buttons, links, or images. With CSS, you can create impressive effects without a single line of JavaScript.&lt;/p&gt;

&lt;p&gt;For example, a simple zoom-in effect on an image:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.image-container&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;transform&lt;/span&gt; &lt;span class="m"&gt;0.3s&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.image-container&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;1.1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Such effects improve user experience by making the interface feel more responsive and polished.&lt;/p&gt;

&lt;h3&gt;
  
  
  Responsive Design
&lt;/h3&gt;

&lt;p&gt;Responsive design ensures that your website looks good on all devices, from desktops to smartphones. Media queries are the key tool in this regard, allowing you to apply styles based on the device’s screen size.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;600px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By combining Flexbox, Grid, and media queries, you can create layouts that adapt seamlessly to different screen sizes, improving accessibility and user experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Replacing JavaScript with Clever CSS
&lt;/h2&gt;

&lt;p&gt;Now for the fun part: using CSS to do things that most people think require JavaScript. With some creativity, CSS can handle many interactive elements on its own.&lt;/p&gt;

&lt;h3&gt;
  
  
  Checkbox Hack
&lt;/h3&gt;

&lt;p&gt;The checkbox hack is a popular technique where a hidden checkbox input is used to toggle UI elements. By pairing the &lt;code&gt;:checked&lt;/code&gt; pseudo-class with labels and other elements, you can create toggles, dropdowns, and even simple modal windows.&lt;/p&gt;

&lt;p&gt;Example of a simple toggle:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"toggle"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"toggle"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Toggle Content&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"content"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;This content is toggled on and off with CSS only!&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;#toggle&lt;/span&gt;&lt;span class="nd"&gt;:checked&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;.content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This technique allows you to create interactive elements without writing any JavaScript, simplifying your codebase and improving performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  CSS Tooltips
&lt;/h3&gt;

&lt;p&gt;Tooltips are commonly implemented with JavaScript, but CSS can handle them elegantly using the &lt;code&gt;:hover&lt;/code&gt; pseudo-class and the &lt;code&gt;::after&lt;/code&gt; pseudo-element.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.tooltip&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;inline-block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.tooltip&lt;/span&gt;&lt;span class="nd"&gt;:hover::after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'Tooltip text'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#333&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#fff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;125%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-50%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nl"&gt;white-space&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;nowrap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This method creates a simple, effective tooltip that requires no extra HTML elements or JavaScript.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dropdown Menus
&lt;/h3&gt;

&lt;p&gt;Dropdown menus are another feature often implemented with JavaScript, but CSS can handle them using the &lt;code&gt;:hover&lt;/code&gt; pseudo-class and careful positioning.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.menu&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;inline-block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.menu-content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#f9f9f9&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;160px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;box-shadow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0px&lt;/span&gt; &lt;span class="m"&gt;8px&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt; &lt;span class="m"&gt;0px&lt;/span&gt; &lt;span class="n"&gt;rgba&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nl"&gt;z-index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.menu&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="nc"&gt;.menu-content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This CSS-only approach to dropdowns keeps your codebase lean and avoids potential issues with JavaScript event handling.&lt;/p&gt;

&lt;h3&gt;
  
  
  Accordions
&lt;/h3&gt;

&lt;p&gt;Accordions are a common UI element, often used in FAQs or to hide/show sections of content. With CSS, you can create an accordion using the &lt;code&gt;:target&lt;/code&gt; pseudo-class or the checkbox hack.&lt;/p&gt;

&lt;p&gt;Example with &lt;code&gt;:target&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"accordion"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h3&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"section1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Section 1&lt;span class="nt"&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"content"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Content for section 1&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h3&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"section2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Section 2&lt;span class="nt"&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"content"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Content for section 2&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;#section1&lt;/span&gt;&lt;span class="nd"&gt;:target&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="nc"&gt;.content&lt;/span&gt;&lt;span class="nd"&gt;:nth-of-type&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;1&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt;
&lt;span class="nf"&gt;#section2&lt;/span&gt;&lt;span class="nd"&gt;:target&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="nc"&gt;.content&lt;/span&gt;&lt;span class="nd"&gt;:nth-of-type&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;2&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This approach lets users expand and collapse content sections without needing JavaScript, making for a simpler and more accessible solution.&lt;/p&gt;

&lt;h3&gt;
  
  
  CSS Counters
&lt;/h3&gt;

&lt;p&gt;CSS counters can replace JavaScript for simple numbering tasks, such as&lt;/p&gt;

&lt;p&gt;automatically numbering list items, sections, or figures.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;ol&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;counter-reset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;section&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;ol&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;counter-increment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;section&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;ol&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt;&lt;span class="nd"&gt;::before&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;section&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="s1"&gt;". "&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bold&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CSS counters are a powerful tool that can simplify your HTML structure by eliminating the need for manually adding numbers or JavaScript logic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-World Examples
&lt;/h2&gt;

&lt;p&gt;Let’s look at a few real-world examples where CSS has replaced JavaScript, resulting in cleaner, faster, and more maintainable code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example 1: Pure CSS Modal
&lt;/h3&gt;

&lt;p&gt;A modal window is often implemented using JavaScript to control its visibility. However, using the checkbox hack, you can create a modal with just HTML and CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"checkbox"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"modal-toggle"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"modal-toggle"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"modal-button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Open Modal&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"modal"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"modal-toggle"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"modal-close"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;×&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;This is a modal dialog created with pure CSS.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.modal&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;fixed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-50%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;-50%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#fff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;box-shadow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt; &lt;span class="m"&gt;15px&lt;/span&gt; &lt;span class="n"&gt;rgba&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;0.3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;#modal-toggle&lt;/span&gt;&lt;span class="nd"&gt;:checked&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;.modal&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example 2: CSS-Only Carousel
&lt;/h3&gt;

&lt;p&gt;Carousels or sliders are typically powered by JavaScript, but you can create a simple one using CSS animations and the &lt;code&gt;:checked&lt;/code&gt; pseudo-class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"carousel"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"slides"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"slide1"&lt;/span&gt; &lt;span class="na"&gt;checked&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"slides"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"slide2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"slides"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"slide3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"slides"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"slide"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"slide-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Slide 1&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"slide"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"slide-2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Slide 2&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"slide"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"slide-3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Slide 3&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.slides&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;300%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;transform&lt;/span&gt; &lt;span class="m"&gt;0.5s&lt;/span&gt; &lt;span class="n"&gt;ease&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;#slide1&lt;/span&gt;&lt;span class="nd"&gt;:checked&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="nc"&gt;.slides&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;#slide2&lt;/span&gt;&lt;span class="nd"&gt;:checked&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="nc"&gt;.slides&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-100%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;#slide3&lt;/span&gt;&lt;span class="nd"&gt;:checked&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="nc"&gt;.slides&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-200%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These examples show how powerful CSS can be when it comes to creating interactive elements without relying on JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;CSS has grown far beyond simple styling. With a solid understanding of its basics, you can leverage CSS to handle tasks that once required JavaScript, simplifying your code and improving performance. From hover effects to interactive UI components like dropdowns, accordions, and modals, CSS offers elegant solutions that are both lightweight and accessible. I encourage you to experiment with these techniques in your own projects. You might be surprised at how much you can achieve with just CSS!&lt;/p&gt;

&lt;h2&gt;
  
  
  Further Reading and Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://css-tricks.com/" rel="noopener noreferrer"&gt;CSS Tricks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS" rel="noopener noreferrer"&gt;MDN Web Docs - CSS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://css-tricks.com/snippets/css/a-guide-to-flexbox/" rel="noopener noreferrer"&gt;A Complete Guide to Flexbox&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://css-tricks.com/snippets/css/complete-guide-grid/" rel="noopener noreferrer"&gt;A Complete Guide to Grid&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>css</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Utilizing Generative AI for Coding Questions</title>
      <dc:creator>Hroney</dc:creator>
      <pubDate>Tue, 11 Jun 2024 15:12:17 +0000</pubDate>
      <link>https://forem.com/hroney/utilizing-generative-ai-for-coding-questions-20dg</link>
      <guid>https://forem.com/hroney/utilizing-generative-ai-for-coding-questions-20dg</guid>
      <description>&lt;h1&gt;
  
  
  Using Generative AI to Best Edit and Utilize for Coding-Related Questions
&lt;/h1&gt;




&lt;h2&gt;
  
  
  Index
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Why use Generative AI for Coding&lt;/li&gt;
&lt;li&gt;Best practices

&lt;ul&gt;
&lt;li&gt;Starting Off&lt;/li&gt;
&lt;li&gt;Scope&lt;/li&gt;
&lt;li&gt;Clear Context&lt;/li&gt;
&lt;li&gt;Sharing Relevant code snippets&lt;/li&gt;
&lt;li&gt;State clear objectives&lt;/li&gt;
&lt;li&gt;Highlight errors and issues&lt;/li&gt;
&lt;li&gt;Ask Targeted Questions&lt;/li&gt;
&lt;li&gt;Include Input and Output&lt;/li&gt;
&lt;li&gt;Use Comments&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Examples of Effective AI utilization

&lt;ul&gt;
&lt;li&gt;Debugging a Flask Route&lt;/li&gt;
&lt;li&gt;Optimizing a React Component&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Conclusion&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;We've now been living with generative AI's for nearly 2 years. It's here to stick around and I've grown accustomed to utilizing it for all manner of questions. I'd like to share with you today the required skillset for getting the information you want using your acumen to discern good and proper answers. &lt;/p&gt;

&lt;p&gt;Resources used: Chatgpt 3.5, 4, and Perplexity.ai&lt;/p&gt;

&lt;p&gt;This will blog post will be centered around coding but following this ruleset will allow you to tease out the proper information from a generative AI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Use Generative AI for Coding?
&lt;/h2&gt;

&lt;p&gt;Generative AI's save time. Quick solutions to coding problems if given the right context. They are a great learning tool. My background is in education with a focus on pedagogy. Hiring and training tutors is what I'm good at, utilizing these AI tools to mold them into good tutors is essential to understanding how to get the answers you need. &lt;br&gt;
These AI tools are also fantastic for debugging - Stuck on a logical problem? They can offer a solution or, if you don't want an outright solution, suggestions on how to approach the topic to allow for the learner/user to remain in that zone of proximal development. &lt;/p&gt;
&lt;h2&gt;
  
  
  Best Practices for Utilizing AI in Coding
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Starting off
&lt;/h3&gt;

&lt;p&gt;Be nice to your AI :) Say please an thank you &lt;em&gt;(Or at least I will, should be lose the technology arms race against our binary counterparts I wish to have been known as Cordial)&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Following a simple speaking and presenting pattern can help you sum most of what I'll say. This may look familiar to a lot of you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tell'em what you're going to tell'em.

&lt;ul&gt;
&lt;li&gt;Start off by telling the AI the outcome you want from your problem&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Tell'em

&lt;ul&gt;
&lt;li&gt;Give the AI the context of the problem (code, math problem, etc.)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Tell'em what you told'em

&lt;ul&gt;
&lt;li&gt;Summarize your requirements be adding additional specific context on how you want the problem presented to you (As code, as an answer, as an outline, etc)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Scope
&lt;/h3&gt;

&lt;p&gt;It's important to share code snippets and not your entire code base. You can share your code base as context for something like &lt;code&gt;Add comments to my code&lt;/code&gt; or &lt;code&gt;provide a read me&lt;/code&gt;. But limiting your scope of questioning will ensure good answers more often and maintains your personal autonomy to know how the code is developed. Asking an AI tool to write you code will only have you endlessly error handling and playing catch-up. Instead, write what you can - ask for help when you must. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Please fix the bug in this component **[provide snippet]** it's not doing **[XYZ]**&lt;/code&gt; is a much better query than &lt;code&gt;Here's my code **[entire code-base]**. Why isn't it working?&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Provide Clear Context
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Starting off, every query to a generative AI needs clear context. Context on what you're attempting to accomplish or want to get out of the exchange.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight markdown"&gt;&lt;code&gt;I am working on a web application that manages tutoring sessions using Flask and React.
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;The above gives the AI context on which areas to focus: &lt;code&gt;flask&lt;/code&gt;, &lt;code&gt;React&lt;/code&gt;, &lt;code&gt;Web application&lt;/code&gt;, &lt;code&gt;POST&lt;/code&gt; all give the AI the groundwork on where to build out THEIR context on how to share information. Since we've put in &lt;code&gt;flask&lt;/code&gt; and &lt;code&gt;React&lt;/code&gt; the answers delivered back to you will be entirely centered around these context languages and framework (Javascript, Python, etc.) &lt;/p&gt;

&lt;h3&gt;
  
  
  Share Relevant Code Snippets
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;After establishing where the groundwork is with context, you need to next provide the &lt;code&gt;Tell'em&lt;/code&gt;. Give the context of the code in question.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/sessions&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;methods&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;POST&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create_session&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;new_session&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Session&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;tutor_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;tutor_id&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="n"&gt;tutee_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;tutee_id&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="n"&gt;start_time&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;start_time&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="n"&gt;end_time&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;end_time&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;new_session&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;commit&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;jsonify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;new_session&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_dict&lt;/span&gt;&lt;span class="p"&gt;()),&lt;/span&gt; &lt;span class="mi"&gt;201&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  State Clear Objectives
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Clarify what you want to achieve with the code. It's important to explain to the AI the outcome that you want. This is all part of the process on getting back relevant answers. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;I want to add validation to ensure that the session times do not overlap for the same tutor.
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Make note&lt;/strong&gt; It's important to know that you will often get 'wrong' answers. It will at first be hard to discern what a 'wrong' answer looks like. Thus, you will need to be at the very least comfortable with discerning WHAT an issue looks like. As my dad would call it - your BS meter needs to be good at sniffing out potential problems. Knowing your vocabulary, data structures, and what the input / output of your components is, will better help you maintain code autonomy. &lt;/p&gt;

&lt;h3&gt;
  
  
  Highlight Errors or Issues
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Next, provide context on what is happening negatively to your snippet (If you so desire)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;Currently, the code does not check for overlapping session times, which can lead to scheduling conflicts.
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Ask Targeted Questions
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Be specific in your queries to get precise answers. The AI tools are just that, tools. They can't read your mind (yet). Give them an actionable command.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;How can I modify this route to check for overlapping sessions before creating a new one?
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Include Input and Output
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Provide sample input and expected output to help the tool understand WHAT is going through the modules/components. It not only provides better and more context (Keyword of the day!) it also helps you maintain that code autonomy I've been mentioning all over the blog.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;Sample Input: {"tutor_id": 1, "tutee_id": 2, "start_time": "2024-06-11T10:00:00", "end_time": "2024-06-11T11:00:00"}
Expected Output: {"error": "Session times overlap for the same tutor."}
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Use Comments
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Highlight specific parts of the code you are unsure about using comments. Your comments add extra context WITHIN the query. They pinpoint the problem for the AI tools to better target where you believe the issue may lit. &lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# This is where I need to check for overlapping sessions
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Examples of Effective AI Utilization
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Example 1: Debugging a Flask Route
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;I'm working on a Flask web application, and I'm encountering an error in one of my routes. I'm using Flask for the backend and React for the frontend. The specific route causing the issue is /api/get_data.&lt;br&gt;
Here's the code snippet for the route that's causing the problem:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# This is the route for retrieving data from the database
&lt;/span&gt;&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/api/get_data&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;methods&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;GET&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_data&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="c1"&gt;# Some code here that's causing the error
&lt;/span&gt;    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;jsonify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;I need help identifying and fixing the error in this route so that it returns the expected data when accessed.&lt;br&gt;
The error I'm encountering seems to be related to a KeyError when accessing a dictionary in the route function. I'm not sure why this error is occurring. &lt;br&gt;
Can you help me identify what might be causing the KeyError in this route function? Any suggestions on how to fix it?&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Example 2: Optimizing a React Component
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;I'm working on a React project, and I've noticed that one of my components is rendering slowly. The component in question is a dashboard displaying real-time data, and it's impacting the overall performance of the application.&lt;br&gt;
Here's the code snippet for the component that's rendering slowly:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Dashboard Component: Renders real-time data&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Dashboard&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Component code here&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* Dashboard content */&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Dashboard&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;I'm looking for suggestions on how to optimize this component's performance to improve rendering speed and overall application performance.&lt;br&gt;
The main issue I'm encountering is that the dashboard component takes a long time to render, especially when fetching and displaying large amounts of real-time data.&lt;br&gt;
What are some best practices for optimizing React components, particularly those that render real-time data? Are there any specific techniques or libraries I should consider using?&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Generative AI is a tool like any other - skilled wielders will be able to utilize the tool to a much greater effect. Knowing your subject area allows you to better focus the AI to get the answers you want. As such, Anyone can ask a Generative AI to write a webpage, but not everyone can then take that code to style it, deploy it, expand on it, change it to the customers wishes, etc. &lt;/p&gt;

&lt;p&gt;Following the above practices will give your AI the best &lt;u&gt;Context&lt;/u&gt; for understanding and providing you with the best answer or at least one you can adapt. &lt;/p&gt;

&lt;p&gt;I'd love to hear about your journeys with AI tools and how you have learned to best prompt them for information&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>ai</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>All Things Python (in-so-far as I've been using it!)</title>
      <dc:creator>Hroney</dc:creator>
      <pubDate>Fri, 15 Mar 2024 20:02:28 +0000</pubDate>
      <link>https://forem.com/hroney/all-things-python-in-so-far-as-ive-been-using-it-2cjl</link>
      <guid>https://forem.com/hroney/all-things-python-in-so-far-as-ive-been-using-it-2cjl</guid>
      <description>&lt;p&gt;Hello!&lt;/p&gt;

&lt;p&gt;Here marks another phase completed with #flatironschool! I feel as though this phase (phase 3) was quite a different approach to the learning process.&lt;/p&gt;

&lt;p&gt;First off - this phase was done in a new language, Python!&lt;/p&gt;

&lt;p&gt;Now... At first (And possibly even still...) It's not my favorite of the languages I've been introduced to. That being said - I adore object oriented programming and I thought I'd share some of what I've learned.&lt;/p&gt;

&lt;p&gt;But, before we dive into Object-oriented programming - let's mark out something I have enjoyed about Python.&lt;/p&gt;

&lt;p&gt;It's clear and concise in its language! If I wanted to consume every cookie in the cookie jar, it's as easy as looping through it like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;cookie&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;cookie_jar&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;consume&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cookie&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That same could be done in javascript but would look something like...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;cookie_jar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;cookie&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;consume&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cookie&lt;/span&gt;&lt;span class="p"&gt;)};&lt;/span&gt;
&lt;span class="c1"&gt;// or&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;cookie&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;cookie_jar&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;consume&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cookie&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The javascript is far less readable out the box.&lt;/p&gt;

&lt;p&gt;This is just one example.&lt;/p&gt;

&lt;p&gt;Printing to the console is straightforward in both. But Python just reads more easily.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;foo&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;foo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Checking the length of an array or string makes more sense to be a wrapper around the object rather than a function OF the object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;2&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;3&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;3&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;length&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But I enjoy most of all - classes.&lt;/p&gt;

&lt;p&gt;Let's look at an example of a class and break it down line by line.&lt;/p&gt;

&lt;h4&gt;
  
  
  Person.py
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="mf"&gt;1.&lt;/span&gt; &lt;span class="c1"&gt;# lib/person/Person.py
&lt;/span&gt;&lt;span class="mf"&gt;2.&lt;/span&gt; &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;lib.person._Person&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;PersonMethods&lt;/span&gt;
&lt;span class="mf"&gt;3.&lt;/span&gt; 
&lt;span class="mf"&gt;4.&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;PersonMethods&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;span class="mf"&gt;5.&lt;/span&gt; 
&lt;span class="mf"&gt;6.&lt;/span&gt;     &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;span class="mf"&gt;7.&lt;/span&gt;         &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
&lt;span class="mf"&gt;8.&lt;/span&gt; 
&lt;span class="mf"&gt;9.&lt;/span&gt;     &lt;span class="nd"&gt;@property&lt;/span&gt;
&lt;span class="mf"&gt;10.&lt;/span&gt;     &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;span class="mf"&gt;11.&lt;/span&gt;         &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_name&lt;/span&gt;
&lt;span class="mf"&gt;12.&lt;/span&gt; 
&lt;span class="mf"&gt;13.&lt;/span&gt;     &lt;span class="nd"&gt;@name.setter&lt;/span&gt;
&lt;span class="mf"&gt;14.&lt;/span&gt;     &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;span class="mf"&gt;15.&lt;/span&gt;         &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;span class="mf"&gt;16.&lt;/span&gt;             &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
&lt;span class="mf"&gt;17.&lt;/span&gt;         &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="mf"&gt;18.&lt;/span&gt;             &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="mf"&gt;19.&lt;/span&gt;                 &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Name must be a non-empty string&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="mf"&gt;20.&lt;/span&gt;             &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Breakdown
&lt;/h5&gt;

&lt;p&gt;&lt;u&gt;Line 1&lt;/u&gt;: A Single line comment indicating the file path.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Line 2&lt;/u&gt;: &lt;code&gt;from lib.person._Person import PersonMethods&lt;/code&gt; Imports the &lt;code&gt;PersonMethods&lt;/code&gt; class from the &lt;code&gt;_Player&lt;/code&gt; module.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Line 4&lt;/u&gt;: &lt;code&gt;class Person(PersonMethods):&lt;/code&gt; Defines a new class named &lt;code&gt;Person&lt;/code&gt; that inherits from the &lt;code&gt;PersonMethods&lt;/code&gt; class imported on Line 2. Inheritance allows a class to inherit attributes and methods from another class. In this case, separating methods from Getters / Setters.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Line 6&lt;/u&gt;: &lt;code&gt;__init__&lt;/code&gt; is a &lt;code&gt;Constructor&lt;/code&gt;. This is a special method that is called when a new instance of the class is instantiated. There are two parameters to the constructor here, &lt;code&gt;self&lt;/code&gt; and &lt;code&gt;name&lt;/code&gt;. &lt;code&gt;self&lt;/code&gt; refers to the instance of the class and is not expressly passed into the constructor upon creation. &lt;code&gt;name&lt;/code&gt; is a string (in this case) that is passed into the constructor when initializing the instance.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Line 7&lt;/u&gt;: &lt;code&gt;self.name = name&lt;/code&gt; This line assigns the value of &lt;code&gt;name&lt;/code&gt; that was passed in on line 6 into an attribute of the current instance &lt;code&gt;self&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Line 9 - 11&lt;/u&gt;: &lt;code&gt;@property&lt;/code&gt; is a &lt;code&gt;decorator&lt;/code&gt; used to define a property. Properties provide a way to customize attribute access. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;John&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# This will print "John"
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However this is equivalent to calling the &lt;code&gt;name()&lt;/code&gt; method on the instance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;# This will also print "John"
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By using the &lt;code&gt;@property&lt;/code&gt; decorator, it allows us to more cleanly access the attribute as though it were a direct attribute.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Line 13&lt;/u&gt;: &lt;code&gt;@name.setter&lt;/code&gt; is a decorator that defines a setter method for the &lt;code&gt;name&lt;/code&gt; property. &lt;/p&gt;

&lt;p&gt;&lt;u&gt;Line 14&lt;/u&gt;: &lt;code&gt;def name(self, name):&lt;/code&gt; defines the &lt;code&gt;name&lt;/code&gt; method as a setter based on the decorator in line 13.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Line 15&lt;/u&gt;: &lt;code&gt;if isinstance(name, str) and len(name):&lt;/code&gt; This is our first bit of logic! This line checks if the value passed into the setter, &lt;code&gt;name&lt;/code&gt;, is a non-empty string. &lt;code&gt;isinstance()&lt;/code&gt; is a function to check if the value is an instance of the &lt;code&gt;string&lt;/code&gt; class and the &lt;code&gt;len()&lt;/code&gt; function checks if the string has a length greater than 0&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Line 17 - 20&lt;/u&gt;: &lt;code&gt;else: raise ValueError("Name....")&lt;/code&gt; this line only fires if the value passed into the setter method is not a valid string. It will raise a &lt;code&gt;ValueError&lt;/code&gt; with the message attached.&lt;/p&gt;

&lt;p&gt;All in all, by defining a setter method for the name property, the &lt;code&gt;name&lt;/code&gt; attribute of an instance &lt;code&gt;Person&lt;/code&gt; can be modified using assignment syntax. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;John&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Alice&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;# Changes the name of person
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  _Person.py
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="mf"&gt;1.&lt;/span&gt; &lt;span class="c1"&gt;# lib/person/_Person.py
&lt;/span&gt;&lt;span class="mf"&gt;2.&lt;/span&gt; 
&lt;span class="mf"&gt;3.&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PersonMethods&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="mf"&gt;4.&lt;/span&gt; 
&lt;span class="mf"&gt;5.&lt;/span&gt;     &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;say_name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;span class="mf"&gt;6.&lt;/span&gt;         &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;My name is &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Breakdown
&lt;/h4&gt;

&lt;p&gt;&lt;u&gt;Line 1&lt;/u&gt;: A Single line comment indicating the file path.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Line 3&lt;/u&gt;: &lt;code&gt;class PersonMethods:&lt;/code&gt; defines a new class &lt;code&gt;PersonMethods&lt;/code&gt; that, unlike &lt;code&gt;Person&lt;/code&gt;, does not inherit any methods. Instead, this class has a single method &lt;code&gt;say_name()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Line 5&lt;/u&gt;: &lt;code&gt;def say_name(self):&lt;/code&gt; definds a method named &lt;code&gt;say_name&lt;/code&gt; within the method that has the &lt;code&gt;self&lt;/code&gt; parameter, indicating that this is an instance method (a method specifically used by each instance of the class rather than the class itself). &lt;/p&gt;

&lt;p&gt;&lt;u&gt;Line 6&lt;/u&gt;: &lt;code&gt;return f"My name is {self.name}"&lt;/code&gt; returns a string formatted using string interpolation.&lt;/p&gt;

&lt;h3&gt;
  
  
  All together now!
&lt;/h3&gt;

&lt;p&gt;So! By inheriting from &lt;code&gt;PersonMethods&lt;/code&gt;, instances of the &lt;code&gt;Person&lt;/code&gt; class gain access to the methods defined in the &lt;code&gt;PersonMethods&lt;/code&gt; class! For example, the &lt;code&gt;say_name()&lt;/code&gt; method we created earlier can be invoked directly on instances of the &lt;code&gt;Person&lt;/code&gt; class!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;John&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;say_name&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="c1"&gt;# Output: "My name is John"
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This illustrates how the &lt;code&gt;Person&lt;/code&gt; class in &lt;code&gt;Person.py&lt;/code&gt; benefits from the methods encapsulated in the &lt;code&gt;PersonMethods&lt;/code&gt; class defined in &lt;code&gt;_Person.py&lt;/code&gt;!&lt;/p&gt;

&lt;h4&gt;
  
  
  A Caveat to Python...
&lt;/h4&gt;

&lt;p&gt;While I love the object oriented programming paradigm... Python has a major annoyance for my organized brain...&lt;/p&gt;

&lt;p&gt;The indentation! 4 spaces!? With Javascript, just wrap everything in curly braces {}. Boom! You know where your scope lines are.&lt;/p&gt;

&lt;p&gt;This whitespace sensitivity to define block structure is a real visual problem for me. I appreciate the explicit block delimiters that javascript has with &lt;code&gt;{}&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I learned a lot more about Python but this is just a neat little explanation of something I found fun to learn.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>React-Router-Dom as told by a noob :)</title>
      <dc:creator>Hroney</dc:creator>
      <pubDate>Mon, 22 Jan 2024 22:35:43 +0000</pubDate>
      <link>https://forem.com/hroney/react-router-dom-as-told-by-a-noob--4bng</link>
      <guid>https://forem.com/hroney/react-router-dom-as-told-by-a-noob--4bng</guid>
      <description>&lt;p&gt;I began my Phase 2 project by deciding to build out a webpage using an open source D&amp;amp;D 5e API. I learned pretty quickly, that the documentation was amazing but, some of the structures inside the JSON were rather difficult to parse out... But that's a topic for a different time. &lt;/p&gt;

&lt;p&gt;I wanted to focus on the &lt;code&gt;React-Router-Dom&lt;/code&gt; library and my routes and try to explain, As best as I can, how it works to give myself a better understanding and perhaps help some other soul who happens to find themselves here. &lt;/p&gt;

&lt;p&gt;Below is my Routes.js file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;routes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;children&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Home&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/classes&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Classes&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;children&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
                    &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/classes/:id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ClassInformation&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/spells&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Spells&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;children&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
                    &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/spells/:id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;SpellInformation&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="na"&gt;children&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
                            &lt;span class="p"&gt;{&lt;/span&gt;
                                &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/spells/:id/:id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                                &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Spell&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                            &lt;span class="p"&gt;}&lt;/span&gt;
                        &lt;span class="p"&gt;]&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;
                &lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/pick-a-class&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Classform&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/party&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Party&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fairly straightforward but, what the heck does it all mean?&lt;/p&gt;

&lt;p&gt;Well let's start from the top.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;routes&lt;/code&gt; is an array of route configurations (an object).&lt;br&gt;
Each route configuration is itself an object with properties such as &lt;code&gt;path&lt;/code&gt; and &lt;code&gt;element&lt;/code&gt;.&lt;br&gt;
The &lt;code&gt;Path&lt;/code&gt; property represents the URL path for the route.&lt;br&gt;
The &lt;code&gt;Element&lt;/code&gt; property represents the React component to be rendered when the route is matched.&lt;/p&gt;

&lt;p&gt;Now, let's break down the nested structure!&lt;/p&gt;

&lt;p&gt;The top-level route has a &lt;code&gt;path&lt;/code&gt; of &lt;code&gt;'/'&lt;/code&gt; and its &lt;code&gt;element&lt;/code&gt; is the &lt;code&gt;&amp;lt;App /&amp;gt;&lt;/code&gt; component. It also has &lt;code&gt;children&lt;/code&gt;, which are nested routes.&lt;/p&gt;

&lt;p&gt;The first &lt;code&gt;Child&lt;/code&gt; route has a &lt;code&gt;path&lt;/code&gt; of &lt;code&gt;'/'&lt;/code&gt; (the Root path) and its &lt;code&gt;element&lt;/code&gt; is the &lt;code&gt;&amp;lt;Home /&amp;gt;&lt;/code&gt; component.&lt;/p&gt;

&lt;p&gt;The Second &lt;code&gt;Child&lt;/code&gt; route has a &lt;code&gt;path&lt;/code&gt; of &lt;code&gt;'/classes'&lt;/code&gt; and its &lt;code&gt;element&lt;/code&gt; is the &lt;code&gt;&amp;lt;Classes /&amp;gt;&lt;/code&gt; component. It ALSO has a nested route under the &lt;code&gt;children&lt;/code&gt; property with a &lt;code&gt;Dynamic parameter&lt;/code&gt; labeled &lt;code&gt;:id&lt;/code&gt; (used to capture the Class ID) and its &lt;code&gt;element&lt;/code&gt; is the &lt;code&gt;&amp;lt;ClassInformation /&amp;gt;&lt;/code&gt; component. &lt;/p&gt;
&lt;h3&gt;
  
  
  HOLD ON NOW
&lt;/h3&gt;

&lt;p&gt;What's a &lt;code&gt;Dynamic Parameter&lt;/code&gt;?! Well dear reader, I'm glad I foresaw your question! &lt;/p&gt;

&lt;p&gt;In the context of routing, a dynamic parameter refers to a placeholder in the URL path that can capture different values as part of the route.&lt;/p&gt;

&lt;p&gt;In the code I provided, the dynamic parameter (&lt;code&gt;/classes/:id&lt;/code&gt;) in certain route paths is a dynamic parameter. It means that the route will match any path that follows the pattern &lt;code&gt;"/classes/"&lt;/code&gt; and is followed by some dynamic value. &lt;/p&gt;

&lt;p&gt;For instance, if the URL is &lt;code&gt;"/classes/123"&lt;/code&gt; the value of &lt;code&gt;:id&lt;/code&gt; would be "123". In my code that's not labelled here - the &lt;code&gt;:id&lt;/code&gt; is itself fairly dynamic because I wanted to reuse the Class Sidebar I created!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Link&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;link-text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;linkInfo&lt;/span&gt;&lt;span class="p"&gt;}${&lt;/span&gt;&lt;span class="nx"&gt;characterClass&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;characterClass&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Link&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;My &lt;code&gt;${linkInfo}&lt;/code&gt; is passed into this component and is the string of the first start of the URL. In the case above it would be &lt;code&gt;/classes/&lt;/code&gt; while the &lt;code&gt;${characterClass.index}&lt;/code&gt; is the index value of the class in the higher component (in this case, it's each individual class in the &lt;code&gt;ClassList&lt;/code&gt; that was rendered out from the API).&lt;/p&gt;

&lt;p&gt;This means that each Character class is given its own unique webpage URL that is rendered out from the component I made for them! Pretty neat!&lt;/p&gt;

&lt;h3&gt;
  
  
  BACK TO THE ROUTES
&lt;/h3&gt;

&lt;p&gt;So going down the list you can see the pattern. Each of my components is given a Route and URL. Each component is rendered when the URL is changed. Each URL is changed based on the NavBar or other navigations in my web application. All in all, it's really neat!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>The "Is this a word" check of my Phase 1 Flatiron Project</title>
      <dc:creator>Hroney</dc:creator>
      <pubDate>Mon, 13 Nov 2023 22:56:13 +0000</pubDate>
      <link>https://forem.com/hroney/the-is-this-a-word-check-of-my-phase-1-flatiron-project-1kb1</link>
      <guid>https://forem.com/hroney/the-is-this-a-word-check-of-my-phase-1-flatiron-project-1kb1</guid>
      <description>&lt;h2&gt;
  
  
  Hello!
&lt;/h2&gt;

&lt;p&gt;I thought I'd break apart my "isAWord" function in my project as this is where all of the magic happens.&lt;/p&gt;

&lt;p&gt;My project can be found here: &lt;code&gt;https://github.com/Hroney/flatiron-phase-1-project&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Object
&lt;/h2&gt;

&lt;p&gt;For reference: The Object that is the word and its functions are seen here.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Word {
    constructor(name) {
        this.name = name;
        this.definitions = [];
        this.nameArray = [];
    }

    addDefinition(definition, partOfSpeech) {
        this.definitions.push({ definition, partOfSpeech });
    }

    splitTheWord() {
        this.nameArray = this.name.toUpperCase().split('');
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Function
&lt;/h2&gt;

&lt;p&gt;We start off by creating an &lt;code&gt;Async&lt;/code&gt; function as &lt;code&gt;isAWord&lt;/code&gt; calls the dictionary api multiple times while writing information to a &lt;code&gt;db.json&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The passed in &lt;code&gt;userInput&lt;/code&gt; is grabbed from an event listener text input and put to lowercase to standardize the usage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function isAWord(userInput) {
    let word = userInput.toLowerCase();
    ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next the user input &lt;code&gt;word&lt;/code&gt; is checked against the &lt;code&gt;db.json&lt;/code&gt; and pulls the relevant data instead of calling the dictionary api a second time for information we've already gathered.&lt;/p&gt;

&lt;p&gt;Each definition and the related &lt;code&gt;partOfSpeech&lt;/code&gt; in the &lt;code&gt;db&lt;/code&gt; is grabbed and is passed into the object &lt;code&gt;theWord&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;&lt;code&gt;theWord&lt;/code&gt; is split using &lt;code&gt;splitTheWord&lt;/code&gt; which turns the name of &lt;code&gt;theWord&lt;/code&gt; into an array so each letter can be appended to it's own &lt;code&gt;Div&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   if (db &amp;amp;&amp;amp; word in db) {
        const dbWord = db[word];
        theWord = new Word(dbWord.name);
        dbWord.definitions.forEach(({ definition, partOfSpeech }) =&amp;gt; {
            theWord.addDefinition(definition, partOfSpeech);
        });
        theWord.splitTheWord();
        return theWord;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the word is not in the &lt;code&gt;db.json&lt;/code&gt; it is checked first to make sure it is a word.&lt;/p&gt;

&lt;p&gt;This function checks the passed in &lt;code&gt;userInput&lt;/code&gt; and determines if any of the elements in the &lt;code&gt;userInput&lt;/code&gt; are themselves a space, a punctuation mark, or a number. All of which would not return a proper word.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;returnValue&lt;/code&gt; defaults &lt;code&gt;true&lt;/code&gt; as to assume it's a valid word until proven otherwise.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function isASingleWord(userInput) {
    let charArray = userInput.split('');
    const punctuation = /[!"#$%&amp;amp;'()*+,-./:;&amp;lt;=&amp;gt;?@[\]^_`{|}~]/;
    const numbers = /\d+/g;
    let returnValue = true;

    if (charArray.some(element =&amp;gt; element.includes(' '))) {
        returnValue = false;
    } else if (charArray.some(element =&amp;gt; punctuation.test(element))) {
        returnValue = false;
    } else if (charArray.some(element =&amp;gt; numbers.test(element))) {
        returnValue = false;
    }
    return returnValue;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the word passes the &lt;code&gt;isASingleWord&lt;/code&gt; if statement, the dictionary api is called.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;response&lt;/code&gt; variable is created and assigned the fetched status. If the response is &lt;code&gt;ok&lt;/code&gt; (a read only property of response) and it's boolean returns false, the api call was unsuccessful.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const response = await fetch(apiUrl);
            if (!response.ok) {
                throw new Error(`HTTP Error! Status is: ${response.status}`);
            }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If it passes as true however, the &lt;code&gt;data&lt;/code&gt; variable is assigned the response passed through the built in &lt;code&gt;json()&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;This &lt;code&gt;data&lt;/code&gt; is checked for the title of the word and if the title returns &lt;code&gt;No Definitions Found&lt;/code&gt; then while it is a word, it is not a definable word in the dictionary and will return an empty object Word.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try {
     const data = await response.json();
            if (data.title === "No Definitions Found") {
                return new Word('');
            }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If however it does have a title that isn't the api's default &lt;code&gt;No Definitions Found&lt;/code&gt;, then &lt;code&gt;theWord&lt;/code&gt; is instantiated with the &lt;code&gt;word&lt;/code&gt; data from the api call. The definitions and parts of speech are grabbed and build the object.&lt;/p&gt;

&lt;p&gt;It is then added to the database with the &lt;code&gt;addToDB&lt;/code&gt; function so that successive api calls do not call words already added to the &lt;code&gt;db.json&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;            else {
                theWord = new Word(data[0].word);
                data[0].meanings.forEach(object =&amp;gt; {
                    object.definitions.forEach(definitionArray =&amp;gt; {
                        theWord.addDefinition(definitionArray.definition, object.partOfSpeech);
                    });
                });
                theWord.splitTheWord();
                addToDB(theWord);
                return theWord;
            }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lastly, the &lt;code&gt;try-catch&lt;/code&gt; block is finished, where the catch grabs an &lt;code&gt;error&lt;/code&gt; if one exists and if the &lt;code&gt;isASingleWord&lt;/code&gt; function returns false, it fires the &lt;code&gt;else&lt;/code&gt; statement to return an empty &lt;code&gt;Word Object&lt;/code&gt; to clear out the gamefield.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;catch (error) {
            console.error('Error fetching word data:', error);
            return new Word('');
        }
    } else {
        return new Word('');
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This project was a lot of fun and I learned a lot about &lt;code&gt;async&lt;/code&gt; and &lt;code&gt;promise&lt;/code&gt; and yet, I feel as though I have so much to learn on the subject. &lt;/p&gt;

&lt;p&gt;Thank you if you stuck with me! I'm sure there's a better way to do the project I've created as I essentially brute forced my way through on the API calls, my Json-server crashes often I believe because of my anti-virus, and the async functions often are slow. I look forward to challenging myself and learning to know what I did wrong where how to improve.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>I'm bad at blogging</title>
      <dc:creator>Hroney</dc:creator>
      <pubDate>Fri, 29 Sep 2023 19:45:14 +0000</pubDate>
      <link>https://forem.com/hroney/im-bad-at-blogging-540d</link>
      <guid>https://forem.com/hroney/im-bad-at-blogging-540d</guid>
      <description>&lt;p&gt;Wowee!&lt;/p&gt;

&lt;p&gt;It's been 10 days. Note to others - Life gets in the way of even the best intentions. &lt;/p&gt;

&lt;p&gt;I'm chugging along with Javascript at Flatiron! Currently on-track with the 10 month long process. I don't get any time off to actually dig into the material and just plow through it sadly. That being said - I learned quite a bit about objects that I didn't know prior. In fact - It's the first time that objects has finally clicked with me. I first tried C and C++ in my undergrad and it just never made any sense. But, this is so simple now. It's like the language just keeps unfolding and it's so internally consistent.&lt;/p&gt;

&lt;p&gt;I'm sure I'm wrong and I'll learn soon just how wrong I am. But, don't burst my bubble quite yet!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Returning to a Journey</title>
      <dc:creator>Hroney</dc:creator>
      <pubDate>Tue, 19 Sep 2023 17:25:23 +0000</pubDate>
      <link>https://forem.com/hroney/returning-to-a-journey-238d</link>
      <guid>https://forem.com/hroney/returning-to-a-journey-238d</guid>
      <description>&lt;p&gt;Hey Y'all!&lt;/p&gt;

&lt;p&gt;This is a first for me. I've hardly ever felt it necessary to write down my thoughts or exploits as it's mostly just lived within my skull. However, as I and my kids are aging it is becoming increasingly difficult to remember not just my life but theirs as well.&lt;/p&gt;

&lt;p&gt;So! Without further ado.&lt;/p&gt;

&lt;p&gt;My Name is Hayden and I went to school for Philosophical Logic from 2015-2018. I got my Bachelors and graduated Summa Cum Laude. During my time in the program I took electives in Java, C, and C++. I enjoyed the structure of taking arguments and scoped logical problems and adapting them to a computer to then give back to me what I could do with propositional and predicate logic.&lt;/p&gt;

&lt;p&gt;I'm returning now after marrying and with 2 kids in the mix. I can't afford to live on the salary I am and I'm looking to not only change my lot in life through this medium - I am also looking to expand my skillset to be more than an abstract set of Jeopardy facts.&lt;/p&gt;

&lt;p&gt;I started the Flatiron school's Software Engineering course 9/18/23 and I'm excited to give this a proper try. &lt;/p&gt;

&lt;p&gt;I'll keep you all updated once a week. &lt;/p&gt;

&lt;p&gt;-Hayden&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
