<?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" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Ilenia Magoni - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Ilenia Magoni - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Thu, 28 May 2026 04:41:30 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/uccellino95/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Lowercase a String in JavaScript – toLowerCase() in JS ]]>
                </title>
                <description>
                    <![CDATA[ Strings are a fundamental part of working with JavaScript. And the toLowerCase() method is one of the many integrated methods that you can use to work with strings. In this article, we'll see how to make strings lowercase with the toLowerCase() metho... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-lowercase-a-string-in-javascript-tolowercase-in-js/</link>
                <guid isPermaLink="false">66b0c39029f55a5720e0554a</guid>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ilenia Magoni ]]>
                </dc:creator>
                <pubDate>Mon, 17 Oct 2022 15:51:50 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/10/pexels-magda-ehlers-1337382.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Strings are a fundamental part of working with JavaScript. And the <code>toLowerCase()</code> method is one of the many integrated methods that you can use to work with strings.</p>
<p>In this article, we'll see how to make strings lowercase with the <code>toLowerCase()</code> method in Python.</p>
<h2 id="heading-what-is-a-string"><strong>What is a</strong> S<strong>tring?</strong></h2>
<p>A string is a data type that can contain many different characters. A string is written as a series of characters between single or double quotes.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> exampleString = <span class="hljs-string">'I am a String!'</span>
<span class="hljs-built_in">console</span>.log(exampleString); <span class="hljs-comment">// I am a String!</span>
</code></pre>
<h2 id="heading-what-is-a-method"><strong>What is a</strong> M<strong>ethod?</strong></h2>
<p>A method is a function that you can use on a specific data type. Methods can either take or not take arguments.</p>
<h2 id="heading-how-does-the-tolowercase-method-work"><strong>How</strong> D<strong>oes the</strong> <code>toLowerCase()</code> M<strong>ethod</strong> W<strong>ork?</strong></h2>
<p>The <code>toLowerCase()</code> method is a string method that returns a new string that's completely lowercase. If the original string has uppercase letters, in the new string these will be lowercase. Any lowercase letter, or any character that is not a letter, is not affected.</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(exampleString.toLowerCase()); <span class="hljs-comment">// i am a string!</span>

<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'FREECODECAMP'</span>.toLowerCase()); <span class="hljs-comment">// freecodecamp</span>
</code></pre>
<h2 id="heading-what-to-keep-in-mind-when-using-the-tolowercase-method"><strong>What to</strong> K<strong>eep in</strong> M<strong>ind</strong> W<strong>hen</strong> U<strong>sing the</strong> toLowerCase M<strong>ethod</strong></h2>
<p>The <code>toLowerCase()</code> method does a pretty straightforward thing: it creates a new string where all the uppercase letters are now lowercase. But there are a few things to keep in mind when using it. Let's take a look at them.</p>
<h3 id="heading-strings-are-immutable"><strong>Strings are immutable</strong></h3>
<p>Strings are an immutable data type, which means they can't be changed. The original string will stay unchanged after you use the <code>toLowerCase()</code> method.</p>
<p>In the examples above, the <code>toLowerCase()</code> method has acted on the <code>exampleString</code> but never changed it. Checking the value of <code>exampleString</code> still shows the original value:</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(exampleString); <span class="hljs-comment">// I am a string!</span>

<span class="hljs-built_in">console</span>.log(exampleString.toLowerCase()); <span class="hljs-comment">// i am a string!</span>

<span class="hljs-built_in">console</span>.log(exampleString); <span class="hljs-comment">// I am a string!</span>
</code></pre>
<h3 id="heading-the-tolowercase-method-returns-a-new-string"><strong>The</strong> <code>toLowerCase()</code> <strong>method returns a new string</strong></h3>
<p>This means that the <code>toLowerCase()</code>  method returns a new string. You'll need to save it in a variable if you want to use it again in your code.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> newString = exampleString.toLowerCase()

<span class="hljs-built_in">console</span>.log(newString); <span class="hljs-comment">// i am a string!</span>
</code></pre>
<h3 id="heading-strings-are-case-sensitive"><strong>Strings are case sensitive</strong></h3>
<p>Strings are case sensitive, so a lowercase string is different than an uppercase string.</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(<span class="hljs-string">'freecodecamp'</span> === <span class="hljs-string">'FREECODECAMP'</span>); <span class="hljs-comment">// false</span>
</code></pre>
<p>This is useful when thinking about what the <code>toLowerCase()</code> method could be useful for. In the example you will see how this feature makes the <code>toLowerCase()</code> method useful and necessary when building a script or program that deals with strings.</p>
<h2 id="heading-tolowercase-method-example-how-to-check-if-the-user-input-matches"><strong><code>toLowerCase()</code></strong> M<strong>ethod</strong> E<strong>xample</strong> – H<strong>ow to</strong> C<strong>heck if the</strong> U<strong>ser</strong> I<strong>nput</strong> M<strong>atches</strong></h2>
<p>Let's write a small app that asks the user a question, gets the input, and gives feedback about the user's answer.</p>
<p>There are various ways to do that: you could use this in a web app, getting the value from an <code>input</code> element with <code>type="text"</code>. To keep it simple, in the example you will see the usage of the <code>prompt</code> JavaScript function.</p>
<p>The <code>prompt</code> function will display a browser message popup with an input field in which the user can write an answer:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> answer = prompt(<span class="hljs-string">"What color is the sun?"</span>)
<span class="hljs-keyword">if</span> (answer === <span class="hljs-string">"yellow"</span>) {
  alert(<span class="hljs-string">"Correct!"</span>)
} <span class="hljs-keyword">else</span> {
  alert(<span class="hljs-string">"That is not the correct color!"</span>)
}
</code></pre>
<p>This code asks the user a question, "What color is the sun?", and waits for an answer. Then it checks if the answer is "yellow", and if it is it prints "Correct!" If it isn't, it prints "That is not the correct color!".</p>
<p>But there is an issue with this code.</p>
<p>Running this code, you will have this question asked in the popup:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/image-69.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>If you answer "Yellow", it says "That is not the correct color!"</p>
<p>Why does this happen?</p>
<p>Remember that strings are case sensitive. The script is checking if the user input the string <code>yellow</code> – <code>Yellow</code>, with a capital "Y", is a different string.</p>
<p>You can easily fix this by using the <code>toLowerCase()</code> method, and doing this small change to the code:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> answer = prompt(<span class="hljs-string">"What color is the sun?"</span>)
<span class="hljs-keyword">if</span> (answer.toLowerCase() === <span class="hljs-string">"yellow"</span>) {
  alert(<span class="hljs-string">"Correct!"</span>)
} <span class="hljs-keyword">else</span> {
  alert(<span class="hljs-string">"That is not the correct color!"</span>)
}
</code></pre>
<p>And now, if you try again...</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/10/image-70.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>What changed? Writing <code>answer.toLowerCase()</code> you make sure that the checked string is completely lowercase before comparing it with the correct answer string "yellow". In this way it doesn't matter if the user writes "YELLOW" or "yELLOW" or "yellow" – it is all converted to lowercase.</p>
<p>Thanks for reading! Now you know how to use the <code>toLowerCase()</code> method in JavaScript.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Remove an Element from a JavaScript Array – Removing a Specific Item in JS ]]>
                </title>
                <description>
                    <![CDATA[ You will often need to remove an element from an array in JavaScript, whether it's for a queue data structure, or maybe from your React State. In the first half of this article you will learn all the methods that allow you to remove an element from a... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-remove-an-element-from-a-javascript-array-removing-a-specific-item-in-js/</link>
                <guid isPermaLink="false">66b0c394bb3f390180bed0d9</guid>
                
                    <category>
                        <![CDATA[ arrays ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ilenia Magoni ]]>
                </dc:creator>
                <pubDate>Wed, 31 Aug 2022 17:00:43 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/08/vinicius-amnx-amano-dbOV1qSiL-c-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>You will often need to remove an element from an array in JavaScript, whether it's for a queue data structure, or maybe from your React State.</p>
<p>In the first half of this article you will learn all the methods that allow you to remove an element from an array without mutating the original array. In fact, this is what you will want to do most often. For example, if you don't want to mutate your React State. Or the array is used in other parts of your code, and mutating it would cause unexpected issues.</p>
<p>Always better to avoid mutations!</p>
<p>But, for completeness, the second half of the article will list methods to remove an item from an array in place. These methods do mutate the array itself.</p>
<p>Here you can find a handy summary of the article content, if you want to navigate to a section in particular.</p>
<ul>
<li><a class="post-section-overview" href="#heading-how-to-remove-an-element-from-an-array-without-mutating-the-array">How to remove an element from an array without mutating the array</a><ul>
<li><a class="post-section-overview" href="#heading-remove-the-first-element-of-an-array-with-slice">Remove the first element of an array with <code>slice</code></a></li>
<li><a class="post-section-overview" href="#heading-remove-the-last-element-of-an-array-with-slice">Remove the last element of an array with <code>slice</code></a></li>
<li><a class="post-section-overview" href="#heading-remove-an-element-at-any-position-of-an-array-with-slice-and-concat">Remove an element at any position of an array with <code>slice</code> and <code>concat</code></a></li>
<li><a class="post-section-overview" href="#heading-remove-an-element-of-a-certain-value-with-filter">Remove an element of a certain value with <code>filter</code></a></li>
<li><a class="post-section-overview" href="#heading-remove-an-element-from-an-array-with-a-for-loop-and-push">Remove an element from an array with a <code>for</code> loop and <code>push</code></a></li>
<li><a class="post-section-overview" href="#heading-remove-the-first-element-of-an-array-with-destructuring-and-the-rest-operator">Remove the first element of an array with destructuring and the rest operator</a></li>
</ul>
</li>
<li><a class="post-section-overview" href="#heading-how-to-remove-an-element-from-an-array-while-mutating-the-array">How to remove an element from an array while mutating the array</a><ul>
<li><a class="post-section-overview" href="#heading-remove-the-last-element-of-an-array-with-pop">Remove the last element of an array with <code>pop</code></a></li>
<li><a class="post-section-overview" href="#heading-remove-the-first-element-of-an-array-with-shift">Remove the first element of an array with <code>shift</code></a></li>
<li><a class="post-section-overview" href="#heading-remove-an-element-at-any-index-with-splice">Remove an element at any index with <code>splice</code></a></li>
</ul>
</li>
<li><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></li>
</ul>
<h2 id="heading-how-to-remove-an-element-from-an-array-without-mutating-the-array">How to remove an element from an array without mutating the array</h2>
<p>If you have an input array, like as a function parameter, best practices dictate that you should not mutate the array. Instead you should create a new one.</p>
<p>There are a few methods you can use to remove a specific item from an array without mutating the array.</p>
<p>To avoid mutating the array, a new array will be created without the element you want to remove.</p>
<p>You could use methods like:</p>
<ul>
<li><code>Array.prototype.slice()</code></li>
<li><code>Array.prototype.slice()</code> together with <code>Array.prototype.concat()</code></li>
<li><code>Array.prototype.filter()</code></li>
<li>A <code>for</code> loop and <code>Array.prototype.push()</code></li>
</ul>
<p>Let's see in detail how you could use each one of these to remove an element from an array without mutating the original one.</p>
<h3 id="heading-remove-the-first-element-of-an-array-with-slice">Remove the first element of an array with <code>slice</code></h3>
<p>If you want to remove the first element in an array, you can use <code>Array.prototype.slice()</code> on an array named <code>arr</code> like this: <code>arr.slice(1)</code>.</p>
<p>Here is a complete example, in which you want to remove the first element from an array containing the first 6 letters of the alphabet.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// the starting array</span>
<span class="hljs-keyword">const</span> arrayOfLetters = [<span class="hljs-string">'a'</span>, <span class="hljs-string">'b'</span>, <span class="hljs-string">'c'</span>, <span class="hljs-string">'d'</span>, <span class="hljs-string">'e'</span>, <span class="hljs-string">'f'</span>];

<span class="hljs-comment">// here the array is copied, without the first element</span>
<span class="hljs-keyword">const</span> copyWithoutFirstElement = arrayOfLetters.slice(<span class="hljs-number">1</span>);

<span class="hljs-comment">// arrayOfLetters is unchanged</span>
<span class="hljs-built_in">console</span>.log(arrayOfLetters) <span class="hljs-comment">// ['a', 'b', 'c', 'd', 'e', 'f']</span>

<span class="hljs-comment">// and copyWithoutFirstElement contains the letters from b to f</span>
<span class="hljs-built_in">console</span>.log(copyWithoutFirstElement) <span class="hljs-comment">// ['b', 'c', 'd', 'e', 'f']</span>
</code></pre>
<p>The <code>slice</code> method can take a single number as argument, and in this case it copies from that index to the end of the array. So using <code>arrayOfLetters.slice(1)</code> will create a copy of the <code>arrayOfLetters</code> array that excludes the first element.</p>
<h3 id="heading-remove-the-last-element-of-an-array-with-slice">Remove the last element of an array with <code>slice</code></h3>
<p>If the element you want to remove is the last element of the array, you can use <code>Array.prototype.slice()</code> on an array named <code>arr</code> in this way: <code>arr.slice(0, -1)</code>.</p>
<p>Here is a complete example using the same alphabet array from above, starting with an array of the first 6 alphabet letters.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> arrayOfLetters = [<span class="hljs-string">'a'</span>, <span class="hljs-string">'b'</span>, <span class="hljs-string">'c'</span>, <span class="hljs-string">'d'</span>, <span class="hljs-string">'e'</span>, <span class="hljs-string">'f'</span>];
<span class="hljs-keyword">const</span> copyWithoutLastElement = arrayOfLetters.slice(<span class="hljs-number">0</span>, <span class="hljs-number">-1</span>);

<span class="hljs-comment">// arrayOfLetters is unchanged</span>
<span class="hljs-built_in">console</span>.log(arrayOfLetters) <span class="hljs-comment">// ['a', 'b', 'c', 'd', 'e', 'f']</span>

<span class="hljs-built_in">console</span>.log(copyWithoutLastElement) <span class="hljs-comment">// ['a', 'b', 'c', 'd', 'e']</span>
</code></pre>
<p>The <code>slice</code> method takes up to two parameters. The first index of <code>slice</code> indicates from which index to start the copy, and the second argument says up to which element to copy – but it's not inclusive.</p>
<p><code>slice</code> accepts a negative index to count from the end. This means that writing <code>-1</code> would mean the last index. So from <code>0</code> to <code>-1</code> means to create a copy from index <code>0</code> up to (but not including) the last index. The end result is that the last element is not included in the copy.</p>
<h3 id="heading-remove-an-element-at-any-position-of-an-array-with-slice-and-concat">Remove an element at any position of an array with <code>slice</code> and <code>concat</code></h3>
<p>If you want to create a copy that is missing an element at any index you can use <code>Array.prototype.slice</code> and <code>Array.prototype.concat</code> together in this way: <code>arrayOfLetters.slice(0, n).concat(arrayOfLetters.slice(n+1))</code> where <code>n</code> is the index of the element you want to remove.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> arrayOfLetters = [<span class="hljs-string">'a'</span>, <span class="hljs-string">'b'</span>, <span class="hljs-string">'c'</span>, <span class="hljs-string">'d'</span>, <span class="hljs-string">'e'</span>, <span class="hljs-string">'f'</span>];

<span class="hljs-keyword">const</span> halfBeforeTheUnwantedElement = arrayOfLetters.slice(<span class="hljs-number">0</span>, <span class="hljs-number">2</span>)

<span class="hljs-keyword">const</span> halfAfterTheUnwantedElement = arrayOfLetters(<span class="hljs-number">3</span>);

<span class="hljs-keyword">const</span> copyWithoutThirdElement = halfBeforeTheUnwantedElement.concat(halfAfterTheUnwantedElement);

<span class="hljs-comment">// arrayOfLetters is unchanged</span>
<span class="hljs-built_in">console</span>.log(arrayOfLetters) <span class="hljs-comment">// ['a', 'b', 'c', 'd', 'e', 'f']</span>

<span class="hljs-built_in">console</span>.log(copyWithoutFifthElement) <span class="hljs-comment">// ['a', 'b', 'd', 'e', 'f']</span>
</code></pre>
<p>This use of <code>slice</code> is a way to put together the two previous uses.</p>
<p>The first use of <code>slice</code> will create an array from the beginning to just before the element you want to remove.</p>
<p>The second use of <code>slice</code> creates an array from after the element you want to remove to the end of the array.</p>
<p>The two arrays are concatenated together with <code>concat</code> to form an array that is similar to the starting one, but without a particular element.</p>
<h3 id="heading-remove-an-element-of-a-certain-value-with-filter">Remove an element of a certain value with <code>filter</code></h3>
<p>If you want to remove an element with a certain value, you can use <code>Array.prototype.filter()</code>. Let's take the same <code>arrayOfLetters</code> and create a copy without the <code>d</code>.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> arrayOfLetters = [<span class="hljs-string">'a'</span>, <span class="hljs-string">'b'</span>, <span class="hljs-string">'c'</span>, <span class="hljs-string">'d'</span>, <span class="hljs-string">'e'</span>, <span class="hljs-string">'f'</span>];

<span class="hljs-keyword">const</span> arrayWithoutD = arrayOfLetters.filter(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">letter</span>) </span>{
    <span class="hljs-keyword">return</span> letter !== <span class="hljs-string">'d'</span>;
});

<span class="hljs-comment">// arrayOfLetters is unchanged</span>
<span class="hljs-built_in">console</span>.log(arrayOfLetters); <span class="hljs-comment">// ['a', 'b', 'c', 'd', 'e', 'f']</span>

<span class="hljs-built_in">console</span>.log(arrayWithoutD); <span class="hljs-comment">// ['a', 'b', 'c', 'e', 'f']</span>
</code></pre>
<p><code>filter</code> takes a callback, and tests all the elements of the array with that callback. It keeps the elements for which the callback returns <code>true</code> (or a truthy value) and excludes the elements for which the callback returns <code>false</code> (or a falsy value).</p>
<p>In this case, the callback checks <code>letter !== "d"</code> so it returns <code>false</code> for the letter <code>d</code> and <code>true</code> for all others, resulting in an array that doesn't include the letter <code>d</code>.</p>
<p>The callback to <code>filter</code> is passed three arguments, in order: the element itself, the index of the element, and the whole array.</p>
<p>You can create more complex conditions than this example, as complex as you need.</p>
<h3 id="heading-remove-an-element-from-an-array-with-a-for-loop-and-push">Remove an element from an array with a <code>for</code> loop and <code>push</code></h3>
<p>A final method to remove an element from an array without mutating the original array is by using the <code>push</code> method.</p>
<p>With these simple steps:</p>
<ol>
<li>Create an empty array</li>
<li>Loop through the original array</li>
<li>Push to the empty array the elements you want to keep</li>
</ol>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> arrayOfLetters = [<span class="hljs-string">'a'</span>, <span class="hljs-string">'b'</span>, <span class="hljs-string">'c'</span>, <span class="hljs-string">'d'</span>, <span class="hljs-string">'e'</span>, <span class="hljs-string">'f'</span>];

<span class="hljs-keyword">const</span> arrayWithoutB = [];

<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; arrayOfLetters.length; i++) {
    <span class="hljs-keyword">if</span> (arrayOfLetters[i] !== <span class="hljs-string">'b'</span>) {
        arrayWithoutH.push(arrayOfLetters[i]);
    }
}

