<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Stephen Gachoki</title>
    <description>The latest articles on Forem by Stephen Gachoki (@stevedev).</description>
    <link>https://forem.com/stevedev</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%2F924401%2Fb469ce74-c2dd-4810-9d6a-501fc7623995.jpg</url>
      <title>Forem: Stephen Gachoki</title>
      <link>https://forem.com/stevedev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/stevedev"/>
    <language>en</language>
    <item>
      <title>Introduction to GitHub</title>
      <dc:creator>Stephen Gachoki</dc:creator>
      <pubDate>Tue, 04 Apr 2023 12:44:40 +0000</pubDate>
      <link>https://forem.com/stevedev/introduction-to-github-l1m</link>
      <guid>https://forem.com/stevedev/introduction-to-github-l1m</guid>
      <description>&lt;h2&gt;
  
  
  Understanding the basics of version control and collaboration with GitHub
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Table of contents
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
Introduction to GitHub

&lt;ul&gt;
&lt;li&gt;Table of contents&lt;/li&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;What is GitHub&lt;/li&gt;
&lt;li&gt;Why GitHub&lt;/li&gt;
&lt;li&gt;Git vs. GitHub&lt;/li&gt;
&lt;li&gt;GitHub Desktop vs. GitHub CLI&lt;/li&gt;
&lt;li&gt;Cloning a Git Repository&lt;/li&gt;
&lt;li&gt;
How to create an empty repository

&lt;ul&gt;
&lt;li&gt;Prerequisites&lt;/li&gt;
&lt;li&gt;Creating the repository on GitHub&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

How to Clone a git repository

&lt;ul&gt;
&lt;li&gt;Prerequisites&lt;/li&gt;
&lt;li&gt;Cloning the repository&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Committing to a repository&lt;/li&gt;

&lt;li&gt;Pull requests&lt;/li&gt;

&lt;li&gt;Opening a pull request&lt;/li&gt;

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

&lt;/ul&gt;

&lt;/li&gt;

&lt;/ul&gt;

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

&lt;p&gt;GitHub and version control are two of the most salient topics to learn as a developer or software engineer. The scope to which this knowledge is applied is vast and is not constrained to software development only. GitHub can be used for tasks such as collaboration with teams, developing complex algorithms, and hosting websites, among others. GitHub is a tool that can be powerful if its capabilities are leveraged by the user to produce marvelous results.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is GitHub
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;GitHub&lt;/strong&gt; is a cloud-based platform that hosts git projects on a remote server. GitHub is used by individuals and teams for version control and collaboration using Git. GitHub's Graphical User Interface (GUI) is very user-friendly, and it allows even novice programmers to leverage the power of Git, which could otherwise be very problematic.&lt;/p&gt;

&lt;p&gt;GitHub is free for all, and anyone can sign up and begin hosting their projects without limits. This feature makes GitHub especially popular for open-source projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why GitHub
&lt;/h2&gt;

&lt;p&gt;GitHub has a myriad of benefits when used by a developer or any GitHub user at any level. You will have a backup of your project because it hosts git projects on a remote server. You can still easily access and retrieve your project files in a matter of minutes, if not seconds, even if there is damage to the local storage.&lt;/p&gt;

&lt;p&gt;Additionally, it is simple to keep track of both individual and group projects. The process of tracking the progress is made simpler by making changes to your project and pushing them to GitHub. Additionally, this is valid for multi-person collaborative projects. By creating new branches, everyone can work on the project remotely and contribute up until the deployment stage without running into any problems.&lt;/p&gt;

&lt;p&gt;GitHub provides some of the best documentation that makes it simple for new users to understand its technical aspects. The documentations make it easy to solve any problem encountered on the way without requiring a third party to take you through. In addition, GitHub offers a markdown that is used in the writing of instructions and explanations about a project (README.md). Markdown is also used by book authors to write their books, and technical writers to write their technical articles.&lt;/p&gt;

&lt;h2&gt;
  
  
  Git vs. GitHub
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Git&lt;/strong&gt; is an open-source version control tool that can be downloaded and installed on a computer. It is used to keep track of a development's source code history.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub&lt;/strong&gt; is a cloud-based code hosting platform that allows users to save their Git repositories on a remote server. It essentially stores code that is pushed to it from computers running the Git tool.&lt;br&gt;
You can learn more about &lt;a href="https://www.theserverside.com/video/Git-vs-GitHub-What-is-the-difference-between-them" rel="noopener noreferrer"&gt;Git and GitHub here&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  GitHub Desktop vs. GitHub CLI
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;GitHub Desktop&lt;/strong&gt; is an application that enables you to communicate with GitHub using a Graphical User Interface (GUI), instead of utilizing the command line or a web browser. GitHub Desktop allows you to perform the majority of Git operations from your desktop with visual confirmation. You can read more about how to install and use &lt;a href="https://docs.github.com/en/desktop/installing-and-configuring-github-desktop/overview/getting-started-with-github-desktop" rel="noopener noreferrer"&gt;GitHub desktop here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub CLI&lt;/strong&gt; on the other side is an open-source tool that allows you to interact with the GitHub from the computer's Command Line Interface(CLI). The CLI makes use of the git commands to perform certain tasks. You can find out more about the GitHub CLI and how to install it &lt;a href="https://docs.github.com/en/github-cli/github-cli/about-github-cli" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;br&gt;
Some of the commands that are used in the GitHub CLI can be found at the &lt;a href="https://docs.github.com/en/get-started/using-git/about-git#about-version-control-and-git" rel="noopener noreferrer"&gt;GitHub documentation&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Cloning a Git Repository
&lt;/h2&gt;
&lt;h3&gt;
  
  
  How to create an empty repository
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Prerequisites
&lt;/h4&gt;

