<?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: Shashank Sharma</title>
    <description>The latest articles on Forem by Shashank Sharma (@anothereader_22).</description>
    <link>https://forem.com/anothereader_22</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%2F1036121%2Fa3175ac8-62fb-4dbb-b79d-87044dcdb901.jpg</url>
      <title>Forem: Shashank Sharma</title>
      <link>https://forem.com/anothereader_22</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/anothereader_22"/>
    <language>en</language>
    <item>
      <title>HOW TO MAKE BMI CALCULATOR</title>
      <dc:creator>Shashank Sharma</dc:creator>
      <pubDate>Sat, 18 Mar 2023 12:03:51 +0000</pubDate>
      <link>https://forem.com/anothereader_22/how-to-make-bmi-calculator-4ii6</link>
      <guid>https://forem.com/anothereader_22/how-to-make-bmi-calculator-4ii6</guid>
      <description>&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In this blog, I will walk you through a step-by-step process to create a simple BMI Calculator.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I assume you can create HTML and CSS File for this, so I am not making it for you. Although, I will provide my version of the HTML and CSS code below for your convenience.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In this blog, I focus mainly on the JavaScript part of this BMI Calculator.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8" /&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge" /&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"/&amp;gt;
    &amp;lt;title&amp;gt;BMI CALCULATOR&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="styles.css" /&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div&amp;gt;
      &amp;lt;h1 style="text-align: center"&amp;gt;BMI CALCULATOR&amp;lt;/h1&amp;gt;
      &amp;lt;h3&amp;gt;What is BMI?&amp;lt;/h3&amp;gt;
      &amp;lt;p class="para"&amp;gt;                                                 BMI stands for Body Mass Index, which is a measure of body fat  based on a person's weight and height. It is commonly used to assess whether a person is underweight, normal weight, overweight, or obese. BMI is calculated by dividing a person's weight (in kilograms) by their height(in meters squared).
      &amp;lt;/p&amp;gt;
      &amp;lt;p class="para"&amp;gt;                                                 BMI is a useful tool to assess whether a person is at a healthy   weightor not, but it is not always a perfect indicator of health. For example,someone with a high amount of muscle mass may have a high BMI even though they are not overweight or obese. Additionally, BMI does not take into account other factors such as age, sex, or body composition, so it should be used in conjunction with other measures to assess overall
        health.
      &amp;lt;/p&amp;gt;
      &amp;lt;h3&amp;gt;Ranges&amp;lt;/h3&amp;gt;
      &amp;lt;p class="para"&amp;gt;
BMI ranges are typically categorized into different levels of bodyweight and are used to indicate whether a person is underweight, normalweight, overweight, or obese. The World Health Organization (WHO) has established the following BMI ranges for adults:
      &amp;lt;/p&amp;gt;
      &amp;lt;ul class="para"&amp;gt;
        &amp;lt;li&amp;gt;Underweight: BMI below 18.5&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;Normal weight: BMI between 18.5 and 24.9&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;Overweight: BMI between 25 and 29.9&amp;lt;/li&amp;gt;
        &amp;lt;li&amp;gt;Obese: BMI 30 or higher&amp;lt;/li&amp;gt;
      &amp;lt;/ul&amp;gt;

      &amp;lt;section class="work"&amp;gt;
        &amp;lt;h2 class="top"&amp;gt;Calculate your BMI&amp;lt;/h2&amp;gt;
        &amp;lt;p class="weight"&amp;gt;&amp;lt;b&amp;gt;Enter Your Weight in kg&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt;
        &amp;lt;input type="number" id="weightInput" /&amp;gt;
        &amp;lt;p class="height"&amp;gt;&amp;lt;b&amp;gt;Enter your height in meters&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt;

        &amp;lt;input type="number" id="heightInput" /&amp;gt;
        &amp;lt;br /&amp;gt;
        &amp;lt;button
          type="submit
      "
          id="btn"
        &amp;gt;
          Calculate
        &amp;lt;/button&amp;gt;
      &amp;lt;/section&amp;gt;

      &amp;lt;h1 id="result"&amp;gt;Your BMI is&amp;lt;/h1&amp;gt;
      &amp;lt;footer&amp;gt;
        &amp;lt;p class="foot" style="text-align: center"&amp;gt;
          Made with ❤ by SHASHANK SHARMA &amp;amp;copy;2023
        &amp;lt;/p&amp;gt;
      &amp;lt;/footer&amp;gt;
    &amp;lt;/div&amp;gt;

    &amp;lt;script src="script.js"&amp;gt;&amp;lt;/script&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body {
  margin: 0;
  padding-left: 350px;
  padding-right: 350px;
  overflow: auto;
  box-sizing: border-box;
  background-color: #ecf2ff;
}
div {
  border: 5px solid black;
  padding: 40px;
}
.top {
  font-size: 40px;
  color: white;
}

