<?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: Iszyk</title>
    <description>The latest articles on DEV Community by Iszyk (@iszy).</description>
    <link>https://dev.to/iszy</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3668400%2F7f6f8a90-260a-477d-8b1a-18e12fd4d574.png</url>
      <title>DEV Community: Iszyk</title>
      <link>https://dev.to/iszy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iszy"/>
    <language>en</language>
    <item>
      <title>Building Shopping Cart With Python: What I Learned About Dictionaries, Loops, and Logic</title>
      <dc:creator>Iszyk</dc:creator>
      <pubDate>Tue, 25 Aug 2026 11:00:10 +0000</pubDate>
      <link>https://dev.to/iszy/building-shopping-cart-with-python-what-i-learned-about-dictionaries-loops-and-logic-3l7l</link>
      <guid>https://dev.to/iszy/building-shopping-cart-with-python-what-i-learned-about-dictionaries-loops-and-logic-3l7l</guid>
      <description>&lt;p&gt;I'm continuing my journey of learning Python, and this time I decided to build something a little more practical: a Simple Shopping Cart.&lt;/p&gt;

&lt;p&gt;After learning variables, strings, conditionals, functions, loops, lists, dictionaries, and sets, I wanted to see how I could combine these concepts into one project.&lt;/p&gt;

&lt;p&gt;At first, I thought a shopping cart would be simple:&lt;/p&gt;

&lt;p&gt;Select a product → choose a quantity → calculate the total.&lt;/p&gt;

&lt;p&gt;But while building it, I realized there was much more logic involved.&lt;/p&gt;

&lt;p&gt;Starting With a Dictionary&lt;/p&gt;

&lt;p&gt;The first thing I needed was a way to store my products and their prices.&lt;/p&gt;

&lt;p&gt;A Python dictionary was perfect for this because it stores information as key-value pairs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;products&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Wireless Mouse&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;25.99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Mechanical Keyboard&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;89.99&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bluetooth Headphones&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;120.00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Water Bottle&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;15.50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Backpack&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;45.00&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The product name is the key, while the price is the value.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;products&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Wireless Mouse&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;returns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;span class="mf"&gt;25.99&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This helped me understand dictionaries much better because I wasn't just learning that a dictionary stores key-value pairs. I was actually using one to solve a problem.&lt;/p&gt;

&lt;p&gt;Looping Through the Products&lt;/p&gt;

&lt;p&gt;I used a for loop with .items() to display all the products:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I learned that .items() allows me to get both the key and value while looping through a dictionary.&lt;/p&gt;

&lt;p&gt;So:&lt;/p&gt;

&lt;p&gt;for product, price in products.items():&lt;/p&gt;

&lt;p&gt;basically means:&lt;/p&gt;

&lt;p&gt;For every product and its price in this dictionary...&lt;/p&gt;

&lt;p&gt;This was useful because I needed to display the available products before the customer made a selection.&lt;/p&gt;

&lt;p&gt;Creating the Cart&lt;/p&gt;

&lt;p&gt;Next, I created an empty dictionary:&lt;/p&gt;

&lt;p&gt;cart = {}&lt;/p&gt;

&lt;p&gt;I decided that my cart would store:&lt;/p&gt;

&lt;p&gt;Product → Quantity&lt;/p&gt;

&lt;p&gt;For example:&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="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Wireless Mouse"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Coffee Mug"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&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;This was one of the moments where dictionaries started making more sense to me.&lt;/p&gt;

&lt;p&gt;I wasn't just storing random data. I was creating a structure that represented something from the real world.&lt;/p&gt;

&lt;p&gt;Handling User Input&lt;/p&gt;

&lt;p&gt;The customer needs to select a product and enter how many they want.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;customer_request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;What product would you like to buy? &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;product_quantity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;How many would you like to buy? &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One thing I had to remember was that input() returns a string.&lt;/p&gt;

&lt;p&gt;So when I wanted the quantity to be treated as a number, I needed to convert it using int().&lt;/p&gt;

&lt;p&gt;int(input(...))&lt;/p&gt;

&lt;p&gt;This was another example of how concepts I had previously learned started working together.&lt;/p&gt;

&lt;p&gt;Using a While Loop&lt;/p&gt;

&lt;p&gt;I wanted the customer to be able to continue shopping instead of selecting only one product.&lt;/p&gt;

&lt;p&gt;So I used a while loop:&lt;/p&gt;

&lt;p&gt;while continue_shopping.lower() == "yes":&lt;/p&gt;

&lt;p&gt;The idea was simple:&lt;/p&gt;

&lt;p&gt;Keep asking the customer for products while they want to continue shopping.&lt;/p&gt;

&lt;p&gt;This was a good exercise because I had recently learned loops, and now I was using a loop to control an actual program.&lt;/p&gt;

&lt;p&gt;The Problem of Buying the Same Product Twice&lt;/p&gt;

&lt;p&gt;This was one of the interesting problems I encountered.&lt;/p&gt;

&lt;p&gt;Suppose the customer buys:&lt;/p&gt;

&lt;p&gt;Wireless Mouse → 2&lt;/p&gt;

&lt;p&gt;Then later buys:&lt;/p&gt;

&lt;p&gt;Wireless Mouse → 3&lt;/p&gt;

&lt;p&gt;If I simply did:&lt;/p&gt;

&lt;p&gt;cart[customer_request] = product_quantity&lt;/p&gt;

&lt;p&gt;the second purchase would replace the first one.&lt;/p&gt;

&lt;p&gt;The cart would contain:&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="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Wireless Mouse"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&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="err"&gt;instead&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;of:&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;"Wireless Mouse"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5&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;So I needed to check whether the product already existed in the cart:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;customer_request&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;customer_request&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;product_quantity&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;customer_request&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;product_quantity&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if the customer buys 2 and then another 3, Python adds them together.&lt;/p&gt;

&lt;p&gt;This taught me an important lesson:&lt;/p&gt;

&lt;p&gt;Writing code isn't always about knowing the syntax. Sometimes it's about thinking carefully about how your data should behave.&lt;/p&gt;

&lt;p&gt;Calculating the Total&lt;/p&gt;

&lt;p&gt;After the customer finished shopping, I needed to calculate the total price.&lt;/p&gt;

&lt;p&gt;I started with:&lt;/p&gt;

&lt;p&gt;total = 0&lt;/p&gt;

&lt;p&gt;Then I looped through the cart:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;cart&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;item_total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;
    &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;item_total&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This was where many of the concepts I had learned came together.&lt;/p&gt;

&lt;p&gt;I had the product and quantity from the cart, and I could use the product name to find its price in the products dictionary.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Wireless Mouse
$25.99 × 2 = $51.98

Then:

Coffee Mug
$12.99 × 3 = $38.97

And finally:

$51.98 + $38.97 = $90.95
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also learned the difference between an individual item total and the overall cart total.&lt;/p&gt;

&lt;p&gt;item_total = products[product] * quantity&lt;/p&gt;

&lt;p&gt;represents the cost of one type of product.&lt;/p&gt;

&lt;p&gt;While:&lt;/p&gt;

&lt;p&gt;total += item_total&lt;/p&gt;

&lt;p&gt;keeps adding those individual totals together.&lt;/p&gt;

&lt;p&gt;A Mistake I Made&lt;/p&gt;

&lt;p&gt;One of my mistakes was modifying the original product price while calculating the total.&lt;/p&gt;

&lt;p&gt;I initially tried something like:&lt;/p&gt;

&lt;p&gt;products[product] *= quantity&lt;/p&gt;

&lt;p&gt;This changed the original price inside my products dictionary.&lt;/p&gt;

&lt;p&gt;For example, if the Wireless Mouse originally cost:&lt;/p&gt;

&lt;p&gt;$25.99&lt;/p&gt;

&lt;p&gt;and the customer bought two, it would become:&lt;/p&gt;

&lt;p&gt;$51.98&lt;/p&gt;

&lt;p&gt;inside my product dictionary.&lt;/p&gt;

&lt;p&gt;That wasn't what I wanted.&lt;/p&gt;

&lt;p&gt;I learned that I should calculate the value separately instead:&lt;/p&gt;

