<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Hussaini Ahmed</title>
    <description>The latest articles on Forem by Hussaini Ahmed (@husayn01).</description>
    <link>https://forem.com/husayn01</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1078027%2F36cf3446-dfae-4e2f-82d2-fd40a6f9f181.jpeg</url>
      <title>Forem: Hussaini Ahmed</title>
      <link>https://forem.com/husayn01</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/husayn01"/>
    <language>en</language>
    <item>
      <title>Debunking Common Programming Myths and Misconceptions</title>
      <dc:creator>Hussaini Ahmed</dc:creator>
      <pubDate>Sun, 25 Jun 2023 16:50:46 +0000</pubDate>
      <link>https://forem.com/husayn01/debunking-common-programming-myths-and-misconceptions-4306</link>
      <guid>https://forem.com/husayn01/debunking-common-programming-myths-and-misconceptions-4306</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--naBP35jY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wglr2zz0x9wuzsr8b3r6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--naBP35jY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wglr2zz0x9wuzsr8b3r6.png" alt="Programming myths and misconceptions" width="392" height="237"&gt;&lt;/a&gt;&lt;br&gt;
Programming, often hailed as the language of the future, is a field surrounded by many myths and misconceptions, which can be misleading, most especially to aspiring programmers, creating a misconception of what it takes to get started and be successful in the industry.&lt;/p&gt;

&lt;p&gt;From popular TV series like &lt;em&gt;Silicon valley&lt;/em&gt; and &lt;em&gt;Mr Robot&lt;/em&gt; to social media forums and online forums, there have been very a strong portrayal of this misconceptions. One popular example is that all programmers fit to this stereotype: Genius, socially awkward and introverted as portrayed in &lt;em&gt;Mr Robot&lt;/em&gt;. In the TV series, Elliot's character embodies this stereotype, as he is portrayed as a brilliant but socially awkward hacker who struggles  with interpersonal relationships. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DR554DBX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ja0wnto097bze7no5ux.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DR554DBX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2ja0wnto097bze7no5ux.png" alt="meme" width="327" height="362"&gt;&lt;/a&gt;&lt;br&gt;
This is also seen in &lt;em&gt;Silicon Valley&lt;/em&gt;, as the main character, Richard Hendricks is a badass programmer but lacks good communication skill, He  struggles with selling his ideas to others. One scene even shows him blabbering utter nonsense in front of his employees as he attempts to introduce&lt;br&gt;
himself. Well, He ends up puking.&lt;/p&gt;

&lt;p&gt;These examples, among several others has led a lot of people to believe these as being the truth. &lt;br&gt;
This is why we here today - to unravel these myths and shed light on the realities of the programming landscape.  we will uncover the truth behind these misconceptions and present a more accurate portrayal of the programming profession. &lt;/p&gt;

&lt;p&gt;By debunking these myths, we aim to empower individuals to approach programming with a balanced perspective,  understand the challenges they may encounter, and make informed decisions about their learning and career paths, So, let's dive.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GdhJxzeZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l48ek6srn28ou7gr8lsz.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GdhJxzeZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l48ek6srn28ou7gr8lsz.gif" alt="meme" width="500" height="281"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Myth 1: Programming is only for the Genius.
&lt;/h2&gt;

&lt;p&gt;Many aspiring programmers have let themselves believe that programming is exclusively reserved  for extraordinarily intelligent individuals. However, I'm here to debunk this myth once and for all: programming is not solely for geniuses. In fact, it's far from it. Hell, I'm kinda dumb and i can code. No offense, Hussaini.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--70OJBsdu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/an0i40hum0tk0i7w7l78.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--70OJBsdu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/an0i40hum0tk0i7w7l78.gif" alt="meme" width="480" height="462"&gt;&lt;/a&gt;&lt;br&gt;
Here's the truth: learning how to code requires commitment, perseverance, and a sh*t ton of practice. If you possess basic reading and writing skills, you already have a solid foundation to start learning how to code. Most popular programming languages used today are considered high-level languages, meaning their syntax resembles English (except with those annoying semicolons and braces). This makes it more accessible and easier to understand for beginners.&lt;/p&gt;

&lt;h2&gt;
  
  
  Myth 2: Programmers can solve any technical problem instantly; they don't need to refer to documentation or search for solutions.
&lt;/h2&gt;

&lt;p&gt;This is yet another popular myth and for a while, i too, believed this. I did, so well that i thought i was a fraud for actually looking at documentations or asking CHATGPT for help when i got stuck whilst solving a programming problem.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--elukJDsD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s7x9zqf8sxfwpt2o5jtv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--elukJDsD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s7x9zqf8sxfwpt2o5jtv.png" alt="meme" width="480" height="359"&gt;&lt;/a&gt;&lt;br&gt;
I always believed being a good programmer meant sitting right in front of the PC and smashing the keyboard non-stop, Having it all figured out and all...&lt;/p&gt;

&lt;p&gt;But is this true?&lt;/p&gt;

&lt;p&gt;Nah. Programming is a vast and complex field, and no programmer, no matter how experienced, can have all the solutions memorized.  Programming languages and frameworks are continually evolving, and new challenges and scenarios arise regularly. Programmers often rely on documentation, references, and online resources to assist them in solving problems. &lt;/p&gt;

&lt;h2&gt;
  
  
  Myth 3: You need a computer science degree to become a successful programmer.
&lt;/h2&gt;

&lt;p&gt;The success of &lt;a href="https://en.wikipedia.org/wiki/Elon_Musk"&gt;Elon Musk&lt;/a&gt; and many other self-taught programmers serves as a testament to the fact that formal education is not the only determining factor for success in the field. Self-taught &lt;br&gt;
programmers often possess a unique drive, passion, and determination to learn and excel in programming.&lt;/p&gt;

&lt;p&gt;At age of 12, &lt;a href="https://en.wikipedia.org/wiki/Elon_Musk"&gt;Elon musk&lt;/a&gt; invented a video game, Blaster, and later sold it to a computer magazine company that published the code’s printed copy. He later founded  Zip2, which was acquired by a company called Compaq for $207 million.&lt;/p&gt;

&lt;p&gt;So if you are a self-taught programmer like Elon Musk and me, or intend to become one, don’t let the absence of a formal education discourage you. Pursue your dream  and keep the fire burning. Forgive me if I sound over-dramatic.&lt;/p&gt;

&lt;h2&gt;
  
  
  Myth 4: Programming is only for the young.
&lt;/h2&gt;

&lt;p&gt;A lot of people believe that programming is reserved only for the young, and older people like my Grandma who wants to learn how to code have missed the opportunity to venture into the field. Well, fortunately for my Grandma and the older people out there, this is only a misconception.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wId_DchY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t82vxu3671hek3k9zbf5.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wId_DchY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t82vxu3671hek3k9zbf5.gif" alt="meme" width="220" height="123"&gt;&lt;/a&gt;&lt;br&gt;
Programming in fact, has no age barrier,  and individuals of all ages can successfully learn to code and pursue a career in the field.&lt;/p&gt;

&lt;p&gt;Mario Burgos, on this &lt;a href="https://www.quora.com/Is-30-years-old-too-old-to-learn-computer-programming"&gt;Quora question&lt;/a&gt;, shares his motivating experience about how he started his coding career at the age of 37 and years later, he became the director of software development in one of the biggest Insurance Companies.&lt;/p&gt;

&lt;h2&gt;
  
  
  Myth 5: All programmers earn six-figure salaries; it's a guaranteed path to financial success.
&lt;/h2&gt;

&lt;p&gt;Sorry to burst your bubbles but Yeah its true, not all programmers earn six-figures salaries and it is not a guaranteed path to success. &lt;/p&gt;

&lt;p&gt;As pretty as it seem to imagine yourself being landing your first job and earning six-figure earner after 3 years of learning how to code, it doesn’t always happen.&lt;/p&gt;

&lt;p&gt;Becoming successful or even earning as  programmer, like in any other profession, depends on various factors such as experience, expertise, location, industry, job demand, and economic conditions.&lt;/p&gt;

&lt;p&gt;This is why it is important to approach programming as a career choice based on passion and interest rather than solely for the pursuit of financial gain.&lt;/p&gt;

&lt;h2&gt;
  
  
  Myth 6: Language X is better than language Y
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RD1Qt1UN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/11ne9zsxnkht51yx6acn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RD1Qt1UN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/11ne9zsxnkht51yx6acn.png" alt="meme" width="219" height="268"&gt;&lt;/a&gt;&lt;br&gt;
I’ve seen a lot of programmers arguing about which programming language is better. But in reality, this is silly. And there should be no comparison between two programming languages. Its like comparing a hammer to a spanner. Using this tools other than for purposes they are meant for will only lead to inefficiency and frustration, Since a hammer cannot be used to loosen a bolt and a spanner cannot be used to punch a nail into wood.&lt;/p&gt;

&lt;p&gt;To make informed decision before picking a programming language it is important that you clearly define your objectives. For web development, Javascript emerges as the best option due to it versatility and browser compatibility.&lt;/p&gt;

&lt;p&gt;On the other hand, for app development, java, react native, Kotlin or flutter are the best options as they have tons of libraries tailored for mobile applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping things up.
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5Vo7hg9L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nqxixpasi8f7uu6a3lc9.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5Vo7hg9L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nqxixpasi8f7uu6a3lc9.gif" alt="Gif" width="442" height="200"&gt;&lt;/a&gt;&lt;br&gt;
That’s it folks, we’ve discussed quite a lot today. These are some of the myths and misconceptions out there about programming. Hopefully you can now see programming from a clearer perspective and are able to accurately separate them from the truth and dispel unrealistic expectations.&lt;/p&gt;

&lt;p&gt;My name is &lt;strong&gt;Hussaini Ahmed&lt;/strong&gt;, I am a &lt;strong&gt;front end developer&lt;/strong&gt;. I also write about front end languages, frameworks and latest technologies. I’d loved to hear your thought on this article. Feel free to drop a comment below or reach out to me via:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.upwork.com/freelancers/~018f66d92dda7e4417"&gt;Upwork&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Husayn01"&gt;Github&lt;/a&gt;&lt;br&gt;
&lt;a href="https://wa.me/message/PAGMWLPTLJAOK1"&gt;WhatsApp&lt;/a&gt;&lt;br&gt;
&lt;a href="https://mobile.twitter.com/Husayn_01"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/mwlite/in/hussaini-ahmed-a51232252"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
      <category>coding</category>
    </item>
    <item>
      <title>From Zero To Hero: Front End Development Projects For Beginners[With Source Code]</title>
      <dc:creator>Hussaini Ahmed</dc:creator>
      <pubDate>Tue, 30 May 2023 16:10:36 +0000</pubDate>
      <link>https://forem.com/husayn01/from-zero-to-hero-front-end-development-projects-for-beginnerswith-source-code-5mo</link>
      <guid>https://forem.com/husayn01/from-zero-to-hero-front-end-development-projects-for-beginnerswith-source-code-5mo</guid>
      <description>&lt;p&gt;Welcome, fellow developers, to today's blog post where we will explore the world of simple web development projects that are ideal for beginners. Regardless of your age or technical background, these projects provide a playground for aspiring coders to grow their abilities and embark on a path to becoming a skilled programmer.&lt;/p&gt;