.para {
  font-size: 18px;
}
.work {
  text-align: center;
  background-color: #3e54ac;
}

#result {
  text-align: center;
}

.weight {
  font-size: 24px;
}
.height {
  font-size: 24px;
}
.foot {
  color: black;
  border: 2px solid black;
  padding: 20px;
  font-size: 20px;
}
#btn {
  margin-top: 15px;
  padding: 9px 40px;
  background-color: black;
  color: white;
}

/* CSS MEDIA QUERIES */
@media only screen and (max-width: 600px) {
  /* Adjust font sizes */
  h1 {
    font-size: 2rem;
  }
  h2 {
    font-size: 1.5rem;
  }
  h3 {
    font-size: 1.2rem;
  }
  p {
    font-size: 1rem;
  }
  /* Center align text */
  h1,
  h2,
  h3,
  p {
    text-align: center;
  }
  /* Adjust padding and margins */
  body {
    padding: 0.5rem;
  }
  .para {
    margin: 0.5rem;
  }
  /* Adjust input field sizes */
  #weightInput,
  #heightInput {
    width: 100%;
    margin-bottom: 0.5rem;
  }
}

@media only screen and (min-width: 600px) and (max-width: 1200px) {
  /* Adjust font sizes */
  h1 {
    font-size: 3rem;
  }
  h2 {
    font-size: 2rem;
  }
  h3 {
    font-size: 1.5rem;
  }
  p {
    font-size: 1.2rem;
  }
  /* Adjust padding and margins */
  body {
    padding: 1rem;
  }
  .para {
    margin: 1rem;
  }
  /* Adjust input field sizes */
  #weightInput,
  #heightInput {
    width: 50%;
    margin-bottom: 1rem;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, Let's move to the interesting part, which is JavaScript.&lt;/p&gt;

&lt;p&gt;To help you understand more easily, I divided the codes into 7 steps, So that you can understand the logic clearly without creating any mess.&lt;/p&gt;

&lt;h2&gt;
  
  
  STEP-1
&lt;/h2&gt;

&lt;p&gt;1) var :- Creating a variable&lt;/p&gt;

&lt;p&gt;2) valueOne :- The name we have given to our variable&lt;/p&gt;

&lt;p&gt;3) document:- The document from which we are selecting the element&lt;/p&gt;

&lt;p&gt;4) getElementById(“ ”) :- Id selector to select the element with a unique ID&lt;/p&gt;