&lt;p&gt;item_total = products[product] * quantity&lt;/p&gt;

&lt;p&gt;and then add it to the overall total:&lt;/p&gt;

&lt;p&gt;total += item_total&lt;/p&gt;

&lt;p&gt;This was a simple mistake, but fixing it helped me understand the difference between changing data and using data in a calculation.&lt;/p&gt;

&lt;p&gt;Making Product Search Case-Insensitive&lt;/p&gt;

&lt;p&gt;I also wanted users to be able to enter:&lt;/p&gt;

&lt;p&gt;Wireless Mouse&lt;/p&gt;

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

&lt;p&gt;wireless mouse&lt;/p&gt;

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

&lt;p&gt;WIRELESS MOUSE&lt;/p&gt;

&lt;p&gt;and still find the product.&lt;/p&gt;

&lt;p&gt;I used .lower() to compare the user's input with the product names:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;customer_request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="n"&gt;customer_request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;product&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This allowed me to compare both strings in lowercase while keeping the original product name from the dictionary.&lt;/p&gt;

&lt;p&gt;It was another example of taking something I had learned previously and applying it to a real problem.&lt;/p&gt;

&lt;p&gt;What I Learned From This Project&lt;/p&gt;

&lt;p&gt;This project taught me more than just how to build a shopping cart.&lt;/p&gt;

&lt;p&gt;*Dictionaries are extremely useful&lt;/p&gt;

&lt;p&gt;I understood dictionaries much better after using them in a real project.&lt;/p&gt;

&lt;p&gt;*Loops become more meaningful when you build something&lt;/p&gt;

&lt;p&gt;Instead of simply writing a loop to practice syntax, I was using loops to process actual data.&lt;/p&gt;

&lt;p&gt;*if statements control the logic of a program&lt;/p&gt;

&lt;p&gt;The program constantly needs to make decisions:&lt;/p&gt;

&lt;p&gt;Does this product exist?&lt;br&gt;
Is it already in the cart?&lt;br&gt;
Does the customer want to continue shopping?&lt;/p&gt;

&lt;p&gt;*Bugs are part of learning&lt;/p&gt;

&lt;p&gt;I made several mistakes while building this project.&lt;/p&gt;

&lt;p&gt;But fixing those mistakes helped me understand the concepts better than if everything had worked perfectly on the first try.&lt;/p&gt;

&lt;p&gt;*Small projects show what you actually understand&lt;/p&gt;

&lt;p&gt;I could recognize Python syntax before starting this project.&lt;/p&gt;

&lt;p&gt;But building the shopping cart forced me to think about how the different concepts work together.&lt;/p&gt;

&lt;p&gt;And I think that's where real learning starts.&lt;/p&gt;

&lt;p&gt;What's Next?&lt;/p&gt;

&lt;p&gt;This is another step in my Python learning journey.&lt;/p&gt;

&lt;p&gt;So far, I've built:&lt;/p&gt;

&lt;p&gt;🎯 A Number Guessing Game&lt;/p&gt;

&lt;p&gt;🏧 A Simple ATM&lt;/p&gt;

&lt;p&gt;❓ A Python Quiz Game&lt;/p&gt;

&lt;p&gt;🛒 A Simple Shopping Cart&lt;/p&gt;

&lt;p&gt;I'm still a beginner, but I'm starting to understand something important:&lt;/p&gt;

&lt;p&gt;You don't become better at programming by waiting until you know everything. You become better by building things with what you currently know.&lt;/p&gt;

&lt;p&gt;And that's exactly what I'm going to keep doing.&lt;/p&gt;

&lt;p&gt;One project at a time. 🐍💻&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Learning Python Loops as a Beginner: What I Finally Understood</title>
      <dc:creator>Iszyk</dc:creator>
      <pubDate>Wed, 19 Aug 2026 19:35:44 +0000</pubDate>
      <link>https://dev.to/iszy/learning-python-loops-as-a-beginner-what-i-finally-understood-3n3a</link>
      <guid>https://dev.to/iszy/learning-python-loops-as-a-beginner-what-i-finally-understood-3n3a</guid>
      <description>&lt;p&gt;When I started learning Python, I understood variables, data types, conditionals, and functions. But there was one concept I knew I couldn't avoid for long: &lt;strong&gt;loops&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Loops are one of those programming concepts that seem simple when someone explains them, but actually using them in a project is where things start to make sense.&lt;/p&gt;

&lt;p&gt;After learning and practicing them, I decided to write about what I learned and how I used loops in my first Python projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is a Loop?
&lt;/h2&gt;

&lt;p&gt;A loop allows us to &lt;strong&gt;repeat a block of code multiple times&lt;/strong&gt; without writing the same code over and over again.&lt;/p&gt;

&lt;p&gt;Imagine I wanted Python to print the numbers from 1 to 5.&lt;/p&gt;

&lt;p&gt;Without a loop, I would have to write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That works, but imagine having to print 1 to 1,000.&lt;/p&gt;

&lt;p&gt;That's where loops become useful.&lt;/p&gt;

&lt;p&gt;Instead, I can use a loop to tell Python:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Repeat this action for each number."&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
2
3
4
5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Much cleaner.&lt;/p&gt;




&lt;h2&gt;
  
  
  The &lt;code&gt;for&lt;/code&gt; Loop
&lt;/h2&gt;

&lt;p&gt;The first loop I focused on was the &lt;code&gt;for&lt;/code&gt; loop.&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;for&lt;/code&gt; loop is useful when I want to go through a collection of items or repeat something a specific number of times.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;fruits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Apple&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Banana&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Orange&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;fruit&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;fruits&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fruit&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Python goes through the list one item at a time.&lt;/p&gt;

&lt;p&gt;The output is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Apple
Banana
Orange
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important thing I learned here is that the variable &lt;code&gt;fruit&lt;/code&gt; represents the &lt;strong&gt;current item&lt;/strong&gt; in the list.&lt;/p&gt;

&lt;p&gt;So the loop is essentially doing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;First → fruit = Apple
Second → fruit = Banana
Third → fruit = Orange
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This helped me understand that a loop isn't magic. Python is simply repeating the same instructions while changing the value of the loop variable.&lt;/p&gt;




&lt;h2&gt;
  
  
  Understanding &lt;code&gt;range()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Another important thing I learned was &lt;code&gt;range()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This produces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0
1
2
3
4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One thing that initially confused me was why it stops at &lt;code&gt;4&lt;/code&gt; instead of &lt;code&gt;5&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The reason is that &lt;code&gt;range(5)&lt;/code&gt; starts at &lt;code&gt;0&lt;/code&gt; and stops &lt;strong&gt;before&lt;/strong&gt; &lt;code&gt;5&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can also specify a starting point:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we get:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
2
3
4
5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Understanding this made working with loops much easier.&lt;/p&gt;




&lt;h2&gt;
  
  
  Using Loops With Conditions
&lt;/h2&gt;

&lt;p&gt;Loops become much more powerful when combined with &lt;code&gt;if&lt;/code&gt; statements.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This goes through the numbers from 1 to 5 and only prints the even numbers.&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;This showed me that loops don't just have to repeat the exact same action. I can also make decisions during each repetition.&lt;/p&gt;




&lt;h2&gt;
  
  
  Using &lt;code&gt;enumerate()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;One of the most useful things I learned while building my quiz project was &lt;code&gt;enumerate()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Suppose I have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;questions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;What is Python?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;What is HTML?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;What is CSS?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I can write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;question&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;questions&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output will be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0 What is Python?