&lt;p&gt;In this section, it is assumed that you have already created a GitHub account and your first task will be to create a repository otherwise known as a repo. If you have not created an account, you can create one from &lt;a href="https://github.com/" rel="noopener noreferrer"&gt;github.com&lt;/a&gt;.&lt;br&gt;
You will use the web-version of GitHub for this activity.&lt;/p&gt;
&lt;h4&gt;
  
  
  Creating the repository on GitHub
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click the &lt;strong&gt;&lt;em&gt;+&lt;/em&gt;&lt;/strong&gt; on the top right corner of your GitHub home page and it will show a dropdown with options.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu3cd70da9zz1tg37ss82.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu3cd70da9zz1tg37ss82.jpeg" alt="New Repository button"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You will use the &lt;strong&gt;New repository&lt;/strong&gt; option that is shown on the dropdown. Click on that option which will take you to a new page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the next step, you are required to give your repository a name. You can write your own repository name or use the one suggested for you.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Write a short description of your repository. This step is optional but preferable.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;ol&gt;
&lt;li&gt;You are required to choose whether your repository will be &lt;strong&gt;public&lt;/strong&gt; or &lt;strong&gt;private&lt;/strong&gt;. For this tutorial we will set the repository to be public and everyone in the internet can see it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can add a &lt;strong&gt;README&lt;/strong&gt; file which is used to talk briefly about your project. The README file also gives instructions to the people interacting with the project on how to use the project. At this stage you will not be required to add a README file since you will be creating an empty repository. Other files you can add to your repository include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Git ignore file. You can find out more about a git ignore file &lt;a href="https://git-scm.com/docs/gitignore#:~:text=A%20gitignore%20file%20specifies%20intentionally,gitignore%20file%20specifies%20a%20pattern" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;License.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You will not require the above files for now and we will leave them out.&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;Click on the &lt;strong&gt;&lt;code&gt;Create repository&lt;/code&gt;&lt;/strong&gt; button at the bottom to finish creating your repository.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;After creating you repository, you will be redirected to another page with the link to your repository. You will need this link when you will be cloning your repository to your local machine for changes.&lt;/p&gt;

&lt;p&gt;On that page, you will see other alternative ways of &lt;strong&gt;creating a repository from the command line, pushing an existing repository from the command line&lt;/strong&gt; and &lt;strong&gt;importing code from another repository&lt;/strong&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Copy the link to the repository by clicking on the clipboard symbols on the right side of the link.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpcfusyku5w5izw7xhqak.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpcfusyku5w5izw7xhqak.jpg" alt="Copy the repository link"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you are ready for the next step, cloning.&lt;/p&gt;
&lt;h3&gt;
  
  
  How to Clone a git repository
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Cloning&lt;/strong&gt; is the act of copying a repository from &lt;a href="https://github.com" rel="noopener noreferrer"&gt;GitHub.com&lt;/a&gt; to your local machine. Your clone will contain all the project files (if any), history and branches.&lt;/p&gt;

&lt;p&gt;You can also contribute to repositories belonging to other people or already in existence. All you will need is the link to the repository.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select the repository you want to clone and click
on the green button labelled &lt;strong&gt;&lt;code&gt;code&lt;/code&gt;&lt;/strong&gt; and it will show a
dropdown.&lt;/li&gt;
&lt;li&gt;Choose the &lt;code&gt;HTTPS&lt;/code&gt; option and copy the link to the
repository by clicking on the clipboard symbol on the far-right
of the link.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsugmxj4bek1gln65an8u.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsugmxj4bek1gln65an8u.jpg" alt="Repository link"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Prerequisites
&lt;/h4&gt;

&lt;p&gt;You are supposed to have installed &lt;strong&gt;git&lt;/strong&gt; into your computer for this section. If you have not installed it yet, you can learn how to install git which will be compatible with your machine from &lt;a href="https://github.com/git-guides/install-git" rel="noopener noreferrer"&gt;Git Guides&lt;/a&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Cloning the repository
&lt;/h4&gt;

&lt;p&gt;In this article I will be using the windows Git Bash, but Git can be downloaded to any Operating system including macOS and Linux/Unix distros &lt;a href="https://git-scm.com/downloads" rel="noopener noreferrer"&gt;See here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Search for &lt;strong&gt;git bash&lt;/strong&gt; in the search bar found on the bottom left corner of your windows machine and click on &lt;code&gt;open&lt;/code&gt;.&lt;/p&gt;

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

&lt;p&gt;Write the commands below to clone the repository.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="c"&gt;# download a repository on GitHub to our machine
# Replace `owner/repo` with the owner and name of the repository to clone
&lt;/span&gt;  &lt;span class="err"&gt;git&lt;/span&gt; &lt;span class="err"&gt;clone&lt;/span&gt; &lt;span class="err"&gt;https://github.com/owner/repo.git&lt;/span&gt;

&lt;span class="c"&gt;# It will look like this for the repository that we created
&lt;/span&gt;  &lt;span class="err"&gt;git&lt;/span&gt; &lt;span class="err"&gt;clone&lt;/span&gt; &lt;span class="err"&gt;https://github.com/&amp;lt;your&lt;/span&gt; &lt;span class="err"&gt;username&amp;gt;/github-&lt;/span&gt;
  &lt;span class="err"&gt;introduction.git&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Committing to a repository
&lt;/h2&gt;

&lt;p&gt;According to Wikipedia, a &lt;strong&gt;commit&lt;/strong&gt; is an operation which sends the latest changes of the source code to the repository, making these changes part of the head revision of the repository, in version control systems.&lt;/p&gt;