&lt;p&gt;5) (“weightInput”) :- The name of the Id.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;By joining all the above parts, our code will look something like this;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var valueOne = document.getElementById("weightInput");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Lets deep dive into this and try to understand it clearly:-&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;First thing first, I have to create a variable to store the value which the user enters in the input field.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Here, I am giving the variable the name “valueOne”, you can give any name you want.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now after creating the variable and giving it a name, I can now move to the interesting part, now I have to access the value entered by the user in the input field.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As known already, I can select any element, change its value, get the value from it, and do many more things using DOM(Document Object Model).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;first I select the document from which I will be accessing the information, in this case, an HTML document.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After that, I select the desired element from the document using the selector.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you wanna learn about selectors, check out this blog of mine:- "&lt;a href="https://shashnode.hashnode.dev/understanding-domdocument-object-model"&gt;Understanding DOM(Document Object Model)&lt;/a&gt;"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Here, I give the unique Id to the element I am selecting, so I am using the ID selector:- getElementById(“ ”).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now, after doing all these steps, I will get the value entered by the user in the “weightInput” field.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  STEP-2
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var valueTwo = document.getElementById("heightInput");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Everything I did in step-1, goes exactly the same for step-2, except the variable name and Id name.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I gave the variable a new name here to store the “heightInput” value entered by the user.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I also changed the Id name to #heightInput&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I want to store the height and weight values separately, That’s Why I change these two things.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  STEP-3
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Now, after getting both the values and storing those values in our variables, it's time to do the calculation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I can do the calculation here with two methods:-&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Method-1:- by simply retrieving the values, storing them in variables, and doing the calculation.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Method-2:- by using the function()&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's see both methods and figure out which one works well for us.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Method-1:- by simply retrieving the values, storing them in variables, and doing the calculation.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var weight = document.getElementById("weightInput").value;
var height = document.getElementById("heightInput").value;
var bmi = Math.round(weight / (height * height));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Here, I store ‘weightInput’ in a new variable called ‘weight’&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Similarly, I store ‘heightInput’ in a new variable called ‘height’&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The formula to calculate BMI is weight divided by the square of height.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;so I created another variable and give it the name ‘bmi’ and applied the formula there.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As you see, there is Math.round written there and you might be thinking what is it for?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;So, what Math. round will do is it will round off the output to its nearest integer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Let's say, the user enters weight as 65kg and height as 1.63 meters. So without Math.round we get the output like this // 24.4646016&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now to round this off, we use Math.round and the same output looks something like this// 24.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Method-2:- by using the function()&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function bmiCalc(weight, height) {
  var bmi = Math.round(weight / (height * height));
  return bmi;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;I first created a function and give it the name of bmiCalc&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;As Known already, the function takes two arguments. In this case, those two arguments are ‘weight’ and ‘height’&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then I did the same as what I did early, imbedded the formula in a new variable with Math.round&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;return bmi =&amp;gt; returns the output after the calculation is done.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;**Que) WHICH METHOD SHOULD WE USE HERE?&lt;/p&gt;

&lt;p&gt;Ans) The Function Method()&lt;/p&gt;

&lt;p&gt;The function method is more appropriate here as it can be reused again. Also by using the function, I can separate the ‘calculation logic’ and the ‘code that retrieves the input values’.&lt;/p&gt;

&lt;p&gt;Calculation logic:- a function that takes two arguments, in this case, ‘weight’ and ‘height’, and then calculate BMI using a formula.&lt;/p&gt;

&lt;p&gt;Code that retrieves input value:- Here, I am talking about getElementById(“ ”), Which is retrieving information from the document.&lt;br&gt;
**&lt;br&gt;
Now, it's time to make the BMI calculator more functional and write some more codes for the ‘button’ element so that when the user enters height and weight and clicks the button, BMI gets displayed on the screen.&lt;/p&gt;
&lt;h2&gt;
  
  
  STEP-4
&lt;/h2&gt;

&lt;p&gt;I created a button in our HTML file and gave it an Id of ‘btn’.&lt;/p&gt;

&lt;p&gt;Let’s access this button and start playing with it.&lt;/p&gt;

&lt;p&gt;Now, by this time I think you guys will know how we can access the element from the document.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var valueThree = document.getElementById("btn");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Here I created a variable and gave it the name of valueThree and then using the Id selector, I accessed the button from the HTML document.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now, what I want here is, when the user enters the values and clicks the button, it will show the BMI to the user. But, it's not that simple, we have to write some behind the scene codes for this to work.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;First, I have to make the button work. Whatever event is happening (in this case ‘click’), it should listen to that event, do the behind-the-scenes calculation, and then returns the output.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;So for that, I have to add a function called addEventListener to the Button which listens to the event that is happening there.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  STEP-5
&lt;/h2&gt;

&lt;p&gt;**(SKIP THIS STEP IF YOU ALREADY KNOW ABOUT EVENT LISTENERS)&lt;/p&gt;

&lt;p&gt;Que) WHAT IS EVENT LISTENER?&lt;/p&gt;

&lt;p&gt;Ans) Event listener is a function that we attach to an HTML element and then it listens for the specific event to happen, be it a mouse click, or keyboard input, or anything else.&lt;/p&gt;

&lt;p&gt;It takes two arguments;&lt;/p&gt;

&lt;p&gt;1) first is the ‘event’ that is happening, in this case, click event&lt;/p&gt;

