<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alfred Nwanokwai</title>
    <description>The latest articles on DEV Community by Alfred Nwanokwai (@zuxcode).</description>
    <link>https://dev.to/zuxcode</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%2F885269%2F9ce87e40-a702-4e6b-9ab7-250cb8e0efe6.jpg</url>
      <title>DEV Community: Alfred Nwanokwai</title>
      <link>https://dev.to/zuxcode</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zuxcode"/>
    <language>en</language>
    <item>
      <title>Conquer Version Control: Git &amp; GitHub - Your Beginner’s Guide</title>
      <dc:creator>Alfred Nwanokwai</dc:creator>
      <pubDate>Mon, 15 Apr 2024 01:13:50 +0000</pubDate>
      <link>https://dev.to/zuxcode/conquer-version-control-git-github-your-beginners-guide-3f89</link>
      <guid>https://dev.to/zuxcode/conquer-version-control-git-github-your-beginners-guide-3f89</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NP3Ndpf8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/318/1%2A3LJUSYjD0Kd57gux5kC4jw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NP3Ndpf8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/318/1%2A3LJUSYjD0Kd57gux5kC4jw.png" alt="" width="318" height="159"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Git and GitHub&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Ever lost precious code after accidentally overwriting it? Dread no more! Master version control with Git and GitHub, the powerful tools that let you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Effortlessly rewind your code to any previous state.&lt;/li&gt;
&lt;li&gt;Collaborate seamlessly with others on projects.&lt;/li&gt;
&lt;li&gt;Track every change made to your codebase.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This beginner-friendly guide will equip you with the essential skills to conquer Git and GitHub. We’ll break down key concepts into easy-to-follow steps, navigate the GitHub interface, and show you how to collaborate effectively. Get ready to unlock a stress-free coding experience and say goodbye to version control confusion!&lt;/p&gt;
&lt;h4&gt;
  
  
  How to Set Up Git for Your Machine
&lt;/h4&gt;

&lt;p&gt;Before diving into the world of Git and GitHub, you'll need Git installed on your local machine. The installation process varies slightly depending on your operating system. Here's a breakdown for the most common ones:&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;strong&gt;Install Git on Windows Machine:&lt;/strong&gt;
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Download the Git Installer: Head over to the official &lt;a href="https://git-scm.com/downloads"&gt;Git website&lt;/a&gt; and download the latest version of the installer for your system (32-bit or 64-bit).&lt;/li&gt;
&lt;li&gt;Run the Installer: Double-click the downloaded installer and follow the on-screen instructions. It’s recommended to keep the default options selected during installation. One important choice is selecting "Use Git from the Windows Command Prompt" if you want to use Git directly from the command prompt. Otherwise, Git Bash, a Unix-like shell environment, will be your primary tool for interacting with Git.&lt;/li&gt;
&lt;li&gt;Verify Installation: Open a command prompt (or Git Bash) and type
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git --version

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

&lt;/div&gt;


&lt;p&gt;If Git is installed correctly, you should see the installed version number displayed.&lt;/p&gt;
&lt;h4&gt;
  
  
  Install Git on macOS Machine:
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Using Homebrew (Recommended): If you’re comfortable with the command line and use a package manager like Homebrew, installing Git is a breeze. Open your terminal and run the following command:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew install git

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

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Using the Installer: Alternatively, you can download the official Git installer for macOS from the &lt;a href="https://git-scm.com/downloads"&gt;Git website&lt;/a&gt;. The installation process is straightforward - just follow the on-screen instructions.&lt;/li&gt;
&lt;li&gt;Verify Installation: Open your terminal and type
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git --version

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

&lt;/div&gt;


&lt;p&gt;If Git is installed successfully, you’ll see the installed version number displayed.&lt;/p&gt;
&lt;h4&gt;
  
  
  Install Git on Linux Machine:
&lt;/h4&gt;

&lt;p&gt;Most Linux distributions come with Git pre-installed. To check if it’s already available, open a terminal and type&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;If Git is not found, you can install it using your distribution’s package manager. The specific command will vary depending on your distro, but it’s typically something like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get install git

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

&lt;/div&gt;



&lt;p&gt;for Debian-based systems&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo yum install git

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

&lt;/div&gt;



&lt;p&gt;for RPM-based systems.&lt;/p&gt;

&lt;p&gt;Congratulations! You’ve successfully installed Git on your machine. Now you’re ready to explore the exciting world of version control and unlock the power of Git and GitHub!&lt;/p&gt;

&lt;h4&gt;
  
  
  Git for Beginners: Configuring Your Local User Information
&lt;/h4&gt;

&lt;p&gt;Now that you have Git installed, let’s personalize it! Git uses your name and email address to identify you when you commit changes to your code. Here’s how to configure your local user information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open your terminal or command prompt. This is where you’ll interact with Git using text commands.&lt;/li&gt;
&lt;li&gt;Run the following command:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --global user.name "Your Name"

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

&lt;/div&gt;



&lt;p&gt;Replace "Your Name" with your actual name. This sets the name associated with your Git commits.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Configure your email address:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --global user.email "your_email@example.com"

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

&lt;/div&gt;



&lt;p&gt;Run this command, replacing "your_&lt;a href="mailto:email@example.com"&gt;email@example.com&lt;/a&gt;" with your valid email address:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Verify your configuration (optional):&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use the following command to see your current Git settings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --list

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

&lt;/div&gt;



&lt;p&gt;This should display your username and email address under the &lt;code&gt;user.name&lt;/code&gt; and &lt;code&gt;user.email&lt;/code&gt; keys, respectively.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why is this important?
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Proper Attribution: When you commit changes to a project (local or remote), your username and email will be associated with those changes. This helps maintain a clear history of who made what modifications.&lt;/li&gt;
&lt;li&gt;Consistent Identity: Using the same email address across different Git repositories ensures a consistent identity within the Git ecosystem.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Set Your Default Branch Name (Optional):
&lt;/h4&gt;

&lt;p&gt;Run the following command to set "master" as your preferred default branch name for newly created repositories:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --global init.defaultBranch master

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

&lt;/div&gt;