&lt;p&gt;We use git commands to stage the changes made to the repository and finally push them to GitHub. The commands that are used in committing the repository include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git add&lt;/code&gt; - stages a change.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git commit&lt;/code&gt; - completes the change-tracking procedure by adding the snapshot to the project history. In essence, committing works like taking a picture. With &lt;code&gt;git commit&lt;/code&gt;, anything that has been staged with &lt;code&gt;git add&lt;/code&gt; will be added to the snapshot.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;git push&lt;/code&gt; - Updates a branch's remote repository with any commits made locally.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To learn more about the git commands, refer to &lt;a href="https://docs.github.com/en/get-started/using-git/about-git#about-version-control-and-git" rel="noopener noreferrer"&gt;GitHub documentation&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;
&lt;span class="c"&gt;# Change into the `github-introduction` directory
&lt;/span&gt;  &lt;span class="err"&gt;cd&lt;/span&gt; &lt;span class="err"&gt;github-introduction&lt;/span&gt;

&lt;span class="c"&gt;# Make changes, for example, create a `README.md` and `file1.md` using the text editor
&lt;/span&gt;  &lt;span class="err"&gt;touch&lt;/span&gt; &lt;span class="err"&gt;README.md&lt;/span&gt;
  &lt;span class="err"&gt;touch&lt;/span&gt; &lt;span class="err"&gt;file1.md&lt;/span&gt;

&lt;span class="c"&gt;# Check to confirm the files you have created using the `ls` command
&lt;/span&gt;  &lt;span class="err"&gt;ls&lt;/span&gt;

&lt;span class="c"&gt;# stage the changed files
&lt;/span&gt;  &lt;span class="err"&gt;git&lt;/span&gt; &lt;span class="err"&gt;add&lt;/span&gt; &lt;span class="err"&gt;.&lt;/span&gt;

&lt;span class="c"&gt;# take a snapshot of the staging area (anything that's been added)
&lt;/span&gt;  &lt;span class="err"&gt;git&lt;/span&gt; &lt;span class="err"&gt;commit&lt;/span&gt; &lt;span class="err"&gt;-m&lt;/span&gt; &lt;span class="err"&gt;"My&lt;/span&gt; &lt;span class="err"&gt;first&lt;/span&gt; &lt;span class="err"&gt;commit"&lt;/span&gt;

&lt;span class="c"&gt;# push changes to GitHub
&lt;/span&gt;  &lt;span class="err"&gt;git&lt;/span&gt; &lt;span class="err"&gt;push&lt;/span&gt; &lt;span class="err"&gt;--set-upstream&lt;/span&gt; &lt;span class="err"&gt;origin&lt;/span&gt; &lt;span class="err"&gt;main&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Pull requests
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;Pull Request&lt;/strong&gt; is a "message" that lets you inform other contributors of the changes that you have pushed to a branch in a repository on GitHub.&lt;/p&gt;

&lt;p&gt;You contribute to other people's projects by creating a new &lt;code&gt;branch&lt;/code&gt;, which essentially gives you a copy of what is there in the &lt;code&gt;main&lt;/code&gt; branch. You can make your changes in the new branch and commit the changes to GitHub before opening a pull request.&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;pull request&lt;/code&gt; proposes your changes to someone, asking the person to review, pull in your contributions and merge them into their branch. It shows the differences of the contents from both branches.&lt;/p&gt;

&lt;h3&gt;
  
  
  Opening a pull request
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="c"&gt;# Pull the repository that you pushed to GitHub so that you can be update your local repository
&lt;/span&gt; &lt;span class="err"&gt;git&lt;/span&gt; &lt;span class="err"&gt;pull&lt;/span&gt;

&lt;span class="c"&gt;# Create a new branch and switch to the new branch
&lt;/span&gt; &lt;span class="err"&gt;git&lt;/span&gt; &lt;span class="err"&gt;checkout&lt;/span&gt; &lt;span class="err"&gt;-b&lt;/span&gt; &lt;span class="err"&gt;new-branch&lt;/span&gt;

&lt;span class="c"&gt;# Make some changes to the files that you created.
# Write something inside the file.
# Press `CTRL` + D to terminate the command
&lt;/span&gt;  &lt;span class="err"&gt;cat&lt;/span&gt; &lt;span class="err"&gt;&amp;gt;&lt;/span&gt; &lt;span class="err"&gt;README.md&lt;/span&gt;

&lt;span class="c"&gt;# stage the changes made to the files
&lt;/span&gt;&lt;span class="err"&gt;git&lt;/span&gt; &lt;span class="err"&gt;add&lt;/span&gt; &lt;span class="err"&gt;.&lt;/span&gt;

&lt;span class="c"&gt;# take a snapshot of the staging area (anything that's been added)
&lt;/span&gt;&lt;span class="err"&gt;git&lt;/span&gt; &lt;span class="err"&gt;commit&lt;/span&gt; &lt;span class="err"&gt;-m&lt;/span&gt; &lt;span class="err"&gt;"Modified&lt;/span&gt; &lt;span class="err"&gt;README.md&lt;/span&gt; &lt;span class="err"&gt;file"&lt;/span&gt;

