<?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>DEV Community: David Chedrick</title>
    <description>The latest articles on DEV Community by David Chedrick (@davidchedrick).</description>
    <link>https://dev.to/davidchedrick</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%2F680374%2Fe1cfeb49-02f1-4287-934d-dedbdca0cdd4.png</url>
      <title>DEV Community: David Chedrick</title>
      <link>https://dev.to/davidchedrick</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/davidchedrick"/>
    <language>en</language>
    <item>
      <title>The Purrfect Loop: Understanding JavaScript's Event Loop and Call Stack with Cats 🐾</title>
      <dc:creator>David Chedrick</dc:creator>
      <pubDate>Fri, 05 May 2023 03:05:17 +0000</pubDate>
      <link>https://dev.to/davidchedrick/the-purrfect-loop-understanding-javascripts-event-loop-and-call-stack-with-cats-4l9a</link>
      <guid>https://dev.to/davidchedrick/the-purrfect-loop-understanding-javascripts-event-loop-and-call-stack-with-cats-4l9a</guid>
      <description>&lt;p&gt;Hello ❤️, fellow cat lovers and coders! 🐈💻&lt;/p&gt;

&lt;p&gt;Lets get into another JavaScript topic that is often overlooked.&lt;/p&gt;

&lt;p&gt;Today we will explore the heart of JavaScript's runtime environment: the Event Loop and Call Stack. We will use some playful kittens to guide us through.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Call Stack: A Line of Playful Kitties 🐱
&lt;/h2&gt;

&lt;p&gt;Imagine a line of kittens, each waiting for their turn to play with a toy. The first kitten in line gets to play first. This is just like the Call Stack in JavaScript, where our function calls are the kittens.&lt;/p&gt;

&lt;p&gt;In JavaScript, when a function is called, it's added to the top of the stack (just like a new kitten joining the front of the line). This function will run before the ones that were added before it (our first kitten gets to play while the others watch).&lt;/p&gt;

&lt;p&gt;When the function finishes running, it leaves the stack (our kitten finishes playing and leaves the line). If a function calls another function, it's like a kitten bringing a friend to the front of the line to play next.&lt;/p&gt;

&lt;p&gt;Here's a code example:&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;function&lt;/span&gt; &lt;span class="nx"&gt;chaseLaserPointer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&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;Kitty is chasing the laser pointer!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;play&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;chaseLaserPointer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&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;Kitty is playing!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;play&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, calling play() adds the play function to the Call Stack. Inside play, we call chaseLaserPointer, which gets added to the top of the Call Stack and runs first. Once chaseLaserPointer finishes, it's removed from the stack, and the rest of play can continue.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Event Loop: The Human Deciding Which Kitty Plays Next 🙋‍♀️
&lt;/h2&gt;

&lt;p&gt;Now, imagine a human watching over our kittens, deciding which one gets to play next. This is just like JavaScript's Event Loop.&lt;/p&gt;

&lt;p&gt;The Event Loop has one simple job: to monitor the Call Stack and the callback queue. If the Call Stack is empty (all the kittens have finished playing), it takes the first event from the queue and moves it to the Call Stack (the human lets the next kitten play).&lt;/p&gt;

&lt;p&gt;This mechanism allows JavaScript to handle asynchronous events like clicks, timers, or fetch calls (the kittens that are too excited to wait in line and want to play right away).&lt;/p&gt;

&lt;p&gt;Here's a code example:&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;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;First kitten starts playing&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&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;Second kitten starts playing&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&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;Third kitten starts playing&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, console.log("First kitten starts playing") gets added to the Call Stack and executes immediately. The setTimeout function is also added to the Call Stack, but it's an asynchronous function. It sets up a timer and then finishes, so it's quickly removed from the Call Stack.&lt;/p&gt;

&lt;p&gt;The callback function inside setTimeout is like an excited kitten—it's added to the callback queue, not the Call Stack. After 1000 milliseconds (1 second), it's ready to play, but it has to wait its turn!&lt;/p&gt;

&lt;p&gt;While it's waiting, console.log("Third kitten starts playing") gets added to the Call Stack and executes. Once the Call Stack is empty, the Event Loop moves our waiting callback onto the Call Stack, and it finally gets to execute: "Second kitten starts playing" is logged to the console.&lt;/p&gt;

&lt;p&gt;When we write JavaScript, we're choreographing a ballet of kittens, deciding when and how they get to play. Understanding the Call Stack and Event Loop helps us create a more synchronized dance, ensuring that each kitten gets their fair share of the fun, and our users enjoy a smooth experience.&lt;/p&gt;




&lt;p&gt;❤️❤️❤️&lt;/p&gt;

&lt;p&gt;Follow me on &lt;a href="https://www.linkedin.com/in/davidchedrick/"&gt;LinkedIn &lt;/a&gt;for future blog posts&lt;br&gt;
May your code always be as graceful as a cat! 🐾&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Cats, Code, and Jest: Testing Your JavaScript Purrfectly</title>
      <dc:creator>David Chedrick</dc:creator>
      <pubDate>Wed, 03 May 2023 05:01:50 +0000</pubDate>
      <link>https://dev.to/davidchedrick/cats-code-and-jest-testing-your-javascript-purrfectly-48jb</link>
      <guid>https://dev.to/davidchedrick/cats-code-and-jest-testing-your-javascript-purrfectly-48jb</guid>
      <description>&lt;p&gt;Hello ❤️, fellow cat-loving coders! 😺 Today, we'll be exploring the world of testing JavaScript with Jest. When it comes to software development, testing is often overlooked, especially in the hustle of coding boot camps and self learning. So lets do a quick intro into unit testing with Jest. Grab your cat (or a lovie) and let's get started!&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Test Your JavaScript Code?
&lt;/h2&gt;

&lt;p&gt;In an ideal world, our code would always work purrfectly, but we know that's not the case. 🙀 This is why we test our code, to catch bugs and ensure that our applications function as expected. Unit testing is a crucial part of this process, as it helps us verify individual components of our code in isolation. Jest is a popular testing library for JavaScript that allows us to write tests easily and efficiently.&lt;/p&gt;




&lt;h2&gt;
  
  
  Getting Started with Jest!
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;To get started, let's add Jest to our project. Open your terminal, navigate to your project folder, and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; jest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Configuration
&lt;/h3&gt;

&lt;p&gt;Next, add a "test" script to your package.json file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"jest"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you're all set to start writing tests with Jest! 🎉&lt;/p&gt;




&lt;h2&gt;
  
  
  Creating Our First Test
&lt;/h2&gt;

&lt;p&gt;Let's say we have a simple function that calculates the total number of kitty treats we need to buy. It's in a file called &lt;/p&gt;

&lt;p&gt;&lt;em&gt;treats.js:&lt;/em&gt;&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;function&lt;/span&gt; &lt;span class="nx"&gt;calculateTreats&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;kitties&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;treatsPerKitty&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;kitties&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;treatsPerKitty&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;calculateTreats&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To test this function, create a new file in the same directory called treats.test.js. Inside this file, we'll write our first test:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;treats.test.js:&lt;/em&gt;&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;calculateTreats&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./treats&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Calculate the total number of kitty treats&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;kitties&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&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;treatsPerKitty&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&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;expectedTotalTreats&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;calculateTreats&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;kitties&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;treatsPerKitty&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nx"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;expectedTotalTreats&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;In this test, we're using the test function provided by Jest. The first argument is a string describing the test, and the second argument is a function containing the actual test.&lt;/p&gt;




&lt;h2&gt;
  
  
  Running Our Tests
&lt;/h2&gt;

