<?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: Kritika Pattalam Bharathkumar</title>
    <description>The latest articles on Forem by Kritika Pattalam Bharathkumar (@kritikapattalam).</description>
    <link>https://forem.com/kritikapattalam</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%2F666609%2F482a270e-16ac-494c-b0ad-8722f1a4b523.jpeg</url>
      <title>Forem: Kritika Pattalam Bharathkumar</title>
      <link>https://forem.com/kritikapattalam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/kritikapattalam"/>
    <language>en</language>
    <item>
      <title>June Celebrations Globe - A 3D CSS Journey Through Cultural Unity</title>
      <dc:creator>Kritika Pattalam Bharathkumar</dc:creator>
      <pubDate>Sat, 28 Jun 2025 20:31:02 +0000</pubDate>
      <link>https://forem.com/kritikapattalam/june-celebrations-globe-a-3d-css-journey-through-cultural-unity-324o</link>
      <guid>https://forem.com/kritikapattalam/june-celebrations-globe-a-3d-css-journey-through-cultural-unity-324o</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for &lt;a href="https://dev.to/challenges/frontend-2025-06-04"&gt;Frontend Challenge - June Celebrations, CSS Art: June Celebrations&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Inspiration
&lt;/h2&gt;

&lt;p&gt;June represents a powerful intersection of celebrations that define our shared humanity from the vibrant colors of Pride Month advocating for love and equality, to the profound significance of Juneteenth commemorating freedom, the warmth of Father's Day honoring paternal bonds, and World Environment Day calling us to protect our planet. &lt;br&gt;
As a developer, I wanted to create something that visually captured how these seemingly different celebrations actually orbit around the same core values: &lt;em&gt;respect&lt;/em&gt;, &lt;em&gt;love&lt;/em&gt;, &lt;em&gt;freedom&lt;/em&gt;, and &lt;em&gt;responsibility&lt;/em&gt;. The globe concept felt perfect, each celebration gets its own "face" while being part of one unified whole, rotating together in harmony.&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;a href="https://codepen.io/kpattalam/full/xbGBzXQ" rel="noopener noreferrer"&gt;Demo&lt;/a&gt;
&lt;/h2&gt;

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

&lt;h2&gt;
  
  
  Journey
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Technical Challenge&lt;/strong&gt;&lt;br&gt;
Building a 3D rotating globe in pure CSS was both fun and challenging. I've been coding for years, but CSS 3D transforms still surprises me with their power and complexity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key techniques I used:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;transform-style&lt;/em&gt;: preserve-3d to create the 3D space&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;perspective&lt;/em&gt;: 1000px for realistic depth perception&lt;/li&gt;
&lt;li&gt;Strategic translateZ() positioning for each globe face&lt;/li&gt;
&lt;li&gt;Coordinated animation timing across multiple elements&lt;/li&gt;
&lt;li&gt;Complex gradient backgrounds respecting each celebration's authentic colors&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What I Learned&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Color Theory Matters:&lt;/strong&gt; Each celebration has deeply meaningful color associations. Pride Month's rainbow, Juneteenth's red-green-black symbolism, Father's Day's classic blues, and Environment Day's natural greens. I spent considerable time researching and respecting these choices.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Performance:&lt;/strong&gt; With multiple animations running simultaneously, I focused on using &lt;code&gt;transform&lt;/code&gt; and &lt;code&gt;opacity&lt;/code&gt; properties for smooth performance. Most animations use &lt;code&gt;ease-in-out&lt;/code&gt; timing for natural motion.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Responsive Design:&lt;/strong&gt; The globe scales from &lt;code&gt;400px&lt;/code&gt; to &lt;code&gt;300px&lt;/code&gt; on mobile while maintaining all visual relationships and animation timings.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;What I'm Proud Of&lt;/strong&gt;&lt;br&gt;
The unified rotation timing - the globe rotates every 20 seconds while orbital elements move at 15s and 25s intervals, creating a synchronized dance. I also researched each celebration's significance and visual representations to ensure respectful, authentic styling rather than just throwing colors together.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next Steps&lt;/strong&gt;&lt;br&gt;
I'd love to extend this concept with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Interactive controls&lt;/em&gt; such as pause rotation, click to focus on specific celebrations&lt;/li&gt;
&lt;li&gt;_Sound design _with subtle audio cues for each face transition&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Better accessibility&lt;/em&gt;: reduced motion preferences, screen reader optimizations&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The code uses CSS 3D transforms, strategic animation timing, and responsive design to create this rotating celebration of June's meaningful observances.&lt;/p&gt;

</description>
      <category>frontendchallenge</category>
      <category>devchallenge</category>
      <category>css</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Do you know what "use strict" does in JavaScript ?</title>
      <dc:creator>Kritika Pattalam Bharathkumar</dc:creator>
      <pubDate>Sat, 19 Nov 2022 20:03:31 +0000</pubDate>
      <link>https://forem.com/kritikapattalam/do-you-know-what-use-strict-does-in-javascript--1b35</link>
      <guid>https://forem.com/kritikapattalam/do-you-know-what-use-strict-does-in-javascript--1b35</guid>
      <description>&lt;p&gt;As JavaScript developers, we often have "use strict" - strict mode enabled in our projects. But do we know what does that expression does?. Let's find out.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a strict mode?
&lt;/h3&gt;

&lt;p&gt;JavaScript's strict mode makes JS be executed in strict mode, which helps identify common mistakes in coding practices which might lead to potential bugs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As part of this blog, let's see a list of things to remember while using strict mode in JavaScript&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Declaring strict mode&lt;/li&gt;
&lt;li&gt;Declaring a variable/object in strict mode&lt;/li&gt;
&lt;li&gt;Deleting a variable/object in strict mode&lt;/li&gt;
&lt;li&gt;Naming variables in strict mode&lt;/li&gt;
&lt;li&gt;Duplicating a parameter in a function&lt;/li&gt;
&lt;li&gt;Octal numeric literals are not allowed&lt;/li&gt;
&lt;li&gt;Eval function to create a variable&lt;/li&gt;
&lt;li&gt;Writing to a read-only property is not allowed&lt;/li&gt;
&lt;li&gt;Writing to a get-only property is not allowed&lt;/li&gt;
&lt;li&gt;'this' in strict mode &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Below is the list of few things which are identified as issues in strict mode vs without one
&lt;/h3&gt;

&lt;h3&gt;
  
  
  1.  Declaring strict mode
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;"use strict"&lt;/strong&gt; directive/expression is only recognized at the beginning of a script or a function.&lt;/p&gt;

&lt;h4&gt;
  
  
  Declare strict mode at the top of the file
&lt;/h4&gt;

&lt;p&gt;Strict mode can be declared at the top of the file as the first thing. When declared at the top it takes a global scope.&lt;br&gt;
In the below piece of code, use strict is declared as the first thing on the script file, making it a global scope, causing the strict mode feature to be enabled for the whole file.&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I am part of the file&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;test&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="nx"&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;javascript use strict is declared at the top of the file&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;test&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  What happens when strict mode is declared inside a function and not at the top?
&lt;/h4&gt;

&lt;p&gt;When used inside a function it has local scope and only that function will execute in strict mode. &lt;br&gt;
In the example below, the strict mode will be enabled only inside the function(local scope), and the code outside it will not follow the strict rules.&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&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="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  What to avoid?
&lt;/h4&gt;

&lt;p&gt;In the example below, use strict is not the first line &amp;amp; should be avoided. Preferably it's better to declare it on the top of the file due to global scope, instead of declaring it inside a function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I am inside this file&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;//not declared as the first line&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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;javascript use strict is not declared at the first thing&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;h3&gt;
  
  
  2. Variable/Object declaring in strict mode
&lt;/h3&gt;

&lt;p&gt;Using a variable/object without declaring it is not allowed in strict mode.&lt;br&gt;
In the example below, &lt;strong&gt;myVar&lt;/strong&gt; variable is assigned a value before declaring, this will throw an error. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What happens strict mode is not enabled?&lt;/strong&gt; - myVar will just be created as a global variable in that scenario.&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="nx"&gt;myVar&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;// This will throw an error&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&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="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Deleting a variable/object/function
&lt;/h3&gt;

&lt;p&gt;Deleting a variable or object or function when in strict mode enabled is not possible.&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;use&lt;/span&gt; &lt;span class="nx"&gt;strict&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;myVar&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;// This will throw an error&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//throws an error&lt;/span&gt;
&lt;span class="k"&gt;delete&lt;/span&gt; &lt;span class="nx"&gt;myVar&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//throws an error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Naming variables in strict mode
&lt;/h3&gt;