&lt;p&gt;Note: This step is optional. The default branch name is typically master, but some projects might use main or a custom name. Choose the name that aligns with your project’s conventions.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why Set a Default Branch?
&lt;/h4&gt;

&lt;p&gt;Setting your preferred default branch name streamlines the process of creating new Git repositories. By default, Git uses master, but you can customize it to suit your workflow.&lt;/p&gt;

&lt;p&gt;Congratulations! You've successfully configured your local Git user information and (optionally) set your default branch name. Now you're ready to start using Git commands and interact with version control systems effectively!&lt;/p&gt;

&lt;h4&gt;
  
  
  Git Fundamentals
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Open your terminal or command prompt and navigate to the directory containing your project files.&lt;/li&gt;
&lt;li&gt;Type the following command and press Enter:&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Initializing Your Project:
&lt;/h4&gt;

&lt;p&gt;The first step to using Git with your project is to initialize a Git repository. This creates the essential structure for Git to track changes. Here’s how to do it:&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;If successful, Git will create a hidden folder called .git in your project directory. This folder stores all the Git-related information, including the history of your project’s changes.&lt;/p&gt;

&lt;h4&gt;
  
  
  Git status
&lt;/h4&gt;

&lt;p&gt;The git status command provides a snapshot of your project’s current state, revealing valuable information about changes and the overall Git workflow. Here’s how to use it:&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Adding Changes to the Staging Area
&lt;/h4&gt;

&lt;p&gt;Think of your working directory as your active workspace where you edit and modify project files. Git keeps track of changes through "commits," but before a commit happens, there’s a crucial step: staging. The git add command allows you to add specific changes from your working directory to a temporary holding zone called the staging area. These changes are then designated for inclusion in your next commit.&lt;/p&gt;

&lt;h4&gt;
  
  
  Git add
&lt;/h4&gt;

&lt;p&gt;There are two main ways to use git add:&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;&amp;lt;filename&amp;gt;&lt;/code&gt; with the actual name of the file you want to stage. This adds only that specific file to the staging area.&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;Or&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;Or&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;The dot (.) acts as a wildcard, signifying that you want to add all modified files in the current directory (excluding untracked files) to the staging area. This can be useful if you’ve made multiple changes and want to include them all in the next commit.&lt;/p&gt;

&lt;h4&gt;
  
  
  Removing a File from the Staging Area (Without Deleting the File):
&lt;/h4&gt;

&lt;p&gt;Let’s say you’ve added a file to the staging area using git add but decide you don’t want to include it in the next commit. You can remove it from the staging area without deleting the actual file from your working directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git rm --cached &amp;lt;filename&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;--cached&lt;/code&gt; flag tells Git to remove the file from the staging area only, leaving the physical file intact in your working directory.&lt;/p&gt;

&lt;h4&gt;
  
  
  git restore
&lt;/h4&gt;

&lt;p&gt;The git restore command in Git serves a dual purpose: restoring files and restoring the contents of the staging area.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git restore &amp;lt;filename&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;&amp;lt;filename&amp;gt;&lt;/code&gt; with the actual name of the file you want to restore.&lt;/p&gt;

&lt;h4&gt;
  
  
  Discarding vs. Restoring:
&lt;/h4&gt;

&lt;p&gt;By default, git restore discards any local modifications in the file. Use the&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git restore -k &amp;lt;filename&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;to keep those modifications while restoring the file content from another source.&lt;br&gt;&lt;br&gt;
Scenarios for Using git&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Imagine accidentally modifying a file or even deleting it. git restore can help you recover the file from a previous state.&lt;/li&gt;
&lt;li&gt;It allows you to restore a file to its condition at the last committed version (HEAD), the index (staging area), or a specific commit in your history.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Restoring the Staging Area:
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;git restore --staged&lt;/code&gt; command allows you to remove a file from the staging area without affecting the actual content of the file in your working directory. This is particularly useful when you’ve accidentally added changes or want to revise them before committing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git restore --staged &amp;lt;filename&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;&amp;lt;filename&amp;gt;&lt;/code&gt; with the actual name of the file you want to unstage.&lt;/p&gt;

&lt;h4&gt;
  
  
  Git Rename or move a File
&lt;/h4&gt;

&lt;p&gt;The git mv command in Git serves two purposes: renaming and moving files within your project’s repository. It’s a convenient way to manage changes to your file structure while keeping track of those changes in your version control history.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git mv &amp;lt;old filename&amp;gt; &amp;lt;new filename&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;&amp;lt;old filename&amp;gt;&lt;/code&gt; with the actual name of the file you want to rename or move and replace &lt;code&gt;&amp;lt;new filename&amp;gt;&lt;/code&gt; with the new name of the file you want.&lt;/p&gt;

&lt;h4&gt;
  
  
  Git Remove a File from Git’s Tracking (Staged or Unstaged):
&lt;/h4&gt;

&lt;p&gt;This command removes a file from both Git’s tracking and your working directory. It essentially erased the file from your project’s version control history and deletes it from your local filesystem.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git rm &amp;lt;filename&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;&amp;lt;filename&amp;gt;&lt;/code&gt; with the actual name of the file you want to delete and untrack.&lt;/p&gt;

&lt;h4&gt;
  
  
  Git &lt;code&gt;.gitignore&lt;/code&gt; File
&lt;/h4&gt;

&lt;p&gt;The .gitignore file is a plain text file located in the root directory of your Git repository. It acts as a set of instructions for Git, specifying files and patterns that should be excluded from version control. This prevents unnecessary files from being tracked by Git and cluttering your commit history.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new text file named &lt;code&gt;.gitignore&lt;/code&gt; (note the leading dot) in the root directory of your Git repository.&lt;/li&gt;
&lt;li&gt;Open the &lt;code&gt;.gitignore&lt;/code&gt; file in a text editor and add lines specifying the files or patterns you want to exclude.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Git Commit.
&lt;/h4&gt;

&lt;p&gt;Git commit acts like a save point in the history of your project. It captures a permanent record of the changes you’ve made to your files at a specific point in time. Imagine it like taking a picture of your project at a particular stage of development.&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Git Environment
&lt;/h3&gt;