&lt;p&gt;2) function block, to execute a specific block of code that we want to work when the click happens.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var button = document.querySelector('button');
button.addEventListener('click', function() {
  alert('I got clicked!');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above dummy code, we accessed the button using a query selector and then added an event listener to it.&lt;/p&gt;

&lt;p&gt;After that, we write the code that whenever a user clicks on the button, an alert of ‘I got clicked!’ pops onto the screen.&lt;br&gt;
**&lt;/p&gt;

&lt;h2&gt;
  
  
  STEP-6
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;valueThree.addEventListener("click", function () {
  var weight = document.getElementById("weightInput").value;
  var height = document.getElementById("heightInput").value;

  var bmi = bmiCalc(weight, height);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;By reading Step-5, I now know that an event listener takes two arguments.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;First, I provide a click argument because here the ‘click’ is the event that is happening&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Second, I assigned a function that stores input values in variables, do the calculation, and returns the bmi value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now, when a user enters weight and height and presses the button, the event listener listens to the click, calls the function and the code gets executed.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  STEP-7
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Now as the user gets the BMI Values, I want to give specific messages to the user according to the BMI value they received.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;So, for that I used conditionals.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I covered the &lt;a href="https://shashnode.hashnode.dev/conditionals-in-javascript"&gt;conditionals&lt;/a&gt; in my previous blog so check that out before reading the below codes.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementById("result").innerHTML = "Your BMI is = " + bmi;
if (bmi &amp;lt; 18.5) {
  document.getElementById("result").innerHTML =
    "Your BMI is " + bmi + ", You are Underweight.";
} else if (bmi &amp;gt;= 18.5 &amp;amp;&amp;amp; bmi &amp;lt;= 24.9) {
  document.getElementById("result").innerHTML =
    "Your BMI is " + bmi + ", You are in Normal weight. Keep Maintaining this.";
} else if (bmi &amp;gt;= 25 &amp;amp;&amp;amp; bmi &amp;lt;= 29.9) {
  document.getElementById("result").innerHTML =
    "Your BMI is " +
    bmi +
    ", You are Overweight. Try to do workout 2-3 days in week.";
} else if (bmi &amp;gt; 30) {
  document.getElementById("result").innerHTML =
    "Your BMI is " +
    bmi +
    ", You are Obese. Try to do workout 5-6 days in week.";
}
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;That's it for this blog. I tried to explain this in the easiest way possible, so if you like the blog and if you think you learn something new today, make sure to leave a like, comment, and do follow me on Twitter, medium, and DevTo.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Make sure to leave your important feedback, so that I can improve my future blogs.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>programming</category>
    </item>
    <item>
      <title>New Day, New Blog</title>
      <dc:creator>Shashank Sharma</dc:creator>
      <pubDate>Tue, 07 Mar 2023 08:06:21 +0000</pubDate>
      <link>https://forem.com/anothereader_22/new-day-new-blog-20b0</link>
      <guid>https://forem.com/anothereader_22/new-day-new-blog-20b0</guid>
      <description>&lt;p&gt;I wrote a blog about &lt;strong&gt;JavaScript Conditionals&lt;/strong&gt; with some good examples. Do read and leave your important feedback so that I can improve my future blogs. &lt;br&gt;
&lt;a href="https://shashnode.hashnode.dev/conditionals-in-javascript"&gt;https://shashnode.hashnode.dev/conditionals-in-javascript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>community</category>
      <category>writing</category>
    </item>
    <item>
      <title>JAVASCRIPT CONDITIONALS</title>
      <dc:creator>Shashank Sharma</dc:creator>
      <pubDate>Tue, 07 Mar 2023 08:02:12 +0000</pubDate>
      <link>https://forem.com/anothereader_22/javascript-conditionals-bp9</link>
      <guid>https://forem.com/anothereader_22/javascript-conditionals-bp9</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Conditional statements are used for making decisions based on different conditions.&lt;/p&gt;

&lt;p&gt;Conditionals in JavaScript allow you to execute different blocks of code based on whether a certain condition is true or false.&lt;/p&gt;

&lt;p&gt;Conditions can be implemented using the following ways:-&lt;/p&gt;

&lt;p&gt;1)If&lt;/p&gt;

&lt;p&gt;2)If Else&lt;/p&gt;

&lt;p&gt;3)Else If&lt;/p&gt;

&lt;p&gt;4)Switch&lt;/p&gt;

&lt;p&gt;5)ternary operators&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1) If statement:-&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Shows truthy values&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;used to check if the given conditions are true &amp;amp; then execute the block of code.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(condition){
-----block of code which is going to execute-----
}

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

&lt;/div&gt;