<span class="hljs-comment">// arrayOfLetters is unchanged</span>
<span class="hljs-built_in">console</span>.log(arrayOfLetters); <span class="hljs-comment">// ['a', 'b', 'c', 'd', 'e', 'f']</span>

<span class="hljs-built_in">console</span>.log(arrayWithoutB); <span class="hljs-comment">// ['a', 'c', 'd', 'e', 'f']</span>
</code></pre>
<p>The condition of the <code>if</code> statement can check both the index (<code>i</code>) and the value of the element for more complex statements.</p>
<h3 id="heading-remove-the-first-element-of-an-array-with-destructuring-and-the-rest-operator">Remove the first element of an array with destructuring and the rest operator</h3>
<p>Array destructuring and the rest operator are two concepts that are a bit confusing.</p>
<p>I suggest this article that covers <a target="_blank" href="https://www.freecodecamp.org/news/array-and-object-destructuring-in-javascript/">how to destructure an array</a> if you want to go deeper on this topic.</p>
<p>You can remove the first element using destructuring – let's say of an array named <code>arr</code> – and create a new array named <code>newArr</code> in this way: <code>const [ , ...newarr] = arr;</code>.</p>
<p>Now, let's see a practical example on how to use destructuring and the rest operator.</p>
<pre><code><span class="hljs-keyword">const</span> arrayOfFruits = [<span class="hljs-string">'olive'</span>, <span class="hljs-string">'apricot'</span>, <span class="hljs-string">'cherry'</span>, <span class="hljs-string">'peach'</span>, <span class="hljs-string">'plum'</span>, <span class="hljs-string">'mango'</span>];

<span class="hljs-keyword">const</span> [ , ...arrayOfCulinaryFruits] = arrayOfFruits;

<span class="hljs-comment">// arrayOfFruits is unchanged</span>
<span class="hljs-built_in">console</span>.log(arrayOfFruits); <span class="hljs-comment">// ['olive', 'apricot', 'cherry', 'peach', 'plum', 'mango']</span>

<span class="hljs-built_in">console</span>.log(arrayOfCulinaryFruits); <span class="hljs-comment">// ['apricot', 'cherry', 'peach', 'plum', 'mango']</span>
</code></pre><p>Putting a comma before the rest operator says to avoid the first element in the array, and all the others are copied in the <code>arrayOfCulinaryFruits</code> array.</p>
<h2 id="heading-how-to-remove-an-element-from-an-array-while-mutating-the-array">How to remove an element from an array while mutating the array</h2>
<p>In some cases it might be appropriate to mutate the original array. In these cases you can also use one of the following mutating methods.</p>
<ul>
<li><code>Array.prototype.pop()</code></li>
<li><code>Array.prototype.shift()</code></li>
<li><code>Array.prototype.splice()</code></li>
</ul>
<h3 id="heading-remove-the-last-element-of-an-array-with-pop">Remove the last element of an array with <code>pop</code></h3>
<p>You can remove the last item of an array with <code>Array.prototype.pop()</code>.</p>
<p>If you have an array named <code>arr</code>, it looks like <code>arr.pop()</code>.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> arrayOfNumbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>];

<span class="hljs-keyword">const</span> previousLastElementOfTheArray = arrayOfNumbers.pop();

<span class="hljs-built_in">console</span>.log(arrayOfNumbers); <span class="hljs-comment">// [1, 2, 3]</span>

<span class="hljs-built_in">console</span>.log(previousLastElementOfTheArray); <span class="hljs-comment">// 4</span>
</code></pre>
<p>The <code>pop</code> method is used on the array, and it changes the array by removing the last item of the array.</p>
<p>The <code>pop</code> method also returns the removed element.</p>
<h3 id="heading-remove-the-first-element-of-an-array-with-shift">Remove the first element of an array with <code>shift</code></h3>
<p>The <code>shift</code> method can be used on an array to remove the first element of an array.</p>
<p>If you have an array named <code>arr</code> it can be used in this way: <code>arr.shift()</code>.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> arrayOfNumbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>];

<span class="hljs-keyword">const</span> previousFirstElementOfTheArray = arrayOfNumbers.shift();

<span class="hljs-built_in">console</span>.log(arrayOfNumbers); <span class="hljs-comment">// [2, 3, 4]</span>

<span class="hljs-built_in">console</span>.log(previousFirstElementOfTheArray); <span class="hljs-comment">// 1</span>
</code></pre>
<p>The <code>shift</code> method removes the first item of the array.</p>
<p>It also returns the removed element.</p>
<h3 id="heading-remove-an-element-at-any-index-with-splice">Remove an element at any index with <code>splice</code></h3>
<p>You can remove the element at any index by using the <code>splice</code> method.</p>
<p>If you have an array named <code>arr</code> it can be used in this way to remove an element at any index: <code>arr.splice(n, 1)</code>, with <code>n</code> being the index of the element to remove.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> arrayOfNumbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>];

<span class="hljs-keyword">const</span> previousSecondElementOfTheArray = arrayOfNumbers.splice(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>);

<span class="hljs-built_in">console</span>.log(arrayOfNumbers); <span class="hljs-comment">// [1, 3, 4]</span>

<span class="hljs-built_in">console</span>.log(previousSecondElementOfTheArray); <span class="hljs-comment">// [2]</span>
</code></pre>
<p>The <code>splice</code> method can accept many arguments.</p>
<p>To remove an element at any index, you need to give <code>splice</code> two arguments: the first argument is the index of the element to remove, the second argument is the number of elements to remove.</p>
<p>So, if you have an array named <code>arr</code>, in order to remove an element at index 4, the way to use the <code>splice</code> method would be: <code>arr.splice(4, 1)</code>.</p>
<p>The <code>splice</code> method then returns an array containing the removed elements.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>There are many different ways to do the same thing in JavaScript. </p>
<p>In this article you have learned nine different methods to remove an element from an array. Six of them do not mutate the original array, and three of them do. </p>
<p>You will probably use all of them at one point or an other, and maybe you will learn even more methods to do this same thing.</p>
<p>Have fun!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Calculate Percentage in Excel – Formula for Percentages ]]>
                </title>
                <description>
                    <![CDATA[ A percentage is a kind of fraction saying how many parts over 100 something is. In this article you will see in detail what a percentage is, and how to calculate a percentage in Excel. First, before diving into how it works in Excel, let's take a loo... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-calculate-percentage-in-excel-formula-for-percentages/</link>
                <guid isPermaLink="false">66b0c38ebb3f390180bed0d5</guid>
                
                    <category>
                        <![CDATA[ excel ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Math ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Mathematics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ MathJax ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ilenia Magoni ]]>
                </dc:creator>
                <pubDate>Thu, 18 Aug 2022 17:44:39 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/08/victoria-strukovskaya-OhL_qEqpef4-unsplash-1.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>A percentage is a kind of fraction saying how many parts over 100 something is. In this article you will see in detail what a percentage is, and how to calculate a percentage in Excel.</p>
<p>First, before diving into how it works in Excel, let's take a look at the math.</p>
<p>If you want to jump directly to the Excel part, and avoid the math part, please proceed to the section <a class="post-section-overview" href="#heading-how-to-work-with-percentages-in-excel">How to work with percentages in Excel</a>.</p>
<h2 id="heading-what-is-the-formula-for-calculating-a-percentage">What is the Formula for Calculating a Percentage?</h2>
<p>Percentages from 0% to 100% are equivalent to decimal values from 0 to 1. That means you can convert from a percentage to a decimal number. Let's see how.</p>
<h3 id="heading-how-to-convert-from-decimal-number-to-percentage">How to Convert from Decimal Number to Percentage</h3>
<p>You can convert from a decimal number to a percentage in the following way:</p>
<ul>
<li>take the decimal number, (d),</li>
<li>multiply it by (100),</li>
<li>and then add the percentage (\%) symbol,</li>
</ul>
<p>In short, if you want to get a percentage from a number (d) you can do this:</p>
<p>$$ ( d \cdot 100 ) \% $$</p><h3 id="heading-how-to-convert-from-a-percentage-to-a-decimal-number">How to Convert from a Percentage to a Decimal Number</h3>
<p>If you want to convert from a percentage to a number, you can:</p>
<ul>
<li>take the percentage (P\%),</li>
<li>remove the percentage symbol, (P)</li>
<li>then divide the number by (100): (\frac{P}{100})</li>
</ul>
<p>In short, to convert a percentage (P\%) to a decimal number:</p>
<p>$$ \frac{P\xcancel{\%}}{100} $$</p><h3 id="heading-how-to-calculate-the-percentage-of-a-number">How to Calculate the Percentage of a Number</h3>
<p>There are three cases in which you might want to calculate the percentage of a number:</p>
<ul>
<li>to add a percentage to the number (like for calculating how much you have to pay including VAT)</li>
<li>to just get the percentage of the number</li>
<li>to subtract a percentage from the number (like for a sale)</li>
</ul>
<h4 id="heading-how-to-add-a-percentage-to-a-number">How to add a percentage to a number</h4>
<p>Let's first use a specific case, and then let's generalise.</p>
<p>You went shopping, and the total you need to pay is $185 + VAT. Let's say VAT in this case is 17%.</p>
<p>So you would have to calculate 17% of $185 and then add it to $185.</p>
<p>$$ \$185  \cdot 17 \% + \$185 $$</p>
<p>You can make it a single operation if instead you multiply by ( 117 \% ).</p>
<p>$$ \$185 \cdot ( 100\% + 17\% ) = \$185 \cdot 117\% $$</p>
<p>If you have a simple calculator that doesn't have a percentage operator, you can convert the percentage to a decimal number as we discussed above. Here's what that would look like:</p>
<p>$$ \$185 \cdot 117\% = \$185 \cdot \frac{117 \xcancel{ \% }}{ 100 } = \$185 \cdot 1.17 $$</p>
<p>So, in general, if you want to add a percentage ( P \% ) to a number ( n ) you can do this:</p>
<p>$$ n \cdot ( 100\% + P\%) $$</p><p>Or if instead you have the percentage in the decimal number form ( d ) you can do this:</p>
<p>$$ n \cdot (1 + d) $$</p><h4 id="heading-how-to-calculate-the-percentage-of-a-number-1">How to calculate the percentage of a number</h4>
<p>If you want to buy a house you need to pay a deposit on the house. Let's say that's 15% of the total value of the house.</p>
<p>If the house price is $200,000, how can you calculate it?</p>
<p>You can multiply the price by the percent number to get the percentage.</p>
<p>$$ \$200,000 \cdot 15 \% = \$30,000 $$</p>
<p>So if you want to know what's the percentage (P\%) or fraction (d) of a number (m), you can multiply that number by the percentage or fraction.</p>
<p>$$ m \cdot P\% \newline \, \\ m \cdot d $$</p><h4 id="heading-how-to-subtract-a-percentage-from-a-number">How to subtract a percentage from a number</h4>
<p>This case is common for calculating the price of an item on sale. For example, if something has an original price of $999 and it is on sale for 20% less, you can calculate the the final price by figuring out what is 20% of $999. Well, it's $199.80, so then you just subtract that value from $999.</p>
<p>The final price of the item on sale is $799.20.</p>
<p>You can calculate it in a single step if you multiply the original price by ((100\% - 20\%)) or (80\%):</p>
<p>$$ \$999 \cdot (100\% - 20\%) = \$999 \cdot 80\% = \$779.20 $$</p>
<p>So the general formula to subtract a percentage (P\%) from a number (b) is:</p>
<p>$$ b \cdot (100\% - P\%) $$</p><p>Or in decimal form:</p>
<p>$$ b \cdot (1 - d) $$</p><h3 id="heading-how-to-calculate-the-percentage-of-a-number-in-respect-to-another-number">How to Calculate the Percentage of a Number in Respect to Another Number</h3>
<p>A cake weights 11 lbs, and you eat 3 pieces for a total of 21 oz. How can you know what percentage of cake have you eaten?</p>
<p>It's important to do calculations of this kind with everything in the same units. So, first, let's convert the weight of the cake to ounces.</p>
<p>$$ 11~\mathrm{lb} \cdot \frac{16~\mathrm{oz}}{\mathrm{lb}} = 176~\mathrm{oz} $$</p><p>Now it's possible to see the percentage of the cake you've eaten: you need to divide the part (in this case the 21 oz of cake you have eaten) by the whole (the 176 oz of the whole cake):</p>
<p>$$ \frac{11~\mathrm{oz}}{176~\mathrm{oz}} = 0.0625 $$</p><p>As seen in the paragraph on how to convert a decimal to a number, you can convert this to a percentage with ( 0.0625 \cdot 100 \% = 6.25\%).</p>
<p>In this example, you have eaten 6.25% of the whole cake.</p>
<h3 id="heading-how-do-you-combine-two-percentages">How Do You Combine Two Percentages?</h3>
<p>Let's say that some items in an online store are discounted at 20%, and then there is an offer for a 10% discount for everything in your cart at payment.</p>
<p>If you are getting a discount of 20% and then another 10% on top of that... how much is the discount?</p>
<p>It's not 30%, because the second discount is applied at a different time than the first discount.</p>
<p>A discount of 20% means you pay 80% ((100\% - 20\%)) of the original price, and a discount of 10% means you pay 90% ((100\% - 10\%))of the original price. Combining the two discounts means multiplying together the two percentages, like so:</p>
<p>$$ 80\% \cdot 90\% = 72\% $$</p><p>Or in decimal form:</p>
<p>$$ 0.80 \cdot 0.90 = 0.72 $$</p><p>So you pay 72% of the original price, or have a discount of 28%.</p>
<h2 id="heading-why-are-a-decimal-and-a-percentage-equivalent">Why Are a Decimal and a Percentage Equivalent?</h2>
<p>Percentage comes from "per cent", or "over one hundred". The percentage symbol represents the line fraction with 100 in the denominator.</p>
<p>$$ 0.20 = \frac{20}{100} = 20\% $$</p><p>The percentage is a simple way to describe how many hundredths of a whole something is.</p>
<h2 id="heading-how-to-work-with-percentages-in-excel">How to Work with Percentages in Excel</h2>
<p>Now it's time to start working with Excel. Let's start with a pretty important thing. How do you write percentages in Excel?</p>
<h3 id="heading-how-to-write-percentages-in-excel">How to Write Percentages in Excel</h3>
<p>In Excel you can write percentages in two ways:</p>
<ul>
<li>You can write a decimal number and then format the cell as a percentage from the format drop down menu or from the Percent Style button:</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/image-86.png" alt="Image" width="600" height="400" loading="lazy">
<em>In the first image the Percent Style button is circled in red, and a decimal number is written in the cell. In the second image, the cell has been formatted as a percentage, and the number is converted to a percentage.</em></p>
<ul>
<li>You can write a percentage in the cell, and the cell will automatically take the percentage formatting:</li>
</ul>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/image-87.png" alt="Image" width="600" height="400" loading="lazy">
<em>In the first image you can see that the empty cell has the "General" formatting, in the second image you can see a percentage being written in the cell, and in the third image you can see that the cell has taken the percentage formatting.</em></p>
<p>The default format is for a whole percentage. You can change the number of decimal places shown with the "Increase Decimal" and "Decrease Decimal" buttons.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/image-112.png" alt="Image" width="600" height="400" loading="lazy">
<em>The two buttons "Increase Decimal" and "Decrease Decimal" circled in red.</em></p>
<p>Let's say you have a decimal form of 0.12345. Formatting it to a percentage will show ( 12\% ). You can use the buttons to show the decimal places.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/image-113.png" alt="Image" width="600" height="400" loading="lazy">
<em>In the first image, the value 12% appears in the cell K1. In the second image, after using the "Increase Decimal" button twice, the value 12.35% appears in the cell K1. In the third image, after using the button "Decrease Decimal" once, the value 12.3% appears in the cell K1.</em></p>
<h3 id="heading-how-to-calculate-the-percentage-of-a-number-in-excel">How to Calculate the Percentage of a Number in Excel</h3>
<p>In math, the percentage of a number is calculated by multiplying that number by the percentage: ( 87\% \cdot 824 = 716.88 ).</p>
<p>In Excel, let's say you have the number in cell A1 and the percentage in cell B1. To calculate the result, you can write in cell C1 <code>=A1*B1</code>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/image-110.png" alt="Image" width="600" height="400" loading="lazy">
<em>In the first image you can see the formula to calculate the percentage of a number, and then its result in the second image.</em></p>
<h3 id="heading-how-to-calculate-the-percentage-of-a-number-with-respect-to-another-in-excel">How to Calculate the Percentage of a Number with Respect to Another in Excel</h3>
<p>In math, you can calculate the percentage of a number with respect to another number by taking the ratio of the two numbers and then converting to a percentage.</p>
<p>If you want to know what percentage 75 is with respect to 142, you can do ( \frac{75}{142} = 0.528 = 52.8\% ).</p>
<p>Let's write 75 in cell G1, and 142 in cell H1. To get the percentage of 75 in respect of 142 you can write in cell I1 <code>=G1/H1</code>. The cell will have the result in decimal format, but you can format it to a percentage using the Percent Style button. Then you can adjust the number of decimal places with the Increase Decimal and Decrease Decimal buttons.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/image-111.png" alt="Image" width="600" height="400" loading="lazy">
<em>In the first image you can see the formula to do the calculation. In the second image it results in a decimal number. In the third image it has been converted to a percentage, and then in the fourth the number of digits after the decimal separator has been changed.</em></p>
<h3 id="heading-how-to-calculate-a-percentage-of-multiple-percentages-in-excel">How to Calculate a Percentage of Multiple Percentages in Excel</h3>
<p>Let's take the example used above.</p>
<p>An online store has a promotion on some items for 20% off. Then there is another promotion of 10% off for everything in the cart at the moment of payment.</p>
<p>The first discount means you pay 80% of the original price of the item. And then you pay 90% of what's in the cart.</p>
<p>How much is the discount?</p>
<p>You get the result by multiplying the two percentages. ( 90\% \cdot 80\%).</p>
<p>In Excel, if you have the first percentage in I2 and the second in J2, you can write <code>=I2*J2</code> to calculate the result.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/image-120.png" alt="Image" width="600" height="400" loading="lazy">
<em>In the first image you can see the formula to calculate the percentage from multiple percentages, and then its result in the second image.</em></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Percentages are a mathematical tool we use in every day life. In this tutorial, you have learned how they work mathematically, and how to use them in Excel.</p>
<p>I hope this article has been useful.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is a Callback Function in JavaScript? JS Callbacks Example Tutorial ]]>
                </title>
                <description>
                    <![CDATA[ In JavaScript there are higher order methods and functions that accept a function as an argument. These functions used as arguments for other functions are called callback functions. What is a callback in JavaScript? A callback is a function passed a... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-a-callback-function-in-javascript-js-callbacks-example-tutorial/</link>
                <guid isPermaLink="false">66b0c3bcc82f8da076e5b028</guid>
                
                    <category>
                        <![CDATA[ callbacks ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ilenia Magoni ]]>
                </dc:creator>
                <pubDate>Tue, 09 Aug 2022 00:32:48 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/08/pexels-pixabay-39656.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In JavaScript there are higher order methods and functions that accept a function as an argument. These functions used as arguments for other functions are called callback functions.</p>
<h2 id="heading-what-is-a-callback-in-javascript">What is a callback in JavaScript?</h2>
<p>A callback is a function passed as an argument of another function.</p>
<p>This means that the parent function is usually built to use any kind of function. But the callback function, on the other hand, is meant to be used in a specific case (or a restricted number of cases) in which the parent function is used. </p>
<h2 id="heading-how-do-you-create-a-callback-function-in-javascript">How do you create a callback function in JavaScript?</h2>
<p>You create a callback function just like any other function in JavaScript:</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">callbackFunction</span> (<span class="hljs-params"></span>) </span>{

}
</code></pre>
<p>The difference between a callback function and any other function is how it's used.</p>
<p>A callback function is specifically built to be used as argument of another function.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">anyFunction</span>(<span class="hljs-params">fun</span>) </span>{
    <span class="hljs-comment">// ...</span>
    fun(a, b, c);
    <span class="hljs-comment">//...</span>
}