&lt;h3&gt;
  
  
  The Power of Building Front-End Projects:
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Building projects is akin to playing the stock market. It requires an investment of time and effort, and while success is not guaranteed, the process serves as a valuable learning experience.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Building projects is a lot like embarking on a thrilling adventure. It requires dedication, effort, and a willingness to step outside of your comfort zone. However, the rewards that come from building front-end projects are immeasurable.&lt;/p&gt;

&lt;p&gt;When you engage in building front-end projects, you are actively applying the knowledge you've acquired. By putting theory into practice, you solidify your understanding of concepts and develop problem-solving skills. Each project becomes an opportunity to explore new techniques, experiment with different approaches, and overcome challenges.&lt;/p&gt;

&lt;p&gt;The beauty of front-end projects lies in their versatility. You have the freedom to choose projects that align with your interests, allowing you to create something meaningful and engaging. &lt;/p&gt;

&lt;p&gt;Whether it's building a personal portfolio website, crafting a responsive landing page, or developing a dynamic JavaScript calculator, each project serves as a stepping stone on your journey to becoming a front-end development hero.&lt;/p&gt;

&lt;p&gt;Building projects not only helps you refine your technical skills, but it also nurtures your creativity. As you tackle design decisions, implement interactive features, and polish the user experience, you gain a deeper appreciation for the artistry behind web development. It's an opportunity to showcase your unique style and leave a lasting impression on your audience.&lt;/p&gt;




&lt;h2&gt;
  
  
  Beginner Projects for front end Developers
&lt;/h2&gt;

&lt;p&gt;Now, let's dive into the heart of the matter—the beginner projects that are both enjoyable and straightforward, suitable even for those with limited coding experience. These projects provide an opportunity to grasp essential front-end development concepts while making the learning process delightful.&lt;/p&gt;

&lt;h3&gt;
  
  
  Project 1: Simple website
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ilmISvFI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4zjuok3njuztg7bhylmm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ilmISvFI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4zjuok3njuztg7bhylmm.png" alt="Simple website" width="800" height="385"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Prerequisites:&lt;/strong&gt;&lt;br&gt;
To build a simple website, you'll need the following prerequisites:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;HTML: Understanding of HTML tags and structure to create the content and layout of the website.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSS: Familiarity with CSS selectors, styles, and layout techniques to design and customize the website's appearance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Basic Web Design Principles: Knowledge of fundamental web design principles, including visual hierarchy, typography, color theory, and user experience.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br&gt;
Building a simple website involves creating a digital presence to showcase information, products, or services in an accessible and user-friendly manner. Here's a breakdown of how you can approach building a simple website:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Planning and Content: Start by planning the purpose and goals of your website. Determine the target audience and define the content that you want to present to visitors. This could include text, images, videos, or other multimedia elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;HTML Structure: Create the basic HTML structure for your website. Use HTML tags to define headings, paragraphs, lists, links, images, and other content elements. Structure the content using semantic HTML for better accessibility and search engine optimization.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSS Styling: Apply CSS styles to enhance the visual appearance of your website. Use CSS selectors to target HTML elements and apply colors, fonts, spacing, and other visual properties. Create a cohesive design by considering typography, layout, and consistent styling across the website.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Layout and Navigation: Design the layout of your website to ensure a clear and intuitive user experience. Organize the content into logical sections and create a navigation menu to allow visitors to navigate between different pages or sections of your site. Consider using responsive design techniques to make your website mobile-friendly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Interactive Elements: Enhance user engagement by incorporating interactive elements into your website. This can include contact forms, image sliders, buttons, accordions, or other interactive components that provide a dynamic and engaging experience for visitors.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Testing and Optimization: Test your website across different browsers and devices to ensure it displays correctly and functions properly. Optimize your website's performance by minimizing file sizes, optimizing images, and utilizing caching techniques. Test for accessibility to ensure your website is usable by people with disabilities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Deployment and Domain: Choose a hosting provider and deploy your website to make it accessible on the internet. If you cannot afford to pay for a hosting plan, you can use &lt;a href="https://vercel.com/"&gt;vercel&lt;/a&gt; or &lt;a href="https://www.netlify.com/"&gt;netlify&lt;/a&gt;. They offer free hosting.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://tech-website01.netlify.app/"&gt;Live Demo&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Husayn01/Tech-Website"&gt;Source code&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Project 2: Quote generator
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FhPWI_8---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/09781flokn9p5asjbufm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FhPWI_8---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/09781flokn9p5asjbufm.png" alt="Quote generator" width="800" height="340"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Prerequisites:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Basic knowledge of HTML, CSS, and JavaScript.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Familiarity with HTML tags, CSS selectors, and JavaScript functions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Understanding of DOM manipulation and event handling in JavaScript.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Text editor or Integrated Development Environment (IDE) for coding.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Web browser for testing and previewing the project.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt; &lt;br&gt;
The quote generator project involves creating a web application that displays random quotes to the user when a button is clicked. It's a great project for beginners to practice their HTML, CSS, and JavaScript skills while learning about event handling and dynamic content manipulation.&lt;/p&gt;