&lt;p&gt;Let's understand this with 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;let num = 10
if (num &amp;gt; 0) {
console.log(num + "is a positive number")
} 
//Output =&amp;gt; 10 is a positive number//
//In the above example, we set the condition that if the user enters any number greater than 0, then "if" condition got executed and it returns the output.//
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2) Else statement:-&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It's like the opposite of an 'If' statement.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;So we will say that, if the 'If' condition is not executed which &lt;br&gt;
will happen when the given condition is false, then the 'Else' &lt;br&gt;
statement gets executed.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(condition){
-----block of code which is going to execute-----
} else {
-----block of code which is going to execute-----
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's take an example and try to understand this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//lets say we made a google form for football trails and age limit for the peoples who can apply for this is 16+. Now, If the user enter age more or less than the given age, certain blocks of code gets executed and give response accordingly.//
let myAge = 15
if (myAge &amp;gt; 16) {
console.log(myAge + " is valid age, you are eligible for trials.")
} else {
console.log(myAge + " is not a valid age, you are not eligible for the trials .")
}
//I Hope this clears how "If" and "Else" statements works//
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3) Else If:-&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is used for most cases because there are multiple options 
to select from sometimes.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(condition){
-----block of code which is going to execute-----
} else if(condition){
-----block of code which is going to execute-----
} else {
-----block of code which is going to execute-----
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's understand this with an example.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Let's say, we found an interesting website and in order to get 
the most out of this website it's asking us to make an account 
on it. As we are going through the process of making an account, 
it asks us to set questions and answers, in case we lost our 
password we can still be able to log in by giving the correct 
answer to the questions. Now, a few months pass and we want to 
sign in to that website but we couldn't remember our password, 
so the website gives us the option to sign in by giving answers 
to the questions we set previously. It gives us a question and 
four options to choose from.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Que) what is your favorite color?&lt;/p&gt;

&lt;p&gt;a) blue&lt;/p&gt;

&lt;p&gt;b) Indigo&lt;/p&gt;

&lt;p&gt;c) pink&lt;/p&gt;

&lt;p&gt;d) red&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let favColor = 'blue'
if(favColor === 'indigo'){
console.log("indigo is not your favorite color.Try again") 
} else if(favColor === 'pink'){
console.log("pink is not your favorite color.Try again")
} else if(favColor === 'red'){
console.log("Seriously, red, broooo Try again")
} else if(favColor === 'blue'){
console.log("Thats my bro, blue is your fav color. Never forget your password again.")
} else {
console.log("Enter your fav color")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4) Switch statement:-&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;'Switch statement' is an alternative for 'If Else' statements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The 'Switch statement' makes the code more concise and easier to &lt;br&gt;
read when you need to test a single variable against multiple &lt;br&gt;
possible values.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;switch (case value) {
case 1: 
   console.log('   ')
   break; //Suppose, the condition is satisfied after end of case 1, then, 'break' terminates the code//
case 2:
   console.log('   ')
   break;

default: //default runs only if all the cases dont satisfy conditions.//
   console.log(' ')
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's understand this with 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;let theDay = 'tuesday'
switch(theDay) {
case'monday':
   console.log('Today is not monday');
   break;
case'tuesday':
   console.log('Yes, today is tuesday');
   break;
default:
console.log('Please enter a valid day');
}
//In this example, the code terminates after 2nd case, as the condition is satisfied at case 2//
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5) Ternary operator:-&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;It is a simple way of writing an 'If Else' statement.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;It takes three values or operands&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A condition&lt;/li&gt;
&lt;li&gt;expression to execute if the condition is true&lt;/li&gt;
&lt;li&gt;expression to execute if the condition is false&lt;/li&gt;
&lt;/ul&gt;


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