&lt;span class="c"&gt;# push changes to GitHub
&lt;/span&gt;&lt;span class="err"&gt;git&lt;/span&gt; &lt;span class="err"&gt;push&lt;/span&gt; &lt;span class="err"&gt;--set-upstream&lt;/span&gt; &lt;span class="err"&gt;origin&lt;/span&gt; &lt;span class="err"&gt;new-branch&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will now have changes in a branch off the main branch. You can now open a pull request.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click on the &lt;strong&gt;Pull requests&lt;/strong&gt; tab of your &lt;code&gt;github- 
introduction&lt;/code&gt; repository.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;ol&gt;
&lt;li&gt;Click &lt;strong&gt;New pull request&lt;/strong&gt; button.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn9kpkc3t7kxi8jsb4fs6.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn9kpkc3t7kxi8jsb4fs6.jpeg" alt="New Pull Request button"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the Comparisons box, select the branch you made changes to, &lt;code&gt;new-branch&lt;/code&gt;, to compare with main branch (the original).&lt;/li&gt;
&lt;/ol&gt;

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

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Confirm the changes in the &lt;strong&gt;diffs&lt;/strong&gt; on the comparing changes page and make sure they are the changes that you want to submit.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Create pull request&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Give your pull request a title and a brief description of changes made.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Create pull request&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F12xccdgxpqlfzpdn4scl.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F12xccdgxpqlfzpdn4scl.jpeg" alt="Finish up creating the pull request"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congratulations!🎉 You have created a new pull request ready for review and merging of your branch. You can learn more about Git and GitHub from the &lt;a href="https://github.com/skills/introduction-to-github" rel="noopener noreferrer"&gt;GitHub docs.&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;By using Git and GitHub, your production is boosted and you can focus the time you spent thinking about your project history to other projects. GitHub, and specifically, pull requests are the heart of collaboration. You can contribute to projects from anywhere around the globe and be sure of no data loss.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>github</category>
    </item>
    <item>
      <title>Javascript: Building a Dice Game</title>
      <dc:creator>Stephen Gachoki</dc:creator>
      <pubDate>Mon, 13 Feb 2023 13:52:28 +0000</pubDate>
      <link>https://forem.com/stevedev/javascript-building-a-dice-game-3kf</link>
      <guid>https://forem.com/stevedev/javascript-building-a-dice-game-3kf</guid>
      <description>&lt;h3&gt;
  
  
  Introduction.
&lt;/h3&gt;

&lt;p&gt;The dice game is a duo-player game that is very interesting to play and brings the feel of the physical dice game to the players.&lt;br&gt;
The players roll the dice and their cumulative scores are updated consistently until the active player hits a 1. Hitting a 1 means that the active player loses their current scores and the game switches to the next player. You should use the hold button to update your overall score and to make sure that you do not lose your high scores before switching to the next player. The first player to hit a 100 and above cumulative points wins the game. From this game, you will learn more about the JavaScript DOM manipulation.&lt;/p&gt;
&lt;h3&gt;
  
  
  Overview
&lt;/h3&gt;

&lt;p&gt;This tutorial puts the DOM(Document Object Model) skills into practice. You should already have knowledge on how to manipulate the DOM. This knowledge will come in handy in our small project.&lt;/p&gt;
&lt;h3&gt;
  
  
  Prerequisites.
&lt;/h3&gt;

&lt;p&gt;This tutorial blog assumes that you already have HTML and CSS knowledge and you are just going to work with JavaScript to make the game functional.&lt;br&gt;
This project however, will be helpful to both code newbies and intermediate programmers who want to brush their JavaScript skills.&lt;/p&gt;
&lt;h3&gt;
  
  
  HTML and CSS starter files.
&lt;/h3&gt;

&lt;p&gt;The starter files for the HTML and CSS of this project can be found on my GitHub page plus the images required therein: &lt;a href="https://github.com/Stegeek/Dice-Game" rel="noopener noreferrer"&gt;Github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Clone the project to your local machine and let's enjoy the ride.&lt;/p&gt;

&lt;p&gt;By now, your website should be looking like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8xvh0gro58zd31xbste4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8xvh0gro58zd31xbste4.png" alt="Dice-game website view" width="800" height="402"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With all that set, you are now ready to begin our adventure.&lt;/p&gt;
&lt;h3&gt;
  
  
  Functionality with JavaScript.
&lt;/h3&gt;

&lt;p&gt;Looking at your HTML code, you can see that you have linked all the important scripts (script.js and style.css) meaning that you can work directly on separate sheets and expect all the changes to occur within the markup.&lt;/p&gt;

&lt;p&gt;As seen in the image, the dice image shown is hard coded as well as the scores. These should be generated automatically according to the dice rolled.&lt;/p&gt;
&lt;h4&gt;
  
  
  1. Selecting the elements.
&lt;/h4&gt;

&lt;p&gt;The first step is to select all the elements that you are going to manipulate (Work with). You use the &lt;code&gt;querySelector&lt;/code&gt; and the &lt;code&gt;getElementById&lt;/code&gt; methods to select your elements using both the IDs and the classes.&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="c1"&gt;//Selecting Elements&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;player0&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="s1"&gt;.player--0&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;player1&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="s1"&gt;.player--1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//Final cumulative scores&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;score0Element&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="s1"&gt;#score--0&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;score1Element&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="s1"&gt;#score--1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//Current Scores and the Dice element.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;currentScore0&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="s1"&gt;current--0&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;currentScore1&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="s1"&gt;current--1&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;diceElement&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="s1"&gt;.dice&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//Buttons&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;btnRoll&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="s1"&gt;.btn--roll&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;btnNew&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="s1"&gt;.btn--new&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;btnHold&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="s1"&gt;.btn--hold&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;h4&gt;
  
  
  2. Initializing the game.
&lt;/h4&gt;

&lt;p&gt;You need to make all the elements flexible by removing the hard coded values and manipulating them using the DOM whenever the dice is rolled.&lt;br&gt;
You should set the final score to begin at 0 and be updated continuously as the game progresses. The dice image too should be hidden since it is only supposed to show after the dice is rolled.&lt;/p&gt;

&lt;p&gt;The scores accumulated by the active player are supposed to be stored in an array so that at the end of the game, they are added and displayed on their final score element.&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;let&lt;/span&gt; &lt;span class="nx"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentScore&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;activePlayer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;playing&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Defining a function to initialize the whole game when called.&lt;/span&gt;

 &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;init&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="nx"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&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="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
   &lt;span class="nx"&gt;currentScore&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;activePlayer&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="c1"&gt;//Final scores elements set to zero&lt;/span&gt;
   &lt;span class="nx"&gt;score0Element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="nx"&gt;score1Element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

 &lt;span class="c1"&gt;//Set surrent score elements to zero&lt;/span&gt;
   &lt;span class="nx"&gt;currentScore0&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="nx"&gt;currentScore1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="nx"&gt;playing&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="nx"&gt;diceElement&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="s1"&gt;hidden&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="nx"&gt;player0&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="s1"&gt;player--winner&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="nx"&gt;player1&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="s1"&gt;player--winner&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="nx"&gt;player0&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="s1"&gt;player--active&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="nx"&gt;player1&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="s1"&gt;player--active&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;init&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Roll Button Functionality.