&lt;p&gt;The project can be divided into the following steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;HTML Structure: Begin by setting up the HTML structure. Create a container element to hold the quote and a button for generating new quotes. Add appropriate IDs or classes to the necessary elements for easy access using JavaScript.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSS Styling: Apply CSS styling to make the quote generator visually appealing. Customize the font, colors, and layout to match your desired design. You can experiment with different CSS properties to achieve the desired look and feel.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JavaScript Functionality: Write JavaScript code to handle the button click event and generate random quotes. Define an array or object to store a collection of quotes. When the button is clicked, randomly select a quote from the collection and display it on the web page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dynamic Content Update: Use JavaScript to update the quote content dynamically. Access the necessary HTML elements using selectors or IDs and modify their text or &lt;code&gt;innerHTML&lt;/code&gt; property with the selected quote.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Optional: Additional Features: Once you have the basic functionality working, you can enhance the quote generator with additional features. For example, you can add a "Share" button to allow users to share quotes on social media, include animations for a more interactive experience, or provide the ability to filter quotes based on categories.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Throughout the project, test your code in a web browser to ensure everything is functioning as expected. You can also customize the project by adding your own styling or modifying the functionality to suit your preferences.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://random-quote-generator01.netlify.app/"&gt;Live Demo&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Husayn01/Random-Quote-Generator"&gt;Source code&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Project 3: Password Generator
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jgz_h8VO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l4o0vek6vb4fozq6qhe7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jgz_h8VO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l4o0vek6vb4fozq6qhe7.png" alt="Password Generator" width="800" height="360"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Prerequisites :&lt;/strong&gt;&lt;br&gt;
To build a password generator, you should have a basic understanding of the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;HTML: Knowledge of HTML is necessary to create the user interface elements such as input fields, buttons, and display areas.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSS: Familiarity with CSS will enable you to style the user interface and make it visually appealing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JavaScript: Proficiency in JavaScript is essential as it will be used to generate random passwords, handle user interactions, and manipulate the DOM to update the password display.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br&gt;
A password generator is a tool that creates random and secure passwords based on certain criteria. Here's a breakdown of how a password generator can be built:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;HTML Structure: Start by creating the necessary HTML structure to display the password generator interface. This typically includes input fields for specifying password length, check boxes for selecting character types (e.g., uppercase letters, lowercase letters, numbers, symbols), a button to generate the password, and an area to display the generated password.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JavaScript Functionality:&lt;br&gt;
Write a function that generates the password based on the user's specified criteria. This function will typically include the logic to randomly select characters from the desired character types and combine them to form the password.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Handle user interactions, such as retrieving the selected options (password length and character types) from the HTML elements and passing them to the password generation function.&lt;br&gt;
Update the DOM to display the generated password in the designated area.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Randomization and Secure Passwords:&lt;br&gt;
Utilize JavaScript's random number generation capabilities to ensure the password generated is random and secure.&lt;br&gt;
Consider using built-in functions like &lt;code&gt;Math.random()&lt;/code&gt; and array manipulation methods to randomly select characters from the chosen character types.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Optional Features:&lt;br&gt;
Allow users to customize the password criteria further, such as setting a minimum requirement for each character type or excluding certain characters.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implement additional functionalities like a "Copy to Clipboard" button to make it easier for users to use the generated password.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://password-generator02.netlify.app/"&gt;Live Demo&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Husayn01/password-generator"&gt;Source code&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Project 4:  Analog Clock
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S744lKBN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ts08hzroj80x6vy67mud.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S744lKBN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ts08hzroj80x6vy67mud.png" alt="Analog Clock" width="800" height="415"&gt;&lt;/a&gt;&lt;br&gt;
To build an analog clock, you'll need the following &lt;strong&gt;prerequisites:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Basic HTML: Familiarity with HTML tags and structure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Basic CSS: Understanding of CSS selectors, positioning, and transformations.&lt;br&gt;
Basic JavaScript: Knowledge of JavaScript functions, intervals, and DOM manipulation.&lt;br&gt;
&lt;strong&gt;Description:&lt;/strong&gt;&lt;br&gt;
Building an analog clock involves creating a visual representation of the current time using HTML, CSS, and JavaScript. Here's a breakdown of how you can approach building an analog clock:&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;HTML Structure: Start by creating the basic HTML structure for the clock. Typically, this would include a container element for the clock and nested elements for the clock face, hour hand, minute hand, and second hand.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSS Styling: Apply CSS styles to position and style the clock elements. Use CSS properties like position, transform, and border-radius to create the circular clock face and hands. Adjust the size, colors, and styling to achieve the desired visual appearance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JavaScript Logic: Write JavaScript code to update the position of the clock hands based on the current time. Use JavaScript's Date object to get the current time, and calculate the corresponding angles for the hour, minute, and second hands. Update the CSS transform property of each hand to rotate them accordingly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Clock Animation: To make the clock continuously update and display the correct time, use JavaScript's setInterval() function to repeatedly call a function that updates the clock hands. By specifying an appropriate interval (e.g., every second), the clock will continuously update to reflect the current time.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Responsive Design: Consider making the analog clock responsive by using CSS media queries. Adjust the size and layout of the clock elements for different screen sizes to ensure it displays well on various devices.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://analog-clock-01.vercel.app/"&gt;Live Demo&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Husayn01/Analog-Clock"&gt;Source code&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Project 5: Stopwatch
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WmTVj6_n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mhs8vunpiikygv6ajy52.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WmTVj6_n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mhs8vunpiikygv6ajy52.png" alt="Stopwatch" width="800" height="432"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Prerequisites:&lt;/strong&gt;&lt;br&gt;
To build a stopwatch using JavaScript, you'll need the following prerequisites:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;HTML: Understanding of HTML tags and structure to create the stopwatch display and UI elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSS: Familiarity with CSS selectors, styles, and layout techniques to design and customize the stopwatch's appearance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JavaScript: Knowledge of JavaScript functions, DOM manipulation, and event handling.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br&gt;
Building a stopwatch involves creating a functional timer that can measure elapsed time accurately. Here's a breakdown of how you can approach building a stopwatch using JavaScript:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;HTML Structure: Create the HTML structure for your stopwatch. Use HTML tags to define the stopwatch display, control buttons, and other necessary elements. Structure the layout using appropriate HTML elements and classes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSS Styling: Apply CSS styles to enhance the visual appearance of your stopwatch. Use CSS to customize the colors, fonts, and layout of the stopwatch interface. Apply styles to the display area, control buttons, and other elements to create a visually appealing design.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JavaScript Logic: Write JavaScript code to handle the stopwatch's functionality. Implement functions to start, stop, and reset the stopwatch. Use JavaScript's &lt;code&gt;setInterval()&lt;/code&gt; and &lt;code&gt;clearInterval()&lt;/code&gt; methods to measure elapsed time accurately and update the display accordingly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Button Interactivity: Add event listeners to the control buttons to capture user input. When the start button is clicked, start the stopwatch timer by invoking the appropriate functions. Similarly, clicking the stop button should pause the timer, and the reset button should reset the timer to zero.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Time Calculation: Use JavaScript's Date object or the &lt;code&gt;performance.now()&lt;/code&gt; method to measure elapsed time accurately. Calculate the time difference between the start and stop events and update the stopwatch display accordingly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Display Formatting: Format the stopwatch display to show the elapsed time in a user-friendly manner. Convert milliseconds to hours, minutes, seconds, and milliseconds as needed. Ensure that the display format is consistent and easy to read.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Responsive Design: Consider implementing responsive design techniques to ensure your stopwatch functions well on different screen sizes and devices. Use CSS media queries to adjust the layout and styling for optimal user experience.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Testing and Refinement: Test your stopwatch thoroughly, checking for accurate timekeeping and proper display. Debug any issues or errors that may arise during testing. Refine the design and functionality based on user feedback and testing results.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://stopwatch-husayn01.vercel.app/"&gt;Live Demo&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Husayn01/Stopwatch"&gt;Source code&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Project 6: Simple Javascript calculator
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Wuy9DNPX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9875njo2t7uyfx41yefe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Wuy9DNPX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9875njo2t7uyfx41yefe.png" alt="Simple Javascript calculator" width="800" height="475"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Prerequisites:&lt;/strong&gt;&lt;br&gt;
To build a simple JavaScript calculator, you'll need the following prerequisites:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;HTML: Understanding of HTML tags and structure to create the calculator interface.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSS: Familiarity with CSS selectors, styles, and layout techniques to design and customize the calculator's appearance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JavaScript: Knowledge of JavaScript functions, DOM manipulation, and event handling.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br&gt;
Building a simple JavaScript calculator involves creating a functional calculator interface that can perform basic arithmetic operations. Here's a breakdown of how you can approach building a simple JavaScript calculator:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;HTML Structure: Create the HTML structure for your calculator. Use HTML tags to define the calculator display, buttons, and other necessary elements. Structure the layout using appropriate HTML elements and classes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSS Styling: Apply CSS styles to enhance the visual appearance of your calculator. Use CSS to customize the colors, fonts, and layout of the calculator interface. Apply styles to the buttons, display area, and other elements to create an appealing design.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JavaScript Logic: Write JavaScript code to handle the calculator's functionality. Implement functions to perform arithmetic operations, handle user input, and update the display accordingly. Use JavaScript's addEventListener() method to handle button clicks and trigger the appropriate actions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Button Interactivity: Add event listeners to the calculator buttons to capture user input. When a button is clicked, retrieve the button value and perform the corresponding operation or update the display accordingly. Use JavaScript to handle decimal numbers, clear the display, or evaluate the final result.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Responsive Design: Consider implementing responsive design techniques to ensure your calculator functions well on different screen sizes and devices. Use CSS media queries to adjust the layout and styling for optimal user experience.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Testing and Refinement: Test your calculator thoroughly, checking for accurate calculations and proper display. Debug any issues or errors that may arise during testing. Refine the design and functionality based on user feedback and testing results.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://html-calculator.netlify.app/"&gt;Live Demo&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Husayn01/Javascript-calculator"&gt;Source code&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Project 7: Tic Tac Toe Game
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VYQ0CtXg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/anv6u7gpsyxo1u3itghq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VYQ0CtXg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/anv6u7gpsyxo1u3itghq.png" alt="Tic Tac Toe Game" width="800" height="492"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Prerequisites:&lt;/strong&gt;&lt;br&gt;
To build a Tic Tac Toe game, you'll need the following prerequisites:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;HTML: Familiarity with HTML tags and structure to create the game board and UI elements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSS: Understanding of CSS selectors, styles, and layout to visually design the game.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JavaScript: Knowledge of JavaScript functions, arrays, DOM manipulation, and event handling.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Description:&lt;/strong&gt;&lt;br&gt;
Building a Tic Tac Toe game involves creating a playable game board where two players take turns marking X and O symbols until one of them wins or the game ends in a draw. Here's a breakdown of how you can approach building a Tic Tac Toe game:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;HTML Structure: Begin by creating the basic HTML structure for the game board. Use a combination of &lt;/p&gt; elements or an HTML table to represent the grid of cells for the Tic Tac Toe board.
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSS Styling: Apply CSS styles to visually design the game board and UI elements. Use CSS to set the dimensions of the cells, customize the appearance of X and O symbols, and style the game status display.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;JavaScript Logic: Write JavaScript code to handle the game logic. Create data structures to represent the game board state, track player turns, and handle win conditions. Implement functions to update the board, check for a winning combination, and determine the game's outcome.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;User Interaction: Add event listeners to the game cells to handle player moves. When a player clicks on an empty cell, update the board state, display the corresponding symbol, and check for a win or draw. Allow players to take turns until the game is won or ends in a draw.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Game Outcome Display: Implement a display mechanism to show the game outcome. Update the UI to inform players when someone wins, the game ends in a draw, or it's the next player's turn. Optionally, provide a restart button to allow players to play again.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Optional Enhancements: You can further enhance the game by adding features like player names, score tracking, a timer, or an AI opponent for single-player mode. These enhancements can make the game more engaging and customizable.&lt;/p&gt;&lt;/li&gt;


&lt;p&gt;&lt;a href="https://tic-tac-toe-game01.vercel.app/"&gt;Live Demo&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Husayn01/Tic-Tac-Toe-Game"&gt;Source code&lt;/a&gt;&lt;/p&gt;


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

&lt;p&gt;building front-end projects is an excellent way to enhance your coding skills and embark on a journey from zero to hero in the world of web development. Regardless of your technical background, beginner projects provide an opportunity to grasp essential concepts while enjoying the learning process.&lt;/p&gt;

&lt;p&gt;We explored various beginner-friendly projects, such as a password generator, analog clock, tic-tac-toe game, and a simple website. These projects not only allow you to practice your coding skills but also serve as tangible proof of your progress as you create functional and visually appealing applications.&lt;br&gt;
Remember, the path to becoming a skilled front-end developer requires practice and hands-on experience. The more you immerse yourself in building projects, the closer you get to achieving your goal. Don't be afraid to experiment, make mistakes, and learn from them. Every project you undertake adds to your knowledge and expertise.&lt;/p&gt;

&lt;p&gt;With the right prerequisites in place, such as HTML, CSS, and JavaScript skills, you have a solid foundation to embark on these projects. By following the guidelines, planning your approach, and staying dedicated, you can build impressive projects that showcase your abilities.&lt;/p&gt;

&lt;p&gt;So, what are you waiting for? Start your coding journey today with these beginner projects and let your creativity flourish. With each project, you'll gain confidence, problem-solving skills, and a deeper understanding of front-end development.&lt;/p&gt;

&lt;p&gt;Remember, the path from zero to hero is about the dedication, passion, and willingness to learn. Embrace the power of building projects, and before you know it, you'll transform into a front-end development hero!&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

&lt;p&gt;My name is &lt;strong&gt;Hussaini Ahmed&lt;/strong&gt;, I am a &lt;strong&gt;front end developer&lt;/strong&gt;. I also write about front end languages, frameworks and latest technologies. I’d loved to hear your thought on this article. Feel free to drop a comment below or reach out to me via:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.upwork.com/freelancers/~018f66d92dda7e4417"&gt;Upwork&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Husayn01"&gt;Github&lt;/a&gt;&lt;br&gt;
&lt;a href="https://wa.me/message/PAGMWLPTLJAOK1"&gt;WhatsApp&lt;/a&gt;&lt;br&gt;
&lt;a href="https://mobile.twitter.com/Husayn_01"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/mwlite/in/hussaini-ahmed-a51232252"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>coding</category>
      <category>javascript</category>
    </item>
    <item>
      <title>JavaScript Closures: Understanding Private Variables, Callbacks, and Memoization for Efficient Code</title>
      <dc:creator>Hussaini Ahmed</dc:creator>
      <pubDate>Thu, 11 May 2023 23:16:16 +0000</pubDate>
      <link>https://forem.com/husayn01/javascript-closures-understanding-private-variables-callbacks-and-memoization-for-efficient-code-2ph4</link>
      <guid>https://forem.com/husayn01/javascript-closures-understanding-private-variables-callbacks-and-memoization-for-efficient-code-2ph4</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh7cpvfxyvnvlz7k3suqi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh7cpvfxyvnvlz7k3suqi.png" alt="javascript closure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;JavaScript is a powerful programming language that is used to create interactive websites and web applications. One of the most important concepts in JavaScript is closures. Closures can be a little tricky to understand at first, but once you get the hang of them, they can make your code much more powerful and flexible. In this article, we will explain what closures are, how they work, and how to use them in your code.&lt;/p&gt;