&lt;p&gt;Let's understand this with 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;let playFootball = true
playFootball
? console.log('you needs football boots to play on ground')
: console.log('i dont wanna play')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The ternary operator is useful when you need to make a simple 
decision based on a single condition. It can make your code more 
concise and easier to read, especially when used with short 
expressions.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;This blog discusses various conditional statements in JavaScript, which allow the execution of different blocks of code based on certain conditions. This includes If, Else, Else If, Switch, and Ternary operators. If statements are used to check whether a condition is true, while Else statements execute when the If condition is false. Else If statements are used when multiple options need to be considered. Switch statements are an alternative to If Else statements and make the code more concise. Ternary operators are a simple way of writing If Else statements.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>frontend</category>
    </item>
    <item>
      <title>SIMPLE PROJECT</title>
      <dc:creator>Shashank Sharma</dc:creator>
      <pubDate>Mon, 06 Mar 2023 08:45:41 +0000</pubDate>
      <link>https://forem.com/anothereader_22/httpsbmicalculator19netlifyappmade-this-simple-bmi-calculator-with-html-css-and-javascript-2elj</link>
      <guid>https://forem.com/anothereader_22/httpsbmicalculator19netlifyappmade-this-simple-bmi-calculator-with-html-css-and-javascript-2elj</guid>
      <description>&lt;p&gt;&lt;a href="https://bmicalculator19.netlify.app"&gt;https://bmicalculator19.netlify.app&lt;/a&gt; Made this Simple BMI Calculator with HTML, CSS, and JavaScript.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>html</category>
    </item>
    <item>
      <title>CSS DISPLAY PROPERTY BASICS</title>
      <dc:creator>Shashank Sharma</dc:creator>
      <pubDate>Fri, 03 Mar 2023 07:47:03 +0000</pubDate>
      <link>https://forem.com/anothereader_22/css-display-property-basics-3ibi</link>
      <guid>https://forem.com/anothereader_22/css-display-property-basics-3ibi</guid>
      <description>&lt;p&gt;1)Block&lt;/p&gt;

&lt;p&gt;2)Inline&lt;/p&gt;

&lt;p&gt;3)Inline-Block&lt;/p&gt;

&lt;p&gt;4)None&lt;/p&gt;

&lt;p&gt;(A) Block:-&lt;/p&gt;

&lt;p&gt;Take the whole width of a line.&lt;br&gt;
                                  or&lt;br&gt;
Blocking out other elements which are in side by side position with it. &lt;/p&gt;

&lt;p&gt;Some Block level elements are:-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Paragraph&lt;/li&gt;
&lt;li&gt;Headers&lt;/li&gt;
&lt;li&gt;Divs&lt;/li&gt;
&lt;li&gt;Lists &amp;amp; list item&lt;/li&gt;
&lt;li&gt;Forms&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;(B) Inline:-&lt;/p&gt;

&lt;p&gt;Take the only amount of space that is needed.&lt;/p&gt;

&lt;p&gt;Some Inline elements are:-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;spans &lt;span&gt;&lt;/span&gt;
&lt;/li&gt;
&lt;li&gt;images &lt;img&gt;
&lt;/li&gt;
&lt;li&gt;Anchors &lt;a&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Que)Why do we use block elements when we can use inline elements which don't take much space?&lt;/p&gt;

&lt;p&gt;Ans) When using an inline element, we can’t change the height &amp;amp; width, their height, and width are set according to the content inside them, while in block elements, we can change the width.**&lt;/p&gt;

&lt;p&gt;NOTE:- We can change the property of the block element to an inline element using the display property, but after doing this, we can’t change width &amp;amp; height.&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="nt"&gt;p&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="nb"&gt;inline&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="nt"&gt;is&lt;/span&gt; &lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="nt"&gt;block&lt;/span&gt; &lt;span class="nt"&gt;element&lt;/span&gt; &lt;span class="nt"&gt;but&lt;/span&gt; &lt;span class="nt"&gt;here&lt;/span&gt; &lt;span class="nt"&gt;we&lt;/span&gt; &lt;span class="nt"&gt;change&lt;/span&gt; &lt;span class="nt"&gt;its&lt;/span&gt; &lt;span class="nt"&gt;property&lt;/span&gt; &lt;span class="nt"&gt;to&lt;/span&gt; &lt;span class="nt"&gt;an&lt;/span&gt; &lt;span class="nt"&gt;inline&lt;/span&gt; &lt;span class="nt"&gt;element&lt;/span&gt;&lt;span class="o"&gt;.//&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;(C) Inline-Block:-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It’s a mixture of both inline and block properties.&lt;/li&gt;
&lt;li&gt;we can change the width of the element, as well as let it display as inline so that it takes the space as much needed to it.
&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;p&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;inline-block&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;(D) None:-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If we want to hide things on our page, we can do that by two methods.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  1)display: None;

  2)visibility: hidden;
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>productivity</category>
      <category>learning</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Understanding DOM(Document Object Model)</title>
      <dc:creator>Shashank Sharma</dc:creator>
      <pubDate>Wed, 01 Mar 2023 08:26:31 +0000</pubDate>
      <link>https://forem.com/anothereader_22/understanding-domdocument-object-model-1c32</link>
      <guid>https://forem.com/anothereader_22/understanding-domdocument-object-model-1c32</guid>
      <description>&lt;p&gt;CONTENTS:-&lt;/p&gt;