anyFunction(callbackFunction);
</code></pre>
<p>So, to create a <code>callbackFunction</code> you need to know how the parent function uses the callback function, what arguments it passes in, and what order it passes them in.</p>
<h3 id="heading-what-is-an-example-of-a-callback-function">What is an example of a callback function?</h3>
<p>We'll now write our own callback function, as it's something you'll have to do many times. So, let's start!</p>
<p>A higher order function that's already integrated in the JavaScript language is the <code>every</code> method.</p>
<p>The <code>every</code> method is an array method, and uses a callback to check that all the elements in the array pass a certain test.</p>
<p>Looking at the <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every">documentation on the <code>every</code> method</a>, you can see that the callback is passed three arguments: an element of the array, the index of that element, and the whole array.</p>
<p>So the callback function signature would be something like this:</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">callbackFunction</span>(<span class="hljs-params">element, index, array</span>) </span>{
    <span class="hljs-comment">// do something</span>
}
</code></pre>
<p>Callback functions can be as simple or as complex as you need them to be. To create an example, we need some context.</p>
<h3 id="heading-how-to-write-a-callback-function-in-javascript">How to write a callback function in JavaScript</h3>
<p>So, let's say you are working with arrays of strings. You need to check if the array contains only strings that are exactly three characters long, are uppercase, contain all different letters, and that they don't repeat inside the array.</p>
<p>This is a pretty complex case, but maybe you will eventually need to do something like this or of equal complexity, so it's all good practice.</p>
<p>You can tackle one condition at a time when you build a function with so many things to check.</p>
<p>The first condition is that the element is a string, so, let's add it:</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">callbackFunction</span>(<span class="hljs-params">element, index, array</span>) </span>{

    <span class="hljs-comment">// check that element is a string</span>
    <span class="hljs-keyword">const</span> isNotString = <span class="hljs-keyword">typeof</span> element !== <span class="hljs-string">"string"</span>;
    <span class="hljs-comment">// if it's not, end function</span>
    <span class="hljs-keyword">if</span> (isNotString) {<span class="hljs-keyword">return</span>;}

}
</code></pre>
<p>Next, the strings must be all uppercase, contain only letters, and be 3 characters long.</p>
<p>You could check these three conditions separately, or you can check them together with a regular expression that checks for exactly those three things.</p>
<p>Such a regular expression would look like this: <code>/^[A-Z]{3}$/</code>.</p>
<p>Let's see what the parts of this regular expression are:</p>
<ul>
<li>The characters <code>^</code> at the beginning and <code>$</code> at the end are anchors. These say that the string must start and end in exactly that way. And if you use both, they restrict a string to contain only and exactly the pattern in the regular expression.</li>
<li><code>[A-Z]</code> is a character class that matches any character from <code>A</code> to <code>Z</code>, so all uppercase letters.</li>
<li><code>{3}</code> is a counter. This says that the previous thing must be matched exactly three consecutive times.</li>
</ul>
<p>The regular expression explained above is the equivalent of this regular expression: <code>/^[A-Z][A-Z][A-Z]$/</code>.</p>
<p>In this case instead of the counter <code>{3}</code> we have written the class <code>[A-Z]</code> three times.</p>
<p>Let's add this to the code.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">callbackFunction</span>(<span class="hljs-params">element, index, array</span>) </span>{

    <span class="hljs-comment">// check that element is a string</span>
    <span class="hljs-keyword">const</span> isNotString = <span class="hljs-keyword">typeof</span> element !== <span class="hljs-string">"string"</span>;
    <span class="hljs-comment">// if it's not, end function</span>
    <span class="hljs-keyword">if</span> (isNotString) {
        <span class="hljs-keyword">return</span>;
    }

    <span class="hljs-comment">// check that string is 3 characters long and only uppercase letters</span>
    <span class="hljs-keyword">const</span> isItThreeUpperCaseLetters = <span class="hljs-regexp">/^[A-Z]{3}$/</span>.test(element);
    <span class="hljs-comment">// otherwise, end function</span>
    <span class="hljs-keyword">if</span> (!isItThreeUpperCaseLetters) {
        <span class="hljs-keyword">return</span>;
    }

}
</code></pre>
<p>If you don't like regular expressions, you can read <a class="post-section-overview" href="#heading-and-if-we-didnt-use-a-regular-expression">below</a> how to do the same checks without using a regular expression.</p>
<p>Then, next, we need to check if the characters are all different.</p>
<p>There are three characters you can use: <code>element[0] !== element[1] &amp;&amp; element[0] !== element[2] &amp;&amp; element[1] !== element[2]</code>. </p>
<p>But, you can also do this with a loop – a double loop actually.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// with the outer loop, you get j, the first index to compare</span>
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> j = <span class="hljs-number">0</span>; j++; j &lt; element.length) {
    <span class="hljs-comment">// with the inner loop you get k, the second index to compare</span>
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> k = j+<span class="hljs-number">1</span>; k++; k &lt; element.length) {
        <span class="hljs-comment">// you compare the element at index j with the element at index k</span>
        <span class="hljs-keyword">if</span> (element[j] === element[k]) {
            <span class="hljs-comment">// if they are equal return to stop the function</span>
            <span class="hljs-keyword">return</span>;
        }
    }
}
</code></pre>
<p>The loop will work with any length, and you don't need to rewrite it for different situations.</p>
<p>Is it the exact same as writing the three comparisons? Let's follow the loop to check.</p>
<p>At first iteration we have that <code>j=0</code>, and <code>k=1</code>, so the first comparison is <code>element[0] === element[1]</code>. Then <code>k</code> increases, so it's <code>j=0</code> and <code>k=2</code>, so that is <code>element[0] === element[2]</code>.</p>
<p>At this point the inner loop stops, and the outer loop (the one with <code>j</code>) goes to the next iteration. This time <code>j=1</code>, and the inner loop starts at <code>k=j+1</code> so at <code>k=2</code> – the comparison here is <code>element[1] === element[2]</code>.</p>
<p>The inner loop has finished looping, the outer loop goes from <code>j=1</code> to <code>j=2</code>, the inner loop doesn't start as <code>k = j+1 = 3</code> doesn't pass the <code>k &lt; element.length</code> condition of the loop.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">callbackFunction</span>(<span class="hljs-params">element, index, array</span>) </span>{


    <span class="hljs-comment">// check that element is a string</span>
    <span class="hljs-keyword">const</span> isNotString = <span class="hljs-keyword">typeof</span> element !== <span class="hljs-string">"string"</span>;
    <span class="hljs-comment">// if it's not, end function</span>
    <span class="hljs-keyword">if</span> (isNotString) {
        <span class="hljs-keyword">return</span>;
    }


    <span class="hljs-comment">// check that string is 3 characters long and only uppercase letters</span>
    <span class="hljs-keyword">const</span> isItThreeUpperCaseLetters = <span class="hljs-regexp">/^[A-Z]{3}$/</span>.test(element);
    <span class="hljs-comment">// otherwise, end function</span>
    <span class="hljs-keyword">if</span> (!isItThreeUpperCaseLetters) {
        <span class="hljs-keyword">return</span>;
    }


    <span class="hljs-comment">// check if all characters are different</span>
    <span class="hljs-keyword">const</span> allDifferentCharacters = element[<span class="hljs-number">0</span>] !== element[<span class="hljs-number">1</span>] &amp;&amp; element[<span class="hljs-number">0</span>] !== element[<span class="hljs-number">2</span>] &amp;&amp; element[<span class="hljs-number">1</span>] !== element[<span class="hljs-number">2</span>];
    <span class="hljs-comment">// if not, return to stop the function</span>
    <span class="hljs-keyword">if</span> (!allDifferentCharacters) {
        <span class="hljs-keyword">return</span>;
    }



}
</code></pre>
<p>Then, the last thing we need to check is that the strings are not repeated inside the array.</p>
<p>We can use <code>indexOf</code> to check that the current one is the first appearance of <code>element</code> inside the array.</p>
<p>We would need to reference the array for this. And we have it – it's one of the arguments passed in to the callback, the <code>array</code> parameter.</p>
<p>If this is the first appearance of the string in the array, the output of <code>indexOf</code> will be the same as <code>index</code>.</p>
<p>If  <code>array.indexOf(element) === index</code> is <code>true</code>, that means that <code>element</code> is present in the array for the first time at <code>index</code>. If it's <code>false</code>, an identical string is present earlier in the array.</p>
<p>Let's add this check to the function. And if the string has survived through all the checks, then the function can return <code>true</code> at the end.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">callbackFunction</span>(<span class="hljs-params">element, index, array</span>) </span>{


    <span class="hljs-comment">// check that element is a string</span>
    <span class="hljs-keyword">const</span> isNotString = <span class="hljs-keyword">typeof</span> element !== <span class="hljs-string">"string"</span>;
    <span class="hljs-comment">// if it's not, end function</span>
    <span class="hljs-keyword">if</span> (isNotString) {
        <span class="hljs-keyword">return</span>;
    }


    <span class="hljs-comment">// check that string is 3 characters long and only uppercase letters</span>
    <span class="hljs-keyword">const</span> isItThreeUpperCaseLetters = <span class="hljs-regexp">/^[A-Z]{3}$/</span>.test(element);
    <span class="hljs-comment">// otherwise, end function</span>
    <span class="hljs-keyword">if</span> (!isItThreeUpperCaseLetters) {
        <span class="hljs-keyword">return</span>;
    }


    <span class="hljs-comment">// check if all characters are different</span>
    <span class="hljs-keyword">const</span> allDifferentCharacters = element[<span class="hljs-number">0</span>] !== element[<span class="hljs-number">1</span>] &amp;&amp; element[<span class="hljs-number">0</span>] !== element[<span class="hljs-number">2</span>] &amp;&amp; element[<span class="hljs-number">1</span>] !== element[<span class="hljs-number">2</span>];
    <span class="hljs-comment">// if not, return to stop the function</span>
    <span class="hljs-keyword">if</span> (!allDifferentCharacters) {
        <span class="hljs-keyword">return</span>;
    }


    <span class="hljs-comment">// check if it's the first appearence of element inside the array</span>
    <span class="hljs-keyword">const</span> isItFirstAppearence = array.indexOf(element) === index;
    <span class="hljs-comment">// if not, return to stop the function</span>
    <span class="hljs-keyword">if</span> (!isItFirstAppearence) {
        <span class="hljs-keyword">return</span>;
    }


    <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
}
</code></pre>
<h4 id="heading-and-if-we-didnt-use-a-regular-expression">And if we didn't use a regular expression?</h4>
<p>In the code above, to check three different things, we used a regular expression: <code>/^[A-Z]{3}$/</code>.</p>
<p>But if you don't want to work with regex, you can use the <code>length</code> property to check if a string is of exactly a certain length. In this case <code>element.length === 3</code> to check that the string is exactly three characters long.</p>
<p>Next, the string must be all uppercase and contain only letters.</p>
<p>You can use <code>charCodeAt</code> for this. This method returns the ASCII code of a character, and knowing that uppercase letters have ASCII codes from 65 to 90, you can check that there are only uppercase letters.</p>
<p>There are three numbers to check: <code>element.charCodeAt(0)</code>, <code>element.charCodeAt(1)</code>, and <code>element.charCodeAt(2)</code>. They all need to be between 65 and 90. It's only three characters, but we can still use a loop.</p>
<p>So, that would be as below:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i++; i &lt; element.length) {
    <span class="hljs-comment">// find the ASCII code of the character</span>
    <span class="hljs-keyword">const</span> code = element.charCodeAt(i);
    <span class="hljs-comment">// check if it's outside of the range</span>
    <span class="hljs-keyword">if</span> (code &lt; <span class="hljs-number">65</span> || code &gt; <span class="hljs-number">90</span>) {
        <span class="hljs-comment">// if it is, return to stop the function</span>
        <span class="hljs-keyword">return</span>;
    }
}
</code></pre>
<p>Let's add this to the function:</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">callbackFunction</span>(<span class="hljs-params">element, index, array</span>) </span>{

    <span class="hljs-comment">// check that element is a string</span>
    <span class="hljs-keyword">const</span> isNotString = <span class="hljs-keyword">typeof</span> element !== <span class="hljs-string">"string"</span>;
    <span class="hljs-comment">// if it's not, end function</span>
    <span class="hljs-keyword">if</span> (isNotString) {<span class="hljs-keyword">return</span>;}

    <span class="hljs-comment">// check that element has length string</span>
    <span class="hljs-keyword">const</span> hasLengthThree = element.length === <span class="hljs-number">3</span>;
    <span class="hljs-comment">// if it has a different length, end function</span>
    <span class="hljs-keyword">if</span> (!hasLengthThree) {<span class="hljs-keyword">return</span>;}

    <span class="hljs-comment">// loop over the characters</span>
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i++; i &lt; element.length) {
        <span class="hljs-comment">// find the ASCII code of the character</span>
        <span class="hljs-keyword">const</span> code = element.charCodeAt(i);
        <span class="hljs-comment">// check if it's outside of the range</span>
        <span class="hljs-keyword">if</span> (code &lt; <span class="hljs-number">65</span> || code &gt; <span class="hljs-number">90</span>) {
            <span class="hljs-comment">// if it's outside the range, return and stop the function</span>
            <span class="hljs-keyword">return</span>;
        }
    } 
}
</code></pre>
<p>If you have come here from the link above, you can return there to continue reading how to finish the function, otherwise, please continue to the end.</p>
<h3 id="heading-how-to-use-the-example-callback-function">How to use the example callback function</h3>
<p>We have written the callback function. So how do you use it?</p>
<pre><code class="lang-javascript">anArray.every(callbackFunction);
</code></pre>
<p>You can also use the <code>every</code> method inside a callback – maybe the callback to a <a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter"><code>filter</code> method</a>.</p>
<p>As a program becomes more complex, it's probably going to use proportionally more callback functions.</p>
<h2 id="heading-why-do-we-use-callback-functions-in-javascript">Why do we use callback functions in JavaScript?</h2>
<p>Callback functions are a neat feature of JavaScript. It means we can have a general function that does something (like <code>every</code> that checks if every element in an array match a certain condition, <code>filter</code>, that removes the elements that don't match a certain condition, <code>replace</code>, a string method that accepts a callback to describe how to replace parts of a string, and so on) and a callback function to add specifics of that behaviour for the specific situation.</p>
<ul>
<li><code>filter</code> in that situation will remove the elements specified by the callback.</li>
<li><code>every</code> will check that all the elements in that situation are as specified by the callback function. </li>
<li><code>replace</code> will replace parts of the string in the situation in which it is used as specified by the callback.</li>
</ul>
<p>Higher order functions add a level of abstraction to the code. We don't know (and don't need to know), how <code>every</code> checks every element of the array and verifies that they all pass the tests specified by the callback. We only need to know that the method accepts a callback function for that.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Callbacks are functions that are passed as arguments of other functions. You have seen an example of how to create one, and some considerations on why they are useful.</p>
<p>Thank you for reading!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is a Factorial? How to Calculate Factorials with Examples ]]>
                </title>
                <description>
                    <![CDATA[ A factorial is a mathematical operation that you write like this: n!. It represents the multiplication of all numbers between 1 and n. So if you were to have 3!, for example, you'd compute 3 x 2 x 1 (which = 6). Let's see how it works with some more ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-a-factorial/</link>
                <guid isPermaLink="false">66b0c3bff8d7f56c3f394b08</guid>
                
                    <category>
                        <![CDATA[ Advanced Mathematics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Math ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Mathematics ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ilenia Magoni ]]>
                </dc:creator>
                <pubDate>Wed, 03 Aug 2022 16:32:53 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/08/antoine-dautry-_zsL306fDck-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>A factorial is a mathematical operation that you write like this: <code>n!</code>. It represents the multiplication of all numbers between 1 and n.</p>
<p>So if you were to have <code>3!</code>, for example, you'd compute 3 x 2 x 1 (which = 6). Let's see how it works with some more examples.</p>
<h2 id="heading-definition-of-a-factorial">Definition of a Factorial</h2>
<p>The factorial of a number is the multiplication of all the numbers between 1 and the number itself. It is written like this: <code>n!</code>. So the factorial of 2 is <code>2!</code> (= 1 × 2).</p>
<p>To calculate a factorial you need to know two things:</p>
<ol>
<li><code>0! = 1</code></li>
<li><code>n! = (n - 1)! × n</code></li>
</ol>
<p>The factorial of 0 has value of 1, and the factorial of a number <code>n</code> is equal to the multiplication between the number <code>n</code> and the factorial of <code>n-1</code>.</p>
<p>For example, <code>5!</code> is equal to <code>4! × 5</code>.</p>
<p>Here the first few factorial values to give you an idea of how this works:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Factorial</td><td>Multiplication</td><td>Result</td></tr>
</thead>
<tbody>
<tr>
<td>0!</td><td>1</td><td>1</td></tr>
<tr>
<td>1!</td><td>1</td><td>1</td></tr>
<tr>
<td>2!</td><td>1 × 2</td><td>2</td></tr>
<tr>
<td>3!</td><td>1 × 2 × 3</td><td>6</td></tr>
<tr>
<td>4!</td><td>1 × 2 × 3 × 4</td><td>24</td></tr>
<tr>
<td>5!</td><td>1 × 2 × 3 × 4 × 5</td><td>120</td></tr>
<tr>
<td>6!</td><td>1 × 2 × 3 × 4 × 5 × 6</td><td>720</td></tr>
<tr>
<td>7!</td><td>1 × 2 × 3 × 4 × 5 × 6 × 7</td><td>5040</td></tr>
<tr>
<td>8!</td><td>1 × 2 × 3 × 4 × 5 × 6 × 7 × 8</td><td>40,320</td></tr>
<tr>
<td>9!</td><td>1 × 2 × 3 × 4 × 5 × 6 × 7 × 8 × 9</td><td>362,880</td></tr>
</tbody>
</table>
</div><h2 id="heading-what-is-a-factorial-used-for">What is a Factorial Used For?</h2>
<p>Practically speaking, a factorial is the number of different permutations you can have with <code>n</code> items: 3 items can be arranged in exactly 6 different ways (expressed as <code>3!</code>). </p>
<p>For example, let's see all the arrangements you can have with the three items, A, B and C:</p>
<pre><code class="lang-text">ABC
ACB
BAC
BCA
CAB
CBA
</code></pre>
<p>And in fact, <code>3! = 6</code>.</p>
<h3 id="heading-how-to-calculate-the-factorial-of-0">How to Calculate the Factorial of 0</h3>
<p>Looking at the factorial from this point of view, what's the factorial of 0?</p>
<p>Well, how many different ways can you arrange 0 elements? </p>
<p>There is exactly 1 way to arrange zero elements. And that's making a sequence of zero elements.</p>
<h3 id="heading-factorial-use-cases">Factorial Use Cases</h3>
<p>You typically use a factorial when you have a problem related to the number of possible arrangements. Let's look at some example problems.</p>
<h4 id="heading-factorial-example-problem-1-the-letters-in-the-word-camper">Factorial example problem 1: the letters in the word "camper"</h4>
<p><em>How many different ways can you arrange the letters of the word <code>camper</code>?</em></p>
<p>The word <code>camper</code> has 6 letters, so the number of possible arrangements is given by the factorial of 6: <code>6! = 6 × 5 × 4 × 3 × 2 × 1 = 720</code>. That would have been a pretty big number of arrangements to find by hand, wouldn't it?</p>
<h4 id="heading-factorial-example-problem-2-drawing-colored-balls-from-a-bag">Factorial example problem 2: drawing colored balls from a bag</h4>
<p>Let's say there are three balls in a bag – one green, one blue, and one yellow.</p>
<p>If you draw the three balls in sequence, what chance is there that you'll get the yellow first, the green one second, and the blue one last?</p>
<p>Maybe now you are wondering what chances have to do with factorials – well, in a moment you will see.</p>
<p>There are 6 possible sequences in which the balls can be drawn: 3! = 6.</p>
<p>There is a chance of 1 over the total number of possibilities to get the yellow-green-blue sequence, so that is <code>1/(3!)</code> or <code>1/6</code> or <code>16.7%</code> chance to get the desired outcome.</p>
<h2 id="heading-how-to-calculate-a-factorial-programmatically-with-javascript">How to Calculate a Factorial Programmatically with JavaScript</h2>
<p>There are two ways to calculate factorials programmatically in JavaScript:</p>
<h3 id="heading-how-to-calculate-a-factorial-in-js-with-recursion">How to calculate a factorial in JS with recursion</h3>
<p>Let's get back to the two things to know when calculating a factorial – that is <code>0! = 1</code> and <code>n! = (n - 1)! × n</code>. We can use the first one to create the base case of the recursive function, because in that case we know the result already.</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">factorial</span>(<span class="hljs-params">n</span>) </span>{
  <span class="hljs-keyword">if</span> (n === <span class="hljs-number">0</span>) {
      <span class="hljs-keyword">return</span> <span class="hljs-number">1</span>;
  }
}
</code></pre>
<p>The second thing to know about how to calculate a factorial, <code>n! = (n - 1)! × n</code>, can be the recursive case.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">factorial</span>(<span class="hljs-params">n</span>) </span>{
    <span class="hljs-keyword">if</span> (n === <span class="hljs-number">0</span>) {
        <span class="hljs-keyword">return</span> <span class="hljs-number">1</span>;
    } <span class="hljs-keyword">else</span> {
        <span class="hljs-keyword">return</span> factorial(n<span class="hljs-number">-1</span>) * n;
    }
}
</code></pre>
<h3 id="heading-how-to-calculate-a-factorial-with-a-javascript-while-loop">How to calculate a factorial with a JavaScript <code>while</code> loop</h3>
<p>We said before that <code>0! = 1</code>. So, to calculate the factorial of a number with a loop, we can initialize a variable to <code>1</code>, and multiply the numbers from <code>n</code> to <code>1</code> by the variable inside the loop.</p>
<p>In this way, if the input is higher than 1, the output will easily be 1.</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">factorial</span>(<span class="hljs-params">n</span>) </span>{
    <span class="hljs-keyword">let</span> result = <span class="hljs-number">1</span>;
    <span class="hljs-keyword">for</span> (n &gt; <span class="hljs-number">1</span>) {
        result *= n;
        n--;
    }
    <span class="hljs-keyword">return</span> result;
}
</code></pre>
<h2 id="heading-conclusion">Conclusion</h2>
<p>The factorial is a pretty important operator to know if you are interested in statistics and probabilities.</p>
<p>In this article you have learned a how to calculate a factorial, a simple application, and you have seen how to calculate it using JavaScript.</p>
<p>Have fun with it!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ CSS Functions – How to Use calc(), max(), min(), and clamp() ]]>
                </title>
                <description>
                    <![CDATA[ In CSS there are a lot of different units of measurement. You have px and percentages, vh, vw, em, rem, and others.  There will come a time when you want to get a value by combining two or more different units. CSS has a function that you can use ]]>
                </description>
                <link>https://www.freecodecamp.org/news/css-functions-for-beginners/</link>
                <guid isPermaLink="false">66b0c38029f55a5720e05547</guid>
                
                    <category>
                        <![CDATA[ beginners guide ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ilenia Magoni ]]>
                </dc:creator>
                <pubDate>Wed, 18 May 2022 15:11:08 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/05/pexels-katerina-holmes-5905965.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In CSS there are a lot of different units of measurement. You have px and percentages, vh, vw, em, rem, and others. </p>