&lt;h2&gt;
  
  
  What are Closures?
&lt;/h2&gt;

&lt;p&gt;A closure is a function that has access to its parent function's variables, even after the parent function has returned. In other words, a closure is created when a function is defined inside another function, and the inner function has access to the outer function's variables. This means that the inner function "closes over" the variables of the outer function, hence the name closure.&lt;/p&gt;




&lt;h2&gt;
  
  
  How do Closures Work?
&lt;/h2&gt;

&lt;p&gt;To understand how closures work, let's look at an example. Consider the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function outer() {
 var name = "Hussaini";
 function inner() {
 console.log(name);
 }
 return inner;
}
var closure = outer();
closure();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, we define a function called &lt;code&gt;outer&lt;/code&gt; that contains a variable &lt;code&gt;name&lt;/code&gt; and a function &lt;code&gt;inner&lt;/code&gt;. The function &lt;code&gt;inner&lt;/code&gt; logs the value of &lt;code&gt;name&lt;/code&gt; to the console. We then return the function inner from outer and store it in a variable called &lt;code&gt;closure&lt;/code&gt;. Finally, we call the &lt;code&gt;closure&lt;/code&gt; function.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;When we call &lt;code&gt;closure()&lt;/code&gt;, it logs the value of &lt;code&gt;name&lt;/code&gt; to the console, even though name is not defined within the closure function itself. This is because &lt;code&gt;closure&lt;/code&gt; is a closure that has access to the variables of the &lt;code&gt;outer&lt;/code&gt; function, even though &lt;code&gt;outer&lt;/code&gt; has already returned.&lt;/p&gt;

&lt;p&gt;This may seem like a small and insignificant detail, but closures can be incredibly powerful when used correctly. They allow you to create functions that are both flexible and efficient, and can help you write code that is easier to read and maintain.&lt;/p&gt;




&lt;h2&gt;
  
  
  How to Use Closures?
&lt;/h2&gt;

&lt;p&gt;Now that we know what closures are and how they work, let's look at some examples of how to use them in your code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Creating Private Variables&lt;/strong&gt;&lt;br&gt;
One common use of closures is to create private variables. In JavaScript, all variables defined within a function are accessible to any nested functions within that function. This means that if you define a variable in a function, any functions defined within that function can also access that variable. 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;function outer() {
 var name = "Hussaini";
 function inner() {
 console.log(name);
 }
 inner();
}
outer();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, we define a function called &lt;code&gt;outer&lt;/code&gt; that contains a variable &lt;code&gt;name&lt;/code&gt; and a function &lt;code&gt;inner&lt;/code&gt;. The function &lt;code&gt;inner&lt;/code&gt; logs the value of &lt;code&gt;name&lt;/code&gt; to the console. We then call the &lt;code&gt;inner&lt;/code&gt; function from within the &lt;code&gt;outer&lt;/code&gt; function.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;When we call &lt;code&gt;outer()&lt;/code&gt;, it logs the value of &lt;code&gt;name&lt;/code&gt; to the console, because &lt;code&gt;inner&lt;/code&gt; has access to the name variable. However, this also means that any other functions defined within &lt;code&gt;outer&lt;/code&gt; would also have access to the &lt;code&gt;name&lt;/code&gt; variable, which may not always be desirable.&lt;/p&gt;

&lt;p&gt;To create a private variable that is only accessible to the&lt;code&gt;inner&lt;/code&gt;function, we can use a closure. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function outer() {
 var name = "Hussaini";
 function inner() {
 console.log(name);
 }
 return inner;
}
var closure = outer();
closure();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, we define a function called &lt;code&gt;outer&lt;/code&gt; that contains a variable &lt;code&gt;name&lt;/code&gt; and a function &lt;code&gt;inner&lt;/code&gt;. The function &lt;code&gt;inner&lt;/code&gt; is returned from &lt;code&gt;outer&lt;/code&gt; instead of being called directly. We then store the returned function in a variable called &lt;code&gt;closure&lt;/code&gt;. Finally, we call the &lt;code&gt;closure&lt;/code&gt; function.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;When we call &lt;code&gt;closure()&lt;/code&gt;, it logs the value of &lt;code&gt;name&lt;/code&gt; to the console, just like before. However, because &lt;code&gt;name&lt;/code&gt; is defined within the &lt;code&gt;outer&lt;/code&gt; function and not directly accessible outside of it, it is effectively a private variable that is only accessible through the closure created by &lt;code&gt;outer&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Creating Callback Functions&lt;/strong&gt;&lt;br&gt;
Another common use of closures is to create callback functions. A callback function is a function that is passed as an argument to another function and is executed when the original function completes. Callback functions can be used for a variety of purposes, such as handling user input or responding to server requests.&lt;/p&gt;

&lt;p&gt;Here's an example of how to create a callback function using closures:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function calculate(num1, num2, operation) {
 var result = operation(num1, num2);
 console.log("Result: " + result);
}
function add(num1, num2) {
 return num1 + num2;
}
function subtract(num1, num2) {
 return num1 - num2;
}
calculate(5, 10, add);
calculate(5, 10, subtract);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, we define a function called calculate that takes three arguments: num1, num2, and operation. The operation argument is expected to be a function that takes two numbers and returns their result. We then use the operation function to calculate the result of &lt;code&gt;num1&lt;/code&gt; and &lt;code&gt;num2&lt;/code&gt;, and log the result to the console.&lt;/p&gt;

&lt;p&gt;We also define two additional functions called &lt;code&gt;add&lt;/code&gt; and &lt;code&gt;subtract&lt;/code&gt; that take two numbers and return their sum and difference, respectively. We then call the calculate function twice, passing in the &lt;code&gt;add&lt;/code&gt; and &lt;code&gt;subtract&lt;/code&gt; functions as the operation argument each time.&lt;/p&gt;

&lt;p&gt;When we run this code, we should see the following output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Result: 15
//Result: -5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is because the &lt;code&gt;calculate&lt;/code&gt; function is using the operation function passed in as an argument to perform the calculation. This allows us to use different functions for different calculations without having to rewrite the calculate function every time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Memoization&lt;/strong&gt;&lt;br&gt;
Finally, closures can also be used for memoization, which is a technique for optimizing function performance by caching the results of expensive calculations. Memoization can be especially useful when dealing with recursive functions that perform the same calculations multiple times.&lt;/p&gt;

&lt;p&gt;Here's an example of how to use closures for memoization:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function fibonacci() {
 var cache = {};
 function calculate(n) {
 if (n in cache) {
 return cache[n];
 } else {
 if (n &amp;lt;= 1) {
 return n;
 } else {
 var result = calculate(n - 1) + calculate(n - 2);
 cache[n] = result;
 return result;
 }
 }
 }
 return calculate;
}
var fib = fibonacci();
console.log(fib(10));
console.log(fib(15));
console.log(fib(20));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this code, we define a function called &lt;code&gt;fibonacci&lt;/code&gt; that returns another function called &lt;code&gt;calculate&lt;/code&gt;. The calculate function takes a single argument n and uses memoization to calculate the nth Fibonacci number.&lt;/p&gt;

&lt;p&gt;We use a closure to create a cache object that stores the results of expensive calculations. If the result of the calculation for a given n value is already in the cache, we return that result instead of performing the calculation again. Otherwise, we calculate the result using a recursive call to calculate, store the result in the cache, and then return the result.&lt;/p&gt;

&lt;p&gt;Finally, we call the &lt;code&gt;fibonacci&lt;/code&gt; function to get the calculate function, and store it in a variable called fib. We then call the fib function three times with different values to calculate the 10th, 15th, and 20th Fibonacci numbers.&lt;/p&gt;

&lt;p&gt;When we run this code, we should see the following output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//55
//610
//6765
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is because the calculate function is using memoization to avoid performing the same calculations multiple times. This makes the function faster and more efficient.&lt;/p&gt;




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

&lt;p&gt;In conclusion, closures are a powerful feature of JavaScript that allow you to create functions with private variables and maintain state between function calls. Closures can also be used for creating callback functions and for memoization. By understanding how closures work, you can write more efficient and flexible JavaScript code.&lt;/p&gt;

&lt;p&gt;My name is &lt;strong&gt;Hussaini Ahmed&lt;/strong&gt;, I am a &lt;strong&gt;front end developer&lt;/strong&gt;. I also write about front end languages, frameworks and latest technologies. I’d loved to hear your thought on this article. Feel free to drop a comment below or reach out to me via:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.upwork.com/freelancers/~018f66d92dda7e4417" rel="noopener noreferrer"&gt;Upwork&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Husayn01" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;br&gt;
&lt;a href="https://wa.me/message/PAGMWLPTLJAOK1" rel="noopener noreferrer"&gt;WhatsApp&lt;/a&gt;&lt;br&gt;
&lt;a href="https://mobile.twitter.com/Husayn_01" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/mwlite/in/hussaini-ahmed-a51232252" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Unleashing the Full Potential of the CSS Box Model</title>
      <dc:creator>Hussaini Ahmed</dc:creator>
      <pubDate>Wed, 10 May 2023 00:07:06 +0000</pubDate>
      <link>https://forem.com/husayn01/unleashing-the-full-potential-of-the-css-box-model-526j</link>
      <guid>https://forem.com/husayn01/unleashing-the-full-potential-of-the-css-box-model-526j</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4p8-1O_S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1fvt0ndu6vjqob29iip0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4p8-1O_S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1fvt0ndu6vjqob29iip0.png" alt="css box model" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Everything in CSS has a box around it, and understanding these boxes is key to being able to create more complex layouts with CSS, or to align items with other items.&lt;/em&gt;&lt;br&gt;
 -&lt;strong&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/The_box_model"&gt;MDN Web Docs.&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Table of content
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prerequisite&lt;/li&gt;
&lt;li&gt;Explanation of the CSS box model&lt;/li&gt;
&lt;li&gt;Importance of understanding the box model&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. The Four Parts of the CSS Box Model&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;A. Content Box&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Definition and explanation&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How to manipulate the content box with example&lt;br&gt;
&lt;strong&gt;B. Padding&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Definition and explanation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How to manipulate the padding with example&lt;br&gt;
&lt;strong&gt;C. Border&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Definition and explanation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How to manipulate the border with example&lt;br&gt;
&lt;strong&gt;D. Margin&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Definition and explanation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How to manipulate the margin with example&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Understanding the Box Model in Practice&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Common CSS properties that interact with the box model&lt;/li&gt;
&lt;li&gt;Examples of how the box model affects layout and design&lt;/li&gt;
&lt;li&gt;Tips for working with the box model&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4.Common Box Model Issue: Problems with box sizing&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Explanation of the issue&lt;/li&gt;
&lt;li&gt;How to solve it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5. Conclusion&lt;/strong&gt;&lt;/p&gt;


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