&lt;p&gt;When learning JS for the first time, the thing which we are sure often would have read is "Do not use reserved words as variable names".&lt;/p&gt;

&lt;p&gt;But at times people do tend to use reserved words without realizing it, in such cases strict mode helps by throwing an error. Just try it out in a chrome developer tool console and one should be able to see the difference.&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//static is a reserved word, hence when using strict mode, it will throw below error&lt;/span&gt;
&lt;span class="c1"&gt;// Uncaught SyntaxError: Unexpected strict mode reserved word&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. Duplicating a parameter in a function
&lt;/h3&gt;

&lt;p&gt;In the example below, you will see that the x parameter in the function log has been duplicated. This is not allowed in strict mode.&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;use&lt;/span&gt; &lt;span class="nx"&gt;strict&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// This will throw an error because "x" parameter is duplicated&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;x&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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  6. Octal numeric literals are not allowed
&lt;/h3&gt;

&lt;p&gt;In the example below, one might assume a preceding zero before 1 does nothing and the value might just be 12, but in JavaScript preceding zero before a number means its Octal numeric. &lt;br&gt;
Strict mode does not allow octal numeric.&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="c1"&gt;// Will throw an error&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;012&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;   
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  7. Eval function to create a variable is not allowed
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;var x = 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;// error&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  8. Writing to a read-only property is not allowed.
&lt;/h3&gt;

&lt;p&gt;In the example below, we define an object, and in the configurable property, we set the writable value to false, which means that a particular object is read-only.&lt;br&gt;
So when you try to assign a new value to that object, the strict mode will throw an error.&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;use strict&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;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;defineProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;x&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="na"&gt;value&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="na"&gt;writable&lt;/span&gt;&lt;span class="p"&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;// Will throw an error&lt;/span&gt;
&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&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;25&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  9.  Writing to a get-only property is not allowed
&lt;/h3&gt;

&lt;p&gt;In the example below, trying to write to a get-only property throws an error.&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;use strict&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;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="c1"&gt;// Will throw an error&lt;/span&gt;
&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&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;25&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  10. 'this' in strict mode
&lt;/h3&gt;

&lt;p&gt;In non-strict mode, when you call a function that isn't bound to any object "this" will refer to the global window object, whereas in strict mode it returns undefined.&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;use strict&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;foo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="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="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// undefined in strict mode&lt;/span&gt;
&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;The concludes what is strict mode is, how/where to declare it, and the list of few items to keep in mind/expect while using "use strict" in JavaScript.&lt;/p&gt;

&lt;h4&gt;
  
  
  References
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode"&gt;strict&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Follow me on  &lt;a href="https://twitter.com/KritikaPattalam"&gt;Twitter&lt;/a&gt;  | &lt;a href="https://www.linkedin.com/in/kritika-p-296739155/"&gt;LinkedIn&lt;/a&gt; for more web development related tips and posts. Feedbacks and suggestions are welcome.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Create a DOWNLOAD link in a single line of HTML</title>
      <dc:creator>Kritika Pattalam Bharathkumar</dc:creator>
      <pubDate>Tue, 07 Dec 2021 21:17:58 +0000</pubDate>
      <link>https://forem.com/kritikapattalam/create-a-download-link-in-a-single-line-of-html-4c3c</link>
      <guid>https://forem.com/kritikapattalam/create-a-download-link-in-a-single-line-of-html-4c3c</guid>
      <description>&lt;p&gt;As a website user, one would have come across links or buttons which say "Click to download" or "Download"  on a website. Have you ever wondered how can you add one to your website?.  Keep reading!!!. &lt;/p&gt;

&lt;p&gt;As part of this blog let us see how one can create a download link or button which lets you download an asset (e.g. image, pdf, files, etc.).  Do you know what is even more interesting?. This can be done with just a single line of HTML.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to create a download link or button in HTML
&lt;/h3&gt;

&lt;p&gt;The simple way to achieve this is &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;create an anchor tag with the text of your choice e.g "Click to download"&lt;/li&gt;
&lt;li&gt;to the href attribute add the path to the URL of the asset you want to be downloaded. In the below example,  I have added a path to an image.&lt;/li&gt;
&lt;li&gt;next comes the more important part, add the* *&lt;em&gt;download *&lt;/em&gt;*attribute to the anchor tag.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Yay!!! You have created your download link now.&lt;/p&gt;

&lt;h4&gt;
  
  
  How do I make this look like a button?.
&lt;/h4&gt;

&lt;p&gt;Simply add some CSS to make the anchor tag look like a button.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://blog.kritikapattalam.com/images/click-me.jpg"&lt;/span&gt; &lt;span class="na"&gt;download&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Click to download&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Save the file using a custom name
&lt;/h3&gt;

&lt;p&gt;In the above-given example, when the user clicks on download, it will save the file as "click-me.jpg", since that is the file name specified in the href attribute.&lt;/p&gt;

&lt;h4&gt;
  
  
  What about if you want to give it a different name?.
&lt;/h4&gt;

&lt;p&gt;Simply add the name as a value for the download attribute. For example in the below code, I have added &lt;strong&gt;download = test&lt;/strong&gt;, hence when the user clicks on download the file will be saved as test.jpg&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://blog.kritikapattalam.com/images/click-me.jpg"&lt;/span&gt; &lt;span class="na"&gt;download=&lt;/span&gt;&lt;span class="s"&gt;"test"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Click to download&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Can the asset/href value be of a different domain?
&lt;/h4&gt;

&lt;p&gt;NO, they cannot. Download attribute works only for files from the same Origin URL's (i.e the file should be hosted on the same origin as the site you are trying to implement it in) or blob or data URL files.&lt;/p&gt;

&lt;p&gt;In the below example, href value is from twitter.com whereas my site is blog.kritikapattalam.com. In this case, the download button will not work.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!--- Site origin - https://blog.kritikapattalam.com ---&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://twitter.com/images/click-me.jpg"&lt;/span&gt; &lt;span class="na"&gt;download=&lt;/span&gt;&lt;span class="s"&gt;"test"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Click to download&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well, that is it for this blog, and by now you should know how to create a download on your website.&lt;/p&gt;

&lt;p&gt;Follow me on  &lt;a href="https://twitter.com/KritikaPattalam"&gt;Twitter&lt;/a&gt;  | &lt;a href="https://www.linkedin.com/in/kritika-p-296739155/"&gt;LinkedIn&lt;/a&gt; for more web development related tips and posts. Feedbacks and suggestions are welcome.&lt;/p&gt;

&lt;h4&gt;
  
  
  Are you more of a Twitter person?. Then check out the short version of this blog in the below thread.
&lt;/h4&gt;


&lt;blockquote class="ltag__twitter-tweet"&gt;
      &lt;div class="ltag__twitter-tweet__media"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_-0-PByT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/media/E6BojTVXEAE8SbH.jpg" alt="unknown tweet media content"&gt;
      &lt;/div&gt;

  &lt;div class="ltag__twitter-tweet__main"&gt;
    &lt;div class="ltag__twitter-tweet__header"&gt;
      &lt;img class="ltag__twitter-tweet__profile-image" src="https://res.cloudinary.com/practicaldev/image/fetch/s---uKBzazU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/profile_images/1432790142889168899/o0sCWWhl_normal.png" alt="Kritika 🕸👩‍💻 profile image"&gt;
      &lt;div class="ltag__twitter-tweet__full-name"&gt;
        Kritika 🕸👩‍💻
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__username"&gt;
        &lt;a class="mentioned-user" href="https://dev.to/kritikapattalam"&gt;@kritikapattalam&lt;/a&gt;

      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__twitter-logo"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ir1kO05j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-f95605061196010f91e64806688390eb1a4dbc9e913682e043eb8b1e06ca484f.svg" alt="twitter logo"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__body"&gt;
      💡 HTML - Code Snippet💡&lt;br&gt;&lt;br&gt;Did you know that you can create a DOWNLOAD LINK , with just a single attribute on an anchor tag?. &lt;br&gt;&lt;br&gt;Check this out.!!!&lt;br&gt;&lt;br&gt;&lt;a href="https://twitter.com/hashtag/webdevelopment"&gt;#webdevelopment&lt;/a&gt; &lt;a href="https://twitter.com/hashtag/DEVCommunity"&gt;#DEVCommunity&lt;/a&gt; &lt;a href="https://twitter.com/hashtag/HTML"&gt;#HTML&lt;/a&gt; &lt;a href="https://twitter.com/hashtag/WomenWhoCode"&gt;#WomenWhoCode&lt;/a&gt; 
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__date"&gt;
      15:30 PM - 11 Jul 2021
    &lt;/div&gt;


    &lt;div class="ltag__twitter-tweet__actions"&gt;
      &lt;a href="https://twitter.com/intent/tweet?in_reply_to=1414245816064225280" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fFnoeFxk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-reply-action-238fe0a37991706a6880ed13941c3efd6b371e4aefe288fe8e0db85250708bc4.svg" alt="Twitter reply action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/retweet?tweet_id=1414245816064225280" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k6dcrOn8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-retweet-action-632c83532a4e7de573c5c08dbb090ee18b348b13e2793175fea914827bc42046.svg" alt="Twitter retweet action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/like?tweet_id=1414245816064225280" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SRQc9lOp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-like-action-1ea89f4b87c7d37465b0eb78d51fcb7fe6c03a089805d7ea014ba71365be5171.svg" alt="Twitter like action"&gt;
      &lt;/a&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;