&lt;p&gt;There are three environments in git&lt;/p&gt;

&lt;h4&gt;
  
  
  Working Files
&lt;/h4&gt;

&lt;p&gt;working files refer to the files in your project directory that have been modified but haven’t yet been added to the staging area for the next commit. Imagine your project directory as your messy desk. The working files are the papers, notes, and unfinished projects scattered around – they haven’t been organized or filed away yet.&lt;/p&gt;

&lt;h4&gt;
  
  
  Staging Area
&lt;/h4&gt;

&lt;p&gt;The staging area in Git acts like a holding zone for changes you plan to include in your next commit. Imagine you’re cleaning your room and have a pile of clothes on your bed. These are the modified files in your project that haven’t yet been "committed" or saved permanently&lt;/p&gt;

&lt;h4&gt;
  
  
  Commit
&lt;/h4&gt;

&lt;p&gt;commit represents a permanent snapshot of your project’s state at a specific point in time. It captures the changes you’ve made to the files that were staged using the git add command&lt;/p&gt;

&lt;h4&gt;
  
  
  Git Skip Staging
&lt;/h4&gt;

&lt;p&gt;The command &lt;code&gt;git commit -a -m "&amp;lt;commit message&amp;gt;"&lt;/code&gt; combines three functionalities in Git for creating a commit:&lt;/p&gt;

&lt;h4&gt;
  
  
  Staging all modified and deleted files (&lt;code&gt;-a&lt;/code&gt; flag):
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;-a&lt;/code&gt; flag with git commit instructs Git to automatically add all modified and deleted files in your working directory to the staging area.&lt;/li&gt;
&lt;li&gt;This bypasses the need for you to use &lt;code&gt;git add&lt;/code&gt; on individual files or patterns.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Creating a commit (&lt;code&gt;git commit&lt;/code&gt;):
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The core function of git commit is to capture a snapshot of the currently staged files and store it as a permanent record in your Git repository.&lt;/li&gt;
&lt;li&gt;This snapshot represents the state of your project at that specific point in time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Adding a commit message (&lt;code&gt;-m "&amp;lt;commit message&amp;gt;"&lt;/code&gt;):
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;The -m flag with git commit allows you to provide a descriptive message that explains the changes included in the commit.&lt;/li&gt;
&lt;li&gt;This message is crucial for understanding the project’s history and what modifications were made in that particular commit.&lt;/li&gt;
&lt;li&gt;Replace &lt;code&gt;&amp;lt;commit message&amp;gt;&lt;/code&gt; with a clear and concise explanation of the changes you’ve made.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Git Amend commit
&lt;/h4&gt;

&lt;p&gt;Amending a commit in Git allows you to modify an existing commit, but not directly. It’s like realizing you forgot to add something important to a photograph you just took, and wanting to fix it without having to retake the entire picture.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit -m "&amp;lt;message&amp;gt;" --amend

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Git log
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;git log&lt;/code&gt; command acts like a time machine for your project in Git. It allows you to explore the history of your project, revealing all the changes made to your codebase over time. It’s like flipping through a logbook that documents each significant event (commit) in your project’s journey.&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  What git log shows you:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Commit Hashes: Each commit is identified by a unique code (hash), allowing you to pinpoint specific versions of your project.&lt;/li&gt;
&lt;li&gt;Author Information: You see who made the commit (author name and email).&lt;/li&gt;
&lt;li&gt;Commit Date and Time: It displays the exact timestamp of when the commit was created.
Commit Message: This is the message you provided when creating the commit, ideally summarizing the changes made.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Enhancing git log with options:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Limiting the output: You can specify a number e.g.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git log -2

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

&lt;/div&gt;



&lt;p&gt;to see only the last two commits.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Filtering by author: Use
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git log --author="&amp;lt;name&amp;gt;"

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

&lt;/div&gt;



&lt;p&gt;to view commits made by a specific author.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Searching for keywords: Include a keyword after git log to search for commits containing that term in the message e.g.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git log fix

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

&lt;/div&gt;



&lt;p&gt;shows commits mentioning "fix"&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Abbreviated version: the
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git log --oneline

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

&lt;/div&gt;



&lt;p&gt;command provides a concise way to view your Git commit history.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Viewing full commit diff: Use
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git log -p

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

&lt;/div&gt;



&lt;p&gt;to see the detailed changes introduced in each commit.&lt;/p&gt;

&lt;h4&gt;
  
  
  Git diff
&lt;/h4&gt;

&lt;p&gt;The git diff command is a workhorse in Git, allowing you to compare the differences between various data sources within your project's version control system. Here's a breakdown of its functionalities:&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  What git diff can compare:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Working Directory vs. Staging Area: You can see the changes you’ve made in your working directory that haven’t yet been staged for the next commit.&lt;/li&gt;
&lt;li&gt;Staging Area vs. Repository: It can show the difference between the files currently staged and their most recent committed version in your Git repository.&lt;/li&gt;
&lt;li&gt;Two Commits: You can compare the changes introduced between any two specific commits in your project history.&lt;/li&gt;
&lt;li&gt;Working Directory vs. Specific Commit: It allows you to see how your working directory’s files differ from a particular commit in the past.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Common Options with git diff:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git diff --cached

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

&lt;/div&gt;



&lt;p&gt;shows the difference between the staging area and the latest commit (useful for reviewing staged changes).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git diff &amp;lt;commit_one&amp;gt; &amp;lt;commit_two&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;This syntax allows you to compare the specific commits&lt;/p&gt;

&lt;h3&gt;
  
  
  Git reset
&lt;/h3&gt;

&lt;p&gt;The git reset command in Git is a powerful tool for manipulating the state of your Git repository, but it’s important to understand its effects carefully before using it. It allows you to move the HEAD pointer (which points to the latest commit) to a different position in your commit history. However, unlike some other Git commands, git reset can have significant consequences, so it’s crucial to use it cautiously&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Modes of git reset:
&lt;/h4&gt;

