<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Divyamcm</title>
    <description>The latest articles on DEV Community by Divyamcm (@divyamcm).</description>
    <link>https://dev.to/divyamcm</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%2F720972%2Fdcc31174-301f-4265-b3bc-46c832a462e6.jpg</url>
      <title>DEV Community: Divyamcm</title>
      <link>https://dev.to/divyamcm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/divyamcm"/>
    <language>en</language>
    <item>
      <title>PASSWORD GENERATOR using HTML, CSS, and Javascript</title>
      <dc:creator>Divyamcm</dc:creator>
      <pubDate>Wed, 20 Oct 2021 10:44:35 +0000</pubDate>
      <link>https://dev.to/divyamcm/password-generator-using-html-css-and-javascript-3a0c</link>
      <guid>https://dev.to/divyamcm/password-generator-using-html-css-and-javascript-3a0c</guid>
      <description>&lt;p&gt;==================================================&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1477039181047-efb4357d01bd%3Fixlib%3Drb-1.2.1%26ixid%3DMnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8%26auto%3Dformat%26fit%3Dcrop%26w%3D1470%26q%3D80" 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%2Fimages.unsplash.com%2Fphoto-1477039181047-efb4357d01bd%3Fixlib%3Drb-1.2.1%26ixid%3DMnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8%26auto%3Dformat%26fit%3Dcrop%26w%3D1470%26q%3D80"&gt;&lt;/a&gt;Photo by &lt;a href="https://unsplash.com/@markusspiske?utm_source=medium&amp;amp;utm_medium=referral" rel="noopener noreferrer"&gt;Markus Spiske&lt;/a&gt; on &lt;a href="https://unsplash.com?utm_source=medium&amp;amp;utm_medium=referral" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dear Reader,&lt;/p&gt;

&lt;p&gt;Let’s build a password generator which generate passwords of different lengths and which can include or exclude special characters in the generated passwords based on user selection. This is going to be simple. Stay with me till the end. 🔐&lt;/p&gt;

&lt;p&gt;Folder structure:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;em&gt;index.html — contains the HTML layout which defines the element structure that would be shown on the page.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt; &lt;em&gt;style.css- contains CSS code for styling. Using CSS we can style the different portions to make them more visually appealing.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt; &lt;em&gt;script.js — contains Javascript code where all the functions are placed.&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  HTML Layout
&lt;/h1&gt;

&lt;p&gt;Open VSCode and create the basic HTML structure in an &lt;strong&gt;index.html&lt;/strong&gt; file by pressing ! and then pressing tab. Give the &lt;strong&gt;title&lt;/strong&gt; as ‘&lt;strong&gt;Password Generator&lt;/strong&gt;’. Link &lt;strong&gt;style.css&lt;/strong&gt; and &lt;strong&gt;script.js&lt;/strong&gt; to the created HTML file and link &lt;strong&gt;FontAwesome&lt;/strong&gt; CSS to use icons*&lt;em&gt;.&lt;/em&gt;*&lt;/p&gt;

&lt;p&gt;Generate Password Button: Create &lt;strong&gt;button&lt;/strong&gt; inside &lt;strong&gt;div&lt;/strong&gt; class &lt;strong&gt;wrapper&lt;/strong&gt; clicking on which we will generate the password. Add &lt;code&gt;&amp;lt;i class=”fab fa-keycdn”&amp;gt;&amp;lt;/i&amp;gt;&lt;/code&gt; to display icon.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button id="generate" class="action-btn"&amp;gt;Generate Password &amp;lt;i class="fab fa-keycdn"&amp;gt;&amp;lt;/i&amp;gt;&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Slider to select length: Add one more div class &lt;strong&gt;slider_main&lt;/strong&gt; inside &lt;strong&gt;wrapper class .slider_main&lt;/strong&gt; class contains the slider which is used to select the length of the password. The  min, max and the initial  value is set and the selected value using slider will be displayed in the &lt;strong&gt;output&lt;/strong&gt; section.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="slider\_main"&amp;gt;
 &amp;lt;input type="range" value="8" min="1" max="25" class="slider"oninput="this.nextElementSibling.value = this.value" id="slider"&amp;gt;
 &amp;lt;output&amp;gt;8&amp;lt;/output&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Checkbox to include special characters: Add an &lt;strong&gt;input&lt;/strong&gt; tag of type &lt;strong&gt;checkbox&lt;/strong&gt;, on checking we will include special characters in the password, and on unchecking we will remove special characters from password.&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;label class="container" style="font-family: fantasy;color: rgb(3, 3, 3);"&amp;gt;Include special characters
            &amp;lt;input type="checkbox" checked="checked" id="checkbox"&amp;gt;
            &amp;lt;span class="checkmark"&amp;gt;&amp;lt;/span&amp;gt;
        &amp;lt;/label&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Password display and copy button: Add a &lt;strong&gt;h5&lt;/strong&gt; tag under div class &lt;strong&gt;wrapper_main&lt;/strong&gt; to display the generated password and add a button to copy the generated password. Use &lt;code&gt;&amp;lt;i class=”fas fa-clipboard”&amp;gt;&lt;/code&gt; for the clipboard icon.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="wrapper_main"&amp;gt;
        &amp;lt;h5 id="pwd_txt"&amp;gt;&amp;lt;/h5&amp;gt;
        &amp;lt;button id="clipboard" class="clipboard"&amp;gt;
            &amp;lt;i class="fas fa-clipboard"&amp;gt;&amp;lt;/i&amp;gt;
        &amp;lt;/button&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the complete HTML code,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Password Generator&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"&amp;gt;
     &amp;lt;link rel="stylesheet" href="style.css"&amp;gt; 
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;div class="wrapper"&amp;gt;
        &amp;lt;button id="generate" class="action-btn"&amp;gt;
            Generate Password &amp;lt;i class="fab fa-keycdn"&amp;gt;&amp;lt;/i&amp;gt;
        &amp;lt;/button&amp;gt;
        &amp;lt;div class="slider_main"&amp;gt;
            &amp;lt;input type="range" value="8" min="1" max="25" class="slider"
                oninput="this.nextElementSibling.value = this.value" id="slider"&amp;gt;
            &amp;lt;output&amp;gt;8&amp;lt;/output&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;label class="container" style="font-family: fantasy;color: rgb(3, 3, 3);"&amp;gt;Include special characters
            &amp;lt;input type="checkbox" checked="checked" id="checkbox"&amp;gt;
            &amp;lt;span class="checkmark"&amp;gt;&amp;lt;/span&amp;gt;
        &amp;lt;/label&amp;gt;
    &amp;lt;/div&amp;gt;



    &amp;lt;div class="wrapper_main"&amp;gt;
        &amp;lt;h5 id="pwd_txt"&amp;gt;&amp;lt;/h5&amp;gt;
        &amp;lt;button id="clipboard" class="clipboard"&amp;gt;
            &amp;lt;i class="fas fa-clipboard"&amp;gt;&amp;lt;/i&amp;gt;
        &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;script src="script.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt; 

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

&lt;/div&gt;



&lt;h1&gt;
  
  
  CSS Styling
&lt;/h1&gt;

&lt;p&gt;Implement a slider to override the default one and hovering on the slider will make it less opaque.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.slider{

-webkit-appearance: none;
width: 70%;
height: 10px;
background: #f7be04;
border-radius: 15px;
opacity: 1;
-webkit-transition: .2s;
transition: opacity .2s;
margin-left: 40px;
margin-top: 25px;
margin-bottom: 20px;
}