</description>
      <category>webdev</category>
      <category>html</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Display random quotes from Chuck Norris API</title>
      <dc:creator>Kritika Pattalam Bharathkumar</dc:creator>
      <pubDate>Sat, 09 Oct 2021 01:31:16 +0000</pubDate>
      <link>https://forem.com/kritikapattalam/display-random-quotes-from-chuck-norris-api-1gki</link>
      <guid>https://forem.com/kritikapattalam/display-random-quotes-from-chuck-norris-api-1gki</guid>
      <description>&lt;p&gt;What a fun way to learn JavaScript than by building projects. In my previous blog post, I showed how one can  &lt;a href="https://dev.to/kritikapattalam/build-a-random-quote-generator-using-javascript-2n5j"&gt;build a random quote generator using arrays&lt;/a&gt;, it was simple and beginner-friendly. It would have helped one understand how to get started when building projects or how to address a problem. &lt;/p&gt;

&lt;p&gt;I thought let me take this one step above and show how one can create a similar random quote generator using an API, and I am going to be using the famous Chuck Norris API for this. &lt;/p&gt;

&lt;p&gt;Let's get started.&lt;/p&gt;

&lt;h4&gt;
  
  
  What will we learn as part of this blog
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;function declaration vs function expression&lt;/li&gt;
&lt;li&gt;window.onload function&lt;/li&gt;
&lt;li&gt;Fetch() method&lt;/li&gt;
&lt;li&gt;attaching onclick eventlistener to an element&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What will be the end result
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create random quotes on button click. The quotes are going to be from the Chuck Norris API&lt;/li&gt;
&lt;li&gt;Add a dropdown category filter that will display random quotes from the category chosen.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Project structure
&lt;/h3&gt;

&lt;p&gt;Create the list of files as listed below&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;index.html&lt;/li&gt;
&lt;li&gt;script.js&lt;/li&gt;
&lt;li&gt;style.css [ styles if we have any. As part of this blog, I am not going to add any styles.].&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  HTML
&lt;/h3&gt;

&lt;p&gt;HTML is going to be very simple&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Select field for the category&lt;/strong&gt;-  A simple select field with a list of all categories available in the Chuck Norris API. The options from inside the select field are created by the retrieved list from here &lt;br&gt;
&lt;a href="https://api.chucknorris.io/jokes/categories"&gt;Retrieve the categories&lt;/a&gt;&lt;br&gt;
&lt;a href="https://api.chucknorris.io/jokes/categories"&gt;https://api.chucknorris.io/jokes/categories&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Section to display Quotes&lt;/strong&gt; - A div "display_facts", is going to have the img tag which is going to have the chuck Norris icon from the API, and a p tag which will be populated with the quote from the API&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Generate Quote button&lt;/strong&gt; - This is the button onclick of which we will generate/retrieve a new quote from the API.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!Doctype html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Random Quote Generator&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"styles.css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"outer-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
           &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"heading"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                   &lt;span class="nt"&gt;&amp;lt;h3&amp;gt;&lt;/span&gt;Chuck Norris Facts - Select category from the dropdown&lt;span class="nt"&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
                       &lt;span class="nt"&gt;&amp;lt;select&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"category"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"all"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;All&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"animal"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Animal&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"career"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Career&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"celebrity"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Celebrity&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"explicit"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Explicit&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"fashion"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Fashion&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"food"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Food&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"history"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;History&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"money"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Money&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"movie"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Movie&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"music"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Money&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"political"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Political&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"religion"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Religion&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"science"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Science&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"sport"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Sport&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
                            &lt;span class="nt"&gt;&amp;lt;option&lt;/span&gt; &lt;span class="na"&gt;value=&lt;/span&gt;&lt;span class="s"&gt;"travel"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Travel&lt;span class="nt"&gt;&amp;lt;/option&amp;gt;&lt;/span&gt;
                        &lt;span class="nt"&gt;&amp;lt;/select&amp;gt;&lt;/span&gt;
           &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
           &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"display_facts"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"icon"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"quote"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Author&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
           &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"generate"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Generate&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  JavaScript
&lt;/h3&gt;

&lt;p&gt;Let's break this down into four steps&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an array inside a function and call that function on window load.&lt;/li&gt;
&lt;li&gt;Check what is Chuck Norris API capable of.&lt;/li&gt;
&lt;li&gt;Using fetch method retrieve all the results&lt;/li&gt;
&lt;li&gt;Generate quote on button click&lt;/li&gt;
&lt;li&gt;Let's generate quotes based on the category selected.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  1) Create an array inside a function and call that function on window load.
&lt;/h4&gt;

&lt;p&gt;This can be done in two ways using &lt;strong&gt;function expression&lt;/strong&gt; or vs &lt;strong&gt;function declaration&lt;/strong&gt;.  Read more about it  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function"&gt;here&lt;/a&gt; .&lt;br&gt;
The main difference with function expression is they are not hoisted, you cannot call the function expression before they are declared.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the below example, I created a function called &lt;strong&gt;generateQuote&lt;/strong&gt;, which contains a console.log hi. &lt;/li&gt;
&lt;li&gt;Next inside window.onload function I call the function generateQuote.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now save this file, and open index.html in your browser. In the chrome developer tool console, you should see the text "hi". What happens here is,  once the entire window including the DOM &amp;amp; assets is loaded, generateQuote function is called.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;As per MDN docs, The load event fires at the end of the document loading process. At this point, all of the objects in the document are in the DOM, and all the images, scripts, links, and sub-frames have finished loading.&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&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;generateQuote&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="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="nx"&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;Hi&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="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;generateQuote&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;
  
  
  2. Check what is Chuck Norris API capable of.
&lt;/h3&gt;

&lt;p&gt;As part of this step, we are going to retrieve the results from the Chuck Norris API&lt;/p&gt;

&lt;p&gt;Let's first see go check out the API &lt;/p&gt;

&lt;p&gt;&lt;a href="https://api.chucknorris.io/"&gt;ChuckNorris API&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;An important tip for anyone trying to use an API is to read the documentation of the API, they usually have answers to all your questions as to how to use them and what is the API capable of doing. &lt;/p&gt;

&lt;p&gt;When reading the API docs, what we concur is that the API is capable of doing the following things&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Retrieve random quotes&lt;/li&gt;
&lt;li&gt;Retrieve a list of random quotes based on a list of categories&lt;/li&gt;
&lt;li&gt;Retrieve the list of category&lt;/li&gt;
&lt;li&gt;Retrieve quotes based on the text entered by the user.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Using fetch method retrieve all the results
&lt;/h3&gt;

&lt;p&gt;As per the docs, the URL to fetch the results in a JSON format is to use the below URL&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Retrieve a random chuck joke in JSON format.
GET https://api.chucknorris.io/jokes/random
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just try opening this URL  &lt;a href="https://api.chucknorris.io/jokes/random"&gt;https://api.chucknorris.io/jokes/random&lt;/a&gt; in a browser window, you should see a similar response that is a single random quote with below details &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The time when the random joke was created&lt;/li&gt;
&lt;li&gt;an icon image of Chuck Norris&lt;/li&gt;
&lt;li&gt;id for that particular quote&lt;/li&gt;
&lt;li&gt;the updated date&lt;/li&gt;
&lt;li&gt;a URL to the quote on the Chuck Norris API page&lt;/li&gt;
&lt;li&gt;value - which is actually the quote that will be displayed on our page.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//The result has been formatted for a better view&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;categories&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;created_at&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2020-01-05 13:42:24.142371&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;icon_url&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://assets.chucknorris.host/img/avatar/chuck-norris.png&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;DciuboTEQxqEaVG0Qd2T2w&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;updated_at&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2020-01-05 13:42:24.142371&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;url&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://api.chucknorris.io/jokes/DciuboTEQxqEaVG0Qd2T2w&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;value&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Chuck Norris flashes the peace sign a lot because it's the easiest way to go for the eyes.&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;Now try refreshing the API URL and you should see a different response. Let's go ahead and see how to add this via code and display it on the page.&lt;/p&gt;