<p>There will come a time when you want to get a value by combining two or more different units. CSS has a function that you can use to make such calculations – <code>calc()</code>. And in this tutorial, you'll learn how it works.</p>
<p>There are other functions you can use with these relative units – like <code>max</code>, <code>min</code> and <code>clamp</code> – that, when confronted with different values, use the appropriate one. These are really useful in responsive layouts, and can be an alternative to using media queries.</p>
<p>If you learn to use them appropriately you can avoid the jumpy change of layout that can happen when resizing a window if you used media queries, and with less code!</p>
<h2 id="heading-how-to-use-the-css-calc-function">How to Use the CSS <code>calc()</code> Function</h2>
<p>The calc function takes a single parameter. This parameter can be an expression combining any length unit and the four mathematical operators <code>+</code>, <code>-</code>, <code>/</code>, <code>*</code>.</p>
<p>You can also use parenthesis to indicate an order of evaluation different than the standard precedence rules.</p>
<p>In the expression inside the <code>calc()</code> function you can use CSS variables, values obtained with <code>[attr()](https://developer.mozilla.org/en-US/docs/Web/CSS/attr)</code>, and values from the functions <code>max()</code>, <code>min()</code> and <code>clamp()</code>.</p>
<p><code>calc()</code> allows you to calculate a value from complex parameters.</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">div</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-built_in">calc</span>(<span class="hljs-number">100%</span> - <span class="hljs-number">2em</span>);
}
</code></pre>
<p><strong>Note</strong>: always leave a space on either side of the mathematical operators.</p>
<h2 id="heading-how-to-use-the-css-max-function">How to Use the CSS <code>max()</code> Function</h2>
<p>The <code>max</code> function accepts a list of comma separated values and returns the biggest one. Each value can also be an expression (whatever you can use as an argument for the <code>calc()</code> function can be one of the arguments in this function, too).</p>
<p>The max function can be seen as a way to determine a <em>minimum value</em> for a certain thing.</p>
<p>A use case for this function is making a text responsive, while giving a minimum value to the dimension.</p>
<p>For example:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">h1</span> {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-built_in">max</span>(<span class="hljs-number">1rem</span>, <span class="hljs-number">10vh</span>);
}
</code></pre>
<p>In this way, the text will be a tenth of the viewport height, unless the viewport height becomes too small. The text will always have a <code>font-size</code> of at least <code>1rem</code> to ensure legibility.</p>
<h2 id="heading-how-to-use-the-css-min-function">How to Use the CSS <code>min()</code> Function</h2>
<p>In the same way as the max function, <code>min</code> can take any number of arguments, including other <code>max</code>, <code>min</code>, or <code>clamp</code> functions, and give back the smallest value between them.</p>
<p>The min function can be seen as determining a <em>maximum value</em>.</p>
<p>For example, let's say that you are creating a form and you want it to be responsive while the screen width changes. You'll want to give it a maximum width to avoid that horizontally stretched look that can happen on the largest screens.</p>
<p>You could write something like this:</p>
<pre><code class="lang-css"><span class="hljs-selector-class">.form</span> {
    <span class="hljs-attribute">width</span>: <span class="hljs-built_in">min</span>(<span class="hljs-number">600px</span>, <span class="hljs-number">90vw</span>);
}
</code></pre>
<p>Your page will have a width equal to 90% of the viewport width, or 600px wide, whatever is smallest. So if the viewport width is larger than ~670px, the form will not stretch horizontally.</p>
<h2 id="heading-example-for-min-and-max">Example for <code>min()</code> and <code>max()</code>:</h2>
<p>You can see the code snippets at work in this pen. Try resizing the pen horizontally and vertically and see the form width and font size change responsively.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/nethleen/embed/XWZMGVd" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<h2 id="heading-how-to-use-the-css-clamp-function">How to Use the CSS <code>clamp()</code> Function</h2>
<p>The clamp function clamps a value between and upper and lower limit. It selects a value in a range with defined limits.</p>
<p><code>clamp</code> takes three values. The first one will be the minimum value, the second one the preferred value, and the third one the maximum value. </p>
<p>The clamp function will give back the preferred value, unless it is smaller than the minimum value (in which case it will give back the minimum value) or if it is bigger than the maximum value, in which case it will give back the maximum value.</p>
<p>You can use <code>clamp</code> to have layout elements responsively resize within a range.</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">h1</span> {
    <span class="hljs-attribute">font-size</span>: <span class="hljs-built_in">clamp</span>(<span class="hljs-number">1rem</span>, <span class="hljs-number">10vw</span>, <span class="hljs-number">2rem</span>);
}

<span class="hljs-selector-tag">div</span> {
    <span class="hljs-attribute">padding</span>: <span class="hljs-built_in">clamp</span>(<span class="hljs-number">10px</span>, <span class="hljs-number">6vw</span>, <span class="hljs-number">50px</span>);
    <span class="hljs-attribute">width</span>: <span class="hljs-built_in">clamp</span>(<span class="hljs-number">140px</span>, <span class="hljs-number">90vw</span>, <span class="hljs-number">600px</span>);
}
</code></pre>
<h2 id="heading-example-of-clamp-function">Example of <code>clamp</code> Function:</h2>
<p>See it in action in this pen! Resize the pen horizontally and see how the various elements change dimensions.</p>
<div class="embed-wrapper">
        <iframe width="100%" height="350" src="https://codepen.io/nethleen/embed/ExQWJZo" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="CodePen embed" scrolling="no" allowtransparency="true" allowfullscreen="true" loading="lazy"></iframe></div>