&lt;/h4&gt;

&lt;p&gt;The first button that you need to work with is the "Roll Dice" button. When clicked, it rolls the dice and gives us the final number rolled, displays the rolled dice to the website and checks if the dice is equal to one. If the dice rolled is equal to 1, the game switches to the next player.&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="c1"&gt;//Button Roll Functionality&lt;/span&gt;
&lt;span class="nx"&gt;btnRoll&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="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;playing&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//1. Generate a random dice number between 1 and 6.&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;dice&lt;/span&gt; &lt;span class="o"&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="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&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="c1"&gt;//2. Display dice&lt;/span&gt;
      &lt;span class="c1"&gt;// Set the image source to the rolled dice&lt;/span&gt;
    &lt;span class="nx"&gt;diceElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;src&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`dice-&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;dice&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.png`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
     &lt;span class="c1"&gt;// Remove the 'hidden' class to display the dice that has been rolled.&lt;/span&gt;
    &lt;span class="nx"&gt;diceElement&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="s1"&gt;hidden&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;//3. Check if the number is equal to 1; If true, move to the next player.&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;dice&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="p"&gt;{&lt;/span&gt;
   &lt;span class="c1"&gt;//Update the current score of the current player. &lt;/span&gt;
      &lt;span class="nx"&gt;currentScore&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;dice&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="c1"&gt;// Display the current score to the page.&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="s2"&gt;`current--&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;activePlayer&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
        &lt;span class="nx"&gt;currentScore&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="c1"&gt;//switch to Next Player&lt;/span&gt;
      &lt;span class="nf"&gt;switchPlayer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Switching the players.
&lt;/h4&gt;

&lt;p&gt;In the code above, if the current player rolls a 1, the game is supposed to switch to the next player. The code to switch the player is repeated twice, thus you need to create a function to reuse at both instances to keep your code DRY (Do not Repeat Yourself).&lt;br&gt;
You set the active player to be from zero since we store their scores in an array and you need to access the scores using bracket notation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;switchPlayer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;//Display the current score of the active player.&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="s2"&gt;`current--&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;activePlayer&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;textContent&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="c1"&gt;// Set the current scores to zero.&lt;/span&gt;
  &lt;span class="nx"&gt;currentScore&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="c1"&gt;//If active player is player 0, switches to player 1 else sets the player to 0.&lt;/span&gt;
  &lt;span class="nx"&gt;activePlayer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;activePlayer&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="mi"&gt;1&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="cm"&gt;/*Toggles between player--active class.
 Adds the 'player--active' class to an element if it is not there and removes it if it is already there.
Already defined in the CSS file*/&lt;/span&gt;
  &lt;span class="nx"&gt;player0&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;toggle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;player--active&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;player1&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;toggle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;player--active&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. Hold Button Functionality.
&lt;/h4&gt;

&lt;p&gt;The hold button is supposed to update the cumulative scores of the current player and display it, reset the current score of the active player to zero, and then switch immediately to the next player.&lt;br&gt;
If the cumulative scores of the active player is equal to or greater than 100, the player is considered the winner and the winner class is added to the element which changes the background color.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;btnHold&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="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;playing&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// 1. Add the current score to the player's score&lt;/span&gt;
    &lt;span class="nx"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;activePlayer&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;currentScore&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// Display the score to the current player's scores&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="s2"&gt;`score--&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;activePlayer&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
      &lt;span class="nx"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;activePlayer&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="c1"&gt;// Check if the score[activeplayer] &amp;gt;= 100, if true exit the game&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;activePlayer&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;//Finish the game&lt;/span&gt;
      &lt;span class="nx"&gt;diceElement&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="s1"&gt;hidden&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="c1"&gt;// Set playing to false so that none of the buttons works.&lt;/span&gt;
      &lt;span class="nx"&gt;playing&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="c1"&gt;// Add the winner class to the active player if the score is greater or equal to 100.&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="s2"&gt;`.player--&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;activePlayer&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="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="s1"&gt;player--winner&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// Remove the player active class from the winner to make sure the game ends.&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="s2"&gt;`.player--&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;activePlayer&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="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="s1"&gt;player--active&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="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;switchPlayer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  6. New Game button functionality.
&lt;/h3&gt;

&lt;p&gt;Now that you have all buttons working well, it's time to make your "New Game" button functional. This will be easy since in the event where you click the new game button, it is supposed to initialize everything we have manipulated back to the initial content.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;btnNew&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="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;//We call the init function which has all the code to revert everything to original.&lt;/span&gt;
  &lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;We have looked at how we can use JavaScript to manipulate CSS styles and HTML elements in response to the clicking of buttons.&lt;br&gt;
I hope you enjoyed the article and learnt something from it.&lt;/p&gt;

</description>
      <category>watercooler</category>
    </item>
    <item>
      <title>Javascript: What You Need to Know (Part one)</title>
      <dc:creator>Stephen Gachoki</dc:creator>
      <pubDate>Thu, 02 Feb 2023 21:19:24 +0000</pubDate>
      <link>https://forem.com/stevedev/javascript-what-you-need-to-know-part-one-1dh3</link>
      <guid>https://forem.com/stevedev/javascript-what-you-need-to-know-part-one-1dh3</guid>
      <description>&lt;h2&gt;
  
  
  Table of contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
Basic Syntax 

&lt;ul&gt;
&lt;li&gt;Numbers&lt;/li&gt;
&lt;li&gt;Strings&lt;/li&gt;
&lt;li&gt;Booleans&lt;/li&gt;
&lt;li&gt;Undefined and Null&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

