<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Aishwarya Mali</title>
    <description>The latest articles on Forem by Aishwarya Mali (@aishwaryamali24).</description>
    <link>https://forem.com/aishwaryamali24</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F278798%2F2bb073a7-ec6f-4b19-9364-4dbc06312ec4.jpg</url>
      <title>Forem: Aishwarya Mali</title>
      <link>https://forem.com/aishwaryamali24</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/aishwaryamali24"/>
    <language>en</language>
    <item>
      <title>#JavaScriptmas 2023 Day 19 to 24</title>
      <dc:creator>Aishwarya Mali</dc:creator>
      <pubDate>Sun, 24 Dec 2023 10:28:24 +0000</pubDate>
      <link>https://forem.com/aishwaryamali24/javascriptmas-2023-day-19-to-24-183</link>
      <guid>https://forem.com/aishwaryamali24/javascriptmas-2023-day-19-to-24-183</guid>
      <description>&lt;p&gt;Welcome back! If you've been following along, we've already solved challenges of Days 1 to 18 in our journey. Now, buckle up as we dive into the last leg of this adventure of Days 19 to 24. &lt;/p&gt;

&lt;h2&gt;
  
  
  Day 19: Debug Jingle Words
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;There are loads of problems in JS. Find them, and fix them!
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function handleGuess(e) {
    e.preventDefault()
    let currentState = []
    let input = document.getElementById('user-input')
    let guess = input.value
    const guessArr = guess.split('')
    for (let i = 0; i &amp;lt; wordArr.length; i++) {
        if (guessArr[i] === wordArr[i]) {
            currentState.push(guessArr[i])
        } else {
            currentState.push("-")
        }
    }
    renderGuess(currentState)
    checkWin(guess)
    input.value = ''
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The problems causing the errors were:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;id&lt;/code&gt; of the input was incorrect. &lt;/li&gt;
&lt;li&gt;Instead of using &lt;code&gt;guess.split(' ')&lt;/code&gt;, it was necessary to use &lt;code&gt;guess.split('')&lt;/code&gt; to split the string into individual letters.&lt;/li&gt;
&lt;li&gt;Implemented a &lt;code&gt;for&lt;/code&gt; loop to iterate through each letter of both the &lt;code&gt;guess&lt;/code&gt; and &lt;code&gt;wordArr&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Finally, when a letter is matched, it is pushed; otherwise, ('-') is pushed.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function renderGuess(arr) {
    const wordHtml = arr.map((letter) =&amp;gt; {
        let html = ""
        if (letter === "-") {
            html += `&amp;lt;span class="letter wrong"&amp;gt;-&amp;lt;/span&amp;gt;`
        } else {
            html += `&amp;lt;span class="letter correct"&amp;gt;${letter}&amp;lt;/span&amp;gt;`
        }
        return html
    })
    wordDisplay.innerHTML = wordHtml.join('')
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PH8UBEo_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7azh8k6e736rg9nf39br.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PH8UBEo_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7azh8k6e736rg9nf39br.png" alt="Visual clue indicating whether entered letter is correct" width="450" height="493"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have also updated the &lt;code&gt;renderGuess&lt;/code&gt; function to provide users with a visual clue indicating whether the letter is correct or not.&lt;/p&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/co70545a58b1263c02719f922"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 20: Save Santa!
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Save Santa by removing the lions, tigers, bears, and other nefarious creatures from the deeply-nested array. Following is the input.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const dangerArray = [
    ["🎅", "👺"],
    [
        ["🎅", "🦁"],
        ["👹", "🎅"]
    ],
    [
        [
            ["🎅", "🐻"],
            ["🧌", "🎅"]
        ],
        [
            ["🐯", "🎅"],
            ["🎅", "😈"]
        ]
    ]
];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function saveSanta(arr) {
    for(let i=0; i&amp;lt;arr.length; i++ ){
        if(Array.isArray(arr[i])){
            saveSanta(arr[i])
        }
        else{
            if(arr[i]!=="🎅"){
                arr.splice(i, 1)
            }
        }
    }
    return arr
}

console.log(saveSanta(dangerArray))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;First we iterate over the array and check if each item is an array. &lt;/li&gt;
&lt;li&gt;If it is, a recursive call to the current function is made.&lt;/li&gt;
&lt;li&gt;Otherwise, we check if the item is not Santa. &lt;/li&gt;
&lt;li&gt;If it isn't, the item is sliced from the array.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/co9c247d5b0d9dfac4d45c761"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 21: Expanding Search Bar
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;﻿Search input: Takes upto 1/3 of the width of its container&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When the user clicks into the search bar:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input grows to entire width of its parent container with smooth transition&lt;/li&gt;
&lt;li&gt;Shrinks back to original size when user clicks away&lt;/li&gt;
&lt;li&gt;Blue border&lt;/li&gt;
&lt;li&gt;Bonus: placeholder text is not visible when user clicks inside the search bar
&lt;/li&gt;
&lt;/ul&gt;


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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container"&amp;gt;
  &amp;lt;label for="search-field" class="visually-hidden"&amp;gt;Search&amp;lt;/label&amp;gt;
  &amp;lt;input type="search" 
    class="search-bar" 
    id="search-field"
    placeholder="Search..."/&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;html, body {
    margin: 0;
    padding: 0;
}

:root {
    --search-border: #bbb;
    --search-focus-border: #3a71ca;
}

.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0,0,0,0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.container{
    width: 80%;
    margin: 30px auto 0;
}

.search-bar{
    border: 1px solid var(--search-border);
    border-radius: 4px;
    padding: 8px;
    width: 30%;
    transition: width .2s linear;
}

.search-bar:focus{
    width: 100%;
    border-color: var(--search-focus-border);
}

.search-bar:focus::-webkit-input-placeholder {
    opacity: 0;
}

.search-bar:focus::-moz-placeholder {
   opacity: 0;
}

.search-bar:focus:-ms-input-placeholder {
    opacity: 0;
}

.search-bar:focus:-moz-placeholder {
   opacity: 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The trick here is that we initially set the width of &lt;code&gt;.search-bar&lt;/code&gt; to 30% of its parent container. When clicked, we utilize the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/:focus"&gt;&lt;code&gt;:focus&lt;/code&gt;&lt;/a&gt; selector to dynamically adjust the width to 100%, employing a transition effect for a smooth visual transition. To hide the placeholder text, browser-specific placeholder selectors are used, and a style of opacity: 0; is applied.&lt;/p&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/co81d445fbf3ef31a77f0abb9"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 22: Gift App
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Make it so that the data doesn't disappear on reload.
Use localStorage.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let people = JSON.parse(localStorage.getItem("people")) || []

if(people) renderList(people)

addButtonEl.addEventListener("click", function() {
    let inputValue = inputFieldEl.value

    if (inputValue) {
        people.push(inputValue)
        localStorage.setItem("people", JSON.stringify(people))
        clearInputFieldEl()

        renderList(people)
    }
})

function appendPersonToPeopleListEl(person) {

    let newEl = document.createElement("li")

    newEl.textContent = person

    newEl.addEventListener("dblclick", function() {
        let index = people.indexOf(person)

        people.splice(index, 1)
        localStorage.setItem("people", JSON.stringify(people))
        img.src = "./images/gifts.webp"
        renderList(people)
    })

    peopleListEl.append(newEl)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;When a new person is added to our Gift App list, we use &lt;code&gt;localStorage.setItem("people", JSON.stringify(people))&lt;/code&gt; to store the people array with the key named "people" in &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage"&gt;localStorage&lt;/a&gt;. The &lt;code&gt;stringify&lt;/code&gt; function is used to convert a JavaScript object (in this case, the people array) into a JSON-formatted string.&lt;/li&gt;
&lt;li&gt;The object is similarly updated when a person is removed from the list. &lt;/li&gt;
&lt;li&gt;Lastly, to retrieve the data, we use &lt;code&gt;JSON.parse(localStorage.getItem("people"))&lt;/code&gt;. The &lt;code&gt;parse&lt;/code&gt; function is used to convert a JSON-formatted string back into a JavaScript object.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/co4ea45a2b8f5546ebc12717f"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 23: Toggle Switch
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;On click, toggle switch moves from one side to another&lt;/li&gt;
&lt;li&gt;Cursor becomes pointer&lt;/li&gt;
&lt;li&gt;Match styles&lt;/li&gt;
&lt;li&gt;No JavaScript
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="toggle-wrap"&amp;gt;
  &amp;lt;label for="toggle"&amp;gt;
    &amp;lt;input type="checkbox" id="toggle" class="toggle-input"&amp;gt;&amp;lt;/input&amp;gt;
    &amp;lt;div class="toggle-switch"&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;/label&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#toggle{
    display: none;
}

.toggle-wrap{
    width: 80px;
    height: 40px;
    border: 2px solid var(--toggle-border);
    border-radius: 100px;
    background: var(--toggle-bg);
    display: flex;
    align-items: center;
}

label{
    width: 100%;
    cursor: pointer;
}

.toggle-switch{
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--toggle-switch-bg);
    transition: transform 0.2s linear;
    backface-visibility: hidden;
}

.toggle-input:checked + .toggle-switch{
    transform: translateX(45px);
}

.toggle-input:not(:checked) + .toggle-switch{
    transform: translateX(5px); 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Here, we hide the actual checkbox, but since we use the &lt;code&gt;id&lt;/code&gt; and &lt;code&gt;for&lt;/code&gt; attributes in both the label and input, we can determine whether it is checked or not. &lt;/li&gt;
&lt;li&gt;We utilize the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/:checked"&gt;&lt;code&gt;:checked&lt;/code&gt;&lt;/a&gt; selector and a combination selector to shift the slide to the right side. &lt;/li&gt;
&lt;li&gt;To check if it is unchecked, we use &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/:not"&gt;&lt;code&gt;:not()&lt;/code&gt;&lt;/a&gt; selector in combination with &lt;code&gt;:checked&lt;/code&gt; and translate the position to its initial state.&lt;/li&gt;
&lt;li&gt;The transition property is used to ensure a smooth animation. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/coe01435a9119cabdcf26708d"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 24: Christmas Lights
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Make Christmas tree lights flash on and off every 800 milliseconds on a permanent loop.&lt;/li&gt;
&lt;li&gt;Make the blue and red lights toggle on and off alternatively. So first the red lights come on, and then as they go off, the blue lights come on.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const blues = document.querySelectorAll('.blue');
const reds = document.querySelectorAll('.red');
let isRed = true;

function toggleLights() {
    if (isRed) {
        reds.forEach(redLight =&amp;gt; {
            redLight.classList.add("lights-on");
        });
        blues.forEach(blueLight =&amp;gt; {
            blueLight.classList.remove("lights-on");
        });
    } else {
        blues.forEach(blueLight =&amp;gt; {
            blueLight.classList.add("lights-on");
        });
        reds.forEach(redLight =&amp;gt; {
            redLight.classList.remove("lights-on");
        });
    }
    isRed = !isRed;
}

setInterval(toggleLights, 800);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We use &lt;code&gt;setInterval(toggleLights, 800);&lt;/code&gt; to call the &lt;code&gt;toggleLights&lt;/code&gt; function every 800 milliseconds. &lt;/li&gt;
&lt;li&gt;In the function, we check if &lt;code&gt;isRed&lt;/code&gt; is true. If it is, we &lt;em&gt;add the &lt;code&gt;lights-on&lt;/code&gt; class to the red lights&lt;/em&gt; and &lt;em&gt;remove it from the blue lights&lt;/em&gt;. &lt;/li&gt;
&lt;li&gt;Otherwise, we &lt;em&gt;add the &lt;code&gt;lights-on&lt;/code&gt; class to the blue lights&lt;/em&gt; and &lt;em&gt;remove it from the red lights&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/co04e4759b8878fe0a1eb5c1a"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As we finish up the 24-day coding adventure of #JavaScriptmas, I can't help but smile thinking about how much fun it brought to my daily routine. Solving a new challenge each day became something I looked forward to, keeping me consistent and excited.&lt;/p&gt;

&lt;p&gt;I want to say a big thank you to everyone who followed along and joined me in this coding journey. Your support and enthusiasm made it even better!&lt;/p&gt;

&lt;p&gt;Thanks for being a part of it. Until next time, happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>scrimba</category>
      <category>javascript</category>
      <category>javascriptmas</category>
    </item>
    <item>
      <title>#JavaScriptmas 2023 Day 13 to 18</title>
      <dc:creator>Aishwarya Mali</dc:creator>
      <pubDate>Tue, 19 Dec 2023 14:08:42 +0000</pubDate>
      <link>https://forem.com/aishwaryamali24/javascriptmas-2023-day-13-to-18-5f88</link>
      <guid>https://forem.com/aishwaryamali24/javascriptmas-2023-day-13-to-18-5f88</guid>
      <description>&lt;p&gt;Welcome back! If you've been following along, we've already solved challenges of Days 1 to 12 in our journey. Now, buckle up as we dive into the next leg of this adventure Days 13 to 18. Let's start.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 13: Christmas Dinner Picker
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Write the code to help a user choose the perfect Christmas dinner idea based on the number of people attending.&lt;/li&gt;
&lt;li&gt;Include a checkbox for the user to specify the meal should be vegetarian-friendly.&lt;/li&gt;
&lt;li&gt;Dinner suggestions (or choose your own!):
Vegetarian: Winter Squash Risotto
4 people or less: Ham
5+ people: Turkey
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const numOfGuests = document.getElementById('guests')
const btnCalculate = document.getElementById('btn')
const isVegetarian = document.getElementById('vegetarian-input')

const dinnerOption = document.getElementById('food')

btnCalculate.addEventListener('click', function(){
    const guests = +numOfGuests.value
    if(isVegetarian.checked){
        dinnerOption.textContent = 'Winter Squash Risotto'
    } else{
        dinnerOption.textContent = guests &amp;lt;= 4 ? 'Ham' : 'Turkey'
    }
    numOfGuests.value = ''
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;When the 'Calculate' button is first pressed, we retrieve the number of guests. Adding &lt;code&gt;+&lt;/code&gt; is a trick to convert string to a number.&lt;/li&gt;
&lt;li&gt;If the 'Vegetarian?' checkbox is checked, the dinner option appended to the UI is 'Winter Squash Risotto'. &lt;/li&gt;
&lt;li&gt;Otherwise, we check if the number of guests is less than or equal to 4.&lt;/li&gt;
&lt;li&gt;If it is, 'Ham' is chosen; otherwise, 'Turkey' is chosen and then appended to the UI.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/co99a4cc29690e76f1b6a8b70"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 14: Lonely elf
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Write a function to duplicate the elf when the button is clicked.&lt;/li&gt;
&lt;li&gt;Limit the number of elves to 6 per row.&lt;/li&gt;
&lt;li&gt;Make sure that the elves stay in the elf hangout zone, no matter how many there are.&lt;/li&gt;
&lt;li&gt;Limit the total number of elves to 100.
&lt;/li&gt;
&lt;/ul&gt;

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

btn.addEventListener("click", duplicateElf)

function duplicateElf(){
    if(elfCount === 2) elfHeader.innerText = 'Elves'
    if(elfCount &amp;lt;= 100){
        elf.textContent += '🧝'
        elfCount += 1
    }else{
        const enoughElves = document.getElementById('more-elfs')
        enoughElves.style.display = "block"
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;When the 'Duplicate elf' button is pressed, we first change the title to 'Elves'.&lt;/li&gt;
&lt;li&gt;Next, we check if &lt;code&gt;elfCount&lt;/code&gt; is less than or equal to 100.&lt;/li&gt;
&lt;li&gt;If it is, we append one more elf to the UI and increase the count of &lt;code&gt;elfCount&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Otherwise, we append 'No more elves can be added' to UI.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/cof334413b93d4719de8068e8"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 15: Archery Target
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create CSS only archery target&lt;/li&gt;
&lt;/ul&gt;

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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="rings"&amp;gt;
 &amp;lt;div class="ring ring-1"&amp;gt;
  &amp;lt;div class="ring ring-2"&amp;gt;
   &amp;lt;div class="ring ring-3"&amp;gt;
    &amp;lt;div class="ring bullseye"&amp;gt;&amp;lt;/div&amp;gt;
   &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
 &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.rings{
    position: relative;
}

.ring{
    border-radius: 50%;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%)
}

.ring-1{
    width: 300px;
    height: 300px;
    background: var(--black);
}

.ring-2{
    width: 220px;
    height: 220px;
    background: var(--blue);
}

.ring-3{
   width: 140px;
   height: 140px;
   background: var(--red); 
}

.bullseye{
   width: 60px;
   height: 60px;
   background: var(--yellow); 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The main &lt;code&gt;.rings div&lt;/code&gt; is set to &lt;code&gt;position: relative;&lt;/code&gt; so that the other rings can overlay it.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The above CSS is to ensure the circles are always centered.&lt;/li&gt;
&lt;li&gt;Subsequently, for each ring, we decrease the width and height by &lt;code&gt;80px&lt;/code&gt;, ensuring the circle remains perfectly sized, and apply the background color.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/coae0471dbb0491ac451efc33"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 16: Naughty list, nice list
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Write the JavaScript to sort the people in sorteesArr into the naughty and nice lists, according to whether they have been good or not. Then display the names in the relevant place in the DOM.&lt;/li&gt;
&lt;li&gt;Add the option to add new names to the sorteesArr.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;btn.addEventListener("click", function(){
    for(let i=0; i&amp;lt;sorteesArr.length; i++){
        sort(sorteesArr[i])
    }
})

addPerson.addEventListener('click', function(){
    const newPerson = {
        name: newName.value,
        hasBeenGood: isGood.checked
    }
    sorteesArr.push(newPerson)
    sort(newPerson)
    newName.value = ''
    isGood.checked = false
})

function sort(person){
    if(person.hasBeenGood){
        nice += `&amp;lt;li&amp;gt;${person.name}&amp;lt;/li&amp;gt;`
    }else{
        naughty += `&amp;lt;li&amp;gt;${person.name}&amp;lt;/li&amp;gt;`
    }
    niceList.innerHTML = nice
    naughtyList.innerHTML = naughty
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;First, we call the &lt;code&gt;sort()&lt;/code&gt; function for the length of the &lt;code&gt;sorteesArr&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Within the function, we check if the person 'has been good?'. &lt;/li&gt;
&lt;li&gt;If yes, we create a string of &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt; elements and add it to the &lt;code&gt;niceList&lt;/code&gt;. Otherwise, we add it to the &lt;code&gt;naughtyList&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;When 'Add person' is pressed, we create a &lt;code&gt;newPerson&lt;/code&gt; object and push it to &lt;code&gt;sorteesArr&lt;/code&gt;, followed by a call to the &lt;code&gt;sort()&lt;/code&gt; function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/coc084ae7bde3212222c079f2"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 17: Word Carousel
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create a CSS only Word Carousel.&lt;/li&gt;
&lt;li&gt;Match styles and display 4 things you love.&lt;/li&gt;
&lt;/ul&gt;

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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="container"&amp;gt;
 &amp;lt;h1&amp;gt;I love&amp;lt;/h1&amp;gt;
&amp;lt;div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;body{
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

h1::after {
  content: "";
  animation: carousel 5s steps(1) infinite;
  background: var(--bg-word);
  color: #fff;
  margin-left: 2px;
  padding: 8px 10px;
  border-radius: 4px;
}

@keyframes carousel {
  0% {
    content: "reading";
  }
  45% {
    content: "Scrimba";
  }
  65% {
    content: "coding";
  }
  85% {
      content: "music";
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We first center the &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; tag by applying styles to &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;For the carousel part, we apply styles to the &lt;code&gt;::after&lt;/code&gt; selector.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;animation: carousel 5s steps(1) infinite;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The animation is named 'carousel' with a duration of 5s. &lt;/li&gt;
&lt;li&gt;The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/animation-timing-function"&gt;&lt;code&gt;steps()&lt;/code&gt;&lt;/a&gt; function is set to 1, which means the animation will move in discrete steps rather than smoothly transitioning.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;infinite&lt;/code&gt; value is used to make the animation repeat indefinitely.&lt;/li&gt;
&lt;li&gt;Keyframes are added to specify the content to be displayed at different percentages.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/co04943ee894499f9b7686595"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 18: AI Alt Text Generator
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use AI to generate alt text for the image provided by generateImage().&lt;/li&gt;
&lt;li&gt;Pass the alt text to renderImage() as a parameter.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function generateAltText(blob, imageUrl) {
    const altText = await hf.imageToText({
        data: blob,
        model: "nlpconnect/vit-gpt2-image-captioning",
    })
    renderImage(imageUrl, altText.generated_text) 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;I used &lt;a href="https://huggingface.co/"&gt;huggingface&lt;/a&gt; for this challenge. You can find the documentation &lt;a href="https://huggingface.co/docs/huggingface.js/inference/README"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;hf.imageToText&lt;/code&gt; is a function from the Hugging Face library for generating text from a provided image.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;data&lt;/code&gt; passed to it is in the form of a blob, and the &lt;code&gt;model&lt;/code&gt; parameter represents the specific model used for image-to-text generation.&lt;/li&gt;
&lt;li&gt;In summary, this code requests a model from Hugging Face to generate alt text for an image based on the provided blob. The resulting alt text is then passed to the &lt;code&gt;renderImage()&lt;/code&gt; function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/co76b4faa8a174db83e29b513"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Would love to hear your thoughts on this. Can't believe it has been 18 days already. Stay tuned for the last iteration of this series.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>scrimba</category>
      <category>javascript</category>
      <category>javascriptmas</category>
    </item>
    <item>
      <title>#JavaScriptmas 2023 Day 7 to 12</title>
      <dc:creator>Aishwarya Mali</dc:creator>
      <pubDate>Wed, 13 Dec 2023 12:50:31 +0000</pubDate>
      <link>https://forem.com/aishwaryamali24/javascriptmas-2023-day-7-to-12-33kg</link>
      <guid>https://forem.com/aishwaryamali24/javascriptmas-2023-day-7-to-12-33kg</guid>
      <description>&lt;p&gt;Welcome back! If you've been following along, we've already solved challenges of &lt;a href="https://dev.to/aishwaryamali24/javascriptmas-2023-day-1-6-3m15"&gt;Days 1 to 6&lt;/a&gt; in our journey. Now, buckle up as we dive headfirst into the next leg of this adventure Days 7 to 12. Let's start.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 7: Xmas Present wishlist
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Add items to wishlist array.&lt;/li&gt;
&lt;li&gt;Iterate over the wishlist array.&lt;/li&gt;
&lt;li&gt;Display your wishlist on the page.&lt;/li&gt;
&lt;li&gt;Style the wishlist with CSS.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Stretch Goals
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Provide a way to add / remove wishlist items.&lt;/li&gt;
&lt;li&gt;Make each array an object with item's name, description, and a link to where it can be purchased
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const wishlist = [
  {
      name: "Books",
      description: "I love to read so need more books!",
      link: "https://www.amazon.in/"
  },
  {
      name: "Headphone",
      description: "Nirvanaa 751 ANC Wireless Headphone",
      link: "https://www.boat-lifestyle.com/products/nirvana-751-anc-headphone"
  }
];

function renderList(list){
    let listEl = ""
    list.map((list, index) =&amp;gt;{
        listEl += `
        &amp;lt;div class='wishlist-box'&amp;gt;
            &amp;lt;div&amp;gt;
                &amp;lt;h2&amp;gt;&amp;lt;a href='${list.link}' target='_blank'&amp;gt;${list.name}&amp;lt;/a&amp;gt;&amp;lt;/h2&amp;gt;
                &amp;lt;p&amp;gt;${list.description}&amp;lt;/p&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div class="delete" onclick="deleteWish(${index})"&amp;gt;❌&amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
        `
    })
    wishlistEl.innerHTML = listEl
}

renderList(wishlist)

addWishBtn.addEventListener('click', function(){
    if(!wishNameInput.value || !wishDescriptionInput.value || !wishLinkInput.value) return
    const newWish = {
        name: wishNameInput.value,
        description: wishDescriptionInput.value,
        link: wishLinkInput.value
    }
    wishlist.push(newWish)
    renderList(wishlist)
    wishNameInput.value = wishDescriptionInput.value = wishLinkInput.value = ""
})

function deleteWish(index){
    wishlist.splice(index, 1)
    renderList(wishlist)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;First, created an array of objects called &lt;code&gt;wishlist&lt;/code&gt; and rendered this object using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map" rel="noopener noreferrer"&gt;&lt;code&gt;map()&lt;/code&gt;&lt;/a&gt; method on the UI.&lt;/li&gt;
&lt;li&gt;For the &lt;code&gt;Add Wish&lt;/code&gt; button, first checked if there is a value in the inputs. If not, the process is terminated. If there is a value, added all the values to a new object and pushed this object to the &lt;code&gt;wishlist&lt;/code&gt; array. Finally, cleared all the inputs.&lt;/li&gt;
&lt;li&gt;Lastly, for &lt;code&gt;deleteWish&lt;/code&gt;, get the index of the item we wished to delete. Based on that index, use the splice method to remove that item from the array and update the UI.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/cod2a468aa65a80482fb066c7" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 8: Animated Progress Bar
&lt;/h2&gt;

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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="progress-bar"&amp;gt;
  &amp;lt;div class="progress-status"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.progress-bar,
.progress-status {
  height: 30px;
  background: var(--progressbar-bg);
  border-radius: 50px;
  width: 100%;
}

.progress-bar {
  position: relative;
}

.progress-status {
  position: absolute;
  top: 0;
  animation: progress 5s infinite;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
}

@keyframes progress {
  0% {
    width: 0%;
    background-color: var(--start);
  }
  50% {
    width: 50%;
    background-color: var(--middle);
  }
  100% {
    width: 100%;
    background-color: var(--finish);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;First, positioned the &lt;code&gt;progress-status&lt;/code&gt; div on the &lt;code&gt;progress-bar&lt;/code&gt; using &lt;code&gt;position:absolute&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;For the &lt;code&gt;progress-status&lt;/code&gt;, applied animation: progress 5s infinite; to call the keyframe "progress" infinitely.&lt;/li&gt;
&lt;li&gt;In the keyframe, defined animations starting at 0%, reaching 50%, and finishing at 100%.&lt;/li&gt;
&lt;li&gt;To ensure smooth operation, used &lt;code&gt;animation-timing-function: linear&lt;/code&gt;. Without this, the progress bar starts correctly but then slows down at 50% and restarts again after that.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/coa414b5ebf7a881548916750" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 9: AI Christmas E-card
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;When a user hits submit, dialogModal should be hidden.&lt;/li&gt;
&lt;li&gt;Use the inputted text to generate an image for the e-card using an AI model. &lt;/li&gt;
&lt;li&gt;Render the image to imageContainer.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;formSubmit.addEventListener('submit', function(e){
    e.preventDefault()
    dialogModal.close();
    image.style.display = "none"
    loadingText.style.display = "block"
    if(!userInput.value) return

    query({"inputs": userInput.value}).then(async(response) =&amp;gt; {
        const src = await blobToBase64(response)
        loadingText.style.display = "none"
        image.src = src
        image.style.display = "block"
    });

})

async function query(data) {
    const response = await fetch(
        "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0",
        {
            headers: { Authorization: `Bearer ${process.env.HUGGING_FACE_API_KEY}` },
            method: "POST",
            body: JSON.stringify(data),
        }
    );
    const result = await response.blob();
    return result;
}


function blobToBase64(blob) {
    return new Promise((resolve, reject) =&amp;gt; {
        const reader = new FileReader();
        reader.onload = function () {
            const base64String = reader.result;
            resolve(base64String);
        };
        reader.onerror = function (error) {
            reject(error);
        };
        reader.readAsDataURL(blob);
    });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;I used &lt;a href="https://huggingface.co/" rel="noopener noreferrer"&gt;huggingface&lt;/a&gt; for this challenge. You can find the documentation &lt;a href="https://huggingface.co/docs/huggingface.js/inference/README" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;When the form is submitted we use the given description as input to call the function that will return a blob of image. This blob is then converted to Base64 using the &lt;code&gt;blobToBase64&lt;/code&gt; function.&lt;/li&gt;
&lt;li&gt;The function uses the &lt;code&gt;FileReader&lt;/code&gt; object, which is part of the web platform's File API, to read the contents of the Blob.&lt;/li&gt;
&lt;li&gt;It sets up an onload event handler, which will be triggered when the reading operation is successfully completed.&lt;/li&gt;
&lt;li&gt;Inside the onload handler, it converts the read content to a Base64-encoded string and resolves the Promise with that string.&lt;/li&gt;
&lt;li&gt;If there is an error during the reading operation, the onerror event handler is triggered, and the Promise is rejected with the error.&lt;/li&gt;
&lt;li&gt;Finally, we append this image to UI.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/co86a468cbb3a7184411c7859" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 10: Rockin' Around
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Add code to make the youtube player play the new YouTube song
&lt;/li&gt;
&lt;/ul&gt;

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

function playSong(id) {
  const youtubeSrc = `https://www.youtube.com/embed/${id}?autoplay=1`
  player.src = youtubeSrc
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The code creates a URL for a YouTube video using a template literal. It takes a video ID and constructs a YouTube video URL with the format.&lt;/li&gt;
&lt;li&gt;At the end, assigned this URL to the player's src.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/co3dc4558bb56f2ead0d5b196" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 11: Flag Challenge
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create Switzerland Flag in CSS&lt;/li&gt;
&lt;/ul&gt;

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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="flag flag-swiss"&amp;gt;
 &amp;lt;div class="cross cross1"&amp;gt;&amp;lt;/div&amp;gt;
 &amp;lt;div class="cross cross2"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.flag{
    width: 300px;
    height: 300px;
    background: var(--red);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
}

.cross{
    background: var(--white);
}

.cross1{
    grid-row: 2/5;
    grid-column: 3/4;
}

.cross2{
    grid-row: 3/4;
    grid-column: 2/5;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;I used &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_grid_layout" rel="noopener noreferrer"&gt;&lt;code&gt;grid&lt;/code&gt;&lt;/a&gt;` for this challenge, defining the height and width of the div and setting its display property to grid.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;The grid is defined with 5 rows and 5 columns, each set to  &lt;code&gt;1fr&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Based on the image above, I have positioned &lt;code&gt;.cross1&lt;/code&gt;, &lt;code&gt;.cross2&lt;/code&gt; accordingly using &lt;code&gt;grid-row&lt;/code&gt; and &lt;code&gt;grid-column&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/co5ed47048aef825733374126" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 12: Santa's Gift Sorter
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Help santa by sorting the gifts array into alphabetical order and reverse alphabetical order.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const xmasGifts = ['guitar 🎸', 'skates ⛸️', 'bear 🧸', 'magnet 🧲', 'laptop 💻', 'games console 🎮', 'jewellery 💍', 'kite 🪁'];

const sortedAZ = [...xmasGifts].sort();
console.log('A-Z: ', sortedAZ);

const sortedZA = [...xmasGifts].sort().reverse();
console.log('Z-A: ', sortedZA);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;For sorting into alphabetical order, we have used &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort" rel="noopener noreferrer"&gt;&lt;code&gt;sort()&lt;/code&gt;&lt;/a&gt; method&lt;/li&gt;
&lt;li&gt;For sorting in reverse alphabetical order, we have first used sort() and then used &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse" rel="noopener noreferrer"&gt;&lt;code&gt;reverse()&lt;/code&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/cof374ab4ae40ac0b01451586" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Would love to hear your thoughts. Stay tuned for the next iteration of this series.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>scrimba</category>
      <category>javascript</category>
      <category>javascriptmas</category>
    </item>
    <item>
      <title>#JavaScriptmas 2023 Day 1 to 6</title>
      <dc:creator>Aishwarya Mali</dc:creator>
      <pubDate>Thu, 07 Dec 2023 15:12:59 +0000</pubDate>
      <link>https://forem.com/aishwaryamali24/javascriptmas-2023-day-1-6-3m15</link>
      <guid>https://forem.com/aishwaryamali24/javascriptmas-2023-day-1-6-3m15</guid>
      <description>&lt;p&gt;This is my first time participating in the &lt;a href="https://scrimba.com/learn/javascriptmas"&gt;#JavaScriptmas&lt;/a&gt; Challenge of &lt;a href="https://scrimba.com/"&gt;Scrimba&lt;/a&gt;, and this is my take on its solutions.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is #JavaScriptmas Challenge?
&lt;/h2&gt;

&lt;p&gt;This is a FREE challenge hosted by &lt;a href="https://scrimba.com/"&gt;Scrimba&lt;/a&gt; where you get a coding challenge related to JavaScript and CSS each day, starting from December 1st to December 24th. You can learn more about it &lt;a href="https://scrimba.com/learn/javascriptmas"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 1: Countdown to Christmas
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Get today's date (you only need the day).&lt;/li&gt;
&lt;li&gt;Calculate remaining days.&lt;/li&gt;
&lt;li&gt;Display remaining days in countdownDisplay.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Stretch Goals
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Display hours, minutes and seconds.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const countdownDisplay = document.getElementById("countdown-display")
const timeLeft = document.getElementById("time-left")

function renderCountdown(){
    const christmas = 25
    const date = new Date()

    const todaysDate = date.getDate()
    const hours = date.getHours()
    const minutes = date.getMinutes()
    const seconds = date.getSeconds()

    const remainingDays = christmas - todaysDate

    countdownDisplay.textContent = remainingDays
    timeLeft.textContent = `${hours} hrs : ${minutes} mins : ${seconds} secs`
}

renderCountdown()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;First created a date variable which calls &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date"&gt;&lt;code&gt;new Date()&lt;/code&gt;&lt;/a&gt; that returns a date object with the current date and time.&lt;/li&gt;
&lt;li&gt;Based on that, retrieved today's date, hours, minutes, and seconds. Then calculated the remaining days with &lt;code&gt;remainingDays = christmas - todaysDate&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Finally, appended this information to the UI.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/co4c04d358f304306078690ed"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 2: Style a Colorful Button
&lt;/h2&gt;

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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;div class="container"&amp;gt;
  &amp;lt;div class="button-border"&amp;gt;
   &amp;lt;button type="button" class="button"&amp;gt;
    Start Coding!
   &amp;lt;/button&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.button-border{
    position: relative;
    background: linear-gradient(115deg, var(--grad-color1), var(--grad-color2), var(--grad-color3),var(--grad-color4),var(--grad-color5));
    padding: 2px 3px;
    text-align: center;
    transition: all 0.2s;
}

.button-border:hover{
    background: linear-gradient(-115deg, var(--grad-color1), var(--grad-color2), var(--grad-color3),var(--grad-color4),var(--grad-color5));
    transform: scale(1.1);
}

.button{
    display: block;
    color: var(--btn-color);
    background: var(--btn-bg);
    letter-spacing: 1px;
    padding: 20px 30px;
    border: none;
    font-family: 'Karla', sans-serif;
}

.button:hover{
    color: var(--btn-color-hover);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;The trick here was to give &lt;code&gt;.button-border&lt;/code&gt; gradient background and then placing your button on top of it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/co30b46c9afc3d37ac02b7f0b"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 3: Divide Candy
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Find the total number of pieces of candy the children can eat.&lt;/li&gt;
&lt;li&gt;Example:

&lt;ul&gt;
&lt;li&gt;Children: 3, Candies: 10&lt;/li&gt;
&lt;li&gt;Each of the 3 children can eat 3 candies. &lt;/li&gt;
&lt;li&gt;So the total number of candies that can be eaten &lt;/li&gt;
&lt;li&gt;is 3*3 = 9. So the function calcTotalCandies should &lt;/li&gt;
&lt;li&gt;log out 9.
&lt;/li&gt;
&lt;/ul&gt;


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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function calcTotalCandies(children, candy) {
 const oneChildCanEat = Math.floor(candy/children) 
 const totalCandiesEaten = oneChildCanEat * children
 console.log(totalCandiesEaten)
}

calcTotalCandies(3, 10) // expected output: 9
calcTotalCandies(4, 20) // expected output: 20
calcTotalCandies(6, 25) // expected output: 24
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;For this, first determined the number of candies one child can eat by using &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor"&gt;Math.floor&lt;/a&gt;(candy/children).&lt;/li&gt;
&lt;li&gt;Next, multiplied this value by the total number of children to obtain the result.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/co4d646929e9255a213043b71"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 4: AI Christmas Joke Generator
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use AI to generate one-line Christmas Joke.&lt;/li&gt;
&lt;li&gt;Use AI provider (openai / huggingface)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { HfInference } from '@huggingface/inference'

const hf = new HfInference(process.env.HUGGING_FACE_API_KEY)
const model = "tiiuae/falcon-7b-instruct"

document.getElementById('window-container').addEventListener('click', async function () {

    const jokeResponse = await hf.textGeneration({
        model: model,
        inputs: 'Tell me a random one line Christmas joke.'
    }) 

    const joke = jokeResponse.generated_text.replace(/Tell me a random one line Christmas joke\./i, '');

    const jokeEl = document.getElementById('joke-display')
    jokeEl.textContent = joke
})

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This one was a bit tough. I used &lt;a href="https://huggingface.co/"&gt;huggingface&lt;/a&gt; for this challenge. You can find the documentation &lt;a href="https://huggingface.co/docs/huggingface.js/inference/README"&gt;here&lt;/a&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const jokeResponse = await hf.textGeneration({
    model: model,
    inputs: 'Tell me a random one line Christmas joke.'
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;hf.textGeneration&lt;/code&gt; is a function from the Hugging Face library for generating text.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;model&lt;/code&gt; represents the model used for text generation.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;inputs&lt;/code&gt; parameter is set to the prompt 'Tell me a random one line Christmas joke.'&lt;/li&gt;
&lt;li&gt;So in short, this code is asking a model from Hugging Face to generate a random one-liner Christmas joke in response to the given prompt. The result, the generated joke, is stored in the variable jokeResponse.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/co67c40139c0956ebf667b34d"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 5: Jeopardy Card Flip
&lt;/h2&gt;

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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="card"&amp;gt;
 &amp;lt;div class="card-inner"&amp;gt;
  &amp;lt;div class="card-front"&amp;gt;
   &amp;lt;h2&amp;gt;
    This now deprecated HTML tag, popular in the early days of 
    the internet, magically made text scroll across the screen 
   &amp;lt;/h2&amp;gt;
  &amp;lt;/div&amp;gt;
  &amp;lt;div class="card-back"&amp;gt;
   &amp;lt;h2&amp;gt;What is the marquee tag&amp;lt;/h2&amp;gt;
  &amp;lt;/div&amp;gt;
 &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.card{
  perspective: 1000px;
  background-color: transparent;
  width: 400px;
  height: 250px;
}

.card h2{
  text-transform: uppercase;
  color: var(--font-color-main);
  padding: 20px
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  text-align: center;
  transition: transform 0.6s;
  transform-style: preserve-3d;
  box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
  background-color: var(--jeopardy-blue);
  border-radius: 10px;
}

.card:hover .card-inner {
  transform: rotateY(180deg);
}

.card-front, .card-back {
  position: absolute;
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.card-front, .card-back{
  display: flex;
  align-items: center;
}

.card-back{
  justify-content: center;
  transform: rotateY(180deg);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/co5e4496f9f7d503d2fc908f0"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Day 6: Secret Santa
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Task
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Write a function to randomly assign each person in an array a "Secret Santa", who is someone else in the array.&lt;/li&gt;
&lt;li&gt;No one should be assigned themselves as their own Secret Santa.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Stretch goals
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Create a UI with a button to trigger your Secret Santa function and display the results.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ssPairBtn = document.getElementById("ss-pairs")
const displayPairsEl = document.getElementById("display-pairs")

const people = ["Alice", "Bob", "Carly", "Dan", "Ed", "Ferdinand", "Ginny"]

ssPairBtn.addEventListener('click', function(){
    const secretSantaPairs = generateSecretSantaPairs(people)
    let list = ""
    Object.entries(secretSantaPairs).forEach(([name, pair])=&amp;gt;{
        list += `&amp;lt;li&amp;gt;${name} = ${pair}&amp;lt;/li&amp;gt;`
    })
    displayPairsEl.innerHTML = list
})

function generateSecretSantaPairs(arr) {
    const secretSantaPairs={}
    const peopleCopy = [...arr]
    const shuffledArray = shuffle(peopleCopy)
    for(let i=0; i&amp;lt;arr.length; i++){
        if(arr[i] !== shuffledArray[i]){
            secretSantaPairs[arr[i]] = shuffledArray[i]
        } else {
            const temp = shuffledArray[i];
            shuffledArray[i] = shuffledArray[(i + 1) % arr.length];
            shuffledArray[(i + 1) % arr.length] = temp;
            secretSantaPairs[arr[i]] = shuffledArray[i];
        }
    }
    return secretSantaPairs
}

function shuffle(arr){
    return arr.sort(() =&amp;gt; Math.random() - 0.5);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;For this challenge, first shuffled the original array using the &lt;code&gt;shuffle&lt;/code&gt; function. Then, ensured that no one should be assigned themselves as their own Secret Santa.&lt;/li&gt;
&lt;li&gt;If that condition isn't met, pairs are assigned. &lt;/li&gt;
&lt;li&gt;Otherwise, a temporary variable (temp) stores the person at the current index (i) in the shuffled array.&lt;/li&gt;
&lt;li&gt;The next two lines swap the person at index i with the person at the next index in a circular manner. This is done to avoid pairing someone with themselves. &lt;/li&gt;
&lt;li&gt;The pair is then added to the secretSantaPairs object, where the original person is paired with the new person after the swap.&lt;/li&gt;
&lt;li&gt;Finally, this function is called on the "Secret Santa Pairs" button click, and the pairs are appended to the UI.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my scrim &lt;a href="https://scrimba.com/scrim/coc2b43eabd59f831b1d5cd0c"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Would love to hear your thoughts. Stay tuned for the next iteration of this series. &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>scrimba</category>
      <category>javascript</category>
      <category>javascriptmas</category>
    </item>
    <item>
      <title>How to convert an Object into an array?</title>
      <dc:creator>Aishwarya Mali</dc:creator>
      <pubDate>Fri, 24 Nov 2023 14:37:21 +0000</pubDate>
      <link>https://forem.com/aishwaryamali24/how-to-convert-an-object-into-an-array-7hl</link>
      <guid>https://forem.com/aishwaryamali24/how-to-convert-an-object-into-an-array-7hl</guid>
      <description>&lt;p&gt;As JavaScript developers, we frequently encounter the need to transform objects into arrays. In this blog, we'll explore methods for accomplishing this task.&lt;/p&gt;

&lt;h4&gt;
  
  
  To convert Object into an array JavaScript provides following three methods:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Object.keys()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Object.values()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Object.entries()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys"&gt;&lt;code&gt;Object.keys()&lt;/code&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;It returns an array of a given object's key names. Here's a simple example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const bookObj = {
  title: "Atomic Habits",
  author: "James Clear",
  publishedYear: 2018
}

const keysArray = Object.keys(bookObj);
console.log(keysArray); 
// Output: ['title', 'author', 'publishedYear']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, &lt;code&gt;Object.keys()&lt;/code&gt; gets the keys from &lt;code&gt;bookObj&lt;/code&gt; object and returns them as an array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Suppose you have an employee object, and you want to count the number of employees. 
// In that case, you can use Object.keys()

const employeeData = {
  "id101": {name: "John Doe"},
  "id102": {name: "Jane Smith"},
}

const employeeCount = Object.keys(employeeData).length;
console.log(employeeCount);
// Output: 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values"&gt;&lt;code&gt;Object.values()&lt;/code&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;It returns an array of a given object's values. Here's a simple example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const bookObj = {
  title: "Atomic Habits",
  author: "James Clear",
  publishedYear: 2018
}

const valuesArray = Object.values(bookObj);
console.log(valuesArray); 
// Output: ['Atomic Habits', 'James Clear', 2018]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, valuesArray holds the values of the properties in &lt;code&gt;bookObj&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Suppose you have an employee object, and you want to count their total salary.
// In that case, you can use Object.values()

const employeeData = {
  "id101": { name: "John Doe", position: "Software Engineer", salary: 80000 },
  "id102": { name: "Jane Smith", position: "Product Manager", salary: 95000 },
};

const salariesArray = Object.values(employeeData).map(employee =&amp;gt; employee.salary);
console.log(salariesArray);
// Output: [80000, 95000]

// Calculate the total salary
const totalSalary = salariesArray.reduce((acc, salary) =&amp;gt; acc + salary, 0);
console.log("Total Salary:", totalSalary);
// Output: Total Salary: 175000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries"&gt;&lt;code&gt;Object.entries()&lt;/code&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;It doesn't just give you the keys or values alone; it gives you both, together in pair.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const bookObj = {
  title: "Atomic Habits",
  author: "James Clear",
  publishedYear: 2018
}

const entriesArray = Object.entries(bookObj);
console.log(entriesArray); 
// Output: [["title", "Atomic Habits"],["author", "James Clear"],["publishedYear", 2018]]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result is an array of arrays, where each inner array contains a key-value pair. This is particularly handy when you need both the keys and values together.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Suppose you have a booksObject, and you want to display their data together.
// In that case, you can use Object.entries()

const bookCollection = {
  book1: { title: "Atomic Habits", author: "James Clear", ratings: "seven lakhs plus" },
  book2: { title: "The Power of Your Subconscious Mind", author: "Joseph Murphy", ratings: "seventy two thousand plus" }
};

Object.entries(bookCollection).forEach(([bookId, bookInfo]) =&amp;gt; {
  console.log(`${bookId}: ${bookInfo.title} by ${bookInfo.author} has ${bookInfo.ratings} ratings`);
});

// Output:
// book1: Atomic Habits by James Clear has seven lakhs plus ratings
// book2: The Power of Your Subconscious Mind by Joseph Murphy has seventy two thousand plus ratings
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Understanding Object.keys(), Object.values(), and Object.entries() in JavaScript is helpful. They simplify working with objects by allowing you to iterate through keys, values, or key-value pairs effortlessly. &lt;/p&gt;

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