<p>The MDN has more detailed info on all of these functions:</p>
<ul>
<li><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/calc">calc</a></li>
<li><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/max">max</a></li>
<li><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/min">min</a></li>
<li><a target="_blank" href="https://developer.mozilla.org/en-US/docs/Web/CSS/clamp">clamp</a></li>
</ul>
<p>And with this, you have seen an overview of these four marvelous functions. You have learned enough to start using them, so go out there and have fun!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Concatenate in Excel – How to Use the Concat Function ]]>
                </title>
                <description>
                    <![CDATA[ Excel has many useful functions that you can use to work with your data. In this guide you will learn about the CONCAT function and how to use it. Concatenation just means to join two things together. And in Excel, you can use the CONCAT function to ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/concatenate-in-excel-how-to-use-the-concat-function/</link>
                <guid isPermaLink="false">66b0c37be379be09b93a1bd3</guid>
                
                    <category>
                        <![CDATA[ excel ]]>
                    </category>
                
                    <category>
                        <![CDATA[ spreadsheets ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ilenia Magoni ]]>
                </dc:creator>
                <pubDate>Thu, 12 May 2022 19:26:13 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/05/pexels-yan-krukov-7693224.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Excel has many useful functions that you can use to work with your data.</p>
<p>In this guide you will learn about the <code>CONCAT</code> function and how to use it.</p>
<p>Concatenation just means to join two things together. And in Excel, you can use the <code>CONCAT</code> function to join data from multiple cells into one cell. Let's see how it works.</p>
<h2 id="heading-syntax-of-the-concat-function">Syntax of the CONCAT function</h2>
<p>The general syntax of the CONCAT function is:</p>
<pre><code class="lang-text">=CONCAT(text1; [text2; ...])
</code></pre>
<p>Where the arguments are:</p>
<ul>
<li><code>text1</code> is a required argument that can be a string or an array of strings (like a range of cells).</li>
<li><code>[text2, ...]</code> identifies the optional arguments that follow. There can be up to 253 text arguments, and each one can also be a string or an array of strings (such as a range of cells).</li>
</ul>
<h2 id="heading-how-to-use-the-concat-function-in-excel">How to use the CONCAT function in Excel</h2>
<p>To use the CONCAT function, you will need to click on the cell in which you want the result to appear, and type <code>=CONCAT(</code> there. </p>
<p>After that you can click on the cells, or range of cells, you want to concatenate (or join) together – you will need to keep the Ctrl button pressed to add multiple arguments.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/image-67.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/image-68.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/image-69.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Like you can see in these screenshots, we are writing <code>=CONCAT(</code> in the cell D1 and then clicking on the cells A1 and B1 while keeping Ctrl pressed. After that, pressing Enter will give the result in the cell D1.</p>
<p>If you want to add text in between the different cells' content, for example a space, you can click on a cell, then type a semicolon and the text you want to add in between quotes, then another semicolon, and finally click on the next cell:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/image-70.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/image-71.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>In this case you would write <code>=CONCAT(</code> in cell D1, then click on cell A1, type a semicolon, then type the space surrounded by strings, <code>" "</code>, followed by another semicolon, and finally click on cell B1. This will result in "Leonardo da Vinci" in cell D1.</p>
<p><strong>Note:</strong> You can concatenate together up to 32,767 characters, which is the cell limit. If the resulting string is longer than 32,767 characters the function will output a <code>#VALUE!</code> error.</p>
<h2 id="heading-examples">Examples</h2>
<p>The <a target="_blank" href="https://support.microsoft.com/en-us/office/concat-function-9b1a9a3f-94ff-41af-9736-694cbd6b4ca2">official Microsoft documentation</a> has three helpful examples of how to use the <code>CONCAT</code> function. Let's examine them.</p>
<h3 id="heading-concat-example-1">CONCAT Example 1:</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>=CONCAT(B:B; C:C)</td><td>A's</td><td>B's</td></tr>
</thead>
<tbody>
<tr>
<td></td><td>a1</td><td>b1</td></tr>
<tr>
<td></td><td>a2</td><td>b2</td></tr>
<tr>
<td></td><td>a4</td><td>b4</td></tr>
<tr>
<td></td><td>a5</td><td>b5</td></tr>
<tr>
<td></td><td>a6</td><td>b6</td></tr>
<tr>
<td></td><td>a7</td><td>b7</td></tr>
</tbody>
</table>
</div><p>If you want to follow along, copy this table and paste its data in cell A1 of a new Excel sheet.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/image-75.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>This function allows for whole column reference, so in the formula <code>=CONCAT(B:B; C:C)</code> you are concatenating the whole column B (<code>B:B</code>) followed by the whole column C (<code>C:C</code>), so the result is <code>A'sa1a2a4a5a6a7B'sb1b2b4b5b6b7</code> – the empty cells do not contribute to the end result.</p>
<h3 id="heading-concat-example-2">CONCAT Example 2:</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>=CONCAT(B2:C8)</td><td>A's</td><td>B's</td></tr>
</thead>
<tbody>
<tr>
<td></td><td>a1</td><td>b1</td></tr>
<tr>
<td></td><td>a2</td><td>b2</td></tr>
<tr>
<td></td><td>a4</td><td>b4</td></tr>
<tr>
<td></td><td>a5</td><td>b5</td></tr>
<tr>
<td></td><td>a6</td><td>b6</td></tr>
<tr>
<td></td><td>a7</td><td>b7</td></tr>
</tbody>
</table>
</div><p>To follow along, copy this table, and paste it in the A1 cell of an empty Excel sheet.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/image-76.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>In this case, it is the cells in the range <code>B2:C8</code> (the range highlighted in the picture) that are being concatenated together, and the formula in the A1 cell will result in <code>a1b1a2b2a4b4a5b5a6b6a7b7</code>. Also in this case the empty cells do not contribute to the result.</p>
<p><strong>Note:</strong> The cells in a range are read row by row, so the cells are concatenated in the order: <code>B2;C2;B3;C3;B4;C4;B5;C5;B6;C6;B7;C7;B8;C8</code> (with B8 and C8 being empty, so not contributing to the end result).</p>
<h3 id="heading-concat-example-3">CONCAT Example 3</h3>
<p>This example has various examples in it, all with the general theme of joining cells with other text. This example illustrates well how you can do a lot of things with the Concat function.</p>
<p>Let's take a look.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Data</td><td>First Name</td><td>Last name</td></tr>
</thead>
<tbody>
<tr>
<td>brook trout</td><td>Andreas</td><td>Hauser</td></tr>
<tr>
<td>species</td><td>Fourth</td><td>Pine</td></tr>
<tr>
<td>32</td><td></td><td></td></tr>
<tr>
<td><strong>Formula</strong></td><td><strong>Description</strong></td><td><strong>Result</strong></td></tr>
<tr>
<td><code>=CONCAT("Stream population for "; A2;" "; A3; " is "; A4; "/mile.")</code></td><td>Creates a sentence by joining the data in column A with other text.</td><td>Stream population for brook trout species is 32/mile.</td></tr>
<tr>
<td><code>=CONCAT(B2;" "; C2)</code></td><td>Joins three things: the string in cell B2, a space character, and the value in cell C2.</td><td>Andreas Hauser</td></tr>
<tr>
<td><code>=CONCAT(C2; ", "; B2)</code></td><td>Joins three things: the string in cell C2, a string with a comma and a space character, and the value in cell B2.</td><td>Hauser, Andreas</td></tr>
<tr>
<td><code>=CONCAT(B3; " &amp; "; C3)</code></td><td>Joins three things: the string in cell B3, a string consisting of a space with ampersand and another space, and the value in cell C3.</td><td>Fourth &amp; Pine</td></tr>
<tr>
<td><code>=B3 &amp; " &amp; " &amp; C3</code></td><td>Joins the same items as the previous example, but by using the ampersand (&amp;) calculation operator instead of the CONCAT function.</td><td>Fourth &amp; Pine</td></tr>
</tbody>
</table>
</div><p>To follow along you can also copy this table in the A1 cell of an empty Excel sheet.</p>
<h4 id="heading-stream-population-for-brook-trout-species-is-32mile">Stream population for brook trout species is 32/mile.</h4>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/image-77.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>The first formula shown in this example joins together the text of three cells (A2, A3 and A4) with a few strings to form a longer sentence.</p>
<p>So, the result is given by the combination of the string <code>"Stream population for "</code> with the content of the cell A2, so <code>"brook trout"</code>, which is then followed by a space (<code>" "</code>), the content of cell A3 (<code>"species"</code>), the string <code>" is "</code>, the content of cell A4 (<code>32</code>), and finally, the string <code>"/mile."</code>. </p>
<p>All together it results in the string <code>"Stream population for brook trout species is 32/mile."</code>.</p>
<p>(For the following screenshots I have hidden the rows of the formulas I have already talked about).</p>
<h4 id="heading-andreas-hauser">Andreas Hauser</h4>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/image-78.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>In this example, the formula <code>=CONCAT(B2; " "; C2)</code> joins together the string from the cell B2, a space <code>" "</code> and the string from the cell C2, resulting in <code>"Andreas Hauser"</code>.</p>
<h4 id="heading-hauser-andreas">Hauser, Andreas</h4>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/image-79.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>From this example you can see that the order in which the cells are written in the <code>CONCAT</code> function arguments matter. The formula <code>=CONCAT(C2; ", "; B2)</code> joins together the strings from cell C2, a comma and a space <code>", "</code> and from cell B2, resulting in <code>"Hauser, Andreas"</code>. </p>
<p>The strings from cells C2 and B2 have been joined in a different order because they have been written in a different order in the arguments of the method.</p>
<h4 id="heading-fourth-amp-pine">Fourth &amp; Pine</h4>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/image-80.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>You can join together any kind of screen. See here where the formula <code>=CONCAT(B3; " &amp; "; C3)</code> joins the string from cell B3 with the string from cell C3 putting in the middle of the two the string with a space, an ampersand and another space, <code>" &amp; "</code> resulting in <code>"Fourth &amp; Pine"</code>. </p>
<h4 id="heading-fourth-amp-pine-ii">Fourth &amp; Pine (II)</h4>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/05/image-81.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>This example shows an alternative method of concatenating strings: using the operator <code>&amp;</code> you can write the list of strings you want to join separated by an ampersand (<code>&amp;</code>). So <code>=B3 &amp; " &amp; " &amp; C3</code> gives the same result as <code>=CONCAT(B3; " &amp; "; C3)</code>.</p>
<p><strong>Note:</strong> You can use the <code>&amp;</code> operator only for single cells, it doesn't work for ranges.</p>
<p>And that's it! Now you know how to use the <code>CONCAT</code> function in Excel. Thanks for reading!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Python Lowercase – How to Use the String lower() Function ]]>
                </title>
                <description>
                    <![CDATA[ Strings are a fundamental part of working with Python. And the lower() method is one of the many integrated methods that you can use to work with strings. In this article, we'll see how to make strings lowercase with the lower() method in Python. Wha... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/python-lowercase-how-to-use-the-string-lower-function/</link>
                <guid isPermaLink="false">66b0c3a6c82f8da076e5b023</guid>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ilenia Magoni ]]>
                </dc:creator>
                <pubDate>Mon, 09 May 2022 22:04:42 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/05/pexels-christina-morillo-1181467--1-.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Strings are a fundamental part of working with Python. And the <code>lower()</code> method is one of the many integrated methods that you can use to work with strings.</p>
<p>In this article, we'll see how to make strings lowercase with the <code>lower()</code> method in Python.</p>
<h2 id="heading-what-is-a-string">What is a string?</h2>
<p>A string is a data type that can contain many different characters. A string is written as a series of characters between single or double quotes.</p>
<pre><code class="lang-python"><span class="hljs-meta">&gt;&gt;&gt; </span>example_string = <span class="hljs-string">'I am a String!'</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>example_string
<span class="hljs-string">'I am a String!'</span>
</code></pre>
<h2 id="heading-what-is-a-method">What is a method?</h2>
<p>A method is a function that can be used on a specific data type. Methods can take or not take arguments.</p>
<p>Sometimes you may wonder if a method exists. In Python you can see the whole list of string methods by using the <code>dir()</code> function with a string as argument, like so:</p>
<pre><code class="lang-python"><span class="hljs-meta">&gt;&gt;&gt; </span>dir(example_string)
[<span class="hljs-string">'__add__'</span>, <span class="hljs-string">'__class__'</span>, <span class="hljs-string">'__contains__'</span>, <span class="hljs-string">'__delattr__'</span>, <span class="hljs-string">'__dir__'</span>, <span class="hljs-string">'__doc__'</span>, <span class="hljs-string">'__eq__'</span>, <span class="hljs-string">'__format__'</span>, <span class="hljs-string">'__ge__'</span>, <span class="hljs-string">'__getattribute__'</span>, <span class="hljs-string">'__getitem__'</span>, <span class="hljs-string">'__getnewargs__'</span>, <span class="hljs-string">'__gt__'</span>, <span class="hljs-string">'__hash__'</span>, <span class="hljs-string">'__init__'</span>, <span class="hljs-string">'__init_subclass__'</span>, <span class="hljs-string">'__iter__'</span>, <span class="hljs-string">'__le__'</span>, <span class="hljs-string">'__len__'</span>, <span class="hljs-string">'__lt__'</span>, <span class="hljs-string">'__mod__'</span>, <span class="hljs-string">'__mul__'</span>, <span class="hljs-string">'__ne__'</span>, <span class="hljs-string">'__new__'</span>, <span class="hljs-string">'__reduce__'</span>, <span class="hljs-string">'__reduce_ex__'</span>, <span class="hljs-string">'__repr__'</span>, <span class="hljs-string">'__rmod__'</span>, <span class="hljs-string">'__rmul__'</span>, <span class="hljs-string">'__setattr__'</span>, <span class="hljs-string">'__sizeof__'</span>, <span class="hljs-string">'__str__'</span>, <span class="hljs-string">'__subclasshook__'</span>, <span class="hljs-string">'capitalize'</span>, <span class="hljs-string">'casefold'</span>, <span class="hljs-string">'center'</span>, <span class="hljs-string">'count'</span>, <span class="hljs-string">'encode'</span>, <span class="hljs-string">'endswith'</span>, <span class="hljs-string">'expandtabs'</span>, <span class="hljs-string">'find'</span>, <span class="hljs-string">'format'</span>, <span class="hljs-string">'format_map'</span>, <span class="hljs-string">'index'</span>, <span class="hljs-string">'isalnum'</span>, <span class="hljs-string">'isalpha'</span>, <span class="hljs-string">'isascii'</span>, <span class="hljs-string">'isdecimal'</span>, <span class="hljs-string">'isdigit'</span>, <span class="hljs-string">'isidentifier'</span>, <span class="hljs-string">'islower'</span>, <span class="hljs-string">'isnumeric'</span>, <span class="hljs-string">'isprintable'</span>, <span class="hljs-string">'isspace'</span>, <span class="hljs-string">'istitle'</span>, <span class="hljs-string">'isupper'</span>, <span class="hljs-string">'join'</span>, <span class="hljs-string">'ljust'</span>, <span class="hljs-string">'lower'</span>, <span class="hljs-string">'lstrip'</span>, <span class="hljs-string">'maketrans'</span>, <span class="hljs-string">'partition'</span>, <span class="hljs-string">'replace'</span>, <span class="hljs-string">'rfind'</span>, <span class="hljs-string">'rindex'</span>, <span class="hljs-string">'rjust'</span>, <span class="hljs-string">'rpartition'</span>, <span class="hljs-string">'rsplit'</span>, <span class="hljs-string">'rstrip'</span>, <span class="hljs-string">'split'</span>, <span class="hljs-string">'splitlines'</span>, <span class="hljs-string">'startswith'</span>, <span class="hljs-string">'strip'</span>, <span class="hljs-string">'swapcase'</span>, <span class="hljs-string">'title'</span>, <span class="hljs-string">'translate'</span>, <span class="hljs-string">'upper'</span>, <span class="hljs-string">'zfill'</span>]
</code></pre>
<p>Of these many string methods, in this article you will learn about the <code>lower()</code> method and how it works.</p>
<h2 id="heading-how-does-the-lower-method-work">How does the <code>lower()</code> method work?</h2>
<p>The <code>lower()</code> method is a string method that returns a new string, completely lowercase. If the original string has uppercase letters, in the new string these will be lowercase. Any lower case letter, or any character that is not a letter, is not affected.</p>
<pre><code>&gt;&gt;&gt; example_string.lower()
<span class="hljs-string">'i am a string!'</span>

&gt;&gt;&gt; <span class="hljs-string">'FREECODECAMP'</span>.lower()
<span class="hljs-string">'freecodecamp'</span>
</code></pre><h2 id="heading-what-to-keep-in-mind-when-using-the-lower-method">What to keep in mind when using the lower method</h2>
<p>The <code>lower()</code> method does a pretty straightforward thing: it creates a new string were all the uppercase letters are now lowercase. But there are a few things to keep in mind when using it. Let's take a look at them.</p>
<h3 id="heading-strings-are-immutable">Strings are immutable</h3>
<p>Strings are an immutable data type, which means they can't be changed. The original string will stay unchanged after you use the <code>lower()</code> method.</p>
<p>In the examples above, the <code>lower()</code> method has acted on the <code>example_string</code> but never changed it. Checking the value of <code>example_string</code> still shows the original value.</p>
<pre><code class="lang-python"><span class="hljs-meta">&gt;&gt;&gt; </span>example_string
<span class="hljs-string">'I am a String!'</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>example_string.lower()
<span class="hljs-string">'i am a string!'</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>example_string
<span class="hljs-string">'I am a String!'</span>
</code></pre>
<h3 id="heading-the-lower-method-returns-a-new-string">The <code>lower()</code> method returns a new string</h3>
<p>The <code>lower()</code> returns a new string. You'll need to save it in a variable if you want to use it again in your code.</p>
<pre><code class="lang-python"><span class="hljs-meta">&gt;&gt;&gt; </span>new_string = example_string.lower()

<span class="hljs-meta">&gt;&gt;&gt; </span>new_string
<span class="hljs-string">'i am a string!'</span>
</code></pre>
<h3 id="heading-strings-are-case-sensitive">Strings are case sensitive</h3>
<p>Strings are case sensitive, so a lowercase string is different than an uppercase string.</p>
<pre><code class="lang-python"><span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-string">'freecodecamp'</span> == <span class="hljs-string">'FREECODECAMP'</span>
<span class="hljs-literal">False</span>
</code></pre>
<p>This is useful when thinking about what the <code>lower()</code> method could be useful for. In the example you will see how this feature makes the <code>lower()</code> method useful and necessary when building a script or program that deals with strings.</p>
<h2 id="heading-lower-method-example-how-to-check-if-the-user-input-matches"><code>lower()</code> method example: how to check if the user input matches</h2>
<p>Let's write a small script that asks the user a question and waits for input, and gives feedback about the user's answer.</p>
<pre><code class="lang-python">answer = input(<span class="hljs-string">"What color is the sun? "</span>)
<span class="hljs-keyword">if</span> answer == <span class="hljs-string">"yellow"</span>:
  print(<span class="hljs-string">"Correct!"</span>)
<span class="hljs-keyword">else</span>:
  print(<span class="hljs-string">"That is not the correct color!"</span>)
</code></pre>
<p>This script asks the user a question, "What color is the sun?", and waits for an answer. Then it checks if the answer is "yellow", and if it is it prints "Correct!" If it isn't, it prints "That is not the correct color!".</p>
<p>But there is an issue with this script.</p>
<p>Running this script, you will have this question asked in the terminal:</p>
<pre><code class="lang-shell">$ python sun_color.py
What color is the sun?
</code></pre>
<p>If you answer "Yellow", it says:</p>
<pre><code class="lang-shell">$ python sun_color.py
What color is the sun? Yellow
That is not the correct color!
</code></pre>
<p>Why does this happen?</p>
<p>Remember that strings are case sensitive. The script is checking if the user input the string <code>yellow</code> – <code>Yellow</code>, with a capital "Y", is a different string.</p>
<p>You can easily fix this by using the <code>lower()</code> method, and doing this small change to the <code>sun_color.py</code> file:</p>
<pre><code class="lang-python">answer = input(<span class="hljs-string">"What color is the sun? "</span>)
<span class="hljs-keyword">if</span> answer.lower() == <span class="hljs-string">"yellow"</span>:
  print(<span class="hljs-string">"Correct!"</span>)
<span class="hljs-keyword">else</span>:
  print(<span class="hljs-string">"That is not the correct color!"</span>)
</code></pre>
<p>And now, if you try again...</p>
<pre><code>&gt;&gt;&gt; python sun_color.py
What color is the sun? Yellow
Correct!
</code></pre><p>What changed? Writing <code>answer.lower()</code> you make sure that the checked string is completely lower case before comparing it with the correct answer string "yellow". In this way it doesn't matter if the user writes "YELLOW" or "yELLOW" or "yellow" – it is all converted to lowercase.</p>
<p>Thanks for reading! Now you know how to use the <code>lower()</code> method in JavaScript.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ SQL Inner Join – How to Join 3 Tables in SQL and MySQL ]]>
                </title>
                <description>
                    <![CDATA[ When you're working with your database, you might need to put together data from a few different tables. This article will show you how. I have already written about SQL joins here and here, but let's take a moment to review how a join works first, a... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/sql-inner-join-how-to-join-3-tables-in-sql-and-mysql/</link>
                <guid isPermaLink="false">66b0c3b0cde8fd3100cae199</guid>
                
                    <category>
                        <![CDATA[ database ]]>
                    </category>
                
                    <category>
                        <![CDATA[ MySQL ]]>
                    </category>
                
                    <category>
                        <![CDATA[ SQL ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ilenia Magoni ]]>
                </dc:creator>
                <pubDate>Fri, 01 Apr 2022 18:19:05 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/04/pexels-pixabay-269399--1-.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>When you're working with your database, you might need to put together data from a few different tables. This article will show you how.</p>
<p>I have already written about SQL joins <a target="_blank" href="https://www.freecodecamp.org/news/sql-join-types-inner-join-vs-outer-join-example/">here</a> and <a target="_blank" href="https://www.freecodecamp.org/news/sql-left-join-example-join-statement-syntax/">here</a>, but let's take a moment to review how a join works first, and particularly the syntax specific to MySQL.</p>
<h2 id="heading-sql-join-statement">SQL Join Statement</h2>
<p>Join is a statement that lets you put together two tables, matching rows that are related to each other, and keeping only the rows that can be matched, not keeping unpaired rows.</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> * <span class="hljs-keyword">FROM</span> table1 
  <span class="hljs-keyword">INNER</span> <span class="hljs-keyword">JOIN</span> table2
  <span class="hljs-keyword">ON</span> table1.id = table2.id;
</code></pre>
<p>The <code>SELECT ... FROM</code> statement indicates which is the first table, then the second table name is written just after the <code>INNER JOIN</code> keywords. </p>
<p>How the two tables should be joined is written in the <code>ON</code> statement. In this case the two tables are joined using the relationship <code>table1.id = table2.id</code>.</p>
<p>It is possible to use multiple join statements together to join more than one table at the same time.</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> *
  <span class="hljs-keyword">FROM</span> table1
  <span class="hljs-keyword">INNER</span> <span class="hljs-keyword">JOIN</span> table2
  <span class="hljs-keyword">ON</span> table1.id = table2.id
  <span class="hljs-keyword">INNER</span> <span class="hljs-keyword">JOIN</span> table3
  <span class="hljs-keyword">ON</span> table2.id = table3.id;
</code></pre>
<p>To do that you add a second <code>INNER JOIN</code> statement and a second <code>ON</code> statement to indicate the third table and the second relationship.</p>
<p>Let's talk a moment about the relationships you can have between tables and why you might want to join three tables together.</p>
<h2 id="heading-relationships-between-tables-in-sql">Relationships Between Tables in SQL</h2>
<p>When you have tables that are related to each other, their relationships could be one of various types.</p>
<h3 id="heading-one-to-many">one-to-many</h3>
<p>In a one-to-many kind of relationship, one row of the first table can be related to multiple rows of the second table.</p>
<p>In a relational database this can be implemented with the second table having a <code>first_table_id</code> column that says to which row of the first table that row is related.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/image-11.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-many-to-one">many-to-one</h3>
<p>In a many-to-one kind of relationship, one row of the first table can be related to one single row of the second table, and one row of the second table can be related to multiple rows of the first table.</p>
<p>In a relational database this can be implemented with the first table having a <code>second_table_id</code> column that says to which row of the second table that row is related.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/image-10.png" alt="Image" width="600" height="400" loading="lazy">
<em>Many-to-one</em></p>
<h3 id="heading-many-to-many">many-to-many</h3>
<p>In this case multiple rows are related to multiple rows.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/image-9.png" alt="Image" width="600" height="400" loading="lazy">
<em>Many-to-many</em></p>
<p>This kind of relationship can't be represent as is with SQL tables – you need to add a coupling table between the two tables so that only many-to-one and one-to-many relationships are present between tables. </p>
<p>Each row of the table in the middle represents one relationship between the rows of the left table and and the rows of the right table.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/11/image-12.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>In practice in MySQL, that middle table will have a column for <code>first_table_id</code> and a column for <code>second_table_id</code>, with each combination being unique.</p>
<h2 id="heading-joining-sql-tables-in-practice">Joining SQL Tables in Practice</h2>
<p>Let's imagine we have an organization's database, where we have a table with teams (their name, and other identifing info), and a table with projects (name, progress, and so on).</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>id</td><td>team_name</td><td>specialty</td></tr>
</thead>
<tbody>
<tr>
<td>1</td><td>Banana Throwers</td><td>Bananas</td></tr>
<tr>
<td>2</td><td>Wood gnawers</td><td>Gnawing on wood</td></tr>
<tr>
<td>3</td><td>The Pink Elephants</td><td>Stomping on the ground</td></tr>
<tr>
<td>4</td><td>Fluffy potatoes</td><td>Working and sleeping</td></tr>
</tbody>
</table>
</div><div class="hn-table">
<table>
<thead>
<tr>
<td>id</td><td>project_name</td><td>progress</td></tr>
</thead>
<tbody>
<tr>
<td>1</td><td>Dam building</td><td>Some more wood gnawing and ground stomping needed</td></tr>
<tr>
<td>2</td><td>Banana Cake</td><td>Someone is eating all the bananas</td></tr>
<tr>
<td>3</td><td>Sleep research</td><td>To much sleeping not enough research</td></tr>
</tbody>
</table>
</div><p>As a team can work on multiple projects, and a project can be worked on by multiple teams, there is also a third table that keeps track of team-project matches.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>project_id</td><td>group_id</td></tr>
</thead>
<tbody>
<tr>
<td>1</td><td>2</td></tr>
<tr>
<td>1</td><td>3</td></tr>
<tr>
<td>2</td><td>1</td></tr>
<tr>
<td>3</td><td>1</td></tr>
<tr>
<td>3</td><td>2</td></tr>
<tr>
<td>3</td><td>3</td></tr>
<tr>
<td>3</td><td>4</td></tr>
</tbody>
</table>
</div><p>We can use a <code>JOIN</code> statement to put everything together when we need to view the info from the tables in a human readable way, like this:</p>
<pre><code class="lang-mysql">SELECT
  teams.team_name AS team_name,
  projects.project_name AS project_name
FROM TABLE teams
INNER JOIN matches
  ON teams.id = matches.team_id
INNER JOIN matches
  ON matches.project_id = projects.id
ORDER BY teams.id;
</code></pre>
<p>We choose which columns to show from each table with a <code>SELECT</code> statement.</p>
<p>We specify how the rows of the tables are to be combined with an <code>ON</code> statement.</p>
<p>And we order the rows in the way we prefer with an <code>ORDER BY</code> statement.</p>
<p>The <code>ON</code> statements <code>teams.id = matches.team_id</code> and <code>matches.projects_id = projects.id</code> mean that the rows are combined using the rows of the <code>matches</code> table. Each row of the output table has the project name and the team name combined using the pairs of project id and team id in the <code>matches</code> table.</p>
<p>The output table will look like below. </p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Team_name</td><td>Project_name</td></tr>
</thead>
<tbody>
<tr>
<td>Banana Throwers</td><td>Banana Cake</td></tr>
<tr>
<td>Banana Throwers</td><td>Sleep Research</td></tr>
<tr>
<td>Wood gnawers</td><td>Dam Bulding</td></tr>
<tr>
<td>Wood gnawers</td><td>Sleep Research</td></tr>
<tr>
<td>The Pink Elephants</td><td>Dam Building</td></tr>
<tr>
<td>The Pink Elephants</td><td>Dam Building</td></tr>
<tr>
<td>Fluffy potatoes</td><td>Sleep Research</td></tr>
</tbody>
</table>
</div><p>There is no column directly from the <code>matches</code> table. The <code>matches</code> table is not shown in the output but it is used as instructions for how to combine the rows of the <code>teams</code> and <code>projects</code> tables.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>The <code>JOIN</code> statement lets you join together one or more tables. It has to be used in conjunction with the <code>ON</code> statement to determine the relationship between the rows of a table and the rows of a different table. </p>
<p>In this article you have learned how to use the <code>JOIN</code> statement to join together three different tables.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Learn to Code RPG Player Guide – How to Unlock All Achievements and Endings ]]>
                </title>
                <description>
                    <![CDATA[ In this guide, you'll learn to how to collect all 54 achievements and reach all six endings of the Learn to Code RPG.  According to the game's creator, Lynn Zheng, Learn to Code RPG is an interactive visual novel game where you will teach yourself t... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learntocoderpg-player-guide-how-to-unlock-all-achievements-and-endings/</link>
                <guid isPermaLink="false">66b0c3a293daff72552fc865</guid>
                
                    <category>
                        <![CDATA[ freeCodeCamp.org ]]>
                    </category>
                
                    <category>
                        <![CDATA[ #Game Design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Game Development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Video games ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ilenia Magoni ]]>
                </dc:creator>
                <pubDate>Mon, 31 Jan 2022 21:32:45 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/01/Splash-Art-2.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In this guide, you'll learn to how to collect all 54 achievements and reach all six endings of the Learn to Code RPG. </p>
<p>According to the game's creator, <a target="_blank" href="https://www.freecodecamp.org/news/author/lynn/">Lynn Zheng</a>,</p>
<blockquote>
<p><strong>Learn to Code RPG</strong> is an interactive visual novel game where you will teach yourself to code, make friends in the tech industry, and pursue your dream of becoming a developer. 🎯</p>
</blockquote>
<p>If this is the first time you're hearing about this game, you can <a target="_blank" href="https://freecodecamp.itch.io/learn-to-code-rpg">download it and play it first on your own</a>. </p>
<p>And if you want to learn more about the game from Lynn herself, <a target="_blank" href="https://www.freecodecamp.org/news/learn-to-code-rpg/">check out this introductory article</a>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/01/image-139.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-learn-to-code-rpg-story-milestones">Learn to Code RPG Story Milestones</h2>
<p>These are the achievements that you get for sure by following the storyline.</p>
<p><strong>3, 2, 1, Learn to Code!</strong> You'll get this achievement the first time you start working on the quizzes.</p>
<p><strong>Got My First Interview!</strong> You get this achievement once your character goes through their first interview after completing the curriculum.</p>
<p><strong>Got My First Offer!</strong> Once you receive your first job offer you get this achievement.</p>
<p><strong>Gotta Crush Those Technical Interviews!</strong> Once you start preparing for the technical interviews you get this achievement.</p>
<p><strong>Nailed the Curriculum!</strong> You unlock this achievement once you reach a CS Knowledge of 60 or more, enough to allow you to go to the next step. </p>
<p><strong>Now Streaming: My Dream Dev Job</strong> You unlock this achievement once you accept an offer for a dev job.</p>
<p><strong>Submitted My First Dev Job Application!</strong> When you submit your first job application, you get this achievement.</p>
<h2 id="heading-learn-to-code-rpg-story-easter-eggs">Learn to Code RPG Story Easter Eggs</h2>
<p>You can unlock these special achievements mostly by making certain choices in the game, by employing some skill, or in some cases by pure chance.</p>
<p><strong>Applied to CupcakeCPU Through a Recruiter</strong>: This achievement has the prerequisite of getting all the questions of the trivia quiz at the Hacker Space right. This will give you the opportunity to apply to CupcakeCPU.</p>
<p><strong>Asked My Tech-Savvy Friends about Tech Buzzwords</strong>: Ask about one of the buzzwords you discovered by eavesdropping on people's conversations.</p>
<p><strong>Barista Is My Undercover Identity for Collecting Buzzwords</strong>: You unlock this one during your first Barista shift.</p>
<p><strong>Beat Up AI at Pong</strong>: beat the Pong AI to unlock this achievement.</p>
<p><strong>Chill Beats to Code to</strong>: listen to music during one of your rest days.</p>
<p><strong>Chill Beats to Smash Keyboard to</strong>: play the rythm game during one of your rest days.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2021-12-17-at-19.33.39.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><strong>Flunked All Quizzes in a Session</strong>: Get all questions in a session wrong.</p>
<p><strong>Got Beaten Up by AI at Pong</strong>: lose at Pong. </p>
<p><strong>Got a Nearly Perfect Score on ALL Music Tracks</strong>: Get above 95% for all tracks. See next achievements for details.</p>
<p><strong>Got a Nearly Perfect Score on My Favorite Music Track</strong>: Get this achievement for reaching a score above 95%. For reference to reach 90% you need at least 3/4 of your scores to be perfects (100pt each) and 1/4 to be goods (60pt each).</p>
<p><strong>Hanging Out at the Hacker Space</strong>: you get this achievement after hanging out at the Hacker Space for the first time.</p>
<p><strong>I Might Get a Puppy Just So I Can Go to the Park</strong>: Go take a walk on one of your rest days.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/01/image-140.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><strong>Late-night Cookie Crunch</strong>: When confronted with all the certifications available in the freeCodeCamp curriculum, choose Quality Assurance and go grab a cookie.</p>
<p><strong>Maxed Out ALL CS Knowledge Stats</strong>: Max out all of the CS Knowledge Stats.</p>
<p><strong>Maxed Out One CS Knowledge Stat</strong>: Max out one of the CS Knowledge Stats.</p>
<p><strong>Nailed All Quizzes in a Session</strong>: Get all quizzes in a session right.</p>
<p><strong>Referred by a VIP Member</strong>: In the intro, after the disaster of an interview you are asked how you came across the opportunity. If you say you were referred by certain people, for example, me, you can get the achievement. (Fine, the complete list of names is Quincy, Lynn, Abbey, Estefania, Jessica, Oliver, Ilenia, Dionysia, Naomi, Yoko, Daniel, Beau.)</p>
<p><strong>Rejected? Well, The First One Seldom Works Out</strong>: Be rejected by a job you applied to for the first time.</p>
<p><strong>Rejected Again? I Thought Third Time Was the Charm</strong>: Be rejected by a job you applied to for the third time.</p>
<p><strong>Set a New High Score in the Rhythm Game</strong>: available from the second time you play a song, just get a new high score!</p>
<p><strong>Tech Buzzword Encyclopedia</strong>: collect all buzzwords at the coffee shop.</p>
<p><strong>Tech Trivia Guru</strong>: Answer correctly to all questions in the Trivia quiz at the Hacker Space.</p>
<p><strong>The Hacker Space Is My Second Home Now</strong>: Experience all events at Hacker Space.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2021-12-18-at-12.40.00-copy.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><strong>This Job Needs Me to... ?</strong>: there are 6 achievements of this kind, related to job interviews. You could find job postings that have strange skill requirements, and finding those you unlock these achievements. The whole list of skill requirements is: <strong>Brew Coffee</strong>, <strong>Fix Fax Machines</strong>, <strong>Fuse Cables</strong>, <strong>Handle Angry Customers</strong>, <strong>Pacify Office Pets</strong>, and <strong>Retrieve Lost Passwords</strong>.</p>
<p><strong>Travel in Time and SAVE the World</strong>: unlock one of the alternative endings (ones that are not getting a dev job) and then go back in time to continue playing.</p>
<p><strong>You Can Never Be Too Careful with Prod</strong>: get a dev job, and once it's time to push your code to production, check your code again and again as many times as possible.</p>
<h2 id="heading-quiz-question-easter-eggs">Quiz Question Easter Eggs</h2>
<p>These are achievements that are unlocked by chance while you complete the quizzes. If you get one of the questions about freeCodeCamp right, you unlock one of these achievements.</p>
<ul>
<li>Contribute to Open Source with freeCodeCamp!</li>
<li>Dr. DevDocs.io</li>
<li>Hello, Earth to Code Radio!</li>
<li>The Launch of freeCodeCamp</li>
<li>The Mission of freeCodeCamp</li>
<li>The Tech Stack of freeCodeCamp</li>
<li>What inspired freeCodeCamp?</li>
<li>freeCodeCamp Has a Chat Server? Fancy!</li>
<li>freeCodeCamp Has a Forum? Neat!</li>
<li>freeCodeCamp Has a Mascot? Cute!</li>
</ul>
<h2 id="heading-alternative-learn-to-code-rpg-endings">Alternative Learn to Code RPG Endings</h2>
<p>These are the achievements you unlock by playing the six different endings. There's one you can get to easily just by following the main storylines – but the others are all about chance. There is a small chance of the event that unlocks the ending happening in certain moments.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/01/Screen-Shot-2021-12-17-at-18.51.41.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><strong>Cat Who Codes</strong>: this ending involves Mint the cat, during the night you could be woken up by the cat doing something...<br>Coding It Forward: during dinner you could have the chance to become a coding tutor, accept the offer to unlock this ending.<br>Dev Who Brought Down Prod on the First Day: get a dev job and play till the end to unlock this one.<br>Just Another Day at the Office: while going through job postings you could find one unrelated to coding, for an office job. Accept that job to unlock this ending.<br>Nature Lover at Heart: each day of forced rest there is a small chance that the character may come to the conclusion that learning to code is too much and decide to do something different...<br>Now serving <code>0xc0ffee</code>: you could be offered a promotion at the Coffee Shop, accept it to unlock this ending.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>This is the list of achievements for the release on December 22nd. I hope you can satisfy your completionist spirit with this guide. Have nice replays!</p>
<p>If you want to learn more about the game you can read the article <em><a target="_blank" href="https://www.freecodecamp.org/news/learn-to-code-rpg-press-kit/">Learn to Code RPG – A Visual Novel Video Game Where you Learn Computer Science Concepts</a></em> from the game dev herself about the process of creating the game.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Lambda Function in Python – Example Syntax ]]>
                </title>
                <description>
                    <![CDATA[ Lambda functions are anonymous functions that can contain only one expression. You may think that lambda functions are an intermediate or advanced feature, but here you will learn how you can easily start using them in your code. In Python, functions... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/lambda-function-in-python-example-syntax/</link>
                <guid isPermaLink="false">66b0c39f4d2b90ec4a447a56</guid>
                
                    <category>
                        <![CDATA[ beginner ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Lambda Expressions ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ilenia Magoni ]]>
                </dc:creator>
                <pubDate>Mon, 27 Sep 2021 15:23:43 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/09/pexels-aleksandar-pasaric-4344759.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Lambda functions are anonymous functions that can contain only one expression.</p>
<p>You may think that lambda functions are an intermediate or advanced feature, but here you will learn how you can easily start using them in your code.</p>
<p>In Python, functions are usually created like this:</p>
<pre><code class="lang-pithon">def my_func(a):
  # function body
</code></pre>
<p>You declare them with the <code>def</code> keyword, give them a name, and then add the list of arguments surrounded by round parenthesis. There could be many lines of code, with as many statements and expressions as you need inside.</p>
<p>But sometimes you might need a function with only one expression inside, for example a function that doubles its argument:</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">double</span>(<span class="hljs-params">x</span>):</span>
  <span class="hljs-keyword">return</span> x*<span class="hljs-number">2</span>
</code></pre>
<p>This is a function that you can use, for example, with the <code>map</code> method.</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">double</span>(<span class="hljs-params">x</span>):</span>
  <span class="hljs-keyword">return</span> x*<span class="hljs-number">2</span>

my_list = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>]
new_list = list(map(double, my_list))
print(new_list) <span class="hljs-comment"># [2, 4, 6, 8, 10, 12]</span>
</code></pre>
<p>This would be a good place to use a lambda function, as it can be created exactly where you need to use it. This means using fewer lines of code and and you can avoid creating a named function that is only used once (and then has to be stored in memory).</p>
<h2 id="heading-how-to-use-lambda-functions-in-python">How to use lambda functions in Python</h2>
<p>You use lambda functions when you need a small function for a short time – for example as an argument of a higher order function like <code>[map](https://www.freecodecamp.org/news/python-map-function-how-to-map-a-list-in-python-3-0-with-example-code/)</code> or <code>filter</code>. </p>
<p>The syntax of a lambda function is <code>lambda args: expression</code>. You first write the word <code>lambda</code>, then a single space, then a comma separated list of all the arguments, followed by a colon, and then the expression that is the body of the function.</p>
<p>Note that you can't give a name to lambda functions, as they are anonymous (without a name) by definition.</p>
<p>A lambda function can have as many arguments as you need to use, but the body must be one single expression.</p>
<h3 id="heading-example-1">Example 1</h3>
<p>For example, you could write a lambda function that doubles its argument: <code>lambda x: x*2</code>, and use it with the <code>map</code> function to double all elements in a list:</p>
<pre><code class="lang-python">my_list = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>]
new_list = list(map(<span class="hljs-keyword">lambda</span> x: x*<span class="hljs-number">2</span>, my_list))
print(new_list) <span class="hljs-comment"># [2, 4, 6, 8, 10, 12]</span>
</code></pre>
<p>Notice the difference between this one and the function we wrote above with the <code>double</code> function. This one is more compact, and there is not an extra function occupying space in memory.</p>
<h3 id="heading-example-2">Example 2</h3>
<p>Or you could write a lambda function that checks if a number is positive, like <code>lambda x: x &gt; 0</code>, and use it with <code>filter</code> to create a list of only positive numbers.</p>
<pre><code class="lang-python">my_list = [<span class="hljs-number">18</span>, <span class="hljs-number">-3</span>, <span class="hljs-number">5</span>, <span class="hljs-number">0</span>, <span class="hljs-number">-1</span>, <span class="hljs-number">12</span>]
new_list = list(filter(<span class="hljs-keyword">lambda</span> x: x &gt; <span class="hljs-number">0</span>, my_list))
print(new_list) <span class="hljs-comment"># [18, 5, 12]</span>
</code></pre>
<p>The lambda function is defined where it is used, in this way there is not a named function in memory. If a function is used i only one place it makes sense to use a lambda function to avoid cluttering.</p>
<h3 id="heading-example-3">Example 3</h3>
<p>You can also return a lambda function from a function.</p>
<p>If you ever need to create multiple functions that multiply numbers, for example doubling or tripling and so on, lambda can help.</p>
<p>Instead of creating multiple functions, you could create a function <code>multiplyBy</code> as below, and then call this function multiple times with different arguments to create the functions that double, triple, and so on.</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">muliplyBy</span> (<span class="hljs-params">n</span>):</span>
  <span class="hljs-keyword">return</span> <span class="hljs-keyword">lambda</span> x: x*n

double = multiplyBy(<span class="hljs-number">2</span>)
triple = muliplyBy(<span class="hljs-number">3</span>)
times10 = multiplyBy(<span class="hljs-number">10</span>)
</code></pre>
<p>The lambda function takes the value <code>n</code> from the parent function, so that in <code>double</code> the value of <code>n</code> is <code>2</code>, in <code>triple</code> it is <code>3</code> and in <code>times10</code> it is <code>10</code>. Now calling these functions with an argument will multiply that number.</p>
<pre><code class="lang-python">double(<span class="hljs-number">6</span>)
&gt; <span class="hljs-number">12</span>
triple(<span class="hljs-number">5</span>)
&gt; <span class="hljs-number">15</span>
times10(<span class="hljs-number">12</span>)
&gt; <span class="hljs-number">120</span>
</code></pre>
<p>If you weren't using a lambda function here, you would need to define a different function inside <code>multiplyBy</code>, something like the below:</p>
<pre><code class="lang-python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">muliplyBy</span> (<span class="hljs-params">x</span>):</span>
  <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">temp</span> (<span class="hljs-params">n</span>):</span>
    <span class="hljs-keyword">return</span> x*n
  <span class="hljs-keyword">return</span> temp
</code></pre>
<p>Using a lambda function uses half the lines and makes it more readable.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Lambda functions are a compact way to write functions if your function includes only one small expression. They are not usually something that beginner coders use, but here you have seen how you can easily use them at any level.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ RNG Meaning – What does RNG Stand for in Gaming? ]]>
                </title>
                <description>
                    <![CDATA[ If everything is predictable in a game, that isn't much fun. RNGs, or Random Number Generators, are a way to introduce a touch of randomness and causality you need to spice it up. In this article, we'll learn how random number generators work. How an... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/rng-meaning-what-does-rng-stand-for-in-gaming/</link>
                <guid isPermaLink="false">66b0c3ab4d2b90ec4a447a58</guid>
                
                    <category>
                        <![CDATA[ #Game Design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ gaming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Math ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                    <category>
                        <![CDATA[ random ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ilenia Magoni ]]>
                </dc:creator>
                <pubDate>Wed, 15 Sep 2021 21:55:10 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/09/pexels-pixabay-37534.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>If everything is predictable in a game, that isn't much fun. RNGs, or Random Number Generators, are a way to introduce a touch of randomness and causality you need to spice it up.</p>
<p>In this article, we'll learn how random number generators work.</p>
<h2 id="heading-how-an-analogic-random-number-generator-works">How an Analogic Random Number Generator Works</h2>
<p>The simplest form of a RNG is throwing dice or flipping coins.</p>
<p>Using a single die or coin means that each value has the same probability of occurring. Using multiple dice or coins instead will give a lower probability to the highest and lower values, and a higher probability to the middle values.</p>
<p>The oldest known tabletop game, <a target="_blank" href="https://en.wikipedia.org/wiki/Royal_Game_of_Ur">the Royal Game of Ur</a>, uses four 4-sided dice. Each die can give a value of 0 or 1 meaning that the value obtained by a single dice throw can go from 0 to 4.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/image-1.png" alt="Image" width="600" height="400" loading="lazy">
<em>All the possible combinations obtained by throwing 4 dice, each can give a value of 0 or 1</em></p>
<p>There are 16 possible combinations, of which one gives a value of 0, 4 gives a value of 1, 6 gives a value of 2, 4 gives a value of 3, and one gives a value of 4.</p>
<p>In this case there is a 1/16 or 6.25% chance of getting 0, 1/4 or 25% chance of getting 1, 3/8 or 37.5% chance of getting 2, 1/4 or 25% chance of getting 3 and 1/16 or 6.25% change of getting 4.</p>
<p>More complex games have manuals full of tables to determine something randomly.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/image-2.png" alt="Image" width="600" height="400" loading="lazy">
<em>Part of a table for random effects after drinking a potion. <a target="_blank" href="https://luetkemj.github.io/160419/random-potion-effects-table">Here's the whole table</a>.</em></p>
<p>Any game that uses dice has an analogic random number generator.</p>
<h2 id="heading-how-random-number-generators-work-in-video-games">How Random Number Generators Work in Video Games</h2>
<p>In video games, RNGs are much less noticeable and more complex, and players might not even be aware they exist. <a target="_blank" href="https://www.freecodecamp.org/news/random-number-generator/">There are many ways you can generate a Random Number</a>, but how do you actually use one?</p>
<p>Breaking it down into the simplest terms, using a RNG is not dissimilar from what you saw above with the dice throw used to determine an effect from a table. You just don't see the dice throw.</p>
<p>In a video game, you can use a RNG to determine what kind of loot might be dropped by a fallen enemy, or what you can find in a chest, or what kind of random encounter will await you, or even what the weather will be.</p>
<p>RNGs are used, for example, to live up open world games without the developers having to code every single section of forests and roads and deserts. Instead, developers code some possibilities and let chance determine what happens when the player reaches a certain point in the map. </p>
<p>Will you meet a bear, a wolf pack, or some bandits? The game does its version of rolling a die to determine that.</p>
<p>Let's see how to code a simple example of a Random Number Generator to better understand how they actually work.</p>
<h2 id="heading-how-to-code-a-random-number-generator">How to Code a Random Number Generator</h2>
<p>Most programming languages contain a <code>random</code> function. This function returns a random number, and what kind of random number depends on its implementation.</p>
<p>For example, in <a target="_blank" href="https://www.freecodecamp.org/news/javascript-math-random-method-explained/">JavaScript</a>, <a target="_blank" href="https://www.freecodecamp.org/news/javascript-math-random-method-explained/"><code>Math.random()</code></a> returns a random number between 0 (included) and 1 (not included). In Python, <code>randint</code> from the <code>random</code> module returns a whole number in a range (Python has also a function that does the same as JavaScript's <code>Math.random</code>).</p>
<p>Let's consider a pretty common video game situation: we have an enemy that often drops a common item, but now and then drops something rare. This enemy may be, for example, a wolf that could drop a wolf pelt (common) or a wolf fang (rare). </p>
<p>How do you determine what is "rare"? That depends on you – it can be that 1 in 10 drops is a rare item, or that 1 in 100 drops is a rare item. A middle ground may be a chance of 1 in 25 for a rare items. And to complicate it a bit, there could be also a 1 in 10 chance of no item.</p>
<p>In this case you would need a function that returns a value between 0 and 1.</p>
<p>A chance of 1 in 25 is 4%, and a chance of 1 in 10 is 10%. In decimal form that would be 0.04 and 0.1, respectively. </p>
<p>In this case you can say that a number in the range from 0 to 0.04 gives the rare item, and a number in the range from 0.9 to 1 gives no item.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/09/image-3.png" alt="Image" width="600" height="400" loading="lazy">
<em>The percentage breakdown of the wolf drop</em></p>
<p>To avoid sticking to one language, let's first see how we can code this using <a target="_blank" href="https://www.freecodecamp.org/news/what-is-pseudocode-in-programming/">pseudocode</a>. This is not a real programming language – rather, it's a way to break down the code logic. It's like taking notes, as it's personal and will have varied syntax depending on the person writing it.</p>
<pre><code>FUNCTION wolfDrop
  randomNumber = random(<span class="hljs-number">0</span>,<span class="hljs-number">1</span>)
  IF
    randomNumber &lt; <span class="hljs-number">0.04</span>
    THEN
     -&gt; wolf fang
  ELSE IF
    randomNumber &lt; <span class="hljs-number">0.9</span>
    THEN
     -&gt; wolf pelt
  ELSE
    -&gt; empty
  END IF
END FUNCTION
</code></pre><p>Or a more verbose version:</p>
<blockquote>
<p>Create a function called <code>wolfDrop</code> and inside it store a random number between 0 (included) and 1 (excluded) in the <code>randomNumber</code> variable. If <code>randomNumber</code> has a value less than <code>0.04</code> the drop will be a wolf fang, else if the <code>randomNumber</code> has a value less than <code>0.9</code> the drop will be a wolf pelt, and otherwise there will be no drop.</p>
</blockquote>
<p>With the pseudocode ready, we can implement the code snippet in any language. Let's see, for example, how to code it in a few different languages:</p>
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">wolfDrop</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> randomNumber = <span class="hljs-built_in">Math</span>.random();
  <span class="hljs-keyword">if</span> (randomNumber &lt; <span class="hljs-number">0.04</span>) {
    <span class="hljs-keyword">return</span> <span class="hljs-string">"Wolf fang"</span>;
  } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (randomNumber &lt; <span class="hljs-number">0.9</span>) {
    <span class="hljs-keyword">return</span> <span class="hljs-string">"Wolf pelt"</span>;
  } <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">return</span>;
  }
}
</code></pre>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> random
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">wolfDrop</span>():</span>
  randomNumber = random.random()
  <span class="hljs-keyword">if</span> randomNumber &lt; <span class="hljs-number">0.04</span>:
    <span class="hljs-keyword">return</span> <span class="hljs-string">"Wolf fang"</span>
  <span class="hljs-keyword">elif</span> randomNumber &lt; <span class="hljs-number">0.9</span>:
    <span class="hljs-keyword">return</span> <span class="hljs-string">"Wolf pelt"</span>
  <span class="hljs-keyword">else</span>
    <span class="hljs-keyword">return</span>
</code></pre>
<pre><code class="lang-clojure">(<span class="hljs-keyword">defn</span> <span class="hljs-title">wolf-drop</span> []
  (<span class="hljs-name"><span class="hljs-builtin-name">let</span></span> [random-number (<span class="hljs-name"><span class="hljs-builtin-name">rand</span></span>)]
    (<span class="hljs-name"><span class="hljs-builtin-name">cond</span></span> (<span class="hljs-name"><span class="hljs-builtin-name">&lt;</span></span> random-number <span class="hljs-number">0.04</span>) <span class="hljs-string">"Wolf fang"</span>
          (<span class="hljs-name"><span class="hljs-builtin-name">&lt;</span></span> random-number <span class="hljs-number">0.9</span>) <span class="hljs-string">"Wolf pelt"</span>)))
</code></pre>
<pre><code class="lang-go"><span class="hljs-function"><span class="hljs-keyword">func</span> <span class="hljs-title">wolfDrop</span><span class="hljs-params">()</span> <span class="hljs-title">string</span></span> {
    randomNumber := rand.Float64()
    <span class="hljs-keyword">switch</span> {
        <span class="hljs-keyword">case</span> randomNumber &lt; <span class="hljs-number">0.04</span>:
            <span class="hljs-keyword">return</span> <span class="hljs-string">"Wolf fang"</span>
        <span class="hljs-keyword">case</span> randomNumber &lt; <span class="hljs-number">0.9</span>:
            <span class="hljs-keyword">return</span> <span class="hljs-string">"Wolf pelt"</span>
        <span class="hljs-keyword">default</span>:
            <span class="hljs-keyword">return</span> <span class="hljs-string">""</span>
    }
}
</code></pre>
<pre><code class="lang-kotlin"><span class="hljs-function"><span class="hljs-keyword">fun</span> <span class="hljs-title">wolfDrop</span><span class="hljs-params">()</span></span>: String {
    <span class="hljs-keyword">val</span> randomNumber = Random.nextFloat()
    <span class="hljs-keyword">when</span> {
        randomNumber &lt; <span class="hljs-number">0.04</span> -&gt; <span class="hljs-keyword">return</span> <span class="hljs-string">"Wolf fang"</span>
        randomNumber &lt; <span class="hljs-number">0.9</span> -&gt; <span class="hljs-keyword">return</span> <span class="hljs-string">"Wolf pelt"</span>
        <span class="hljs-keyword">else</span> -&gt; <span class="hljs-keyword">return</span> <span class="hljs-string">""</span>
    }
}
</code></pre>
<pre><code class="lang-elixir"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">wolf_pelt</span></span>() <span class="hljs-keyword">do</span>
  random_number = <span class="hljs-symbol">:rand</span>.uniform()
  <span class="hljs-keyword">cond</span> <span class="hljs-keyword">do</span>
    random_number &lt; 0.04 -&gt; <span class="hljs-string">"Wolf fang"</span>
    random_number &lt; 0.<span class="hljs-number">9</span> -&gt; <span class="hljs-string">"Wolf pelt"</span>
    <span class="hljs-keyword">true</span> -&gt; <span class="hljs-keyword">nil</span>
  <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<pre><code class="lang-c#"><span class="hljs-function"><span class="hljs-keyword">string</span> <span class="hljs-title">WolfPelt</span>(<span class="hljs-params"></span>)</span> {
  <span class="hljs-keyword">var</span> random = <span class="hljs-keyword">new</span> Random();
  <span class="hljs-keyword">double</span> randomNumber = random.NextDouble();
  <span class="hljs-keyword">if</span> (randomNumber &lt; <span class="hljs-number">0.04</span>) <span class="hljs-keyword">return</span> <span class="hljs-string">"Wolf fang"</span>;
  <span class="hljs-keyword">if</span> (randomNumber &lt; <span class="hljs-number">0.9</span>) <span class="hljs-keyword">return</span> <span class="hljs-string">"Wolf pelt"</span>;
  <span class="hljs-keyword">return</span> <span class="hljs-literal">null</span>;
}
</code></pre>
<pre><code class="lang-rust"><span class="hljs-keyword">extern</span> <span class="hljs-keyword">crate</span> rand;

<span class="hljs-function"><span class="hljs-keyword">fn</span> <span class="hljs-title">wolf_drop</span></span>() -&gt; &amp;<span class="hljs-symbol">'static</span> <span class="hljs-built_in">str</span> {
  <span class="hljs-keyword">let</span> random_number: <span class="hljs-built_in">f64</span> = rand::random();
  <span class="hljs-keyword">if</span> random_number &lt; <span class="hljs-number">0.04</span> {
    <span class="hljs-string">"Wolf fang"</span>
  } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> random_number &lt; <span class="hljs-number">0.9</span> {
    <span class="hljs-string">"Wolf pelt"</span>
  } <span class="hljs-keyword">else</span> {
    <span class="hljs-string">""</span>
  }
}
</code></pre>
<pre><code class="lang-c"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;stdlib.h&gt;</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;string.h&gt;</span></span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;time.h&gt;</span></span>

<span class="hljs-function"><span class="hljs-keyword">int</span> <span class="hljs-title">wolf_drop</span><span class="hljs-params">(<span class="hljs-keyword">char</span> *drop_item)</span> </span>{
  srand((<span class="hljs-keyword">unsigned</span>) time(<span class="hljs-number">0</span>));
  <span class="hljs-keyword">double</span> random_number = <span class="hljs-number">1.0</span> * rand() / RAND_MAX;
  <span class="hljs-keyword">if</span> (random_number &lt; <span class="hljs-number">0.04</span>) {
    <span class="hljs-built_in">strncpy</span>(drop_item, <span class="hljs-string">"wolf fang\0"</span>, <span class="hljs-number">10</span>);
  } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (random_number &lt; <span class="hljs-number">0.9</span>) {
    <span class="hljs-built_in">strncpy</span>(drop_item, <span class="hljs-string">"wolf pelt\0"</span>, <span class="hljs-number">10</span>);
  } <span class="hljs-keyword">else</span> {
    <span class="hljs-built_in">strncpy</span>(drop_item, <span class="hljs-string">"\0"</span>, <span class="hljs-number">1</span>);
  }
  <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;
}
</code></pre>
<pre><code class="lang-julia"><span class="hljs-keyword">function</span> wolfdrop()
    randomnumber = rand()
    <span class="hljs-keyword">if</span> randomnumber &lt; <span class="hljs-number">0.04</span>
        <span class="hljs-keyword">return</span> <span class="hljs-string">"wolf fang"</span>
    <span class="hljs-keyword">elseif</span> randomnumber &lt; <span class="hljs-number">0.9</span>
        <span class="hljs-keyword">return</span> <span class="hljs-string">"wolf pelt"</span>
    <span class="hljs-keyword">else</span>
        <span class="hljs-keyword">return</span> <span class="hljs-string">""</span>
    <span class="hljs-keyword">end</span>
<span class="hljs-keyword">end</span>
</code></pre>
<p>(Thanks to <a target="_blank" href="https://forum.freecodecamp.org/u/alpox">alpox</a> for the code snippets in Clojure, Golang, Kotlin, Elixir and C#, and to <a target="_blank" href="https://www.freecodecamp.org/news/author/jeremylt/">Jeremy</a> for the snippets in Rust, C, and Julia.)</p>
<h3 id="heading-other-examples-of-mathrandom">Other examples of math.random</h3>
<p>If you want to learn more about all this, you can read this article about the <a target="_blank" href="https://www.freecodecamp.org/news/how-to-use-javascript-math-random-as-a-random-number-generator/">Math.random function in JavaScript</a> and create a Dice Rolling Game. </p>
<p>You can also read this <a target="_blank" href="https://www.freecodecamp.org/news/how-to-make-your-own-procedural-dungeon-map-generator-using-the-random-walk-algorithm-e0085c8aa9a/">article on using the random walk algorithm</a> and create a random dungeon map with JavaScript to experiment some more with RNGs.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Random Number Generators, or RNGs, are used in many games. In this article, you have learned how and why they are used, and you've seen an example implementation. </p>
<p>Next time you play a video game, will you be able to spot where a RNG may be used?</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Git Revert Commit – How to Undo the Last Commit ]]>
                </title>
                <description>
                    <![CDATA[ Say you're working on your code in Git and something didn't go as planned. So now you need to revert your last commit. How do you do it? Let's find out! There are two possible ways to undo your last commit. We'll look at both of them in this article.... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/git-revert-commit-how-to-undo-the-last-commit/</link>
                <guid isPermaLink="false">66b0c3874d2b90ec4a447a52</guid>
                
                    <category>
                        <![CDATA[ Git ]]>
                    </category>
                
                    <category>
                        <![CDATA[ version control ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ilenia Magoni ]]>
                </dc:creator>
                <pubDate>Tue, 31 Aug 2021 20:20:41 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/08/pexels-siegfried-poepperl-8778445--1-.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Say you're working on your code in Git and something didn't go as planned. So now you need to revert your last commit. How do you do it? Let's find out!</p>
<p>There are two possible ways to undo your last commit. We'll look at both of them in this article. </p>
<h2 id="heading-the-revert-command">The <code>revert</code> command</h2>
<p>The <code>revert</code> command will create a commit that reverts the changes of the commit being targeted. You can use it to revert the last commit like this:</p>
<pre><code>git revert &lt;commit to revert&gt;
</code></pre><p>You can find the name of the commit you want to revert using <code>[git log](https://www.freecodecamp.org/news/git-log-command/)</code>. The first commit that's described there is the last commit created. Then you can copy from there the alphanumerical name and use that in the <code>revert</code> command.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/image-117.png" alt="A diagram showing that the git revert command creates a new commit to revert previous changes." width="600" height="400" loading="lazy">
<em>In this image, each circe represents a commit.</em></p>
<h2 id="heading-the-reset-command">The <code>reset</code> command</h2>
<p>You can also use the <code>reset</code> command to undo your last commit. But be careful – it will change the commit history, so you should use it rarely. It will move the HEAD, the working branch, to the indicated commit, and discard anything after:</p>
<pre><code>git reset --soft HEAD~<span class="hljs-number">1</span>
</code></pre><p>The <code>--soft</code> option means that you will not lose the uncommitted changes you may have.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/08/git-reset-soft.png" alt="A diagram showing that git reset --soft will change your commit history, but will keep any unstaged changes you have." width="600" height="400" loading="lazy">
<em>In this image, each circle represents a commit.</em></p>
<p>If you want to reset to the last commit and also remove all unstaged changes, you can use the <code>--hard</code> option:</p>
<pre><code>git reset --hard HEAD~<span class="hljs-number">1</span>
</code></pre><p>This will undo the latest commit, but also any uncommitted changes.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/image-112.png" alt="A diagram showing that git reset --hard will change your commit history, but will also remove any unstaged changes you have." width="600" height="400" loading="lazy">
<em>In this image, each circle represents a commit.</em></p>
<h2 id="heading-should-you-use-reset-or-revert-in-git">Should You Use <code>reset</code> or <code>revert</code> in Git?</h2>
<p>You should really only use <code>reset</code> if the commit being reset only exists locally. This command changes the commit history and it might overwrite history that remote team members depend on. </p>
<p><code>revert</code> instead creates a <em>new commit</em> that undoes the changes, so if the commit to revert has already been pushed to a shared repository, it is best to use <code>revert</code> as it doesn't overwrite commit history.</p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>You have learned two ways to undo the last commit and also when it's best to use one over the other. </p>
<p>Now if you notice that your last commit introduces a bug or should have not been committed you know how to fix that!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Remove a Directory in Linux – How to Delete Directories and Contents From the Command Line ]]>
                </title>
                <description>
                    <![CDATA[ Linux is a popular open source operating system, and its features are often available in your development environment. If you can learn its basic commands, it'll make your life as a developer much easier. In this guide you will learn how to delete di... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/remove-a-directory-in-linux-how-to-delete-directories-and-contents-from-the-command-line/</link>
                <guid isPermaLink="false">66b0c3a9e379be09b93a1bda</guid>
                
                    <category>
                        <![CDATA[ command line ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Linux ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ilenia Magoni ]]>
                </dc:creator>
                <pubDate>Mon, 30 Aug 2021 21:35:33 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/08/pexels-any-lane-5945735.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Linux is a popular open source operating system, and its features are often available in your development environment. If you can learn its basic commands, it'll make your life as a developer much easier.</p>
<p>In this guide you will learn how to delete directories and files from the Linux command line.</p>
<h1 id="heading-the-linux-rm-command">The Linux <code>rm</code> Command</h1>
<p>The <code>rm</code> (short for remove) command is pretty useful. Let's learn its syntax and look at a few examples to see it in action.</p>
<h2 id="heading-rm-command-syntax"><code>rm</code> Command Syntax</h2>
<p>The syntax is shown below, with <code>args</code> being any number of arguments (folders or files).</p>
<pre><code>rm [options] args
</code></pre><p>Without <code>options</code> you can use it to delete files. But to delete directories you need to use the <code>options</code> for this command.</p>
<p>The options are as follows:</p>
<ul>
<li><code>-r</code>, "recursive" – this option allows you to delete folders and recursively remove their content first</li>
<li><code>-i</code>, "interactive" – with this option, it will ask for confirmation each time before you delete something</li>
<li><code>-f</code>, "force" – it ignores non-existent files and overrides any confirmation prompt (essentially, it's the opposite of <code>-i</code>). It will not remove files from a directory if the directory is write-protected.</li>
<li><code>-v</code>, "verbose" – it prints what the command is doing on the terminal</li>
<li><code>-d</code>, "directory" – which allows you to delete a directory. It works only if the directory is empty.</li>
</ul>
<h2 id="heading-linux-rm-command-example">Linux <code>rm</code> Command Example</h2>
<p>Let's take a <code>project_folder</code> directory as an example. It has these files and folders inside:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/image-94.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Let's use this directory to show how the various options work.</p>
<p>You can add the option <code>-v</code> to all commands so that it will write down step by step what's going on.</p>
<p>So, let's start with the first option, <code>-r</code>. You just learned that this removes files and folders recursively. You can use it like this <code>rm -r project_folder</code> or also <code>rm -rv project_folder</code> as the verbose option.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/image-98.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>It has deleted the <code>project_folder</code> directory and everything inside it, in the order shown.</p>
<p>Let's recreate the folder and try again.</p>
<p>What happens if you don't use the <code>-r</code> option and you try to delete the directory anyway? It will not allow it and will instead show an error:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/image-99.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>To delete directories you can use the <code>-d</code> option, but if you try to use it in this case it will give an error as the folder is not empty.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/image-106.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>The <code>-i</code> option make so that it asks about each action individually.</p>
<p>And you need to press <code>y</code> or <code>n</code> and then <code>Enter</code> after each query.</p>
<p>If you select <code>y</code> for all queries it will delete everything:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/image-107.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>If instead you decide to not delete some files or folders, with <code>n</code> it will keep those files and continue with the rest:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/image-109.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>The last option we haven't seen so far is <code>-f</code>, which will suppress errors. </p>
<p>For example writing as below you would be trying to delete two non existing files – there is not a <code>rat.png</code> file, and <code>dog.pmg</code> has a typo and it gives two errors. With the <code>-f</code> option, you will not see the errors.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/08/image-108.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>The Linux command line is pretty useful if you're a developer. In this article, you have seen one of its possible commands, <code>rm</code>, that you can use to delete directories and files. </p>
<p>Enjoy this new tool in your arsenal!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ SQL Left Join – Example Join Statement Syntax ]]>
                </title>
                <description>
                    <![CDATA[ In a Relational Database, tables are often related to each other in a way that allows their information to only be written once in the whole database. Then, when you need to analyze the data, you'll need to combine the info from those related tables.... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/sql-left-join-example-join-statement-syntax/</link>
                <guid isPermaLink="false">66b0c3b5d2b167de8127ab60</guid>
                
                    <category>
                        <![CDATA[ database ]]>
                    </category>
                
                    <category>
                        <![CDATA[ SQL ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Ilenia Magoni ]]>
                </dc:creator>
                <pubDate>Thu, 26 Aug 2021 20:29:12 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/08/pexels-pixabay-262347.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>In a Relational Database, tables are often related to each other in a way that allows their information to only be written once in the whole database. Then, when you need to analyze the data, you'll need to combine the info from those related tables.</p>
<p>To do this in SQL, you can use <code>JOIN</code> statements. The <code>LEFT JOIN</code> statement is one of <a target="_blank" href="https://www.freecodecamp.org/news/sql-join-types-inner-join-vs-outer-join-example/">the various <code>JOIN</code> statements available</a>. When you use it to join two tables, it keeps all the rows of the first table (the left table), even if there is not a corresponding match on the second table.</p>
<p>You can use <code>JOIN</code> in a <code>SELECT</code> query to join two tables, <code>table_1</code> and <code>table_2</code>, like this:</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">columns</span>
<span class="hljs-keyword">FROM</span> table_1
<span class="hljs-keyword">LEFT</span> <span class="hljs-keyword">OUTER</span> <span class="hljs-keyword">JOIN</span> table_2
<span class="hljs-keyword">ON</span> relation;
</code></pre>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> <span class="hljs-keyword">columns</span>
<span class="hljs-keyword">FROM</span> table_1
<span class="hljs-keyword">LEFT</span> <span class="hljs-keyword">JOIN</span> table_2
<span class="hljs-keyword">ON</span> relation;
</code></pre>
<p>First you write which columns will be present in the joined table. You can specify to which table the column belongs by prefixing the table name to the column name. This is necessary if some columns have the same name (like <code>table_1.column_1</code> and <code>table_2.column_1</code>) with <code>SELECT &lt;columns&gt;</code>.</p>
<p>Then you would write the name of the first table as <code>FROM table_1</code>.</p>
<p>After that you'd write the name of the second table as <code>LEFT OUTER JOIN table_2</code> or <code>LEFT JOIN table_2</code> (omitting the <code>OUTER</code> keyword).</p>
<p>And at the end you'd write the relation to use to match the rows, for example <code>ON table_1.column_A = table_2.column_B</code>. Often the relation is by id, but it can be with any column.</p>
<h1 id="heading-sql-left-join-example">SQL LEFT JOIN Example</h1>
<p>Let's say you have a book database in which you have two tables, one with books, the other with authors. To avoid repeating all the author info for each book, that info is in its own table, and the books have only the <code>author_name</code> column.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>book_id</td><td>title</td><td>author_name</td><td>publ_year</td></tr>
</thead>
<tbody>
<tr>
<td>1</td><td>Uno, nessuno e centomila</td><td>Luigi Pirandello</td><td>1926</td></tr>
<tr>
<td>2</td><td>Il visconte dimezzato</td><td>Italo Calvino</td><td>1952</td></tr>
<tr>
<td>3</td><td>Le tigri di Mompracem</td><td>Emilio Salgari</td><td>1900</td></tr>
<tr>
<td>4</td><td>Il giorno della civetta</td><td>Leonardo Sciascia</td><td>1961</td></tr>
<tr>
<td>5</td><td>A ciascuno il suo</td><td>Leonardo Sciascia</td><td>1966</td></tr>
<tr>
<td>6</td><td>Il fu Mattia Pascial</td><td>Luigi Pirandello</td><td>1904</td></tr>
<tr>
<td>7</td><td>I Malavoglia</td><td>Giovanni Verga</td><td>1881</td></tr>
</tbody>
</table>
</div><div class="hn-table">
<table>
<thead>
<tr>
<td>author_id</td><td>name</td><td>year_of_birth</td><td>place_of_birth</td><td>trivia</td></tr>
</thead>
<tbody>
<tr>
<td>1</td><td>Luigi Pirandello</td><td>1867</td><td>Agrigento</td><td>Nobel Prize in Literature in 1934</td></tr>
<tr>
<td>2</td><td>Giovanni Verga</td><td>1840</td><td>Vizzini</td><td>was Senator of the Kingdom of Italy from 1920 to 1922</td></tr>
<tr>
<td>3</td><td>Italo Svevo</td><td>1861</td><td>Trieste</td><td>real name was Aron Hector Schmitz</td></tr>
<tr>
<td>4</td><td>Cesare Pavese</td><td>1908</td><td>Santo Stefano Belbo</td><td>NULL</td></tr>
<tr>
<td>5</td><td>Giuseppe Tomasi di Lampedusa</td><td>1896</td><td>Palermo</td><td>was prince of Lampedusa from 1934 to 1957</td></tr>
</tbody>
</table>
</div><p>We can join these two tables based on the names of the authors. Using the <code>books</code> table as the left table, you can write the following code to join them:</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> books.title <span class="hljs-keyword">AS</span> book_title, books.publ_year, books.author_name, authors.year_of_birth, authors.place_of_birth
   <span class="hljs-keyword">FROM</span> books
   <span class="hljs-keyword">LEFT</span> <span class="hljs-keyword">JOIN</span> <span class="hljs-keyword">authors</span>
   <span class="hljs-keyword">ON</span> books.author_name = authors.name
;
</code></pre>
<p>Let's break it down.</p>
<p>In the first line, you choose which columns to show in the final table. It's also the place to decide if some columns will have a different name in the resulting table using <code>AS</code> like with <code>books.title AS book_title</code>.</p>
<p>The second line, <code>FROM books</code>, says which is the first table to consider, also called the left table.</p>
<p>Then the third line, <code>LEFT JOIN authors</code>, says which other table to consider.</p>
<p><code>ON books.author_name = authors.name</code> says to match the tables using the rows <code>books.author_name</code> and <code>authors.name</code>.</p>
<p>After this query you would get the table as below, where the rows that didn't get info from the authors table just show <code>NULL</code>.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>book_title</td><td>publ_year</td><td>author_name</td><td>year_of_birth</td><td>place_of_birth</td></tr>
</thead>
<tbody>
<tr>
<td>Uno, nessuno e centomila</td><td>1926</td><td>Luigi Pirandello</td><td>1867</td><td>Agrigento</td></tr>
<tr>
<td>Il visconte dimezzato</td><td>1952</td><td>Italo Calvino</td><td>NULL</td><td>NULL</td></tr>
<tr>
<td>Le tigri di Mompracem</td><td>1900</td><td>Emilio Salgari</td><td>NULL</td><td>NULL</td></tr>
<tr>
<td>Il giorno della civetta</td><td>1961</td><td>Leonardo Sciascia</td><td>NULL</td><td>NULL</td></tr>
<tr>
<td>A ciascuno il suo</td><td>1966</td><td>Leonardo Sciascia</td><td>NULL</td><td>NULL</td></tr>
<tr>
<td>Il fu Mattia Pascal</td><td>1904</td><td>Luigi Pirandello</td><td>1867</td><td>Agrigento</td></tr>
<tr>
<td>I Malavoglia</td><td>1881</td><td>Giovanni Verga</td><td>1840</td><td>Vizzini</td></tr>
</tbody>
</table>
</div><p>Note that the authors not present in the <code>books</code> table are not in this joined table. This is because, as I said before, only the unrelated rows from the left table (in this case <code>books</code>) are kept, not those from the right/second table.</p>
<h2 id="heading-a-more-complex-left-join-example">A more complex LEFT JOIN example</h2>
<p>Let's see another way you can use <code>JOIN</code> together with other SQL features to do some data analysis.</p>
<p>You might want to see how many books from each author are present in the database. You could use the below query to do so:</p>
<pre><code class="lang-sql"><span class="hljs-keyword">SELECT</span> authors.name <span class="hljs-keyword">AS</span> author_name,
    <span class="hljs-keyword">SUM</span>(
      <span class="hljs-keyword">CASE</span>
        <span class="hljs-keyword">WHEN</span> books.title <span class="hljs-keyword">LIKE</span> <span class="hljs-string">'%'</span>
          <span class="hljs-keyword">THEN</span> <span class="hljs-number">1</span>
        <span class="hljs-keyword">ELSE</span> <span class="hljs-number">0</span>
      <span class="hljs-keyword">END</span>
    ) <span class="hljs-keyword">as</span> number_of_books
  <span class="hljs-keyword">FROM</span> <span class="hljs-keyword">authors</span>
  <span class="hljs-keyword">LEFT</span> <span class="hljs-keyword">JOIN</span> books
  <span class="hljs-keyword">ON</span> books.author_name = authors.name
  <span class="hljs-keyword">GROUP</span> <span class="hljs-keyword">BY</span> authors.name
  <span class="hljs-keyword">ORDER</span> <span class="hljs-keyword">BY</span> number_of_books <span class="hljs-keyword">DESC</span>
;
</code></pre>
<h4 id="heading-code-breakdown">Code breakdown</h4>
<p>Line 1: with <code>SELECT</code> you list the columns you want in the resulting table.</p>
<p>Line 2: <a target="_blank" href="https://www.freecodecamp.org/news/sql-group-by-clauses-explained/#aggregations-count-sum-avg-"><code>SUM</code> is an aggregation function</a> used in conjunction with GROUP BY. The values of the rows that are grouped together are then summed.</p>
<p>Line 3-7: you use the <a target="_blank" href="https://www.freecodecamp.org/news/case-statement-in-sql-example-query/">CASE statement</a> to get different results depending on a condition. In this case, a row is counted as 1 if it contains a book title, otherwise it is counted as 0. And here we use <code>LIKE</code> to check if the cell contains any characters (learn more in this <a target="_blank" href="https://www.freecodecamp.org/news/sql-contains-string-sql-regex-example-query">article about Contains String</a>).</p>
<p>Line 8: this gives a name of <code>number_of_books</code> to the column that is created for the SUM.</p>
<p>Line 9: the left/first table in this case is <code>authors</code>.</p>
<p>Line 10: the right/second table in this case is <code>books</code>.</p>
<p>Line 11: this joins the two tables using the author names.</p>
<p>Line 12: the rows are <a target="_blank" href="https://www.freecodecamp.org/news/sql-group-by-clauses-explained/">grouped by author name</a> - all the rows with the same value in that column will be represented by a single row.</p>
<p>Line 13: we use <a target="_blank" href="https://www.freecodecamp.org/news/sql-order-by-statement-example-sytax/">order by</a> to arrange in descending order using the number of books.</p>
<p>The query will give you the below table. Note that you see here only the authors that are present in the <code>authors</code> table. The authors mentioned in the <code>books</code> table without an entry in the <code>authors</code> table are not present here. This is an effect of the fact that the unrelated rows from the <code>books</code> table were not kept.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>author_name</td><td>number_of_books</td></tr>
</thead>
<tbody>
<tr>
<td>Luigi Pirandello</td><td>2</td></tr>
<tr>
<td>Giovanni Verga</td><td>1</td></tr>
<tr>
<td>Cesare Pavese</td><td>0</td></tr>
<tr>
<td>Giuseppe Tomasi di Lampedusa</td><td>0</td></tr>
<tr>
<td>Italo Svevo</td><td>0</td></tr>
</tbody>
</table>
</div><p>If the <code>authors</code> table is updated to include all the authors mentioned in the <code>books</code> table, like this:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>author_id</td><td>name</td><td>year_of_birth</td><td>place_of_birth</td><td>trivia</td></tr>
</thead>
<tbody>
<tr>
<td>1</td><td>Luigi Pirandello</td><td>1867</td><td>Agrigento</td><td>Nobel Prize in Literature in 1934</td></tr>
<tr>
<td>2</td><td>Giovanni Verga</td><td>1840</td><td>Vizzini</td><td>was Senator of the Kingdom of Italy from 1920 to 1922</td></tr>
<tr>
<td>3</td><td>Italo Svevo</td><td>1861</td><td>Trieste</td><td>real name was Aron Hector Schmitz</td></tr>
<tr>
<td>4</td><td>Cesare Pavese</td><td>1908</td><td>Santo Stefano Belbo</td><td>NULL</td></tr>
<tr>
<td>5</td><td>Giuseppe Tomasi di Lampedusa</td><td>1896</td><td>Palermo</td><td>was prince of Lampedusa from 1934 to 1957</td></tr>
<tr>
<td>6</td><td>Italo Calvino</td><td>1923</td><td>Santiago de las Vegas</td><td>NULL</td></tr>
<tr>
<td>7</td><td>Emilio Salgari</td><td>1862</td><td>Verona</td><td>NULL</td></tr>
<tr>
<td>8</td><td>Leonardo Sciascia</td><td>1921</td><td>Racalmuto</td><td>NULL</td></tr>
</tbody>
</table>
</div><p>Then the table from the query above would actually give the number of books for all authors.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>author_name</td><td>number_of_books</td></tr>
</thead>
<tbody>
<tr>
<td>Leonardo Sciascia</td><td>2</td></tr>
<tr>
<td>Luigi Pirandello</td><td>2</td></tr>
<tr>
<td>Emilio Salgari</td><td>1</td></tr>
<tr>
<td>Giovanni Verga</td><td>1</td></tr>
<tr>
<td>Giovanni Verga</td><td>1</td></tr>
<tr>
<td>Cesare Pavese</td><td>0</td></tr>
<tr>
<td>Giuseppe Tomasi di Lampedusa</td><td>0</td></tr>
<tr>
<td>Italo Svevo</td><td>0</td></tr>
</tbody>
</table>
</div><h1 id="heading-conclusion">Conclusion</h1>
<p>In a Relational Database, data should be written only once, so we often end up with multiple tables related to each other. <code>LEFT JOIN</code> is a really useful ally when we need to analyse data and join information from different tables. Enjoy querying your database using this powerful tool.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