Operators

&lt;ul&gt;
&lt;li&gt;Arithmetic Operators&lt;/li&gt;
&lt;li&gt;Assignment Operators&lt;/li&gt;
&lt;li&gt;Comparison Operators&lt;/li&gt;
&lt;li&gt;Logical Operators&lt;/li&gt;
&lt;li&gt;Conditional Operator&lt;/li&gt;
&lt;li&gt;Console.log function&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The Nitty Gritty of The Javascript Language&lt;/strong&gt;&lt;br&gt;
As a newbie programmer or a beginner to the &lt;em&gt;Javascript&lt;/em&gt; language, you often find yourself stranded on what to learn. &lt;br&gt;
First of all, what exactly is this &lt;em&gt;Javascript&lt;/em&gt; that I am talking about? Well, Javascript is the most popular language used in the websites' client-side development. More about &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript" rel="noopener noreferrer"&gt;Javascript&lt;/a&gt; can be found in MDN's website, the developer's best friend. Here I am a bit biased on the web development side, but hey, do not go away just yet; you will encounter these Javascript basics irregardless of your motivation to taking any Javascript roadmap.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learn these Basics of Javascript Language and then move on:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Basic syntax&lt;/li&gt;
&lt;li&gt;DOM Manipulation (Web Development).&lt;/li&gt;
&lt;li&gt;Fetch API / Ajax.&lt;/li&gt;
&lt;li&gt;Async Await.&lt;/li&gt;
&lt;li&gt;Event Listeners. (Web)&lt;/li&gt;
&lt;li&gt;ES6+ Javascript.&lt;/li&gt;
&lt;li&gt;Promises.&lt;/li&gt;
&lt;li&gt;Classes.&lt;/li&gt;
&lt;li&gt;Array Methods.&lt;/li&gt;
&lt;li&gt;Scoping.&lt;/li&gt;
&lt;li&gt;Hoisting.&lt;/li&gt;
&lt;li&gt;Closures.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Basic Syntax
&lt;/h2&gt;

&lt;p&gt;The ice peak of any language is learning the basic syntax of the language and advance to the challenging parts with time. Javascript has data types that are the building blocks of any code written in Javascript. These data types include: numbers, strings, Booleans, Undefined and Null.&lt;/p&gt;
&lt;h3&gt;
  
  
  Numbers
&lt;/h3&gt;