&lt;p&gt;There are three primary modes of git reset, each affecting different parts of your Git repository:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;git reset  (soft reset): This mode moves the HEAD pointer to a specific commit but doesn’t modify the working directory or staging area. Your working directory remains unchanged, but any changes you made since the commit you reset to are no longer tracked by Git.
&lt;/li&gt;
&lt;/ul&gt;

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

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;git reset --mixed  (mixed reset - default): This mode moves the HEAD pointer and also discards any changes in the staging area (index). However, it keeps the changes in your working directory, leaving them untracked. This can be useful if you accidentally staged unwanted changes.
&lt;/li&gt;
&lt;/ul&gt;

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

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;git reset --hard  (hard reset): This is the most drastic mode. It moves the HEAD pointer, discards changes from the staging area (like mixed reset), and also discards all uncommitted changes in your working directory. This essentially reverts your working directory to the state it was in at the specified commit.
&lt;/li&gt;
&lt;/ul&gt;

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

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Collaborative Workflows with Git and GitHub
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Git branch
&lt;/h4&gt;

&lt;p&gt;Git branch command is fundamental for managing different lines of development in your project. Here’s a breakdown of what it allows you to do:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creating Branches: Imagine you’re working on a new feature or fixing a bug. You can use
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch &amp;lt;branch_name&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;to create a new branch isolated from the main development line (often called master). This creates a copy of the latest commit at that point, allowing you to work on your changes without affecting the main project code.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Listing Branches: Use
&lt;/li&gt;
&lt;/ul&gt;

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

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

&lt;/div&gt;



&lt;p&gt;on its own to display a list of all the existing branches in your local repository. It will indicate which branch is currently checked out (usually identified by an asterisk).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Switching Branches: Once you have multiple branches, you can switch between them using
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout &amp;lt;branch_name&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;Or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git switch &amp;lt;branch_name&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;This changes your working directory to reflect the content of the specified branch.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deleting Branches: When a branch’s work is complete and merged into the main codebase, you can delete it using
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch -d &amp;lt;branch_name&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;Or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout -d &amp;lt;branch_name&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;However, it’s generally recommended to only delete branches that have already been merged and are no longer needed.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;create branch and switch branch :Combine checkout with branch creation using
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout -b &amp;lt;branch_name&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;Or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git switch -c &amp;lt;branch_name&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;This creates a new branch and switches to it simultaneously.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Force switch branch: switches branches even if you have uncommitted changes in your working directory (use with caution as it can lead to data loss).
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout -f &amp;lt;branch_name&amp;gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Detached HEAD State:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Running&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout &amp;lt;commit_hash&amp;gt; 

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

&lt;/div&gt;



&lt;p&gt;allows you to checkout a specific commit. This detaches your HEAD pointer from any branch and points it directly to that commit. Your working directory reflects the state of the chosen commit, but you’re not technically on any particular branch.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Restoring Files:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you’ve accidentally deleted a file or want to revert changes, git checkout can help. Use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout &amp;lt;filename&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;to restore the file from the latest committed version in your current branch.&lt;/p&gt;

&lt;h4&gt;
  
  
  Merge branch
&lt;/h4&gt;

&lt;p&gt;The git merge command in Git plays a vital role in combining changes from different branches into your project’s history. It allows you to seamlessly integrate work done on separate branches and maintain a clear, unified codebase.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git merge -m &amp;lt;"message"&amp;gt; &amp;lt;branch_name&amp;gt;

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Resolving Merge Conflicts:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Git will mark the conflicting sections in the affected files with special markers (usually &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; and &amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;). You need to manually edit these files, choose the desired changes, and remove the conflict markers to create a resolved version.&lt;/li&gt;
&lt;li&gt;Once you’ve resolved all conflicts and staged the changes, you can use git commit to create a new merge commit that captures the combined history of both branches.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Adding Remotes:
&lt;/h3&gt;

&lt;p&gt;To connect your local repository to a remote one, use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote add &amp;lt;remote_name&amp;gt; &amp;lt;url&amp;gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;remote_name&amp;gt;&lt;/code&gt; is a name you choose to identify the remote repository (e.g., "origin" is a common convention).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;url&amp;gt;&lt;/code&gt; is the web address of the remote repository.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Fetching and Pulling:
&lt;/h3&gt;

&lt;p&gt;Once you have a remote configured, you can use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git fetch &amp;lt;remote_name&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;to retrieve information about the remote branches and commits without actually merging them into your local repository.&lt;/p&gt;

&lt;p&gt;Then&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;To merge the changes.&lt;/p&gt;

&lt;h4&gt;
  
  
  Git pull
&lt;/h4&gt;

&lt;p&gt;git pull is a streamlined way to fetch updates and merge them into your local branch, keeping your project synchronized with the remote repository&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Managing Remotes:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;You can rename an existing remote using
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote rename &amp;lt;old_name&amp;gt; &amp;lt;new_name&amp;gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To remove a remote connection entirely, use
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote remove &amp;lt;remote_name&amp;gt;

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Git push
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Making the first push to a remote branch:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code&gt;git push -u&lt;/code&gt; command in Git is a shortcut specifically designed to streamline your workflow when pushing commits to a remote repository for the first time&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push -u &amp;lt;remote_name&amp;gt; &amp;lt;branch_name&amp;gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Pushing Changes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The core function is to upload your local branch commits to a remote repository. This typically involves specifying the remote repository and the branch name you want to push to.&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  git rebase
&lt;/h3&gt;

&lt;p&gt;The git rebase command in Git allows you to rewrite your commit history by rearranging, squashing, or editing commits. It’s a powerful tool, but it’s important to understand its implications before using it, especially in collaborative workflows.&lt;/p&gt;

&lt;p&gt;Checkout to a different branch and run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git rebase master

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

&lt;/div&gt;



&lt;p&gt;The command git rebase master specifically instructs Git to rebase your current local branch on top of the master branch. Here’s what it does and some key considerations:&lt;/p&gt;

&lt;h4&gt;
  
  
  Reordering Commits:
&lt;/h4&gt;

&lt;p&gt;Imagine you have a series of commits on your local branch, and you decide the order doesn’t logically reflect the development process. git rebase allows you to replay your commits on top of a different base commit, effectively changing their order.&lt;/p&gt;