&lt;p&gt;The fetch method accepts one parameter which is the URL and returns a promise, hence we can use "then" which will return as a raw JSON first, and then once that raw JSON retrieve is successful, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;we then retrieve the icon &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;this.data.icon_url&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;and the value(which is the quote here)&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;this.data.value&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and display it into the respective DOMS using their HTML id. &lt;/p&gt;

&lt;p&gt;If at all there is an error, then the promise will return the console.log inside the catch statement.&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;generateQuote&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://api.chucknorris.io/jokes/random&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nx"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
    &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="c1"&gt;// Getting the raw JSON data&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="c1"&gt;// Storing the quotes internally upon &lt;/span&gt;
        &lt;span class="c1"&gt;// successful completion of request&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 

        &lt;span class="c1"&gt;// Displaying the quote When the Webpage loads&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;icon&lt;/span&gt;&lt;span class="dl"&gt;"&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;icon_url&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;quote&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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;error&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;generateQuote&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;Now, let's run the above piece of code and you should be seeing different quotes every single time you refresh your index.html. When you refresh the page, generateQuote a function inside the window.load gets executed, trying to fetch the new quote every refresh. &lt;/p&gt;

&lt;h3&gt;
  
  
  4. Generate quote on button click
&lt;/h3&gt;

&lt;p&gt;This can easily be done by adding a click event listener, which calls the generateQuote function onclick.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;generateQuote&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;generate&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&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="nx"&gt;generateQuote&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;
  
  
  5. Let's generate quotes based on the category selected.
&lt;/h3&gt;

&lt;p&gt;To retrieve random quotes the API URL to be used is below&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;GET &lt;a href="https://api.chucknorris.io/jokes/random?category=%7Bcategory%7D"&gt;https://api.chucknorris.io/jokes/random?category={category}&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this URL, {category} will be the value chosen from the dropdown .e&lt;/p&gt;

&lt;p&gt;eg: &lt;a href="https://api.chucknorris.io/jokes/random?category=movie"&gt;https://api.chucknorris.io/jokes/random?category=movie&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So in order to retrieve the results based on category is going to be done in just a few steps&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Retrieve the chosen category value from the dropdown&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;let category =  document.getElementById("category").value;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Pass the value of the category to the URL. The URL to use if you see below is decided based on an if/else condition. On the initial page load or if the user decides to view quotes from all the categories then we use the URL from the else condition, if the category chosen is something other than the option "all" eg. movie or sports then we use the URL inside the "if" condition.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&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;url&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;category&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="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;category&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

   &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;category&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;all&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;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://api.chucknorris.io/jokes/random?category=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;category&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="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://api.chucknorris.io/jokes/random&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;
  
  
  Final JavaScript
&lt;/h4&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;generateQuote&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;url&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;category&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="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;category&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

   &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;category&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;all&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;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://api.chucknorris.io/jokes/random?category=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;category&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="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://api.chucknorris.io/jokes/random&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;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; 
    &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="c1"&gt;// Getting the raw JSON data&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="c1"&gt;// Storing the quotes internally upon &lt;/span&gt;
        &lt;span class="c1"&gt;// successful completion of request&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 

        &lt;span class="c1"&gt;// Displaying the quote When the Webpage loads&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;icon&lt;/span&gt;&lt;span class="dl"&gt;"&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;icon_url&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;quote&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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;error&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;generateQuote&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;generate&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&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="nx"&gt;generateQuote&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;
  
  
  Output - Working Demo
&lt;/h3&gt;

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

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions"&gt;Function declaration vs Function expression&lt;/a&gt; &lt;/li&gt;
&lt;li&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener"&gt;addEventListener&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/fetch"&gt;Fetch Method&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Follow me on  &lt;a href="https://twitter.com/KritikaPattalam"&gt;Twitter&lt;/a&gt;  | &lt;a href="https://www.linkedin.com/in/kritika-p-296739155/"&gt;LinkedIn&lt;/a&gt; for more web development related tips and posts. Feedbacks and suggestions are welcome.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Build a Random Quote Generator using JavaScript</title>
      <dc:creator>Kritika Pattalam Bharathkumar</dc:creator>
      <pubDate>Fri, 24 Sep 2021 20:30:48 +0000</pubDate>
      <link>https://forem.com/kritikapattalam/build-a-random-quote-generator-using-javascript-2n5j</link>
      <guid>https://forem.com/kritikapattalam/build-a-random-quote-generator-using-javascript-2n5j</guid>
      <description>&lt;p&gt;The best way to learn to code is by practice and by building small projects. As part of this blog, let's build a beginner-friendly random quote generator in JavaScript.&lt;/p&gt;

&lt;p&gt;Check out my previous blog post  &lt;a href="https://dev.to/kritikapattalam/build-a-simple-clock-using-javascript-3am0"&gt;Build a Simple Clock using JavaScript.&lt;/a&gt; &lt;/p&gt;

&lt;h4&gt;
  
  
  What will we learn as part of this blog
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;function declaration vs function expression&lt;/li&gt;
&lt;li&gt;window.onload function&lt;/li&gt;
&lt;li&gt;Math.random()&lt;/li&gt;
&lt;li&gt;Math.floor&lt;/li&gt;
&lt;li&gt;attaching onclick eventlistener to an element&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's get started!!!.&lt;/p&gt;

&lt;h3&gt;
  
  
  Project structure
&lt;/h3&gt;

&lt;p&gt;Create the list of files as listed below&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;index.html&lt;/li&gt;
&lt;li&gt;script.js&lt;/li&gt;
&lt;li&gt;style.css [ styles if we have any. As part of this blog, I am not going to add any styles.].&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  HTML Structure - index.html
&lt;/h3&gt;

&lt;p&gt;HTML is going to be very simple, nothing fancy here.&lt;br&gt;
In the below HTML, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;link the stylesheet inside the head tag&lt;/li&gt;
&lt;li&gt;link the javascript file inside the head tag&lt;/li&gt;
&lt;li&gt;Inside the body tag we are going to have 
     A main outer container div which is going to hold the below elements
     - a paragraph tag to display the quote
     - a paragraph tag to display the author
     - a button - onclick of which we will generate random quotes
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!Doctype html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Random Quote Generator&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"styles.css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"outer-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"quotes"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"author"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"generate"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Generate&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
       &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  JavaScript
&lt;/h3&gt;

&lt;p&gt;Let's break this down into four steps&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an array inside a function and call that function on window load.&lt;/li&gt;
&lt;li&gt;Retrieve the quotes/author from the array.&lt;/li&gt;
&lt;li&gt;Onclick of the button, pick a random quote(index) from the array to display.&lt;/li&gt;
&lt;li&gt;Use the index generated to display the quotes and author into the paragraph tag using innerHTML.&lt;/li&gt;
&lt;li&gt;Call the function onclick&lt;/li&gt;
&lt;/ol&gt;
&lt;h4&gt;
  
  
  1) Create an array inside a function and call that function on window load.
&lt;/h4&gt;

&lt;p&gt;This can be done in two ways using &lt;strong&gt;function expression&lt;/strong&gt; or vs &lt;strong&gt;function declaration&lt;/strong&gt;.  Read more about it  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function"&gt;here&lt;/a&gt; .&lt;br&gt;
The main difference with function expression is they are not hoisted, you cannot call the function expression before they are declared.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the below example, I created a function called &lt;strong&gt;generateQuote&lt;/strong&gt;, which contains an array called &lt;strong&gt;quotes&lt;/strong&gt; and a console.log hi. I have declared &lt;strong&gt;quotes&lt;/strong&gt; as a &lt;strong&gt;const&lt;/strong&gt; variable because the value of the array is going to be always constant and will never change throughout this project.&lt;/li&gt;
&lt;li&gt;Next inside window.onload function I call the function generateQuote.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now save this file, and open index.html in your browser. In the chrome developer tool console, you should see the text "hi". What happens here is,  once the entire window including the DOM &amp;amp; assets is loaded, generateQuote function is called.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;As per MDN docs, The load event fires at the end of the document loading process. At this point, all of the objects in the document are in the DOM, and all the images, scripts, links, and sub-frames have finished loading.&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&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;generateQuote&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;quotes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Do not pity the dead, Harry. Pity the living, and, above all those who live without love.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Albus Dumbledore&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="na"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;It is impossible to manufacture or imitate love&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Horace Slughorn&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="na"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Being different isn't a bad thing. I mean that you are brave enough to be yourself.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Luna Lovegood&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="na"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;If you want to know what a man’s like, take a good look at how he treats his inferiors, not his equals.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sirius Black&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="na"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Never trust anything that can think for itself if you can’t see where it keeps its brain.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Arthur Weasley&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="na"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Every human life is worth the same, and worth saving.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Kingsley Shacklebolt&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="na"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Have a biscuit, Potter.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Minerva McGonagall&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="na"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Happiness can be found even in the darkest of times if one only remembers to turn on the light.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Albus Dumbledore&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="na"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Socks are Dobby’s favorite, favorite clothes, sir!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dobby&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="nx"&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;Hi&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="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;generateQuote&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;
  
  
  2. Let's see how to retrieve the quotes/author from the array