&lt;p&gt;The CSS box model is like a container for every element on a webpage, and it helps us to control how much space each element takes up on the page. It is used to create and customize design and layout of elements on a webpage.&lt;/p&gt;
&lt;h3&gt;
  
  
  Prerequisite
&lt;/h3&gt;

&lt;p&gt;In other to fully understand CSS Box Model and all it entails, this is what you need to know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Basic Computer Literacy&lt;/li&gt;
&lt;li&gt;HTML Basics&lt;/li&gt;
&lt;li&gt;Styling with CSS&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Explanation of the CSS box model
&lt;/h3&gt;

&lt;p&gt;The CSS Box model is a fundamental concept in web development that governs how elements are displayed on a web page. The box model refers to the way in which elements are represented on a page, and it is based on the idea that every HTML element can be thought of as a &lt;strong&gt;rectangular box&lt;/strong&gt;. Each box contains four different areas:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;content&lt;/li&gt;
&lt;li&gt;Padding&lt;/li&gt;
&lt;li&gt;Border&lt;/li&gt;
&lt;li&gt;Margin&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Content&lt;/strong&gt; -  is the innermost area of the box and represents the actual content of the element. It includes text, images, video or any other media that are contained within the element.&lt;br&gt;
&lt;strong&gt;Padding&lt;/strong&gt; - is the area that surrounds the content area and contained within the border area.&lt;br&gt;
&lt;strong&gt;Border&lt;/strong&gt; - the border area goes around the padding and content and is contained within the margin area.&lt;br&gt;
&lt;strong&gt;Margin&lt;/strong&gt; - This is the outermost area of the box model, it surrounds the content, padding and border area.&lt;/p&gt;

&lt;p&gt;These four areas, together make up the &lt;strong&gt;box model&lt;/strong&gt;. Don't worry if you have no idea what any of these(content, Padding, Border, Margin) means at the moment, afterall it is only meant to serve as a introduction to the concepts. Later, in this article i will give in-depth explanation on them. &lt;/p&gt;
&lt;h3&gt;
  
  
  Importance of understanding the box model
&lt;/h3&gt;

&lt;p&gt;Understanding the CSS box model is crucial for web developers who want to create effective and visually appealing web pages. This concept is fundamental to how elements are displayed on a web page, and a solid  understanding of the box model is essential for creating layouts that work well across different devices and screen sizes.&lt;/p&gt;

&lt;p&gt;One of the most important reasons to understand the box model is that it affects how elements are positioned and sized on a web page. Since every element is thought of as a retangular box and the size and position is determined by the content, padding, border and margin of the element, this means that changing any of this properties(the content, padding, border and margin) can have significant impact on the layout of the page.&lt;/p&gt;

&lt;p&gt;In addition, understanding the box model is crucial for troubleshooting layout issues. When elements are not positioned or sized correctly on a web page, the box model can often provide valuable clues to the source of the problem.&lt;/p&gt;


&lt;h2&gt;
  
  
  The Four Parts of the CSS Box Model
&lt;/h2&gt;

&lt;p&gt;As earlier mentioned, the CSS box model is divided into four parts(content, Padding, Border, Margin). After successfully introducing the concept of CSS box model and highlighting it importance, we will proceed to discuss each of them in-depth, showing how to manipulate them using a few examples.&lt;/p&gt;
&lt;h3&gt;
  
  
  Content Box(Definition and explanation)
&lt;/h3&gt;

&lt;p&gt;Content box is the innermost area of the box and represents the actual content of the element. It includes text, images, video or any other media that are contained within the element. The size of the content box is determined by the width and height properties of the element, as well as any padding or borders that are added to the element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to manipulate the content box with example&lt;/strong&gt;&lt;br&gt;
For example, let's say we have a simple HTML paragraph element that contains some text. By default, the content box of the paragraph element will be sized to fit the text.&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;p&amp;gt;Hello, world!&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In CSS, we can manipulate the content box of this paragraph element in a variety of ways. For example, we can change the font size of the text by setting the &lt;code&gt;font-size&lt;/code&gt; property:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p {
   font-size: 20px;
   background-color: blue;
   color: white;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wV3XdbTV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ewb8sqdq5uf7fadjtg7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wV3XdbTV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ewb8sqdq5uf7fadjtg7.jpg" alt="css box model" width="670" height="189"&gt;&lt;/a&gt;&lt;br&gt;
This will increase the size of the text inside the content box, making the box itself larger to accommodate the text.&lt;br&gt;
We can also change the &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; of the content box using the width and height properties. For example, let's say we want to create a box that is &lt;code&gt;200px&lt;/code&gt; wide and &lt;code&gt;100px&lt;/code&gt; tall:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;p {
    background-color: blue;
    color: white;
    width: 200px;
    height: 100px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---lNh5qn5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p15xu2cnk3wv46e5e3rb.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---lNh5qn5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p15xu2cnk3wv46e5e3rb.jpg" alt="css box model" width="670" height="362"&gt;&lt;/a&gt;&lt;br&gt;
This will create a content box that is &lt;code&gt;200px&lt;/code&gt; wide and &lt;code&gt;100px&lt;/code&gt;tall, with the text inside the box wrapping to fit the available space. In addition to these basic examples, there are many other ways to manipulate the content box using CSS. For example, we can add images to the content box, set the line height to control the spacing between lines of text, or adjust the text alignment within the box&lt;/p&gt;
&lt;h3&gt;
  
  
  Padding (Definition and explanation)
&lt;/h3&gt;

&lt;p&gt;The padding of an HTML element is the space between the content box and the element's border. In other words, it's the amount of space between the content inside the element and the edge of the element. The padding can be thought of as a cushion that surrounds the content inside the element, creating a visual separation between the content and the border.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to manipulate the padding with example&lt;/strong&gt;&lt;br&gt;
Padding can be added to an element using the padding property in CSS. This property allows you to specify the amount of padding that you want to add to each side of the element, using a variety of units such as px, ems, or percentages. For example, the following CSS code would add &lt;code&gt;20px&lt;/code&gt; of padding to all sides of a &lt;code&gt;div&lt;/code&gt; element:&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&amp;gt;Hello, world!&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
  padding: 20px;
  background-color: blue;
  color: white;
}

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Pneyn60x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/41ro8knpn541ngskk8x5.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Pneyn60x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/41ro8knpn541ngskk8x5.jpg" alt="css box model" width="670" height="188"&gt;&lt;/a&gt;&lt;br&gt;
We can also specify different amounts of &lt;code&gt;padding&lt;/code&gt; for each side of the element using the &lt;code&gt;padding-top&lt;/code&gt;,&lt;code&gt;padding-right&lt;/code&gt;, &lt;code&gt;padding-bottom&lt;/code&gt;, and &lt;code&gt;padding-left&lt;/code&gt; properties. For example, the following CSS code would add &lt;code&gt;50px&lt;/code&gt; of padding to the top of a &lt;code&gt;div&lt;/code&gt; element, &lt;code&gt;20px&lt;/code&gt; of padding to the right and bottom and&lt;code&gt;80px&lt;/code&gt; padding to the left:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
  background-color: blue;
  color: white;
  padding-top: 50px;
  padding-right: 20px;
  padding-bottom: 20px;
  padding-left: 80px;
}

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FKJPHi51--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fgcbvmiatf16vk1fmpct.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FKJPHi51--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fgcbvmiatf16vk1fmpct.jpg" alt="css box model" width="670" height="204"&gt;&lt;/a&gt;&lt;br&gt;
Padding can be especially useful for creating visually appealing and easy-to-read layouts. By adding padding to an element, we can create a visual separation between the content and the border, making it easier for the user to read and understand the content. &lt;/p&gt;
&lt;h3&gt;
  
  
  Border(Definition and explanation)
&lt;/h3&gt;

&lt;p&gt;The border of an HTML element is a decorative or structural feature that surrounds the content and padding of an element. The border is typically used to visually separate elements from one another, or to create a sense of structure and hierarchy within a layout.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to manipulate the border with example.&lt;/strong&gt;&lt;br&gt;
Borders can be added to an element using the border property in CSS. This property allows you to specify the &lt;code&gt;width&lt;/code&gt;, &lt;code&gt;style&lt;/code&gt;, and color of the border. For example, the following CSS code would add a &lt;code&gt;1px&lt;/code&gt; wide solid black border to a &lt;code&gt;div&lt;/code&gt; element:&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&amp;gt;Hello, world!&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
  border: 1px solid black;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j3Qa0voA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pcjevd5u2mdgcypedz9k.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j3Qa0voA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pcjevd5u2mdgcypedz9k.jpg" alt="css box model" width="670" height="188"&gt;&lt;/a&gt;&lt;br&gt;
We can also specify the &lt;code&gt;width&lt;/code&gt;, &lt;code&gt;style&lt;/code&gt;, and &lt;code&gt;color&lt;/code&gt; of each side of the border using the &lt;code&gt;border-top&lt;/code&gt;, &lt;code&gt;border-right&lt;/code&gt;, &lt;code&gt;border-bottom&lt;/code&gt;, and &lt;code&gt;border-left&lt;/code&gt; properties. For example, the following CSS code would add a &lt;code&gt;2px&lt;/code&gt; wide dashed red border to the top of a &lt;code&gt;div&lt;/code&gt; element, and a &lt;code&gt;1px&lt;/code&gt; wide solid blue border to the left and right sides:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
  border-top: 2px dashed red;
  border-left: 1px solid blue;
  border-right: 1px solid blue;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rnbepXvf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/io6ty68njz8b9rurqszp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rnbepXvf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/io6ty68njz8b9rurqszp.jpg" alt="css box model" width="670" height="187"&gt;&lt;/a&gt;&lt;br&gt;