&lt;h4&gt;
  
  
  Squashing and Editing Commits:
&lt;/h4&gt;

&lt;p&gt;You can use git rebase to combine multiple commits into a single commit (squashing). This can help clean up your commit history and make it easier to understand.&lt;br&gt;&lt;br&gt;
Additionally, you can edit individual commits by making changes to their message or code during the rebasing process.&lt;/p&gt;
&lt;h4&gt;
  
  
  Interactive Rebasing:
&lt;/h4&gt;

&lt;p&gt;The most powerful form of rebasing is interactive rebasing, initiated with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git rebase -i &amp;lt;branch_name&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;This opens an interactive editor where you can see a list of your commits. You can then choose to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;pick: Keep the commit unchanged. (default)&lt;/li&gt;
&lt;li&gt;squash: Combine the commit with the previous commit.&lt;/li&gt;
&lt;li&gt;fixup: Similar to squash, but discards the commit message of the current commit.&lt;/li&gt;
&lt;li&gt;edit: Modify the content and message of the commit.&lt;/li&gt;
&lt;li&gt;drop: Discard the commit entirely.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git rebase -i --root

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

&lt;/div&gt;



&lt;p&gt;is an advanced Git operation that allows you to rewrite your entire Git repository’s history from the very beginning (the root commit). It involves interactive rebasing, giving you fine-grained control over how you rearrange, squash, or edit commits across your entire commit history.&lt;/p&gt;

&lt;h4&gt;
  
  
  Due to the potential for disrupting your entire history and causing issues for collaborators, it’s generally recommended to avoid using &lt;code&gt;git rebase -i --root&lt;/code&gt; unless you fully understand its implications and have a specific need for such a drastic rewrite.
&lt;/h4&gt;

&lt;p&gt;Congratulations! You’ve unlocked Git &amp;amp; GitHub! Now you can collab seamlessly, track changes with ease, and conquer version control. Want more? &lt;a href="https://zuxcode.medium.com/subscribe"&gt;Subscribe to our newsletter&lt;/a&gt; for new articles and follow us on Twitter &lt;a href="http://x.com/zuxcode"&gt;@zuxcode&lt;/a&gt; for discussions and updates. Happy coding!&lt;/p&gt;

</description>
      <category>github</category>
      <category>technology</category>
      <category>programming</category>
      <category>git</category>
    </item>
    <item>
      <title>How to create an animated hamburger menu</title>
      <dc:creator>Alfred Nwanokwai</dc:creator>
      <pubDate>Fri, 08 Mar 2024 15:45:53 +0000</pubDate>
      <link>https://dev.to/zuxcode/how-to-create-an-animated-hamburger-menu-2m02</link>
      <guid>https://dev.to/zuxcode/how-to-create-an-animated-hamburger-menu-2m02</guid>
      <description>&lt;p&gt;In today's fast-paced digital world, capturing user attention is crucial. A well-designed website not only looks good but also provides a seamless user experience. One way to achieve this is by incorporating interactive elements, like an animated hamburger menu.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a hamburger menu?
&lt;/h2&gt;

&lt;p&gt;A hamburger menu, also known as a three-line menu, is a popular navigation icon commonly used on websites, especially on mobile devices. It consists of three horizontal lines stacked on top of each other, resembling a hamburger patty. When clicked, it expands to reveal the website's navigation links.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why animate your hamburger menu?
&lt;/h2&gt;

&lt;p&gt;Static hamburger menus can sometimes appear bland and uninviting. Adding an animation can bring your menu to life, making it more visually appealing and engaging for users. This can lead to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Increased user interaction:&lt;/strong&gt; A dynamic menu can spark curiosity and encourage users to explore your website's navigation.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enhanced user experience:&lt;/strong&gt; A smooth and visually pleasing animation can elevate the overall user experience on your website.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved brand identity:&lt;/strong&gt; A unique and creative animation can contribute to your website's brand personality and leave a lasting impression on visitors.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Creating an animated hamburger menu with CSS
&lt;/h2&gt;

&lt;p&gt;create an index.html file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Animated Hamburger Menu&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"./css/style.css"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;body&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"flex"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"frame flex"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"hamburger"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"hamburger__animated hamburger--before"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"hamburger__animated"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"hamburger__animated hamburger--after"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"./js/script.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Hamburger Menu Styling:&lt;/strong&gt; The &lt;code&gt;.hamburger&lt;/code&gt; class styles the overall hamburger menu element, including its position, height, width, cursor, and hover effect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.hamburger&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;pointer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Animated Lines:&lt;/strong&gt; The &lt;code&gt;.hamburger__animated&lt;/code&gt; class styles the three lines of the hamburger menu. It defines their position, width, height, background color, transition properties, and border-radius. The &lt;code&gt;.hamburger--before&lt;/code&gt; and &lt;code&gt;.hamburger--after&lt;/code&gt; classes target the top and bottom lines of the menu, respectively.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.hamburger__animated&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#fff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;all&lt;/span&gt; &lt;span class="n"&gt;ease-in-out&lt;/span&gt; &lt;span class="m"&gt;0.2s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;box-shadow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="m"&gt;3px&lt;/span&gt; &lt;span class="n"&gt;rgba&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.hamburger--before&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.hamburger--after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Hover Animation:&lt;/strong&gt; The hover state of the &lt;code&gt;.hamburger&lt;/code&gt; element triggers various animation effects on the lines using additional classes like &lt;code&gt;.hamburger__animated--top&lt;/code&gt;, &lt;code&gt;.hamburger__animated--before-rotate&lt;/code&gt;, etc. These classes modify properties like top, transform, visibility, and width to create the animation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.hamburger&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt;
&lt;span class="nc"&gt;.hamburger__animated&lt;/span&gt;&lt;span class="nd"&gt;:not&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;.hamburger--before&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;.hamburger--after&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;60px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.hamburger&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="nc"&gt;.hamburger--after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;70px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.hamburger__animated--top&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.hamburger__animated--before-rotate&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;45deg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;transition-delay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.2s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.hamburger__animated--rotate&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-45deg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;transition-delay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.2s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.hamburger__animated--transparent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;visibility&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;hidden&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.hamburger__animated--width&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt; &lt;span class="cp"&gt;!important&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Added a little more CSS to make it look awesome&lt;br&gt;
&lt;/p&gt;

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