.slider:hover{
opacity: 0.5;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Complete CSS code is here&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;html{
min-height: 100%;
}



body{
min-height: 100%;
background-color: #2d3436;
background-image: linear-gradient(315deg, #2d3436 0%, #000000 74%);
text-align: center;
}



.slider{
-webkit-appearance: none;
width: 70%;
height: 10px;
background: #f7be04;
border-radius: 15px;
opacity: 1;
-webkit-transition: .2s;
transition: opacity .2s;
margin-left: 40px;
margin-top: 25px;
margin-bottom: 20px;
}

.slider:hover{
opacity: 0.5;
}

.slider::-webkit-slider-thumb{
-webkit-appearance: none;
width: 15px;
height: 15px;
background: #000000;
border-radius: 50%;
cursor: pointer;
}

.action-btn{
background-color: #000;
border: 0;
color: #f7be04;
font-size: 20px;
cursor: pointer
padding: 10px;
margin: 10px  20px;
border-radius: 15px;
font-family: fantasy;
opacity: 1;
transition: opacity .2s;
}



.action-btn:hover{
opacity: 0.5;
}



.wrapper{
display: flex;
background-color: rgb(253, 253, 252);
flex-direction: column;
width: 30%;
margin-top: 10%;
margin-left: 35%;
border-radius: 15px;
font-family: fantasy;
padding-bottom: 1%;
}

.slider_main{
display: flex;
flex-direction: row;
}

output{
margin-top: 20px;
margin-left: 10px;
}



.wrapper_main
{
display: flex;
background-color: rgb(253, 253, 252);
flex-direction: row;
width: 22%;
margin-top: 5%;
margin-left: 38%;
border-radius: 15px;
font-family: Georgia, serif;
padding-left: 45px;
}



.clipboard{
margin-left: auto;
cursor: pointer;
border: 0;
background-color: white;
color:black;
border-radius: 15px;
font-size: 23px;
opacity: 1;
transition: opacity .2s;
}



.clipboard:hover{
opacity: 0.5;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Javascript logic
&lt;/h1&gt;

&lt;p&gt;We need to generate the password by selecting characters randomly. The length slider value given by the user will determine the length of the password and the user can choose whether to include special characters or not using the checkbox. To implement this functionality let’s fetch the required elements and store them in the below constants and variables.&lt;/p&gt;

&lt;p&gt;password_ele — To store the &lt;strong&gt;h5&lt;/strong&gt; element which is used to set the generated password.&lt;/p&gt;

&lt;p&gt;string — To store the &lt;strong&gt;characters&lt;/strong&gt; used to generate passwords except for special characters.&lt;/p&gt;

&lt;p&gt;special_chars —Used to store &lt;strong&gt;special characters&lt;/strong&gt;, based on check box value we can add special characters to the password.&lt;/p&gt;

&lt;p&gt;generate — Used to store the &lt;strong&gt;Generate Password&lt;/strong&gt; button.&lt;/p&gt;

&lt;p&gt;clipboard — Used to store &lt;strong&gt;clipboard&lt;/strong&gt; button.&lt;/p&gt;

&lt;p&gt;pwd_length — Used to store the &lt;strong&gt;slider&lt;/strong&gt; element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const password_ele = document.getElementById("pwd_txt");

var string = "ABCDEFGHIJKLMNOPQRSTUVWXYZacdefghijklnopqrstuvwxyz0123456789";

const special_chars = "@#$%^&amp;amp;*";

const generate = document.getElementById("generate");

const clipboard = document.getElementById("clipboard");

var pwd_length = document.getElementById("slider");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On clicking &lt;strong&gt;Generate Password&lt;/strong&gt; button we will execute some lines of codes to generate the password using &lt;strong&gt;Math.random()&lt;/strong&gt; function. If checkbox is checked then we will add special characters to our original string. Original string contains &lt;code&gt;“ABCDEFGHIJKLMNOPQRSTUVWXYZacdefghijklnopqrstuvwxyz0123456789”.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Loop through the string to fetch the character randomly and in each loop add the randomly selected character to the &lt;strong&gt;password&lt;/strong&gt; variable which was empty initially. The number of times the loop is executed is equal to the slider length so, the length of the password will be equal to the length given by the user.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;generate.addEventListener('click', () =&amp;gt; {
    let password = "";
    var checked = document.getElementById("checkbox").checked;
    var final_string = string;
    console.log(checked);
    if (checked) {
        final_string += "@#$%^&amp;amp;*";
    }
    for (var i = 0; i &amp;lt; pwd_length.value; i++) {
        let pwd = final_string[Math.floor(Math.random() * final_string.length)];
        password += pwd;
    }
    password_ele.innerText = password;
    final_string = string;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;on click of clipboard icon, the password text should get selected and display an alert message.&lt;br&gt;
&lt;/p&gt;

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

clipboard.addEventListener('click', () =&amp;gt; {

 navigator.clipboard.writeText(password_ele.innerText);

 alert("Password copied to clipboard");

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

&lt;/div&gt;



&lt;p&gt;Complete javascript code is here,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const password_ele = document.getElementById("pwd_txt");
var string = "ABCDEFGHIJKLMNOPQRSTUVWXYZacdefghijklnopqrstuvwxyz0123456789";
const special_chars = "@#$%^&amp;amp;*";
const generate = document.getElementById("generate");
const clipboard = document.getElementById("clipboard");
var pwd_length = document.getElementById("slider");


generate.addEventListener('click', () =&amp;gt; {
    let password = "";
    var checked = document.getElementById("checkbox").checked;
    var final_string = string;
    console.log(checked);
    if (checked) {
        final_string += "@#$%^&amp;amp;*";
    }
    for (var i = 0; i &amp;lt; pwd_length.value; i++) {
        let pwd = final_string[Math.floor(Math.random() * final_string.length)];
        password += pwd;
    }
    password_ele.innerText = password;
    final_string = string;
});


clipboard.addEventListener('click', () =&amp;gt; {
    navigator.clipboard.writeText(password_ele.innerText);
    alert("Password copied to clipboard");
});


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

&lt;/div&gt;



&lt;p&gt;Let’s check the output&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/fz6LiqBjVxs"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Complete code is placed in &lt;a href="https://github.com/Divyamcm/Projects/tree/main/Password_Generator" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Thanks for your interest.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>html</category>
      <category>css</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Countdown Timer using HTML, CSS, and Javascript</title>
      <dc:creator>Divyamcm</dc:creator>
      <pubDate>Fri, 15 Oct 2021 22:35:20 +0000</pubDate>
      <link>https://dev.to/divyamcm/countdown-timer-using-html-css-and-javascript-19pj</link>
      <guid>https://dev.to/divyamcm/countdown-timer-using-html-css-and-javascript-19pj</guid>
      <description>&lt;p&gt;===============================================&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fimages.unsplash.com%2Fphoto-1513102419401-0cc6054c8127%3Fixid%3DMnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8%26ixlib%3Drb-1.2.1%26auto%3Dformat%26fit%3Dcrop%26w%3D870%26q%3D80" 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%2Fimages.unsplash.com%2Fphoto-1513102419401-0cc6054c8127%3Fixid%3DMnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8%26ixlib%3Drb-1.2.1%26auto%3Dformat%26fit%3Dcrop%26w%3D870%26q%3D80"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dear Reader,&lt;/p&gt;

&lt;p&gt;We might have come across e-commerce websites with countdown timers that give information on some sales or deals. We will create a web page where we will place a countdown timer that informs us about when the discount sale will end. Let’s implement one such scenario here. Countdown begins⏳ !!!&lt;/p&gt;

&lt;p&gt;Folder Structure of the project:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;em&gt;index.html — contains the HTML layout which defines the element structure that would be shown on the page.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt; &lt;em&gt;images are directly placed inside the folder of our project.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt; &lt;em&gt;style.css- contains CSS code for styling. Using CSS we can style the different portions to make them more visually appealing.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt; &lt;em&gt;script.js — contains Javascript code. There are several functions that work together to handle all the functions of the timer.&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h1&gt;
  
  
  HTML Layout
&lt;/h1&gt;

&lt;p&gt;Open VSCode and create the basic HTML structure in an &lt;strong&gt;index.html&lt;/strong&gt; file by ! and then pressing tab. Give the &lt;strong&gt;title&lt;/strong&gt; as ‘Countdown Timer*&lt;em&gt;’&lt;/em&gt;&lt;em&gt;. Link **style.css&lt;/em&gt;* and &lt;strong&gt;script.js&lt;/strong&gt; to the created HTML file.&lt;/p&gt;

&lt;p&gt;Create a div class &lt;strong&gt;product&lt;/strong&gt; that wraps around everything related to the product. I have used shoes as my discounted product for this example. Use &lt;strong&gt;img&lt;/strong&gt; tag to add the image of the shoe.&lt;/p&gt;

&lt;p&gt;Add the following div class,&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;details&lt;/strong&gt; —  to hold information on the deal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;wrap&lt;/strong&gt; — which wraps timer and text.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;timer&lt;/strong&gt; —  to hold the entire countdown timer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;days, hours, mins,&lt;/strong&gt; and &lt;strong&gt;secs&lt;/strong&gt; — to hold the remaining days, hours, mins, and secs.&lt;/p&gt;

&lt;p&gt;Let &lt;strong&gt;days, hours, mins,&lt;/strong&gt; and &lt;strong&gt;secs&lt;/strong&gt; class contain &lt;strong&gt;span&lt;/strong&gt; tag with id &lt;strong&gt;days_left, hours_left, mins_left,&lt;/strong&gt; and &lt;strong&gt;secs_left&lt;/strong&gt; respectively. The dynamic data will go inside the &lt;strong&gt;span&lt;/strong&gt; element and &lt;strong&gt;id&lt;/strong&gt; will be used in javascript code to fetch the element.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
    &amp;lt;title&amp;gt;Countdown Timer&amp;lt;/title&amp;gt;
    &amp;lt;link rel="stylesheet" href="style.css"&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt; Best deals of the day&amp;lt;/h1&amp;gt;
    &amp;lt;div class="product"&amp;gt;
        &amp;lt;img src="shoe.jpg" alt="shoes" width="400px" height="300px"&amp;gt;
        &amp;lt;div class="details"&amp;gt;
            &amp;lt;h3&amp;gt;🔥30% off on all branded shoes🔥&amp;lt;/h3&amp;gt;
            &amp;lt;p&amp;gt; This festive season we have multiple amazing offers on all branded shoes.
                Bank and payment offers, and many more deals.This sale brings hundreds of deals
                across all branded shoes. To help you find the best discounts,
                we've handpicked some of the best deals and offers available on shoes during the ongoing discount Sale. Grab the offer soon!!🤩
            &amp;lt;/p&amp;gt;
            &amp;lt;div class="wrap"&amp;gt;
                &amp;lt;h3 class="offer"&amp;gt;Offer ends in&amp;lt;/h3&amp;gt;
                &amp;lt;div class="timer"&amp;gt;
                    &amp;lt;div class="days"&amp;gt;
                        &amp;lt;span id="days_left"&amp;gt; 0&amp;lt;/span&amp;gt;
                        days
                    &amp;lt;/div&amp;gt;
                    &amp;lt;div class="hours"&amp;gt;
                        &amp;lt;span id="hours_left"&amp;gt; 0 &amp;lt;/span&amp;gt;
                        hours
                    &amp;lt;/div&amp;gt;
                    &amp;lt;div class="mins"&amp;gt;
                        &amp;lt;span id="mins_left"&amp;gt; 0 &amp;lt;/span&amp;gt;
                        mins
                    &amp;lt;/div&amp;gt;
                    &amp;lt;div class="secs"&amp;gt;
                        &amp;lt;span id="secs_left"&amp;gt; 0 &amp;lt;/span&amp;gt;
                        secs
                    &amp;lt;/div&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;script src="style.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;


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

&lt;/div&gt;
&lt;h1&gt;
  
  
  CSS Styling
&lt;/h1&gt;

&lt;p&gt;Quite a bit of CSS coding is required to make the page visually appealing and even without much CSS, we can implement the basic countdown timer.&lt;/p&gt;

&lt;p&gt;Below is the code,&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;


@import url('https://fonts.googleapis.com/css2?family=Oswald&amp;amp;display=swap');

body{
    font-family: 'Oswald', sans-serif;
    align-content: center;
    text-align: center;
    background-color:rgb(244, 248, 250);
}

.product{
display: flex;
background-color: rgb(237, 243, 243);
gap: 7rem;
}

.details{
    display:flex;
    flex-direction: column;
    margin-right: 150px;  
}

.wrap{
    display: flex;
    flex-direction: row;
}
.timer{
    display: flex;
    text-align: center;
    flex-direction: row;
    margin-left: 3rem;
    gap: 30px;
    color:red;
    margin-top: -5px;

}
.days{
    background-color: blanchedalmond;
    padding: 11px;
    font-size: 22px;
}


.hours{
    background-color: blanchedalmond;
    padding: 11px;
    font-size: 22px;
}
.mins{
    background-color: blanchedalmond;
    padding: 11px;
    font-size: 22px;
}

.secs{
    background-color: blanchedalmond;
    padding: 11px;
    font-size: 22px;
}


h3{
    color:lightseagreen;
}

.offer{
    flex-basis: 6rem;
}

p{
    text-align: left;
}




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

&lt;/div&gt;
&lt;h1&gt;
  
  
  Javascript logic
&lt;/h1&gt;

&lt;p&gt;The whole idea is to calculate the time left before the offer ends. To calculate the time left we will take the difference of the current date and offer end date and present it in valid format.&lt;/p&gt;

&lt;p&gt;Let’s create a function called &lt;strong&gt;countdown()&lt;/strong&gt; in which we will declare a const called &lt;strong&gt;today&lt;/strong&gt; and &lt;strong&gt;offerDate&lt;/strong&gt; to add the current date and offer end date objects respectively.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const today = new Date();  
var offerDate = new Date('30 oct 2021');


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

&lt;/div&gt;
&lt;p&gt;Assign the difference between &lt;strong&gt;offerDate&lt;/strong&gt; and &lt;strong&gt;today&lt;/strong&gt; to the const &lt;strong&gt;offerTime&lt;/strong&gt; which will give the time left in milliseconds.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const offerTime = offerDate - today;


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

&lt;/div&gt;
&lt;p&gt;Let’s calculate the number of days, hours, mins, and secs left using the &lt;strong&gt;offerTime&lt;/strong&gt; value.&lt;/p&gt;

&lt;p&gt;To calculate seconds:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Divide milliseconds by 1000 to convert to seconds: &lt;code&gt;(offerTime/1000)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Divide the total seconds by 60 and grab the remainder. You don’t want all of the seconds, just those remaining after the minutes have been counted: &lt;code&gt;(offerTime/1000) % 60&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Round this down to the nearest whole number. This is because you want complete seconds, not fractions of seconds: &lt;code&gt;Math.floor( (offerTime/1000) % 60 )&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To calculate minutes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Divide milliseconds by 1000 to convert to seconds: &lt;code&gt;(offerTime/1000)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Divide the total seconds by 60 to get the minutes( 1 min = 60 secs), again divide by 60 and grab the remainder. Round this down to the nearest whole number. &lt;code&gt;Math.floor((offerTime / (1000 * 60) % 60))&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To calculate hours:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Divide milliseconds by 1000 to convert to seconds: &lt;code&gt;(offerTime/1000)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Divide the total seconds by 60 to get the minutes( 1 min = 60 secs),again divide by 60 (1 hour = 60 minutes), divide the result by 24 (1 day = 24 hours)and grab the remainder. Round this down to the nearest whole number. &lt;code&gt;Math.floor((offerTime / (1000 * 60 * 60) % 24))&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To calculate days:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Divide milliseconds by 1000 to convert to seconds: &lt;code&gt;(offerTime/1000)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Divide the total seconds by 60 to get the minutes( 1 min = 60 secs),again divide by 60 (1 hour = 60 minutes), divide the result by 24 (1 day = 24 hours). Round this down to the nearest whole number. &lt;code&gt;Math.floor((offerTime / (1000 * 60 * 60 * 24))&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once we have all the values we will set days, hours, mins, and secs to HTML span element.HTML element where the value to be set is fetched using &lt;strong&gt;getElementById()&lt;/strong&gt; method and using &lt;strong&gt;innerHTML&lt;/strong&gt; set the calculated values.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const days\_el = document.getElementById("days\_left");  
days\_el.innerHTML = offerDays;const hours\_el = document.getElementById("hours\_left");  
hours\_el.innerHTML = offerHours;const mins\_el = document.getElementById("mins\_left");  
mins\_el.innerHTML = offerMins;const secs\_el=document.getElementById("secs\_left");  
secs\_el.innerHTML = offerSecs;


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

&lt;/div&gt;
&lt;p&gt;I added one more function just to reset the offer date once the offer date reaches the current date. We can ignore this function if not required.&lt;/p&gt;

&lt;p&gt;Using &lt;strong&gt;setInterval()&lt;/strong&gt; method call the &lt;strong&gt;countdown()&lt;/strong&gt; function every second.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;setInterval(countdown, 1000);&lt;/code&gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

function countdown() {
    const today = new Date();
    var offerDate = new Date('30 oct 2021');

    //If offer ends reset to new value
    if (today.getSeconds() == offerDate.getSeconds()) {
        offerDate = resetOfferDate();
    }

    //offerTime will have the total millseconds 
    const offerTime = offerDate - today;

    // 1 sec= 1000 ms
    // 1 min = 60 sec
    // 1 hour = 60 mins
    // 1 day = 24 hours
    const offerDays = Math.floor(offerTime / (1000 * 60 * 60 * 24));
    const offerHours = Math.floor((offerTime / (1000 * 60 * 60) % 24));
    const offerMins = Math.floor((offerTime / (1000 * 60) % 60));
    const offerSecs = Math.floor((offerTime / 1000) % 60);

    const days_el = document.getElementById("days_left");
    days_el.innerHTML = offerDays;
    const hours_el = document.getElementById("hours_left");
    hours_el.innerHTML = offerHours;
    const mins_el = document.getElementById("mins_left");
    mins_el.innerHTML = offerMins;
    const secs_el = document.getElementById("secs_left");
    secs_el.innerHTML = offerSecs;
}

function resetOfferDate() {
    const futureDate = new Date();
    futureDate.setDate(futureDate.getDate() + 15);
    return futureDate;
}

setInterval(countdown, 1000);


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

&lt;/div&gt;
&lt;p&gt;We’ve finished coding! Time to check the output.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/KKheSN7ItIw"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;All of the above-written code is available on &lt;a href="https://github.com/Divyamcm/Projects/tree/main/Countdown%20Timer" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;strong&gt;.&lt;/strong&gt; Watch this space for more interesting articles, up next in this series!&lt;/p&gt;

&lt;p&gt;Thanks for your interest.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>css</category>
      <category>html</category>
      <category>webdev</category>
    </item>
    <item>
      <title>KEY SEQUENCE DETECTION using HTML, CSS, and Javascript</title>
      <dc:creator>Divyamcm</dc:creator>
      <pubDate>Wed, 13 Oct 2021 08:31:45 +0000</pubDate>
      <link>https://dev.to/divyamcm/key-sequence-detection-using-html-css-and-javascript-p66</link>
      <guid>https://dev.to/divyamcm/key-sequence-detection-using-html-css-and-javascript-p66</guid>
      <description>&lt;p&gt;======================================================&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---WN7IGkp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1634113169/JavaScript/MEDIUM%2520BLOG%25205_Key%2520sequence%2520Detection/typing_pwrxzh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---WN7IGkp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1634113169/JavaScript/MEDIUM%2520BLOG%25205_Key%2520sequence%2520Detection/typing_pwrxzh.jpg" alt=""&gt;&lt;/a&gt;Photo by &lt;a href="https://unsplash.com/@christinhumephoto?utm_source=medium&amp;amp;utm_medium=referral"&gt;Christin Hume&lt;/a&gt; on &lt;a href="https://unsplash.com?utm_source=medium&amp;amp;utm_medium=referral"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dear Reader,&lt;/p&gt;

&lt;p&gt;Let’s learn some javascript by doing a simple project.The objective of the project is to detect a given key sequence in the user input and react to that. In the example, we will add some random images on the page on the key sequence typed in by the user. Time to code!!!&lt;/p&gt;

&lt;p&gt;Folder structure:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;em&gt;index.html — contains the HTML layout which defines the element structure that would be shown on the page.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt; &lt;em&gt;style.css- contains CSS code for styling. Using CSS we can style the different portions to make them more visually appealing.&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  HTML Layout
&lt;/h1&gt;

&lt;p&gt;Open VSCode and create the basic HTML structure in an &lt;strong&gt;index.html&lt;/strong&gt; file by ! and then pressing tab. Give the &lt;strong&gt;title&lt;/strong&gt; as ‘Key Sequence Detection’. Link &lt;strong&gt;style.css.&lt;/strong&gt; Add a header &lt;strong&gt;h1&lt;/strong&gt; with the text*&lt;em&gt;.&lt;/em&gt;* Here, I gave informative text as &lt;strong&gt;‘Enter the code’&lt;/strong&gt;. On clicking &lt;strong&gt;h1&lt;/strong&gt; text we can see the secret code or sequence of keys that we are going to detect and once the user enters this secret code we will add some images on the screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6a_DMhkx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1634113168/JavaScript/MEDIUM%2520BLOG%25205_Key%2520sequence%2520Detection/img_1_odfbme.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6a_DMhkx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1634113168/JavaScript/MEDIUM%2520BLOG%25205_Key%2520sequence%2520Detection/img_1_odfbme.png" alt=""&gt;&lt;/a&gt;index.html&lt;/p&gt;

&lt;h1&gt;
  
  
  CSS Styling
&lt;/h1&gt;

&lt;p&gt;For the styling of the whole HTML page, I have used &lt;strong&gt;background-color&lt;/strong&gt;, &lt;strong&gt;background-image.&lt;/strong&gt; For the &lt;strong&gt;body&lt;/strong&gt; I added &lt;strong&gt;text-align&lt;/strong&gt; and &lt;strong&gt;font-family&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I gave a pink shade to the text inside the &lt;strong&gt;h1&lt;/strong&gt; tag and added CSS code so that when we hover on the &lt;strong&gt;h1&lt;/strong&gt; element the arrow mouse cursor will change to the hand pointer &lt;code&gt;cursor: pointer;&lt;/code&gt; and the text color will change.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;h1:hover {&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;color: rgba(205, 211, 150, 0.9);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HFM2NR8k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1634113167/JavaScript/MEDIUM%2520BLOG%25205_Key%2520sequence%2520Detection/img_2_xp27wu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HFM2NR8k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1634113167/JavaScript/MEDIUM%2520BLOG%25205_Key%2520sequence%2520Detection/img_2_xp27wu.png" alt=""&gt;&lt;/a&gt;style.css&lt;/p&gt;

&lt;h1&gt;
  
  
  Javascript logic
&lt;/h1&gt;

&lt;p&gt;Our predefined sequence of characters are ‘css’ so,we will declare a variable called &lt;strong&gt;secretCode&lt;/strong&gt; and let’s assign value ‘css’ to it.  The first event listener which we are going to create is for showing &lt;strong&gt;secretCode&lt;/strong&gt; when we click on the &lt;strong&gt;h1&lt;/strong&gt; element. At first, we will fetch the &lt;strong&gt;h1 text&lt;/strong&gt; which is &lt;strong&gt;‘Enter your code’&lt;/strong&gt; and store it in const variable called &lt;strong&gt;text.&lt;/strong&gt; Create  event listener which listens for click event on the &lt;strong&gt;h1&lt;/strong&gt; element so, when we click on the original &lt;strong&gt;h1 text&lt;/strong&gt; i.e ‘Enter your code’ text it will verify whether it is a &lt;strong&gt;secretCode&lt;/strong&gt; value or original &lt;strong&gt;h1 text&lt;/strong&gt; . If it is original &lt;strong&gt;h1 text&lt;/strong&gt; (&lt;strong&gt;‘Enter your code’&lt;/strong&gt;) then the text will be changed to the value of &lt;strong&gt;secretCode&lt;/strong&gt;(‘&lt;strong&gt;css&lt;/strong&gt;’) and if the value is ‘css’ it will be changed to ‘ Enter your code’.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8h8H1x8U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1634113168/JavaScript/MEDIUM%2520BLOG%25205_Key%2520sequence%2520Detection/img_4_axu3d9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8h8H1x8U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1634113168/JavaScript/MEDIUM%2520BLOG%25205_Key%2520sequence%2520Detection/img_4_axu3d9.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
javascript code&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3qwJDLr5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1634113168/JavaScript/MEDIUM%2520BLOG%25205_Key%2520sequence%2520Detection/img_3_gif_d6rioh.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3qwJDLr5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1634113168/JavaScript/MEDIUM%2520BLOG%25205_Key%2520sequence%2520Detection/img_3_gif_d6rioh.gif" alt=""&gt;&lt;/a&gt;output view&lt;/p&gt;

&lt;p&gt;We will implement the second event listener which will detect the key sequence entered using keyboard and if the sequence matches the predefined sequence ‘css’ then we will add images to the screen.&lt;/p&gt;

&lt;p&gt;Let’s declare an array to push the characters entered by user. &lt;code&gt;const pressed = [];&lt;/code&gt; .Now, we will create an event listener to check for keyup event on window once that happens push the characters to the array but, that could get fairly big*&lt;em&gt;.&lt;/em&gt;* So what we want to do is just trim this array to be the maximum that we would ever need  and in our case, if we’re just looking for the word&lt;br&gt;&lt;br&gt;
“css,” then we are maximum looking for three characters. So, splice the array. Note that we want the last sequence of characters so, let’s start from counting from the end of the array.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pressed.splice(-secretCode.length — 1 , pressed.length — secretCode.length);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Later, convert this sequence of characters to string using join() function and check whether it includes the &lt;strong&gt;secretCode&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pressed.join(‘’).includes(secretCode)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If the string includes &lt;strong&gt;secretCode&lt;/strong&gt; then we will call predefined function &lt;code&gt;cornify_add()&lt;/code&gt; to display some pictures on the screen.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--w_riVBtn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1634113167/JavaScript/MEDIUM%2520BLOG%25205_Key%2520sequence%2520Detection/img_5_p6l3wy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--w_riVBtn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1634113167/JavaScript/MEDIUM%2520BLOG%25205_Key%2520sequence%2520Detection/img_5_p6l3wy.png" alt=""&gt;&lt;/a&gt;javascript code&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iwzC3Guh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1634113168/JavaScript/MEDIUM%2520BLOG%25205_Key%2520sequence%2520Detection/img_6_gif_irmxfq.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iwzC3Guh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1634113168/JavaScript/MEDIUM%2520BLOG%25205_Key%2520sequence%2520Detection/img_6_gif_irmxfq.gif" alt=""&gt;&lt;/a&gt;final output&lt;/p&gt;

&lt;p&gt;Congratulation 🎉! You have just completed a simple javascript project.&lt;/p&gt;

&lt;p&gt;All of the above-written code is available on &lt;a href="https://github.com/Divyamcm/Projects/tree/main/Key%20sequence%20detection"&gt;GitHub&lt;/a&gt;&lt;strong&gt;.&lt;/strong&gt; Watch this space for more interesting articles, up next in this series!&lt;/p&gt;

&lt;p&gt;Confused about something? Let us know in the responses below.&lt;/p&gt;

&lt;p&gt;Refer &lt;a href="https://javascript30.com/"&gt;https://javascript30.com/&lt;/a&gt; for more projects&lt;/p&gt;

&lt;p&gt;Thanks for your interest.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>html</category>
    </item>
    <item>
      <title>Analog Clock using HTML, CSS, and Javascript</title>
      <dc:creator>Divyamcm</dc:creator>
      <pubDate>Sat, 09 Oct 2021 15:14:55 +0000</pubDate>
      <link>https://dev.to/divyamcm/analog-clock-using-html-css-and-javascript-53j</link>
      <guid>https://dev.to/divyamcm/analog-clock-using-html-css-and-javascript-53j</guid>
      <description>&lt;p&gt;============================================&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633791813%2FJavaScript%2FMEDIUM%2520BLOG%25203_analog%2520clock%2Fimg_1_eqzafk.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633791813%2FJavaScript%2FMEDIUM%2520BLOG%25203_analog%2520clock%2Fimg_1_eqzafk.jpg"&gt;&lt;/a&gt;Photo by &lt;a href="https://unsplash.com/@lucian_alexe?utm_source=medium&amp;amp;utm_medium=referral" rel="noopener noreferrer"&gt;Lucian Alexe&lt;/a&gt; on &lt;a href="https://unsplash.com?utm_source=medium&amp;amp;utm_medium=referral" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dear Reader,&lt;/p&gt;

&lt;p&gt;Let’s start learning some cool CSS tricks and a bit of Javascript by building an analog clock using HTML, CSS, and Javascript. Trust me! This will be the best exercise for beginners in CSS and javascript.&lt;/p&gt;

&lt;p&gt;First, let me show you a demo before starting the implementation&lt;/p&gt;

&lt;p&gt;Analog clock demo&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=ZTUNW9nnAaQ" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=ZTUNW9nnAaQ&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Folder Structure of the project&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;em&gt;index.html — contains the HTML layout which defines the element structure that would be shown on the page.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt; &lt;em&gt;images folder — contains .jpg images used in our project.&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  HTML Layout
&lt;/h1&gt;

&lt;p&gt;Open VSCode and create the basic HTML structure in an &lt;strong&gt;index.html&lt;/strong&gt; file by ! and then pressing tab. Give the &lt;strong&gt;title&lt;/strong&gt; as ‘Analog Clock*&lt;em&gt;’&lt;/em&gt;*.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;title&amp;gt;Analog Clock&amp;lt;/title&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Inside the body, add  the &lt;strong&gt;div&lt;/strong&gt; element with the class &lt;strong&gt;clock&lt;/strong&gt; which represents the outline of the clock, and add three &lt;strong&gt;div&lt;/strong&gt; elements that represent the hands of the clock inside the &lt;strong&gt;clock&lt;/strong&gt; class. Oh wow! we are done with HTML.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633791813%2FJavaScript%2FMEDIUM%2520BLOG%25203_analog%2520clock%2Fhtml_vdyem1.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%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633791813%2FJavaScript%2FMEDIUM%2520BLOG%25203_analog%2520clock%2Fhtml_vdyem1.png"&gt;&lt;/a&gt;index.html&lt;/p&gt;

&lt;h1&gt;
  
  
  CSS Styling
&lt;/h1&gt;

&lt;p&gt;CSS is used to style the different portions and make them more visually appealing. First of all, give the background color or background image of the page in the CSS code with size and alignment.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633791813%2FJavaScript%2FMEDIUM%2520BLOG%25203_analog%2520clock%2FCSS_1_av31nt.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%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633791813%2FJavaScript%2FMEDIUM%2520BLOG%25203_analog%2520clock%2FCSS_1_av31nt.png"&gt;&lt;/a&gt;index.html&lt;/p&gt;

&lt;p&gt;The outline of the clock is circular in shape so let’s set &lt;strong&gt;border-radius&lt;/strong&gt; to 50%. You can experiment on border width and border color.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633791814%2FJavaScript%2FMEDIUM%2520BLOG%25203_analog%2520clock%2Fresult_1_uy5yh7.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%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633791814%2FJavaScript%2FMEDIUM%2520BLOG%25203_analog%2520clock%2Fresult_1_uy5yh7.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.clock {&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;width: 30rem;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;height: 30rem;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;border: 20px solid #fec1b8;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;border-radius: 50%;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;margin: 50px auto;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;position: relative;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;padding: 2rem;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;box-shadow:&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;0 0 0 4px rgba(0,0,0,0.1),&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;inset 0 0 0 3px #f8a09b,&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;inset 0 0 10px black,&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;0 0 10px rgba(0,0,0,0.2);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, let’s implement the clock hands CSS part. The idea is that we’re going to apply a rotation to each of the hands depending on what time it currently is. I am setting the width, height  to place hands in proper positions inside the clock.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;transform-origin: 100%&lt;/code&gt; will help to rotate the clock hand on the very right-hand side, by default it’s 50%. 100% along the x-axis will put that pivot point on the very right-hand side so, that the right edge of the clock hand will be fixed to the center of the clock.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;transform: rotate(90deg);&lt;/code&gt;&lt;strong&gt;divs&lt;/strong&gt; are block and they’re left to right, it’s not actually starting at 12:00. So, we could just rotate the entire thing by 90 degrees.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);&lt;/code&gt; It gives you this tick kind of animation. It goes forward and back, forward and back.&lt;/p&gt;

&lt;p&gt;For individual hands add different widths and heights just to differentiate between them. That’s all with the CSS.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633791813%2FJavaScript%2FMEDIUM%2520BLOG%25203_analog%2520clock%2FCSS_2_aurvwm.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%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633791813%2FJavaScript%2FMEDIUM%2520BLOG%25203_analog%2520clock%2FCSS_2_aurvwm.png"&gt;&lt;/a&gt;index.html&lt;/p&gt;

&lt;h1&gt;
  
  
  Javascript logic
&lt;/h1&gt;

&lt;p&gt;The logic of the player is defined inside the &lt;strong&gt;script&lt;/strong&gt; tag.We are going to grab the reference for the following using &lt;code&gt;querySelector().&lt;/code&gt;&lt;br&gt;&lt;br&gt;
.second-hand&lt;br&gt;&lt;br&gt;
.min-hand&lt;br&gt;&lt;br&gt;
.hour-hand&lt;/p&gt;

&lt;p&gt;&lt;code&gt;new Date()&lt;/code&gt; creates an instance of the Date class from which we can get current date, hours, minutes, seconds, etc.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const now = new Date();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I have stored in &lt;code&gt;'secondsDegrees'&lt;/code&gt; how the second hand will rotate.Then I use &lt;code&gt;rotate(${secondsDegrees}deg)&lt;/code&gt; to rotate the hand.I divided by 60 because 1 minute is equal to 60 seconds.I multiplied by 360 because a circle is formed by 360 degrees.&lt;/p&gt;

&lt;p&gt;Similarly, I have stored in &lt;code&gt;'minsDegrees'&lt;/code&gt; how to turn the hand of the minute.Then use&lt;code&gt;rotate(${minsDegrees}deg)&lt;/code&gt; to rotate the hand. I divided by 60 because 1 hour is equal to 60 minutes.Added second hand position with minutes. Because the minute's hand is in the right place depending on the second.&lt;/p&gt;

&lt;p&gt;Implemented similar logic on hour hand as well.&lt;/p&gt;

&lt;p&gt;We need to call this &lt;code&gt;rotate()&lt;/code&gt; function every 1 second (&lt;code&gt;1000 milliseconds&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633791813%2FJavaScript%2FMEDIUM%2520BLOG%25203_analog%2520clock%2FJavascript_bz1ud0.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%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633791813%2FJavaScript%2FMEDIUM%2520BLOG%25203_analog%2520clock%2FJavascript_bz1ud0.png"&gt;&lt;/a&gt;index.html&lt;/p&gt;

&lt;p&gt;That’s all folks !!&lt;/p&gt;

&lt;p&gt;Refer &lt;a href="https://javascript30.com/" rel="noopener noreferrer"&gt;https://javascript30.com/&lt;/a&gt; for many such projects&lt;/p&gt;

&lt;p&gt;Find the complete source code &lt;a href="https://github.com/Divyamcm/Projects/tree/main/Analog%20Clock" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Thanks for your interest.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>html</category>
      <category>css</category>
    </item>
    <item>
      <title>Follow along Navigation using HTML, CSS, and Javascript</title>
      <dc:creator>Divyamcm</dc:creator>
      <pubDate>Sat, 09 Oct 2021 12:44:45 +0000</pubDate>
      <link>https://dev.to/divyamcm/follow-along-navigation-using-html-css-and-javascript-17p0</link>
      <guid>https://dev.to/divyamcm/follow-along-navigation-using-html-css-and-javascript-17p0</guid>
      <description>&lt;p&gt;=======================================================&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IGM6hNFK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1633781515/JavaScript/follow-along%2520navigation/MEDIUN%2520BLOG%25204_Follow%2520along%2520navigation/img_1_offv7w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IGM6hNFK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1633781515/JavaScript/follow-along%2520navigation/MEDIUN%2520BLOG%25204_Follow%2520along%2520navigation/img_1_offv7w.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dear Reader,&lt;/p&gt;

&lt;p&gt;You might have seen some cool websites where just mouse hover on the navigation will show a strip or highlights. Let’s build a simple project to show follow-along navigation. We’ve got these links on the page and when you hover over one of the links, we’ve got this pill-shaped highlight that’s going to both resize itself, as well as follow you around the page wherever that is going. Now, let’s jump into the implementation part.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;em&gt;index.html — contains the HTML layout which defines the element structure that would be shown on the page.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt; &lt;em&gt;images are directly placed inside the folder of our project.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt; &lt;em&gt;style.css- contains CSS code for styling. Using CSS we can style the different portions to make them more visually appealing.&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  HTML Layout
&lt;/h1&gt;

&lt;p&gt;Open VSCode and create the basic HTML structure in an &lt;strong&gt;index.html&lt;/strong&gt; file by ! and then pressing tab. Give the &lt;strong&gt;title&lt;/strong&gt; as ‘&lt;strong&gt;Follow-along Navigation’&lt;/strong&gt;. Link &lt;strong&gt;style.css&lt;/strong&gt; and add few links using anchor tag &amp;lt; a &amp;gt; under &amp;lt; nav &amp;gt; tag.  Use the &amp;lt; footer &amp;gt; tag to display the footer section. That’s a simple HTML.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yt7eH2DK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1633781514/JavaScript/follow-along%2520navigation/MEDIUN%2520BLOG%25204_Follow%2520along%2520navigation/img_2_vzrymk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yt7eH2DK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1633781514/JavaScript/follow-along%2520navigation/MEDIUN%2520BLOG%25204_Follow%2520along%2520navigation/img_2_vzrymk.png" alt=""&gt;&lt;/a&gt;index.html&lt;/p&gt;

&lt;h1&gt;
  
  
  CSS Styling
&lt;/h1&gt;

&lt;p&gt;For the styling of the &lt;strong&gt;body,&lt;/strong&gt; I have used background image, font-family, color and adjusted the image and text alignment.Added some padding to &lt;strong&gt;h1&lt;/strong&gt; and &lt;strong&gt;nav&lt;/strong&gt; elements&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--S1GK7HPm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1633781514/JavaScript/follow-along%2520navigation/MEDIUN%2520BLOG%25204_Follow%2520along%2520navigation/img_3_abns5i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--S1GK7HPm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1633781514/JavaScript/follow-along%2520navigation/MEDIUN%2520BLOG%25204_Follow%2520along%2520navigation/img_3_abns5i.png" alt=""&gt;&lt;/a&gt;style.css&lt;/p&gt;

&lt;p&gt;Add color, padding, font-size to anchor tagelements. To &lt;strong&gt;highlight&lt;/strong&gt; class elements add &lt;strong&gt;background&lt;/strong&gt;,&lt;strong&gt;border-radius&lt;/strong&gt; to have curve edged highlight. Add &lt;strong&gt;transition&lt;/strong&gt; of 0.2 s for smooth transition of highlight from one element to other.The highlight has a &lt;strong&gt;z-index&lt;/strong&gt; of -1, it will be placed behind the link text.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G-S6QutB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1633781514/JavaScript/follow-along%2520navigation/MEDIUN%2520BLOG%25204_Follow%2520along%2520navigation/img_4_fjcmzy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G-S6QutB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1633781514/JavaScript/follow-along%2520navigation/MEDIUN%2520BLOG%25204_Follow%2520along%2520navigation/img_4_fjcmzy.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
style.css&lt;/p&gt;

&lt;p&gt;To display red heart give color to &lt;strong&gt;heart&lt;/strong&gt; class.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.heart{color: #b14240;}&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Javascript logic
&lt;/h1&gt;

&lt;p&gt;We will fetch all the &lt;strong&gt;link&lt;/strong&gt; elements that will be hovered and store it in &lt;strong&gt;triggers&lt;/strong&gt; variable.Let’s add a class of &lt;strong&gt;highlight&lt;/strong&gt; and later put it into the DOM. Using triggers.forEach() take each link and add the event listener for mouse enter and when that happens we are going to run the function &lt;strong&gt;highlightLink()&lt;/strong&gt;.we need to figure out the width, the height, the X-axis and the Y-axis values which means we need to figure out how big is the element that we hovered and where on the page is that actual element.we’re going to use a method called &lt;strong&gt;getBoundingClientRect()&lt;/strong&gt; to get &lt;strong&gt;link&lt;/strong&gt; elements position on the page and for the obtained top and left values we will add &lt;strong&gt;window.scrollY&lt;/strong&gt; and &lt;strong&gt;window.scrollX&lt;/strong&gt; values i.e scrolled down and scrolled right values.&lt;/p&gt;

&lt;p&gt;Set these values to the &lt;strong&gt;highlight&lt;/strong&gt; width and height . The &lt;code&gt;translate()&lt;/code&gt; method moves an element from its current position (according to the parameters given for the X-axis and the Y-axis). Use translate method to set x-axis and y-axis position.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;highlight.style.width = `${coords.width}px`;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;highlight.style.height = `${coords.height}px`;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;highlight.style.transform = `translate(${coords.left}px, ${coords.top}px)`;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XVv5tpDN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1633781514/JavaScript/follow-along%2520navigation/MEDIUN%2520BLOG%25204_Follow%2520along%2520navigation/img_5_jb9avc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XVv5tpDN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1633781514/JavaScript/follow-along%2520navigation/MEDIUN%2520BLOG%25204_Follow%2520along%2520navigation/img_5_jb9avc.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The final result is here&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=mw2Fmn_P_S0"&gt;https://www.youtube.com/watch?v=mw2Fmn_P_S0&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Complete source code is &lt;a href="https://github.com/Divyamcm/Projects/tree/main/Follow%20Along%20Navigation"&gt;here&lt;/a&gt; .&lt;/p&gt;

&lt;p&gt;Referred &lt;a href="https://javascript30.com/"&gt;https://javascript30.com/&lt;/a&gt; and customized it.&lt;/p&gt;

&lt;p&gt;Thanks for your interest.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>html</category>
      <category>css</category>
      <category>programming</category>
    </item>
    <item>
      <title>Build Music Player using HTML, CSS, and Javascript</title>
      <dc:creator>Divyamcm</dc:creator>
      <pubDate>Thu, 07 Oct 2021 08:56:43 +0000</pubDate>
      <link>https://dev.to/divyamcm/build-music-player-using-html-css-and-javascript-58lb</link>
      <guid>https://dev.to/divyamcm/build-music-player-using-html-css-and-javascript-58lb</guid>
      <description>&lt;p&gt;==================================================&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F10922%2F0%2AniDJTZkfKkb1GcYB" 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%2Fmiro.medium.com%2Fmax%2F10922%2F0%2AniDJTZkfKkb1GcYB"&gt;&lt;/a&gt;Photo by &lt;a href="https://unsplash.com/@leecampbell?utm_source=medium&amp;amp;utm_medium=referral" rel="noopener noreferrer"&gt;Lee Campbell&lt;/a&gt; on &lt;a href="https://unsplash.com?utm_source=medium&amp;amp;utm_medium=referral" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dear Reader,&lt;/p&gt;

&lt;p&gt;How about building a Music player on your own from scratch? Exciting right! Let’s start.&lt;/p&gt;

&lt;p&gt;Folder Structure of the project&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;em&gt;index.html - contains the HTML layout which defines the element structure that would be shown on the page.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt; &lt;em&gt;images folder - contains .jpg images used in our project.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt; &lt;em&gt;music folder - contains .mp3 audio files used in our project.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt; &lt;em&gt;style.css- contains CSS code for styling. Using CSS we can style the different portions to make it more visually appealing&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt; &lt;em&gt;script.js - contains Javascript code. There are several functions that work together to handle all the functions of the player. Ex: play, pause, to switch the songs back and forth, popup title of the song with the progress bar when we play the song, able to click on the progress bar to go to that spot in the song etc.&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  HTML Layout
&lt;/h2&gt;

&lt;p&gt;Open VSCode and create the basic HTML structure in an &lt;strong&gt;index.html&lt;/strong&gt; file by ! and then pressing tab. Give the &lt;strong&gt;title&lt;/strong&gt; as ‘&lt;strong&gt;Music Player’&lt;/strong&gt;. Link &lt;strong&gt;style.css&lt;/strong&gt; and &lt;strong&gt;script.js&lt;/strong&gt; to the created HTML file and link FontAwesome css to use play, pause,next and previous icons.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633592631%2FJavaScript%2FMusic%2520Player%2FBLOG_1_img2_b42te2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633592631%2FJavaScript%2FMusic%2520Player%2FBLOG_1_img2_b42te2.jpg"&gt;&lt;/a&gt;&lt;em&gt;Basic index.html&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Inside the body, Create a &lt;strong&gt;audio-container&lt;/strong&gt; class which will wrap around everything.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;div class =“audio-container" id =“audio-container"&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Inside &lt;strong&gt;audio-container&lt;/strong&gt; class, create a &lt;strong&gt;audio-info&lt;/strong&gt; class which holds the title of the song and the progress when we click play.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;div class=”audio-info”&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Add &lt;strong&gt;h4&lt;/strong&gt; tag with &lt;strong&gt;id = ‘title’&lt;/strong&gt; inside &lt;strong&gt;audio-info&lt;/strong&gt; class and this is going to be populated dynamically with javascript with the current playing song.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;h4 id=”title”&amp;gt;&amp;lt;/h4&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Create &lt;strong&gt;progress-container&lt;/strong&gt; class and inside that add &lt;strong&gt;progress&lt;/strong&gt; class which will be filled dynamically&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;div class=”audio-container” id=”audio-container”&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;div class=”audio-info”&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;h4 id=”title”&amp;gt;&amp;lt;/h4&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;div class=”progress-container” id=”progress-container”&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;div class=”progress” id=”progress”&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Underneath &lt;strong&gt;audio-info&lt;/strong&gt; class add &lt;strong&gt;audio&lt;/strong&gt; tag with the source of the song and id .&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;audio src=”music/melody.mp3" id=”audio”&amp;gt;&amp;lt;/audio&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To hold images&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;img src=”images/melody.jpg” alt=”music-cover” id=”cover”&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Create a navigation class and we will have three buttons inside that to play the song, to play previous song and next song&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;div class=”navigation”&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;button id=”prev” class=”action-btn”&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;i class=”fas fa-backward”&amp;gt;&amp;lt;/i&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;/button&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;button id=”play” class=”action-btn action-btn-big”&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;i class=”fas fa-play”&amp;gt;&amp;lt;/i&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;button id=”next” class=”action-btn”&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;i class=”fas fa-forward”&amp;gt;&amp;lt;/i&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;/button&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633592631%2FJavaScript%2FMusic%2520Player%2FBLOG_1_img3_gwordo.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633592631%2FJavaScript%2FMusic%2520Player%2FBLOG_1_img3_gwordo.jpg"&gt;&lt;/a&gt;&lt;em&gt;index.html&lt;/em&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633592632%2FJavaScript%2FMusic%2520Player%2FBLOG_1_img4_bxtcxb.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633592632%2FJavaScript%2FMusic%2520Player%2FBLOG_1_img4_bxtcxb.jpg"&gt;&lt;/a&gt;&lt;em&gt;Music Player view&lt;/em&gt;&lt;/p&gt;

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

&lt;p&gt;Quite a bit of CSS coding is required and I explained the only the important parts here and rest of the CSS code mostly deals with positioning,size and color of the elements.I shared the github link at the end of the post where you can see the complete code.&lt;/p&gt;

&lt;p&gt;For the styling of the &lt;strong&gt;body,&lt;/strong&gt; I have used linear gradient of yellow and orange color shades as background image.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;background-image: linear-gradient(0deg, rgba(251,252,13,1) 23.8%, rgba(255,170,1,0.99) 92%);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Added &lt;strong&gt;background-color&lt;/strong&gt; as black and also added the shadow for the &lt;strong&gt;audio-container&lt;/strong&gt; class which wraps around everything except the h1 tag&lt;/p&gt;

&lt;p&gt;&lt;code&gt;background-color: #000;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;box-shadow: 0 20px 20px 0 rgb(247, 148, 1);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To make the image circular set the &lt;strong&gt;border-radius&lt;/strong&gt; to 50% in the &lt;strong&gt;img-container&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;border-radius: 50%;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Set animation in the &lt;strong&gt;img-container&lt;/strong&gt; to make the circular image rotate when the song is playing&lt;/p&gt;

&lt;p&gt;&lt;code&gt;animation: rotate 3s linear infinite;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Create rotate keyframes starting at 0 degree to 360 degree&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@keyframes rotate {&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;from {&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;transform: rotate(0deg);&lt;/code&gt;}&lt;/p&gt;

&lt;p&gt;&lt;code&gt;to {&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;transform: rotate(360deg);}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If &lt;strong&gt;audio-container&lt;/strong&gt; has a &lt;strong&gt;play&lt;/strong&gt; class on it then the image will rotate&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.audio-container.play .img-container img {&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;animation-play-state: running;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Only when the music is playing the &lt;strong&gt;audio-info&lt;/strong&gt; will popup. Refer the following CSS implementation&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633592632%2FJavaScript%2FMusic%2520Player%2FBLOG_1_img5_lype7e.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633592632%2FJavaScript%2FMusic%2520Player%2FBLOG_1_img5_lype7e.jpg"&gt;&lt;/a&gt;&lt;em&gt;style.css&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Below is the CSS code for progress bar to show the percentage of song completed. I used white color as background and black color to show the progression.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633592632%2FJavaScript%2FMusic%2520Player%2FBLOG_1_img6_rnui49.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633592632%2FJavaScript%2FMusic%2520Player%2FBLOG_1_img6_rnui49.jpg"&gt;&lt;/a&gt;&lt;em&gt;style.css&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Javascript logic
&lt;/h2&gt;

&lt;p&gt;The logic of the player is defined in the script.js file. There are several functions that work together to handle all the functions of the player.&lt;br&gt;&lt;br&gt;
Defining all the variables and accessing the HTML elements.&lt;br&gt;&lt;br&gt;
The required elements in the HTML layout that are to be dynamically changed are first selected using the getElementById() method and then assigned to a variable names so that they could be accessed and modified.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F2732%2F1%2AZIKr0VDr3AHdJfQd61M_eg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmiro.medium.com%2Fmax%2F2732%2F1%2AZIKr0VDr3AHdJfQd61M_eg.jpeg"&gt;&lt;/a&gt;&lt;em&gt;script.js&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Write a function &lt;strong&gt;loadSong(song)&lt;/strong&gt; to dynamically update the audio source and respective image source. Call the function to load the song details into DOM by passing the &lt;strong&gt;songIndex&lt;/strong&gt; value.I considered &lt;strong&gt;songIndex&lt;/strong&gt; value to be 1 which means music player starts from second song in the list (index starts from 0).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633592632%2FJavaScript%2FMusic%2520Player%2FBLOG_1_img8_qwf99y.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633592632%2FJavaScript%2FMusic%2520Player%2FBLOG_1_img8_qwf99y.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s create event listeners which listens to particular event (for ex: click) and perform particular actions&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Event listener on clicking Play button&lt;/strong&gt;: Clicking on play button should start the song and if the song is already playing then it should stop. Implement &lt;strong&gt;playSong()&lt;/strong&gt; function and &lt;strong&gt;pauseSong()&lt;/strong&gt; function which also includes the logic to change the icons from play icon to pause icon and vice versa.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633592632%2FJavaScript%2FMusic%2520Player%2FBLOG_1_img9_ral5w3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633592632%2FJavaScript%2FMusic%2520Player%2FBLOG_1_img9_ral5w3.jpg"&gt;&lt;/a&gt;&lt;em&gt;script.js&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Event listener on clicking Previous and Next button:&lt;/strong&gt; Clicking on previous button will call &lt;strong&gt;prevSong()&lt;/strong&gt; function which should play the previous song in the list so we are decrementing the &lt;strong&gt;songIndex&lt;/strong&gt; value. If the &lt;strong&gt;songIndex&lt;/strong&gt; value is lesser than 0 then we are setting &lt;strong&gt;songIndex&lt;/strong&gt; value such that it should point to the last song in the list so, the songs will be played in loop.Similarly, clicking on next button will call &lt;strong&gt;nextSong()&lt;/strong&gt; function which should play the next song in the list so we are incrementing the &lt;strong&gt;songIndex&lt;/strong&gt; value. If the &lt;strong&gt;songIndex&lt;/strong&gt; value is greater than or equal to the number of songs in the list then we are setting &lt;strong&gt;songIndex&lt;/strong&gt; value to 0.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633592631%2FJavaScript%2FMusic%2520Player%2FBLOG_1_img10_gv9vcj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633592631%2FJavaScript%2FMusic%2520Player%2FBLOG_1_img10_gv9vcj.jpg"&gt;&lt;/a&gt;&lt;em&gt;script.js&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Event listener to update song progress:&lt;/strong&gt; On HTML audio tag there is an event called &lt;strong&gt;timeupdate.&lt;/strong&gt; Everytime when the song is playing constantly this will be called and on this event we will call &lt;strong&gt;updateProgress()&lt;/strong&gt; function. In the &lt;strong&gt;updateProgress()&lt;/strong&gt; function we will get the &lt;strong&gt;duration&lt;/strong&gt; of the song from the event and the &lt;strong&gt;currentTime&lt;/strong&gt;. Calculate &lt;strong&gt;progressPercent&lt;/strong&gt; by using formula &lt;strong&gt;(currentTime/ duration)*100&lt;/strong&gt; and set that &lt;strong&gt;progressPercent&lt;/strong&gt; value to &lt;strong&gt;width&lt;/strong&gt; of the progress bar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633592631%2FJavaScript%2FMusic%2520Player%2FBLOG_1_img11_luyuva.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633592631%2FJavaScript%2FMusic%2520Player%2FBLOG_1_img11_luyuva.jpg"&gt;&lt;/a&gt;&lt;em&gt;script.js&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Event listener on clicking progress bar&lt;/strong&gt;: To go to that spot in the song when we click anywhere on the &lt;strong&gt;progress-container&lt;/strong&gt; then we will call &lt;strong&gt;setProgress()&lt;/strong&gt; function. This function will change the song progression based on user’s click on progress bar by getting the X-axis offset value to know where the user clicked and calculate the &lt;strong&gt;currentTime&lt;/strong&gt; by using formula &lt;strong&gt;(clickX / width) * duration.&lt;/strong&gt; In this way we can move anywhere in the song.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633592631%2FJavaScript%2FMusic%2520Player%2FBLOG_1_img12_cwndnv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fthewebdev%2Fimage%2Fupload%2Fv1633592631%2FJavaScript%2FMusic%2520Player%2FBLOG_1_img12_cwndnv.jpg"&gt;&lt;/a&gt;&lt;em&gt;style.css&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Event listener to check end of the song:&lt;/strong&gt; The HTML audio API gives us an event called &lt;strong&gt;ended&lt;/strong&gt;. When song ends we will call the &lt;strong&gt;nextSong()&lt;/strong&gt; function which was created before.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;audio.addEventListener(‘ended’, nextSong);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;VOILA !!!!! Music player is ready for the demo&lt;/p&gt;

&lt;p&gt;Final Demo &lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=Xyss5NABwOc" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=Xyss5NABwOc&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Complete source code can be found in the Git hub repo, link is &lt;a href="https://github.com/Divyamcm/Projects/tree/main/Music-Player" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Refer &lt;a href="https://javascript30.com/" rel="noopener noreferrer"&gt;https://javascript30.com/&lt;/a&gt; for many such projects&lt;/p&gt;

&lt;p&gt;Thanks for your interest.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Divya M C M&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>css</category>
      <category>html</category>
      <category>programming</category>
    </item>
    <item>
      <title>Drum Kit using HTML, CSS, and Javascript</title>
      <dc:creator>Divyamcm</dc:creator>
      <pubDate>Thu, 07 Oct 2021 08:53:01 +0000</pubDate>
      <link>https://dev.to/divyamcm/drum-kit-using-html-css-and-javascript-9ha</link>
      <guid>https://dev.to/divyamcm/drum-kit-using-html-css-and-javascript-9ha</guid>
      <description>&lt;p&gt;========================================&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1eO-HgkZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1633595460/JavaScript/MEDIUM%2520BLOG%25202_Drumkit/background_image_bq4d1e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1eO-HgkZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1633595460/JavaScript/MEDIUM%2520BLOG%25202_Drumkit/background_image_bq4d1e.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dear Reader,&lt;/p&gt;

&lt;p&gt;How about building drum kit on your own virtually with the help of some scripting language?Sounds cool right! Let’s start building a simple drum kit using HTML, CSS, and Javascript that runs in a browser which will play the sound when the user press on particular key on the keyboard.&lt;/p&gt;

&lt;p&gt;Folder Structure of the project&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;em&gt;index.html — contains the HTML layout which defines the element structure that would be shown on the page.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt; &lt;em&gt;images folder — contains .jpg images used in our project.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt; &lt;em&gt;sounds folder — contains . wav files used in our project.&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt; &lt;em&gt;style.css — contains CSS code for styling. Using CSS we can style the different portions to make it more visually appealing.&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  HTML Layout
&lt;/h1&gt;

&lt;p&gt;Open VSCode and create the basic HTML structure in an &lt;strong&gt;index.html&lt;/strong&gt; file by ! and then pressing tab. Give the &lt;strong&gt;title&lt;/strong&gt; as ‘Drum Kit*&lt;em&gt;’&lt;/em&gt;&lt;em&gt;. Link **style.css&lt;/em&gt;* to the created HTML file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;title&amp;gt;Drum Kit&amp;lt;/title&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;link rel=”stylesheet” href=”style.css”&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Inside the body, Create a div element with the class of &lt;strong&gt;keys&lt;/strong&gt; which will wrap all the drum kit keys used in our application.Inside the div class we have another set of div’s with a class of &lt;strong&gt;key.&lt;/strong&gt; Now each one of these keys here has a sound associated with it. For every key on the keyboard when we do key up or key down action, there is going to be something called the &lt;strong&gt;key code&lt;/strong&gt; that is associated with that key. For ex: key code of &lt;em&gt;‘A’&lt;/em&gt; is 65.&lt;/p&gt;

&lt;p&gt;In our project, we are using &lt;strong&gt;&lt;em&gt;‘A’, ‘S’, ‘D’, ‘F’, ‘G’ ‘H’, ‘J’, ‘K’, ‘L’&lt;/em&gt;&lt;/strong&gt; keys  to play the sounds of the drum kit. When we press any of the above keys on the keyboard then we’re going to play the corresponding audio element.For example when we press key &lt;strong&gt;&lt;em&gt;‘A’ (_Keycode ‘65’&lt;/em&gt;)_&lt;/strong&gt;  on keyboard we’re going to check if that was the &lt;strong&gt;&lt;em&gt;‘A’&lt;/em&gt;&lt;/strong&gt; Key then we’re going to play the corresponding audio that also has the same &lt;strong&gt;data-key&lt;/strong&gt; and we’re going to find the key &lt;strong&gt;div&lt;/strong&gt; element,add a class of &lt;strong&gt;playing&lt;/strong&gt; so it will animate itself on in.&lt;/p&gt;

&lt;p&gt;Now, &lt;strong&gt;what is this data-key?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;data-*&lt;/code&gt; attribute is used to store custom data private to the page or application.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;data-*&lt;/code&gt; attribute gives us the ability to embed custom data attributes on all HTML elements.&lt;/p&gt;

&lt;p&gt;The stored (custom) data can then be used in the page’s JavaScript to create a more engaging user experience&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;data-*&lt;/code&gt; attribute consist of two parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; The attribute name should not contain any uppercase letters, and must be at least one character long after the prefix “data-”. In our case it is &lt;strong&gt;data-key.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt; The attribute value can be any string. In our case value is a number which represents keycode.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is the HTML code,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;div class=”keys”&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;div data-key=”65" class=”key”&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;kbd&amp;gt;A&amp;lt;/kbd&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;span class=”sound”&amp;gt;clap&amp;lt;/span&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;audio data-key=”83" src=”sounds/hihat.wav”&amp;gt;&amp;lt;/audio&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--548p0nMk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1633595459/JavaScript/MEDIUM%2520BLOG%25202_Drumkit/HTML_code_y0u80e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--548p0nMk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1633595459/JavaScript/MEDIUM%2520BLOG%25202_Drumkit/HTML_code_y0u80e.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;index.html&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  CSS Styling
&lt;/h1&gt;

&lt;p&gt;CSS is used to style the different portions and make it more visually appealing.Experiment on color, background, font-family, margin and font size you want to give to the body,heading and the keys.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ReAixCM0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1633595459/JavaScript/MEDIUM%2520BLOG%25202_Drumkit/CSS_1_phawta.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ReAixCM0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1633595459/JavaScript/MEDIUM%2520BLOG%25202_Drumkit/CSS_1_phawta.png" alt=""&gt;&lt;/a&gt;style.css&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When we press any of these keys &lt;strong&gt;&lt;em&gt;‘A’, ‘S’, ‘D’, ‘F’, ‘G’ ‘H’, ‘J’, ‘K’, ‘L’&lt;/em&gt;&lt;/strong&gt; on keyboard then let’s do some animation on key &lt;strong&gt;div&lt;/strong&gt; element . On key press from the keyboard the corresponding key &lt;strong&gt;div&lt;/strong&gt; element on the UI should scale a bit and the border should be changed to yellow with shadow which means we have to change the existing property value.This transition should happen on key down(key press)and we will use &lt;strong&gt;CSS transitions&lt;/strong&gt; which allows you to change property values smoothly, over a given duration.&lt;/p&gt;

&lt;p&gt;we will define the property values that has to be changed in &lt;strong&gt;playing&lt;/strong&gt; class which will get added to the key &lt;strong&gt;div&lt;/strong&gt; element on key down action using Javascript function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vLZ7ZpSd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1633595459/JavaScript/MEDIUM%2520BLOG%25202_Drumkit/CSS_2_p5qdni.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vLZ7ZpSd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1633595459/JavaScript/MEDIUM%2520BLOG%25202_Drumkit/CSS_2_p5qdni.png" alt=""&gt;&lt;/a&gt;&lt;em&gt;style.css&lt;/em&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Javascript logic
&lt;/h1&gt;

&lt;p&gt;The logic of the player is defined inside the &lt;strong&gt;script&lt;/strong&gt; tag.Our first goal is to listen to the key down event and call &lt;strong&gt;playSound&lt;/strong&gt; function. We are passing the event object to the function where event object holds all kinds of info like what key was actually hit which also contains the &lt;strong&gt;keycode&lt;/strong&gt;.Take an example, we press &lt;strong&gt;keycode 65&lt;/strong&gt; (‘A’) on the keyboard. Next, we are finding out is there an &lt;strong&gt;audio&lt;/strong&gt; element on the page that has a &lt;strong&gt;data-key&lt;/strong&gt; of 65 for that we are going to use &lt;strong&gt;document.querySelector()&lt;/strong&gt; to select an audio element where it has a &lt;strong&gt;data — key&lt;/strong&gt; same as &lt;strong&gt;e.keycode.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;window.addEventListener(‘keydown’, playSound);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;function playSound(e) {&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const audio = document.querySelector(`audio[data-key=”${e.keyCode}”]`);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In a similar way, find out is there an &lt;strong&gt;div&lt;/strong&gt; element on the page that has a &lt;strong&gt;data&lt;/strong&gt;-&lt;strong&gt;key&lt;/strong&gt; of 65 for that we are going to use &lt;strong&gt;document.querySelector()&lt;/strong&gt; to select an &lt;strong&gt;div&lt;/strong&gt; element where it has a &lt;strong&gt;data — key&lt;/strong&gt; same as &lt;strong&gt;e.keycode&lt;/strong&gt;. The returned element is assigned to a constant variable called &lt;strong&gt;key&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const key = document.querySelector(`div[data-key=”${e.keyCode}”]`);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If &lt;strong&gt;audio&lt;/strong&gt; element is not present i.e If the pressed key on the keyboard don’t have an audio element associated with it then &lt;strong&gt;return&lt;/strong&gt; in other words statement stops the execution of a function.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;if (!audio) return;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We are going to add the &lt;strong&gt;playing&lt;/strong&gt; class on the &lt;strong&gt;div&lt;/strong&gt; element which is assigned to constant variable &lt;strong&gt;key .&lt;/strong&gt; This &lt;strong&gt;playing&lt;/strong&gt; class will add animation to the &lt;strong&gt;div&lt;/strong&gt; element of the corresponding key pressed as mentioned in CSS section before.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;key.classList.add(‘playing’);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Next we are going to the play the audio. Before playing the audio we will&lt;br&gt;&lt;br&gt;
rewind it to the start of the element so that if you hit key in succession over and over again it will just rewind it to the start. So let’s say,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;audio.currentTime = 0;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;audio.play();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;we are done with &lt;strong&gt;playSound&lt;/strong&gt; function*&lt;em&gt;.&lt;/em&gt;* As we already discussed,we are adding the animation once the listed key is pressed but we also want to remove the animation in sometime. The requirement is to add the animation only during the key press. we can use a &lt;strong&gt;transitionend&lt;/strong&gt; event that will fire when the element has stopped animating itself on in*&lt;em&gt;.&lt;/em&gt;*&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const keys = Array.from(document.querySelectorAll(‘.key’));&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;keys.forEach(key =&amp;gt; key.addEventListener(‘transitionend’, removeTransition));&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now, what is the transitionend event?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As we already discussed,when the listed key is pressed the &lt;strong&gt;div&lt;/strong&gt; element CSS will be transitioned to scale a bit and the border will be changed to yellow with shadow.The &lt;code&gt;**transitionend**&lt;/code&gt; event is fired when a CSS transition has completed. Once the &lt;strong&gt;transitionend&lt;/strong&gt; event occurs we will call &lt;strong&gt;removeTransition&lt;/strong&gt; function by passing event object. The event object contains a propertyName called ‘&lt;strong&gt;transform&lt;/strong&gt;’ which indicates the transform has finished. If the transition is completed then we will remove the animation by removing the class &lt;strong&gt;playing.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;function removeTransition(e) {&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;if (e.propertyName !== ‘transform’) return;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;e.target.classList.remove(‘playing’);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;*&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wIEsCX8A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1633595459/JavaScript/MEDIUM%2520BLOG%25202_Drumkit/javascript_evpd7c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wIEsCX8A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://res.cloudinary.com/thewebdev/image/upload/v1633595459/JavaScript/MEDIUM%2520BLOG%25202_Drumkit/javascript_evpd7c.png" alt=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are done!! Time to run the code and check the results.&lt;br&gt;
 &lt;a href="https://www.youtube.com/watch?v=fqnWbdOG2-U"&gt;https://www.youtube.com/watch?v=fqnWbdOG2-U&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Find the complete source code &lt;a href="https://github.com/Divyamcm/Projects/tree/main/Drumkit"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Refer &lt;a href="https://javascript30.com/"&gt;https://javascript30.com/&lt;/a&gt; for many such projects&lt;/p&gt;

&lt;p&gt;Thanks for your interest.&lt;/p&gt;

&lt;p&gt;-Divya M C M&lt;/p&gt;

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