&lt;p&gt;1)Introduction to the Document Object Model&lt;/p&gt;

&lt;p&gt;2)What is the DOM?&lt;/p&gt;

&lt;p&gt;3)How does DOM works&lt;/p&gt;

&lt;p&gt;The tree structure of the DOM&lt;/p&gt;

&lt;p&gt;Nodes and Elements&lt;/p&gt;

&lt;p&gt;properties&lt;/p&gt;

&lt;p&gt;Methods&lt;/p&gt;

&lt;p&gt;4)Selectors&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;INTRODUCTION&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this blog, we are going to deep dive into DOM and try to understand what is DOM, and how it works.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is DOM?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It acts as an interface for HTML &amp;amp; XML document, which represent the content of the document as tree-like structure.&lt;/li&gt;
&lt;li&gt;DOM allows JavaScript &amp;amp; other programming languages to interact with and manipulate the content &amp;amp; structure of HTML or XML documents.&lt;/li&gt;
&lt;li&gt;We can use DOM to add or remove elements from the page, change the text of elements, or responds to a mouse click or keyboard inputs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How does DOM work?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When a web page is loaded, the browser creates a Document Object Model(DOM) of the page.&lt;/li&gt;
&lt;li&gt;DOM works like a tree structure and converts the HTML code into a tree in which each node represents the elements of that particular HTML code.&lt;/li&gt;
&lt;li&gt;The root of this tree is document objects and each node represents elements like paragraph, image, headers, links, etc.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt; DOM BLOG &amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;button&amp;gt; Click here to read the blog &amp;lt;/button&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;For example, the above code is simple HTML code, then, What DOM will do is convert this code into a tree-like structure, so that the DOM manipulation can be done easily.&lt;/li&gt;
&lt;li&gt;Below is the image of how the above code gets converted into tree structure by DOM.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt; DOM BLOG &amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;button&amp;gt; Click here to read the blog &amp;lt;/button&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In DOM, Properties &amp;amp; Methods are two types of members associated with each node or element, or object. Properties and Methods along with some attributes and functions help in interacting with and manipulating the HTML to get the desired outcome.&lt;/p&gt;

&lt;p&gt;Let's Understand Properties and Methods with the example:-&lt;/p&gt;

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