&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#8a50f8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.frame&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;400px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;400px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;linear-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;145deg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;#9456ff&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;#7c48df&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;box-shadow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;13px&lt;/span&gt; &lt;span class="m"&gt;13px&lt;/span&gt; &lt;span class="m"&gt;22px&lt;/span&gt; &lt;span class="m"&gt;#7946da&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;-13px&lt;/span&gt; &lt;span class="m"&gt;-13px&lt;/span&gt; &lt;span class="m"&gt;22px&lt;/span&gt; &lt;span class="m"&gt;#9b5aff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the full CSS code.&lt;br&gt;
&lt;/p&gt;

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

&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#8a50f8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.frame&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;400px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;400px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;linear-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;145deg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;#9456ff&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;#7c48df&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;box-shadow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;13px&lt;/span&gt; &lt;span class="m"&gt;13px&lt;/span&gt; &lt;span class="m"&gt;22px&lt;/span&gt; &lt;span class="m"&gt;#7946da&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;-13px&lt;/span&gt; &lt;span class="m"&gt;-13px&lt;/span&gt; &lt;span class="m"&gt;22px&lt;/span&gt; &lt;span class="m"&gt;#9b5aff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.hamburger&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;pointer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.hamburger__animated&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#fff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;all&lt;/span&gt; &lt;span class="n"&gt;ease-in-out&lt;/span&gt; &lt;span class="m"&gt;0.2s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;box-shadow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt; &lt;span class="m"&gt;3px&lt;/span&gt; &lt;span class="n"&gt;rgba&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.hamburger--before&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.hamburger--after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.hamburger&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt;
&lt;span class="nc"&gt;.hamburger__animated&lt;/span&gt;&lt;span class="nd"&gt;:not&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;.hamburger--before&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;.hamburger--after&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;60px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.hamburger&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="nc"&gt;.hamburger--after&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;70px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.hamburger__animated--top&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.hamburger__animated--before-rotate&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;45deg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;transition-delay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.2s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.hamburger__animated--rotate&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;-45deg&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;transition-delay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0.2s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.hamburger__animated--transparent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;visibility&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;hidden&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.hamburger__animated--width&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt; &lt;span class="cp"&gt;!important&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;Here is the full JavaScript code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;hamburger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.hamburger&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;burger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.hamburger__animated&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="cm"&gt;/*
* Initializes a boolean variable named 
* showMenu to false,  indicating that 
* the menu is initially hidden.
**/&lt;/span&gt;
 &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;showMenu&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/**
 * a function named rotate that 
 * handles the animation of the 
 * hamburger menu icon
**/&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rotate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;burger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;burger&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hamburger__animated--transparent&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;burger&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hamburger__animated--rotate&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;burger&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hamburger__animated--before-rotate&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="cm"&gt;/*
 * The function body uses an 
 * `if...else` statement to 
 * handle two scenarios: showing 
 * and hiding the menu.
**/&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;toggleMenu&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;showMenu&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;burger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;burger&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hamburger__animated--width&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nx"&gt;burger&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hamburger__animated--top&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;showMenu&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;burger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="nx"&gt;burger&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hamburger__animated--rotate&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;burger&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hamburger__animated--before-rotate&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;rotate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;burger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;burger&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;classList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hamburger__animated--top&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hamburger__animated--transparent&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hamburger__animated--width&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nx"&gt;showMenu&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;hamburger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;toggleMenu&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

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

&lt;/div&gt;



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

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>JavaScript String Methods: 20 Essential Techniques for Effective String Manipulation</title>
      <dc:creator>Alfred Nwanokwai</dc:creator>
      <pubDate>Thu, 08 Jun 2023 17:41:41 +0000</pubDate>
      <link>https://dev.to/zuxcode/javascript-string-methods-20-essential-techniques-for-effective-string-manipulation-224c</link>
      <guid>https://dev.to/zuxcode/javascript-string-methods-20-essential-techniques-for-effective-string-manipulation-224c</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j-MZgpxj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2AdKqvIxYDwr0UpeQaaDOO-w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j-MZgpxj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/1024/1%2AdKqvIxYDwr0UpeQaaDOO-w.png" alt="javascript string method" width="800" height="800"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;source: instagram | codeauthor&lt;/em&gt;_&lt;/p&gt;