&lt;/h4&gt;

&lt;p&gt;First, let's see how to get the array values. Array values can be retrieved by their indexes. The index of an array starts from 0 to arraylength - 1. This means array index 0 will have the below values&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="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Do not pity the dead, Harry. Pity the living, and, above all those who live without love.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Albus Dumbledore&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;So if you want to print the fourth value, our index would be 3 [Remeber the index starts from 0 ] , so let's try to access the values for quotes and author using the index&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;//Syntax : arrayVariableName[index]&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;quotes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// If you want to know what a man’s like, take a good look at how he treats his inferiors, not his equals.&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;quotes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Sirius Black&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Onclick of the button, pick a random quote(index) from the array to display.
&lt;/h4&gt;

&lt;p&gt;The next thing we want to do is pick a random quote from the array. In the previous step we saw that we can access the quote using the index number, so we are going to need a random number to pick the quote. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;As per MDN Docs, Math.random() returns a floating-point, pseudo-random number between 0 (inclusive) and 1 (exclusive).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Since math.random returns a floating-point number eg: 0.65 and in order to access the array values we need an integer so let's use math.floor which will give us an integer&lt;/p&gt;

&lt;p&gt;As per MDN Docs, Math.floor() returns a number representing the largest integer less than or equal to the specified number.&lt;/p&gt;

&lt;p&gt;in order to return a more efficient number let's multiply the random number with the array length and use math.floor which will return us an integer and save that value in a variable.&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;arrayIndex&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="nx"&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="nx"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;quotes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Use the index generated to display the quotes and author into the paragraph tag using innerHTML
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;quotes&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;quotes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;arrayIndex&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;author&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;quotes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;arrayIndex&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now try saving the file, and when you open the index.html in the browser you should see a quote and author being displayed. When you refresh the browser, you should see a different quote&lt;/p&gt;

&lt;h4&gt;
  
  
  5. Call the function onclick
&lt;/h4&gt;

&lt;p&gt;In the previous step, we were able to see different quotes being displayed every time when we refresh the browser because for every refresh the function gets called, which returns a random index number, displaying a random quote. &lt;/p&gt;

&lt;p&gt;So now let's attach a eventlistener onclick to the button, which when clicked will call the generateQuote function&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;As per MDN docs, The EventTarget method addEventListener() sets up a function that will be called whenever the specified event is delivered to the target.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//Final JavaScript&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;generateQuote&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;quotes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Do not pity the dead, Harry. Pity the living, and, above all those who live without love.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Albus Dumbledore&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="na"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;It is impossible to manufacture or imitate love&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Horace Slughorn&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="na"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Being different isn't a bad thing. I means that you are brave enough to be yourself.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Luna Lovegood&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="na"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;If you want to know what a man’s like, take a good look at how he treats his inferiors, not his equals.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sirius Black&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="na"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Never trust anything that can think for itself if you can’t see where it keeps its brain.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Arthur Weasley&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="na"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Every human life is worth the same, and worth saving.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Kingsley Shacklebolt&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="na"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Have a biscuit, Potter.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Minerva McGonagall&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="na"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Happiness can be found even in the darkest of times, if one only remembers to turn on the light.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Albus Dumbledore&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="na"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Socks are Dobby’s favorite, favorite clothes, sir!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;author&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dobby&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;arrayIndex&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="nx"&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="nx"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;quotes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;quotes&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;quotes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;arrayIndex&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;author&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;quotes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;arrayIndex&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;onload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;generateQuote&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;generate&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&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="nx"&gt;generateQuote&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;
  
  
  Output - Working Demo
&lt;/h3&gt;

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

&lt;h4&gt;
  
  
  Conclusion
&lt;/h4&gt;

&lt;p&gt;Now you should have a working random quote generator, which generates random quotes onclick of a button. Now go ahead and try to load different quotes every few minutes or an hour. [&lt;strong&gt;Tip&lt;/strong&gt;: Call the function inside setInterval, instead of onclick]&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions"&gt;Function declaration vs Function expression&lt;/a&gt; &lt;/li&gt;
&lt;li&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener"&gt;addEventListener&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random"&gt;Math random&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor"&gt;Math floor&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Follow me on  &lt;a href="https://twitter.com/KritikaPattalam"&gt;Twitter&lt;/a&gt;  | &lt;a href="https://www.linkedin.com/in/kritika-p-296739155/"&gt;LinkedIn&lt;/a&gt; for more web development related tips and posts. Feedbacks and suggestions are welcome.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Build a Simple Clock using JavaScript</title>
      <dc:creator>Kritika Pattalam Bharathkumar</dc:creator>
      <pubDate>Tue, 14 Sep 2021 14:00:47 +0000</pubDate>
      <link>https://forem.com/kritikapattalam/build-a-simple-clock-using-javascript-3am0</link>
      <guid>https://forem.com/kritikapattalam/build-a-simple-clock-using-javascript-3am0</guid>
      <description>&lt;p&gt;The best way to learn to code is by practice and building small projects. &lt;br&gt;
As part of this blog, let's build a simple clock that will print the local time of the user using JavaScript. This is great for beginners and for someone who has just started with JavaScript.&lt;/p&gt;
&lt;h4&gt;
  
  
  What will we learn as part of this blog?
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;Defining a function using function expression vs function declartion &lt;/li&gt;
&lt;li&gt;document.getElementById&lt;/li&gt;
&lt;li&gt;setInterval&lt;/li&gt;
&lt;li&gt;Element.innerHTML&lt;/li&gt;
&lt;li&gt;Date.prototype.toLocaleDateString()&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's get started!!!.&lt;/p&gt;
&lt;h3&gt;
  
  
  Project structure
&lt;/h3&gt;

&lt;p&gt;Create the list of files as listed below&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;index.html&lt;/li&gt;
&lt;li&gt;script.js&lt;/li&gt;
&lt;li&gt;style.css [ styles if we have any. As part of this blog, I am not going to add any styles as such.].&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  HTML Structure - index.html
&lt;/h3&gt;

&lt;p&gt;In the below HTML, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;link the stylesheet inside the head tag&lt;/li&gt;
&lt;li&gt;link the javascript file inside the head tag
what will be present in those two files we will see later in the post. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The next step is, inside the body tag add an element of your choice with an id attribute. I have added a paragraph as the element with the id value as a clock. This paragraph is where we are going to display our time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!Doctype html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Simple Clock using JavaScript&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"styles.css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Simple Clock - Current Time&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"clock"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Script - script.js
&lt;/h3&gt;

&lt;p&gt;Let's break this down into steps&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a function called clock and call the function.&lt;/li&gt;
&lt;li&gt;Create a date object and retrieve the local time.&lt;/li&gt;
&lt;li&gt;Call the function clock every second so that the clock gets updated with the new value.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  1. Create a function called clock and call the function.
&lt;/h4&gt;

&lt;p&gt;This can be done in two ways using &lt;strong&gt;function expression&lt;/strong&gt; or vs &lt;strong&gt;function declaration&lt;/strong&gt;.  Read more about it  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/function" rel="noopener noreferrer"&gt;here&lt;/a&gt; .&lt;br&gt;
The main difference with function expression is they are not hoisted, you cannot call the function expression before they are declared.&lt;/p&gt;

