<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Dinithi Nethmini on Medium]]></title>
        <description><![CDATA[Stories by Dinithi Nethmini on Medium]]></description>
        <link>https://medium.com/@dinithinethmini01?source=rss-315d9003adbc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3co3p_-y43QXWuTOQkJcZA.png</url>
            <title>Stories by Dinithi Nethmini on Medium</title>
            <link>https://medium.com/@dinithinethmini01?source=rss-315d9003adbc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 12:48:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dinithinethmini01/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Make a QR Code Reader in HTML, CSS & JavaScript]]></title>
            <link>https://medium.com/@dinithinethmini01/how-to-make-a-qr-code-reader-in-html-css-javascript-e50201c041c4?source=rss-315d9003adbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/e50201c041c4</guid>
            <dc:creator><![CDATA[Dinithi Nethmini]]></dc:creator>
            <pubDate>Tue, 09 Apr 2024 08:52:57 GMT</pubDate>
            <atom:updated>2024-04-09T08:52:57.722Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PK8M_0O8NdADcqi9Ed-NCQ.png" /></figure><p>In this article, we will make a QR code reader in HTML, CSS &amp; JavaScript. We will make the QR code using QR API which we will use in JavaScript. In this, we will provide an area to add an image of Qr code, and as soon we upload image then it automatically tries to read the Qr code. And also, If we try to upload anything except Qr code, then it won’t read it. This is going to be a beginner-friendly project and basic project. So let’s make it step-by-step.</p><h3>Creating HTML File</h3><p>For this project, we need to basically three files. First will be our index.html, in this we will add our elements, and you can simply say we will create the skeleton of the project using HTML file. Then for designing purpose we will be adding our style.css file, with this we will add some styles to our HTML, this is going to be purely based on you, like you can customize it any way. And lastly, our script.js file, this will be our main file because we will add functionality so that we can generate our qr code using the JavaScript file.</p><p>Now in HTML, We have used font awesome to get the icon of upload file. Then in the body, we have added a wrapper &lt;div&gt;, in which we have added an input field with file type. Also, we have added a &lt;div&gt; to add some details, Then we have added a textarea in which we will print the information of the QR code. Lastly we have to add two buttons, one for copy and other for close. So this is it for our HTML.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;<br>    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css&quot;&gt;<br>    &lt;title&gt;QR Code Srceen&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br> &lt;div class=&quot;wrapper&quot;&gt;<br>    &lt;form action=&quot;#&quot;&gt;<br>        &lt;input type=&quot;file&quot; hidden&gt;<br>        &lt;img src=&quot;Dinithi Nethmini (1).svg&quot; alt=&quot;qr-code&quot;&gt;<br>        &lt;div class=&quot;content&quot;&gt;<br>            &lt;i class=&quot;fas fa-cloud-upload&quot;&gt;&lt;/i&gt;<br>           &lt;p&gt;Upload QR Code to Read&lt;/p&gt;<br>        &lt;/div&gt;<br>      &lt;/form&gt;<br>      &lt;div class=&quot;details&quot;&gt;<br>        &lt;textarea spellcheck=&quot;false&quot; disabled&gt;&lt;/textarea&gt;<br>        &lt;div class=&quot;buttons&quot;&gt;<br>          &lt;button class=&quot;close&quot;&gt;Close&lt;/button&gt;<br>          &lt;button class=&quot;copy&quot;&gt;Copy Text&lt;/button&gt;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>&lt;script src=&quot;main.js&quot;&gt;&lt;/script&gt; <br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>o after adding the basic elements which is actually perfect, but we need to add some CSS styling so that our project looks a little bit good. For that we just added some background color, added a font family, and did some customizations to our elements as well as we centered our project, added some border, color, transitions etc. to make the project interactive. CSS styling is purely depending on the developer to give more interactive look, so we won’t discuss much about it.</p><p>All source code will be provided below, so you can simply copy and paste it.</p><p>In CSS, you might see some changes like buttons, image etc. gets hide, this is because we need to create our project little bit dynamic. So as we upload the image, then these missing elements will be shown up. This thing we will control in our JS part.</p><pre>@import url(https://medium.com/&#39;https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&amp;display=swap&#39;);<br>*{<br>  margin: 0;<br>  padding: 0;<br>  box-sizing: border-box;<br>  font-family:&#39;Poppins&#39; sans-serif; <br>}<br><br>body{<br>    display: flex;<br>    align-items: center;<br>    justify-content: center;<br>    min-height: 100vh;<br>    padding:0 10px;<br>    background: #E3F2FD;<br>}<br><br>.wrapper{<br>    height: 270px;<br>    width: 420px;<br>    border-radius:7px;<br>    background: #0B85FF;<br>    padding: 30px 30px 35 px;<br>    transition: height 0.2s ease;<br>    box-shadow: 0 10px 20px rgba(0,0, 0,0.1);<br>}<br>.wrapper.active{<br>    height: 525px;<br>  }<br>  .wrapper form{<br>    height: 210px;<br>    display: flex;<br>    cursor: pointer;<br>    user-select: none;<br>    text-align: center;<br>    border-radius: 7px;<br>    background: #fff;<br>    align-items: center;<br>    justify-content: center;<br>    transition: height 0.2s ease;<br>  }<br>  .wrapper.active form{<br>    height: 225px;<br>    pointer-events: none;<br>  }<br>  form img{<br>    display: none;<br>    max-width: 148px;<br>  }<br>  .wrapper.active form img{<br>    display: block;<br>  }<br>  .wrapper.active form .content{<br>    display: none;<br>  }<br>  form .content i{<br>    color: #0B85FF;<br>    font-size: 55px;<br>  }<br>  form .content p{<br>    color: #0B85FF;<br>    margin-top: 15px;<br>    font-size: 16px;<br>  }<br>  .wrapper .details{<br>    opacity: 0;<br>    margin-top: 25px;<br>    pointer-events: none;<br>  }<br>  .wrapper.active .details{<br>    opacity: 1;<br>    pointer-events: auto;<br>    transition: opacity 0.5s 0.05s ease;<br>  }<br>  .details textarea{<br>    width: 100%;<br>    height: 128px;<br>    outline: none;<br>    resize: none;<br>    color: #fff;<br>    font-size: 18px;<br>    background: none;<br>    border-radius: 5px;<br>    padding: 10px 15px;<br>    border: 1px solid #fff;<br>  }<br>  textarea::-webkit-scrollbar{<br>    width: 0px;<br>  }<br>  textarea:hover::-webkit-scrollbar{<br>    width: 5px;<br>  }<br>  textarea:hover::-webkit-scrollbar-track{<br>    background: none;<br>  }<br>  textarea:hover::-webkit-scrollbar-thumb{<br>    background: #fff;<br>    border-radius: 8px;<br>  }<br>  .details .buttons{<br>    display: flex;<br>    margin-top: 20px;<br>    align-items: center;<br>    justify-content: space-between;<br>  }<br>  .buttons button{<br>    height: 55px;<br>    outline: none;<br>    border: none;<br>    font-weight: 500;<br>    font-size: 16px;<br>    cursor: pointer;<br>    color: #0B85FF;<br>    border-radius: 5px;<br>    background: #fff;<br>    transition: transform 0.3s ease;<br>    width: calc(100% / 2 - 10px);<br>  }<br>  .buttons button:active{<br>    transform: scale(0.95);<br>  }<br>  @media (max-width: 450px) {<br>    .wrapper{<br>      padding: 25px;<br>      height: 260px;<br>    }<br>    .wrapper.active{<br>      height: 520px;<br>    }<br>  }</pre><h3>Adding JS Constant</h3><p>Now our project is looking beautiful, Now we need to add functionalities in this. So as we know JavaScript is powerful, so we will take help from JS. In JS file, we have added some constants in order to fetch required elements. We have used the document.querySelector() method to fetch the classes of elements to access those elements. We have fetched here input field, and button.</p><h3>The File From System</h3><p>Now we need to fetch our file from system like QR code image for that we have added an event listener on form to listen click event, in this we just call click() method so that we can access our system’s files.</p><p>Now we will add another event listener on input field, in which we have a variable which have our file or image. Then we have created an object of FormData(), which allows us to access the methods of FormData(). Here we have added our file to formData. Then we have called a function named fetchRequest() in which we will add logic to identify and fetch the data from qr code.</p><h3>QR Code Reading Function</h3><p>In this fetchRequest() function, we will add main logic to scan qr code. For that we have fetched our qrserver API, we have used post method to send formData as body. By this we want a response in JSON form using this line of code then(res =&gt; res.json()).then(result =&gt; { result = result[0].symbol[0].data;, this we will return data about the file. The result will be empty if we don’t add qr code, then we will replace the inner text with couldn’t scan qr code.</p><p>Then after we will target our textarea in which we will write our result value, and we will put image of QR code using this line of code form.querySelector(&quot;img&quot;).src = URL.createObjectURL(file);. Lastly we just added our active class in which have to show our buttons, images etc.</p><p>Now for copy button, we have added an event listener to listen click, in this we have assigned a variable to store text from textarea using document.querySelector(&quot;textarea&quot;).textContent. Then we need to copy the text as we click the button and this can be performed using the following line of code: <strong>document.querySelector(&quot;textarea&quot;).textContent</strong></p><pre>const wrapper = document.querySelector(&quot;.wrapper&quot;),<br>form = document.querySelector(&quot;form&quot;),<br>fileInp = form.querySelector(&quot;input&quot;),<br>infoText = form.querySelector(&quot;p&quot;),<br>closeBtn = document.querySelector(&quot;.close&quot;),<br>copyBtn = document.querySelector(&quot;.copy&quot;);<br><br>function fetchRequest(file, formData) {<br>    infoText.innerText = &quot;Scanning QR Code...&quot;;<br>    fetch(&quot;http://api.qrserver.com/v1/read-qr-code/&quot;, {<br>        method: &#39;POST&#39;, body: formData<br>    }).then(res =&gt; res.json()).then(result =&gt; {<br>        result = result[0].symbol[0].data;<br>        infoText.innerText = result ? &quot;Upload QR Code to Scan&quot; : &quot;Couldn&#39;t scan QR Code&quot;;<br>        if(!result) return;<br>        document.querySelector(&quot;textarea&quot;).innerText = result;<br>        form.querySelector(&quot;img&quot;).src = URL.createObjectURL(file);<br>        wrapper.classList.add(&quot;active&quot;);<br>    }).catch(() =&gt; {<br>        infoText.innerText = &quot;Couldn&#39;t scan QR Code&quot;;<br>    });<br>}<br><br>fileInp.addEventListener(&quot;change&quot;, async e =&gt; {<br>    let file = e.target.files[0];<br>    if(!file) return;<br>    let formData = new FormData();<br>    formData.append(&#39;file&#39;, file);<br>    fetchRequest(file, formData);<br>});<br><br>copyBtn.addEventListener(&quot;click&quot;, () =&gt; {<br>    let text = document.querySelector(&quot;textarea&quot;).textContent;<br>    navigator.clipboard.writeText(text);<br>});<br><br>form.addEventListener(&quot;click&quot;, () =&gt; fileInp.click());<br>closeBtn.addEventListener(&quot;click&quot;, () =&gt; wrapper.classList.remove(&quot;active&quot;));</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/1*Xdku3Ckykw_X9DJu5q-0gQ.png" /><figcaption>Out Put</figcaption></figure><p>By following these steps, you can easily build a How to Make a QR Code Reader in HTML, CSS &amp; JavaScript Happy Codeing !!!!!!!!</p><p>Follow Me ; <a href="https://www.linkedin.com/in/dinithi-nethmini-aaa4a224b/">https://www.linkedin.com/in/dinithi-nethmini-aaa4a224b/</a></p><p><a href="https://github.com/SavvyChic42/QR-Code-Scanner-or-Reader-in-HTML-CSS-JavaScript/tree/main">https://github.com/SavvyChic42/QR-Code-Scanner-or-Reader-in-HTML-CSS-JavaScript/tree/main</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e50201c041c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build-An-AI-Image-Generator-Website-in-HTML-CSS-and-JavaScript]]></title>
            <link>https://medium.com/@dinithinethmini01/build-an-ai-image-generator-website-in-html-css-and-javascript-6f4634d4bbd6?source=rss-315d9003adbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f4634d4bbd6</guid>
            <dc:creator><![CDATA[Dinithi Nethmini]]></dc:creator>
            <pubDate>Sun, 07 Apr 2024 03:00:19 GMT</pubDate>
            <atom:updated>2024-04-07T03:00:52.313Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c4NEUOc0E87m4Ohe_PvRaA.png" /></figure><p>Websites like Midjourney and DALL-E have gained significant popularity in recent months or years for their ability to generate creative and imaginative images using AI. If you’re a beginner web developer, have you ever considered creating your own version of an AI image generator website? The great news is that with the help of only HTML,CSS and JavaScript you too can build a website .</p><p>If you’re unfamiliar, Midjourny and DALL-E are AI image-generation websites. They use a machine-learning model to create images based on text descriptions. Users can input their desired image prompt, and these will generate a corresponding image that matches the description.</p><p>In this blog post, I will provide a step-by-step guide on how to build your own website for generating AI images using HTML, CSS, and JavaScript. The website will be built entirely from scratch using pure JavaScript. So, as a beginner, you can gain practical experience by applying your newly learned HTML, CSS, and JavaScript skills to real-world web Projects.</p><p>On this custom AI image generation website, users enter their prompt, choose the number of images they want to generate, and click the “Generate” button. The AI will then create images based on the user prompt. To download each image, the user can click on the corresponding download button provided.</p><p>If you enjoy learning through video tutorials, the above YouTube video can be an excellent resource. In the video, I’ve explained each line of code and included informative comments to make building your own AI image generator website simple and easy to follow.</p><p>However, if you like reading blog posts or want a step-by-step guide for this project, you can continue reading this post.</p><h3><strong>Steps to Build AI Image Generator Website HTML &amp; JavaScript</strong></h3><p>To build an AI image generator website using HTML, CSS, and vanilla JavaScript, follow these simple step-by-step instructions:</p><ul><li>First, create a folder with any name you like. Then, make the necessary files inside it.</li><li>Create a file called index.html to serve as the main file.</li><li>Create a file called style.css for the CSS code.</li><li>Create a file called main.js for the JavaScript code.</li><li>Finally, download the Images folder and put it in your project directory. This folder contains default showcase images for the website. You can also use your own images.</li></ul><p>To start, add the following HTML codes to your index.html file. These codes include essential HTML markup with different semantic tags, such as div, form, input, button, image, etc., to build the website layout.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;!-- Coding By CodingNepal - www.codingnepalweb.com --&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>  &lt;meta charset=&quot;UTF-8&quot;&gt;<br>  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>  &lt;title&gt;AI Image Generator HTML CSS and JavaScript &lt;/title&gt;<br>  &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;<br>  &lt;script src=&quot;main.js&quot; defer&gt;&lt;/script&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;section class=&quot;image-generator&quot;&gt;<br>    &lt;div class=&quot;content&quot;&gt;<br>      &lt;h1&gt;AI Image Generator Tool &lt;/h1&gt;<br>      &lt;p&gt;JS can help both with building web applications and with a range of AI functionalities, including machine learning, natural language processing, and computer vision directly in the browser. &lt;/p&gt;<br>      &lt;form action=&quot;#&quot; class=&quot;generate-form&quot;&gt;<br>        &lt;input class=&quot;prompt-input&quot; type=&quot;text&quot; placeholder=&quot;Describe what you want to see&quot; required&gt;<br>        &lt;div class=&quot;controls&quot;&gt;<br>          &lt;select class=&quot;img-quantity&quot;&gt;<br>            &lt;option value=&quot;1&quot;&gt;1 Image&lt;/option&gt;<br>            &lt;option value=&quot;2&quot;&gt;2 Images&lt;/option&gt;<br>            &lt;option value=&quot;3&quot;&gt;3 Images&lt;/option&gt;<br>            &lt;option value=&quot;4&quot; selected&gt;4 Images&lt;/option&gt;<br>          &lt;/select&gt;<br>          &lt;button type=&quot;submit&quot; class=&quot;generate-btn&quot;&gt;Generate&lt;/button&gt;<br>        &lt;/div&gt;<br>      &lt;/form&gt;<br>    &lt;/div&gt;<br>  &lt;/section&gt;<br>  &lt;section class=&quot;image-gallery&quot;&gt;<br>    &lt;div class=&quot;img-card&quot;&gt;&lt;img src=&quot;images/img-1.jpg&quot; alt=&quot;image&quot;&gt;&lt;/div&gt;<br>    &lt;div class=&quot;img-card&quot;&gt;&lt;img src=&quot;images/img-2.png&quot; alt=&quot;image&quot;&gt;&lt;/div&gt;<br>    &lt;div class=&quot;img-card&quot;&gt;&lt;img src=&quot;images/img-3.jpg&quot; alt=&quot;image&quot;&gt;&lt;/div&gt;<br>    &lt;div class=&quot;img-card&quot;&gt;&lt;img src=&quot;images/img-4.png&quot; alt=&quot;image&quot;&gt;&lt;/div&gt;<br>  &lt;/section&gt;<br><br>  <br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Next, add the following CSS codes to your style.css file to make your AI image generator website beautiful and user-friendly. You can customize the different CSS properties, such as color, background, font, etc., to give a personalized touch to your website. Now, if you load the web page in your browser, you can see your AI image generator website with four preloaded images.</p><pre>/* Importing Google font - Poppins */<br>@import url(https://medium.com/&quot;https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&amp;display=swap&quot;);<br><br>* {<br>  margin: 0;<br>  padding: 0;<br>  box-sizing: border-box;<br>  font-family: &quot;Poppins&quot;, sans-serif;<br>}<br><br>.image-generator {<br>  height: 40vh;<br>  display: flex;<br>  align-items: center;<br>  justify-content: center;<br>  position: relative;<br>  background: url(https://medium.com/&quot;images/bg.jpg&quot;);<br>  background-size: cover;<br>  background-position: center;<br>}<br><br>.image-generator::before {<br>  content: &quot;&quot;;<br>  position: absolute;<br>  left: 0;<br>  top: 0;<br>  width: 100%;<br>  height: 100%;<br>  opacity: 0.5;<br>  background: #121212;<br>}<br><br>.image-generator .content {<br>  position: relative;<br>  color: #fff;<br>  padding: 0 15px;<br>  max-width: 760px;<br>  text-align: center;<br>}<br><br>.image-generator h1 {<br>  font-size: 2.5rem;<br>  font-weight: 700;<br>}<br><br>.image-generator p {<br>  margin-top: 10px;<br>  font-size: 1.35rem;<br>}<br><br>.image-generator .generate-form {<br>  height: 56px;<br>  padding: 6px;<br>  display: flex;<br>  margin-bottom: 15px;<br>  background: #fff;<br>  align-items: center;<br>  border-radius: 30px;<br>  margin-top: 45px;<br>  justify-content: space-between;<br>}<br><br>.generate-form .prompt-input {<br>  width: 100%;<br>  height: 100%;<br>  outline: none;<br>  padding: 0 17px;<br>  border: none;<br>  background: none;<br>  font-size: 1rem;<br>  border-radius: 30px;<br>}<br><br>.generate-form .controls {<br>  display: flex;<br>  height: 100%;<br>  gap: 15px;<br>}<br><br>.generate-form .img-quantity {<br>  outline: none;<br>  border: none;<br>  height: 44px;<br>  background: none;<br>  font-size: 1rem;<br>}<br><br>.generate-form .generate-btn {<br>  font-size: 1rem;<br>  outline: none;<br>  border: none;<br>  font-weight: 500;<br>  color: #fff;<br>  cursor: pointer;<br>  height: 100%;<br>  padding: 0 25px;<br>  border-radius: 30px;<br>  background: #4949E7;<br>}<br><br>.generate-form .generate-btn[disabled] {<br>  opacity: 0.6;<br>  pointer-events: none;<br>}<br><br>.generate-form button:hover {<br>  background: #1d1de2;<br>}<br><br>.image-gallery {<br>  display: flex;<br>  gap: 15px;<br>  padding: 0 15px;<br>  flex-wrap: wrap;<br>  justify-content: center;<br>  margin: 50px auto;<br>  max-width: 1250px;<br>}<br><br>.image-gallery .img-card {<br>  display: flex;<br>  position: relative;<br>  align-items: center;<br>  justify-content: center;<br>  background: #f2f2f2;<br>  border-radius: 4px;<br>  overflow: hidden;<br>  aspect-ratio: 1 / 1;<br>  width: 285px;<br>}<br><br>.image-gallery .img-card img {<br>  height: 100%;<br>  width: 100%;<br>  object-fit: cover;<br>}<br><br>.image-gallery .img-card.loading img {<br>  width: 80px;<br>  height: 80px;<br>}<br><br>.image-gallery .img-card .download-btn {<br>  bottom: 15px;<br>  right: 15px;<br>  height: 36px;<br>  width: 36px;<br>  display: flex;<br>  align-items: center;<br>  justify-content: center;<br>  text-decoration: none;<br>  background: #fff;<br>  border-radius: 50%;<br>  position: absolute;<br>  opacity: 0;<br>  pointer-events: none;<br>  transition: 0.2s ease;<br>}<br><br>.image-gallery .img-card .download-btn img {<br>  width: 14px;<br>  height: 14px;<br>}<br><br>.image-gallery .img-card:not(.loading):hover .download-btn {<br>  opacity: 1;<br>  pointer-events: auto;<br>}<br><br>@media screen and (max-width: 760px) {<br>  .image-generator {<br>    height: 45vh;<br>    padding-top: 30px;<br>    align-items: flex-start;<br>  }<br><br>  .image-generator h1 {<br>    font-size: 1.8rem;<br>  }<br><br>  .image-generator p {<br>    font-size: 1rem;<br>  }<br><br>  .image-generator .generate-form {<br>    margin-top: 30px;<br>    height: 52px;<br>    display: block;<br>  }<br><br>  .generate-form .controls {<br>    height: 40px;<br>    margin-top: 15px;<br>    justify-content: end;<br>    align-items: center;<br>  }<br><br>  .generate-form .generate-btn[disabled] {<br>    opacity: 1;<br>  }<br><br>  .generate-form .img-quantity {<br>    color: #fff;<br>  }<br><br>  .generate-form .img-quantity option {<br>    color: #000;<br>  }<br><br>  .image-gallery {<br>    margin-top: 20px;<br>  }<br><br>  .image-gallery .img-card:not(.loading) .download-btn {<br>    opacity: 1;<br>    pointer-events: auto;<br>  }<br>}<br><br>@media screen and (max-width: 500px) {<br>  .image-gallery .img-card {<br>    width: 100%;<br>  }<br>}</pre><p>Finally, add the following JavaScript code to your main.js file to make your AI image generator website functional. This code handles various functions, even listeners, input handling, API calls, image rendering, etc. to generate AI images based on user prompts.</p><pre>const generateForm = document.querySelector(&quot;.generate-form&quot;);<br>const generateBtn = generateForm.querySelector(&quot;.generate-btn&quot;);<br>const imageGallery = document.querySelector(&quot;.image-gallery&quot;);<br><br>const OPENAI_API_KEY = &quot;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&quot;; // Your OpenAI API key here<br>let isImageGenerating = false;<br><br>const updateImageCard = (imgDataArray) =&gt; {<br>  imgDataArray.forEach((imgObject, index) =&gt; {<br>    const imgCard = imageGallery.querySelectorAll(&quot;.img-card&quot;)[index];<br>    const imgElement = imgCard.querySelector(&quot;img&quot;);<br>    const downloadBtn = imgCard.querySelector(&quot;.download-btn&quot;);<br>    <br>    // Set the image source to the AI-generated image data<br>    const aiGeneratedImage = `data:image/jpeg;base64,${imgObject.b64_json}`;<br>    imgElement.src = aiGeneratedImage;<br>    <br>    // When the image is loaded, remove the loading class and set download attributes<br>    imgElement.onload = () =&gt; {<br>      imgCard.classList.remove(&quot;loading&quot;);<br>      downloadBtn.setAttribute(&quot;href&quot;, aiGeneratedImage);<br>      downloadBtn.setAttribute(&quot;download&quot;, `${new Date().getTime()}.jpg`);<br>    }<br>  });<br>}<br><br>const generateAiImages = async (userPrompt, userImgQuantity) =&gt; {<br>  try {<br>    // Send a request to the OpenAI API to generate images based on user inputs<br>    const response = await fetch(&quot;https://api.openai.com/v1/images/generations&quot;, {<br>      method: &quot;POST&quot;,<br>      headers: {<br>        &quot;Content-Type&quot;: &quot;application/json&quot;,<br>        &quot;Authorization&quot;: `Bearer ${OPENAI_API_KEY}`,<br>      },<br>      body: JSON.stringify({<br>         prompt: userPrompt,<br>        n: userImgQuantity,<br>        size: &quot;512x512&quot;,<br>        response_format: &quot;b64_json&quot;<br>      }),<br>    });<br><br>    // Throw an error message if the API response is unsuccessful<br>    if(!response.ok) throw new Error(&quot;Failed to generate AI images. Make sure your API key is valid.&quot;);<br><br>    const { data } = await response.json(); // Get data from the response<br>    updateImageCard([...data]);<br>  } catch (error) {<br>    alert(error.message);<br>  } finally {<br>    generateBtn.removeAttribute(&quot;disabled&quot;);<br>    generateBtn.innerText = &quot;Generate&quot;;<br>    isImageGenerating = false;<br>  }<br>}<br><br>const handleImageGeneration = (e) =&gt; {<br>  e.preventDefault();<br>  if(isImageGenerating) return;<br><br>  // Get user input and image quantity values<br>  const userPrompt = e.srcElement[0].value;<br>  const userImgQuantity = parseInt(e.srcElement[1].value);<br>  <br>  // Disable the generate button, update its text, and set the flag<br>  generateBtn.setAttribute(&quot;disabled&quot;, true);<br>  generateBtn.innerText = &quot;Generating&quot;;<br>  isImageGenerating = true;<br>  <br>  // Creating HTML markup for image cards with loading state<br>  const imgCardMarkup = Array.from({ length: userImgQuantity }, () =&gt; <br>      `&lt;div class=&quot;img-card loading&quot;&gt;<br>        &lt;img src=&quot;images/loader.svg&quot; alt=&quot;AI generated image&quot;&gt;<br>        &lt;a class=&quot;download-btn&quot; href=&quot;#&quot;&gt;<br>          &lt;img src=&quot;images/download.svg&quot; alt=&quot;download icon&quot;&gt;<br>        &lt;/a&gt;<br>      &lt;/div&gt;`<br>  ).join(&quot;&quot;);<br><br>  imageGallery.innerHTML = imgCardMarkup;<br>  generateAiImages(userPrompt, userImgQuantity);<br>}<br><br>generateForm.addEventListener(&quot;submit&quot;, handleImageGeneration);</pre><p>Please note that your website is still unable to generate AI images because you have not provided your API key in the OPENAI_API_KEY variable. We’re using OpenAI API to generate images. So to get a free API key from OpenAI, sign up for an account at</p><p><a href="https://platform.openai.com/api-keys">https://platform.openai.com/api-keys</a></p><p>In conclusion, developing an AI-powered image generation website is an engaging and rewarding project that allows you to apply your web development skills to a domain that is gaining significant importance in today’s digital landscape. By following the steps outlined in this article, you have successfully created a unique AI image generator, which can be further customized with various styles and features to enhance its capabilities.</p><p>To continue expanding your expertise, consider undertaking projects such as building a ChatGPT clone, a chatbot, or an image search engine. These projects will not only challenge you but also enable you to explore different aspects of AI and web development.</p><p>If you encounter any difficulties during the process of building your AI-powered image generation website, you can download the source code files provided for this project free of charge. Just click the Download button, and remember to input your valid OpenAI API key into the OPENAI_API_KEY variable in the <a href="https://raw.githubusercontent.com/SavvyChic42/Build-An-AI-Image-Generator-Website-in-HTML-CSS-and-JavaScript/main/main.js">main.js </a>file.</p><p>Congratulations on completing this project, and I wish you all the best in your future AI and web development endeavors!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f4634d4bbd6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Isometric Landing Page UI Design Using HTML and CSS]]></title>
            <link>https://medium.com/@dinithinethmini01/isometric-landing-page-ui-design-using-html-and-css-6aed6c3547fb?source=rss-315d9003adbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/6aed6c3547fb</guid>
            <dc:creator><![CDATA[Dinithi Nethmini]]></dc:creator>
            <pubDate>Thu, 04 Apr 2024 19:09:53 GMT</pubDate>
            <atom:updated>2024-04-04T19:09:53.550Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SO5vVcjnacSBvoeF1F2Vmg.png" /></figure><p>A landing page is a web page that is designed to convert visitors into customers or leads. It is often the first page that a visitor sees when they come to your website, so it is important to make a good first impression.</p><p>In this blog post, I will show you how to build a responsive landing page with HTML and CSS. A responsive landing page will look good on any device, from desktop computers to smartphones.</p><p><strong>Step 1: Create the Basic Structure</strong></p><p>The first step is to create the basic structure of your landing page. This includes creating the HTML elements for the header, navigation bar, main content area, and footer.</p><p>Here is an example of the basic HTML structure for a landing page:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;title&gt;Isometric Landing Page UI Design&lt;/title&gt;<br>    &lt;!-- fontswesome cdn link --&gt;<br>    &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css&quot;&gt;<br>    &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>   &lt;!-- header section starts --&gt;<br><br>   &lt;header class=&quot;header&quot;&gt;<br><br>    &lt;a href=&quot;#&quot; class=&quot;logo&quot;&gt;&lt;i class=&quot;fas fa-store&quot;&gt;&lt;/i&gt; shop&lt;/a&gt;<br><br>    &lt;nav&gt;<br>        &lt;ul&gt;<br>            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;home&lt;/a&gt;&lt;/li&gt;<br>            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;products&lt;/a&gt;&lt;/li&gt;<br>            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;featured&lt;/a&gt;&lt;/li&gt;<br>            &lt;li&gt;&lt;a href=&quot;#&quot;&gt;review&lt;/a&gt;&lt;/li&gt;<br>        &lt;/ul&gt;<br>    &lt;/nav&gt;<br><br>    &lt;div class=&quot;icons&quot;&gt;<br>        &lt;div class=&quot;fas fa-search&quot;&gt;&lt;/div&gt;<br>        &lt;div class=&quot;fas fa-shopping-cart&quot;&gt;&lt;/div&gt;<br>    &lt;/div&gt;<br><br>&lt;/header&gt;<br><br>&lt;!-- header section ends --&gt;<br><br>&lt;!-- container --&gt;<br><br>&lt;div class=&quot;container&quot;&gt;<br><br>    &lt;div class=&quot;content&quot;&gt;<br>        &lt;h1&gt;running application&lt;/h1&gt;<br>        &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.&lt;/p&gt;<br>        &lt;div class=&quot;button&quot;&gt;<br>            &lt;a href=&quot;#&quot;&gt;&lt;button class=&quot;btn1&quot;&gt;get started&lt;/button&gt;&lt;/a&gt;<br>            &lt;a href=&quot;#&quot;&gt;&lt;button class=&quot;btn2&quot;&gt;read more&lt;/button&gt;&lt;/a&gt;<br>        &lt;/div&gt;<br>    &lt;/div&gt;<br><br>    &lt;div class=&quot;image&quot;&gt;<br>        &lt;img src=&quot;home.png&quot; alt=&quot;&quot;&gt;<br>    &lt;/div&gt;<br><br>&lt;/div&gt;<br><br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Step 2: Add CSS</strong><br>Now that you have the basic structure of your landing page in place, you can start adding CSS to style it.<br><strong>Here are some basic CSS rules that you can use to style your landing page:</strong></p><pre>*{<br>    font-family: Arial, Helvetica, sans-serif;<br>    margin: 0; padding: 0;<br>    box-sizing: border-box;<br>    text-decoration: none;<br>    text-transform: uppercase;<br>    transition: .2s linear;<br>  }<br>  <br>  html{<br>    font-size: 62.5%;<br>  }<br>  <br>  body{<br>    background: linear-gradient(45deg, #28204e 37.47%, #3a0ca3 93.82%);<br>    overflow: hidden;<br>  }<br>  <br>  .header{<br>    position: fixed;<br>    top: 0; left: 0; right: 0;<br>    display: flex;<br>    align-items: center;<br>    justify-content: space-between;<br>    padding: 2rem 7rem;<br>  }<br>  <br>  .header .logo{<br>    font-size: 2.5rem;<br>    color: #fff;<br>    font-weight: bolder;<br>  }<br>  <br>  .header .logo i{<br>    color: #13bcf1;<br>  }<br>  <br>  .header nav ul{<br>    list-style: none;<br>    display: flex;<br>    align-items: center;<br>    justify-content: space-around;<br>  }<br>  <br>  .header nav ul li{<br>    margin: 0 1rem;<br>  }<br>  <br>  .header nav ul li a{<br>    font-size: 1.7rem;<br>    color: #fff;<br>    padding: .5rem 2rem;<br>  }<br>  <br>  .header nav ul li a:hover{<br>    color: #13bcf1;<br>  }<br>  <br>  .header .icons div{<br>    font-size: 2.5rem;<br>    margin-left: 2rem;<br>    color: #3a0ca3;<br>    cursor: pointer;<br>    -webkit-text-stroke: .1rem #fff;<br>  }<br>  <br>  .header .icons div:hover{<br>    -webkit-text-stroke: .1rem #13bcf1;<br>  }<br>  <br>  /* end */<br>  <br>  .container{<br>    min-height: 100vh;<br>    width: 100vw;<br>    display: flex;<br>    align-items: center;<br>    justify-content: space-around;<br>  }<br>  <br>  .content{<br>    color: #fff;<br>    width: 40vw;<br>    padding-top: 10rem;<br>    font-style: italic;<br>    animation: content .5s linear;<br>  }<br>  <br>  .content h1{<br>    font-size: 5.5rem;<br>  }<br>  <br>  .content p{<br>    font-size: 1.5rem;<br>    margin: 2rem 0;<br>    line-height: 2;<br>  }<br>  <br>  .content .button button{<br>    width: 15rem;<br>    height: 4rem;<br>    color: #13bcf1;<br>    font-weight: bold;<br>    border-radius: 5rem;<br>    cursor: pointer;<br>    outline: none;<br>    border: none;<br>  }<br>  <br>  .content .button .btn1:hover{<br>    background: none;<br>    border: .2rem solid #13bcf1;<br>  }<br>  <br>  .content .button .btn2{<br>    background: none;<br>    border: .2rem solid #13bcf1;<br>  }<br>  <br>  .content .button .btn2:hover{<br>    background: #fff;<br>    border: none;<br>  }<br>  <br>  .content .button a:nth-child(2){<br>    margin-left: 2rem;<br>  }<br>  <br>  .image img{<br>    margin-top: 8rem;<br>    width: 36vw;<br>    animation: image .5s linear;<br>  }<br>  <br>  <br>  @keyframes image{<br>    0%{<br>      transform: translateY(-10rem);<br>    }<br>  }<br>  <br>  @keyframes content{<br>    0%{<br>      transform: translateX(-10rem);<br>    }<br>  }</pre><p><strong>Step 3: Make the Landing Page Responsive</strong><br>Finally, you need to make your landing page responsive so that it looks good on all devices.<br>To do this, you can use CSS media queries. CSS media queries allow you to specify different CSS rules for different screen sizes.<br><strong>Here is an example of how you can use CSS media queries to make your landing page responsive:</strong></p><pre>*{<br>    font-family: Arial, Helvetica, sans-serif;<br>    margin: 0; padding: 0;<br>    box-sizing: border-box;<br>    text-decoration: none;<br>    text-transform: uppercase;<br>    transition: .2s linear;<br>  }<br>  <br>  html{<br>    font-size: 62.5%;</pre><p>By following these steps, you can easily build a responsive landing page with HTML and CSS. Happy Codeing</p><p>Follow me :<a href="https://github.com/SavvyChic42">https://github.com/SavvyChic42</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SO5vVcjnacSBvoeF1F2Vmg.png" /><figcaption>Out Put</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6aed6c3547fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How-To-Build-a-Sidebar Component-in-React]]></title>
            <link>https://medium.com/@dinithinethmini01/how-to-build-a-sidebar-component-in-react-abcf471f449e?source=rss-315d9003adbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/abcf471f449e</guid>
            <dc:creator><![CDATA[Dinithi Nethmini]]></dc:creator>
            <pubDate>Thu, 04 Apr 2024 08:25:14 GMT</pubDate>
            <atom:updated>2024-04-04T08:25:14.615Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*tQjeyczE7GiRDJ44U-PL5A.png" /><figcaption>Using For Canva</figcaption></figure><p>Do you need a sidebar navigation menu for your next React.js project? Here I came up with a tutorial on how to create a sidebar menu in React js. Yesterday I was working for one of my clients and his design requires me to create a sidebar navigation menu that can also collapse. So let us see how I created that menu.</p><ol><li>Create a React Project</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*yAS7Tra9nADrZm-JtEYyQQ.png" /></figure><p>2. Follow the below diagram to create our folders and file structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WcD6ll1NNSr3IXv2DF66mQ.png" /></figure><p>3. Now open the terminal and install the required modules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*7Hj9Cd-R-L0SskhuEJK9dg.png" /></figure><p>4. Now open the Navbar<strong>.js</strong> file and paste the below code.</p><pre>import React, { useState } from &quot;react&quot;;<br>import * as FaIcons from &quot;react-icons/fa&quot;;<br>import * as AiIcons from &quot;react-icons/ai&quot;;<br>import { Link } from &quot;react-router-dom&quot;;<br>import { SidebarData } from &quot;./SidebarData&quot;;<br>import &quot;../App.css&quot;;<br>import { IconContext } from &quot;react-icons&quot;;<br><br>function Navbar() {<br>  const [sidebar, setSidebar] = useState(false);<br><br>  const showSidebar = () =&gt; setSidebar(!sidebar);<br><br>  return (<br>    &lt;&gt;<br>      &lt;IconContext.Provider value={{ color: &quot;undefined&quot; }}&gt;<br>        &lt;div className=&quot;navbar&quot;&gt;<br>          &lt;Link to=&quot;#&quot; className=&quot;menu-bars&quot;&gt;<br>            &lt;FaIcons.FaBars onClick={showSidebar} /&gt;<br>          &lt;/Link&gt;<br>        &lt;/div&gt;<br>        &lt;nav className={sidebar ? &quot;nav-menu active&quot; : &quot;nav-menu&quot;}&gt;<br>          &lt;ul className=&quot;nav-menu-items&quot; onClick={showSidebar}&gt;<br>            &lt;li className=&quot;navbar-toggle&quot;&gt;<br>              &lt;Link to=&quot;#&quot; className=&quot;menu-bars&quot;&gt;<br>                &lt;AiIcons.AiOutlineClose /&gt;<br>              &lt;/Link&gt;<br>            &lt;/li&gt;<br>            {SidebarData.map((item, index) =&gt; {<br>              return (<br>                &lt;li key={index} className={item.cName}&gt;<br>                  &lt;Link to={item.path}&gt;<br>                    {item.icon}<br>                    &lt;span&gt;{item.title}&lt;/span&gt;<br>                  &lt;/Link&gt;<br>                &lt;/li&gt;<br>              );<br>            })}<br>          &lt;/ul&gt;<br>        &lt;/nav&gt;<br>      &lt;/IconContext.Provider&gt;<br>    &lt;/&gt;<br>  );<br>}<br><br>export default Navbar;</pre><p>5. Now open the SidebarData<strong>.js</strong> file and paste the below code.</p><pre>import React from &quot;react&quot;;<br>import * as FaIcons from &quot;react-icons/fa&quot;;<br>import * as AiIcons from &quot;react-icons/ai&quot;;<br>import * as IoIcons from &quot;react-icons/io&quot;;<br><br>export const SidebarData = [<br>  {<br>    title: &quot;Home&quot;,<br>    path: &quot;/&quot;,<br>    icon: &lt;AiIcons.AiFillHome /&gt;,<br>    cName: &quot;nav-text&quot;,<br>  },<br>  {<br>    title: &quot;Reports&quot;,<br>    path: &quot;/reports&quot;,<br>    icon: &lt;IoIcons.IoIosPaper /&gt;,<br>    cName: &quot;nav-text&quot;,<br>  },<br>  {<br>    title: &quot;Products&quot;,<br>    path: &quot;/products&quot;,<br>    icon: &lt;FaIcons.FaCartPlus /&gt;,<br>    cName: &quot;nav-text&quot;,<br>  },<br>  {<br>    title: &quot;Team&quot;,<br>    path: &quot;/team&quot;,<br>    icon: &lt;IoIcons.IoMdPeople /&gt;,<br>    cName: &quot;nav-text&quot;,<br>  },<br>  {<br>    title: &quot;Messages&quot;,<br>    path: &quot;/messages&quot;,<br>    icon: &lt;FaIcons.FaEnvelopeOpenText /&gt;,<br>    cName: &quot;nav-text&quot;,<br>  },<br>  {<br>    title: &quot;Support&quot;,<br>    path: &quot;/support&quot;,<br>    icon: &lt;IoIcons.IoMdHelpCircle /&gt;,<br>    cName: &quot;nav-text&quot;,<br>  },<br>];</pre><p>5. Now open the Home<strong>.js</strong> file and paste the below code.</p><pre>import React from &quot;react&quot;;<br><br>function Home() {<br>  return (<br>    &lt;div className=&quot;home&quot;&gt;<br>      &lt;h1&gt;Home&lt;/h1&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default Home;</pre><p>6. Now open the Products<strong>.js</strong> file and paste the below code.</p><pre>import React from &quot;react&quot;;<br><br>function Home() {<br>  return (<br>    &lt;div className=&quot;home&quot;&gt;<br>      &lt;h1&gt;Home&lt;/h1&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default Home;</pre><p>6. Now open the Reports<strong>.js</strong> file and paste the below code.</p><pre>import React from &quot;react&quot;;<br><br>function Products() {<br>  return (<br>    &lt;div className=&quot;products&quot;&gt;<br>      &lt;h1&gt;Products&lt;/h1&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default Products;</pre><p>7. Now it’s time to add some styling to our menu. Paste the below code in the App<strong>.css </strong>file.</p><pre>@import url(https://medium.com/&quot;https://fonts.googleapis.com/css2?family=Lato&amp;display=swap&quot;);<br><br>* {<br>  box-sizing: border-box;<br>  margin: 0;<br>  padding: 0;<br>  font-family: &quot;Lato&quot;, sans-serif;<br>}<br><br>.home,<br>.reports,<br>.products {<br>  display: flex;<br>  height: 90vh;<br>  align-items: center;<br>  justify-content: center;<br>  font-size: 3rem;<br>  background-color: #000;<br>  color: #fff;<br>}<br><br>/* Navbar CSS */<br>.navbar {<br>  background-color: #ffffff;<br>  height: 80px;<br>  display: flex;<br>  justify-content: flex-start;<br>  align-items: center;<br>}<br><br>.menu-bars {<br>  margin-left: 2rem;<br>  font-size: 2rem;<br>  background: none;<br>  color: #000;<br>}<br><br>.nav-menu {<br>  background-color: #ffffff;<br>  width: 250px;<br>  height: 100vh;<br>  display: flex;<br>  justify-content: center;<br>  position: fixed;<br>  top: 0;<br>  left: -100%;<br>  transition: 850ms;<br>}<br><br>.nav-menu.active {<br>  left: 0;<br>  transition: 450ms;<br>}<br><br>.nav-text {<br>  display: flex;<br>  justify-content: flex-start;<br>  align-items: center;<br>  padding: 8px 0px 8px 16px;<br>  list-style: none;<br>  height: 60px;<br>}<br><br>.nav-text a {<br>  text-decoration: none;<br>  color: #151414;<br>  font-size: 18px;<br>  width: 95%;<br>  height: 100%;<br>  display: flex;<br>  align-items: center;<br>  padding: 0 16px;<br>  border-radius: 4px;<br>}<br><br>.nav-text a:hover {<br>  background-color: #000000;<br>  color: #fff;<br>}<br><br>.nav-menu-items {<br>  width: 100%;<br>}<br><br>.navbar-toggle {<br>  background-color: #ffffff;<br>  width: 80%;<br>  height: 80px;<br>  display: flex;<br>  justify-content: flex-start;<br>  align-items: center;<br>}<br><br>span {<br>  margin-left: 16px;<br>}</pre><p>8. Now import the component to your<strong> index.js</strong> file.</p><pre>import React from &quot;react&quot;;<br>import { createRoot } from &quot;react-dom/client&quot;;<br>import {<br>  createBrowserRouter,<br>  RouterProvider,<br>  Route,<br>  Link,<br>  Outlet,<br>  createRoutesFromElements,<br>} from &quot;react-router-dom&quot;;<br>import Products from &quot;./routes/Products&quot;;<br>import Home from &quot;./routes/Home&quot;;<br>import Reports from &quot;./routes/Reports&quot;;<br>import Navbar from &quot;./components/Navbar&quot;;<br>import &quot;./App.css&quot;;<br><br>const AppLayout = () =&gt; (<br>  &lt;&gt;<br>    &lt;Navbar /&gt;<br>    &lt;Outlet /&gt;<br>  &lt;/&gt;<br>);<br><br>// const router = createBrowserRouter(<br>//   createRoutesFromElements(<br>//     &lt;Route element={&lt;AppLayout /&gt;}&gt;<br>//       &lt;Route path=&quot;/&quot; element={&lt;Home /&gt;} /&gt;<br>//       &lt;Route path=&quot;/products&quot; element={&lt;Products /&gt;} /&gt;<br>//       &lt;Route path=&quot;/reports&quot; element={&lt;Reports /&gt;} /&gt;<br>//     &lt;/Route&gt;<br>//   )<br>// );<br><br>const router = createBrowserRouter([<br>  {<br>    element: &lt;AppLayout /&gt;,<br>    children: [<br>      {<br>        path: &quot;/&quot;,<br>        element: &lt;Home /&gt;,<br>      },<br>      {<br>        path: &quot;products&quot;,<br>        element: &lt;Products /&gt;,<br>      },<br>      {<br>        path: &quot;reports&quot;,<br>        element: &lt;Reports /&gt;,<br>      },<br>    ],<br>  },<br>]);<br><br>createRoot(document.getElementById(&quot;root&quot;)).render(<br>  &lt;RouterProvider router={router} /&gt;<br>);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GM7wa5QgERecPdZd" /><figcaption>out put</figcaption></figure><p>Follow me:<a href="https://github.com/SavvyChic42/How-To-Build-a-Sidebar-Component-in-React/tree/main?tab=readme-ov-file">https://github.com/SavvyChic42/How-To-Build-a-Sidebar-Component-in-React/tree/main?tab=readme-ov-file</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abcf471f449e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a Quiz Application with HTML, CSS, and JavaScript]]></title>
            <link>https://medium.com/@dinithinethmini01/build-a-quiz-application-with-html-css-and-javascript-3cac01e848e7?source=rss-315d9003adbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/3cac01e848e7</guid>
            <dc:creator><![CDATA[Dinithi Nethmini]]></dc:creator>
            <pubDate>Tue, 02 Apr 2024 10:54:49 GMT</pubDate>
            <atom:updated>2024-04-02T10:54:49.692Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*7hhHKMYobSTxHpwtnwZLYQ.png" /><figcaption>Using For Canva</figcaption></figure><p>Quiz applications are a fantastic way to engage and entertain users on websites. Whether you want to test knowledge, provide educational content, or simply offer a fun activity, building a quiz application using HTML, CSS, and JavaScript is an excellent choice. In this step-by-step guide, we will walk you through the process of creating a quiz application from scratch.</p><p>By the end of this tutorial, you will have a fully functional quiz application that you can customize to fit your specific needs. We will start by setting up the HTML structure, where we’ll define the layout and elements required for the quiz. Then, we’ll move on to designing the user interface using CSS, making the application visually appealing and engaging.</p><p>Next, we’ll dive into the JavaScript implementation, where we’ll handle the logic behind displaying questions, capturing user responses, and calculating the score. JavaScript will be the backbone of our quiz application, allowing us to dynamically generate content, validate user inputs, and provide interactive feedback.</p><p>Throughout this tutorial, we’ll provide code snippets, examples, and clear explanations to help you understand each step of the process. Even if you’re a beginner to web development, don’t worry! We’ve designed this guide with simplicity in mind, making it accessible for anyone looking to improve their front-end development skills.</p><p><strong>Step 1 (HTML Code):</strong></p><p>To get started, we will first need to create a basic HTML file. In this file, we will include the main structure for our quiz application.</p><p>After creating the files just paste the following codes into your file. Make sure to save your HTML document with a .html extension, so that it can be properly viewed in a web browser.</p><p>Here is an explanation of each element:</p><p><strong>&lt;!DOCTYPE html&gt;</strong>: This is a declaration that specifies the HTML version being used, in this case, HTML5.</p><p><strong>&lt;html&gt;</strong>: The root element of an HTML document. It encapsulates all other elements on the page.</p><p><strong>&lt;head&gt;</strong>: This element contains metadata and other information about the web page that is not directly displayed on the page itself.</p><p><strong>&lt;title&gt;</strong>: This element sets the title of the web page, which appears in the browser’s title bar or tab.</p><p><strong>&lt;link rel=”stylesheet” href=”styles.css”&gt;</strong>: This line links an external CSS stylesheet file named “styles.css” to the HTML document. It is used to apply styles to the elements on the page.</p><p><strong>&lt;body&gt;</strong>: The main content of the web page is placed within this element.</p><p><strong>&lt;div class=”container”&gt;</strong>: This <strong>&lt;div&gt;</strong> element acts as a container for grouping and organizing other elements.</p><p><strong>&lt;h1&gt;</strong>Quiz App<strong>&lt;/h1&gt;</strong>: This <strong>&lt;h1&gt;</strong> heading element displays the text “Quiz App” as the main heading of the web page.</p><p><strong>&lt;div id=”quiz”&gt;&lt;/div&gt;</strong>: This <strong>&lt;div&gt;</strong> element with the id attribute “quiz” will serve as a placeholder for dynamically generated quiz questions.</p><p><strong>&lt;div id=”result” class=”result”&gt;&lt;/div&gt;</strong>: This <strong>&lt;div&gt;</strong> element with the id attribute “result” and class attribute “result” will be used to display the quiz result.</p><p><strong>&lt;button id=”submit” class=”button”&gt;</strong>Submit<strong>&lt;/button&gt;</strong>: This <strong>&lt;button&gt;</strong> element with the id attribute “submit” and class attribute “button” represents a button labeled “Submit.” Users can click this button to submit their quiz answers.</p><p><strong>&lt;button id=”retry” class=”button hide”&gt;</strong>Retry<strong>&lt;/button&gt;</strong>: This <strong>&lt;button&gt;</strong> element with the id attribute “retry” and class attribute “button hide” represents a button labeled “Retry.” It is initially hidden (hide class), and will be displayed when the user wants to retry the quiz.</p><p><strong>&lt;button id=”showAnswer” class=”button hide”&gt;</strong>Show Answer<strong>&lt;/button&gt;</strong>: This <strong>&lt;button&gt;</strong> element with the id attribute “showAnswer” and class attribute “button hide” represents a button labeled “Show Answer.” It is initially hidden (hide class), and will be displayed to allow users to see the correct answers.</p><p><strong>&lt;script src=”script.js”&gt;&lt;/script&gt;</strong>: This line includes an external JavaScript file named “script.js” that contains the logic and functionality for the quiz app. The JavaScript code will be executed when the browser encounters this script tag.</p><p>This is the basic structure of our quiz application using HTML, and now we can move on to styling it using CSS.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;&gt;<br>    &lt;title&gt;Quiz Application&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;div class=&quot;container&quot;&gt;<br>     &lt;h1&gt;Quiz App&lt;/h1&gt;   <br>     &lt;div id=&quot;quiz&quot;&gt;&lt;/div&gt;<br>    &lt;div id=&quot;result&quot; class=&quot;result&quot;&gt;&lt;/div&gt;<br>    &lt;button id=&quot;submit&quot; class=&quot;button&quot;&gt;Submit&lt;/button&gt;<br>    &lt;button id=&quot;retry&quot; class=&quot;button hide&quot;&gt;Retry&lt;/button&gt;<br>    &lt;button id=&quot;showAnswer&quot; class=&quot;button hide&quot;&gt;Show Answer&lt;/button&gt;<br>  &lt;/div&gt;<br>  &lt;script src=&quot;main.js&quot;&gt;&lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>Step 2 (CSS Code):</strong></p><p>Once the basic HTML structure of the quiz application is in place, the next step is to add styling to the quiz application using CSS.</p><p>Next, we will create our CSS file. In this file, we will use some basic CSS rules to create our quiz application.</p><p>Let’s go through each section and explain what it does:</p><ol><li><strong>@import url(https://medium.com/%E2%80%98https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;700&amp;display=swap&#39;);</strong>: This line imports the Poppins font from Google Fonts, with different font weights (400, 500, and 700). The display=swap ensures that the text is displayed using fallback fonts until the Poppins font is fully loaded.</li><li><strong>body</strong>: This selector targets the element of the HTML document. It sets the following properties:</li></ol><p><strong>font-family: ‘Poppins’, sans-serif;</strong> It specifies the font family for the entire body text, using Poppins as the preferred font. If Poppins is not available, it falls back to the generic sans-serif font.</p><p><strong>background: </strong>#27307A<strong>;</strong> It sets the background color of the body to a light grayish-brown color (#27307A).</p><p><strong>display: flex;</strong> It makes the body a flex container.</p><p><strong>justify-content: center;</strong> It horizontally centers the flex items (content) within the body.</p><p><strong>3. container</strong>: This selector targets an element with the class “container”. It sets the following properties:</p><ul><li><strong>width: 450px;</strong> It sets the width of the container to 450 pixels.</li><li><strong>padding: 20px;</strong> It adds 20 pixels of padding around the content of the container.</li><li><strong>margin-top: 80px;</strong> It creates a top margin of 80 pixels for the container.</li><li><strong>background-color: #fff;</strong> It sets the background color of the container to white (#fff).</li><li><strong>box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);</strong>: It applies a box shadow to the container, creating a subtle shadow effect.</li><li><strong>border-radius: 20px;</strong>: It adds rounded corners to the container, with a border radius of 20 pixels.</li></ul><p><strong>4. h1</strong>: This selector targets all &lt;h1&gt; elements. It sets the following property:</p><ul><li><strong>text-align: center;</strong>: It aligns the text within the &lt;h1&gt; element to the center.</li></ul><p><strong>5. question</strong>: This selector targets an element with the class “question”. It sets the following properties:</p><ul><li><strong>font-weight: bold;</strong>: It makes the text within the element bold.</li><li><strong>margin-bottom: 10px;</strong>: It adds a bottom margin of 10 pixels to the element.</li></ul><p><strong>6. options</strong>: This selector targets an element with the class “options”. It sets the following property:</p><ul><li><strong>margin-bottom: 20px;</strong>: It adds a bottom margin of 20 pixels to the element.</li></ul><p><strong>7. option</strong>: This selector targets an element with the class “option”. It sets the following property:</p><ul><li><strong>display: block;</strong>: It makes the element a block-level element, causing it to take up the full width available.</li></ul><p><strong>8. button</strong>: This selector targets an element with the class “button”. It sets the following properties:</p><ul><li><strong>display: inline-block;</strong> It makes the element an inline block.</li><li><strong>padding: 10px 20px;</strong> It adds 10 pixels of padding on the top and bottom and 20 pixels of padding on the left and right.</li><li><strong>background-color: #428bca;</strong>: It sets the background color of the button to a shade of blue (#428bca).</li><li><strong>color: #fff;</strong>: It sets the text color of the button to white (#fff).</li><li><strong>border: none;</strong>: It removes the border around the button.</li><li><strong>cursor: pointer;</strong>: It changes the cursor to a pointer when hovering over the button.</li><li><strong>font-size: 16px;</strong>: It sets the font size of the button text to 16 pixels.</li><li><strong>border-radius: 4px;</strong>: It adds rounded corners to the button, with a border radius of 4 pixels.</li><li><strong>transition: background-color 0.3s;</strong>: It adds a transition effect to the background color property, with a duration of 0.3 seconds.</li><li><strong>margin-right: 10px;</strong>: It adds a right margin of 10 pixels to the button.</li></ul><p><strong>9. button:hover</strong>: This selector targets the button when it is being hovered over. It sets the following property:</p><ul><li><strong>background-color: #3071a9;</strong> It changes the background color of the button to a darker shade of blue when hovered.</li></ul><p><strong>10.result</strong>: This selector targets an element with the class “result”. It sets the following properties:</p><ul><li><strong>text-align: center;</strong> It aligns the text within the element to the center.</li><li><strong>margin-top: 20px;</strong> It adds a top margin of 20 pixels to the element.</li><li><strong>font-weight: bold;</strong> It makes the text within the element bold.</li></ul><p><strong>11.hide</strong>: This selector targets an element with the class “hide”. It sets the following property:</p><ul><li><strong>display: none;</strong> It hides the element by setting its display property to “none”.</li></ul><p>This will give our quiz application an upgraded presentation. Create a CSS file with the name of styles.css and paste the given codes into your CSS file. Remember that you must create a file with the .css extension.</p><pre>@import url(https://medium.com/&#39;https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;700&amp;display=swap&#39;);<br><br>body{<br>    font-family:&#39;Poppins&#39;, sans-serif;<br>    background:#27307A ;<br>    display: flex;<br>    justify-content: center;<br><br>}<br><br>.container{<br>    width: 450px;<br>    padding: 20px;<br>    margin-top: 80px;<br>    background: white;<br>    box-shadow:0 2px 4px rgba(0, 0, 0, 0.1) ;<br>    border-radius: 20px;<br>}<br>h1{<br>    text-align: center;<br>}<br>.question {<br>    font-weight: bold;<br>    margin-bottom: 10px;<br>  }<br>  <br>  .options {<br>    margin-bottom: 20px;<br>  }<br>  <br>  .option {<br>    display: block;<br>    margin-bottom: 10px;<br>  }<br>  <br>  .button {<br>    display: inline-block;<br>    padding: 10px 20px;<br>    background-color: #428bca;<br>    color: #fff;<br>    border: none;<br>    cursor: pointer;<br>    font-size: 16px;<br>    border-radius: 4px;<br>    transition: background-color 0.3s;<br>    margin-right: 10px;<br>  }<br>  <br>  .button:hover {<br>    background-color: #3071a9;<br>  }<br>  <br>  .result {<br>    text-align: center;<br>    margin-top: 20px;<br>    font-weight: bold;<br>  }<br>  <br>  .hide{<br>    display: none;<br>  }</pre><p><strong>Step 3 (JavaScript Code):</strong></p><p>Finally, we need to create a function in JavaScript to sets up a simple quiz game. Let’s go through the code step by step:</p><p>The code defines an array called <strong>quizData</strong> that contains multiple objects. Each object represents a question in the quiz and has properties such as question (the question itself), options (an array of answer options), and answer (the correct answer).</p><p>The code then defines variables to store references to various elements in the HTML document, such as the <strong>quizContainer</strong>, <strong>resultContainer</strong>, <strong>submitButton</strong>, <strong>retryButton</strong>, and <strong>showAnswerButton</strong>. These elements are identified using their respective IDs.</p><p>Two variables, <strong>currentQuestion </strong>and <strong>score</strong>, are initialized to keep track of the current question being displayed and the player’s score, respectively. Additionally, an array called <strong>incorrectAnswers </strong>is created to store any incorrect answers provided by the player.</p><p>The code includes a function called <strong>shuffleArray</strong>, which takes an array as input and shuffles its elements randomly. This function is used to randomize the order of answer options for each question.</p><p>The <strong>displayQuestion </strong>function is defined to render the current question and its answer options on the page. It retrieves the question data from the <strong>quizData </strong>array based on the <strong>currentQuestion </strong>index. It creates HTML elements dynamically to display the question and options, and appends them to the <strong>quizContainer</strong>.</p><p>The <strong>checkAnswer </strong>function is responsible for validating the player’s answer. It retrieves the selected option using a CSS selector, checks if an option is selected, compares the selected answer with the correct answer from <strong>quizData</strong>, and increments the score or adds the question to the <strong>incorrectAnswers</strong> array accordingly. It then updates the <strong>currentQuestion </strong>index, clears the selected option, and either displays the next question or the result if there are no more questions.</p><p>The <strong>displayResult</strong> function is called when all the questions have been answered. It hides the quiz container and submit button, and shows the retry and show answer buttons. It displays the player’s score and the number of questions in the <strong>resultContainer</strong>.</p><p>The <strong>retryQuiz </strong>function is called when the player clicks the retry button. It resets the <strong>currentQuestion</strong>, score, and <strong>incorrectAnswers </strong>to their initial values, displays the quiz container and submit button, and hides the retry and show answer buttons. It also clears the result container and calls <strong>displayQuestion </strong>to start the quiz again.</p><p>The <strong>showAnswer </strong>function is called when the player clicks the show answer button. It hides the quiz container, submit button, and show answer button. It generates HTML to display the player’s score and lists all the incorrect answers with the corresponding correct answers.</p><p>Event listeners are attached to the submit, retry, and show answer buttons, which call their respective functions when clicked.</p><p>Finally, the <strong>displayQuestion </strong>function is called initially to start the quiz by displaying the first question.</p><p>Create a JavaScript file with the name of script.js and paste the given codes into your JavaScript file and make sure it’s linked properly to your HTML document, so that the scripts are executed on the page. Remember, you’ve to create a file with .js extension.</p><pre>const quizData = [<br>    {<br>      question: &#39;A set of intructions that tells the computer how to behave, what to do and derive at a solution to a particular problem is:&#39;,<br>      options: [&#39;Algorithm&#39;, &#39;Pseudocode&#39;, &#39;Programming&#39;, &#39;Program&#39;],<br>      answer: &#39;Program&#39;,<br>    },<br>    {<br>      question: &#39;A set of logically sequenced instructions that allows to find the solution to a problem is:&#39;,<br>      options: [&#39;Algorithm&#39;, &#39;Pseudocode&#39;, &#39;Programming&#39;, &#39;Program&#39;],<br>      answer: &#39;Algorithm&#39;,<br>    },<br>    {<br>      question: &#39;The six stages of program development in logical order are:&#39;,<br>      options: [&#39;Define, Analyze, Write, Test, Document, Debug&#39;, &#39;Define, Analyze, Develop, Write, Test and Debug, Document&#39;, &#39;Define, Write, Develop, Analyze, Test, Document&#39;, &#39;Define, Develop, Write, Test, Document, Debug&#39;],<br>      answer: &#39;Define, Analyze, Develop, Write, Test and Debug, Document&#39;,<br>    },<br>    {<br>      question: &#39;The programming language that is used to show pupils the concept and structure of programming is called:&#39;,<br>      options: [&#39;Basic&#39;, &#39;Cobol&#39;, &#39;Pascal&#39;, &#39;Java&#39;],<br>      answer: &#39;Pascal&#39;,<br>    },<br>    {<br>      question: &#39;Java is an example of which generation programming language&#39;,<br>      options: [<br>        &#39;4GLs&#39;,<br>        &#39;3rd&#39;,<br>        &#39;2nd&#39;,<br>        &#39;1st&#39;,<br>      ],<br>      answer: &#39;3rd&#39;,<br>    },<br>    {<br>      question: &#39;Which of the following generations of programming language executed code faster:&#39;,<br>      options: [&#39;4GLs&#39;, &#39;3rd&#39;, &#39;2nd&#39;, &#39;1st&#39;],<br>      answer: &#39;1st&#39;,<br>    },<br>    {<br>      question: &#39;Algorithms must be all of the following except:&#39;,<br>      options: [<br>        &#39;Logical&#39;,<br>        &#39;Ambiguous&#39;,<br>        &#39;Concise&#39;,<br>        &#39;Precise&#39;,<br>      ],<br>      answer: &#39;Ambiguous&#39;,<br>    },<br>    {<br>      question: &#39;Which language had codes such as MOV, ADD, SUB&#39;,<br>      options: [&#39;Java&#39;, &#39;Binary&#39;, &#39;Pascal&#39;, &#39;Assembly&#39;],<br>      answer: &#39;Assembly&#39;,<br>    },<br>    {<br>      question: &#39;Which of the following had executes programming codes line by line, rather than the whole program&#39;,<br>      options: [<br>        &#39;Compiler&#39;,<br>        &#39;Interprete&#39;,<br>        &#39;Executer&#39;,<br>        &#39;Translator&#39;,<br>      ],<br>      answer: &#39;Interpreter&#39;,<br>    },<br>    {<br>      question: &#39;All the following are examples of third programming language except:&#39;,<br>      options: [&#39;Pascal&#39;, &#39;C#&#39;, &#39;Basic&#39;, &#39;Fortran&#39;],<br>      answer: &#39;Fortran&#39;,<br>    },<br>  ];<br>  <br>  const quizContainer = document.getElementById(&#39;quiz&#39;);<br>  const resultContainer = document.getElementById(&#39;result&#39;);<br>  const submitButton = document.getElementById(&#39;submit&#39;);<br>  const retryButton = document.getElementById(&#39;retry&#39;);<br>  const showAnswerButton = document.getElementById(&#39;showAnswer&#39;);<br>  <br>  let currentQuestion = 0;<br>  let score = 0;<br>  let incorrectAnswers = [];<br>  <br>  function shuffleArray(array) {<br>    for (let i = array.length - 1; i &gt; 0; i--) {<br>      const j = Math.floor(Math.random() * (i + 1));<br>      [array[i], array[j]] = [array[j], array[i]];<br>    }<br>  }<br>  <br>  function displayQuestion() {<br>    const questionData = quizData[currentQuestion];<br>  <br>    const questionElement = document.createElement(&#39;div&#39;);<br>    questionElement.className = &#39;question&#39;;<br>    questionElement.innerHTML = questionData.question;<br>  <br>    const optionsElement = document.createElement(&#39;div&#39;);<br>    optionsElement.className = &#39;options&#39;;<br>  <br>    const shuffledOptions = [...questionData.options];<br>    shuffleArray(shuffledOptions);<br>  <br>    for (let i = 0; i &lt; shuffledOptions.length; i++) {<br>      const option = document.createElement(&#39;label&#39;);<br>      option.className = &#39;option&#39;;<br>  <br>      const radio = document.createElement(&#39;input&#39;);<br>      radio.type = &#39;radio&#39;;<br>      radio.name = &#39;quiz&#39;;<br>      radio.value = shuffledOptions[i];<br>  <br>      const optionText = document.createTextNode(shuffledOptions[i]);<br>  <br>      option.appendChild(radio);<br>      option.appendChild(optionText);<br>      optionsElement.appendChild(option);<br>    }<br>  <br>    quizContainer.innerHTML = &#39;&#39;;<br>    quizContainer.appendChild(questionElement);<br>    quizContainer.appendChild(optionsElement);<br>  }<br>  <br>  function checkAnswer() {<br>    const selectedOption = document.querySelector(&#39;input[name=&quot;quiz&quot;]:checked&#39;);<br>    if (selectedOption) {<br>      const answer = selectedOption.value;<br>      if (answer === quizData[currentQuestion].answer) {<br>        score++;<br>      } else {<br>        incorrectAnswers.push({<br>          question: quizData[currentQuestion].question,<br>          incorrectAnswer: answer,<br>          correctAnswer: quizData[currentQuestion].answer,<br>        });<br>      }<br>      currentQuestion++;<br>      selectedOption.checked = false;<br>      if (currentQuestion &lt; quizData.length) {<br>        displayQuestion();<br>      } else {<br>        displayResult();<br>      }<br>    }<br>  }<br>  <br>  function displayResult() {<br>    quizContainer.style.display = &#39;none&#39;;<br>    submitButton.style.display = &#39;none&#39;;<br>    retryButton.style.display = &#39;inline-block&#39;;<br>    showAnswerButton.style.display = &#39;inline-block&#39;;<br>    resultContainer.innerHTML = `You scored ${score} out of ${quizData.length}!`;<br>  }<br>  <br>  function retryQuiz() {<br>    currentQuestion = 0;<br>    score = 0;<br>    incorrectAnswers = [];<br>    quizContainer.style.display = &#39;block&#39;;<br>    submitButton.style.display = &#39;inline-block&#39;;<br>    retryButton.style.display = &#39;none&#39;;<br>    showAnswerButton.style.display = &#39;none&#39;;<br>    resultContainer.innerHTML = &#39;&#39;;<br>    displayQuestion();<br>  }<br>  <br>  function showAnswer() {<br>    quizContainer.style.display = &#39;none&#39;;<br>    submitButton.style.display = &#39;none&#39;;<br>    retryButton.style.display = &#39;inline-block&#39;;<br>    showAnswerButton.style.display = &#39;none&#39;;<br>  <br>    let incorrectAnswersHtml = &#39;&#39;;<br>    for (let i = 0; i &lt; incorrectAnswers.length; i++) {<br>      incorrectAnswersHtml += `<br>        &lt;p&gt;<br>          &lt;strong&gt;Question:&lt;/strong&gt; ${incorrectAnswers[i].question}&lt;br&gt;<br>          &lt;strong&gt;Your Answer:&lt;/strong&gt; ${incorrectAnswers[i].incorrectAnswer}&lt;br&gt;<br>          &lt;strong&gt;Correct Answer:&lt;/strong&gt; ${incorrectAnswers[i].correctAnswer}<br>        &lt;/p&gt;<br>      `;<br>    }<br>  <br>    resultContainer.innerHTML = `<br>      &lt;p&gt;You scored ${score} out of ${quizData.length}!&lt;/p&gt;<br>      &lt;p&gt;Incorrect Answers:&lt;/p&gt;<br>      ${incorrectAnswersHtml}<br>    `;<br>  }<br>  <br>  submitButton.addEventListener(&#39;click&#39;, checkAnswer);<br>  retryButton.addEventListener(&#39;click&#39;, retryQuiz);<br>  showAnswerButton.addEventListener(&#39;click&#39;, showAnswer);<br>  <br>  displayQuestion();</pre><p>With these code snippets in place, you’ll have Build a Quiz Application with HTML, CSS, and JavaScriptthat responds to mouse move, mouse out, and mouse stopped events on your webpage. Feel free to customize the styles and animation behavior to suit your needs. Enjoy creating awesome cursor effects on your website!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m0tJuiSI-dHELmVt" /><figcaption>Out Put</figcaption></figure><p>Follow me :<a href="https://github.com/SavvyChic42/Build-a-Quiz-Application-with-HTML-CSS-and-JavaScript/tree/main">https://github.com/SavvyChic42/Build-a-Quiz-Application-with-HTML-CSS-and-JavaScript/tree/main</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3cac01e848e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to create Animated-Cursor-using-React-GSAP]]></title>
            <link>https://medium.com/@dinithinethmini01/how-to-create-animated-cursor-using-react-gsap-7e9f41424341?source=rss-315d9003adbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e9f41424341</guid>
            <dc:creator><![CDATA[Dinithi Nethmini]]></dc:creator>
            <pubDate>Sat, 30 Mar 2024 17:11:34 GMT</pubDate>
            <atom:updated>2024-03-30T17:11:34.407Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c5iG0GAsDz5jbytSXnJH6Q.png" /><figcaption>Using For Canva</figcaption></figure><p>GSAP stands for GreenSock Animation Platform. It’s a powerful JavaScript library that enables developers to create high-performance, feature-rich animations and interactive elements for the web. With GSAP, you can animate various CSS properties, including position, size, color, and more, with precise control over timing, easing, and sequencing.</p><p>In the context of creating an animated custom cursor, GSAP can be utilized to create smooth transitions, interactive behaviors, and engaging visual effects that enhance the user experience.</p><p>To get started with GSAP, you can include the GSAP library in your HTML file using a &lt;script&gt; tag or import it as a module in your JavaScript code. Once you’ve set up GSAP, you can define animations by creating GSAP instances and specifying the target elements and desired animation properties.</p><h3>What is GSAP?</h3><p>GSAP (GreenSock Animation Platform) is a high-performance JavaScript library that enables developers to create complex, feature-rich animations and interactive elements for web-based projects. It provides a flexible and intuitive API that simplifies the process of animating CSS properties, DOM elements, and other aspects of web content.</p><p>GSAP’s key features include:</p><ol><li><strong>Performance</strong>: GSAP is known for its exceptional performance, delivering smooth animations even on resource-constrained devices.</li><li><strong>Advanced Control</strong>: GSAP offers fine-grained control over animation properties, such as duration, easing, stagger, and sequencing.</li><li><strong>Easing Options</strong>: GSAP provides various easing equations to control animation acceleration and deceleration, giving your animations a more natural feel.</li><li><strong>Plugins</strong>: GSAP offers a wide range of plugins to extend its capabilities, such as animating SVG elements, morphing shapes, and handling advanced physics-based motion.</li></ol><p>In our example, GSAP will be used to create an engaging animation effect by making objects follow the user’s mouse cursor. This enhances the user experience by adding interactive elements to the web page and providing visual feedback to the user’s actions. By leveraging the power of GSAP, developers can easily create complex and visually appealing animations without sacrificing performance or control.</p><h3>Setting Up the Project</h3><p>Before we dive into the code, make sure you have Node.js and npm (Node Package Manager) installed on your computer.</p><p>Now, let’s set up a new React project. Open your terminal and run the following commands:</p><pre>npx create-react-app my app&lt;br&gt;<br>cd mouse-hover-effect&lt;br&gt;<br>npm install gsap&lt;br&gt;</pre><p>We’re creating a new React application called “mouse-hover-effect” and installing the GSAP library. Once that’s done, you can open your project folder with a code editor.</p><p>If you intend to use Tailwind CSS for styling, follow this <a href="https://tailwindcss.com/docs/guides/create-react-app">guide</a> for installation. Feel free to use vanilla CSS or any other CSS framework or library of your choice.</p><h3>Creating the App Component</h3><pre>import { useEffect,useRef } from &#39;react&#39;;<br>import &#39;./App.css&#39;;<br>import gsap from &quot;gsap&quot;;<br><br><br>function App() {<br>  const size =30;<br>  const circle= useRef();<br>  const mouse =useRef({x:0 , y: 0});<br>  const delayedMouse =useRef({x:0,y:0});<br><br>  const handleMouseMove =(e) =&gt; {<br>    mouse.current ={x:e.clientX, y: e.clientY};<br>  };<br><br>  const animateCursor =(x,y) =&gt;{<br>    gsap.set(circle.current,{x,y, yPercent: -50, xPercent: -50});<br>};<br>const lerp =(x,y, alpha) =&gt;x *(1 - alpha) + y* alpha;<br><br>const animation =() =&gt;{<br>  const {x,y} = delayedMouse.current;<br>  delayedMouse.current ={<br>    x: lerp(x,mouse.current.x,0.075),<br>    y: lerp(y,mouse.current.x,0.075),<br>  };<br>  animateCursor(delayedMouse.current.x,delayedMouse.current.y);<br>  window.requestAnimationFrame(animation);<br>};<br>useEffect(()=&gt;{<br>  animation();<br>  window.addEventListener(&quot;mousemove&quot;,handleMouseMove);<br>  return () =&gt;{<br>   window.removeEventListener(&quot;mousemove&quot;,handleMouseMove)<br>  };<br>},[]);<br>  return (<br>    &lt;div ref={circle}<br>    className=&#39;animated-cursor&#39;<br>    style={{<br>      width:size,<br>      height :size,<br>    }}<br>    &gt;<br>      &lt;div&gt;&lt;/div&gt;<br><br>    &lt;/div&gt;<br>    <br>  );<br>}<br><br>export default App;</pre><p>To see the app in action, start your development server with the following command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*bftcPBNab0hMypRzXb9bRw.png" /></figure><p>Open your web browser and go to http://localhost:3000 You should see a black interface with five yellow balls stacked at the top-right of your screen. We also have a text heading that says &quot;Mouse Hover Effect&quot; at the center of the screen.</p><h3>Let’s Get Our Balls Moving</h3><pre>import { useEffect,useRef } from &#39;react&#39;;<br>import &#39;./App.css&#39;;<br>import gsap from &quot;gsap&quot;;<br><br><br>function App() {<br>  const size =30;<br>  const circle= useRef();<br>  const mouse =useRef({x:0 , y: 0});<br>  const delayedMouse =useRef({x:0,y:0});<br><br>  const handleMouseMove =(e) =&gt; {<br>    mouse.current ={x:e.clientX, y: e.clientY};<br>  };<br><br>  const animateCursor =(x,y) =&gt;{<br>    gsap.set(circle.current,{x,y, yPercent: -50, xPercent: -50});<br>};<br>const lerp =(x,y, alpha) =&gt;x *(1 - alpha) + y* alpha;<br><br>const animation =() =&gt;{<br>  const {x,y} = delayedMouse.current;<br>  delayedMouse.current ={<br>    x: lerp(x,mouse.current.x,0.075),<br>    y: lerp(y,mouse.current.x,0.075),<br>  };<br>  animateCursor(delayedMouse.current.x,delayedMouse.current.y);<br>  window.requestAnimationFrame(animation);<br>};<br>useEffect(()=&gt;{<br>  animation();<br>  window.addEventListener(&quot;mousemove&quot;,handleMouseMove);<br>  return () =&gt;{<br>   window.removeEventListener(&quot;mousemove&quot;,handleMouseMove)<br>  };<br>},[]);<br>  return (<br>    &lt;div ref={circle}<br>    className=&#39;animated-cursor&#39;<br>    style={{<br>      width:size,<br>      height :size,<br>    }}<br>    &gt;<br>      &lt;div&gt;&lt;/div&gt;<br><br>    &lt;/div&gt;<br>    <br>  );<br>}<br><br>export default App;</pre><p>gsap.set(&quot;.ball&quot;, { xPercent: -50, yPercent: -50 }); centers all HTML elements with the class &quot;ball&quot; both horizontally and vertically within their parent containers by adjusting the xPercent and yPercent properties using GSAP. The selection of elements can also be done by using React&#39;s <a href="https://www.w3schools.com/react/react_useref.asp">useRef hook</a> to access DOM elements.</p><p>xPercent: -50 and YPercent: -50 properties specify the horizontal position and vertical position of the element as a percentage of its width and height, respectively.</p><p>gsap.utils.toArray(&quot;.ball&quot;) is used to select all HTML elements with the class &quot;ball&quot; and convert them into an array. This can be useful when you want to work with multiple elements that share the same class. The resulting array is assigned to the variable targets</p><p>gsap.to(targets, { ... }); uses GSAP&#39;s to method to animate one or more elements specified by the targets variable. The animation properties and values are defined within the object passed as the second argument.</p><p>x: e.clientX, y: e.clientYset the x and y properties of the animation. They are being animated to the current position of the mouse cursor.</p><p>ease: &quot;power1.out&quot; specifies the easing function for the animation. &quot;power1.out&quot; provides smooth acceleration and deceleration.<br>You can check out <a href="https://greensock.com/docs/v3/Eases">GreenSock Ease Visualizer</a> to see and test other easing functions in GSAP</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/0*BOvrFm9XoNpN2EEG" /></figure><p>overwrite: &quot;auto&quot; controls how the animation behaves if multiple animations are triggered before the previous one completes. &quot;Auto&quot; means that GSAP will automatically handle overlapping animations, ensuring that the latest animation takes precedence.</p><p>stagger: 0.02 introduces a stagger effect, meaning that if you have multiple elements in your targets array, they will start their animations with a slight delay of 0.02 seconds between each element. This creates a cascading or staggered effect for the animations.</p><p>With these code snippets in place, you’ll have an animated cursor effect that responds to mouse move, mouse out, and mouse stopped events on your webpage. Feel free to customize the styles and animation behavior to suit your needs. Enjoy creating awesome cursor effects on your website!</p><p>Follow: <a href="https://github.com/SavvyChic42/Animated-Cursor-using-React-GSAP/tree/main">https://github.com/SavvyChic42/Animated-Cursor-using-React-GSAP/tree/main</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e9f41424341" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Cursor Animation Effects with JavaScript, HTML, and CSS]]></title>
            <link>https://medium.com/@dinithinethmini01/creating-cursor-animation-effects-with-javascript-html-and-css-e450f6c0ed69?source=rss-315d9003adbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/e450f6c0ed69</guid>
            <dc:creator><![CDATA[Dinithi Nethmini]]></dc:creator>
            <pubDate>Thu, 28 Mar 2024 18:48:46 GMT</pubDate>
            <atom:updated>2024-03-28T18:48:46.571Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QpSBVxmDqqT4-NEnc2k25g.png" /><figcaption>Using For Canva</figcaption></figure><p>Hello everyone! In this video, you are going to learn how to create an animated cursor for a website using HTML, CSS, and Javascript on mouse move, mouse out, and mouse stopped. On the mouse move event, the cursor animation element will follow the cursor pointer everywhere it moves on the page. On the mouse out event, when the mouse pointer is out from the page the cursor animation will hide from the page. And also on the mouse stopped function, when the mouse pointer stopped on the page the cursor will hide from the page. Let’s see how to create this animated cursor effect.</p><p>First, create the index.html file and style.css file. After you created those files then start the HTML part of the cursor element in the index.html file. When the HTML part is complete, to start the styling part with the cursor element animation link the style.css file to the index.html file in between &lt;head&gt;&lt;/head&gt; tags. Then go to the style.css file and do the styling part of the cursor element animation as you can see in the video. After the styling part complete then go to the index.html file for the javascript part. In the index.html file before the body close tag open &lt;script&gt;&lt;/script&gt; tags and complete the javascript part inside that tags as you can see in the video. So that’s all. Hope this video will be helpful to create awesome cursor effects on a website.</p><h3>Step 1: Setting up HTML and CSS</h3><p>First, create two files: index.html and style.css. In the index.html file, set up the basic HTML structure and link the style.css file within the &lt;head&gt;&lt;/head&gt; tags:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;<br>    &lt;title&gt;Curusor Effect&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;div class=&quot;cursor&quot;&gt;<br>        &lt;h1&gt;Hello!!&lt;/h1&gt;<br>        &lt;p&gt;Happy Codeing&lt;/p&gt;<br>    &lt;/div&gt;<br>    &lt;script src=&quot;script.js&quot;&gt;&lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>In the style.css file, apply the CSS styles to the cursor element:</p><pre>body {<br>    background: black;<br>    display: flex;<br>    justify-content: center;<br>    align-items: center;<br>    height: 100vh;<br>    font-family: poppins;<br>  }<br>  <br>  .cursor {<br>    z-index: 999;<br>    position: fixed;<br>    background: #2696E8;<br>    width: 20px;<br>    height: 20px;<br>    border-radius: 50%;<br>    pointer-events: none;<br>    box-shadow: 0 0 20px #2696E8,<br>        0 0 60px #2696E8,<br>        0 0 100px #2696E8;<br>    animation: colors 5s infinite;<br>    transform: translate(-50%, -50%);<br>    display: none;<br>  }<br>h1{<br>    color: white;<br>}<br><br>p{<br>    color: white;<br>}<br>  <br>  @keyframes colors {<br>    0% {<br>        filter: hue-rotate(0deg);<br>    }<br>  <br>    100% {<br>        filter: hue-rotate(360deg);<br>    }<br>  }<br>  <br>  .cursor:before {<br>    content: &#39;&#39;;<br>    position: absolute;<br>    background: #2696E8;<br>    width: 50px;<br>    height: 50px;<br>    opacity: 0.2;<br>    transform: translate(-30%, -30%);<br>    border-radius: 50%;<br>  }</pre><p>Step 2: Implementing JavaScript for cursor effects</p><p>Back in the index.html file, add the JavaScript code inside &lt;script&gt;&lt;/script&gt; tags before the closing &lt;/body&gt; tag. Here, you’ll define event listeners for mousemove, mouseout, and the custom mouse stopped event:</p><pre>const cursor = document.querySelector(&quot;.cursor&quot;);<br>var timeout;<br><br>//follow cursor on mousemove<br>document.addEventListener(&quot;mousemove&quot;, (e) =&gt; {<br>    let x = e.pageX;<br>    let y = e.pageY;<br><br>    cursor.style.top = y + &quot;px&quot;;<br>    cursor.style.left = x + &quot;px&quot;;<br>    cursor.style.display = &quot;block&quot;;<br><br>    //cursor effects when mouse stopped<br>    function mouseStopped() {<br>        cursor.style.display = &quot;none&quot;;<br>    }<br>    clearTimeout(timeout);<br>    timeout = setTimeout(mouseStopped, 5000);<br>});<br><br>//cursor effects when mouseout<br>document.addEventListener(&quot;mouseout&quot;, () =&gt; {<br>    cursor.style.display = &quot;none&quot;;<br>});</pre><p>With these code snippets in place, you’ll have an animated cursor effect that responds to mouse move, mouse out, and mouse stopped events on your webpage. Feel free to customize the styles and animation behavior to suit your needs. Enjoy creating awesome cursor effects on your website!</p><p>Follow me :<a href="https://github.com/SavvyChic42/Animated-Cursor-using-HTML-CSS-JS">https://github.com/SavvyChic42/Animated-Cursor-using-HTML-CSS-JS</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e450f6c0ed69" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a Secure Password Generator with React and CSS Step-by-step guide.]]></title>
            <link>https://medium.com/@dinithinethmini01/create-a-secure-password-generator-with-react-and-css-step-by-step-guide-16d027c01479?source=rss-315d9003adbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/16d027c01479</guid>
            <dc:creator><![CDATA[Dinithi Nethmini]]></dc:creator>
            <pubDate>Thu, 28 Mar 2024 08:39:22 GMT</pubDate>
            <atom:updated>2024-03-28T08:39:22.656Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OmZMOAaNRLwjuvPDfEto5g.png" /><figcaption>Password Generator with React</figcaption></figure><p>Learn how to build a safe password generator with customizable options, copy-to-clipboard functionality, and an elegant design using React and CSS.</p><p><strong>Introduction</strong>: In this tutorial, you will learn how to create a safe password generator using React and CSS. We’ll cover step by step how to build a customizable password generator component, implement copy-to-clipboard functionality, and design a visually appealing UI.</p><p><strong>Prerequisites</strong>:</p><ul><li>Basic knowledge of React and JavaScript</li><li>Familiarity with CSS</li><li>Node.js and npm installed</li></ul><p><strong>Step 1:</strong> Set up a new React app First, create a new React app using create-react-app or any other preferred method. Navigate to the project directory and run the following command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*N3UQ-kj__AHqPSW8W9C0TQ.png" /></figure><p><strong>Step 2:</strong> Create the password generator components the src folder, create a new folder named components, and inside it, create a new file called App.js</p><pre>import React, { useState } from &#39;react&#39;<br>import &quot;./App.css&quot;<br>import { numbers, upperCaseLetters, lowerCaseLetters, specialCharacters } from &#39;./Character&#39;<br>import { toast, ToastContainer } from &#39;react-toastify&#39;<br>import &#39;react-toastify/dist/ReactToastify.css&#39;;<br>import { COPY_Fail, COPY_SUCCESS } from &#39;./message&#39;;<br><br>const App = () =&gt; {<br>  const [password, setPassword] = useState(&quot;&quot;)<br>  const [passwordLength, setPasswordLength] = useState(26)<br>  const [includeUpperCase, setIncludeUpperCase] = useState(false)<br>  const [includeLowerCase, setIncludeLowerCase] = useState(false)<br>  const [includeNumbers, setIncludeNumbers] = useState(false)<br>  const [includeSymbols, setIncludeSymbols] = useState(false)<br>  const handleGeneratePassword = () =&gt; {<br>    if (!includeUpperCase &amp;&amp; !includeLowerCase &amp;&amp; !includeNumbers &amp;&amp; !includeSymbols) {<br>      notify(&quot;To generate password you must select atleast one checkbox&quot;, true)<br>    }<br>    else {<br>      let characterList = &quot;&quot;<br>      if (includeNumbers) {<br>        characterList = characterList + numbers<br>      }<br>      if (includeUpperCase) {<br>        characterList = characterList + upperCaseLetters<br>      }<br>      if (includeLowerCase) {<br>        characterList = characterList + lowerCaseLetters<br>      }<br>      if (includeSymbols) {<br>        characterList = characterList + specialCharacters<br>      }<br>      setPassword(createPassword(characterList))<br>      notify(&quot;Password is generated successfully&quot;, false)<br>    }<br><br><br>  }<br>  const createPassword = (characterList) =&gt; {<br>    let password = &quot;&quot;<br>    const characterListLength = characterList.length<br>    for (let i = 0; i &lt; passwordLength; i++) {<br>      const characterIndex = Math.round(Math.random() * characterListLength)<br>      password = password + characterList.charAt(characterIndex)<br>    }<br>    return password<br>  }<br>  const copyToClipboard = (password) =&gt; {<br><br>    navigator.clipboard.writeText(password)<br>  }<br>  const notify = (message, hasError = false) =&gt; {<br>    if (hasError) {<br>      toast.error(message, {<br>        position: &quot;top-center&quot;,<br>        autoClose: 5000,<br>        hideProgressBar: false,<br>        closeOnClick: true,<br>        pauseOnHover: true,<br>        draggable: true,<br>        progress: undefined,<br>      });<br>    }<br>    else {<br>      toast(message, {<br>        position: &quot;top-center&quot;,<br>        autoClose: 5000,<br>        hideProgressBar: false,<br>        closeOnClick: true,<br>        pauseOnHover: true,<br>        draggable: true,<br>        progress: undefined,<br>      });<br>    }<br><br>  }<br>  const handleCopyPassword = (e) =&gt; {<br>    if (password === &quot;&quot;) {<br>      notify(COPY_Fail, true)<br>    }<br>    else {<br>      copyToClipboard(password)<br>      notify(COPY_SUCCESS)<br>    }<br><br>  }<br><br>  return (<br>    &lt;div className=&quot;App&quot;&gt;<br>      &lt;div className=&quot;container&quot;&gt;<br>        &lt;div className=&quot;generator&quot;&gt;<br>          &lt;h2 className=&quot;generator__header&quot;&gt;<br>           Password Generator<br>          &lt;/h2&gt;<br>          &lt;div className=&quot;generator__password&quot;&gt;<br>            &lt;h3 &gt;{password}&lt;/h3&gt;<br>            &lt;button className=&quot;copy__btn&quot;&gt;<br>              &lt;i onClick={handleCopyPassword} className=&quot;far fa-clipboard&quot;&gt;&lt;/i&gt;<br>            &lt;/button&gt;<br>          &lt;/div&gt;<br>          &lt;div className=&quot;form-group&quot;&gt;<br>            &lt;label htmlFor=&quot;password-strength&quot;&gt;Password length&lt;/label&gt;<br>            &lt;input className=&quot;pw&quot; defaultValue={passwordLength} onChange={(e) =&gt; setPasswordLength(e.target.value)} type=&quot;number&quot; id=&quot;password-stregth&quot; name=&quot;password-strength&quot; max=&quot;26&quot; min=&quot;8&quot; /&gt;<br>          &lt;/div&gt;<br>          &lt;div className=&quot;form-group&quot;&gt;<br>            &lt;label htmlFor=&quot;uppercase-letters&quot;&gt;Add Uppercase Letters&lt;/label&gt;<br>            &lt;input checked={includeUpperCase} onChange={(e) =&gt; setIncludeUpperCase(e.target.checked)} type=&quot;checkbox&quot; id=&quot;uppercase-letters&quot; name=&quot;uppercase-letters&quot; /&gt;<br>          &lt;/div&gt;<br>          &lt;div className=&quot;form-group&quot;&gt;<br>            &lt;label htmlFor=&quot;lowercase-letters&quot;&gt;Add Lowercase Letters&lt;/label&gt;<br>            &lt;input checked={includeLowerCase} onChange={(e) =&gt; setIncludeLowerCase(e.target.checked)} type=&quot;checkbox&quot; id=&quot;lowercase-letters&quot; name=&quot;lowercase-letters&quot; /&gt;<br>          &lt;/div&gt;<br>          &lt;div className=&quot;form-group&quot;&gt;<br>            &lt;label htmlFor=&quot;include-numbers&quot;&gt;Include Numbers&lt;/label&gt;<br>            &lt;input checked={includeNumbers} onChange={(e) =&gt; setIncludeNumbers(e.target.checked)} type=&quot;checkbox&quot; id=&quot;include-numbers&quot; name=&quot;include-numbers&quot; /&gt;<br>          &lt;/div&gt;<br>          &lt;div className=&quot;form-group&quot;&gt;<br>            &lt;label htmlFor=&quot;include-symbols&quot;&gt;Include Symbols&lt;/label&gt;<br>            &lt;input checked={includeSymbols} onChange={(e) =&gt; setIncludeSymbols(e.target.checked)} type=&quot;checkbox&quot; id=&quot;include-symbols&quot; name=&quot;include-symbols&quot; /&gt;<br>          &lt;/div&gt;<br>          &lt;button onClick={handleGeneratePassword} className=&quot;generator__btn&quot;&gt;<br>            Generate Password<br>          &lt;/button&gt;<br>          &lt;ToastContainer<br>            position=&quot;top-center&quot;<br>            autoClose={5000}<br>            hideProgressBar={false}<br>            newestOnTop={false}<br>            closeOnClick<br>            rtl={false}<br>            pauseOnFocusLoss<br>            draggable<br>            pauseOnHover<br>          /&gt;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  )<br>}<br><br><br>export default App;</pre><p>Create the password generator components the src folder, create a new folder named components, and inside it, create a new file called character.js</p><pre>export const numbers = &#39;0123456789&#39;<br>export const upperCaseLetters = &#39;ABCDEFGHIJKLMNOPQRSTUVWXYZ&#39;<br>export const lowerCaseLetters =&#39;abcdefghijklmnopqrstuvwxyz&#39;<br>export const specialCharacters = &quot;!&#39;^+%&amp;/()=?_#$½§{[]}|;:&gt;÷`&lt;.*-@é&quot;</pre><p>Create the password generator components the src folder, create a new folder named components, and inside it, create a new file called message.js</p><pre>export const COPY_SUCCESS = &quot;Password successfully copied to clipboard&quot;<br>export const COPY_Fail = &quot;Password successfully copied to clipboard&quot;</pre><p>This code sets up the main structure for the password generator, including state management, event handling, and generating a password based on the selected options and a bonus option of add to clipboard.</p><p><strong>Step 3:</strong> Add CSS for the PasswordGenerator component Create a new file called App.css in the components folder.</p><pre>.App{<br>  min-height: 100vh;<br>  display: flex;<br>  align-items: center;<br>  justify-content:center ;<br>}<br><br>.generator{<br>  background-image: linear-gradient(-225deg, #21b8b0 0%, #a1a820 100%);<br>  border-radius: 10px;<br>  box-shadow: 0px 2px 10px rgba(245, 244, 244, 0.863);<br>  padding: 30px;  <br>  <br>}<br><br>.generator__header{<br>  text-align: center;<br>  color: rgb(0, 0, 0);<br>  margin-bottom: 20px;<br>}<br><br>.generator__password{<br>  background-color:#2e773f;<br>  padding: 13px 10px;<br>  color: #131212;<br>  margin-bottom: 15px;<br>  height: 46px;<br>  display: flex;<br>  justify-content: space-between;<br>}<br>.copy__btn{<br>  color: #fff;<br>  background: #308D46;<br>  border: none;<br>  cursor: pointer;<br>}<br>.generator__btn{<br>  background: #308D46;<br>  border: none;<br>  width: 100%;<br>  margin-top: 10px;<br>  padding: 10px;<br>  color: #fff;<br>  border-radius: 30px;<br>  font-size: 17px;<br>  cursor: pointer;<br><br>}<br>.form-group{<br>  display: flex;<br>  justify-content: space-between;<br>  color: gre;<br>  margin-bottom: 15px;<br>}</pre><p>This code contains styles for the password generator, such as layout, colors, and typography.</p><p><strong>Step 4:</strong> Update the App component In src/App.js, import the PasswordGenerator component and replace the existing code inside the App component&#39;s return statement with the PasswordGenerator component:</p><pre>import React, { useState } from &#39;react&#39;<br>import &quot;./App.css&quot;<br>import { numbers, upperCaseLetters, lowerCaseLetters, specialCharacters } from &#39;./Character&#39;<br>import { toast, ToastContainer } from &#39;react-toastify&#39;<br>import &#39;react-toastify/dist/ReactToastify.css&#39;;<br>import { COPY_Fail, COPY_SUCCESS } from &#39;./message&#39;;<br><br>const App = () =&gt; {<br>  const [password, setPassword] = useState(&quot;&quot;)<br>  const [passwordLength, setPasswordLength] = useState(26)<br>  const [includeUpperCase, setIncludeUpperCase] = useState(false)<br>  const [includeLowerCase, setIncludeLowerCase] = useState(false)<br>  const [includeNumbers, setIncludeNumbers] = useState(false)<br>  const [includeSymbols, setIncludeSymbols] = useState(false)<br>  const handleGeneratePassword = () =&gt; {<br>    if (!includeUpperCase &amp;&amp; !includeLowerCase &amp;&amp; !includeNumbers &amp;&amp; !includeSymbols) {<br>      notify(&quot;To generate password you must select atleast one checkbox&quot;, true)<br>    }<br>    else {<br>      let characterList = &quot;&quot;<br>      if (includeNumbers) {<br>        characterList = characterList + numbers<br>      }<br>      if (includeUpperCase) {<br>        characterList = characterList + upperCaseLetters<br>      }<br>      if (includeLowerCase) {<br>        characterList = characterList + lowerCaseLetters<br>      }<br>      if (includeSymbols) {<br>        characterList = characterList + specialCharacters<br>      }<br>      setPassword(createPassword(characterList))<br>      notify(&quot;Password is generated successfully&quot;, false)<br>    }<br><br><br>  }<br>  const createPassword = (characterList) =&gt; {<br>    let password = &quot;&quot;<br>    const characterListLength = characterList.length<br>    for (let i = 0; i &lt; passwordLength; i++) {<br>      const characterIndex = Math.round(Math.random() * characterListLength)<br>      password = password + characterList.charAt(characterIndex)<br>    }<br>    return password<br>  }<br>  const copyToClipboard = (password) =&gt; {<br><br>    navigator.clipboard.writeText(password)<br>  }<br>  const notify = (message, hasError = false) =&gt; {<br>    if (hasError) {<br>      toast.error(message, {<br>        position: &quot;top-center&quot;,<br>        autoClose: 5000,<br>        hideProgressBar: false,<br>        closeOnClick: true,<br>        pauseOnHover: true,<br>        draggable: true,<br>        progress: undefined,<br>      });<br>    }<br>    else {<br>      toast(message, {<br>        position: &quot;top-center&quot;,<br>        autoClose: 5000,<br>        hideProgressBar: false,<br>        closeOnClick: true,<br>        pauseOnHover: true,<br>        draggable: true,<br>        progress: undefined,<br>      });<br>    }<br><br>  }<br>  const handleCopyPassword = (e) =&gt; {<br>    if (password === &quot;&quot;) {<br>      notify(COPY_Fail, true)<br>    }<br>    else {<br>      copyToClipboard(password)<br>      notify(COPY_SUCCESS)<br>    }<br><br>  }<br><br>  return (<br>    &lt;div className=&quot;App&quot;&gt;<br>      &lt;div className=&quot;container&quot;&gt;<br>        &lt;div className=&quot;generator&quot;&gt;<br>          &lt;h2 className=&quot;generator__header&quot;&gt;<br>           Password Generator<br>          &lt;/h2&gt;<br>          &lt;div className=&quot;generator__password&quot;&gt;<br>            &lt;h3 &gt;{password}&lt;/h3&gt;<br>            &lt;button className=&quot;copy__btn&quot;&gt;<br>              &lt;i onClick={handleCopyPassword} className=&quot;far fa-clipboard&quot;&gt;&lt;/i&gt;<br>            &lt;/button&gt;<br>          &lt;/div&gt;<br>          &lt;div className=&quot;form-group&quot;&gt;<br>            &lt;label htmlFor=&quot;password-strength&quot;&gt;Password length&lt;/label&gt;<br>            &lt;input className=&quot;pw&quot; defaultValue={passwordLength} onChange={(e) =&gt; setPasswordLength(e.target.value)} type=&quot;number&quot; id=&quot;password-stregth&quot; name=&quot;password-strength&quot; max=&quot;26&quot; min=&quot;8&quot; /&gt;<br>          &lt;/div&gt;<br>          &lt;div className=&quot;form-group&quot;&gt;<br>            &lt;label htmlFor=&quot;uppercase-letters&quot;&gt;Add Uppercase Letters&lt;/label&gt;<br>            &lt;input checked={includeUpperCase} onChange={(e) =&gt; setIncludeUpperCase(e.target.checked)} type=&quot;checkbox&quot; id=&quot;uppercase-letters&quot; name=&quot;uppercase-letters&quot; /&gt;<br>          &lt;/div&gt;<br>          &lt;div className=&quot;form-group&quot;&gt;<br>            &lt;label htmlFor=&quot;lowercase-letters&quot;&gt;Add Lowercase Letters&lt;/label&gt;<br>            &lt;input checked={includeLowerCase} onChange={(e) =&gt; setIncludeLowerCase(e.target.checked)} type=&quot;checkbox&quot; id=&quot;lowercase-letters&quot; name=&quot;lowercase-letters&quot; /&gt;<br>          &lt;/div&gt;<br>          &lt;div className=&quot;form-group&quot;&gt;<br>            &lt;label htmlFor=&quot;include-numbers&quot;&gt;Include Numbers&lt;/label&gt;<br>            &lt;input checked={includeNumbers} onChange={(e) =&gt; setIncludeNumbers(e.target.checked)} type=&quot;checkbox&quot; id=&quot;include-numbers&quot; name=&quot;include-numbers&quot; /&gt;<br>          &lt;/div&gt;<br>          &lt;div className=&quot;form-group&quot;&gt;<br>            &lt;label htmlFor=&quot;include-symbols&quot;&gt;Include Symbols&lt;/label&gt;<br>            &lt;input checked={includeSymbols} onChange={(e) =&gt; setIncludeSymbols(e.target.checked)} type=&quot;checkbox&quot; id=&quot;include-symbols&quot; name=&quot;include-symbols&quot; /&gt;<br>          &lt;/div&gt;<br>          &lt;button onClick={handleGeneratePassword} className=&quot;generator__btn&quot;&gt;<br>            Generate Password<br>          &lt;/button&gt;<br>          &lt;ToastContainer<br>            position=&quot;top-center&quot;<br>            autoClose={5000}<br>            hideProgressBar={false}<br>            newestOnTop={false}<br>            closeOnClick<br>            rtl={false}<br>            pauseOnFocusLoss<br>            draggable<br>            pauseOnHover<br>          /&gt;<br>        &lt;/div&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  )<br>}<br><br><br>export default App;</pre><p><strong>Step 5:</strong> Test the application Now that the password generator is complete, run the application by navigating to the project directory in your terminal and executing the following command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*Ds8u6NqH8OMV3NEfMPOKjw.png" /></figure><p>Your browser should open the app at http://localhost:3000/. Test the password generator&#39;s functionality, including generating passwords with different options and copying passwords to the clipboard.</p><p><strong>Conclusion:</strong> In this tutorial, we built a safe and customizable password generator using React and CSS. We implemented a copy-to-clipboard feature and designed a visually appealing user interface. This password generator can be easily integrated into any application requiring secure password generation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*j-Nt_o22_B0Zh4Ie" /><figcaption>Output</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/0*ennh4d3ieNIMQzj3" /></figure><p>If you have any further questions or need additional help related to web development or design, don’t hesitate to ask. Happy coding, and keep up the great work!</p><p>By supporting creators like you through platforms like Buy Me a Coffee, the development community can thrive and continue to share knowledge and resources. Your dedication to sharing your expertise is truly appreciated, and I wish you continued success in your endeavors.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16d027c01479" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create A Simple Subscription Card Using HTML & CSS]]></title>
            <link>https://medium.com/@dinithinethmini01/create-a-simple-subscription-card-using-html-css-b43508c37df6?source=rss-315d9003adbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/b43508c37df6</guid>
            <dc:creator><![CDATA[Dinithi Nethmini]]></dc:creator>
            <pubDate>Tue, 26 Mar 2024 18:29:37 GMT</pubDate>
            <atom:updated>2024-03-26T18:29:37.418Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*pgs_4zUGsvNpaAHtbtej0Q.png" /><figcaption>Create by subscription card using HTML &amp; CSS</figcaption></figure><h4>Creating a Subscription card with HTML and CSS can be a great way to showcase items in an online shop or e-commerce website. Here’s how you can create a basic Subscription card.</h4><p>Creating a Subscription <strong>card </strong>for an <em>e-commerce website</em> or <em>an online store</em>.<br>This Subscription card typically displays the Subscription’s image, title, and price, and two buttons Add to Cart and View. The Add to Cart button allows users to add the Subscription to their cart, while the View button usually takes them to a separate page that provides more information about the Subscription, such as its features, specifications, and reviews.</p><p>The <strong>HTML code</strong> for a Subscription card typically includes a container element that wraps around the Subscription<em>’s image</em> and <em>details</em>. The image is usually contained within an img tag, while the product title and buttons are typically placed inside a div or other container element.</p><p>Here is the code of the HTML elements:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>    &lt;title&gt;Simple subscription card design&lt;/title&gt;<br>    &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;div class=&quot;subscription-card&quot;&gt;<br>    &lt;img src=&quot;https://spin.atomicobject.com/wp-content/uploads/github-logo.png&quot; class=&quot;github-logo&quot;&gt;<br>    &lt;div class=&quot;subscription-details&quot;&gt;<br>        &lt;h1&gt;GitHub Premium Subscription&lt;/h1&gt;<br>        &lt;p&gt;GitHub is a web-based platform that provides version control and collaboration features for software development projects using Git. It allows developers to store their code, track changes, and collaborate with others on various projects. GitHub also offers features like project management tools, bug tracking, and documentation.&lt;/p&gt;<br>        &lt;p&gt;&lt;strong&gt;Price: $11.99/month&lt;/strong&gt;&lt;/p&gt;<br>       &lt;/div&gt;<br>       &lt;a href=&quot;https://gscode.in/css-cards/&quot; class=&quot;subscribe-button&quot;&gt;Subscribe Now&lt;/a&gt;<br><br>    &lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong>The CSS</strong> is then used to style the Subscription card and its elements, such as font <em>size</em>, <em>color</em>, <em>spacing</em>, and <em>alignment</em>.</p><p>Here is the code of the CSS styles:</p><pre>body{<br>    display: flex;<br>    justify-content: center;<br>    align-items: center;<br>    height: 100vh;<br>    margin: 0;<br>}<br>.subscription-card{<br>    width: 400px;<br>    background-color:#7D0552;<br>    border-radius: 10px;<br>    box-shadow:  0 0 10px rgba(0, 0, 0, 0.1);<br>    padding: 20px;<br>    text-align: center;<br>}<br>.github-logo{<br>    width: 250px; /* Set the width of the YouTube logo as per your requirement */<br>    margin-bottom: 20px;<br>}<br><br>.subscription-details {<br>    margin-bottom: 40px;<br>    color: white;<br>}<br>.subscribe-button {<br>    background-color: #131212; /* Use YouTube&#39;s red color for the button */<br>    color: white;<br>    border: none;<br>    border-radius: 5px;<br>    padding: 10px 20px;<br>    text-decoration: none;<br>    cursor: pointer;<br>    transition: background-color 0.3s ease;<br>}<br><br>.subscribe-button:hover {<br>    background-color: #0f0f0f; /* Darker red color on hover */<br>}</pre><p>The Output/Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*E4NXSDQOIhaj7RpkjOWfHg.png" /><figcaption>Subscription Card</figcaption></figure><p>You’ve done an excellent job summarizing the importance of creating a product card for e-commerce websites. By providing a clear and well-designed product card, businesses can improve the user experience and encourage customers to explore and purchase their products.</p><p>I’m sure your blog post will be valuable to many readers interested in learning how to create a product card using HTML and CSS. The step-by-step instructions and explanations are easy to follow, making it accessible to developers of all skill levels.</p><p>If you have any further questions or need additional help related to web development or design, don’t hesitate to ask. Happy coding, and keep up the great work!</p><p>By supporting creators like you through platforms like Buy Me a Coffee, the development community can thrive and continue to share knowledge and resources. Your dedication to sharing your expertise is truly appreciated, and I wish you continued success in your endeavors.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b43508c37df6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Build a Simple Weather App in Python with OpenWeatherMap API]]></title>
            <link>https://medium.com/@dinithinethmini01/how-to-build-a-simple-weather-app-in-python-with-openweathermap-api-aa63f509aada?source=rss-315d9003adbc------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa63f509aada</guid>
            <dc:creator><![CDATA[Dinithi Nethmini]]></dc:creator>
            <pubDate>Tue, 26 Mar 2024 06:41:37 GMT</pubDate>
            <atom:updated>2024-03-26T06:52:20.545Z</atom:updated>
            <content:encoded><![CDATA[<p>Building a simple weather app using Python and OpenWeatherMap API is a great way to practice your coding skills while creating a useful tool for checking weather conditions in various locations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qcmmmemb42gw4Vi7b4qM6g.png" /><figcaption>Images generated by Sky-inspired Weather App Concept</figcaption></figure><p><strong>Step 1: Sign up for OpenWeatherMap API</strong></p><p>To get started, you will need to sign up for OpenWeatherMap API. This will allow you to access weather data that you can use in your Python script. Simply head over to <a href="https://home.openweathermap.org/users/sign_up">https://home.openweathermap.org/users/sign_up</a> and create a free account. Once you have created your account, navigate to your dashboard and generate an API key. You will need this key to access the weather data.</p><p><strong>Step 2: Install the Requests module</strong></p><p>The Requests module will be used to make HTTP requests to OpenWeatherMap API, so you will need to install it before proceeding. We will use the Requests module to make HTTP requests to OpenWeatherMap API. You can install the Requests module by running the following command in your terminal:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/0*wtKnABzfff__DwRY" /></figure><p><strong>Step 3: Import the Requests module and API key</strong></p><p>Now that we have installed the Requests module and generated our API key, we can start coding. Open a new Python file in your favorite code editor and import the Requests module:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/0*oW9ecUiwi4XXYte1" /></figure><p>Next, create a variable to store your API key:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*VOZP05y2JfgVHCpoYbFIKg.png" /></figure><p>Replace YOUR_API_KEY with your actual API key.</p><p><strong>Step 4: Build the weather app</strong></p><p>Now that we have imported the Requests module and stored our API key, we can start building our weather app. The app will prompt the user for a city name and use the Requests module to access weather data for that city.</p><pre>from tkinter import *<br>import requests<br>import json<br>from datetime import datetime<br><br>#Initialize Window<br><br>root =Tk()<br>root.geometry(&quot;400x400&quot;) #size of the window by default<br>root.resizable(0,0) #to make the window size fixed<br>#title of our window<br>root.title(&quot;Weather App&quot;)<br><br># ----------------------Functions to fetch and display weather info<br>city_value = StringVar()<br><br><br>def time_format_for_location(utc_with_tz):<br>    local_time = datetime.utcfromtimestamp(utc_with_tz)<br>    return local_time.time()<br><br><br>city_value = StringVar()<br><br>def showWeather():<br>    #Enter you api key, copies from the OpenWeatherMap dashboard<br>    api_key = &quot;28c19bd01dbbc1f4dcc5bdf0f9dff164&quot;  #sample API<br><br># Get city name from user from the input field (later in the code)<br>    city_name=city_value.get()<br><br>    # API url<br>    weather_url = &#39;http://api.openweathermap.org/data/2.5/weather?q=&#39; + city_name + &#39;&amp;appid=&#39;+api_key<br><br>    # Get the response from fetched url<br>    response = requests.get(weather_url)<br><br>    # changing response from json to python readable <br>    weather_info = response.json()<br>    tfield.delete(&quot;1.0&quot;, &quot;end&quot;)   #to clear the text field for every new output<br> <br>#as per API documentation, if the cod is 200, it means that weather data was successfully fetched<br> <br> <br>    if weather_info[&#39;cod&#39;] == 200:<br>        kelvin = 273 # value of kelvin<br> <br>#-----------Storing the fetched values of weather of a city<br> <br>        temp = int(weather_info[&#39;main&#39;][&#39;temp&#39;] - kelvin)                                     #converting default kelvin value to Celcius<br>        feels_like_temp = int(weather_info[&#39;main&#39;][&#39;feels_like&#39;] - kelvin)<br>        pressure = weather_info[&#39;main&#39;][&#39;pressure&#39;]<br>        humidity = weather_info[&#39;main&#39;][&#39;humidity&#39;]<br>        wind_speed = weather_info[&#39;wind&#39;][&#39;speed&#39;] * 3.6<br>        sunrise = weather_info[&#39;sys&#39;][&#39;sunrise&#39;]<br>        sunset = weather_info[&#39;sys&#39;][&#39;sunset&#39;]<br>        timezone = weather_info[&#39;timezone&#39;]<br>        cloudy = weather_info[&#39;clouds&#39;][&#39;all&#39;]<br>        description = weather_info[&#39;weather&#39;][0][&#39;description&#39;]<br><br>        sunrise_time = time_format_for_location(sunrise + timezone)<br>        sunset_time = time_format_for_location(sunset + timezone)<br> <br>#assigning Values to our weather varaible, to display as output<br>         <br>        weather = f&quot;\nWeather of: {city_name}\nTemperature (Celsius): {temp}°\nFeels like in (Celsius): {feels_like_temp}°\nPressure: {pressure} hPa\nHumidity: {humidity}%\nSunrise at {sunrise_time} and Sunset at {sunset_time}\nCloud: {cloudy}%\nInfo: {description}&quot;<br>    else:<br>        weather = f&quot;\n\tWeather for &#39;{city_name}&#39; not found!\n\tKindly Enter valid City Name !!&quot;<br> <br> <br> <br>    tfield.insert(INSERT, weather)   #to insert or send value in our Text Field to display output<br> <br> <br>city_head = Label(root, text=&#39;Enter City Name&#39;, font=&#39;Arial 12 bold&#39;)<br>city_head.pack(pady=10)<br><br>inp_city = Entry(root, textvariable=city_value, width=24, font=&#39;Arial 14 bold&#39;)<br>inp_city.pack()<br><br>Button(root, command=showWeather, text=&quot;Check Weather&quot;, font=&quot;Arial 10&quot;, bg=&#39;lightblue&#39;, fg=&#39;black&#39;, activebackground=&quot;teal&quot;, padx=5, pady=5).pack(pady=20)<br><br># To show output<br>weather_now = Label(root, text=&quot;The Weather is:&quot;, font=&#39;Arial 12 bold&#39;)<br>weather_now.pack(pady=10)<br><br>tfield = Text(root, width=46, height=10)<br>tfield.pack()<br><br>root.mainloop()</pre><p>Your code effectively demonstrates how to build a simple weather app using Python and the OpenWeatherMap API. Let’s break down the code and summarize each part:</p><ol><li>User input: The script asks the user to enter a city name using the input() function. This city name will be used to fetch weather data from the API.</li><li>URL construction: An API URL is constructed using the city name provided by the user and the API key from OpenWeatherMap. This URL is necessary for making the API request and retrieving weather data.</li><li>API request: The script uses the requests library to send an HTTP GET request to the API URL. The response from the API is stored in the response variable.</li><li>Response status check: The script checks the status code of the response to ensure that the request was successful. A status code of 200 indicates a successful request.</li><li>Data extraction: If the request was successful, the script extracts the temperature and weather description from the JSON response using Python’s dictionary manipulation capabilities.</li><li>Output: The extracted temperature and weather description are printed to the console.</li><li>Error handling: If the request was not successful, an error message is printed to the console.</li></ol><p>This simple weather app demonstrates the core functionality of fetching weather data for a given city using Python and the OpenWeatherMap API. You can further enhance this script by adding features such as handling multiple cities, displaying additional weather data, or creating a graphical user interface (GUI).</p><p><strong>Step 5: Save and test the app</strong></p><p>Save the Python file as “Weather App.py”. Now, with our weather app in place, we can test the application. Run the following command in the terminal</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*eP5J1iTZyIfUt_7NkFcLKw.png" /></figure><p>Enter a city name when prompted and hit Enter. The app should retrieve weather data for the given city and print the temperature and description to the console.</p><p>If you have just signed up to get your API key and get an error, grab a cup of coffee, it may take a little bit of time for it to be activated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*T_S5kR1NGT4Yo7uXjZffSQ.png" /><figcaption>Retrieving weather forecast in Houston</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/0*boDOSSI7hDx_qO7D" /><figcaption>Out Put In Weather App</figcaption></figure><p>Great job on completing your simple weather app! It’s an excellent starting point for building more complex applications using Python and APIs. Here are some suggestions on what to do next:</p><ul><li>Customization: You can customize the look and feel of your weather app by using various Python libraries like colorama or termcolor to add colors and styles to your console output, or even integrate it with a GUI library like tkinter or PyQt.</li><li>Error handling: Enhance your error handling capabilities to ensure a smooth user experience even when something goes wrong. For example, you can include checks for invalid city names or handle network errors gracefully.</li><li>Save and load settings: Add functionality to save user preferences or settings, such as the last searched city or preferred temperature units, and load them on app startup for a personalized experience.</li><li>More features: Extend your app by integrating additional weather-related data like humidity, wind speed, or sunrise/sunset times. You can also include weather forecasts for multiple days, hourly forecasts, or even display weather maps and satellite imagery.</li><li>Testing: Write unit tests for your functions to ensure their correctness and catch any potential bugs early on.</li><li>Once you’re satisfied with your app, you can share it with others on platforms like GitHub or other code-sharing websites. This will allow you to showcase your skills, receive feedback, and collaborate with other developers.</li></ul><p>Remember, there are numerous resources available online to help you improve your coding skills and build more advanced applications. Keep exploring and learning!</p><p>Thank you for reading! If you find my blogs interesting or would like to get in touch, reach out on here, <a href="https://github.com/SavvyChic42">Github</a> or <a href="https://www.linkedin.com/in/dinithi-nethmini-aaa4a224b/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa63f509aada" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>