&lt;p&gt;_Numbers _are the integer values, both negative and positive and are used to quantify something and can also be used in arithmetic calculations.&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;let&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;9&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;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//-&amp;gt;19&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Strings
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Strings&lt;/em&gt; are used to represent text. This data type makes use of quotation marks; Single quotes('), double quotes("), and backticks(`). Backticks have a special purpose when used in strings and are called &lt;strong&gt;Template literals&lt;/strong&gt;-More about this to be discussed a bit later.&lt;br&gt;
It is mandatory to use the quotation marks since not using them would introduce bugs to your code.&lt;/p&gt;

&lt;p&gt;`&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;day&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Wednesday&lt;/span&gt;&lt;span class="dl"&gt;'&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;lesson&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Javascript Fundamentals&lt;/span&gt;&lt;span class="dl"&gt;"&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;newStr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;123&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;&lt;br&gt;
`&lt;/p&gt;
&lt;h3&gt;
  
  
  Booleans
&lt;/h3&gt;

&lt;p&gt;Booleans are &lt;em&gt;true&lt;/em&gt; and &lt;em&gt;false&lt;/em&gt; values. These values are assigned to variables, object properties, arrays and comparisons. These data types are used just as they are:&lt;/p&gt;

&lt;p&gt;`&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;married&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;hasDriversLicense&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="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="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//-&amp;gt; true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
`&lt;br&gt;
The last code evaluates to true. This is because, the program asks the question, "Is 3 greater than 2?" and prints the answer to the console. Those are the booleans.&lt;/p&gt;
&lt;h3&gt;
  
  
  Undefined and Null
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Null&lt;/strong&gt; is the deliberate absence of a value in the code. It is encountered whereby you assign it to a variable to mean that the variable might not have a value now, but it will have one later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Undefined&lt;/strong&gt; on the otherhand means that the value that is being referred to does not exist in the compiler. An example is when you define an empty variable.&lt;/p&gt;

&lt;p&gt;`&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;newNum&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newNum&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// -&amp;gt; undefined&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;boxLabel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
`&lt;/p&gt;
&lt;h2&gt;
  
  
  Operators
&lt;/h2&gt;

&lt;p&gt;Now that we have looked at data types, let's look at &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators" rel="noopener noreferrer"&gt;Operators&lt;/a&gt;. There are different types of operators in Javascript. The most common and the most used operators include: &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Assignment Operators.&lt;/li&gt;
&lt;li&gt;Arithmetic operators.&lt;/li&gt;
&lt;li&gt;Comparison operators.&lt;/li&gt;
&lt;li&gt;Logical operators.&lt;/li&gt;
&lt;li&gt;Conditional operators.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Arithmetic Operators
&lt;/h3&gt;

&lt;p&gt;The Arithmetic operators takes two numerical values as their operands, one on the left and one on the right side and returns one numerical value. The most common ones are addition(+), subtraction(-), division(/) and multiplication(*).&lt;/p&gt;

&lt;p&gt;In addition to these standard operators, there are other arithmetic operators that are offered by Javascript that include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Remainder operator&lt;/strong&gt; -denoted by (&lt;strong&gt;%&lt;/strong&gt;).This one returns the value that remains after dividing two values. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Increment operator&lt;/strong&gt; - denoted by (&lt;strong&gt;++&lt;/strong&gt;). It adds 1 to its operand. It is a unary operator meaning that it performs operations on only one operand.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Decrement operator&lt;/strong&gt; - denoted by (&lt;strong&gt;--&lt;/strong&gt;). It subtracts 1 from its operand. It is a unary operator too.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;`&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// Ans = 4&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//y will be equal to 6&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;z&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//z will be equal to 9&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;remainder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// Ans = 1 &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;Operators have &lt;em&gt;precedence&lt;/em&gt; whereby one operation is performed first before it moves on to the other incase they appear in the same code. *, / and modulo (%) have the same precedence and are handled first in an operation. - and + have the same precedence and are handled last after *, % and /.&lt;/p&gt;
&lt;h3&gt;
  
  
  Assignment Operators
&lt;/h3&gt;

&lt;p&gt;Assignment operators as the name suggests, are used to assign values on their right to operands on their left side. The most common assignment operator is the &lt;code&gt;=&lt;/code&gt; and we have seen it before in the code blocks.&lt;br&gt;
`&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//Assigns the value 10 to x. Thus whenever we invoke x, we get 10.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;There are other types of assignment operators called the &lt;em&gt;Compound Assignment Operators&lt;/em&gt; which are shorthand for some operations.&lt;/p&gt;

&lt;p&gt;`&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;x&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;means&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&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="c1"&gt;//Addition Assignment &lt;/span&gt;

&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&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;means&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//Subtraction Assignment &lt;/span&gt;

&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;means&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//Multiplication Assignment&lt;/span&gt;

&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;/=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;means&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//Division Assignment &lt;/span&gt;

&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&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;means&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//Remainder Assignment &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
`&lt;/p&gt;
&lt;h3&gt;
  
  
  Comparison Operators
&lt;/h3&gt;

&lt;p&gt;The comparison operators are used to compare two operands (Binary operators). They compare whether one operand is greater than denoted by (&lt;strong&gt;&amp;gt;&lt;/strong&gt;), less than denoted by (&lt;strong&gt;&amp;lt;&lt;/strong&gt;), less or equal to denoted by (&lt;strong&gt;&amp;lt;=&lt;/strong&gt;), greater or equal to denoted by (&lt;strong&gt;&amp;gt;=&lt;/strong&gt;), equal to the other (&lt;strong&gt;==&lt;/strong&gt;) or strictly (exactly) equal to denoted by (&lt;strong&gt;===&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;`&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="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="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//-&amp;gt;true (This is true because 3 is greater than 2)&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="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//-&amp;gt;true (This is true because 5 is less than 7)&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="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//-&amp;gt;false (This is false because 3 is greater than 2)&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="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//-&amp;gt;true (This is true because 2 is less than 3)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;The most crucial part of using the loosely equal (==) operator and the strict equal operator (===) is to know the difference between the two. The loosely equal(==) applies type conversion before comparison while the strict equal (===) compares the two operands without conversion. In Javascript, there is type conversion that is triggered by some operators before comparison. For example, a string can be converted to a number before the comparison is done. This is done internally by Javascript.&lt;/p&gt;

&lt;p&gt;`&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//-&amp;gt; true (This comparison translates to true since the string "2" is first converted to number then compared to 2.)&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//-&amp;gt; false (This translates to false since there is no type conversion done here. The operands are compared as they are.)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
`&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;Not equal (!=)&lt;/code&gt; operator - Returns &lt;code&gt;true&lt;/code&gt; if the operands are not equal.&lt;br&gt;
The &lt;code&gt;Strict not equal (!==)&lt;/code&gt; - Returns &lt;code&gt;true&lt;/code&gt; if the operands are of the same type but not equal, or are of different type.&lt;/p&gt;
&lt;h3&gt;
  
  
  Logical Operators
&lt;/h3&gt;

&lt;p&gt;Logical operators are used with Boolean (logical) values. They return a Boolean value after the conditions set by the operands are met. There are three logical operators:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The logical &lt;strong&gt;and&lt;/strong&gt;  denoted by &lt;strong&gt;&amp;amp;&amp;amp;&lt;/strong&gt;. This operator returns true if both the operands are true. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;`&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;example&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//true&lt;/span&gt;
&lt;span class="c1"&gt;//-&amp;gt; return true since both the operands are true.&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;example2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//false&lt;/span&gt;
&lt;span class="c1"&gt;//-&amp;gt;returns false since one of the operands is false meaning they are different.&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;example3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//false&lt;/span&gt;
&lt;span class="c1"&gt;//-&amp;gt;returns false since all the operands are false.&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;example4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Cats&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dogs&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;//Dogs;&lt;/span&gt;
&lt;span class="c1"&gt;//-&amp;gt;returns Dogs.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
`&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The logical &lt;code&gt;or&lt;/code&gt; denoted by &lt;code&gt;||&lt;/code&gt;.It returns &lt;code&gt;expression1&lt;/code&gt; if it can be converted to &lt;code&gt;true&lt;/code&gt;; otherwise, returns &lt;code&gt;expression2&lt;/code&gt;. Thus, when used with Boolean values, &lt;code&gt;||&lt;/code&gt; returns &lt;code&gt;true&lt;/code&gt; if either operand is &lt;code&gt;true&lt;/code&gt;; if both are &lt;code&gt;false&lt;/code&gt;, returns &lt;code&gt;false&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;`&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="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="kc"&gt;true&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="c1"&gt;// true.&lt;/span&gt;
&lt;span class="c1"&gt;// -&amp;gt; returns true since one of the operands is true.&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="kc"&gt;false&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="c1"&gt;//false&lt;/span&gt;
&lt;span class="c1"&gt;// -&amp;gt; returns false since all the operands are false and none can be converted to true.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
`&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The logical &lt;code&gt;not&lt;/code&gt; denoted by &lt;code&gt;!&lt;/code&gt;. This operator gives the opposite of the operand given. For example, &lt;code&gt;!true == false&lt;/code&gt; and &lt;code&gt;!false == true&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Conditional Operator
&lt;/h3&gt;

&lt;p&gt;The conditional operator (Also called the &lt;code&gt;Ternary operator&lt;/code&gt;) is the only Javascript operator that takes three operands. It's general syntax is:  &lt;code&gt;condition ? expression to execute if the condition is met(truthy) : expression to execute if the condition is not met (falsy).&lt;/code&gt;&lt;br&gt;
This operator is used instead of if...else condition.&lt;/p&gt;

&lt;p&gt;`&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="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="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// 1&lt;/span&gt;
&lt;span class="c1"&gt;//-&amp;gt; returns 1 because the condition is true.&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;13&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;18&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Adult&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Minor&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Minor&lt;/span&gt;
&lt;span class="c1"&gt;// -&amp;gt; returns Minor because the condition has not been met / it is false since age is 13.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
`&lt;/p&gt;

&lt;h3&gt;
  
  
  Console.log function
&lt;/h3&gt;

&lt;p&gt;You might be wondering what console.log in my code means. Well,&lt;br&gt;
&lt;strong&gt;console.log&lt;/strong&gt; is a function that is used to print values to the console in Javascript.&lt;/p&gt;

&lt;p&gt;PART 2 IS ON THE WAY...HAPPY CODING.&lt;/p&gt;

</description>
      <category>watercooler</category>
    </item>
    <item>
      <title>A DEEP DIVE INTO C PROGRAMMING. (Part 1)</title>
      <dc:creator>Stephen Gachoki</dc:creator>
      <pubDate>Sun, 11 Sep 2022 15:43:13 +0000</pubDate>
      <link>https://forem.com/stevedev/a-deep-dive-into-c-programming-part-1-245n</link>
      <guid>https://forem.com/stevedev/a-deep-dive-into-c-programming-part-1-245n</guid>
      <description>&lt;h1&gt;
  
  
  A little History of the C language
&lt;/h1&gt;

&lt;p&gt;A little dive into the history of C would be a good place to start I presume. &lt;strong&gt;Dennis Ritchie&lt;/strong&gt; is the name behind this magnificent language. The C programming language had it predecessor from B created by Ken Thompson. 'C' is more of an upgrade of B. It was founded in 1978 by both Brian Kerninghan and Dennis Ritchie. C is the programming language that was used to write &lt;strong&gt;UNIX&lt;/strong&gt; developed by both Dennis Ritchie and Ken Thompson. Dennis Ritchie died in October 2011 having received many awards based on his inventions and creations. &lt;a href="https://en.wikipedia.org/wiki/Dennis_Ritchie"&gt;Dennis Ritchie&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A journey of a thousand miles is started by taking the first step- Chinese Proverb.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Before we dive in into C programming we have to know what C as a language is and why it is important to learn C programming. C is considered a high-level programming language but compared to other programming languages such as Python, Javascript and Java, it is the lowest level programming language. "What high level and low level language is he talking about?" You probably must be asking yourself what the meaning of high and low level language by now. The highest level is the human language that we use to communicate especially English. The lowest level is the machine language or should I call it the computer language (binaries). This means that a high level programming language syntax is close to human language and can comfortably be read by human, the vice versa is true. This means that the C syntax can easily be understood by humans.&lt;/p&gt;

&lt;p&gt;Too much of that already, but we can't begin before we know what type of language C is. C is a compiled language. This means that it's not possible to write a C program and run it straight away after saving it. You have to pass it through a compiler so that it can be executed by the machine. As you already know, C being a high-level programming language it is written in a language near human language that the machine, in this case, your computer can not understand. Thus, the written program must be converted to a language that the computer understands. That is where the compiler comes in. The source code passes through four main stages before it can be executed. That's a lot of stages I know. Am I the one who is going to do all that? Relax, the compiler does all the work for you. The stages are preprocesser, compiling, assembling and the linking. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The preprocesser stage:&lt;/strong&gt; This is the stage where the required libraries defined in the header are assembled and made available to the source code. The extension of the source code at this level is &lt;strong&gt;.c&lt;/strong&gt; .Then the source code goes to the compiler stage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The Compiling stage:&lt;/strong&gt; The compiler compiles the source code plus all the libraries that have been assembled into another file called assembly file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The assembly stage:&lt;/strong&gt; At this stage we have an assembly file. The compiler assembles the required function code and makes it available for the linker to link and make an executable file out of it. The assembled data is stored in an &lt;em&gt;object file&lt;/em&gt; with the extension &lt;strong&gt;.obj&lt;/strong&gt; for windows and &lt;strong&gt;.o&lt;/strong&gt; for unix users.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;The linker:&lt;/strong&gt;After all the required function code is made available, it is now time for the linker to connect all of them plus the object file to make an executable file that will now run on the computer to perform the task intended. The linker will yield an executable file with the extension &lt;strong&gt;.exe&lt;/strong&gt; for windows users and &lt;strong&gt;a.out&lt;/strong&gt; for unix users. This is now the binary code.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nIh-YeX_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8rbu8de810r68g5cqx6d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nIh-YeX_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8rbu8de810r68g5cqx6d.png" alt="Image description" width="238" height="212"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's a lot to do isn't it? Well, that's less than blink of an eye to the computer. At this stage you know that you need a compiler if you are using a windows system but for Unix users, the &lt;strong&gt;gcc compiler&lt;/strong&gt; or the &lt;strong&gt;gnu compiler&lt;/strong&gt; comes already installed in the machine. All you need to do is run the &lt;code&gt;gcc&lt;/code&gt; command.(We'll look at it later.)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gcc file_name.c -o new_filename&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now that you know what happens to your program after you write it, it is time to get our hands dirty. Look out for my next article where we will be writing our first code and learning more about the C syntax.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>career</category>
      <category>beginners</category>
      <category>c</category>
    </item>
  </channel>
</rss>