&lt;p&gt;In the below example, I have defined a function called clock which has console.log, and then I call the function at the end of the script. Save the script file and when you open the index.html. You should see "Hi" in the developer tool.&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;//function expression&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;clock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="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;Hi&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="c1"&gt;// or&lt;/span&gt;
&lt;span class="c1"&gt;//function declaration&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;clock&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;Hi&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;clock&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Create a date object and retrieve the local time.
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;new Date()&lt;br&gt;
When called as a constructor, returns a new Date object.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;toLocaleTimeString returns the current local time in a string format.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;clock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;getDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&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;getDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLocaleTimeString&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;
  
  
  3. Display the time inside the paragraph tag
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;In the previous step we retrieved the value of the time, now we should display that value inside the paragraph tag.&lt;/li&gt;
&lt;li&gt;First, let's grab the element using its ID "clock"&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;The Document method getElementById() returns an Element object representing the element whose id property matches the specified string.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Into that element let's insert the time value returned by the date object. Using innerHTML we can set the value.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now let's view this in the browser, what you should be seeing is, the current local time when the browser loaded for the first time. If you refresh the browser, you will see that it updates the time to the current minute. So every single time you want to see the current time, you will have to refresh the browser.&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;clock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;getDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="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;clock&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;getDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLocaleTimeString&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. Call the function using setInterval, for every few seconds.
&lt;/h4&gt;

&lt;p&gt;With the last update, in order to see the current time, we had to refresh the browser every time so that the function gets called on refresh/page load and retrieves the current time. But a clock is supposed to update on its own, which means we will need the clock function to be executed every second to retrieve the current value. This is where we use the setInterval function.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;setInterval executes a function continuously for the given milliseconds.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's add the clock function inside the setInterval, now the clock function is repeated called for every 1000 seconds.&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;clock&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;getDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="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;clock&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;getDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLocaleTimeString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;setInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nf"&gt;clock&lt;/span&gt;&lt;span class="p"&gt;();},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Output
&lt;/h3&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%2Fgzs0v5ijivjteok81b4h.gif" 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%2Fgzs0v5ijivjteok81b4h.gif" alt="Clock"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions" rel="noopener noreferrer"&gt;Function declaration vs Function expression&lt;/a&gt; &lt;/li&gt;
&lt;li&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleTimeString" rel="noopener noreferrer"&gt;date object&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Follow me on  &lt;a href="https://twitter.com/KritikaPattalam" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;  | &lt;a href="https://www.linkedin.com/in/kritika-p-296739155/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; for more web development related tips and posts. Feedbacks and suggestions are welcome.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Disable Zoom on pinch in mobile using HTML tag</title>
      <dc:creator>Kritika Pattalam Bharathkumar</dc:creator>
      <pubDate>Tue, 07 Sep 2021 16:43:12 +0000</pubDate>
      <link>https://forem.com/kritikapattalam/disable-zoom-on-pinch-in-mobile-using-html-tag-2495</link>
      <guid>https://forem.com/kritikapattalam/disable-zoom-on-pinch-in-mobile-using-html-tag-2495</guid>
      <description>&lt;p&gt;As a user when you open a site in mobile, we tend to pinch and zoom the page to see things more clearly. Have you ever wondered if that feature can be disabled?.&lt;/p&gt;

&lt;p&gt;Yes, it can be disabled. What's more interesting is that it can be done by just a single line of code in HTML.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to disable zoom on pinch
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;On the head section of the HTML, include the following piece of line which is a meta tag that tells the browser the details of what should happen on a device's viewport
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!doctype html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
   &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0 ,
    maximum-scale=1.0 , user-scalable=no"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
   ...
 &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
 &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;...&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;name="viewport"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;this means that this meta tag is used for device viewport&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;width=device-width&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;assigns the width of the device as the viewport width&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;initial-scale and maximum-scale is set to 1 -&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;which means it occupies the full 100% of the viewport on page load&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;user-scalable=no, &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;setting the value to no or 0 is what tells the browser to prevent the page from scaling(zoom) in/out&lt;/p&gt;

&lt;h3&gt;
  
  
  Things to keep in mind while using this
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;This can affect accessibility, people with poor vision will have concerns when visiting the page, since it will prevent them for zooming/out and viewing content closely when required. So use wisely.&lt;/li&gt;
&lt;li&gt;iOS or safari still lets the users zoom for the above mentioned accessibility reason, so this fix might not work in those platform.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lets connect on  &lt;a href="https://twitter.com/KritikaPattalam"&gt;Twitter&lt;/a&gt;  | &lt;a href="https://www.linkedin.com/in/kritika-p-296739155/"&gt;LinkedIn&lt;/a&gt; for more web development related chats.&lt;/p&gt;

</description>
      <category>html</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to add a favicon to a website in a single line of HTML?</title>
      <dc:creator>Kritika Pattalam Bharathkumar</dc:creator>
      <pubDate>Tue, 31 Aug 2021 03:32:39 +0000</pubDate>
      <link>https://forem.com/kritikapattalam/how-to-add-a-favicon-to-a-website-in-a-single-line-of-html-2epb</link>
      <guid>https://forem.com/kritikapattalam/how-to-add-a-favicon-to-a-website-in-a-single-line-of-html-2epb</guid>
      <description>&lt;p&gt;Each one of us would login to websites or view multiple sites every single day in our life. And most of us are guilty of having more than one tab open in a browser eg: Facebook, Amazon, Google, Gmail, etc and even with so many tabs open we are still able to click on the correct tab by looking at that small icon on the browser tab which gives us an indication as to which site it is.&lt;/p&gt;

&lt;h3&gt;
  
  
  Have you ever wondered what is that small icon next to the browser title called?.
&lt;/h3&gt;

&lt;p&gt;Well, that is &lt;strong&gt;favicon&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;As part of this blog, we are going to see,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What is a favicon?&lt;/li&gt;
&lt;li&gt;How to identify a favicon on a webpage?&lt;/li&gt;
&lt;li&gt;How to add a favicon to a website with just a single line of HTML?.&lt;/li&gt;
&lt;li&gt;Does favicon help with SEO?&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  What is favicon?
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;/blockquote&gt;

&lt;p&gt;A favicon is a small icon associated with a website/page/application which is present next to the webpage title in a browser.&lt;/p&gt;

&lt;p&gt;It helps users visually identify websites more easily within browser tabs, bookmarks, shortcuts, and address bars.&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt; -  When more browser tabs are open by the favicon user can easily identify the tab and click on it to view the webpage or the same goes for when there are more bookmarks are present etc.&lt;br&gt;
With so many tabs/bookmarks open favicon makes it easier for users to identify the site by the image.&lt;/p&gt;
&lt;h3&gt;
  
  
  How to identify a favicon on a webpage?
&lt;/h3&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%2F99cmenkeom64hhvmr4p8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F99cmenkeom64hhvmr4p8.png" alt="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/99cmenkeom64hhvmr4p8.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The highlighted icon in circle is how it shows on the browser when the tabs are open.&lt;/li&gt;
&lt;li&gt;The highlighted icon in the rectangle below is how it shows when the website is bookmarked. You can see a list of favicons for websites bookmarked here eg: Google, Facebook, Gmail etc&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  How to add favicon to a website?
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt; My test site &amp;lt;/title&amp;gt;
    &amp;lt;link rel="icon" type="image/png" href="images/favicon.png"/&amp;gt;
    .....
&amp;lt;/head&amp;gt;

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

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;add a link tag in the head section of your webpage. [Refer to the above code piece.].&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;link tag should have the rel attribute value as&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;icon&lt;/strong&gt; if just using it for favicon next to the browser title/bookmarks/address bars etc.&lt;/li&gt;
&lt;li&gt;this same icon will be used when the webpage is saved as a shortcut to your desktop/laptop.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;/blockquote&gt;

&lt;p&gt;href="images/favicon.png"&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;add the path to the favicon as the href value&lt;/li&gt;
&lt;li&gt;Square icons are expected to be used as favicon. Most used sizes are - 16x16, 32x32 or 48x48.&lt;/li&gt;
&lt;li&gt;Back in the days, the image extension for favicon was &lt;strong&gt;.ico&lt;/strong&gt; for old browsers, but in recent times mostly &lt;strong&gt;.png&lt;/strong&gt; or &lt;strong&gt;svg&lt;/strong&gt; type images are used.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Does favicon help with SEO?
&lt;/h3&gt;

&lt;p&gt;The more important question to ask is does favicon helps with search engine optimization(SEO). No, it directly does not influence SEO, but it does help in creating brand awareness among the users visiting the site because most favicons are logos of the particular brand. Users are mostly seen to revisit pages that have the favicon present compared to the ones which does not. Because when people see a website without one, they tend to feel that it's not a genuine site.&lt;/p&gt;