There are many different border styles and colors to choose from in CSS, including &lt;code&gt;solid&lt;/code&gt;, &lt;code&gt;dashed&lt;/code&gt;, &lt;code&gt;dotted&lt;/code&gt;, &lt;code&gt;double&lt;/code&gt;, &lt;code&gt;groove&lt;/code&gt;, &lt;code&gt;ridge&lt;/code&gt;, &lt;code&gt;inset&lt;/code&gt;, and &lt;code&gt;outset&lt;/code&gt;. Borders can also be rounded using the border-radius property, which allows you to specify the radius of the corners of the border.&lt;/p&gt;

&lt;p&gt;Borders can be especially useful for creating visually appealing and easy-to-read layouts. By adding a border to an element, we can create a visual separation between different elements on a page, making it easier for the user to navigate and understand the content.&lt;/p&gt;
&lt;h3&gt;
  
  
  Margin(Definition and explanation)
&lt;/h3&gt;

&lt;p&gt;The margin of an HTML element is the space outside of the element's border. In other words, it's the amount of space between the border of an element and the next closest element on the page. The margin can be thought of as a buffer zone that surrounds the element, creating a visual separation between the element and other elements on the page.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to manipulate the margin with example.&lt;/strong&gt;&lt;br&gt;
Margins can be added to an element using the margin property in CSS. This property allows you to specify the amount of margin that you want to add to each side of the element, using a variety of units such as px, ems, or percentages. For example, the following CSS code would add &lt;code&gt;20px&lt;/code&gt; of &lt;code&gt;margin&lt;/code&gt; to all sides of a &lt;code&gt;div&lt;/code&gt; element:&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&amp;gt;First Div&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;Second Div&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;Third Div&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
    background-color: blue;
    color: white;
    margin: 20px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iqL4AEbK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4u8rvshphd6gjd12yqrj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iqL4AEbK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4u8rvshphd6gjd12yqrj.jpg" alt="css box model" width="670" height="253"&gt;&lt;/a&gt;&lt;br&gt;