&lt;p&gt;To run our tests, simply execute the following command in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If all goes well, you should see a message like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;PASS  ./treats.test.js
  ✓ Calculate the total number of kitty treats &lt;span class="o"&gt;(&lt;/span&gt;5 ms&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations! You've just written and run your first Jest test! 🐾🐾🐾🐾&lt;/p&gt;




&lt;h2&gt;
  
  
  Lets look at some of those Jest functions:
&lt;/h2&gt;

&lt;p&gt;The test() function is used to define a single unit test within your test suite. It takes two arguments:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;A string that describes the test's purpose. This description helps you and other developers understand what the test is meant to verify or accomplish. It's important to be clear and concise when writing test descriptions.&lt;br&gt;
In our example above we used the test description: 'Calculate the total number of kitty treats'.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The second argument is a callback function that contains the test logic. We define the input values (kitties and treatsPerKitty), the expected result (expectedTotalTreats), and use Jest's expect() function with the toBe() matcher to verify that the output of our calculateTreats() function matches the expected result.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When you run your tests using npm test, Jest will execute each test() function defined in your test files, and report the results (whether they pass or fail) along with their descriptions. This makes it easier to identify and fix any issues that arise during testing.&lt;/p&gt;




&lt;p&gt;The expect() function is used to assert that a certain value or condition is met within your test. &lt;br&gt;
Recall that we have a simple function in treats.js that calculates the total number of kitty treats we need to buy.&lt;br&gt;
In the test, we first import the calculateTreats function from treats.js. Then, we use the test() function to define our test. Inside the test function, we set up some input values (kitties and treatsPerKitty) and the expected result (expectedTotalTreats).&lt;/p&gt;

&lt;p&gt;Now, let's focus on the expect() function:&lt;/p&gt;

&lt;p&gt;We call expect() with the actual value, which is the result of invoking our calculateTreats() function with the input values kitties and treatsPerKitty. In this case, the actual value is calculateTreats(5, 10) which should equal 50.&lt;/p&gt;

&lt;p&gt;The expect() function then returns an "expectation" object with various matchers. In our example, we use the .toBe() matcher to compare the actual value with the expected result (expectedTotalTreats). The .toBe() matcher checks if the actual value is strictly equal (===) to the expected value.&lt;/p&gt;

&lt;p&gt;In this case, if calculateTreats(5, 10) is equal to 50, the test passes. If not, the test fails, and Jest will report the discrepancy, indicating that our calculateTreats() function may not be working as expected.&lt;/p&gt;




&lt;h2&gt;
  
  
  Other Common Matchers:
&lt;/h2&gt;

&lt;p&gt;.toBe(): Checks if the actual value is strictly equal (===) to the expected value.&lt;/p&gt;

&lt;p&gt;.toEqual(): Checks if the actual value is deeply equal to the expected value. Useful for comparing objects and arrays.&lt;/p&gt;

&lt;p&gt;.toBeTruthy(): Checks if the actual value is truthy (i.e., not false, 0, null, undefined, NaN, or an empty string).&lt;/p&gt;

&lt;p&gt;.toBeFalsy(): Checks if the actual value is falsy (i.e., one of the aforementioned false, 0, null, undefined, NaN, or an empty string).&lt;/p&gt;




&lt;p&gt;Testing your JavaScript code with Jest can help you ensure that your applications are stable and reliable. By writing unit tests, you're investing in the long-term quality of your code, making it easier to maintain and improve. Plus, you'll have more time to cuddle with your favorite feline friends, knowing that your code is in tip-top shape! 🐱&lt;/p&gt;

&lt;p&gt;Remember, a purrfectly tested codebase is a happy codebase. &lt;/p&gt;




&lt;p&gt;Further Reading:&lt;br&gt;
&lt;a href="https://jestjs.io/"&gt;Jest Docs&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;❤️❤️❤️&lt;/p&gt;

&lt;p&gt;Follow me on &lt;a href="https://www.linkedin.com/in/davidchedrick/"&gt;LinkedIn &lt;/a&gt;for future blog posts&lt;br&gt;
May your code always be as graceful as a cat! 🐾&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>testing</category>
    </item>
    <item>
      <title>Beware of Fake Job Offers: My Encounter with a Scammer</title>
      <dc:creator>David Chedrick</dc:creator>
      <pubDate>Fri, 24 Feb 2023 03:10:05 +0000</pubDate>
      <link>https://dev.to/davidchedrick/beware-of-fake-job-offers-my-encounter-with-a-scammer-nf9</link>
      <guid>https://dev.to/davidchedrick/beware-of-fake-job-offers-my-encounter-with-a-scammer-nf9</guid>
      <description>&lt;h4&gt;
  
  
  TL;DR
&lt;/h4&gt;

&lt;p&gt;A scammer will email a job seeker trying to set up an interview. Check the email address, it will be from gmail or something similar not an official company domain, e.g. firstname.lastname.company @gmail.com. The Interview process will move very fast. The scammer will send a job offer, then send a check to set up your home office. The check is fake and will be declined. The scammer will say you need to purchase items from a preferred vendor. The scammer will say you have to use a pay app to be able to get the equipment in time to start, and as usual, the scammer will be very pushy trying to make you do things quickly.&lt;/p&gt;




&lt;p&gt;Below is my personal story of talking with one of these scammers. I started talking with them because I did happen to apply to the company they were impersonating. Luckily I deal with scammers all the time and noticed red flags before giving them money. &lt;/p&gt;

&lt;p&gt;I have talked to others that have had the same scam run on them. The scammers will change details, and company names, and sometimes they will take longer with the scam but it is the same basic setup.&lt;/p&gt;




&lt;p&gt;This blog is a cautionary tale so others don’t fall victim. &lt;/p&gt;

&lt;p&gt;Below is how the scam played out with me. The names in quotes are the actual names the scammers used while talking with me.&lt;/p&gt;




&lt;p&gt;This is how it all went down:&lt;/p&gt;

&lt;h3&gt;
  
  
  Monday ~10 am:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
I receive an email from “Donald” at “Intelletec”. The email states that they have reviewed my application and want to set up a time for an interview. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nice! Sounds good. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
I double check my Huntr app and see I applied to Intelletec for a Software Engineer position about two weeks ago. So I set up a call with “Donald” for the following Day.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Tuesday ~11 am:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
I have my interview with “Donald”. Despite some initial nerves, everything seemed normal and we went into a standard conversation about my experience and their tech stack. Donald seemed seasoned and well-versed in the technologies. We talked about the company culture, and the role itself. At the end “Donald” said that he thought I could be a good fit and said the next step would be a technical test and to answer some behavior questions. “Donald,” said I would receive an email where I could set up a time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Tuesday ~4 pm:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
I receive the email “Donald” spoke of, and I was able to set up my next interview for the next morning. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this process, this was the first time I thought. “Uh weird…”, none of these companies move this fast. Usually, I have to wait a week to even hear anything about the next interview, especially to set up something the next day. But whatever, maybe this company just has their hiring practice down. &lt;/p&gt;

&lt;h3&gt;
  
  
  Wednesday ~11 am:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
I get on a call with the “Technical Team”, and [don’t remember his “name”] tells me that he is having problems with zoom and that we will just do it over the phone. He asks me to open up Replit and he would ask me Data Structure and Algorythm-style questions and I would talk my way through the problem over the phone. We did three of those questions. After the questions, he said I will shortly receive an email from HR with the behavior portion. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This was an odd experience but still relatively normal.&lt;/p&gt;

&lt;h3&gt;
  
  
  Wednesday ~ 12 pm:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
The email from “HR” comes in. It is a list of standard behavior-type questions. Ones like “Tell me about a time when you had to solve a particularly challenging problem.” and “Give an example of how you've collaborated with cross-functional teams to deliver a project.” All were reasonable questions. I have to answer the questions and email them back.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Thursday ~ 1 pm:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
I received an email from “HR” saying they liked all my answers and that the “Technical team” agreed. The email stated that I was in consideration for the position and they would get back to me when they reviewed all other candidates. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Okay, now things definitely seem off. This moved really fast. But still, this is my first job in tech so I don’t know what to expect. &lt;/p&gt;

&lt;h3&gt;
  
  
  Friday ~ 4 pm:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
I receive an offer letter from “Intelletec”. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That was way too quick, okay, now I am really second-guessing the validity of this offer. Plus, I only talked to two people over the phone and never even on video.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
The email states that if I am interested in the position I should review the documents and sign and send them back by Monday afternoon. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At this point, I decided to just go along with it, and see what happens, at least I’ll have a fun story and at best I wasted a scammer's time. And who knows, maybe I am wrong and I have a job. &lt;/p&gt;

&lt;p&gt;One thing I have to give to the scammers, the offer letter was very well done. They put time into that fake letter.&lt;/p&gt;

&lt;h3&gt;
  
  
  Monday ~ 7 am
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
“Donald” doesn’t waste any time, he is texting me now. Tells me that if I am accepting the job I should send the papers back soon. He really wants me to set it up in time for the next project. I send the papers back right away. 
Shortly after I receive a text from “Paul” from HR. He tells me that he needs to get me set up with my home office. He says that I have to use their equipment that would be supplied by a “preferred vendor” and that I would receive a check for $6000 to pay the vendor.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Huh? Why wouldn’t they just pay the vendor and have it shipped to me? Very strange, doesn't seem legit. I’ll ask “Paul”.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
“Paul” tells me a story about how they used to just send equipment to employees, but too many people tried to scam them and say they never received the equipment, so now it's on the employee to order the equipment with the stipend check.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Okay, “Paul”, sure.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
I tell “Paul” that “Donald” is in a hurry for me to get started so I should just go to Best Buy and get the equipment so I can start right away.
“Paul” tells me that I can’t. It must be through the “preferred vendor” so that they know I have the correct equipment. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Monday ~ 11 am:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
I get an email from “HR” with a personal check attached. The email says that the check is from a “trusted partner” of theirs. The email goes on that the check has been certified by the “trusted partner” so it clears the bank the same day.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lol, now a “trusted partner” is involved.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
The email continues, I must deposit the check by mobile, and I must screenshot the deposit and send it back to them so they know the process is underway.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Okay, whatever. I have fraud protection so I don’t have to pay for bounced checks. Let's do this.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Obviously, the check is automatically declined and flagged as fraudulent. An alert pops up on my banking app. I screenshot it and send it to “Paul”
“Paul” is “shocked” to see the check is declined. It was even certified! Paul says it must be my bank flagging it because I never cashed a check so big.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Um… did “Paul” just neg me?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
“Paul” will have to get back to me, to see what we can do.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Monday ~ 1 pm:
&lt;/h3&gt;

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

“Donald” is texting again. Tells me he heard from “Paul” what happened. “Donald,” says not to worry, he has seen this before. He says that the bank is just delaying the funds, but it will clear, probably in three days. But “Donald” is worried that this will delay the project. We really need to get that equipment to me. 
“Donald” has an idea! The only thing that I need to get started in the first week is the computer. “Donald,” says the computer is only $2000. “Donald” wants to know if I could raise the funds by the end of the day to pay for it myself and then just keep the $2000 from the stipend check once it clears.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Wait… did “Donald” just say “can you raise the funds”? Who raises funds? This is America, I am already in crippling dept what's another $2000 on the card.&lt;/p&gt;

&lt;p&gt;I am definitely not going to do that, but let's play along with “Donald”.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
I tell “Donald” that I can definitely pay for the computer, I will just use my credit card. “Donald” says he doesn’t know if that would work, he will ask the “preferred vendor manager” if it is okay that I put it on my credit card.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why wouldn’t a company take a credit card? Seems suspicious. Oh, and shouldn’t this “preferred vendor” have some sort of website I could see? How am I supposed to buy the equipment anyways? Seems like I was never meant to buy the equipment. &lt;/p&gt;

&lt;h3&gt;
  
  
  Monday ~ 3 pm:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
“Donald” is back and he says the “preferred vendor manager” can not take a credit card. Credit cards take too long to clear the funds. But he has a new idea! He can take Cash App!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;OMG, did he really? At least he didn’t ask for a Visa gift card. &lt;/p&gt;

&lt;p&gt;I knew it was a scam for a bit now, but that one was the proof. Time to go talk to the real Intelletec.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
I tell “Donald” that I have to download the app and get back to him.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Monday ~ 6 pm:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
I look up the management of the real Intelletec. I reach out to Sally [not her real name] and ask if she knows that scammers are impersonating their company. She replies back pretty quickly. 
Sally is aware of the scammers and thanks me for reaching out to inform them. I tell her that I have a lot of information on them: multiple emails, phone numbers, an offer letter, a check, and I saved all the conversations. I offer to give Sally whatever she needs to help take the scammers down.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When copying the emails, I looked at the full email address for the first time. “Donalds” email was Donald.Fred.Intelletec @gmail.com and “HR” was HR.Intelletec &lt;a class="mentioned-user" href="https://dev.to/mail"&gt;@mail&lt;/a&gt;.com. &lt;br&gt;
Oh… no…. This should have been a huge red flag. Now I check every email address from anyone I don’t know.&lt;/p&gt;

&lt;h3&gt;
  
  
  Monday ~ 9 pm:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
“Donald” reaches back on text and said the “preferred vendor manager” is waiting to place the order, but it needs to be soon to make the deadline.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What a nice “preferred vendor manager”, willing to place my order at 9 pm.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
I tell “Donald” that I reached out to Sally to see what she thought and she said it was best to wait for the check to clear.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note, Sally did not say this, I am just messing with the scammers at this point.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
“Donald” asked who Sally was. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;How does he not know the head of HR? &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
I tell “Donald” Sally is the head of HR, and ask how come he doesn’t know her? I tell “Donald” he better talk to “Paul”.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This was the last communication I had with the scammers. I suppose they realized I was just wasting their time.&lt;/p&gt;




&lt;p&gt;Stay aware, stay safe.&lt;/p&gt;




&lt;p&gt;❤️❤️❤️&lt;/p&gt;

&lt;p&gt;Follow me on &lt;a href="https://www.linkedin.com/in/davidchedrick/"&gt;LinkedIn &lt;/a&gt;for all the updates and future blog posts&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>career</category>
      <category>interview</category>
      <category>scam</category>
    </item>
    <item>
      <title>Closing a Knowledge Gap: CSS Naming Conventions - BEM</title>
      <dc:creator>David Chedrick</dc:creator>
      <pubDate>Sat, 18 Feb 2023 19:24:17 +0000</pubDate>
      <link>https://dev.to/davidchedrick/closing-a-knowledge-gap-css-naming-conventions-bem-3adb</link>
      <guid>https://dev.to/davidchedrick/closing-a-knowledge-gap-css-naming-conventions-bem-3adb</guid>
      <description>&lt;p&gt;When I was learning CSS I was always just naming at random I might have been &lt;code&gt;.navBar&lt;/code&gt; or &lt;code&gt;.nav-bar&lt;/code&gt; or &lt;code&gt;.navarea&lt;/code&gt;. I was just all over the place, it lead to many frustrating days of hunting down why my CSS wasn't working and the answer was usually in my HTML I had  &lt;code&gt;class="navBar"&lt;/code&gt; and my CSS is was trying &lt;code&gt;.nav-bar{}&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  BEM:
&lt;/h2&gt;

&lt;p&gt;BEM stands for "Block Element Modifier".&lt;/p&gt;

&lt;p&gt;BEM is one of the most widely used CSS naming conventions, and it is often used in conjunction with JavaScript frameworks like React. BEM's approach of using descriptive class names that describe the purpose of each element can make it easier to work with CSS in a component-based architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  Core components of BEM:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Blocks: Blocks are standalone components that can be reused throughout a website. They represent larger, meaningful sections of a page, such as a header, footer, or navigation menu.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Elements: Elements are parts of a block and cannot exist outside of their parent block. They represent smaller, functional parts of a block, such as a button or a list item.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Modifiers: Modifiers are used to modify the appearance or behavior of a block or element. They can be used to create variations of a block or element, such as a different color, size, or state.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Syntax
&lt;/h2&gt;

&lt;p&gt;BEM class names are typically structured using the following syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.block {}
.block__element {}
.block--modifier {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example, if you had a block representing a navigation menu, you might use the following class names:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.nav {}
.nav__item {}
.nav__item--active {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This structure helps to create clear and consistent class names that are easy to read and understand. BEM is often used in conjunction with JavaScript frameworks like React, as it can help to create more organized and maintainable components.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Code Example
&lt;/h2&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;nav&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"nav"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ul&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"nav__list"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"nav__item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"nav__link--active"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Home&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"nav__item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"nav__link"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;About&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"nav__item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"nav__link nav__link"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Services&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"nav__item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"nav__link"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Contact&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/nav&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;.nav&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50px&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="nb"&gt;center&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="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;lightblue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.nav__list&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;list-style&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;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&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="nl"&gt;padding&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="nc"&gt;.nav__item&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;margin&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="nl"&gt;padding&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="nc"&gt;.nav__link&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;text-decoration&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;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&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;span class="nc"&gt;.nav__link--active&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="no"&gt;green&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;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl77nl35ccxtmz5nypavg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl77nl35ccxtmz5nypavg.png" alt="Nav with CSS" width="800" height="40"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Further Reading:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://getbem.com/" rel="noopener noreferrer"&gt;getbem.com/&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;❤️❤️❤️&lt;/p&gt;

&lt;p&gt;Follow me on &lt;a href="https://www.linkedin.com/in/davidchedrick/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; for all the updates and future blog posts&lt;/p&gt;

&lt;h3&gt;
  
  
  Other blogs in this series:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://dev.to/davidchedrick/closing-a-knowledge-gap-best-practices-for-writing-git-commit-messages-5c8l"&gt;&lt;strong&gt;Closing a Knowledge Gap: Best Practices for Writing Git Commit Messages&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vibecoding</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Closing a Knowledge Gap: Best Practices for Writing Git Commit Messages</title>
      <dc:creator>David Chedrick</dc:creator>
      <pubDate>Wed, 15 Feb 2023 19:41:42 +0000</pubDate>
      <link>https://dev.to/davidchedrick/closing-a-knowledge-gap-best-practices-for-writing-git-commit-messages-5c8l</link>
      <guid>https://dev.to/davidchedrick/closing-a-knowledge-gap-best-practices-for-writing-git-commit-messages-5c8l</guid>
      <description>&lt;p&gt;When I was learning git there was never much emphasis on commit messaging. &lt;/p&gt;

&lt;p&gt;When it was time to push to GitHub it was always something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .
git commit -m “fixed nav bar”
git push
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That was fine, for a beginner that was working alone and never going back to old commits. &lt;/p&gt;

&lt;p&gt;But just like writing clean code you want to write clean commit messages, you want to be able to clearly and easily read your old messages, and some other person working on the same project should be able to read your commits and know what changed and why.&lt;/p&gt;

&lt;p&gt;Go back and look at your Git commit history and see if you struggle to understand what changes were made, and why they were made?  Poorly written or inconsistent commit messages can make it difficult to understand the history of a codebase, track down bugs, or collaborate effectively with other developers.&lt;/p&gt;

&lt;p&gt;One way to address this issue is by using consistent and descriptive commit message conventions. By following a set of agreed-upon conventions, developers can make it easier to navigate the commit history, understand the purpose of each change, and track issues or bugs related to specific commits.&lt;/p&gt;

&lt;p&gt;Let’s explore the importance of good commit message conventions, discuss some common conventions and best practices, and provide examples of effective commit messages&lt;/p&gt;

&lt;h2&gt;
  
  
  Most common best practices:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use keywords in the subject line of the commit message, "fix", "add", "update", etc., to clearly convey the intent of the commit.&lt;/li&gt;
&lt;li&gt;Keep the subject line short 50 characters or less, to provide a clear and concise summary of the change.&lt;/li&gt;
&lt;li&gt;Add a more detailed description in the body of the commit message, explaining what the change does and why it was necessary.&lt;/li&gt;
&lt;li&gt;Use the body to describe any side effects, gotchas, or dependencies of the change, to help other developers understand how the change fits into the larger codebase.&lt;/li&gt;
&lt;li&gt;If the commit is related to an issue or bug, reference the issue or bug number in the commit message, "Closes #1234".&lt;/li&gt;
&lt;li&gt;Use consistent conventions for formatting and style, such as capitalization, punctuation, and line breaks, to make the commit history easier to read and understand.&lt;/li&gt;
&lt;li&gt;Break up large changes into smaller, atomic commits that can be more easily reviewed and understood by other developers.&lt;/li&gt;
&lt;li&gt;Use the &lt;code&gt;-amend&lt;/code&gt; option to update a commit message that hasn't been pushed to the remote repository yet, rather than creating a new commit with an updated message.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Keywords in the Subject Line:
&lt;/h2&gt;

&lt;p&gt;With git commit messages you can use keywords that can be used to help categorize and organize commits. &lt;/p&gt;

&lt;p&gt;By using these keywords in Git commit messages, it becomes easier to identify the purpose of each commit, and it helps keep the commit history organized and easy to navigate. Also, GitHub can use these keywords to automatically generate useful information, such as release notes or change logs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Commonly used Git message keywords:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;feat&lt;/code&gt;&lt;/strong&gt;: A new feature or functionality has been added to the codebase.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;fix&lt;/code&gt;&lt;/strong&gt;: A bug or issue has been fixed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;refactor&lt;/code&gt;&lt;/strong&gt;: The code has been refactored to improve performance, readability, or maintainability.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;docs&lt;/code&gt;&lt;/strong&gt;: Documentation changes have been made, such as updating README files or inline comments.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;test&lt;/code&gt;&lt;/strong&gt;: Changes have been made to the test suite, such as adding or updating tests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;style&lt;/code&gt;&lt;/strong&gt;: Changes have been made to the code style or formatting, such as adding or removing whitespace or changing variable names.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;chore&lt;/code&gt;&lt;/strong&gt;: Miscellaneous changes that do not fit into the above categories, such as updating build scripts or dependencies.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By using these keywords in Git commit messages, it becomes easier to identify the purpose of each commit, and it helps keep the commit history organized and easy to navigate. Additionally, some Git hosting platforms, such as GitHub, can use these keywords to automatically generate useful information, such as release notes or change logs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Aside: Release notes and change logs?
&lt;/h3&gt;

&lt;p&gt;Release notes and change logs are documents that provide a summary of changes made to a software product. &lt;/p&gt;

&lt;p&gt;A release note is typically a brief summary of the changes in a particular release or version of the software. It may include a list of new features, bug fixes, improvements, or known issues. Release notes can be written in a more informal style and are often used to announce a new release or update to the software.&lt;/p&gt;

&lt;p&gt;A change log is a more detailed and structured document that provides a comprehensive list of changes made to the software over time. It may include information on the release date, version number, author of the change, a brief summary of the change, and any other relevant details. Change logs are often organized chronologically, with the most recent changes listed first.&lt;/p&gt;

&lt;p&gt;Release notes and change logs are a whole other topic, but here are some links if you want to look into the subject now:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes" rel="noopener noreferrer"&gt;Automatically generated release notes - GitHub Docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/github-changelog-generator/github-changelog-generator" rel="noopener noreferrer"&gt;changelog-generator&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Making a Commit
&lt;/h2&gt;

&lt;p&gt;Okay, back to our commit message!&lt;/p&gt;

&lt;p&gt;This time make some changes to your code and save.&lt;/p&gt;

&lt;p&gt;Do git add, but this time when committing do not add the -m&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;depending on what editor you are using, this will appear in a file or in the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch main
# Your branch is up to date with 'origin/main'.
#
# Changes to be committed:
#       modified:   README.md

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;above those # you want to add your message, in this styling:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;type&amp;gt;[optional scope]: &amp;lt;description&amp;gt;

[optional body]

[optional footer(s)]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Fix: CSS in nav bar fix Adjust nav bar styling for small screens

The nav bar was not displaying correctly on small screens due to a styling issue.
This commit addresses the issue by adjusting the CSS to ensure that the nav bar 
displays correctly on screens of all sizes

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch main
# Your branch is ahead of 'origin/main' by 1 commit.
#   (use "git push" to publish your local commits)
#
# Changes to be committed:
#       modified:   README.md
#
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are working in a text file just save the file and then &lt;code&gt;git push&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you are working in the terminal, save by typing &lt;code&gt;:wq&lt;/code&gt; then &lt;code&gt;git push&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Also if you are committing without a lot of detail in the body you can commit inline in the terminal with a double -m flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit -m &amp;lt;title&amp;gt; -m &amp;lt;detailed description&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit -m 'Fix css in nav bar fix Adjust nav bar styling for small screens' -m 'The nav bar was not displaying correctly on small screens due to a styling issue. This commit addresses the issue by adjusting the CSS to ensure that the nav bar displays correctly on screens of all sizes'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Further Reading: Pro Git and Conventional Commits
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://git-scm.com/book/en/v2" rel="noopener noreferrer"&gt;Pro Git Book&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.conventionalcommits.org/en/v1.0.0/" rel="noopener noreferrer"&gt;Conventional Commits&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://git-scm.com/" rel="noopener noreferrer"&gt;Git Docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;❤️❤️❤️&lt;/p&gt;

&lt;p&gt;Follow me on &lt;a href="https://www.linkedin.com/in/davidchedrick/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; for all the updates and future blog posts&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>nosql</category>
      <category>database</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Let’s Build A Web App: Pt 1 - Setting up Next.js</title>
      <dc:creator>David Chedrick</dc:creator>
      <pubDate>Sun, 12 Feb 2023 15:02:03 +0000</pubDate>
      <link>https://dev.to/davidchedrick/lets-build-a-web-app-pt-1-setting-up-nextjs-1j7d</link>
      <guid>https://dev.to/davidchedrick/lets-build-a-web-app-pt-1-setting-up-nextjs-1j7d</guid>
      <description>&lt;p&gt;Let's build a JavaScript project, with the React library, using the Next.js Framework!&lt;/p&gt;

&lt;p&gt;Most of the projects I work on are set up with &lt;strong&gt;create-react-app,&lt;/strong&gt; but this time I want to go bigger and use a framework&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Starting this project it is assumed that you are familiar with JavaScript, React, VS code, git, and GitHub.&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can always check out the official Next.js page to learn more:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://nextjs.org/"&gt;Next.js by Vercel - The React Framework&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;• If you don’t have &lt;strong&gt;Node.js&lt;/strong&gt; installed, &lt;a href="https://nodejs.org/en/"&gt;install it from here&lt;/a&gt;. You’ll need Node.js version &lt;strong&gt;10.13&lt;/strong&gt; or later.&lt;/p&gt;

&lt;p&gt;Fantastic! Let’s Start!&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a Next.js app
&lt;/h3&gt;

&lt;p&gt;To create a Next.js app, open your terminal, &lt;code&gt;cd&lt;/code&gt; into the directory you’d like to create the app in, and run the following command:&lt;br&gt;
&lt;code&gt;npx create-next-app bodhi-test&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;!!! To create your own project replace "bodhi-test" with the desired name of your project or just follow along with what I do.&lt;/p&gt;

&lt;p&gt;I am going with bodhi test because I am going to build out a quiz web app.&lt;/p&gt;

&lt;p&gt;My settings from the terminal startup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✔ Would you like to use TypeScript with this project? … **No** / Yes
✔ Would you like to use ESLint with this project? … No / **Yes**
✔ Would you like to use `src/` directory with this project? … **No** / Yes
✔ Would you like to use experimental `app/` directory with this project? … **No** / Yes
✔ What import alias would you like configured? … @/*
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the project is created, navigate to the project directory:&lt;br&gt;
&lt;code&gt;cd bodhi-test&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I am using VS code for this project.&lt;br&gt;
Open the project:&lt;br&gt;
&lt;code&gt;code .&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Open the terminal and run the development server:&lt;br&gt;
&lt;code&gt;npm run dev&lt;/code&gt;&lt;br&gt;
Now you can access your Next.js application at &lt;strong&gt;&lt;code&gt;http://localhost:3000&lt;/code&gt;&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;At &lt;code&gt;http://localhost:3000&lt;/code&gt; should see the auto-generated Next.js page&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--93xGKaqi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wxu8i1877kxyhvz6kgt9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--93xGKaqi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wxu8i1877kxyhvz6kgt9.png" alt="Next Auto Page" width="880" height="862"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Pages in Next.js
&lt;/h2&gt;

&lt;p&gt;In Next.js, a page is a React Component exported from a file in the &lt;code&gt;pages&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;Pages are associated with a route based on their &lt;strong&gt;file name&lt;/strong&gt;. For example, in development:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;pages/index.js&lt;/code&gt; is associated with the &lt;code&gt;/&lt;/code&gt; route.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;pages/posts/cat-post.js&lt;/code&gt; is associated with the &lt;code&gt;/posts/cat-post&lt;/code&gt; route.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We already have the &lt;code&gt;pages/index.js&lt;/code&gt; file, so let’s create &lt;code&gt;pages/posts/cat-post.js&lt;/code&gt; to see how it works.&lt;/p&gt;
&lt;h3&gt;
  
  
  Create a New Page
&lt;/h3&gt;

&lt;p&gt;Create the &lt;code&gt;posts&lt;/code&gt; folder under &lt;code&gt;pages&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Create a file called &lt;code&gt;cat-post.js&lt;/code&gt; inside the &lt;code&gt;posts&lt;/code&gt; directory&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UvUA8zLs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ym45e280tm782q0ccb6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UvUA8zLs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ym45e280tm782q0ccb6.png" alt="folders" width="164" height="485"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add the following code to the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function CatPost() {
    return &amp;lt;h1&amp;gt;Cat Post&amp;lt;/h1&amp;gt;;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Back to index.js&lt;br&gt;
Change the p tag to an h1&lt;br&gt;
Add and import the Link&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Link href="/posts/cat-post"&amp;gt;Cat Post!&amp;lt;/Link&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;index.js should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Head from "next/head";
import { Inter } from "@next/font/google";
import styles from "@/styles/Home.module.css";
import Link from "next/link";

const inter = Inter({ subsets: ["latin"] });

export default function Home() {
    return (
        &amp;lt;&amp;gt;
            &amp;lt;Head&amp;gt;
                &amp;lt;title&amp;gt;Create Next App&amp;lt;/title&amp;gt;
                &amp;lt;meta
                    name="description"
                    content="Generated by create next app"
                /&amp;gt;
                &amp;lt;meta
                    name="viewport"
                    content="width=device-width, initial-scale=1"
                /&amp;gt;
                &amp;lt;link
                    rel="icon"
                    href="/favicon.ico"
                /&amp;gt;
            &amp;lt;/Head&amp;gt;
            &amp;lt;main className={styles.main}&amp;gt;
                &amp;lt;div className={styles.description}&amp;gt;
                    &amp;lt;h1 className={inter.className}&amp;gt;Cat Home Page!&amp;lt;/h1&amp;gt;
                    &amp;lt;Link href="/posts/cat-post"&amp;gt;Cat Post!&amp;lt;/Link&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/main&amp;gt;
        &amp;lt;/&amp;gt;
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ynnKwBfj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p64rqw8c20dhuj3b034p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ynnKwBfj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p64rqw8c20dhuj3b034p.png" alt="Cat Post" width="880" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Back to cat-post.js&lt;br&gt;
Let's add a link to go back home&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Link from "next/link";

export default function CatPost() {
    return (
        &amp;lt;&amp;gt;
            &amp;lt;h1&amp;gt;Cat Post&amp;lt;/h1&amp;gt;
            &amp;lt;h2&amp;gt;
                &amp;lt;Link href="/"&amp;gt;Back Home&amp;lt;/Link&amp;gt;
            &amp;lt;/h2&amp;gt;
        &amp;lt;/&amp;gt;
    );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WHLT7mzR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9tjevodjdsf52ds2034u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WHLT7mzR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9tjevodjdsf52ds2034u.png" alt="Cat Links" width="513" height="303"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click back and forth to make sure the Links are working.&lt;/p&gt;

&lt;p&gt;Time to push it up to GitHub.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .

git commit -m "added first post”

git push
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;❤️❤️❤️&lt;/p&gt;

&lt;p&gt;Try and and more Pages and Links. Play with it and explore.&lt;/p&gt;

&lt;p&gt;This is part 1 of a series where we will be building out a full stack web application. We will go step by step in the process. Sometimes we will explore different technologies, and sometimes we will dive deeper into a subject. It is all about learning by doing. &lt;/p&gt;

&lt;p&gt;Follow me on &lt;a href="https://www.linkedin.com/in/davidchedrick/"&gt;LinkedIn &lt;/a&gt;for all the updates and future blog posts&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>nextjs</category>
      <category>buildinginpublic</category>
      <category>react</category>
    </item>
    <item>
      <title>Talking About Linked List Traversal in JavaScript</title>
      <dc:creator>David Chedrick</dc:creator>
      <pubDate>Thu, 09 Feb 2023 17:12:22 +0000</pubDate>
      <link>https://dev.to/davidchedrick/talking-about-linked-list-traversal-in-javascript-3ppa</link>
      <guid>https://dev.to/davidchedrick/talking-about-linked-list-traversal-in-javascript-3ppa</guid>
      <description>&lt;p&gt;We practice coding data structures regularly. However, how often do we talk out loud about what the code is doing? I realized this was an area I was lacking in when I was asked to explain a Linked List traversal without coding it. I have wrote some form of the code block below many times, this time I am going to talk about what I am doing in the code block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Node {
  constructor(data, next = null) {
    this.data = data;
    this.next = next;
  }
}

class LinkedList {
  constructor() {
    this.head = null;
  }

  traverse() {
    let currentNode = this.head;
    while (currentNode) {
      console.log(currentNode.data);
      currentNode = currentNode.next;
    }
  }
}

const linkedList = new LinkedList();
linkedList.head = new Node(1, new Node(2, new Node(3, new Node(4))));

linkedList.traverse(); 
// output -&amp;gt;  1 2 3 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Traversing a Linked List in JavaScript Without Using Code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A linked list is a data structure where each element is linked to the next element in the list. In this post, we will explore how to traverse a linked list without using code. This will help us understand the concepts and logic behind linked list traversal and help us write and explain our own code later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Understanding the Structure of a Linked List&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A linked list is made up of nodes. Each node in a linked list has two parts: the data and the pointer. The data part stores the actual value of the node and the pointer points to the next node in the list. The last node in the linked list has a pointer that points to null, indicating the end of the list.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;What is a Linked List Traversal?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Linked list traversal is the process of visiting each node in the linked list and processing its data. The traversal starts from the first node and ends at the last node.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;How to Traverse a Linked List?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To traverse a linked list, you need to start from the first node and follow the pointers until you reach the end of the list. The steps are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a variable, let's call it "currentNode," to keep track of the current node that you are processing. Set its value to the first node in the list.&lt;/li&gt;
&lt;li&gt;Write a loop that continues until the "currentNode" is equal to null.&lt;/li&gt;
&lt;li&gt;In the loop, process the data of the current node.&lt;/li&gt;
&lt;li&gt;Move to the next node by updating the "currentNode" to be equal to the next node, which is stored in the pointer of the current node.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By following these steps, you will visit each node in the linked list and process its data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Linked list traversal is the process of visiting each node in a linked list and processing its data. To traverse a linked list, you start from the first node and follow the pointers until you reach the end of the list.&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>career</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Creating a Rails as API project pt 1: Set Up</title>
      <dc:creator>David Chedrick</dc:creator>
      <pubDate>Sun, 12 Jun 2022 21:42:05 +0000</pubDate>
      <link>https://dev.to/davidchedrick/creating-a-rails-as-api-project-pt-1-set-up-5a53</link>
      <guid>https://dev.to/davidchedrick/creating-a-rails-as-api-project-pt-1-set-up-5a53</guid>
      <description>&lt;p&gt;Over the next few blogs we will be building a Rails project. We will use Rails as an API. Eventually we will use it as the end point for a React project.&lt;/p&gt;

&lt;p&gt;For this you will need Ruby, RubyGems, and Bundler installed on your system. I will be using &lt;a href="https://code.visualstudio.com/"&gt;Visual Studio&lt;/a&gt; as my IDE.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.ruby-lang.org/en/documentation/installation/"&gt;Ruby Docs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://rubygems.org/pages/download"&gt;RubyGems Docs&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$gem update --system
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://bundler.io/v1.12/"&gt;Bundler Docs&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$gem install bundler
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Installing Rails
&lt;/h2&gt;

&lt;p&gt;To install the latest version of Rails, run in the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ gem install rails
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the terminal create a new folder for the project and cd into that folder, once inside we can create our Rails project. I will name mine rails-api-project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ rails new rails-api-project --api --skip-javascript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you run that command a lot will load:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tn84cE1I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sdgmlxb885qvw3miiial.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tn84cE1I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sdgmlxb885qvw3miiial.png" alt="code" width="787" height="613"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A lot just happened right there, the main points are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rails generated a new directory with all the code required to build our application&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;bundle install&lt;/code&gt; ran to download all the required gems&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git&lt;/code&gt; was initialized in the newly created directory&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I used the --skip-javascript flag to tell Rails that we won't be using JavaScript for this project. We will use React for all of our JavaScript needs. Using this flag makes the installation faster.&lt;/p&gt;




&lt;h2&gt;
  
  
  Running the Rails Server
&lt;/h2&gt;

&lt;p&gt;To start the Rails server, make sure that you are in the root of the application in the terminal and run this in the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ rails s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--w8HOwDRP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/779zz3bb2ejyp4fzmb62.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--w8HOwDRP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/779zz3bb2ejyp4fzmb62.png" alt="code" width="558" height="292"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets verify that it's working in the browser by navigating to &lt;a href="http://localhost:3000"&gt;localhost 3000&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TuhyMkKx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qjfpqvro34vwev0x8tf5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TuhyMkKx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qjfpqvro34vwev0x8tf5.png" alt="Rails url" width="671" height="41"&gt;&lt;/a&gt; &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yUn3JxLv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gfjhj7al5c3cr1nmys0k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yUn3JxLv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gfjhj7al5c3cr1nmys0k.png" alt="Rails page" width="837" height="813"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you click on the image it will take you to the &lt;a href="https://rubyonrails.org/"&gt;Ruby On Rails website&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;Fantastic! We have a Rails application running. It isn't doing much right now so lets get something of our own happening.&lt;/p&gt;


&lt;h2&gt;
  
  
  Creating Routes
&lt;/h2&gt;

&lt;p&gt;Here is what we should see in our IDE. These are all the files that Rails set up for us:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gp5XmmCP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eqnktclnfwoc5ezj2azb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gp5XmmCP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eqnktclnfwoc5ezj2azb.png" alt="IDE" width="741" height="719"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now lets click into the folder &lt;code&gt;config&lt;/code&gt; then the file &lt;code&gt;routes.rb&lt;/code&gt;. We should see:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p2_AmUII--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/errxid5xjs7a0i6uxxtc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p2_AmUII--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/errxid5xjs7a0i6uxxtc.png" alt="code" width="647" height="198"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we need to define a route in our Rails app. A route will tell Rails that when a user makes a request with &lt;em&gt;this&lt;/em&gt; HTTP verb and &lt;em&gt;this&lt;/em&gt; path, run the code in &lt;em&gt;this&lt;/em&gt; controller.&lt;/p&gt;

&lt;p&gt;Lets set up a route to cats&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# config/routes.rb

Rails.application.routes.draw do
  get "/cats", to: "cats#index"
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are telling Rails that when a GET request to the /cats path comes in, run the index method in the CatsController.&lt;/p&gt;




&lt;h2&gt;
  
  
  Setting up a controller
&lt;/h2&gt;

&lt;p&gt;Let's create a controller now. Click on the app folder, then the controllers folder, then create a new file called cats_controller.rb and put the following code inside:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CatsController &amp;lt; ApplicationController

  def index
  end

end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since we are creating an API lets render some JSON.&lt;br&gt;
Lets just write something for now so we know our code is working.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CatsController &amp;lt; ApplicationController

    def index
        render json: { love: "Cutie Cats~!!! &amp;lt;3" }
    end

end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets give it a test and check out &lt;a href="http://localhost:3000/cats"&gt;http://localhost:3000/cats&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--z2zfPwxd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ukvhb8vk914zwn9bbfex.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z2zfPwxd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ukvhb8vk914zwn9bbfex.png" alt="cats url" width="698" height="37"&gt;&lt;/a&gt; &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pWifbcS8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n863id8xibvs8yhpqehd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pWifbcS8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n863id8xibvs8yhpqehd.png" alt="cats json" width="880" height="81"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If your JSON doesn't look pretty in the browser I recommend the Chrome extension &lt;a href="https://chrome.google.com/webstore/detail/json-formatter/bcjindcccaagfpapjjmafapmmgkkhgoa?hl=en"&gt;json-formatter&lt;/a&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Next Time
&lt;/h2&gt;

&lt;p&gt;This was the initial set up of our Rails API.&lt;br&gt;
Next blog we will get into adding Active Record to our Rails application so we can start adding tables and data.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>api</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Ruby: Using active record to update database in terminal</title>
      <dc:creator>David Chedrick</dc:creator>
      <pubDate>Wed, 01 Jun 2022 02:29:58 +0000</pubDate>
      <link>https://dev.to/davidchedrick/ruby-using-active-record-to-update-database-in-terminal-51d5</link>
      <guid>https://dev.to/davidchedrick/ruby-using-active-record-to-update-database-in-terminal-51d5</guid>
      <description>&lt;p&gt;To start off I am assuming you are working in a Ruby project, using Active Record, and have a database up and running.&lt;br&gt;
I am using SQLite for this.&lt;/p&gt;

&lt;p&gt;If you are not using Active Record let me tell you that Active Record is a fantastic tool to handle your database. It can be done right in your terminal without any SQL statements. Plus, Active Record is a Ruby gem so all you need is include it in your Gemfile or use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gem install activerecord
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check out the Active Record &lt;a href="https://guides.rubyonrails.org/active_record_basics.html"&gt;Documents&lt;/a&gt;&lt;br&gt;
To learn how to connect to your database and how to create your tables.&lt;/p&gt;

&lt;p&gt;Todays focus is updating your database with Active Record.&lt;/p&gt;

&lt;p&gt;To start off I already have 3 users in my database:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mONEpc3l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qpl7w8wn6wykpvj61nfm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mONEpc3l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qpl7w8wn6wykpvj61nfm.png" alt="code" width="529" height="211"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We see the user jacque has a password column that is NULL, so lets give them a password.&lt;/p&gt;

&lt;p&gt;I like to use a Rakefile to Pry.start my console.&lt;/p&gt;

&lt;p&gt;Once the pry is running in the terminal I use User.last to view the user jacque.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s6DZnbFt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/34741u18ctwce3vl2iqz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s6DZnbFt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/34741u18ctwce3vl2iqz.png" alt="code" width="622" height="137"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now lets give the user a new password. I will give them the password "cutiecat1"&lt;/p&gt;

&lt;p&gt;In the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user = User.last
user.password = "cutiecat1"
user.save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MH40sdFO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jsg7k4yo1kyu1pg4pcc0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MH40sdFO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jsg7k4yo1kyu1pg4pcc0.png" alt="code" width="620" height="292"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets double check our work.&lt;br&gt;
Refresh the database and see our update!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9sqdzRBw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u66uigb6dkn5ouyr2wre.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9sqdzRBw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u66uigb6dkn5ouyr2wre.png" alt="code" width="541" height="212"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, lets go ahead and add a new user named Bob.&lt;/p&gt;

&lt;p&gt;In the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User.create(username: "Bob", password: "pass1234")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EmbXFUKd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ya0nevx59rd404ax4mqd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EmbXFUKd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ya0nevx59rd404ax4mqd.png" alt="code" width="622" height="156"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Looks like it worked! Lets check with typing in the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; User.last
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A8El4UZt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aa67z8i5enesa970f2bf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A8El4UZt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aa67z8i5enesa970f2bf.png" alt="code" width="618" height="72"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Looks good in the terminal, now lets refresh and check our database.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bLvJ03bj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hutk57xteee1rsf2pqid.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bLvJ03bj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hutk57xteee1rsf2pqid.png" alt="code" width="260" height="179"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now what if Bob wants to be called "Bobby".&lt;br&gt;
Back in the terminal we write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bob = User.last
bob.update(:username =&amp;gt; "Bobby")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S7qkbjAj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5w1x6ek2wkfllsqeaxez.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S7qkbjAj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5w1x6ek2wkfllsqeaxez.png" alt="code" width="624" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Again, lets double check the terminal this time we will just use our variable name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bob
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8Ch1b3N6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/14j8cp2dezlwu65cq4id.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8Ch1b3N6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/14j8cp2dezlwu65cq4id.png" alt="code" width="570" height="53"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And refresh the database:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--e1nFv69l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/93nen8x3akuu5vpilh72.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--e1nFv69l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/93nen8x3akuu5vpilh72.png" alt="code" width="244" height="166"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Looks good, the database is updated.&lt;/p&gt;

&lt;p&gt;Did you notice that I updated Bob's username slightly different that how I updated jacque's password?&lt;/p&gt;

&lt;p&gt;Lets update Bob's name one more time to "Rob", but with the first syntax.&lt;br&gt;
In the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bob.username = "Rob"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cQo0s-d4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/357cpsl8vkxzy9c2rsp8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cQo0s-d4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/357cpsl8vkxzy9c2rsp8.png" alt="code" width="575" height="105"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Looks like the terminal is showing the name Rob now. But lets check the database&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--e1nFv69l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/93nen8x3akuu5vpilh72.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--e1nFv69l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/93nen8x3akuu5vpilh72.png" alt="code" width="244" height="166"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Still showing "Bobby" not "Rob". &lt;br&gt;
But we can fix that with using .save&lt;br&gt;
Back in the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bob.save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--b2Mr8rvW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/owxxfgqulebhlj9v1ewx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--b2Mr8rvW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/owxxfgqulebhlj9v1ewx.png" alt="code" width="611" height="191"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now lets check the database:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j59_mPsb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ar9hl2kdfh2fxmfpg02l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j59_mPsb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ar9hl2kdfh2fxmfpg02l.png" alt="code" width="246" height="170"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Perfect! Our database is updated.&lt;/p&gt;

&lt;p&gt;Lets review those two ways to update.&lt;/p&gt;

&lt;p&gt;bob.update(:username =&amp;gt; "Bobby")&lt;/p&gt;

&lt;p&gt;or&lt;/p&gt;

&lt;p&gt;bob.username = "Rob"&lt;br&gt;
bob.save&lt;/p&gt;

&lt;p&gt;Now lets delete Bob with .destroy&lt;br&gt;
In the terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bob.destroy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rUuZC-bP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mhrq9nbs1k976mpkxv7y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rUuZC-bP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mhrq9nbs1k976mpkxv7y.png" alt="code" width="614" height="188"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And Bob is now gone:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2sHsk88z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8y0ha80vejnc03aivvtt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2sHsk88z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8y0ha80vejnc03aivvtt.png" alt="code" width="250" height="138"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Using Styled Components in React</title>
      <dc:creator>David Chedrick</dc:creator>
      <pubDate>Sun, 13 Feb 2022 02:20:25 +0000</pubDate>
      <link>https://dev.to/davidchedrick/using-styled-components-in-react-2o87</link>
      <guid>https://dev.to/davidchedrick/using-styled-components-in-react-2o87</guid>
      <description>&lt;p&gt;&lt;strong&gt;Overview&lt;/strong&gt;&lt;br&gt;
Today we are going to work with some CSS and make custom styled components for our React project. So we are going to assume you already have your React app set up and running and you are ready to start making it super pretty.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Styled-Components:&lt;/strong&gt;&lt;br&gt;
Styled Components is a CSS-in-JavaScript tool you can use in React to write and manage your CSS.&lt;br&gt;
You get to keep everything organized by writing your CSS into your component so you do not have to create another .css file. &lt;/p&gt;

&lt;p&gt;Styled-Components makes it very easy to find and edit your CSS code. No more having to scroll through a long style sheet to find the code you need to edit.&lt;/p&gt;

&lt;p&gt;You can style your entire project with Styled Components or you can use it along side libraries like Bootstrap or Material UI. I personally enjoy combining Styled Components with Bootstrap and React Bootstrap. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installing styled-components:&lt;/strong&gt;&lt;br&gt;
To use styled-components you first need to install it into your project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# with npm
npm install --save styled-components

# with yarn
yarn add styled-components
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At the top every file where you use styled-components, you will need to add this import:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import styled from 'styled-components';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This Example will have a very basic set up.&lt;br&gt;
Two divs, one unstyled and one styled.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import styled from 'styled-components';

function App(){
    return(
      &amp;lt;&amp;gt;
        &amp;lt;div&amp;gt;
          Unstyled Div
        &amp;lt;/div&amp;gt;
        &amp;lt;div&amp;gt;
          Styled Div
        &amp;lt;/div&amp;gt;
      &amp;lt;/&amp;gt;
    )
  }

  export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fah8lmz5cbp0arqhlnb6m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fah8lmz5cbp0arqhlnb6m.png" alt="Page with no style"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;This is the basic syntax to set up your Styled Component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const RedDiv = styled.div ``
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets take a deeper look into that line:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;First declare the name with a const. &lt;br&gt;
I chose the name RedDiv, but you can choose whatever &lt;br&gt;
name you like. Keep it simple and to the point so it is &lt;br&gt;
understandable and reusable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The _styled _ gives us access to the styled-components functionality.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The .div after styled anchors the HTML element &lt;em&gt;div&lt;/em&gt;. &lt;br&gt;
When declaring a Styled Component, any HTML element can be &lt;br&gt;
used: div, h1, a, section, span, etc...&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The actual styling goes between the two back ticks and is written just like CSS syntax. Let's make the font red.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const RedDiv = styled.div `
    color: red;
  `
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next step is to change the name of whichever div you want styled. Here we are going to change the name of our second div to RedDiv.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import styled from 'styled-components';

function App(){
    return(
      &amp;lt;&amp;gt;
        &amp;lt;div&amp;gt;
          Unstyled Div
        &amp;lt;/div&amp;gt;
        &amp;lt;RedDiv&amp;gt;
          Styled Div
        &amp;lt;/RedDiv&amp;gt;
      &amp;lt;/&amp;gt;
    )
  }

const RedDiv = styled.div `
    color: red;
  `

 export default App;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzhuksb0cpewspqsyz9lt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzhuksb0cpewspqsyz9lt.png" alt="One unstyled, one red"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;The styled component is reusable so let's add a second RedDiv.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import styled from 'styled-components';

function App(){
    return(
      &amp;lt;&amp;gt;
        &amp;lt;div&amp;gt;
          Unstyled Div
        &amp;lt;/div&amp;gt;
        &amp;lt;RedDiv&amp;gt;
          Styled Div
        &amp;lt;/RedDiv&amp;gt;
        &amp;lt;RedDiv&amp;gt;
          Second Styled Div
        &amp;lt;/RedDiv&amp;gt;
      &amp;lt;/&amp;gt;
    )
  }

const RedDiv = styled.div `
    color: red;
  `
export default App;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8rvq68tybhcju89i07bq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8rvq68tybhcju89i07bq.png" alt="One unstyled, two red"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;We can set up even more styled components.&lt;br&gt;
Let's create a third styled component but make it blue, bold, and italic instead of red.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import styled from 'styled-components';

function App(){
    return(
      &amp;lt;&amp;gt;
        &amp;lt;div&amp;gt;
          Unstyled Div
        &amp;lt;/div&amp;gt;
        &amp;lt;RedDiv&amp;gt;
          Styled Div
        &amp;lt;/RedDiv&amp;gt;
        &amp;lt;RedDiv&amp;gt;
          Second Styled Div
        &amp;lt;/RedDiv&amp;gt;
        &amp;lt;BlueDiv&amp;gt;
          Third Styled Div
        &amp;lt;/BlueDiv&amp;gt;
      &amp;lt;/&amp;gt;
    )
  }

const RedDiv = styled.div `
    color: red;
  `

const BlueDiv = styled.div `
    color: blue;
    font-weight: bold;
    font-style: italic;
  `

export default App;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvee9b60o0w2j3vje2yim.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvee9b60o0w2j3vje2yim.png" alt="One unstyled, two red, one blue"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;References:&lt;/strong&gt;&lt;br&gt;
Read the official documentation for more advanced topics:&lt;br&gt;
&lt;a href="https://styled-components.com/docs" rel="noopener noreferrer"&gt;https://styled-components.com/docs&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Creating a simple timer and score keeper in JavaScript.</title>
      <dc:creator>David Chedrick</dc:creator>
      <pubDate>Sun, 10 Oct 2021 18:40:31 +0000</pubDate>
      <link>https://dev.to/davidchedrick/creating-a-simple-timer-and-score-keeper-in-javascript-394g</link>
      <guid>https://dev.to/davidchedrick/creating-a-simple-timer-and-score-keeper-in-javascript-394g</guid>
      <description>&lt;p&gt;We are going to focus on creating a simple timer and score keeper using just HTML and JavaScript.&lt;/p&gt;

&lt;p&gt;First we will start with creating our index.html with just basic HTML and our script tag that will connect our index.html and index.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Game&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;script src="index.js" type="text/javascript"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, within the body we will add a div with an ID of "gameDiv". This div will hold the content of our game. Within "gameDiv" we will add two more divs that will hold our Time and Score. Both will contain a span that will hold our counts. These count numbers are what we will be manipulating with our JavaScript. As you see bellow, I named the spans with an ID of "timer" and "score". Remember,all of these ID names are what I chose to call them. You can name them whatever you want, but the name should be something that makes since to you and other people reading your code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;
    &amp;lt;div id="gameDiv"&amp;gt;
        &amp;lt;div&amp;gt;Time: &amp;lt;span id="timer"&amp;gt;10&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt;
        &amp;lt;div&amp;gt;Score: &amp;lt;span id="score"&amp;gt;0&amp;lt;/span&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;script src="index.js" type="text/javascript"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is all we will put in our HTML file. Everything else will be done with JavaScript.&lt;br&gt;
Start with creating a index.js that we already connected to our index.html. &lt;/p&gt;

&lt;p&gt;First we will start with our global variables. &lt;br&gt;
The .querySelector() makes it easier to write our code buy adding our selections into variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const gameDiv= document.querySelector('#gameDiv');
let timer = document.querySelector('#timer');
let score = document.querySelector('#score');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;startCountDown holds our setInterval() method which calls our function countDown, and we will add a 1000 millisecond delay:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let startCountDown = setInterval(countDown, 1000);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Variables timeLeft and totalScore will hold the current values of our timer and score:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let timeLeft = 10;
let totalScore = 0;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next method we will utilize will be .addEventListener()&lt;br&gt;
Once the DOM content is fully loaded it will call our first function renderGame:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.addEventListener('DOMContentLoaded', renderGame())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are into our first function. Inside this function we still have access to our variables set in our global scope, but now we will add some variables that will now only have a function scope and will not be available outside of this function.&lt;br&gt;
First we will create a new DIV using the .createElement() method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function renderGame() {
    const gameCard = document.createElement('div');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we will create a button. &lt;br&gt;
Now that we stored that created button into the variable click we can now type click to access our button.&lt;br&gt;
Now we add in some text for our button and then we add on an event listener to our button. Our event listener will be triggered by a click from the mouse and will call on our function pointsClick:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    const click = document.createElement('button');
    click.textContent = 'CLICK FOR POINTS ';
    click.addEventListener('click', pointsClick);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lastly in this function we append our click variable to our gamecard. Then we append our gamecard to our gameDiv:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    gameCard.append(click);
    gameDiv.append(gameCard);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next function is pointsClick. It is called by the previous event listener we added in. Every time the button we created is clicked it triggers the event listener. &lt;br&gt;
First in this function totalScore++ adds one to our score and score.innerText changes our score from a 0 to 1 on our webpage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function pointsClick() {
    totalScore++
    score.innerText = totalScore
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our countDown function was called at the top when we set our variable in global scope for our .setInterval() method. &lt;br&gt;
First timeLeft-- will countdown our timer and timer.innerText will reflect that on our webpage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function countDown(){
    timeLeft--;
    timer.innerText = timeLeft;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once timeLeft hits 0 we need an if statement to let the program know to go to our gameOver function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    if(timeLeft === 0){
        gameOver();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our last function is gameOver(). &lt;br&gt;
First we clearInterval so that our timer stops at 0.&lt;br&gt;
Next, we have to grab that button we created earlier and tell the event listener to stop. Without taking off the event listener we would be able to continue to click for points even after the timer stopped.&lt;br&gt;
Now we want to tell the player that the game is over and display the finial score.&lt;br&gt;
So we create one more element, an h1 that will display our end game text on the screen.&lt;br&gt;
Lastly we append the gameOver variable to our gameDiv.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function gameOver() {
    clearInterval(startCountDown);

    const button = document.querySelector('button')
    button.removeEventListener('click', pointsClick)

    const gameOver = document.createElement('h1');
    gameOver.innerHTML = 'GAME OVER!' + '&amp;lt;br&amp;gt;' + `Total Score: ${totalScore}`;

    gameDiv.append(gameOver);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is all we need to create a timer and score keeper. Try it out for yourself and then add this into a more complicated JavaScript game.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codepen.io/davidchedrick/pen/GRvRBNZ"&gt;Click to see my example code.&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