&lt;p&gt;Well, that is it for this blog, and by now you should know how to add a favicon to a website and its uses.&lt;/p&gt;

&lt;p&gt;Follow me on  &lt;a href="https://twitter.com/KritikaPattalam" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;  | &lt;a href="https://www.linkedin.com/in/kritika-p-296739155/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; for more web development-related tips and posts. Feedbacks and suggestions are welcome.&lt;/p&gt;
&lt;h3&gt;
  
  
  Are you more of a Twitter person?. Then check out the short version of this blog in the below thread.
&lt;/h3&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1423059971315535879-674" src="https://platform.twitter.com/embed/Tweet.html?id=1423059971315535879"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1423059971315535879-674');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1423059971315535879&amp;amp;theme=dark"
  }



&lt;/p&gt;

</description>
      <category>html</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to add "SKIP TO MAIN CONTENT" to websites</title>
      <dc:creator>Kritika Pattalam Bharathkumar</dc:creator>
      <pubDate>Sat, 21 Aug 2021 01:23:37 +0000</pubDate>
      <link>https://forem.com/kritikapattalam/how-to-add-skip-to-main-content-to-websites-4f5i</link>
      <guid>https://forem.com/kritikapattalam/how-to-add-skip-to-main-content-to-websites-4f5i</guid>
      <description>&lt;p&gt;As part of this blog post let's see what is web accessibility, and how to add "skip to main content" link for web pages and why?.&lt;/p&gt;

&lt;h3&gt;
  
  
  Accessibility
&lt;/h3&gt;

&lt;p&gt;As per w3.org&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Web accessibility means that websites, tools, and technologies are designed and developed so that people with disabilities can use them. More specifically, people can: perceive, understand, navigate, and interact with the Web&lt;br&gt;
contribute to the Web&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For a normal user when he visits a page, he/she directly jumps to the section of the page where they want to read. But if we consider visually impaired users or someone who uses screen reader, the assistive device has to read through the entire page before they can reach a point which interests them. &lt;/p&gt;

&lt;p&gt;Let's assume when a user lands on the page , the screen reader will read the entire navigation/header and then goes to the actual content of the page. The user reads through the first page of your website once, now he/she goes to the second page and the screen reader will again start reading the entire navigation for them before they can go to the main content. This is where "SKIP TO MAIN CONTENT" link comes in handy for them.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to add "SKIP TO MAIN CONTENT" on the page
&lt;/h3&gt;

&lt;h4&gt;
  
  
  HTML
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Inside the body tag add an anchor tag as the first element. &lt;/li&gt;
&lt;li&gt;Add an id to the content you want the screenreader to jump/skip to. eg: 'main-content'&lt;/li&gt;
&lt;li&gt;Add the same id as the href value to the anchor tag eg: 'main-content'
&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;body&amp;gt;
    &amp;lt;a class="skip-link" href="#main-content"&amp;gt;SKIP TO MAIN CONTENT&amp;lt;/a&amp;gt;
    &amp;lt;header&amp;gt; .....&amp;lt;/header&amp;gt;
    &amp;lt;main id="main-content"&amp;gt;
         Main Body Content .....
    &amp;lt;/main&amp;gt;
    &amp;lt;footer&amp;gt;......&amp;lt;/footer&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  CSS
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Add CSS to the link to hide it from view.
&lt;strong&gt;[P.S Do not use display:none or visibility hidden because screen readers will not read the element. Our main focus is for the screen reader to read the link]&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;When the screenreader focuses on that element, make the element visible and also the screen reader will read the content inside the anchor tag . i.e "SKIP TO MAIN CONTENT" in our example.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.skip-link {
    position: absolute;
    left: -999px;
    width: 1px;
    height: 1px;
    top: auto;
}

.skip-link:active, .skip-link:focus {
    color: #000;
    display: inline-block;
    height: auto;
    width: auto;
    position: static;
    margin: auto
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  References
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.w3.org/WAI/fundamentals/accessibility-intro/"&gt;Accessibility&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Checkout my other blog posts
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://dev.to/kritikapattalam/getting-started-with-javascript-ultimate-free-resources-59p6"&gt;Getting Started with JavaScript - Ultimate Free Resources&lt;/a&gt; &lt;/li&gt;
&lt;li&gt; &lt;a href="https://dev.to/kritikapattalam/10-things-you-can-do-in-chrome-developer-tools-333g"&gt;10 Things you can do in Chrome Developer Tools &lt;/a&gt; &lt;/li&gt;
&lt;li&gt; &lt;a href="https://dev.to/kritikapattalam/2-simple-ways-you-can-truncate-text-using-css-1n18"&gt;2 Simple ways you can truncate text using CSS&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please share your feedbacks and suggestions in the comments below.&lt;/p&gt;

&lt;p&gt;Lets connect on  &lt;a href="https://twitter.com/KritikaPattalam"&gt;Twitter&lt;/a&gt;  | &lt;a href="https://www.linkedin.com/in/kritika-p-296739155/"&gt;LinkedIn&lt;/a&gt; for more web development related tips &amp;amp; tricks.&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>webdev</category>
      <category>programming</category>
      <category>html</category>
    </item>
    <item>
      <title>2 Uses of concat method when working with arrays in JavaScript</title>
      <dc:creator>Kritika Pattalam Bharathkumar</dc:creator>
      <pubDate>Thu, 12 Aug 2021 12:33:02 +0000</pubDate>
      <link>https://forem.com/kritikapattalam/2-uses-of-concat-method-when-working-with-arrays-in-javascript-3lhi</link>
      <guid>https://forem.com/kritikapattalam/2-uses-of-concat-method-when-working-with-arrays-in-javascript-3lhi</guid>
      <description>&lt;p&gt;Let's see two ways in which concat() method can be used while working with arrays in JavaScript. &lt;/p&gt;

&lt;h3&gt;
  
  
  1) Merging two or more arrays
&lt;/h3&gt;

&lt;p&gt;Let's now see how we can use the concat method to merge two given arrays, array 1 and array 2&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array1 = [1,2,3,4];
const array2 = [5,6,7];
// merge array 1 into array 2 and store it in a new variable 
const newMergedArray = [].concat(array1, array2);
console.log(newMergedArray); // [1, 2, 3, 4, 5, 6, 7]
console.log(array1); // [1, 2, 3, 4]
console.log(array2); // [5,6,7]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;const newMergedArray = [].concat(array1, array2);&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the above line [] creates a new array and the concat methods combine both array1, array2. This can also accept more than 2 arrays for concatenation by just adding them one next to the other&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;const newMergedArray = [].concat(array1, array2, array 3, arrayN);&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Another alternative for merging two arrays is below&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;const newMergedArray = array1.concat(array2, array 3, arrayN);&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  2) Flatten single level nested arrays
&lt;/h3&gt;

&lt;p&gt;Let's assume there is a nested array as below, and we would want to flatten it in such a way that the output is [1,2,3,4,5,6,7,8], this can be achieved by using concat() method with the help of spread operator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array1 = [1,2,[3,4],[5,6], 7, 8];
const flattened = [].concat(...array1);
console.log(flattened); // [1,2,3,4,5,6,7,8]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;P.S. The above code flattens just a single-level nested array.&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat"&gt;concat()&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax"&gt;spread operator&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Check out my other blog posts
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://dev.to/kritikapattalam/getting-started-with-javascript-ultimate-free-resources-59p6"&gt;Getting Started with JavaScript - Ultimate Free Resources&lt;/a&gt; &lt;/li&gt;
&lt;li&gt; &lt;a href="https://dev.to/kritikapattalam/10-things-you-can-do-in-chrome-developer-tools-333g"&gt;10 Things you can do in Chrome Developer Tools &lt;/a&gt; &lt;/li&gt;
&lt;li&gt; &lt;a href="https://dev.to/kritikapattalam/2-simple-ways-you-can-truncate-text-using-css-1n18"&gt;2 Simple ways you can truncate text using CSS&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Follow me on  &lt;a href="https://twitter.com/KritikaPattalam"&gt;Twitter&lt;/a&gt;  | &lt;a href="https://www.linkedin.com/in/kritika-p-296739155/"&gt;LinkedIn&lt;/a&gt; for more web development tips.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to display content in multiple columns using CSS</title>
      <dc:creator>Kritika Pattalam Bharathkumar</dc:creator>
      <pubDate>Fri, 06 Aug 2021 00:21:15 +0000</pubDate>
      <link>https://forem.com/kritikapattalam/how-to-display-content-in-multiple-columns-using-css-3cfa</link>
      <guid>https://forem.com/kritikapattalam/how-to-display-content-in-multiple-columns-using-css-3cfa</guid>
      <description>&lt;p&gt;In this article, we are going to see how or when  orphans or widows property in CSS can be used in showing content as multiple columns. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;[P.S : Refer the codepen given below to see visually how each property behaves]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Consider that you have a list of paragraphs and you want to show it in 3 or 4 columns and also decide where or how the content can break. Let's see the first step on how you can split the content in a simple way.&lt;/p&gt;