&lt;p&gt;Welcome to my blog post where we’ll dive into the world of JavaScript string methods. Strings play a crucial role in JavaScript, and having a strong grasp of the available string manipulation techniques is essential for any developer. In this comprehensive guide, we will explore 20 powerful JavaScript string methods that will empower you to handle strings with ease and efficiency. Get ready to unlock the full potential of JavaScript string methods and take your coding skills to the next level!&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;String Length (length):
The &lt;code&gt;length&lt;/code&gt; property allows you to determine the number of characters in a string. Here’s an example:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const message = "Hello, world!";
console.log(message.length); // Output: 13

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

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Concatenation (concat):
The &lt;code&gt;concat()&lt;/code&gt; method combines two or more strings, creating a new string. Here’s an example:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const str1 = "Hello";
const str2 = "World";
const concatenatedStr = str1.concat(", ", str2);
console.log(concatenatedStr); // Output: Hello, World
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Extracting Substrings (substring):
The &lt;code&gt;substring()&lt;/code&gt; method extracts a portion of a string based on specified start and end indexes. Here’s an example:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sentence = "JavaScript is amazing!";
const extractedStr = sentence.substring(0, 10);
console.log(extractedStr); // Output: JavaScript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Searching for Substrings (indexOf):
The &lt;code&gt;indexOf()&lt;/code&gt; method locates the first occurrence of a specified substring within a string. Here’s an example:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sentence = "JavaScript is amazing!";
const index = sentence.indexOf("is");
console.log(index); // Output: 11
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Replacing Substrings (replace):
The &lt;code&gt;replace()&lt;/code&gt; method substitutes specific substrings within a string with new values. Here’s an example:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sentence = "JavaScript is amazing!";
const newSentence = sentence.replace("amazing", "incredible");
console.log(newSentence); // Output: JavaScript is incredible!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Converting to Uppercase (toUpperCase):
The &lt;code&gt;toUpperCase()&lt;/code&gt; method transforms all characters in a string to uppercase. Here’s an example:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const message = "Hello, world!";
const uppercaseMsg = message.toUpperCase();
console.log(uppercaseMsg); // Output: HELLO, WORLD!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Converting to Lowercase (toLowerCase):
The &lt;code&gt;toLowerCase()&lt;/code&gt; method converts all characters in a string to lowercase. Here’s an example:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const message = "Hello, world!";
const lowercaseMsg = message.toLowerCase();
console.log(lowercaseMsg); // Output: hello, world!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Checking the Start of a String (startsWith):
The &lt;code&gt;startsWith()&lt;/code&gt; method verifies if a string starts with a particular substring. Here’s an example:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sentence = "JavaScript is amazing!";
console.log(sentence.startsWith("JavaScript")); // Output: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Checking the End of a String (endsWith):
The &lt;code&gt;endsWith()&lt;/code&gt; method checks if a string ends with a specified substring. Here’s an example:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sentence = "JavaScript is amazing!";
console.log(sentence.endsWith("amazing!")); // Output: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Trimming Whitespace (trim):
The &lt;code&gt;trim()&lt;/code&gt; method removes whitespace from the beginning and end of a string. Here’s an example:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const message = " Hello, world! ";
const trimmedMsg = message.trim();
console.log(trimmedMsg); // Output: Hello, world!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Splitting a String (split):
The &lt;code&gt;split()&lt;/code&gt; method divides a string into an array of&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;substrings based on a specified separator. 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;const sentence = "JavaScript is amazing!";
const words = sentence.split(" ");
console.log(words); // Output: ["JavaScript", "is", "amazing!"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Extracting Characters (charAt):
The &lt;code&gt;charAt()&lt;/code&gt; method retrieves the character at a specific index within a string. Here’s an example:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const word = "Hello";
console.log(word.charAt(1)); // Output: e
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Extracting Unicode Values (charCodeAt):
The &lt;code&gt;charCodeAt()&lt;/code&gt; method returns the Unicode value of a character at a specified index. Here’s an example:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const word = "Hello";
console.log(word.charCodeAt(0)); // Output: 72
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Checking if a String Contains a Substring (includes):
The &lt;code&gt;includes()&lt;/code&gt; method checks if a string contains a specific substring. Here’s an example:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sentence = "JavaScript is amazing!";
console.log(sentence.includes("is")); // Output: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Checking if a String Matches a Pattern (match):
The &lt;code&gt;match()&lt;/code&gt; method, used with regular expressions, determines if a string matches a particular pattern. Here’s an example:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sentence = "JavaScript is amazing!";
const pattern = /is/;
console.log(sentence.match(pattern)); // Output: ["is"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Repeating a String (repeat):
The &lt;code&gt;repeat()&lt;/code&gt; method repeats a string a specified number of times. Here’s an example:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const word = "Hello";
console.log(word.repeat(3)); // Output: HelloHelloHello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Extracting the Last Index of a Substring (lastIndexOf):
The &lt;code&gt;lastIndexOf()&lt;/code&gt; method finds the last occurrence of a substring within a string. Here’s an example:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const sentence = "JavaScript is amazing!";
console.log(sentence.lastIndexOf("a")); // Output: 15
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Extracting a Subset of Characters (slice):
The &lt;code&gt;slice()&lt;/code&gt; method extracts a portion of a string based on specified start and end indexes. Here’s an example:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const word = "Hello";
const subset = word.slice(1, 4);
console.log(subset); // Output: ell
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Checking if a String is Empty (isEmpty):
The &lt;code&gt;isEmpty()&lt;/code&gt; method checks if a string is empty. Here’s an example:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function isEmpty(str) {
 return str === "";
}
console.log(isEmpty("")); // Output: true
console.log(isEmpty("Hello")); // Output: false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Checking if a String is a Number (isNaN):
The &lt;code&gt;isNaN()&lt;/code&gt; method determines if a string represents a valid number. Here’s an example:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(isNaN("123")); // Output: false
console.log(isNaN("Hello")); // Output: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations on learning about these 20 essential JavaScript string methods! With these techniques in your arsenal, you are now equipped to handle string manipulation tasks efficiently. Experiment with these methods, explore their variations, and apply them to solve real-world programming challenges. String manipulation is a fundamental aspect of JavaScript development, and by mastering these methods, you’ll enhance your coding skills and become a more proficient JavaScript developer. Happy coding!&lt;/p&gt;

&lt;p&gt;Thank you, dear reader, for investing your time in reading my article. We sincerely appreciate your engagement and interest in the topic. Your support means the world to me!&lt;/p&gt;

&lt;p&gt;We would love to hear your thoughts and feedback on the article. Did it provide you with valuable insights? Were there any specific sections that resonated with you? We value your perspective and would be thrilled to receive your comments. Also, don’t forget to give the article a well-deserved round of applause if you found it informative and helpful. Your feedback and applause inspire us to continue creating meaningful content that meets your needs. Thank you once again for being a part of our community, and we look forward to hearing from you!&lt;/p&gt;