1 What is HTML?
2 What is CSS?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;enumerate()&lt;/code&gt; gives me both:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the position of the item (&lt;code&gt;index&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;the actual item (&lt;code&gt;question&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This became particularly useful in my quiz game.&lt;/p&gt;




&lt;h1&gt;
  
  
  Applying Loops: My Python Quiz Game
&lt;/h1&gt;

&lt;p&gt;After learning loops, I wanted to actually use them in a project.&lt;/p&gt;

&lt;p&gt;I built a simple &lt;strong&gt;Python Quiz Game&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The game contains five questions and asks the user to select an answer for each one.&lt;/p&gt;

&lt;p&gt;I stored the questions in a list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;questions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Question 1...&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Question 2...&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Question 3...&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Question 4...&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Question 5...&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And I stored the correct answers in another list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;answers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;B&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;A&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;D&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;B&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;B&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I used &lt;code&gt;enumerate()&lt;/code&gt; to connect each question to its correct answer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;question&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;questions&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;question&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;answer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;What is your answer?: &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;upper&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;answer&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;answers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
        &lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This was one of the moments where loops really started to click for me.&lt;/p&gt;

&lt;p&gt;Instead of writing separate code for Question 1, Question 2, Question 3, and so on, I could write the logic &lt;strong&gt;once&lt;/strong&gt; and let the loop handle all five questions.&lt;/p&gt;




&lt;h2&gt;
  
  
  Keeping Track of the Score
&lt;/h2&gt;

&lt;p&gt;I also learned that I can use a variable outside the loop and modify it inside the loop.&lt;/p&gt;

&lt;p&gt;I started with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then whenever the user answered correctly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After all the questions were completed, I displayed the result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Your score is: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;score&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/5&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This helped me understand how variables can change as a program runs.&lt;/p&gt;




&lt;h1&gt;
  
  
  What I Learned From Loops
&lt;/h1&gt;

&lt;p&gt;Learning loops wasn't just about learning the &lt;code&gt;for&lt;/code&gt; syntax.&lt;/p&gt;

&lt;p&gt;I learned several important programming ideas along the way:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Don't repeat code unnecessarily
&lt;/h3&gt;

&lt;p&gt;If I'm writing the same block of code multiple times, I should ask myself:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Can a loop handle this?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  2. Lists and loops work really well together
&lt;/h3&gt;

&lt;p&gt;A list can hold multiple pieces of information, while a loop can process them one by one.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This combination is something I'll probably use constantly as I continue learning Python.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Indexes are important
&lt;/h3&gt;

&lt;p&gt;Understanding indexes helped me understand how I could connect data from different lists.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;answers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Loops make programs more dynamic
&lt;/h3&gt;

&lt;p&gt;Without loops, my quiz would have required separate code for every question.&lt;/p&gt;

&lt;p&gt;With a loop, the same logic can handle any number of questions.&lt;/p&gt;

&lt;p&gt;That's a much better way to think about programming.&lt;/p&gt;




&lt;h1&gt;
  
  
  What I'm Learning Next
&lt;/h1&gt;

&lt;p&gt;Now that I've finished learning loops and practiced them by building a project, I'm moving on to &lt;strong&gt;dictionaries and sets&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I'm following the approach of learning a concept and then building something with it instead of trying to memorize everything at once.&lt;/p&gt;

&lt;p&gt;My next Python project will be a &lt;strong&gt;Simple Shopping Cart&lt;/strong&gt;, where I'll put these concepts together and start working with dictionaries.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;Loops were one of the concepts I was looking forward to learning because I knew they were fundamental to programming.&lt;/p&gt;

&lt;p&gt;After actually using them in a project, I can see why.&lt;/p&gt;

&lt;p&gt;The biggest lesson for me wasn't simply learning:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It was learning how to look at a problem and recognize:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;"I don't need to write this five times. I can make Python repeat it for me."&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's one of the small moments that makes learning programming feel a lot more rewarding.&lt;/p&gt;

&lt;p&gt;I'm still learning Python, but I'm starting to understand that the best way to learn isn't just reading about a concept.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learn it → practice it → build something with it → make mistakes → fix them → move on.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And that's exactly what I'm doing.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>learning</category>
      <category>python</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Building My First Python Project (ATM): What I Learned From a Simple Project</title>
      <dc:creator>Iszyk</dc:creator>
      <pubDate>Fri, 14 Aug 2026 16:45:33 +0000</pubDate>
      <link>https://dev.to/iszy/building-my-first-python-project-atm-what-i-learned-from-a-simple-project-5963</link>
      <guid>https://dev.to/iszy/building-my-first-python-project-atm-what-i-learned-from-a-simple-project-5963</guid>
      <description>&lt;p&gt;When I started learning Python, I knew the basics: variables, data types, strings, numbers, conditionals, functions, and scope.&lt;br&gt;
But knowing the syntax and actually using it to build something are two different things.&lt;br&gt;
So I decided to build a Simple ATM program using only the concepts I had learned so far.&lt;/p&gt;

&lt;p&gt;The goal wasn't to build a real banking system. It was to take the fundamentals I had learned and put them together into something practical.&lt;br&gt;
And honestly, this small project taught me more than simply reading about Python syntax.&lt;/p&gt;

&lt;p&gt;I wanted the program to have three basic options:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Withdraw
2. Deposit
3. Check Balance

Choose an option: 1

How much do you want to withdraw? 2000

Withdrawal successful!
Your remaining balance is: 8000 CFA
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;1. Starting with Variables&lt;/strong&gt;&lt;br&gt;
The first thing I needed was a starting balance. This looks very simple, but it represents something important: variables allow programs to store information that can change.&lt;br&gt;
The balance can change after a withdrawal or deposit.&lt;br&gt;
For Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;
&lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;2000&lt;/span&gt;
&lt;span class="n"&gt;Now&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; 
&lt;span class="mi"&gt;8000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Getting Input From the User&lt;/strong&gt;&lt;br&gt;
The ATM needs to interact with the user.&lt;br&gt;
I used Python's input() function. One thing I learned here is that input() returns a string.&lt;br&gt;
That's why when asking for a withdrawal amount, I used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;option&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Choose an option: &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;withdrawal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;How much do you want to withdraw? &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Using Conditional Statements&lt;/strong&gt;&lt;br&gt;
The ATM needs to know what the user wants to do.&lt;br&gt;
That's where if, elif, and else come in.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;option&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;1&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Withdraw
&lt;/span&gt;
&lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;option&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;2&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Deposit
&lt;/span&gt;
&lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;option&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;3&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# Check balance
&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Invalid Option!&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This was one of the most important parts of the project.&lt;br&gt;
The program is essentially making decisions:&lt;br&gt;
If the user chooses 1, do this.&lt;br&gt;
If the user chooses 2, do that.&lt;br&gt;
If the user chooses 3, show the balance.&lt;br&gt;
Otherwise, tell them the option is invalid.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Creating Functions&lt;/strong&gt;&lt;br&gt;
Initially, I had most of my logic directly inside the program.&lt;br&gt;
But I wanted to make the code more organized, so I created functions.&lt;br&gt;
For withdrawals and deposits:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;withdraw_money&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;withdrawal&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;withdrawal&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="n"&gt;withdrawal&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;deposit_money&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;deposit&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;deposit&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This taught me that functions allow me to separate different responsibilities in my program. Instead of having all the withdrawal logic mixed with the menu logic, I can put the withdrawal logic inside its own function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Understanding Parameters&lt;/strong&gt;&lt;br&gt;
My withdrawal function has two parameters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;withdraw_money&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;withdrawal&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;balance represents the current account balance.&lt;br&gt;
withdrawal represents the amount the user wants to withdraw.&lt;/p&gt;

&lt;p&gt;When I call the function:&lt;br&gt;
balance, success = withdraw_money(balance, withdrawal)&lt;br&gt;
I'm passing those values into the function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Understanding return&lt;/strong&gt;&lt;br&gt;
This was probably the concept that challenged me the most.&lt;br&gt;
At first, I was returning messages directly from my function:&lt;br&gt;
return "Withdrawal successful!"&lt;br&gt;
But then I realized that this would make my balance variable become a string instead of a number.&lt;br&gt;
For example: balance = withdraw_money(balance, withdrawal) could make balance contain "Withdrawal Successful" instead of 8000. That would obviously cause problems when I wanted to perform another calculation.&lt;/p&gt;

&lt;p&gt;So I changed the function to return the actual balance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;

&lt;span class="n"&gt;OR&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7. Returning Multiple Values&lt;/strong&gt;&lt;br&gt;
This was another new concept for me.&lt;br&gt;
Python allows a function to return multiple values.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;success&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;withdraw_money&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;withdrawal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;So&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;withdrawal&lt;/span&gt; &lt;span class="n"&gt;succeeds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8000&lt;/span&gt;
&lt;span class="n"&gt;success&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;

&lt;span class="n"&gt;And&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="n"&gt;fails&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10000&lt;/span&gt;
&lt;span class="n"&gt;success&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;

&lt;span class="n"&gt;I&lt;/span&gt; &lt;span class="n"&gt;can&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;use&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;boolean&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;success&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Withdrawal successful!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Insufficient funds!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This helped me understand how functions can perform an operation and communicate the result back to the main program.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. My Final ATM Program&lt;/strong&gt;&lt;/p&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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fife3dzkwi8q9uiq6w1a0.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fife3dzkwi8q9uiq6w1a0.png" alt="My Final ATM Program" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This Project Taught Me That&lt;br&gt;
Before building, I had to understand the individual concepts.&lt;br&gt;
But putting them together helped me understand how they work as a system.&lt;/p&gt;

&lt;p&gt;I practiced:&lt;/p&gt;

&lt;p&gt;Variables&lt;br&gt;
Strings&lt;br&gt;
Integers&lt;br&gt;
Type conversion&lt;br&gt;
User input&lt;br&gt;
Arithmetic operators&lt;br&gt;
Conditional statements&lt;br&gt;
Functions&lt;br&gt;
Function parameters&lt;br&gt;
Scope&lt;br&gt;
Return values&lt;br&gt;
Boolean values&lt;br&gt;
Returning multiple values&lt;br&gt;
Basic program structure&lt;/p&gt;

&lt;p&gt;Most importantly, I learned that building projects exposes gaps in your understanding.&lt;br&gt;
There were several moments where I knew the syntax but wasn't sure how to connect everything together.&lt;br&gt;
That's actually one of the reasons I think projects are so important when learning to program.&lt;/p&gt;

&lt;p&gt;You don't just learn:&lt;br&gt;
"What does return mean?"&lt;br&gt;
You learn:&lt;br&gt;
"Why do I need return here?"&lt;br&gt;
And that's a much deeper understanding.&lt;/p&gt;

&lt;p&gt;What's Next?&lt;/p&gt;

&lt;p&gt;This ATM is still very basic.&lt;br&gt;
There are plenty of things I could add later:&lt;/p&gt;

&lt;p&gt;Multiple transactions&lt;br&gt;
PIN authentication&lt;br&gt;
Transaction history&lt;br&gt;
Account numbers&lt;br&gt;
Transfer functionality&lt;br&gt;
Input validation&lt;br&gt;
Error handling&lt;br&gt;
Loops so the ATM doesn't terminate after one operation&lt;br&gt;
Saving account information&lt;/p&gt;

&lt;p&gt;But I intentionally didn't add those features yet.&lt;br&gt;
I'm still building my Python fundamentals, so I'm focusing on understanding one concept at a time.&lt;br&gt;
The next step is to keep building small projects and gradually introduce new concepts.&lt;/p&gt;

&lt;p&gt;Thanks for staying with me till the end&lt;/p&gt;

</description>
      <category>software</category>
      <category>python</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Building a Simple Currency Converter in React with useState and useMemo</title>
      <dc:creator>Iszyk</dc:creator>
      <pubDate>Thu, 13 Aug 2026 15:41:19 +0000</pubDate>
      <link>https://dev.to/iszy/building-a-simple-currency-converter-in-react-with-usestate-and-usememo-1fna</link>
      <guid>https://dev.to/iszy/building-a-simple-currency-converter-in-react-with-usestate-and-usememo-1fna</guid>
      <description>&lt;p&gt;One of the best ways to learn React is by building small, practical projects. A currency converter is an excellent example because it introduces state management, user input handling, calculations, and performance optimization—all in a single application.&lt;/p&gt;

&lt;p&gt;I built a simple currency converter using React that converts from USD to EUR, GBP, and JPY. For simplicity, I used fixed exchange rates instead of calling a live exchange rate API.&lt;/p&gt;

&lt;p&gt;React applications are interactive because they can respond to user actions. The useState hook allows components to remember values between renders.&lt;/p&gt;

&lt;p&gt;For this project, I declared it as thus,&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const [amount, setAmount] = useState(1); &lt;br&gt;
   const [currency, setCurrency] = useState("EUR");&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;The amount stores the value entered.&lt;br&gt;
The setAmount() updates it.&lt;br&gt;
The currency variable stores the selected currency.&lt;br&gt;
The setCurrency() changes the selected currency.&lt;br&gt;
Whenever either value changes, React automatically re-renders the component.&lt;/p&gt;

&lt;p&gt;Now, to calculate the conversion, I stored the exchange rate in an object&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const RATES = &lt;br&gt;
{ &lt;br&gt;
   USD: 1,&lt;br&gt;
   EUR: 0.92,&lt;br&gt;
   GBP: 0.79,&lt;br&gt;
   JPY: 157.3&lt;br&gt;
};&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;The interface contains:&lt;br&gt;
A number input.&lt;br&gt;
A dropdown menu.&lt;br&gt;
A heading displaying the converted amount.&lt;/p&gt;

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

&lt;p&gt;```return (&lt;br&gt;
  &lt;/p&gt;
&lt;br&gt;
      &lt;h1&gt;Currency Converter&lt;/h1&gt;


&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;input
      type="number"
      value={amount}
      onChange={(e) =&amp;gt; setAmount(Number(e.target.value))}
  /&amp;gt;

  &amp;lt;select
      value={currency}
      onChange={(e) =&amp;gt; setCurrency(e.target.value)}
  &amp;gt;
      &amp;lt;option value="EUR"&amp;gt;EUR&amp;lt;/option&amp;gt;
      &amp;lt;option value="GBP"&amp;gt;GBP&amp;lt;/option&amp;gt;
      &amp;lt;option value="JPY"&amp;gt;JPY&amp;lt;/option&amp;gt;
  &amp;lt;/select&amp;gt;

  &amp;lt;h2&amp;gt;
      {amount} USD = {convertedAmount} {currency}
  &amp;lt;/h2&amp;gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;br&gt;
);```&lt;br&gt;


</description>
      <category>beginners</category>
      <category>frontend</category>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>Building a Simple Currency Converter in React with useState and useMemo</title>
      <dc:creator>Iszyk</dc:creator>
      <pubDate>Thu, 30 Jul 2026 13:38:58 +0000</pubDate>
      <link>https://dev.to/iszy/building-a-simple-currency-converter-in-react-with-usestate-and-usememo-3gab</link>
      <guid>https://dev.to/iszy/building-a-simple-currency-converter-in-react-with-usestate-and-usememo-3gab</guid>
      <description>&lt;p&gt;``&lt;/p&gt;

&lt;p&gt;One of the best ways to learn React is by building small, practical projects. A currency converter is an excellent example because it introduces state management, user input handling, calculations, and performance optimization—all in a single application.&lt;/p&gt;

&lt;p&gt;In this tutorial, I built a simple currency converter using React that converts from USD to EUR, GBP, and JPY.&lt;/p&gt;

&lt;p&gt;For simplicity, I used fixed exchange rates instead of calling a live exchange rate API.&lt;/p&gt;

&lt;p&gt;React applications are interactive because they can respond to user actions. The useState hook allows components to remember values between renders.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;`const [amount, setAmount] = useState('');&lt;br&gt;
  const [fromCurrency, setFromCurrency] = useState('USD');&lt;br&gt;
  const [toCurrency, setToCurrency] = useState('EUR');`&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;amount stores the value entered.&lt;/li&gt;
&lt;li&gt;setAmount() updates it.&lt;/li&gt;
&lt;li&gt;fromCurrency is the initial currency&lt;/li&gt;
&lt;li&gt;setFromCurrency changes the initial currency&lt;/li&gt;
&lt;li&gt;toCurrency stores the selected currency.&lt;/li&gt;
&lt;li&gt;setToCurrency() changes the selected currency.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whenever either value changes, React automatically re-renders the component.&lt;/p&gt;

&lt;p&gt;Normally, React recalculates everything every time the component renders—even when the calculation doesn’t need to change.&lt;/p&gt;

&lt;p&gt;That’s where useMemo comes in.&lt;/p&gt;

&lt;p&gt;It remembers (memoizes) the previous calculation and only recalculates when its dependencies change.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;`const memoizedValue = useMemo(() =&amp;gt; {&lt;br&gt;
    return expensiveCalculation();&lt;br&gt;
}, [dependency]);`&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;`const RATES = {&lt;br&gt;
    USD: 1,&lt;br&gt;
    EUR: 0.92,&lt;br&gt;
    GBP: 0.79,&lt;br&gt;
    JPY: 157.3&lt;br&gt;
};`&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;These rates represent the value of 1 USD.&lt;/p&gt;

&lt;p&gt;I combined everything with useMemo.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;`const convertedAmount = useMemo(() =&amp;gt; {&lt;br&gt;
    const value = Number(amount);&lt;br&gt;
    if (amount === '' || !Number.isFinite(value)) return '';&lt;br&gt;
    return ((value / RATES[fromCurrency]) * RATES[toCurrency]).toFixed(2);&lt;br&gt;
  }, [amount, fromCurrency, toCurrency]);`&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multiply the amount by the selected  RATES.&lt;/li&gt;
&lt;li&gt;Format the result to two decimal places.&lt;/li&gt;
&lt;li&gt;Only recalculate when amount or currency changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Building the User Interface&lt;/p&gt;

&lt;p&gt;The interface contains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A number input.&lt;/li&gt;
&lt;li&gt;A dropdown menu.&lt;/li&gt;
&lt;li&gt;A heading displaying the converted amount.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;&lt;code&gt;`return (&lt;br&gt;
  &amp;lt;div className="table-container"&amp;gt;&lt;br&gt;
      &amp;lt;h1 className="heading"&amp;gt;Currency Converter&amp;lt;/h1&amp;gt;&lt;br&gt;
      &amp;lt;h3 className="converter-title" &amp;gt;{`${fromCurrency} to  ${toCurrency} Conversion`}&amp;lt;/h3&amp;gt;&lt;br&gt;
      &amp;lt;form &lt;br&gt;
        className="form"&lt;br&gt;
        onSubmit={e =&amp;gt; e.preventDefault()}&amp;gt;&lt;br&gt;
        &amp;lt;input &lt;br&gt;
          type="number" &lt;br&gt;
          id="amount" &lt;br&gt;
          placeholder="0"&lt;br&gt;
          value={amount}&lt;br&gt;
          onChange={(e) =&amp;gt; setAmount(e.target.value)} /&amp;gt;`&lt;/code&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; ```&amp;lt;p className="start-paragraph"&amp;gt;Start Currency:&amp;lt;/p&amp;gt;
    &amp;lt;select className="start-currency"
      value={fromCurrency}
      onChange={(e) =&amp;gt; setFromCurrency(e.target.value)} &amp;gt;
     &amp;lt;option&amp;gt;USD&amp;lt;/option&amp;gt;
     &amp;lt;option&amp;gt;EUR&amp;lt;/option&amp;gt;
     &amp;lt;option&amp;gt;GBP&amp;lt;/option&amp;gt;
     &amp;lt;option&amp;gt;JPY&amp;lt;/option&amp;gt;
    &amp;lt;/select&amp;gt; 

 &amp;lt;p className="start-paragraph"&amp;gt;Target Currency:&amp;lt;/p&amp;gt;
    &amp;lt;select className="target-currency"
    value={toCurrency}
    onChange={(e) =&amp;gt; setToCurrency(e.target.value)} &amp;gt;          
      &amp;lt;option&amp;gt;USD&amp;lt;/option&amp;gt;
      &amp;lt;option&amp;gt;EUR&amp;lt;/option&amp;gt;
      &amp;lt;option&amp;gt;GBP&amp;lt;/option&amp;gt;
      &amp;lt;option&amp;gt;JPY&amp;lt;/option&amp;gt;
    &amp;lt;/select&amp;gt;  
  &amp;lt;/form&amp;gt;
  &amp;lt;p className="result"&amp;gt;
  {convertedAmount ? `Converted Amount: ${convertedAmount} ${toCurrency}`: `Converted Amount: 0.00 ${toCurrency}`}
   &amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;);```
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Although this project is simple, it teaches several core React concepts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Managing state with useState.&lt;/li&gt;
&lt;li&gt;Handling user input.&lt;/li&gt;
&lt;li&gt;Rendering UI dynamically.&lt;/li&gt;
&lt;li&gt;Using useMemo to avoid unnecessary calculations.&lt;/li&gt;
&lt;li&gt;Organizing component logic in a clean, readable way.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;Building small projects is one of the fastest ways to become comfortable with React. This currency converter demonstrates how a few hooks can create an interactive, efficient application.&lt;/p&gt;

&lt;p&gt;useState gives your components memory, while useMemo helps avoid unnecessary work by recalculating values only when needed.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>react</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>JavaScript Libraries and Frameworks: REACT</title>
      <dc:creator>Iszyk</dc:creator>
      <pubDate>Tue, 21 Jul 2026 16:25:29 +0000</pubDate>
      <link>https://dev.to/iszy/javascript-libraries-and-frameworks-react-37fe</link>
      <guid>https://dev.to/iszy/javascript-libraries-and-frameworks-react-37fe</guid>
      <description>&lt;p&gt;JavaScript libraries and frameworks provide pre-built code that streamlines the development process. While both libraries and frameworks serve to improve productivity and standardize coding practices, they differ in their approach and level of control they provide to developers.&lt;/p&gt;

&lt;p&gt;Libraries are generally more focused on providing solutions to specific tasks, such as manipulating the DOM, handling events, or managing AJAX requests.&lt;br&gt;
An example of a JavaScript library is jQuery.&lt;/p&gt;

&lt;p&gt;Frameworks, on the other hand, provide a more defined structure for building applications. They often come with a set of rules and conventions that developers need to follow.&lt;/p&gt;

&lt;p&gt;React, a UI library, is more flexible and doesn't enforce any particular architectural pattern. React focuses primarily on the view layer and leaves a lot of the choices on application design up to the developers.&lt;/p&gt;

&lt;p&gt;React is one of the most popular JavaScript libraries for building user interfaces and web applications. Originally developed and maintained by Facebook, React has gained huge popularity in web development due to its efficiency, flexibility, and features.&lt;/p&gt;

&lt;p&gt;A fundamental concept in React is the creation of reusable UI components. These components, such as buttons, cards, and avatar components, can be easily reused throughout an application. It can nest these components inside each other to build more complex, dynamic interfaces.&lt;/p&gt;

&lt;p&gt;Components are the building blocks of React applications that allow developers to break down complex user interfaces into smaller, manageable pieces, making it easier to develop and maintain large-scale applications.&lt;br&gt;
Example of a component:-&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;function Greeting() {&lt;br&gt;
  const name = "John"&lt;br&gt;
  {/* The result will be Hello John*/}&lt;br&gt;
  return &amp;lt;h1 className="title"&amp;gt;Hello {name}&amp;lt;/h1&amp;gt;;&lt;br&gt;
}&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;In this example, we've defined a component called Greeting. The curly braces {} inside the h1 tags enable us to embed JavaScript expressions, allowing us to access the name variable within the h1 element. We are also applying a className called title to the h1 element, this is because in JavaScript, class is a reserved name. So, we need to use className instead.&lt;/p&gt;

&lt;p&gt;One of the key advantages of React is that these custom components can update and render independently as data changes.&lt;/p&gt;

&lt;p&gt;Unlike traditional JavaScript, which requires direct manipulation of the DOM (Document Object Model), React uses a virtual DOM, which improves performance and efficiency.&lt;/p&gt;

&lt;p&gt;In addition to reusable components, React also provides a powerful way to manage the state of your application. State refers to the data that determines how a component renders and behaves.&lt;/p&gt;

&lt;p&gt;With React, you can easily track and update the state of components, ensuring that the UI reflects the most current data.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>javascript</category>
      <category>programming</category>
      <category>react</category>
    </item>
    <item>
      <title>Asynchronous Javascript</title>
      <dc:creator>Iszyk</dc:creator>
      <pubDate>Thu, 02 Apr 2026 09:21:38 +0000</pubDate>
      <link>https://dev.to/iszy/asynchronous-javascript-58mb</link>
      <guid>https://dev.to/iszy/asynchronous-javascript-58mb</guid>
      <description>&lt;p&gt;Asynchronous JavaScript is a way of writing code that allows tasks to run without blocking the rest of your program.&lt;/p&gt;

&lt;p&gt;In simple terms: instead of waiting for a code to finish executing like fetching data from an API, JavaScript continues executing other code and comes back to the result later.&lt;/p&gt;

&lt;p&gt;We basically have two types of operations in javascript, synchronous and asynchronous. The primary difference is that synchronous operations occur sequentially, requiring one task to finish before the next begins, while asynchronous operations allow multiple tasks to run concurrently without waiting, improving efficiency and responsiveness. Synchronous is "blocking" (wait-for-result), while asynchronous is "non-blocking" (continue-to-other-tasks).&lt;/p&gt;

&lt;p&gt;Example of synchronous operation;-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
let data = fetchData(); // waits here until done

console.log(data);
console.log("End");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
The app pauses until fetchData() finishes.&lt;/p&gt;

&lt;p&gt;Example of asynchronous operation;-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("Start");

fetchData().then(data =&amp;gt; {
  console.log(data);
});

console.log("End");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
plaintext&lt;br&gt;
The Output;-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Start
End
(data comes later)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
plaintext&lt;/p&gt;

&lt;p&gt;🔹 Common Asynchronous Techniques&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Callbacks&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A callback is a function passed as an argument to another function, which is then executed (or "called back") inside that outer function to complete a specific task, because functions in JavaScript are First-class Objects, they can be treated like any other variable and passed between functions. &lt;br&gt;
For example,&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A Simple Synchronous Callback&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function greet(name, callback) {
  console.log("Hello, " + name);
  callback(); // Executing the callback function
}

function sayGoodbye() {
  console.log("Goodbye!");
}

// Pass 'sayGoodbye' as a callback to 'greet'
greet("Alice", sayGoodbye);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
plaintext&lt;/p&gt;

&lt;p&gt;In this example, the greet function takes a callback as a parameter and executes it immediately after performing its own logic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Asynchronous Callback&lt;/strong&gt;&lt;br&gt;
Callbacks are essential for asynchronous programming, where a task needs time to complete (like a timer or data fetch) without blocking the rest of the code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log("Start");

// setTimeout takes an anonymous function as a callback
setTimeout(() =&amp;gt; {
  console.log("This appears after 2 seconds");
}, 2000);

console.log("End");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
plaintext&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Promises&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In JavaScript, a Promise is an object representing the eventual completion or failure of an asynchronous operation and its resulting value. It serves as a placeholder for a result that is not yet available, allowing you to handle asynchronous code in a cleaner way than traditional callbacks.&lt;br&gt;
    Promises exist in one of three states: pending (ongoing), fulfilled (successful), or rejected (failed). Once fulfilled or rejected, a promise is settled and cannot change state.&lt;/p&gt;

&lt;p&gt;You create a Promise using the new Promise() constructor, which takes an executor function. This function runs immediately and receives two callback arguments provided by the JavaScript engine: resolve and reject.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myPromise = new Promise((resolve, reject) =&amp;gt; {
  const success = true; 
  if (success) {
    resolve("Operation Successful!"); // Moves state to Fulfilled
  } else {
    reject("Operation Failed.");      // Moves state to Rejected
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
plaintext&lt;br&gt;
To handle the result of a Promise, you attach handlers using these methods: &lt;br&gt;
.then(): Runs when the promise is fulfilled. It can also take a second argument for rejection.&lt;br&gt;
.catch(): A shorthand for handling errors. It runs if the promise is rejected at any point in the chain.&lt;br&gt;
.finally(): Runs after the promise settles, regardless of whether it succeeded or failed. It is often used for cleanup.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const myPromise = new Promise((resolve, reject) =&amp;gt; {
  const success = true; 
  if (success) {
    resolve("Operation successful!"); // Marks as fulfilled
  } else {
    reject("Something went wrong.");  // Marks as rejected
  }
});

// Consuming the promise
myPromise
  .then((data) =&amp;gt; console.log(data))    // Runs if resolved
  .catch((err) =&amp;gt; console.error(err))   // Runs if rejected
  .finally(() =&amp;gt; console.log("Done"));  // Always runs

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

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
plaintext&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Async/Await (Modern &amp;amp; Cleaner)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In JavaScript, async and await are keywords used to write asynchronous code that looks and behaves like synchronous code. They are "syntactic sugar" built on top of JavaScript Promises, making complex asynchronous flows easier to read and maintain.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Concept&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;async Keyword: Placed before a function declaration to define an asynchronous function.&lt;br&gt;
An async function always returns a Promise.&lt;br&gt;
If the function returns a value, that value is automatically wrapped in a resolved Promise.&lt;/p&gt;

&lt;p&gt;await Keyword: Can only be used inside an async function (or at the top level of a module).&lt;br&gt;
It pauses the execution of the async function until the Promise settles (resolves or rejects).&lt;br&gt;
Once the Promise resolves, it returns the result. If it rejects, it throws an error.&lt;br&gt;
While the function is paused, the JavaScript engine can perform other tasks, making it non-blocking.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function fetchData() {
  try {
    // Execution pauses here until the fetch promise resolves
    const response = await fetch('https://example.com');

    // Execution pauses again for the .json() promise
    const data = await response.json();

    console.log(data);
  } catch (error) {
    // Standard try/catch handles any errors in the async flow
    console.error("Fetch error:", error);
  }
}

fetchData();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To fetch data from an API using the Fetch API, the async/await pattern is commonly used.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Building a Simple JavaScript Slider: A Code Walkthrough</title>
      <dc:creator>Iszyk</dc:creator>
      <pubDate>Tue, 17 Feb 2026 11:40:15 +0000</pubDate>
      <link>https://dev.to/iszy/building-a-simple-javascript-slider-a-code-walkthrough-2ae1</link>
      <guid>https://dev.to/iszy/building-a-simple-javascript-slider-a-code-walkthrough-2ae1</guid>
      <description>&lt;p&gt;Image sliders are one of the most widely used UI components in modern web development. From product showcases and portfolio galleries to testimonials and hero banners, sliders allow multiple pieces of content to occupy the same space while keeping the interface clean and interactive. First of all, what is a slider? A slider is a UI component that displays one slide at a time, it allows navigation between slides, it moves content horizontally (most common) or vertically and lastly it uses animation for smooth transitions. A slider typically displays one item at a time and lets users navigate between items using arrows, dots, or swipe gestures. &lt;br&gt;
        The images are placed horizontally inside a fixed-width container but only one slide is visible because the container hides the overflow as shown below.&lt;br&gt;
+----------------------------------+&lt;br&gt;
|          Viewport Window         |&lt;br&gt;
|  [ Slide 1 ]                     |&lt;br&gt;
+----------------------------------+&lt;br&gt;
When we click "Next", we shift the entire row left, likewise when we click "Previous", we shift the entire right. By this way, we allow the next image that was hidden to be displayed while the previous goes hidden. &lt;br&gt;
   When we want to build an image slider, we start with the HTML document by creating the div container first with a class of slider, the left and right arrows are enclosed in a button element with a class of slider_&lt;em&gt;btn slider&lt;/em&gt;_btn--left in the HTML. Then we create the img element with the images we want, and also with a class of slides as it is shown below.&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;div class="slider"&amp;gt;
                    &amp;lt;img src="../images/image-product-1.jpg" alt="Slide 1" class="slide"&amp;gt;
                    &amp;lt;img src="../images/image-product-2.jpg" alt="Slide 2" class="slide"&amp;gt;
                    &amp;lt;img src="../images/image-product-3.jpg" alt="Slide 3" class="slide"&amp;gt;
                    &amp;lt;img src="../images/image-product-4.jpg" alt="Slide 4" class="slide"&amp;gt;
                    &amp;lt;button class="slider__btn slider__btn--left"&amp;gt;&amp;amp;larr;&amp;lt;/button&amp;gt;
                    &amp;lt;button class="slider__btn slider__btn--right"&amp;gt;&amp;amp;rarr;&amp;lt;/button&amp;gt;
            &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The next step is the styling which is done in the css file section. The styling shown below is in 375px, it is shown in mobile view. It gives basic layout, the hiding and showing behavior for slides.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.slider{
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: center;
}

.slides {
    display: flex;
    width: 100%;
    height: auto;
}

.slider__btn--left {
    left: 5px;
}

.slider__btn--right {
    right: 5px;
}

.slider__btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background-color: white;
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    color: hsl(26, 100%, 55%);
    font-weight: 700;
    z-index: 10;
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The last step is implementing the javascript logic. The logic is to make sure that when the button is clicked, it performs a function which is showing the correct slide in this context.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let currentMobileSlide = 0;
const mobileSlides = document.querySelectorAll('.slider .slide');
const mobileLeftBtn = document.querySelector('.slider__btn--left');
const mobileRightBtn = document.querySelector('.slider__btn--right');

unction showMobileSlide(index) {
    if (!mobileSlides || mobileSlides.length === 0) return;
    mobileSlides.forEach((slide, i) =&amp;gt; {
        slide.style.display = (i === index) ? 'block' : 'none';
        slide.classList.toggle('active', i === index);
    });
}

if (mobileLeftBtn) {
    mobileLeftBtn.addEventListener('click', () =&amp;gt; {
        currentMobileSlide = (currentMobileSlide === 0) ? mobileSlides.length - 1 : currentMobileSlide - 1;
        showMobileSlide(currentMobileSlide);
    });
}

if (mobileRightBtn) {
    mobileRightBtn.addEventListener('click', () =&amp;gt; {
        currentMobileSlide = (currentMobileSlide === mobileSlides.length - 1) ? 0 : currentMobileSlide + 1;
        showMobileSlide(currentMobileSlide);
    });
}

// Initialize mobile slider
showMobileSlide(currentMobileSlide);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In conclusion, slider is simple and lightweight, ideal for portfolios or landing pages. It can also be enhanced by adding autoplay, swipe gestures and/or transition effects.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>frontend</category>
    </item>
    <item>
      <title># JavaScript and Event Listeners: Making Web Pages Interactive</title>
      <dc:creator>Iszyk</dc:creator>
      <pubDate>Mon, 22 Dec 2025 11:06:50 +0000</pubDate>
      <link>https://dev.to/iszy/javascript-and-event-listeners-2901</link>
      <guid>https://dev.to/iszy/javascript-and-event-listeners-2901</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;One of the things that makes a website feel alive is &lt;strong&gt;interactivity&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You click a button and something happens.&lt;/p&gt;

&lt;p&gt;You type into a search box and results appear.&lt;/p&gt;

&lt;p&gt;You submit a form and the page responds.&lt;/p&gt;

&lt;p&gt;You move your mouse over an element and its appearance changes.&lt;/p&gt;

&lt;p&gt;You resize your browser and the layout responds.&lt;/p&gt;

&lt;p&gt;But how does JavaScript know that these things are happening?&lt;/p&gt;

&lt;p&gt;The answer is &lt;strong&gt;events and event listeners&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;As I continue learning JavaScript, event listeners are one of the concepts that really helped me understand how JavaScript interacts with HTML and responds to what users do on a webpage.&lt;/p&gt;

&lt;p&gt;In this article, I'll break down:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What an event is&lt;/li&gt;
&lt;li&gt;What an event listener is&lt;/li&gt;
&lt;li&gt;How &lt;code&gt;addEventListener()&lt;/code&gt; works&lt;/li&gt;
&lt;li&gt;Common JavaScript events&lt;/li&gt;
&lt;li&gt;&lt;code&gt;event.preventDefault()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Why events are important for interactive websites&lt;/li&gt;
&lt;li&gt;A simple practical example&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  What Is an Event?
&lt;/h2&gt;

&lt;p&gt;An &lt;strong&gt;event&lt;/strong&gt; is an action or occurrence that happens in the browser.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A user clicks a button&lt;/li&gt;
&lt;li&gt;A user types something into an input&lt;/li&gt;
&lt;li&gt;A form is submitted&lt;/li&gt;
&lt;li&gt;A key is pressed&lt;/li&gt;
&lt;li&gt;The mouse moves over an element&lt;/li&gt;
&lt;li&gt;A checkbox is changed&lt;/li&gt;
&lt;li&gt;The browser window is resized&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;JavaScript can detect these actions and respond to them.&lt;/p&gt;

&lt;p&gt;Think of an event as a &lt;strong&gt;signal&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Hey JavaScript, the user just clicked this button!"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;JavaScript can then decide what should happen next.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Is an Event Listener?
&lt;/h2&gt;

&lt;p&gt;An &lt;strong&gt;event listener&lt;/strong&gt; is a function that waits for a particular event to happen and then executes some code when that event occurs.&lt;/p&gt;

&lt;p&gt;The most common way to create one in JavaScript is with:&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="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The basic syntax looks like this:&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;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;event&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// code to execute&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For 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;const&lt;/span&gt; &lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#myButton&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&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="nf"&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;Button clicked!&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is what is happening:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We select the button from the HTML.&lt;/li&gt;
&lt;li&gt;We tell JavaScript to listen for a &lt;code&gt;"click"&lt;/code&gt; event.&lt;/li&gt;
&lt;li&gt;When the user clicks the button, the function runs.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;"Button clicked!"&lt;/code&gt; is printed to the console.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It's basically JavaScript saying:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"I'm going to watch this button. Whenever someone clicks it, I'll do something."&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Events vs Event Listeners
&lt;/h2&gt;

&lt;p&gt;This was an important distinction for me to understand.&lt;/p&gt;

&lt;p&gt;An &lt;strong&gt;event&lt;/strong&gt; is the action.&lt;/p&gt;

&lt;p&gt;An &lt;strong&gt;event listener&lt;/strong&gt; is what waits for that action and tells JavaScript what to do when it happens.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Event:&lt;/strong&gt; User clicks a button.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Event listener:&lt;/strong&gt; Wait for the click and run this function.&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;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&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="nf"&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;The user clicked the button.&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So you can think of it like this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Event → Listener → Action&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  A Practical Example
&lt;/h2&gt;

&lt;p&gt;Let's build something simple.&lt;/p&gt;

&lt;p&gt;Suppose we have a button:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"myButton"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Click Me&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"message"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Nothing has happened yet.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's use JavaScript to change the message when the button is clicked.&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;button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#myButton&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#message&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&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;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;You clicked the button!&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before clicking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Nothing has happened yet.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After clicking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You clicked the button!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This might look simple, but this is one of the fundamental ideas behind interactive web applications.&lt;/p&gt;

&lt;p&gt;The same concept can eventually be used for things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Opening and closing navigation menus&lt;/li&gt;
&lt;li&gt;Showing and hiding modals&lt;/li&gt;
&lt;li&gt;Form validation&lt;/li&gt;
&lt;li&gt;Image sliders&lt;/li&gt;
&lt;li&gt;Search functionality&lt;/li&gt;
&lt;li&gt;Shopping carts&lt;/li&gt;
&lt;li&gt;Dropdown menus&lt;/li&gt;
&lt;li&gt;Games&lt;/li&gt;
&lt;li&gt;Interactive dashboards&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Common JavaScript Events
&lt;/h2&gt;

&lt;p&gt;JavaScript has many different events that we can listen for.&lt;/p&gt;

&lt;p&gt;Here are some common ones:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;code&gt;click&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Triggered when an element is clicked.&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;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&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="nf"&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;Clicked!&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is probably one of the events you'll use most often as a beginner.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. &lt;code&gt;input&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Triggered when the value of an input changes as the user types.&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;input&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#username&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;input&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is useful for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Search boxes&lt;/li&gt;
&lt;li&gt;Live form validation&lt;/li&gt;
&lt;li&gt;Character counters&lt;/li&gt;
&lt;li&gt;Password strength indicators&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  3. &lt;code&gt;change&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Triggered when the value of certain form elements changes.&lt;/p&gt;

&lt;p&gt;For 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;const&lt;/span&gt; &lt;span class="nx"&gt;select&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#country&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;select&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;change&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;select&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is commonly used with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;select&amp;gt;&lt;/code&gt; elements&lt;/li&gt;
&lt;li&gt;Checkboxes&lt;/li&gt;
&lt;li&gt;Radio buttons&lt;/li&gt;
&lt;li&gt;Form controls&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  4. &lt;code&gt;keydown&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Triggered when a key is pressed down.&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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;keydown&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;key&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;If the user presses the Escape key, for example, JavaScript can detect it.&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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;keydown&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Escape&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&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;Escape was pressed!&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="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You may see &lt;code&gt;keypress&lt;/code&gt; in older tutorials, but for modern JavaScript, &lt;code&gt;keydown&lt;/code&gt; and &lt;code&gt;keyup&lt;/code&gt; are generally preferred.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  5. &lt;code&gt;mousemove&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Triggered when the mouse moves over an element or document.&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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mousemove&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&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="nf"&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;Mouse is moving&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can use mouse events to create interactive effects and animations.&lt;/p&gt;




&lt;h3&gt;
  
  
  6. &lt;code&gt;dblclick&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Triggered when an element is double-clicked.&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;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;dblclick&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&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="nf"&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;Double clicked!&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And there are many more events available in JavaScript.&lt;/p&gt;




&lt;h1&gt;
  
  
  What Is the Event Object?
&lt;/h1&gt;

&lt;p&gt;Another useful concept is the &lt;strong&gt;event object&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When an event occurs, JavaScript can provide information about that event.&lt;/p&gt;

&lt;p&gt;We can receive that information through a parameter, commonly called &lt;code&gt;event&lt;/code&gt; or &lt;code&gt;e&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For 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;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&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;The event object contains useful information about what happened.&lt;/p&gt;

&lt;p&gt;For 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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;keydown&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&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="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;key&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;If I press the letter &lt;strong&gt;A&lt;/strong&gt;, JavaScript can tell me:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;If I press &lt;strong&gt;Escape&lt;/strong&gt;, it can tell me:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This becomes very useful when building interactive applications.&lt;/p&gt;




&lt;h1&gt;
  
  
  &lt;code&gt;event.preventDefault()&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;One method I think every beginner should understand is:&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;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some HTML elements have default browser behavior.&lt;/p&gt;

&lt;p&gt;For example, when a user submits a form, the browser may attempt to send the form and reload the page.&lt;/p&gt;

&lt;p&gt;But what if I want JavaScript to handle the form myself?&lt;/p&gt;

&lt;p&gt;I can prevent the browser's default behavior.&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;form&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#myForm&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;form&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;submit&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;preventDefault&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="nf"&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;Form submission handled by JavaScript!&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important line is:&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;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It tells the browser:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Don't perform the normal default action. I'll handle this with JavaScript."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is particularly useful when building custom form validation and applications where data is sent using JavaScript.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why Are Event Listeners Important?
&lt;/h1&gt;

&lt;p&gt;This is where event listeners become really interesting.&lt;/p&gt;

&lt;p&gt;Imagine a website with only HTML and CSS.&lt;/p&gt;

&lt;p&gt;You can create beautiful layouts.&lt;/p&gt;

&lt;p&gt;You can display text, images, buttons and forms.&lt;/p&gt;

&lt;p&gt;But if nothing responds to the user's actions, the website can feel very limited.&lt;/p&gt;

&lt;p&gt;JavaScript gives us the ability to respond to those actions.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;User clicks "Add to Cart"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JavaScript detects the click&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Event listener runs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;↓&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Product is added to the cart&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That's the basic idea behind many interactive features we use every day.&lt;/p&gt;




&lt;h1&gt;
  
  
  Static vs Interactive Websites
&lt;/h1&gt;

&lt;p&gt;This also helped me understand the difference between a static page and an interactive application.&lt;/p&gt;

&lt;p&gt;A simple static website might mainly display information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;About a company&lt;/li&gt;
&lt;li&gt;Services&lt;/li&gt;
&lt;li&gt;Contact information&lt;/li&gt;
&lt;li&gt;Blog posts&lt;/li&gt;
&lt;li&gt;Images&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But an interactive application can respond to the user.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;E-commerce website&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;User clicks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Add to Cart&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;JavaScript responds:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Product added to your cart.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Login form&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;User enters incorrect information.&lt;/p&gt;

&lt;p&gt;JavaScript responds:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Please enter a valid email address.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Search application&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;User types:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;JavaScript&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;JavaScript can respond by displaying matching results.&lt;/p&gt;

&lt;p&gt;The website isn't simply displaying information anymore.&lt;/p&gt;

&lt;p&gt;It is &lt;strong&gt;responding to the user&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Events Are Everywhere
&lt;/h1&gt;

&lt;p&gt;Once you start paying attention to them, you'll notice events everywhere.&lt;/p&gt;

&lt;p&gt;When you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click a button&lt;/li&gt;
&lt;li&gt;Submit a form&lt;/li&gt;
&lt;li&gt;Type in a search box&lt;/li&gt;
&lt;li&gt;Press a keyboard key&lt;/li&gt;
&lt;li&gt;Select an option&lt;/li&gt;
&lt;li&gt;Move your mouse&lt;/li&gt;
&lt;li&gt;Resize your browser&lt;/li&gt;
&lt;li&gt;Scroll a page&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There is a good chance JavaScript can listen for that action and respond to it.&lt;/p&gt;

&lt;p&gt;That's what makes the web feel interactive.&lt;/p&gt;




&lt;h1&gt;
  
  
  What I'm Taking Away From Learning Event Listeners
&lt;/h1&gt;

&lt;p&gt;Learning event listeners has helped me understand something important about JavaScript.&lt;/p&gt;

&lt;p&gt;JavaScript isn't just about writing calculations and displaying messages in the console.&lt;/p&gt;

&lt;p&gt;It can &lt;strong&gt;listen to what users are doing and respond accordingly.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That is a major part of what makes modern websites and web applications interactive.&lt;/p&gt;

&lt;p&gt;The concept itself is actually quite simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Something happens
       ↓
JavaScript detects it
       ↓
Event listener runs
       ↓
Something changes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that simple process can power surprisingly complex applications.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;Event listeners are one of the fundamental concepts I believe every beginner learning JavaScript should understand.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;addEventListener()&lt;/code&gt; method might look simple:&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;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// do something&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But behind this simple syntax is a powerful idea:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;JavaScript can listen, react, and change the experience of the user.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As I continue learning JavaScript and building projects, I'm beginning to see event listeners everywhere.&lt;/p&gt;

&lt;p&gt;From buttons and forms to search bars and interactive applications, events are a major part of what transforms a webpage from something you simply &lt;strong&gt;look at&lt;/strong&gt; into something you can actually &lt;strong&gt;interact with&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And that's one of the things I really enjoy about JavaScript.&lt;/p&gt;

&lt;p&gt;You don't just write code.&lt;/p&gt;

&lt;p&gt;You write code that &lt;strong&gt;responds to people.&lt;/strong&gt; 🚀&lt;/p&gt;




&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;p&gt;The best way to understand event listeners isn't just by reading about them.&lt;/p&gt;

&lt;p&gt;It's by building.&lt;/p&gt;

&lt;p&gt;So my next step is to keep practicing with small JavaScript projects and use events to make them more interactive.&lt;/p&gt;

&lt;p&gt;If you're also learning JavaScript, don't just memorize &lt;code&gt;addEventListener()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Try something with it.&lt;/p&gt;

&lt;p&gt;Build a button.&lt;/p&gt;

&lt;p&gt;Build a form.&lt;/p&gt;

&lt;p&gt;Build a counter.&lt;/p&gt;

&lt;p&gt;Build a small game.&lt;/p&gt;

&lt;p&gt;Break it.&lt;/p&gt;

&lt;p&gt;Fix it.&lt;/p&gt;

&lt;p&gt;And learn from it.&lt;/p&gt;

&lt;p&gt;That's how the concepts start to stick. 💻🚀&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What was the first JavaScript event you learned? Let me know in the comments.&lt;/strong&gt;&lt;/p&gt;

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