We can also specify different amounts of margin for each side of the element using the &lt;code&gt;margin-top&lt;/code&gt;, &lt;code&gt;margin-right&lt;/code&gt;, &lt;code&gt;margin-bottom&lt;/code&gt;, and &lt;code&gt;margin-left&lt;/code&gt; properties. For example, the following CSS code would add &lt;code&gt;20px&lt;/code&gt; of margin to all sides of the &lt;code&gt;div&lt;/code&gt; element except the first child which has a &lt;code&gt;20px&lt;/code&gt; margin to the top, &lt;code&gt;0px&lt;/code&gt; margin to the right, &lt;code&gt;80px&lt;/code&gt; margin to the bottom and &lt;code&gt;60px&lt;/code&gt;margin to the left.&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&amp;gt;First Div&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;Second Div&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;Third Div&amp;lt;/div&amp;gt;

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
    background-color: blue;
    color: white;
    margin: 20px;
}
div:first-child {
    margin-top: 20px;
    margin-right: 0px;
    margin-bottom: 80px;
    margin-left: 60px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wJzMeET6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3wg1e11eunvuxvqyk61p.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wJzMeET6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3wg1e11eunvuxvqyk61p.jpg" alt="css box model" width="670" height="353"&gt;&lt;/a&gt;&lt;br&gt;
Margins can be especially useful for creating visually appealing and easy-to-read layouts. By adding margin to an element, we can create a visual separation between different elements on the page, making it easier for the user to navigate and understand the content. Margins can also be used to add space around an element, creating a more balanced and visually pleasing layout.&lt;/p&gt;


&lt;h2&gt;
  
  
  Understanding the Box Model in Practice
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Common CSS properties that interact with the box model
&lt;/h3&gt;

&lt;p&gt;There are several common CSS properties that interact with the box model, including &lt;code&gt;width&lt;/code&gt;, height, padding, border, and margin. These properties allow developers to control the size, spacing, and appearance of elements on a page.&lt;/p&gt;

&lt;p&gt;For example, the width property controls the &lt;code&gt;width&lt;/code&gt; of an element's content box, while the &lt;code&gt;height&lt;/code&gt; property controls the height of the content box. The &lt;code&gt;padding&lt;/code&gt; property adds space between the content box and the element's border, while the &lt;code&gt;border&lt;/code&gt;property adds a border around the content box. Finally, the &lt;code&gt;margin&lt;/code&gt; property adds space between the element's border and the next closest element on the page.&lt;/p&gt;

&lt;p&gt;Examples of how the box model affects layout and design**&lt;/p&gt;

&lt;p&gt;The box model can have a significant impact on the layout and design of a web page. For example, consider a simple layout with two &lt;code&gt;div&lt;/code&gt; elements:&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="box1"&amp;gt;This is box 1.&amp;lt;/div&amp;gt;
&amp;lt;div class="box2"&amp;gt;This is box 2.&amp;lt;/div&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;By default, these two elements will be displayed one after the other, with no space between them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.box1 {
  width: 200px;
  height: 100px;
  background-color: red;
  color: white;
  padding: 20px;
}

.box2 {
  width: 200px;
  height: 100px;
  background-color: blue;
  color: white;
  padding: 20px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WY4h6el1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/alxyqfi34ytinr51ph9f.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WY4h6el1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/alxyqfi34ytinr51ph9f.jpg" alt="css box model" width="670" height="776"&gt;&lt;/a&gt;&lt;br&gt;
However, by adding margins and padding to these elements, we can create a more visually appealing and well-organized layout:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.box1 {
  width: 200px;
  height: 100px;
  background-color: red;
  color: white;
  margin-bottom: 20px;
  padding: 20px;
}

.box2 {
  width: 200px;
  height: 100px;
  background-color: blue;
  color: white;
  padding: 20px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_mf033Uk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7mnogjgs4kjm01fcmat9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_mf033Uk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7mnogjgs4kjm01fcmat9.jpg" alt="css box model" width="670" height="791"&gt;&lt;/a&gt;&lt;br&gt;
In this example, we've added a &lt;code&gt;20px&lt;/code&gt; margin to the bottom of &lt;code&gt;box1&lt;/code&gt;, and padding to both &lt;code&gt;box1&lt;/code&gt;and &lt;code&gt;box2&lt;/code&gt;. This creates space between the two boxes, and gives each box a more defined structure and visual hierarchy.&lt;/p&gt;

&lt;p&gt;** Tips for working with the box model**&lt;/p&gt;

&lt;p&gt;When working with the box model in CSS, there are a few important tips to keep in mind:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Be aware of how the box model affects the size of an element:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div&amp;gt;Hello world&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
  width: 200px;
  height: 100px;
  background-color: blue;
  color: white;
  padding: 20px;
  margin: 0px;
  border: none;

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

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UcxdUumI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/voxgs5vb95ja5rwi2n9x.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UcxdUumI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/voxgs5vb95ja5rwi2n9x.jpg" alt="css box model" width="670" height="405"&gt;&lt;/a&gt;&lt;br&gt;
In this example, the &lt;code&gt;div&lt;/code&gt; element has a &lt;code&gt;width&lt;/code&gt; of &lt;code&gt;200px&lt;/code&gt;, &lt;code&gt;height&lt;/code&gt; of &lt;code&gt;100px&lt;/code&gt;, a padding of &lt;code&gt;20px&lt;/code&gt;, a &lt;code&gt;margin&lt;/code&gt; of &lt;code&gt;0px&lt;/code&gt; and no border, its total width will be &lt;code&gt;240px&lt;/code&gt; and height will be &lt;code&gt;140px&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;this is because:&lt;br&gt;
&lt;strong&gt;total element width = width + left padding + right padding + left border + right border + left margin + right margin&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;total element height = height + top padding + bottom padding + top border + bottom border + top margin + bottom margin&lt;/strong&gt;&lt;br&gt;
so:&lt;br&gt;
total div width = 200px + 20px + 20px + 0px + 0px +  0px + 0px = &lt;strong&gt;240px&lt;/strong&gt;&lt;br&gt;
total div height = 100px + 20px + 20px + 0px + 0px +  0px + 0px = &lt;strong&gt;140px&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Note that we used &lt;code&gt;0px&lt;/code&gt; for all sides of the border because the border property was set to none, which is the same as &lt;code&gt;0px&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Always consider the impact of padding and margin on the overall layout of the page. Adding too much padding or margin can create a cluttered or disjointed layout.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the &lt;code&gt;box-sizing&lt;/code&gt; property to control how an element's size is calculated. By default, an element's size is calculated based on its content box. However, by setting &lt;code&gt;box-sizing: border-box&lt;/code&gt;, the size will be calculated based on the content box plus any padding and border.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
  box-sizing: border-box;
  width: 200px;
  height: 100px;
  background-color: blue;
  color: white;
  padding: 20px;
  margin: 0px;
  border: none;
}

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

&lt;/div&gt;


&lt;p&gt;This example has a total &lt;code&gt;width&lt;/code&gt; of &lt;code&gt;200px&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; of &lt;code&gt;100px&lt;/code&gt;regardless of the padding.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use the &lt;code&gt;outline&lt;/code&gt; property to create a visible outline around an element that doesn't affect its size or position. This can be useful for debugging or visualizing the layout of a page.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
  width: 200px;
  height: 100px;
  background-color: blue;
  color: white;
  padding: 20px;
  margin: 0px;
  border: none;
  outline: 3px solid black;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4hwUCOIo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mybxprgghi8qg9v5tbu0.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4hwUCOIo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mybxprgghi8qg9v5tbu0.jpg" alt="css box model" width="670" height="396"&gt;&lt;/a&gt;&lt;br&gt;
This example adds an outline of &lt;code&gt;3px&lt;/code&gt; to the &lt;code&gt;div&lt;/code&gt; element. This does not affect its size or position.&lt;/p&gt;

&lt;p&gt;By keeping these tips in mind, developers can create well-organized and visually appealing layouts using the box model in CSS.&lt;/p&gt;
&lt;h2&gt;
  
  
  Common Box Model Issue: Problems with box sizing
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Explanation of the issue:&lt;/strong&gt;&lt;br&gt;
One common issue with the box model is that the size of an element can be difficult to predict when padding and borders are added. By default, the &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; properties only apply to the content box of an element, while any padding or border is added on top of the content box. This means that if you set a width of &lt;code&gt;200px&lt;/code&gt; and then add &lt;code&gt;20px&lt;/code&gt; of padding and a &lt;code&gt;2px&lt;/code&gt; border, the actual width of the element will be &lt;strong&gt;244px (200 + 20 + 2)&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;div {
  width: 200px;
  background-color: blue;
  color: white;
  padding: 20px;
  border: 2


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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--An6Vw51V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2k6v8x38dqe71h2nxm30.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--An6Vw51V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2k6v8x38dqe71h2nxm30.jpg" alt="css box model" width="670" height="203"&gt;&lt;/a&gt;px solid black;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to solve it:&lt;/strong&gt;&lt;br&gt;
To avoid this issue, you can use the &lt;strong&gt;box-sizing&lt;/strong&gt; property. By setting &lt;code&gt;box-sizing: border-box&lt;/code&gt;, the &lt;strong&gt;width&lt;/strong&gt; and &lt;strong&gt;height&lt;/strong&gt; properties will apply to the content box plus any padding and border. This makes it easier to predict the size of an element, even when padding and borders are added.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;div {
  box-sizing: border-box;
  width: 200px;
  background-color: blue;
  color: white;
  padding: 20px;
  border: 3px solid black;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






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

&lt;p&gt;In this article, we covered the CSS box model, which is the foundation of layout in CSS. We explained how the box model works, including the content box, padding, border, and margin. We also discussed common issues with the box model and how to solve them. &lt;/p&gt;

&lt;p&gt;Understanding the CSS box model is essential for any web developer or designer. Without a solid understanding of the box model, it can be difficult to create consistent and responsive designs. By mastering the box model, you can create layouts that work well on a variety of devices and screen sizes, and you can avoid common layout issues that can cause frustration for users.&lt;/p&gt;

&lt;p&gt;My name is &lt;strong&gt;Hussaini Ahmed&lt;/strong&gt;, I am a &lt;strong&gt;front end developer&lt;/strong&gt;. I also write about front end languages, frameworks and latest technologies. I’d loved to hear your thought on this article. Feel free to drop a comment below or reach out to me via:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.upwork.com/freelancers/~018f66d92dda7e4417"&gt;Upwork&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Husayn01"&gt;Github&lt;/a&gt;&lt;br&gt;
&lt;a href="https://wa.me/message/PAGMWLPTLJAOK1"&gt;WhatsApp&lt;/a&gt;&lt;br&gt;
&lt;a href="https://mobile.twitter.com/Husayn_01"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/mwlite/in/hussaini-ahmed-a51232252"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>webdev</category>
      <category>coding</category>
    </item>
    <item>
      <title>How I built a Tic Tac Toe Game using vanilla Javascript.</title>
      <dc:creator>Hussaini Ahmed</dc:creator>
      <pubDate>Sun, 07 May 2023 00:30:15 +0000</pubDate>
      <link>https://forem.com/husayn01/how-i-built-a-tic-tac-toe-game-using-vanilla-javascript-40bh</link>
      <guid>https://forem.com/husayn01/how-i-built-a-tic-tac-toe-game-using-vanilla-javascript-40bh</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F16fo3y9k5h9ypibsxjle.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F16fo3y9k5h9ypibsxjle.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Tic Tac Toe is a classic game that many of us have played at some point in our lives. The game uses a 3×3 grid. The goal of the game is to be the first player to place three symbols in a straight horizontal, vertical, or diagonal row. If you are a beginner in the field of web development, building a game like Tic Tac Toe is a good start to help build and develop your programming skills.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Prerequisite&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To be able to develop a game like Tic Tac Toe, you will need a solid background knowledge in the following languages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTML&lt;/li&gt;
&lt;li&gt;CSS&lt;/li&gt;
&lt;li&gt;JavaScript&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Building a Tic Tac Toe Game with HTML, CSS, and JavaScript&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/Hussayn01/embed/eYPgGBN?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;br&gt;
To start building a Tic Tac Toe Game, we will need to create three seperate files(HTML, CSS, and JavaScript respectively). You can go ahead and open your favourite code editor and proceed to create the files.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;HTML Structure&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let's start by creating the HTML structure for our game. We will use a simple table to represent the game board. Each cell in the table will represent a position on the board. We will also create a&lt;br&gt;
 section to display the game score and a button to reset the game. Here is the code for our HTML structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
&amp;lt;!DOCTYPE html&amp;gt; &amp;lt;html lang="en"&amp;gt; 
    &amp;lt;head&amp;gt; &amp;lt;meta charset="UTF-8"&amp;gt; 
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&amp;gt; 
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt; 
    &amp;lt;link rel="stylesheet" href="style.css"&amp;gt; 
    &amp;lt;title&amp;gt;Tic Tac Toe Game&amp;lt;/title&amp;gt; 
&amp;lt;/head&amp;gt; 
&amp;lt;body&amp;gt; 
    &amp;lt;div id="main"&amp;gt; 
        &amp;lt;table&amp;gt; 
            &amp;lt;caption&amp;gt;Tic Tac Toe Game&amp;lt;/caption&amp;gt; 
            &amp;lt;tr&amp;gt; 
                &amp;lt;td id="0"&amp;gt;&amp;lt;/td&amp;gt; 
                &amp;lt;td id="1"&amp;gt;&amp;lt;/td&amp;gt; 
                &amp;lt;td id="2"&amp;gt;&amp;lt;/td&amp;gt; 
            &amp;lt;/tr&amp;gt; 
            &amp;lt;tr&amp;gt; 
                &amp;lt;td id="3"&amp;gt;&amp;lt;/td&amp;gt; 
                &amp;lt;td id="4"&amp;gt;&amp;lt;/td&amp;gt; 
                &amp;lt;td id="5"&amp;gt;&amp;lt;/td&amp;gt; 
            &amp;lt;/tr&amp;gt; 
            &amp;lt;tr&amp;gt; 
                &amp;lt;td id="6"&amp;gt;&amp;lt;/td&amp;gt; 
                &amp;lt;td id="7"&amp;gt;&amp;lt;/td&amp;gt; 
                &amp;lt;td id="8"&amp;gt;&amp;lt;/td&amp;gt; 
            &amp;lt;/tr&amp;gt;
        &amp;lt;/table&amp;gt;
        &amp;lt;div id="game-score"&amp;gt; 
            &amp;lt;h1 id="player"&amp;gt;&amp;lt;/h1&amp;gt; 
            &amp;lt;h3 id="text"&amp;gt;&amp;lt;/h3&amp;gt; 
        &amp;lt;/div&amp;gt; 
        &amp;lt;button id="reset-btn"&amp;gt;Reset Game&amp;lt;/button&amp;gt; 
&amp;lt;/div&amp;gt; &amp;lt;script src="script.js"&amp;gt;&amp;lt;/script&amp;gt; 
&amp;lt;/body&amp;gt; 
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code starts with the HTML5 doctype declaration and sets the language to English for the document. It then defines the head section of the document, which includes the meta tags for character set, compatibility mode, and viewport. The stylesheet for the game is also linked to the document.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;body&lt;/code&gt; section of the document contains a div element with an ID of "main" that wraps all the game elements, including a table with 3 rows and 3 columns to represent the Tic Tac Toe game board. Each cell of the table has a unique ID (0-8) to enable JavaScript code to access them easily.&lt;/p&gt;

&lt;p&gt;The code also includes a div element with an ID of "&lt;code&gt;game-score&lt;/code&gt;" to display the current game score, a heading element with an ID of "&lt;code&gt;player&lt;/code&gt;" to display the current player's turn, a subheading element with an ID of "text" to display game-related messages, and a button element with an ID of "&lt;code&gt;reset-btn&lt;/code&gt;" to reset the game when clicked.&lt;/p&gt;

&lt;p&gt;Finally, the code includes a script tag with the source attribute "&lt;code&gt;script.js&lt;/code&gt;," which will be used to write the JavaScript code for the Tic Tac Toe game.&lt;/p&gt;

&lt;p&gt;Now that we've added the HTML structure, let's proceed to include the CSS styling.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;CSS Styling&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/Hussayn01/embed/eYPgGBN?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Next, we will add some CSS styling to our HTML elements. We will use CSS to create a simple and clean interface for our game. We will also use CSS to define the style of our table cells, game score section, and reset button. Here is the code for our CSS styling:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#main{
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;#main&lt;/code&gt; selector applies the&lt;code&gt;display: flex&lt;/code&gt; property to the &lt;code&gt;main&lt;/code&gt; element and sets the &lt;code&gt;flex-direction&lt;/code&gt; to&lt;code&gt;column&lt;/code&gt;, which aligns the game elements in a vertical column. &lt;code&gt;justify-content&lt;/code&gt; and &lt;code&gt;align-items&lt;/code&gt; center the elements both horizontally and vertically, and &lt;code&gt;text-align&lt;/code&gt; centers the text within the main element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;table {
    display: block;
    border-collapse: collapse;
    margin: 20px auto;
}

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;table&lt;/code&gt; selector applies the &lt;code&gt;display: block&lt;/code&gt; property and &lt;code&gt;border-collapse: collapse&lt;/code&gt;, which removes the borders between cells on the table. It also sets the margin property to center the table horizontally.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;caption{
    font-size: 32px;
    margin: 24px auto;
}

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;caption&lt;/code&gt; selector sets the &lt;code&gt;font-size&lt;/code&gt; to 32px and adds &lt;code&gt;margin&lt;/code&gt; to center the caption within the table.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;td{
    border: 1px solid black;
    width: 80px;
    height: 80px;
    font-size: 48px;
    text-align: center;
    vertical-align: middle;
}


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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;td&lt;/code&gt; selector sets the &lt;code&gt;border&lt;/code&gt; property to 1px solid black, and sets the &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; properties to 80px. The &lt;code&gt;font-size&lt;/code&gt; is set to 48px to increase the size of the symbols and &lt;code&gt;text-align&lt;/code&gt; and &lt;code&gt;vertical-align&lt;/code&gt; properties are set to center the content within each cell.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;td:hover {
    background-color: #eee;
    cursor: pointer;
}

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;td:hover&lt;/code&gt; selector applies the &lt;code&gt;background-color&lt;/code&gt; of #eee to the table cell when the mouse hovers over it, and the cursor property is set to pointer to provide visual feedback to the user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;button {
    display: block;
    margin: 20px auto;
    padding: 10px 20px;
    font-size: 16px;
    border-radius: 5px;
    border: none;
    background-color: #4CAF50;
    color: white;
}

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;button&lt;/code&gt; selector sets the display property to block and the &lt;code&gt;margin&lt;/code&gt; property to center the button. It also sets the padding property,&lt;code&gt;font-size&lt;/code&gt;property, and &lt;code&gt;border-radius&lt;/code&gt; property to round the corners. The &lt;code&gt;border&lt;/code&gt; property is set to none, and the &lt;code&gt;background-color&lt;/code&gt; is set to #4CAF50, which is a shade of green, while the &lt;code&gt;color&lt;/code&gt; is set to white.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;button:hover {
    background-color: #3e8e41;
    cursor: pointer;
}

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;button:hover&lt;/code&gt; selector applies the &lt;code&gt;background-color&lt;/code&gt; of #3e8e41 to the button when the mouse hovers over it and the cursor property is set to pointer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#game-winner{
    display: none;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;#game-winner&lt;/code&gt; selector applies the &lt;code&gt;display: none&lt;/code&gt; property to the game-winner element to hide it by default, and it will be used to display the winner when the game ends.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;JavaScript Functionality&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Now, we will add JavaScript functionality to our game. We will use JavaScript to implement the game logic, handle user input, and update the game score. We will create functions to check for a winner&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Declare variables&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;
//Declare variables
let currentPlayer = 'X';
let gameEnded = false;
let gameMoves = ['', '', '', '', '', '', '', '', ''];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At the beginning of the JavaScript code, there are three variables declared - &lt;code&gt;currentPlayer&lt;/code&gt;, &lt;code&gt;gameEnded&lt;/code&gt;, and &lt;code&gt;gameMoves&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;currentPlayer&lt;/code&gt; variable keeps track of whose turn it is. It is initially set to 'X'.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;gameEnded&lt;/code&gt; variable is used to determine if the game has ended. It is initially set to false.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;gameMoves&lt;/code&gt; variable is an array that represents the state of the game. Each index in the array corresponds to a cell on the game board. The initial state of the &lt;code&gt;gameMoves&lt;/code&gt; array is an empty string for each cell.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Get DOM&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;//Get DOM
const boxes = document.querySelectorAll('td');
const table = document.querySelector('table');
const gameScore = document.querySelector('#game-score');
let player = document.querySelector('#player');
let text =  document.querySelector('#text');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the code uses the &lt;code&gt;querySelectorAll()&lt;/code&gt; method to select all the table cells (td elements) in the game board. It also selects the &lt;code&gt;table&lt;/code&gt;, the &lt;code&gt;#game-score&lt;/code&gt; element, the &lt;code&gt;#player element&lt;/code&gt;and &lt;code&gt;#text&lt;/code&gt; element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Add event listener to table cells&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;//add event listener to table boxes
  boxes.forEach((box, index) =&amp;gt;{
      box.addEventListener('click', ()=&amp;gt;{
          if (!gameEnded &amp;amp;&amp;amp; gameMoves[index] === '') {
              gameMoves[index] = currentPlayer;
              box.textContent = currentPlayer;
              //check for winner
              if (gameWin()) {
                  table.style.display = 'none';
                  gameScore.style.display = 'block';
                  player.textContent = currentPlayer;
                  text.textContent = 'WINNER';
                  gameEnded = true;
              }
              //check for tie
              else if (gameTie()) {
                  table.style.display = 'none';
                  gameScore.style.display = 'block';
                  player.textContent = 'XO';
                  text.textContent = 'DRAW';
                  gameEnded = true;
              } else{
                  currentPlayer = currentPlayer === 'X' ? '0' : 'X';
              }
          } 
      });
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A &lt;code&gt;forEach&lt;/code&gt; loop is used to add a click event listener to each table cell. When a table cell is clicked, the event listener triggers a function that checks if the game has ended, if the cell has already been clicked, and updates the &lt;code&gt;gameMoves&lt;/code&gt; array accordingly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check for winner function&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;//Check for winner function
  const gameWin = ()=&amp;gt;{
      const winningCombos = [
      [0, 1, 2], [3, 4, 5], [6, 7, 8], // rows
      [0, 3, 6], [1, 4, 7], [2, 5, 8], // columns
      [0, 4, 8], [2, 4, 6] // diagonals
    ];
    return winningCombos.some(combo=&amp;gt;{
      return combo.every(index=&amp;gt;{
          return gameMoves[index] === currentPlayer;
      })
    })
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;gameWin()&lt;/code&gt; function checks if the current player has won the game. It does this by checking if any of the winning combinations (rows, columns, or diagonals) have all the same value (either 'X' or '0').&lt;/p&gt;

&lt;p&gt;The function uses the &lt;code&gt;some()&lt;/code&gt; method to iterate through each winning combination and the &lt;code&gt;every()&lt;/code&gt; method to iterate through each index in the combination. If all the indexes in a combination have the same value as the current player, the function returns true, and the current player has won.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Check for tie function&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;//Check for tie function
  const gameTie = ()=&amp;gt;{
      return gameMoves.every(move =&amp;gt; {
          return move !== '';
      });
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;gameTie()&lt;/code&gt; function checks if the game is a tie. It does this by checking if all the cells on the game board have been clicked.&lt;/p&gt;

&lt;p&gt;The function uses the &lt;code&gt;every()&lt;/code&gt; method to iterate through each element in the &lt;code&gt;gameMoves&lt;/code&gt; array. If every element is not an empty string, the function returns true, and the game is a tie.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update game state&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If the current player has won the game, the table is hidden, and the &lt;code&gt;game-score&lt;/code&gt; div is displayed. The div displays the current player's move and the text 'WINNER'. The &lt;code&gt;gameEnded&lt;/code&gt; variable is set to &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If the game is a tie, the table is hidden, and the game-score div is displayed. The div displays 'XO' and the text 'DRAW'. The &lt;code&gt;gameEnded&lt;/code&gt; variable is set to true.&lt;/p&gt;

&lt;p&gt;If the game is not over, the &lt;code&gt;currentPlayer&lt;/code&gt; variable is updated to the other player.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reset game function&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;//Reset game function
  const resetGame = ()=&amp;gt;{
    table.style.display = 'block';
    gameScore.style.display = 'none';
    currentPlayer = 'X';
    gameEnded = false;
    gameMoves = ['', '', '', '', '', '', '', '', ''];
    boxes.forEach(box =&amp;gt; {
      box.textContent = '';
    });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Event listener for reset button
const resetButton = document.getElementById('reset-btn');
resetButton.addEventListener('click', resetGame);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;resetGame()&lt;/code&gt; function is called when the reset button is clicked. It sets the game back to its initial state by resetting the &lt;code&gt;gameMoves&lt;/code&gt; array, the &lt;code&gt;currentPlayer&lt;/code&gt; variable, and the &lt;code&gt;gameEnded&lt;/code&gt; variable. It also clears the text in each cell on the game board and hides the game-score div.&lt;/p&gt;

&lt;p&gt;Overall, this JavaScript code works by using a combination of event listeners, functions, and variables to keep track of the game state and update the game board as players make their moves. It also checks for a winner or tie and updates the game state accordingly. Finally, it provides a way to reset the game and start over.&lt;br&gt;
This is the complete javascript code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Declare variables
let currentPlayer = 'X';
let gameEnded = false;
let gameMoves = ['', '', '', '', '', '', '', '', ''];
//Get DOM
  const boxes = document.querySelectorAll('td');
  const table = document.querySelector('table');
  const gameScore = document.querySelector('#game-score');
  let player = document.querySelector('#player');
  let text =  document.querySelector('#text');
  //add event listener to table boxes
  boxes.forEach((box, index) =&amp;gt;{
      box.addEventListener('click', ()=&amp;gt;{
          if (!gameEnded &amp;amp;&amp;amp; gameMoves[index] === '') {
              gameMoves[index] = currentPlayer;
              box.textContent = currentPlayer;
              //check for winner
              if (gameWin()) {
                  table.style.display = 'none';
                  gameScore.style.display = 'block';
                  player.textContent = currentPlayer;
                  text.textContent = 'WINNER';
                  gameEnded = true;
              }
              //check for tie
              else if (gameTie()) {
                  table.style.display = 'none';
                  gameScore.style.display = 'block';
                  player.textContent = 'XO';
                  text.textContent = 'DRAW';
                  gameEnded = true;
              } else{
                  currentPlayer = currentPlayer === 'X' ? '0' : 'X';
              }
          } 
      });
  });
  //Check for winner function
  const gameWin = ()=&amp;gt;{
      const winningCombos = [
      [0, 1, 2], [3, 4, 5], [6, 7, 8], // rows
      [0, 3, 6], [1, 4, 7], [2, 5, 8], // columns
      [0, 4, 8], [2, 4, 6] // diagonals
    ];
    return winningCombos.some(combo=&amp;gt;{
      return combo.every(index=&amp;gt;{
          return gameMoves[index] === currentPlayer;
      })
    })
  }
  //Check for tie function
  const gameTie = ()=&amp;gt;{
      return gameMoves.every(move =&amp;gt; {
          return move !== '';
      });
  }
  //Reset game function
  const resetGame = ()=&amp;gt;{
    table.style.display = 'block';
    gameScore.style.display = 'none';
    currentPlayer = 'X';
    gameEnded = false;
    gameMoves = ['', '', '', '', '', '', '', '', ''];
    boxes.forEach(box =&amp;gt; {
      box.textContent = '';
    });
}

  //Event listener for reset button
  const resetButton = document.getElementById('reset-btn');
  resetButton.addEventListener('click', resetGame);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations, you've just learnt how to create a Tic Tac Toe game using HTML, CSS and Javascript. By now you should be able to build your own version, feel free to modify and use the code to build yours. Ensure you do not copy paste the code but rather write it from scratch and play around with the code to see if you can add new functionalities or edit existing ones to suit your needs. This will not only help you understand the code but also ensure you grow your coding skills faster.&lt;/p&gt;

&lt;p&gt;Conclusively, i want to thank you for finding time to read this article, i sincerely hope you enjoyed it, however if you come across any bugs whilst trying out the code, please do not hesitate to let me know.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/Hussayn01/embed/eYPgGBN?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;My name is &lt;strong&gt;Hussaini Ahmed&lt;/strong&gt;, I am a &lt;strong&gt;front end developer&lt;/strong&gt;. I also write about front end languages, frameworks and latest technologies. I’d loved to hear your thought on this article. Feel free to drop a comment below or reach out to me via:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.upwork.com/freelancers/~018f66d92dda7e4417" rel="noopener noreferrer"&gt;Upwork&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Husayn01" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;br&gt;
&lt;a href="https://wa.me/message/PAGMWLPTLJAOK1" rel="noopener noreferrer"&gt;WhatsApp&lt;/a&gt;&lt;br&gt;
&lt;a href="https://mobile.twitter.com/Husayn_01" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.linkedin.com/mwlite/in/hussaini-ahmed-a51232252" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

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