</description>
      <category>programming</category>
      <category>html</category>
      <category>tech</category>
      <category>web</category>
    </item>
    <item>
      <title>Learn How to Generate Random Colors with JavaScript Like an Expert</title>
      <dc:creator>Alfred Nwanokwai</dc:creator>
      <pubDate>Sat, 20 May 2023 07:35:04 +0000</pubDate>
      <link>https://dev.to/zuxcode/learn-how-to-generate-random-colors-with-javascript-like-an-expert-1gcj</link>
      <guid>https://dev.to/zuxcode/learn-how-to-generate-random-colors-with-javascript-like-an-expert-1gcj</guid>
      <description>&lt;p&gt;Generating random colors with JavaScript can be a bit intimidating, especially to new developers. in this post, I will walk you through how you can generate random colors with JavaScript.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;create an index.html file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;create an index.html file, and copy and paste the code snippet below into the index.html file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;  &lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;http-equiv=&lt;/span&gt;&lt;span class="s"&gt;"X-UA-Compatible"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"IE=edge"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Generate random color&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;style &lt;/span&gt;&lt;span class="err"&gt;="&lt;/span&gt;&lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="err"&gt;/&lt;/span&gt;&lt;span class="na"&gt;css&lt;/span&gt;&lt;span class="err"&gt;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="py"&gt;place-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nf"&gt;#button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;" button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Click me&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;generateRandomColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`#&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mh"&gt;0xffffff&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`background-color: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;generateRandomColor&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://codepen.io/codeauthor1/pen/VwEVxQQ"&gt;See code on codepen&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Code ExplanationCode Explanation
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;the HTML code below will create a button element on the HTML document.
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;I added a little styling to it to place the button element in the center of the HTML document
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;  &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;place-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="nf"&gt;#button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;JavaScript code that does the magic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;firstly, I search through the Dom tree to retrieve a button element with an id of "button", then I stored it in a variable called button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;then, I added an event listener to the button, and I listen to a click event.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;then the code generates a random color each time the button is clicked.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;then I assigned the color to the background.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;generateRandomColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`#&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mh"&gt;0xffffff&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`background-color: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;generateRandomColor&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;thank you for reading. please leave a comment below and share the post with your friends who are also learning JavaScript. don't forget to follow me for more useful content.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>What is JavaScript</title>
      <dc:creator>Alfred Nwanokwai</dc:creator>
      <pubDate>Sun, 07 May 2023 20:17:15 +0000</pubDate>
      <link>https://dev.to/zuxcode/what-is-javascript-3h94</link>
      <guid>https://dev.to/zuxcode/what-is-javascript-3h94</guid>
      <description>&lt;h2&gt;
  
  
  What is JavaScript?
&lt;/h2&gt;

&lt;p&gt;JavaScript often abbreviated as Js, is a lightweight programming or scripting language that is used to make dynamic and interactive web pages.&lt;/p&gt;

&lt;p&gt;It is also referred to as an object-based scripting language with first-class functions. &lt;/p&gt;

&lt;p&gt;This means functions are treated as values that can be assigned to variables, passed as arguments to other functions, and returned as values from functions. In other words, functions in JavaScript can be used just like any other data type&lt;/p&gt;

&lt;p&gt;For instance, you can create a function and assign it to a variable, just like you would assign a string or a number to a variable. You can then pass that variable as an argument to another function or use it as a value in an expression.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sayHello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hello, &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;!`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Alice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we define a greet function that takes a greeting function as its first argument and a name as its second argument. When we call greet with the sayHello function and the name 'Alice', it calls the sayHello function with the name 'Alice', which logs the message "Hello, Alice!" to the console&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>learning</category>
      <category>programming</category>
    </item>
    <item>
      <title>Install Kali Linux on Windows</title>
      <dc:creator>Alfred Nwanokwai</dc:creator>
      <pubDate>Thu, 18 Aug 2022 21:42:40 +0000</pubDate>
      <link>https://dev.to/zuxcode/install-kali-linux-on-windows-3cdp</link>
      <guid>https://dev.to/zuxcode/install-kali-linux-on-windows-3cdp</guid>
      <description>&lt;p&gt;Hi there! today i will walk you through the process of installing and setting up Kali Linux on your windows laptop.&lt;/p&gt;

&lt;p&gt;In this article, you will learn how to use virtual box to setup Kali Linux on your windows laptop.&lt;/p&gt;

&lt;h2&gt;
  
  
  Download Virtual Box
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;click &lt;a href="https://download.virtualbox.org/virtualbox/6.1.36/VirtualBox-6.1.36-152435-Win.exe"&gt;here&lt;/a&gt; to download virtual box&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Download Kali Linux
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;click &lt;a href="https://www.kali.org/get-kali/#kali-virtual-machines"&gt;here&lt;/a&gt; to download Kali Linux&lt;/li&gt;
&lt;li&gt;Kali Linux is available for both 64-bit and 34-bit windows. select either of these two depending on your windows laptop.&lt;/li&gt;
&lt;li&gt;click on the icon labelled Virtual box and start downloading. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5qcscief4c40v47w5nlt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5qcscief4c40v47w5nlt.png" alt="Kali Linux on windows" width="746" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;congratulation!!!&lt;/strong&gt; you have successfully downloaded Kali Linux and Virtual box.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup Kali Linux on windows laptop
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Go to your download folder and install virtual box.&lt;/li&gt;
&lt;li&gt;launch virtual box&lt;/li&gt;
&lt;li&gt;Click on the button labelled import.&lt;/li&gt;
&lt;li&gt;Click on the yellow icon by the right. &lt;/li&gt;
&lt;li&gt;Go to folder you downloaded Kali Linux to (download folder)&lt;/li&gt;
&lt;li&gt;Select and Click on kali-linux&lt;/li&gt;
&lt;li&gt;Click on the button labelled. &lt;/li&gt;
&lt;li&gt;Click on the button labelled next. You should see an interface similar to this. &lt;/li&gt;
&lt;li&gt;Click on the button labelled import. A dialogue box appears, &lt;/li&gt;
&lt;li&gt;Click on the button labelled Agree&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;congratulation! you have successfully installed Kali Linux on windows.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>tutorial</category>
      <category>devjournal</category>
      <category>security</category>
    </item>
    <item>
      <title>colorful rain fall</title>
      <dc:creator>Alfred Nwanokwai</dc:creator>
      <pubDate>Fri, 01 Jul 2022 07:29:02 +0000</pubDate>
      <link>https://dev.to/zuxcode/colorful-rain-fall-aag</link>
      <guid>https://dev.to/zuxcode/colorful-rain-fall-aag</guid>
      <description>&lt;p&gt;&lt;strong&gt;Colorful rain drop with css and JavaScript&lt;/strong&gt;&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/codeauthor1/embed/Jjprxgm?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>codepen</category>
      <category>javascript</category>
      <category>css</category>
      <category>html</category>
    </item>
  </channel>
</rss>