&lt;h3&gt;
  
  
  Simple steps on how to show content into multiple columns.
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create a div with multiple paragraph tags or a ul with multiple li tags&lt;/li&gt;
&lt;li&gt;Add the below code snippet&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;columns: 3 //  should be a positive integer. Here the paragraph will be split into 3 columns.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.split-3-columns {
  display: block;
  columns: 3; // value based on how many columns you want the content to split
  height: 250px; // height of the div as per your need
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, columns property accepts a positive integer value.Eg: value 3 means, the paragraphs will be split into 3 columns in the browser. &lt;br&gt;
When the content is split into multiple columns at times the layout or the paragraph might not look as expected.&lt;/p&gt;

&lt;p&gt;Eg: You might end up seeing something below, where in the second column, the column begins with the last line of the paragraph and seeing it in just two line looks weird. In this case you might wish that when the content does break you might want to show the last three lines of a paragraph at the start of the column instead of just two lines. This is where widows come into the picture. The same goes for the paragraph for &lt;strong&gt;"It was popularised..."&lt;/strong&gt; the first lines of the paragraph at the bottom of the column is in 2 lines, but you want to change how many lines of a paragraph are shown at the bottom of the column, this can be done using orphans.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aP_tAEWn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qfo06sqxu6ka7hmwsyzk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aP_tAEWn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qfo06sqxu6ka7hmwsyzk.png" alt="Example"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Orphans
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;The orphans property sets the minimum number of lines that can stay by themselves at the bottom of a fragment(columns) before a fragmentation(column) break. The value must be positive and applies to block level container elements. This value typically affects the first line of the paragraph&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;In the below codepen example , orphan value has been set to 1. Hence if you check the paragraph &lt;strong&gt;"It was popularised in the 1960s"&lt;/strong&gt;, it breaks as a single line i.e if the paragraph at the bottom of the column is expected to break at the first few lines then it will make sure that atleast 1 line of paragraph is seen at the bottom of the column(fragment), if there is no enough space to break based on the orphan value then it will rather start in the next column.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.split-3-columns {
  display: block;
  orphans: 1; 
  columns: 3; // value based on how many columns you want the content to split
  height: 250px; // height of the div as per your need
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Widows
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;The widow property sets the minimum number of lines that can stay by themselves at the top of a new fragment(column) after a fragmentation(column) break. The value must be positive and applies to block level container elements. This value is typically for the last line of a paragraph&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;In the below codepen example , widows value has been set to 5. Hence if you check the paragraph &lt;strong&gt;"Lorem Ipsum is simply dummy "&lt;/strong&gt; you would see atleast there are 5 lines of text from the end of the parapgraph is shown at the top of the second new column/fragment.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.split-3-columns {
  display: block;
  widows: 5; 
  columns: 3; // value based on how many columns you want the content to split
  height: 250px; // height of the div as per your need
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


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

&lt;h3&gt;
  
  
  Browser support:
&lt;/h3&gt;

&lt;p&gt;This is supported in all major browsers except for firefox in desktop and android firefox in mobile.&lt;br&gt;
For more details refer the MDN docs given below in the references section.&lt;/p&gt;

&lt;h3&gt;
  
  
  References
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/widows"&gt;Widows  - MDN docs&lt;/a&gt; &lt;/li&gt;
&lt;li&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/orphans"&gt;Orphans - MDN docs&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Follow me on  &lt;a href="https://twitter.com/KritikaPattalam"&gt;Twitter&lt;/a&gt;  | &lt;a href="https://www.linkedin.com/in/kritika-p-296739155/"&gt;LinkedIn&lt;/a&gt; for more web development related tips and posts.&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>programming</category>
      <category>html</category>
    </item>
    <item>
      <title>4 Less used HTML tags and their uses</title>
      <dc:creator>Kritika Pattalam Bharathkumar</dc:creator>
      <pubDate>Fri, 30 Jul 2021 00:42:29 +0000</pubDate>
      <link>https://forem.com/kritikapattalam/4-less-used-html-tags-and-their-uses-2df6</link>
      <guid>https://forem.com/kritikapattalam/4-less-used-html-tags-and-their-uses-2df6</guid>
      <description>&lt;p&gt;As part of this blog we are going to see 4 less used HTML tags during web development&lt;/p&gt;

&lt;h3&gt;
  
  
  1) Refresh the browser or redirect the page
&lt;/h3&gt;

&lt;p&gt;Did you know that you can refresh the browser automatically every few seconds with just a single line of code?.&lt;/p&gt;

&lt;p&gt;Yes, this can be done using the  http-equiv="refresh" attribute on the meta tag.&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;meta http-equiv="refresh" content="30"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;content value for 30 here means , the page will refresh every 30 seconds. Enter the value you want and see the page refresh every few seconds. &lt;/li&gt;
&lt;li&gt;if you add a url value followed by the integer, the page will redirect to the given url after the specified time.
eg:
&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;meta http-equiv="refresh" content="3;url=https://dev.to"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Refresh might have accessibility concerns so use with caution.&lt;/p&gt;

&lt;h3&gt;
  
  
  2) Calculating with output tag
&lt;/h3&gt;

&lt;p&gt;Output tag is used to represent the result of a calculation. In the below example we can calculate sum of two input fields and display it in the output field directly.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;for attribute eg: for="a b"&lt;br&gt;
is used to tell the output tag, which fields are used for the manipulation. In the below code pen for attribute value is the id of the two input fields. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;using the name attribute value, the results from the oninput javascript is populated into the output tag. eg: output tag name value is result hence in javascript you can pass the result after calculation using result.value&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;form oninput="result.value=parseInt(a.value)+parseInt(b.value)"&amp;gt;
    &amp;lt;input type="range" id="a" value="50"&amp;gt; +
    &amp;lt;input type="number" id="b" value="100"&amp;gt; =
    &amp;lt;output name="result" for="a b"&amp;gt;&amp;lt;/output&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;h3&gt;
  
  
  3) base tag
&lt;/h3&gt;

&lt;p&gt;This tag is very useful when your entire webpage points to the same base URL&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The base HTML element specifies the base URL to use for all relative URLs in a document. There can be only one  element in a document.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;head&amp;gt;
     &amp;lt;base href="https://kritika-pattalam.hashnode.dev/" target="_blank"&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
      &amp;lt;a href="2-simple-ways-you-can-truncate-text-using-css"&amp;gt;Click on this url&amp;lt;/a&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  How to use it ?.
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;In the below codepen, I have specified the base href attribute to my hashnode main blog page. eg: &lt;a href="https://kritika-pattalam.hashnode.dev/"&gt;https://kritika-pattalam.hashnode.dev/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;In the anchor tag instead of specifying the absolute URL, I have used the relative URL of my blog post eg : 2-simple-ways-you-can-truncate-text-using-css 
And the entire blog URL is : &lt;a href="https://kritika-pattalam.hashnode.dev/2-simple-ways-you-can-truncate-text-using-css"&gt;https://kritika-pattalam.hashnode.dev/2-simple-ways-you-can-truncate-text-using-css&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

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

&lt;h3&gt;
  
  
  4) Template tag in HTML - The Content Template element
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The HTML &lt;strong&gt;template&lt;/strong&gt; tag permits you to declare pieces of HTML sections that can be cloned and embedded into the DOM using script. &lt;/li&gt;
&lt;li&gt;The contents of the template tag are not added to the DOM on page load, they are only inserted based on some user interaction. Eg: Lets say there is an image inside the template tag, the image does not get downloaded until the template is cloned and inserted into the DOM structure.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;Leave me a comment below if you know about other rarely used HTML tags.&lt;/p&gt;

&lt;h3&gt;
  
  
  References - mdn docs
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base"&gt;Base Tag&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta"&gt;http-equiv="refresh"&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/output"&gt;output tag&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template"&gt;template tag&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lets connect on  &lt;a href="https://twitter.com/KritikaPattalam"&gt;Twitter&lt;/a&gt;  | &lt;a href="https://www.linkedin.com/in/kritika-p-296739155/"&gt;LinkedIn&lt;/a&gt; for more web development related chats.&lt;/p&gt;

</description>
      <category>html</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