&lt;p&gt;Let's say you have an HTML document with a heading element like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1 id="blog-head"&amp;gt;It's a blog about DOM&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Now if we want to change this heading without even touching HTML, Then what we going to do is use “DOM”.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;First we “get” this heading element in JavaScript using a selector called getElementbyID(” ”);&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;-It returns the value as an “object”.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var heading = document.getElementById('blog-head');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Then we access its inner HTML using “.innerHTML” and change its value/text accordingly.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;heading.innerHTML = 'Read, Learn and Leave your Feedback!';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;by doing all these steps, We change the innerHTML of the heading without even touching HTML.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Don’t worry we are going to learn selectors in just a few mins.&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;p&gt;Let's say you have a button element in your HTML document like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button id="my-button"&amp;gt;Click me to read the blog about DOM&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Now, same as above, first we select the button in JavaScript using a selector called .getElementsbyID(” ”).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It returns the value as an “object”.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now, we can manipulate and do changes with the button without touching HTML. Let’s say, we want an alert of “You clicked the button for reading the blog about DOM!” whenever a user clicks the button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In order to do that, we need to do two things.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Add event listener which response to the click&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;2.a function() which executes the block of code and returns the alert which says “You clicked the button for reading the blog about DOM!”.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var button = document.getElementById('my-button');
button.addEventListener('click', function() {
  alert('You clicked the button for reading the blog about DOM!');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This .addEventListener() is what we call a Methods in DOM. We passed two arguments in it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;1.click = The click on Button&lt;/p&gt;

&lt;p&gt;2.function() = which shows the alert when the click happens.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:- Methods have parenthesis() at the end and Properties do not.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In summary, Properties are the value of an element or node, or object, while Methods are similar to Functions() as it has a code that gets executed when that particular Method is called.&lt;/p&gt;

&lt;p&gt;There are differences b/w Methods() and Functions(), But it's not the topic of this blog.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SELECTORS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are many ways to select elements inside DOM.&lt;/p&gt;

&lt;p&gt;Lets say we have this HTML code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ul id = title&amp;gt;
  &amp;lt;li class = item&amp;gt; One &amp;lt;li&amp;gt;
  &amp;lt;li class = item&amp;gt; One &amp;lt;li&amp;gt;
  &amp;lt;li class = item&amp;gt; One &amp;lt;li&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, if we want to select the “li” we use selectors:-&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1) get Elements by Tag Name(””);&lt;/strong&gt;&lt;br&gt;
This Selector selects all the elements by there Tag names(li, ul, p, h1, h1 etc…)&lt;/p&gt;

&lt;p&gt;In this case we are selecting “li”.&lt;/p&gt;

&lt;p&gt;This selector selects all the “li” in the HTML document&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementsbyTagName("li");
// HTMLCollection(3) [li.item, li.item, li.item] =&amp;gt; Selects all 3 "li" from above HTML code
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note: Elements is plural, so it returns more than one value in form of an array.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now, Let's style the “li”&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementsbyTagName("li");
document.getElementsbyTagName("li")[0].style.color = "Red"; 
//change color of first li to red
document.getElementsbyTagName("li")[1].style.color = "Blue"; 
//change color of second li to Blue
document.getElementsbyTagName("li")[2].style.color = "Green"; 
//change color of Third li to Green
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We can also change the text size and text style by using different properties in place of “style”.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can change the style of all three elements at once using loops.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var items = document.getElementsByTagName("li");
for (let i = 0; i &amp;lt; 3; i++) {
  items[i].style.backgroundColor = "red";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2) get Elements by Class Name(””);&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This selector selects all the elements with particular class names given to that element.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ul id = title&amp;gt;
  &amp;lt;li class = item&amp;gt; One &amp;lt;li&amp;gt;
  &amp;lt;li class = item&amp;gt; One &amp;lt;li&amp;gt;
  &amp;lt;li class = item&amp;gt; One &amp;lt;li&amp;gt;
&amp;lt;/ul&amp;gt;
&amp;lt;button class="btn"&amp;gt;Click to read blog&amp;lt;/button&amp;gt;

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementsbyClassName("btn");
//This selects all the elements with .btn class in it
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Similar to the above example, we can also add different properties to get different result like changing text color, text size, and others.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementsByClassName("btn");
document.getElementsByClassName("btn")[0].textContent = "you are reading the blog"
//This changes the text content inside the button.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This selector also returns value as an array.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3)get Element by ID(” ”);&lt;/strong&gt;&lt;br&gt;
This selector select the element with Unique ID given to it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;ul id = title&amp;gt;
  &amp;lt;li class = item&amp;gt; One &amp;lt;li&amp;gt;
  &amp;lt;li class = item&amp;gt; One &amp;lt;li&amp;gt;
  &amp;lt;li class = item&amp;gt; One &amp;lt;li&amp;gt;
&amp;lt;/ul&amp;gt;
&amp;lt;button class="btn"&amp;gt;Click to read blog&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No, let's select the ul element using its ID.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementbyID("title");
//Selects element with ID Only
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.getElementbyID("title").style.color = "red";
//Styles the title element and changes its color to Red.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NOTE ⇒ ID selector has “Element” without "s" which means its singular, so it returns only single value.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Also, ID is a unique property and in every page there is only one ID of the same name so that also clears that there’s only one single element with a particular ID.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4)query Selector(””);&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;So, the previously three selectors are used in specific cases(for tag name, for class, for ID) But, in query selector, we can target any element with its name only, whether it be h1,h2,h3 or ID’s like(#title) or class like(.btn)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1 class = "header" id = "first-head"&amp;gt;Follow me for more such informative blogs&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We can style and manipulate the h1 element in three ways here;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.querySelector("h1").style.color = "red"
//Here we select the element with its tag name
//This changes color of element to Red
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.querySelector("#first-head").style.color = "Blue"
//Here we select the same element with its ID
//This changes color of element to Blue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;document.querySelector(".header").style.color = "Green"
//Here we select the same element with its class name
//This changes color of element to Green
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This is all for this blog. Read, Learn and leave your important feedback so that i can improve my future blogs. There is going to be one more part of this blog. so stay tuned for that one..&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>writing</category>
      <category>computerscience</category>
    </item>
  </channel>
</rss>
