<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Code The Web</title>
    <description>The latest articles on DEV Community by Code The Web (@codetheweb).</description>
    <link>https://dev.to/codetheweb</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Forganization%2Fprofile_image%2F2181%2Ff6232faa-47e8-4db1-bc7e-2f466d7ca680.png</url>
      <title>DEV Community: Code The Web</title>
      <link>https://dev.to/codetheweb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codetheweb"/>
    <language>en</language>
    <item>
      <title>JavaScript Objects</title>
      <dc:creator>Ethan</dc:creator>
      <pubDate>Sat, 09 Jun 2018 00:00:00 +0000</pubDate>
      <link>https://dev.to/codetheweb/javascript-objects-2c18</link>
      <guid>https://dev.to/codetheweb/javascript-objects-2c18</guid>
      <description>&lt;p&gt;&lt;a href="https://codetheweb.blog/2018/06/09/javascript-objects/" rel="noopener noreferrer"&gt;This was originally published on my blog, Code The Web&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codetheweb.blog/2018/06/09/javascript-objects/" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fjavascript-objects%2Fcover.png" alt="JavaScript Objects"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Objects are ways of storing data in JavaScript and are a key part of Object Oriented Programming. Learn the syntax and more about them in this article...&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;While it's not completely necessary, a basic understanding of &lt;a href="https://codetheweb.blog/2018/04/28/javascript-arrays/" rel="noopener noreferrer"&gt;JavaScript arrays&lt;/a&gt; may help you understand objects.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  What is an object?
&lt;/h2&gt;

&lt;p&gt;An object in JavaScript is quite similar to an &lt;a href="https://codetheweb.blog/2018/04/28/javascript-arrays/" rel="noopener noreferrer"&gt;array&lt;/a&gt; — it is a data type which stores lots of values. These values can be any data type — numbers, strings, booleans, functions, and even arrays and objects!&lt;/p&gt;

&lt;p&gt;The difference between an array and an object is how the values are referenced. In an array, you reference a value with a number (its position in the array) — for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When referencing a value in an object, you do so using a &lt;em&gt;name&lt;/em&gt; instead of a number. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;superFlashyName&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it! &lt;em&gt;Name instead of number&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to declare an object
&lt;/h2&gt;

&lt;p&gt;The syntax for declaring an object is different to the syntax for an array. Here's what it looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myFriend&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;nationality&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;British&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, it's &lt;em&gt;kind of&lt;/em&gt; similar to the array syntax, but it has curly brackets instead of square brackets. The items are still comma-separated. However, the items now have a 'name' as well as a value. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;27&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;age&lt;/code&gt; is the name (aka 'key') of the item and &lt;code&gt;27&lt;/code&gt; is the item's value. They are separated by a colon.&lt;/p&gt;

&lt;p&gt;We call this a &lt;em&gt;key-value pair&lt;/em&gt;. It has a key and a value... (&lt;em&gt;really?&lt;/em&gt; 😜)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So an object is made of key-value pairs separated by commas, and the whole thing is wrapped in a set of curly brackets.&lt;/p&gt;

&lt;p&gt;Here's our object again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myFriend&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;nationality&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;British&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is perfectly acceptable to write it this way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myFriend&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;nationality&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;British&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some people prefer the first option, while some prefer the second. It's up to you — choose the one that makes the most sense in your head.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to get/set a value in an object
&lt;/h2&gt;

&lt;p&gt;As I mentioned near the beginning, this is how you reference an item in an object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;key&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can express it this way as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the second option, you can't have variables or special characters (including spaces) as the key. For example, these wouldn't work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;someVarContainingTheKey&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="nx"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I have spaces and special characters ;)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, they don't turn out so well!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;someVarContainingTheKey&lt;/span&gt; &lt;span class="c1"&gt;// No longer a variable - equivalent to myObject['someVarContainingTheKey']&lt;/span&gt;
&lt;span class="nx"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;I&lt;/span&gt; &lt;span class="nx"&gt;have&lt;/span&gt; &lt;span class="nx"&gt;spaces&lt;/span&gt; &lt;span class="nx"&gt;and&lt;/span&gt; &lt;span class="nx"&gt;special&lt;/span&gt; &lt;span class="nx"&gt;characters&lt;/span&gt; &lt;span class="p"&gt;;)&lt;/span&gt; &lt;span class="c1"&gt;// \0_0/ The syntax errors are killing me&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's worth saying that it is bad programming practice to use special characters in variable names or object keys. The exception would be if you were using a form of user input (which might include spaces) as your key.&lt;/p&gt;

&lt;p&gt;Unless you have special characters or a variable as your key, it is best to use the second option (&lt;code&gt;myObject.key&lt;/code&gt;). Why? It just looks nicer (it also makes more sense for functions, which you'll see soon). But it's up to you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Functions in objects
&lt;/h2&gt;

&lt;p&gt;I told you at the start that objects can have any types of data inside them. This includes functions! But how would you actually put one inside an object?&lt;/p&gt;

&lt;p&gt;Let's use our friend example from earlier:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myFriend&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;nationality&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;British&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's say we had this function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sayHi&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And we want to add it to our object. This means that we could call it like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;myFriend&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sayHi&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Look familiar? This is why &lt;code&gt;console.log()&lt;/code&gt; is &lt;code&gt;console.log()&lt;/code&gt;! &lt;code&gt;console&lt;/code&gt; is an object with a &lt;code&gt;log&lt;/code&gt; function inside of it!&lt;/p&gt;

&lt;p&gt;Anyway, here's how we'd put &lt;code&gt;sayHi()&lt;/code&gt; into our function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myFriend&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;nationality&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;British&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;sayHi&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What?! Let's take a look at what's going on here. When you say:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;sayHi&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;, it is actually just shorthand for:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;sayHi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, just like &lt;code&gt;var age = 27&lt;/code&gt; becomes &lt;code&gt;age: 27&lt;/code&gt;, this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;sayHi&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;becomes this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;sayHi&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, it makes sense to use the &lt;code&gt;object.key&lt;/code&gt; syntax as supposed to the &lt;code&gt;object['key']&lt;/code&gt; syntax when it comes to functions. Imagine having to write this!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;myFriend&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sayHi&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Eugh, ugly 🙈&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;this&lt;/code&gt; in objects
&lt;/h2&gt;

&lt;p&gt;Let's say we wanted to give our friend another function: an &lt;code&gt;introduce()&lt;/code&gt; function. It would alert this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;My name is John Smith. I'm British and I'm 27 years old.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;However, we can't just alert this as a simple string! We'll want to use the object values. So if we changed the &lt;code&gt;age&lt;/code&gt; to &lt;code&gt;30&lt;/code&gt;, it would say that instead.&lt;/p&gt;

&lt;p&gt;It is bad programming practice to say &lt;code&gt;myFriend.age&lt;/code&gt;. This is because if the function was put into another object instead (let's say &lt;code&gt;myEnemy&lt;/code&gt;), it would still alert the age of &lt;code&gt;myFriend&lt;/code&gt; instead of &lt;code&gt;myEnemy&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Instead, we use &lt;code&gt;this.age&lt;/code&gt;. &lt;code&gt;this&lt;/code&gt; simply refers to the object that the function is in.  See if you can work the function and put it in the object. Remember that you can merge strings and variables together with this syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Here is a variable: &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;myVar&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; ...yay!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Good luck!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NOTE: Use double quotes so you don't interfere with the apostrophe in the word I'm&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myFriend&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;nationality&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;British&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;sayHi&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;introduce&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;My name is &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;. I'm &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nationality&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; and I'm &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; years old.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;{:.reveal}&lt;/p&gt;

&lt;p&gt;Awesome! That's how &lt;code&gt;this&lt;/code&gt; works!&lt;/p&gt;

&lt;h2&gt;
  
  
  Converting between objects and strings
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;In this section, you're going to need to open up the JavaScript console. Do that by right-clicking, clicking on 'Inspect Element', and going to the 'Console' tab.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To convert an array to a string, you can use &lt;code&gt;.join()&lt;/code&gt; or &lt;code&gt;.toString()&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="c1"&gt;// logs '1,2,3,4'&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="c1"&gt;// logs '1,2,3,4'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How would we do this with an object? Let's try &lt;code&gt;.toString()&lt;/code&gt; (&lt;code&gt;.join()&lt;/code&gt; is for arrays only):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;favoriteFood&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Pizza&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;hobby&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Coding&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="c1"&gt;// logs '[object Object]'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ewww! That's not what we want! 💩&lt;/p&gt;

&lt;p&gt;Instead, there's a special function that we use just for objects:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;favoriteFood&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Pizza&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;hobby&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Coding&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// logs '{"favoriteFood":"Pizza","hobby":"Coding"}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's better! Note that it's &lt;code&gt;JSON.stringify(myObject)&lt;/code&gt;, not &lt;code&gt;myObject.stringify()&lt;/code&gt; like with &lt;code&gt;.toString()&lt;/code&gt; and &lt;code&gt;.join()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;JSON&lt;/code&gt; stands for JavaScript Object Notation. I'll go into that a bit further down.&lt;/p&gt;

&lt;p&gt;In JavaScript, you can also make an array from a string with the &lt;code&gt;split&lt;/code&gt; function like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;how,are,you&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// logs ["how", "are", "you"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The equivalent of this for objects is &lt;code&gt;JSON.parse&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;{"favoriteFood":"Pizza","hobby":"Coding"}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myString&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// logs {favoriteFood: "Pizza", hobby: "Coding"}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that it logs the array without the single quotes around it, meaning it is now an object and no longer a string. To see it yourself, paste the above code snippet into your console. It will display it like an object, not a string!&lt;/p&gt;

&lt;p&gt;Try these two new functions out further! Make up some objects and objects as strings, then convert between them.&lt;/p&gt;

&lt;h2&gt;
  
  
  So, what's that JSON thingo?
&lt;/h2&gt;

&lt;p&gt;JSON simply stands for &lt;strong&gt;JavaScript Object Notation&lt;/strong&gt;. In other words, simply the object syntax you have been learning about in this article!&lt;/p&gt;

&lt;p&gt;People liked this syntax so much that they thought it would be a good idea to use it to store data, so now JSON is used in many ways outside of JavaScript. That's why we have things like &lt;code&gt;JSON.parse&lt;/code&gt;: we're simply parsing (interpreting) a JavaScript object.&lt;/p&gt;

&lt;p&gt;You can find out more about JSON at &lt;a href="https://json.org/" rel="noopener noreferrer"&gt;json.org&lt;/a&gt; (but don't overload your brain, it's not that relevant to this tutorial).&lt;/p&gt;

&lt;h2&gt;
  
  
  Object.keys()
&lt;/h2&gt;

&lt;p&gt;With an array, if you know its size then you know how to find all the values. For example — in an array with a length of &lt;code&gt;4&lt;/code&gt;, you know that to find all the values you could reference &lt;code&gt;array[0]&lt;/code&gt;, &lt;code&gt;array[1]&lt;/code&gt;, &lt;code&gt;array[2]&lt;/code&gt;, and &lt;code&gt;array[3]&lt;/code&gt;. However, we can't do this with an object because we don't know what all the keys are — they don't follow a pattern like 0,1,2,3 because we can set them to whatever we like.&lt;/p&gt;

&lt;p&gt;Luckily, there is a function we can use to get all the keys:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myFriend&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;nationality&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;British&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;sayHi&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;introduce&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;My name is &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;. I'm &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nationality&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; and I'm &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; years old.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myFriend&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// logs ["firstName", "lastName", "age", "nationality", "sayHi", "introduce"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, it returns an array with all the keys! Remember that the syntax is this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myFriend&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// RIGHT :)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NOT&lt;/strong&gt; this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;myFriend&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// WRONG!!!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Object.values()&lt;/code&gt; simply makes an array of all the keys in an object.&lt;/p&gt;

&lt;h2&gt;
  
  
  Object.values()
&lt;/h2&gt;

&lt;p&gt;As well as finding all the keys in an object, we can also find all the values! This &lt;em&gt;sort of&lt;/em&gt; turns an object into an array, except all the keys will obviously be lost. Here is how it works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myFriend&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;nationality&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;British&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;sayHi&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;introduce&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;My name is &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lastName&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;. I'm &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nationality&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; and I'm &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; years old.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myFriend&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// logs ["John", "Smith", 27, "British", function() { alert('Hi!'); }, function() { alert('My name is ' + this.firstName + ' ' + this.lastName + ". I'm " + this.nationality + " and I'm " + this.age + ' years old.'); }]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the console may abbreviate the functions with an &lt;code&gt;ƒ&lt;/code&gt; symbol like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Smith&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;British&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ƒ&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ƒ&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is how &lt;code&gt;Object.values()&lt;/code&gt; works — it simply makes an array of all the values in an object.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;That's it for today! Hopefully, this article has given you a good understanding of objects. If so, I'd really appreciate it if you shared this article on social media (&lt;a href="https://codetheweb.blog/2018/06/09/javascript-objects/#share" rel="noopener noreferrer"&gt;click here to do so&lt;/a&gt;) to help spread the word and help others like you.&lt;/p&gt;

&lt;p&gt;Once you have played around with objects for a bit longer and have gotten all your initial confusion out of the way, it's worth looking into some weird behavior with objects (called 'mutability'), and why it can be scary — &lt;a href="https://alistapart.com/article/why-mutation-can-be-scary" rel="noopener noreferrer"&gt;I highly recommend reading this article on it by Zell Liew&lt;/a&gt;. It is more advanced, which is why I recommend playing around a bit with objects first.&lt;/p&gt;

&lt;p&gt;If you need help understanding these concepts, with web development in general or want to give feedback, head to the &lt;a href="https://codetheweb.blog/2018/06/09/javascript-objects/#disqus_thread" rel="noopener noreferrer"&gt;comments below...&lt;/a&gt; (or type in that live chat thingo)&lt;/p&gt;

&lt;p&gt;If you want more quality articles like this, &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;sign up to get my weekly email of curated content from Code The Web and around the internet&lt;/a&gt; (no spam).&lt;/p&gt;

&lt;p&gt;If you happen to be a real-life superhero who appreciates my work, go ahead and &lt;a href="https://buymeacoff.ee/CodeTheWeb" rel="noopener noreferrer"&gt;buy me a coffee or two or three&lt;/a&gt; or &lt;a href="https://www.patreon.com/CodeTheWebBlog" rel="noopener noreferrer"&gt;become my patron&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;See you next time, where I'll be talking all about &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;how to modify HTML and CSS in JavaScript&lt;/a&gt;. This is one of the most important parts of JavaScript and is the intersection between all three web languages.&lt;/p&gt;




&lt;blockquote&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;a href="https://codetheweb.blog/newsletter/" rel="noopener noreferrer"&gt;Want more great tutorials like this? Sign up to Code The Web Weekly!&lt;/a&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;It's weekly email packed with the best resources to learn web development from Code The Web and around the internet&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;(&lt;a href="https://codetheweb.blog/newsletter/" rel="noopener noreferrer"&gt;Learn more...&lt;/a&gt;)&lt;/p&gt;


&lt;/blockquote&gt;

&lt;p&gt;This article was originally published at &lt;a href="https://codetheweb.blog" rel="noopener noreferrer"&gt;Code The Web&lt;/a&gt;, a fun and easy-to-understand blog to help you learn web development 🚀&lt;br&gt;
Learn: &lt;a href="https://codetheweb.blog/learn/html/" rel="noopener noreferrer"&gt;HTML&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/css/" rel="noopener noreferrer"&gt;CSS&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/javascript/" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>The complete guide to JavaScript functions</title>
      <dc:creator>Ethan</dc:creator>
      <pubDate>Thu, 05 Apr 2018 00:00:00 +0000</pubDate>
      <link>https://dev.to/codetheweb/the-complete-guide-to-javascript-functions-2i0l</link>
      <guid>https://dev.to/codetheweb/the-complete-guide-to-javascript-functions-2i0l</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn7yl0huktiocv3825kjk.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn7yl0huktiocv3825kjk.jpg" alt="The complete guide to JavaScript functions" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started!
&lt;/h2&gt;

&lt;p&gt;First of all, I encourage you to follow along in this article. It will help you learn better, and also help you to remember what you have done. Let's start by making a new HTML file with a &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag in it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;If statements are awesome!&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;JavaScript :)&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
            &lt;span class="c1"&gt;// Our script will go here!&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once that's done, open it up in your web browser and you're ready to go! (don't forget to save and reload the page every time you make a change)&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a function?
&lt;/h2&gt;

&lt;p&gt;A function is simply a bit of JavaScript code which you can run again and again. You can even give it with different inputs and outputs!&lt;/p&gt;

&lt;h2&gt;
  
  
  The syntax
&lt;/h2&gt;

&lt;p&gt;For the moment, let's look at the simplest type of function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFirstFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First, we're declaring the function. We do this by saying the word &lt;code&gt;function&lt;/code&gt; and then the name of your function. This is similar to how we declare variable (&lt;code&gt;var variableName&lt;/code&gt; is similar to &lt;code&gt;function functionName&lt;/code&gt;). After the name, there is an empty set of brackets / parentheses / whatever you call these things: &lt;code&gt;()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;What's the point of them if they're empty though? Well, this is where we put &lt;em&gt;inputs&lt;/em&gt; for the function. At the moment, our function doesn't have any inputs so we leave it empty. I'll get onto inputs a bit further on in this article (get excited 😉).&lt;/p&gt;

&lt;p&gt;After that, we have a set of curly brackets (the ending one is on the fourth line). Inside these curly brackets goes all the code in the function.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running (aka &lt;em&gt;'calling'&lt;/em&gt;) a function
&lt;/h2&gt;

&lt;p&gt;Now you know how it works, let's run it! Put it in your &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag, save, and reload the page...&lt;/p&gt;

&lt;p&gt;What!?? Nothing happened! Well, here's the thing — we've only &lt;em&gt;declared&lt;/em&gt; the function, not actually run it. We've just said "hey magical computer, here's this bit of code and it's called &lt;code&gt;myFirstFunction&lt;/code&gt;". However, we haven't told the computer to run the code inside the function! Here's how we do it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;myFirstFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, we run it by referring to its name. We then have an empty set of brackets. This is where the inputs for the function would go, but we don't have any inputs just yet so again we leave them empty. Time to run your function! See if you can work out where to put it in the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFirstFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;myFirstFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this bit of code, it's at the end. However, it can be before the function too! This is very different to variables, where you have to declare the variable &lt;em&gt;before&lt;/em&gt; using it. This wouldn't work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myVariable&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myVariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, this would:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;myFirstFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFirstFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is common practice to put all your function definitions at the bottom of your script, but it doesn't really matter that much.&lt;/p&gt;

&lt;p&gt;Ooookay, here's the moment that you've probably been waiting for — time to try it out! Make sure that your script looks like the code above (although remember that it doesn't matter if you run the function before or after declaring it). Save, reload and Ta-da! Our code inside the function has now been run!&lt;/p&gt;

&lt;p&gt;At first, this may seem like overkill — why not just run the code? Well, imagine if you wanted to make this particular bit of code run at many different points inside your script — inside loops, if statements, and more. Well, then only having to say &lt;code&gt;myFirstFunction();&lt;/code&gt; would come in handy! Especially if your function was 30 lines long 😅&lt;/p&gt;

&lt;h2&gt;
  
  
  Functions with inputs
&lt;/h2&gt;

&lt;p&gt;In the function &lt;code&gt;myFirstFunction&lt;/code&gt;, we set a variable (&lt;code&gt;x&lt;/code&gt;) to &lt;code&gt;5&lt;/code&gt; and then alerted that (&lt;code&gt;10&lt;/code&gt;). What if we were to make a function called &lt;code&gt;alertDouble&lt;/code&gt; which alerted double &lt;em&gt;any&lt;/em&gt; number?&lt;/p&gt;

&lt;p&gt;In this case, we'd have one input — let's call it &lt;code&gt;num&lt;/code&gt;. Here's how the function declaration would look with &lt;code&gt;num&lt;/code&gt; as our input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;alertDouble&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now inside the curly brackets, we can use &lt;code&gt;num&lt;/code&gt; as a variable! (&lt;strong&gt;only inside the curly brackets&lt;/strong&gt;)&lt;/p&gt;

&lt;p&gt;See if you can work out how the finished function would look...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;alertDouble&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Did you get it right? If so, great! If not, don't worry — hopefully, you'll start to get it by the end of this article 🙏&lt;/p&gt;

&lt;h2&gt;
  
  
  Running functions with inputs
&lt;/h2&gt;

&lt;p&gt;Time to run our function! Let's try doubling a few different numbers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2&lt;/li&gt;
&lt;li&gt;70&lt;/li&gt;
&lt;li&gt;1024&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;First of all, you can leave this part of your existing code if you want:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFirstFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, we're done with it and don't want to run it anymore. So, delete or comment out this line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;myFirstFunction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead, we want to call our new function &lt;code&gt;alertDouble&lt;/code&gt;! First, we need to add the function declaration to the end of the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//myFirstFunction();&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFirstFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;alertDouble&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Time to run our function! If it didn't have any inputs, we would simply say &lt;code&gt;alertDouble()&lt;/code&gt;. However, we need to put the input for &lt;code&gt;num&lt;/code&gt; inside the brackets! So, let's try doubling 2 — see if you can guess the code!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;alertDouble&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;2&lt;/code&gt; inside the brackets then becomes &lt;code&gt;num&lt;/code&gt; inside the function when it is run! Try it out...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//myFirstFunction();&lt;/span&gt;

&lt;span class="nf"&gt;alertDouble&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFirstFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;alertDouble&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Woo! It alerted &lt;code&gt;4&lt;/code&gt;! 🎉&lt;br&gt;
Let's try with the other values...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//myFirstFunction();&lt;/span&gt;

&lt;span class="nf"&gt;alertDouble&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;alertDouble&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;70&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;alertDouble&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFirstFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;alertDouble&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yay! Now it alerts &lt;code&gt;4&lt;/code&gt;, &lt;code&gt;140&lt;/code&gt; and then &lt;code&gt;2048&lt;/code&gt;. Time to move on...&lt;/p&gt;

&lt;h2&gt;
  
  
  Functions with multiple inputs
&lt;/h2&gt;

&lt;p&gt;In the function &lt;code&gt;alertDouble&lt;/code&gt;, we multiplied &lt;code&gt;num&lt;/code&gt; by &lt;code&gt;2&lt;/code&gt;. What if we wanted to make a function called &lt;code&gt;alertMultiplied&lt;/code&gt; where we alerted one input multiplied by another input? Here we'd need two inputs: let's say &lt;code&gt;num1&lt;/code&gt; and &lt;code&gt;num2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;First of all, we need to declare the function! When functions have multiple inputs, they are separated by commas — see if you can work it out!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;alertMultiplied&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, it's just a simple matter of alerting &lt;code&gt;num1&lt;/code&gt; multiplied by &lt;code&gt;num2&lt;/code&gt;!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;alertMultiplied&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Running functions with multiple inputs
&lt;/h2&gt;

&lt;p&gt;First of all, comment out (or delete) all the &lt;code&gt;doubleMe&lt;/code&gt; function calls like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//myFirstFunction();&lt;/span&gt;

&lt;span class="c1"&gt;//alertDouble(2);&lt;/span&gt;
&lt;span class="c1"&gt;//alertDouble(70);&lt;/span&gt;
&lt;span class="c1"&gt;//alertDouble(1024);&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFirstFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;alertDouble&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's add the &lt;code&gt;alertMultiplied&lt;/code&gt; function declaration to the end of the code!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//myFirstFunction();&lt;/span&gt;

&lt;span class="c1"&gt;//alertDouble(2);&lt;/span&gt;
&lt;span class="c1"&gt;//alertDouble(70);&lt;/span&gt;
&lt;span class="c1"&gt;//alertDouble(1024);&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFirstFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;alertDouble&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;alertMultiplied&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, it's time to run the function. Let's try multiplying &lt;code&gt;5&lt;/code&gt; by &lt;code&gt;3&lt;/code&gt; and &lt;code&gt;8&lt;/code&gt; by &lt;code&gt;21&lt;/code&gt;. See if you can work out the code (hint: the inputs are separated by commas just like in the declaration 😉)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//myFirstFunction();&lt;/span&gt;

&lt;span class="c1"&gt;//alertDouble(2);&lt;/span&gt;
&lt;span class="c1"&gt;//alertDouble(70);&lt;/span&gt;
&lt;span class="c1"&gt;//alertDouble(1024);&lt;/span&gt;

&lt;span class="nf"&gt;alertMultiplied&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;alertMultiplied&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFirstFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;alertDouble&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;alertMultiplied&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save, reload and see what happens! It should alert &lt;code&gt;15&lt;/code&gt; followed by &lt;code&gt;168&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Functions with an output (functions that 'return' something)
&lt;/h2&gt;

&lt;p&gt;As well as having inputs, functions can also have outputs! However, a function can only have one output (unlike inputs).&lt;/p&gt;

&lt;p&gt;Let's make a function called &lt;code&gt;triple&lt;/code&gt;. However, unlike &lt;code&gt;alertDouble&lt;/code&gt;, it won't alert the result. It will output it!&lt;/p&gt;

&lt;p&gt;To output the result, we simply say inside the function &lt;code&gt;return&lt;/code&gt; and then whatever we want to output. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;introduce&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, I&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt; &lt;span class="nx"&gt;Johnny&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;;
}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that it &lt;em&gt;doesn't require brackets!&lt;/em&gt; However, you can put them in because they're optional. I prefer to put them in because it makes it easier to understand, but it's up to you. It would look like this with brackets:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;introduce&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, I&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="nx"&gt;m&lt;/span&gt; &lt;span class="nx"&gt;Johnny&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;);
}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Obviously, the value returned doesn't have to be a string.&lt;/p&gt;

&lt;p&gt;Let's try making our &lt;code&gt;triple&lt;/code&gt; function! It will need one input, &lt;code&gt;num&lt;/code&gt;. And it will need to output triple that number. See if you can work out how the function would look!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;triple&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Running functions with an output (getting the output)
&lt;/h2&gt;

&lt;p&gt;That's all fine and well, but how do we actually &lt;em&gt;get&lt;/em&gt; the output of this function? We do that by running it!&lt;/p&gt;

&lt;p&gt;The actual function call will become equal to the output, just like a variable is equal to a value. We can then use the function just like a variable. For example, we could say the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;triple&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;triple&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we are alerting the output of &lt;code&gt;triple(10)&lt;/code&gt;. Try it out! Don't forget to add the declaration and comment out the calls of &lt;code&gt;alertMultiplied&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//myFirstFunction();&lt;/span&gt;

&lt;span class="c1"&gt;//alertDouble(2);&lt;/span&gt;
&lt;span class="c1"&gt;//alertDouble(70);&lt;/span&gt;
&lt;span class="c1"&gt;//alertDouble(1024);&lt;/span&gt;

&lt;span class="c1"&gt;//alertMultiplied(5, 3);&lt;/span&gt;
&lt;span class="c1"&gt;//alertMultiplied(8, 21);&lt;/span&gt;

&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;triple&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFirstFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;alertDouble&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;alertMultiplied&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;triple&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Woo! The code will alert &lt;code&gt;30&lt;/code&gt;! We can also use the &lt;code&gt;triple&lt;/code&gt; function just like any other number:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;triple&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is simply like saying &lt;code&gt;(18 + 3) * 2&lt;/code&gt;, which is equal to &lt;code&gt;42&lt;/code&gt; (the meaning of life of course 😉). Try it out!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;//myFirstFunction();&lt;/span&gt;

&lt;span class="c1"&gt;//alertDouble(2);&lt;/span&gt;
&lt;span class="c1"&gt;//alertDouble(70);&lt;/span&gt;
&lt;span class="c1"&gt;//alertDouble(1024);&lt;/span&gt;

&lt;span class="c1"&gt;//alertMultiplied(5, 3);&lt;/span&gt;
&lt;span class="c1"&gt;//alertMultiplied(8, 21);&lt;/span&gt;

&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nf"&gt;triple&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;triple&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFirstFunction&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;alertDouble&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;alertMultiplied&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;num2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;triple&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;num&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now after alerting &lt;code&gt;30&lt;/code&gt;, our code will also alert &lt;code&gt;42&lt;/code&gt;! 🎉&lt;/p&gt;

&lt;h2&gt;
  
  
  Variable scopes within functions
&lt;/h2&gt;

&lt;p&gt;We're nearly done now! 😅&lt;br&gt;
However, there's one more important thing that you need to know about functions — Variables declared inside functions do not work outside of functions. Whaaat? Here's an example — try it out!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunc&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myVar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;myFunc&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myVar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It should alert 3, right? Nope! Because &lt;code&gt;myVar&lt;/code&gt; was declared &lt;em&gt;inside&lt;/em&gt; the function, it does not exist outside the function. The code will not work and give you the following error:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Uncaught ReferenceError: myVar is not defined&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;However, this &lt;em&gt;does&lt;/em&gt; work!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myVar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;myFunc&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;myVar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;myFunc&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myVar&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code will alert &lt;code&gt;3&lt;/code&gt;! Because &lt;code&gt;myVar&lt;/code&gt; has already been declared &lt;em&gt;outside&lt;/em&gt; the function, the code knows that it exists. It will be changed inside the function, and then the code can still alert it because it was defined outside the function.&lt;/p&gt;

&lt;p&gt;This is known as the &lt;em&gt;global&lt;/em&gt; scope. It means that for the rest of the code, &lt;code&gt;myVar&lt;/code&gt; will be defined. In the first example where &lt;code&gt;myVar&lt;/code&gt; was declared inside the function, it declared in the &lt;em&gt;function&lt;/em&gt; scope. It means that the variable will only be defined &lt;em&gt;inside&lt;/em&gt; the curly brackets of the function.&lt;/p&gt;

&lt;p&gt;This might take a while to wrap your head around, but you'll get it eventually. The main thing that you need to remember is that &lt;strong&gt;if you want to use a variable outside a function, declare it outside the function first&lt;/strong&gt;. You don't even have to say &lt;code&gt;var myVar = 1;&lt;/code&gt; — you can literally just say &lt;code&gt;var myVar;&lt;/code&gt; and that is enough. I may do an article focusing more on variable scopes in &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;future&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Whew! 😅&lt;br&gt;
That was a lot to cover, so good job making it all the way through! As always, keep practicing and you will eventually get it. If you need any help, feel free to &lt;a href="https://codetheweb.blog/contact" rel="noopener noreferrer"&gt;shoot me an email&lt;/a&gt; or &lt;a href="https://codetheweb.blog/2018/04/05/javascript-functions/#disqus_thread" rel="noopener noreferrer"&gt;hit the comments&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you learned something from this article, I'd really appreciate it if you &lt;a href="https://buymeacoff.ee/CodeTheWeb" rel="noopener noreferrer"&gt;bought me a coffee&lt;/a&gt;. I've written 53,000 words and counting all for free, to help people like you learn web development. It would be really awesome if you could give me a small tip in return 😉. While it may not seem like a lot, it all adds up. If every person who read an article on this site gave $1, I'd probably be earning close to the minimum hourly wage by now!&lt;/p&gt;

&lt;p&gt;If you know someone who this article or this blog would benefit, go ahead an &lt;a href="https://codetheweb.blog/2018/04/05/javascript-functions/#share" rel="noopener noreferrer"&gt;share it with them&lt;/a&gt; — they'll thank you later 😜&lt;/p&gt;

&lt;p&gt;Finally, if you want to receive some web-dev goodness in your inbox each week to help you learn JavaScript, enter your email and I'll do just that 😜&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;Click here to sign up :D&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Okay, that's it for today! Have fun coding and I'll see you next time, where I'll be talking all about &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;arrays (aka. lists) in JavaScript&lt;/a&gt;. See you then! 👊&lt;/p&gt;




&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Want more posts like this? &lt;a href="https://codetheweb.blog/newsletter/" rel="noopener noreferrer"&gt;Sign up to my newsletter&lt;/a&gt;.
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;I've worked hard on these tutorials and as of now do not make any money on them, so I'd really appreciate if you signed up ;)&lt;/strong&gt;&lt;/p&gt;


&lt;/blockquote&gt;

&lt;p&gt;This article was originally published at &lt;a href="https://codetheweb.blog" rel="noopener noreferrer"&gt;Code The Web&lt;/a&gt;, a fun and easy-to-understand blog to help you learn web development 🚀&lt;br&gt;
Learn: &lt;a href="https://codetheweb.blog/learn/html/" rel="noopener noreferrer"&gt;HTML&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/css/" rel="noopener noreferrer"&gt;CSS&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/javascript/" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>For loops and while loops in JavaScript</title>
      <dc:creator>Ethan</dc:creator>
      <pubDate>Sun, 25 Mar 2018 00:00:00 +0000</pubDate>
      <link>https://dev.to/codetheweb/for-loops-and-while-loops-in-javascript-3a1d</link>
      <guid>https://dev.to/codetheweb/for-loops-and-while-loops-in-javascript-3a1d</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Ffor-and-while-loops-javascript%2Fcover.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Ffor-and-while-loops-javascript%2Fcover.jpg" alt="For loops and while loops in JavaScript"&gt;&lt;/a&gt;&lt;br&gt;
Loops let you run code as many times as you want! They are really powerful, and a great thing to know. Learn them once and for all in this article from Code The Web!&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting started!
&lt;/h2&gt;

&lt;p&gt;Welcome to another post on Code The Web! First of all, I want to encourage you to follow along in this article. It will help you learn better, and also help you to remember what you have done. Let's start by making a new HTML file with a &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag in it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;If statements are awesome!&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;JavaScript :)&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
            &lt;span class="c1"&gt;// Our script will go here!&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once that's done, open it up in your web browser and you're ready to go! (don't forget to save and reload the page every time you make a change)&lt;/p&gt;

&lt;h2&gt;
  
  
  What are loops in JavaScript?
&lt;/h2&gt;

&lt;p&gt;Loops simply run a chunk of code multiple times. For example, take a look at this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we wanted to repeat this five times, we could do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, this is very bad programming and can get very unwieldy if you need to repeat large chunks of code hundreds of times. Also, it is not very useful. For example, what if wanted it to repeat &lt;code&gt;x&lt;/code&gt; times? This is where loops come in handy. The amount of times is often determined by variables, but can also be determined by actual numbers. Loops can be especially useful for doing something to each element in an &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;array&lt;/a&gt; (each item in a list) but come in handy in many of situations.&lt;/p&gt;

&lt;h2&gt;
  
  
  While loops
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Wait, if we're doing while loops first then why did the title start with "for"? I don't know really, it just sounds better that way.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A while loop keeps repeating code over and over again while a certain statement is &lt;code&gt;true&lt;/code&gt; (i.e. until it is &lt;code&gt;false&lt;/code&gt;). Here is the syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="cm"&gt;/* something that's true or false */&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Do some stuff&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's that simple! Here's an example which keeps finding a random number from &lt;code&gt;0&lt;/code&gt;-&lt;code&gt;1&lt;/code&gt; until it is over &lt;code&gt;0.2&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;hi&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But what if we wanted it to alert the number? We can't write &lt;code&gt;alert(Math.random())&lt;/code&gt; because then it would find a &lt;em&gt;new&lt;/em&gt; random number to alert. So, we'd have to make a variable and then set it to the random number at the end of each loop. It would then compare &lt;em&gt;this&lt;/em&gt; number, and would have it stored in a variable so we can alert it later:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;randomNum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomNum&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomNum&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;randomNum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Take a moment to look at that code. First, we set the variable &lt;code&gt;randomNum&lt;/code&gt; to a random number. We then see if it is greater than  0.2. If it is, we run the stuff inside the curly brackets. This alerts the number and then changes &lt;code&gt;randomNum&lt;/code&gt; to a new number. We then check to see if &lt;em&gt;this&lt;/em&gt; number is greater than &lt;code&gt;0.2&lt;/code&gt;. If it is, we run the stuff inside the curly brackets again, and it goes on and on...&lt;/p&gt;

&lt;p&gt;If the number is &lt;em&gt;not&lt;/em&gt; greater than &lt;code&gt;0.2&lt;/code&gt;, the stuff in the brackets doesn't run, and the program continues. It &lt;strong&gt;does not&lt;/strong&gt; then keep running until the number is greater than &lt;code&gt;0.2&lt;/code&gt; again.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h2&gt;
  
  
  ☢☢ A word of warning... AVOID INFINITE LOOPS! ☢☢
&lt;/h2&gt;

&lt;p&gt;Infinite loops are loops that will keep running forever. They can happen with both for loops &lt;em&gt;and&lt;/em&gt; while loops. Here is a very basic example — &lt;strong&gt;DON'T TRY IT UNLESS YOU'RE FINE TO LOSE ALL YOUR TABS&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// some code&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;It will freeze the page, and even entire browser depending on your computer. You will usually not be able to close the tab, and will probably need to quit and reopen the entire browser! &lt;strong&gt;So, always be on the lookout for infinite loops.&lt;/strong&gt; They might not always be as obvious as &lt;code&gt;while(true)&lt;/code&gt;. It could be &lt;em&gt;any&lt;/em&gt; statement that will always evaluate to &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  For loops
&lt;/h2&gt;

&lt;p&gt;Let's say you wanted to alert "Hi" five times. As I said earlier, this is a very bad way to do things:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, how would we do this with a while loop? We'd have to set a counter variable, and then add one to it each time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First, let's make this code follow better programming conventions. Instead of using the &lt;code&gt;counter&lt;/code&gt; variable, we should name it &lt;code&gt;i&lt;/code&gt;. This is simply a convention and stands for 'iteration'. You don't have to use &lt;code&gt;i&lt;/code&gt;, but it is a good idea to do so. It will make your code more easily integrated with other developers' codes, and make everything much more consistent.&lt;/p&gt;

&lt;p&gt;Also, we're starting the counter on &lt;code&gt;1&lt;/code&gt;. In programming, it is a convention to start counter variables on &lt;code&gt;0&lt;/code&gt;. Why not &lt;code&gt;1&lt;/code&gt;? Well, in most programming languages, the first element in an &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;array&lt;/a&gt; (list) is item &lt;code&gt;0&lt;/code&gt;, not item &lt;code&gt;1&lt;/code&gt;. Seeing as loops are often with arrays, it is good programming convention to start all for loops at &lt;code&gt;0&lt;/code&gt;. While it may seem confusing at first, it will make your code a lot less confusing as you progress in learning JavaScript. Because &lt;code&gt;i&lt;/code&gt; is now one less, we'd say &lt;code&gt;counter &amp;lt; 5&lt;/code&gt; instead of &lt;code&gt;counter &amp;lt;= 5&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Finally, there's the line where we increment &lt;code&gt;i&lt;/code&gt; by 1. Instead of saying &lt;code&gt;i = i + 1&lt;/code&gt;, there's a better way to do this! You can simply say &lt;code&gt;i++;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So, here's what our while loop looks like after getting it to follow good programming conventions ('best practices'):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Believe it or not, there is a much faster, better and easier way to do this using JavaScript! It's by using a for loop:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hi!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's take a look at this code. It's quite similar to a while loop, except all the different parts have been moved around. Again, we're using &lt;code&gt;i&lt;/code&gt; as our counter variable.&lt;/p&gt;

&lt;p&gt;So first, we're setting &lt;code&gt;i&lt;/code&gt; to &lt;code&gt;0&lt;/code&gt;. Instead of doing this before the loop, we do it inside the brackets of the for loop, right at the start.&lt;/p&gt;

&lt;p&gt;After the semicolon, we have a &lt;a href="https://codetheweb.blog/2018/02/28/if-statements-boolean-operators/" rel="noopener noreferrer"&gt;boolean&lt;/a&gt; expression (something that evaluates to &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;). This is like the part from the while loop, and operates in the same way! The stuff inside the curly brackets will run while that statement is equivalent to &lt;code&gt;true&lt;/code&gt; (in this case, &lt;code&gt;i &amp;lt; 5&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;After the second semicolon, we have our final bit of code inside the brackets: &lt;code&gt;i++&lt;/code&gt;. This is just our last line inside the curly brackets from the while loop! In short, the code after the second semicolon will run at the end of each repetition of the loop.&lt;/p&gt;

&lt;p&gt;Here's a summary of the for loop syntax to make it easier to understand:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="cm"&gt;/* Set your counter variable */&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="cm"&gt;/* Repeat while this is true */&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="cm"&gt;/* Run this at the end of each repetition */&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Your code!&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(hover over the code and scroll sideways to see it all, or drag sideways on a touchscreen)&lt;/p&gt;

&lt;p&gt;Try to make a for loop that alerts "Yay" three times. &lt;strong&gt;Don't use the code for repeating five times to help!&lt;/strong&gt; See if you can do it using just the syntax code to help you.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="cm"&gt;/* Set your counter variable */&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="cm"&gt;/* Repeat while this is true */&lt;/span&gt; &lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="cm"&gt;/* Run this at the end of each repetition */&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Your code!&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;See if you got it right!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Yay&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Also, you can use &lt;code&gt;i&lt;/code&gt; &lt;em&gt;inside&lt;/em&gt; your code in the curly brackets! While this mostly comes in handy for iterating through &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;arrays&lt;/a&gt;, it can be used however you want. For example, alerting the numbers from 0 - 4:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that it is from 0 - 4 not 1 - 5, because all loops should start at 0! If you wanted to alert the numbers from 1 - 5, I would do the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congrats on learning all about for loops and while loops! I know that when I was learning, I found the concept of for loops especially confusing. Remembering what the three parts inside the brackets went was quite hard, and the only way that I finally got it was through practice. So try making a few different things with for (and while) loops! It is the best way to learn it.&lt;/p&gt;

&lt;p&gt;If you got something out of this article, I'd really appreciate if you &lt;a href="https://codetheweb.blog/2018/03/25/for-and-while-loops-javascript/#share" rel="noopener noreferrer"&gt;shared it&lt;/a&gt; or &lt;a href="https://buymeacoff.ee/CodeTheWeb" rel="noopener noreferrer"&gt;bought me a coffee&lt;/a&gt;. It's $4 that would go a long way, and make the rest of my day awesome.&lt;/p&gt;

&lt;p&gt;If I'd spent the time on Code The Web working at the minimum wage instead, I would have earned $1,770 by now! But instead I've dedicated my time to you guys and to helping people learn, and only earned $16. So it would be great if you could &lt;a href="https://buymeacoff.ee/CodeTheWeb" rel="noopener noreferrer"&gt;give a little thanks in return&lt;/a&gt;, I'd really appreciate it! 😘&lt;/p&gt;

&lt;p&gt;If you want to receive more articles like this on web development as well as awesome web development articles from around the web, &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;be sure to sign up for the weekly newsletter!&lt;/a&gt; I only send an email once a week with a roundup of awesome articles. I'll leave this handy little form below...&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;Click here to sign up :D&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;See you next time, where I'll be talking about &lt;a href="https://codetheweb.blog/2018/04/05/javascript-functions/" rel="noopener noreferrer"&gt;functions in JavaScript!&lt;/a&gt; They are one of the most integral parts of JavaScript (I know I've been saying that for like 4 articles now, but it's true 😉). &lt;a href="https://codetheweb.blog/2018/04/05/javascript-functions/" rel="noopener noreferrer"&gt;See you then!&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;P.S. In this post, I officially passed 50,000 words! 🎉😁&lt;/strong&gt; It's been an awesome time writing this blog (nearly 6 months!), and I will definitely continue into the future! I want to thank all the fans, &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;newsletter subscribers&lt;/a&gt; and readers for actually coming and reading what I have to say. I really didn't think that Code The Web would have so many visitors, and really appreciate every single one of you all. 💖&lt;/p&gt;
&lt;/blockquote&gt;




&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Want more posts like this? &lt;a href="https://codetheweb.blog/newsletter/" rel="noopener noreferrer"&gt;Sign up to my newsletter&lt;/a&gt;.
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;I've worked hard on these tutorials and as of now do not make any money on them, so I'd really appreciate if you signed up ;)&lt;/strong&gt;&lt;/p&gt;


&lt;/blockquote&gt;

&lt;p&gt;This article was originally published at &lt;a href="https://codetheweb.blog" rel="noopener noreferrer"&gt;Code The Web&lt;/a&gt;, a fun and easy-to-understand blog to help you learn web development 🚀&lt;br&gt;
Learn: &lt;a href="https://codetheweb.blog/learn/html/" rel="noopener noreferrer"&gt;HTML&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/css/" rel="noopener noreferrer"&gt;CSS&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/javascript/" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>JavaScript Maths functions and operators</title>
      <dc:creator>Ethan</dc:creator>
      <pubDate>Sun, 18 Mar 2018 00:00:00 +0000</pubDate>
      <link>https://dev.to/codetheweb/javascript-maths-functions-and-operators-1bek</link>
      <guid>https://dev.to/codetheweb/javascript-maths-functions-and-operators-1bek</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fjavascript-math%2Fcover.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fjavascript-math%2Fcover.jpg" alt="JavaScript Maths functions and operators"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Learn how to use addition, subtraction, multiplication, division, powers, rounding, modulo and more in this article...&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started!
&lt;/h2&gt;

&lt;p&gt;Welcome to another post on Code The Web! First of all, I want to encourage you to follow along in this article. It will help you learn better, and also help you to remember what you have done. Let's start by making a new HTML file with a &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag in it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;If statements are awesome!&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;JavaScript :)&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
            &lt;span class="c1"&gt;// Our script will go here!&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once that's done, open it up in your web browser and you're ready to go! (don't forget to save and reload the page every time you make a change)&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of numbers
&lt;/h2&gt;

&lt;p&gt;There are two main types of numbers in JavaScript: &lt;em&gt;floats&lt;/em&gt; and &lt;em&gt;integers&lt;/em&gt;. Integers are whole numbers without decimals. Here are a few examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;3&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;0&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;156&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Floats are numbers which contain a decimal. It is important to note that &lt;em&gt;floats can be whole numbers&lt;/em&gt;. Wait whaaat? I thought you said that integers were whole numbers? Well, stuff like &lt;code&gt;5.0&lt;/code&gt; is still considered a float, because it has a decimal and &lt;em&gt;could&lt;/em&gt; be &lt;code&gt;5.1&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;2.225345&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;0.0&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;42.0&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the most part, you won't have to worry about these different types because JavaScript will automatically convert them for you (😍). However, in some programming languages, you will have to do it yourself. There are also some cases in JavaScript where you &lt;em&gt;will&lt;/em&gt; have to work with converting stuff between floats and integers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic operators
&lt;/h2&gt;

&lt;p&gt;Let's start right from the beginning - with the basic operations!&lt;/p&gt;

&lt;h3&gt;
  
  
  Addition
&lt;/h3&gt;

&lt;p&gt;Addition in JavaScript is really simple - all you need to do is put a plus sign between two numbers, just like in real life. Try it out! Add the following to your script, save, then reload the page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 3&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;2.5&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;3.5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 6&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to -5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also add floats and integers in the one expression:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;1.25&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 8.25&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Obviously, the number that is returned will be a float. Moving on!&lt;/p&gt;

&lt;h3&gt;
  
  
  Subtraction
&lt;/h3&gt;

&lt;p&gt;Subtraction also works just as it does in real life. Easy, huh? Here are some examples - you can try them out if you want:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 2&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;33&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to -9&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;3.3&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mf"&gt;1.1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to -4.4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Multiplication
&lt;/h3&gt;

&lt;p&gt;Multiplication is slightly different to how you would do it on paper. Normally, we would just use a cross symbol - the letter &lt;code&gt;x&lt;/code&gt; on a keyboard. However, we can't use that! In programming, we try to give each character only one meaning. Since &lt;code&gt;x&lt;/code&gt; is already a letter, we have to use something else. In JavaScript, we use the asterisk (&lt;code&gt;*&lt;/code&gt;) symbol. Here are some examples of multiplication in JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 3&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 72&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;2.23&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;7.92&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to -17.6616&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 12&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Division
&lt;/h3&gt;

&lt;p&gt;Division also works differently to on paper. While there is a &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;Unicode symbol&lt;/a&gt; for division (÷), it is not something that you can type easily on your keyboard and is not that commonly used. Instead, we use the slash (&lt;code&gt;/&lt;/code&gt;) sign to mean 'divided by'. Here are some examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 0.5&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to -5&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 0&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;64&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to Infinity&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I just want to highlight the last one on that list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;64&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to Infinity&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In maths, anything divided by 0 is equal to infinity (&lt;a href="https://math.stackexchange.com/questions/1399099/why-is-any-number-divided-by-0-is-infinite/1399100" rel="noopener noreferrer"&gt;explanation here&lt;/a&gt;). However, in JavaScript it can't equal to "&lt;code&gt;infinity&lt;/code&gt;" - otherwise JavaScript would think it was a variable! So, we need to capitalize it to make it &lt;code&gt;Infinity&lt;/code&gt;. This is a &lt;em&gt;special value&lt;/em&gt; in JavaScript (&lt;strong&gt;not&lt;/strong&gt; a variable). It doesn't really have many use cases but is the outcome of statements like the one above.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Fun fact: &lt;a href="https://stackoverflow.com/questions/27074158/infinity-infinity-nan" rel="noopener noreferrer"&gt;&lt;code&gt;Infinity - Infinity&lt;/code&gt; in JavaScript &lt;em&gt;does not&lt;/em&gt; equal &lt;code&gt;0&lt;/code&gt;!&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Modulo
&lt;/h3&gt;

&lt;p&gt;Modulo is something that you may not have heard of before, unlike the four operations above. Put simply, modulo is the &lt;em&gt;remainder&lt;/em&gt; when dividing two numbers. It is done by putting a &lt;code&gt;%&lt;/code&gt; sign between the two numbers. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's break it down a bit further. We have the numbers &lt;code&gt;24&lt;/code&gt; and &lt;code&gt;5&lt;/code&gt;, separated by the modulo (&lt;code&gt;%&lt;/code&gt;) sign. This means that to calculate the answer in our heads, we'd first need to divide &lt;code&gt;24&lt;/code&gt; by &lt;code&gt;5&lt;/code&gt; (into groups of five). Here, we can make four groups of five. However, we'd still have an extra &lt;code&gt;4&lt;/code&gt; left over as a remainder. So, the answer is &lt;code&gt;4&lt;/code&gt;. Here are some other examples - if you still don't get it, try and do the process above on these:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 2&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 0, 3 goes into 30 ten times without a remainder&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;code&gt;Math&lt;/code&gt; functions
&lt;/h2&gt;

&lt;p&gt;As well as the operators above, there are also some functions that we can use to carry out slightly more advanced tasks. These functions generally follow the form of &lt;code&gt;Math.whateverTheFunctionIs()&lt;/code&gt;. This is because &lt;code&gt;Math&lt;/code&gt; is an &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;object&lt;/a&gt; containing lots of different math-related functions. I'll talk more about objects in a &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;later article&lt;/a&gt;, but you don't really have to worry about how it works for the moment. Just use the syntax that I put here and you'll be fine.&lt;/p&gt;

&lt;h3&gt;
  
  
  To the power of
&lt;/h3&gt;

&lt;p&gt;We do this using the &lt;code&gt;Math.pow(number,power)&lt;/code&gt; function. For example, let's say we wanted to square the number &lt;code&gt;5&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 25&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait whaaat? A function &lt;em&gt;inside&lt;/em&gt; the &lt;code&gt;alert&lt;/code&gt; function? Yup. This is because &lt;code&gt;Math.pow&lt;/code&gt; is a function that &lt;a href="https://codetheweb.blog/2018/04/05/javascript-functions/#functions-with-an-output-functions-that-return-something" rel="noopener noreferrer"&gt;&lt;em&gt;returns&lt;/em&gt; something&lt;/a&gt;. You can think of it just like a variable. So instead of &lt;code&gt;x&lt;/code&gt; being equal to &lt;code&gt;25&lt;/code&gt;, &lt;code&gt;Math.pow(5,2)&lt;/code&gt; is equal to &lt;code&gt;25&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can also go to higher powers if you want (pun intended 🙏 &lt;em&gt;*sigh*&lt;/em&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// 3 to the power of 3&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 27&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// 2 to the power of 10&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 1024&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Square root &amp;amp; Cube root
&lt;/h3&gt;

&lt;p&gt;You can calculate square an cube roots in JavaScript using the &lt;code&gt;Math.sqrt()&lt;/code&gt; and &lt;code&gt;Math.cbrt()&lt;/code&gt; functions. Here are some examples which you can try out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sqrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 5&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cbrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Rounding
&lt;/h3&gt;

&lt;p&gt;We can round a number to a whole number using the &lt;code&gt;Math.round()&lt;/code&gt; function. Here are some examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;35.82562&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 36&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;35.22353&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 35&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 4 (already rounded)&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;6.5&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 7 (.5 rounds up)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will round &lt;em&gt;up&lt;/em&gt; if the decimal part of the number is greater than or equal to &lt;code&gt;0.5&lt;/code&gt;. Otherwise it will round down.&lt;/p&gt;

&lt;h3&gt;
  
  
  Specifically rounding up or down
&lt;/h3&gt;

&lt;p&gt;But what if we want to specifically round up or down? For example, what if before we wanted to round &lt;code&gt;35.82562&lt;/code&gt; &lt;em&gt;downwards&lt;/em&gt;? This is where &lt;em&gt;floor&lt;/em&gt; and &lt;em&gt;ceiling&lt;/em&gt; come in handy. &lt;code&gt;Math.floor()&lt;/code&gt; rounds the number &lt;em&gt;down&lt;/em&gt; no matter what, while &lt;code&gt;Math.ceil()&lt;/code&gt; rounds the number &lt;em&gt;up&lt;/em&gt; no matter what. Note that &lt;code&gt;Math.ceil(6)&lt;/code&gt; or even &lt;code&gt;Math.ceil(6.0)&lt;/code&gt; would not round up to &lt;code&gt;7&lt;/code&gt;. Here are some examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;35.82562&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 35&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;35.82562&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 36&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;4.0&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 4&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;4.01&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 5&lt;/span&gt;
&lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.99999&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="c1"&gt;// Equal to 0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;That's it for today! This just covered some basic math operations, but there are many more. &lt;a href="https://www.w3schools.com/js/js_math.asp" rel="noopener noreferrer"&gt;Click here&lt;/a&gt; for a list of all the functions in the &lt;code&gt;Math&lt;/code&gt; object (the ones that start with &lt;code&gt;Math.&lt;/code&gt;). As well as having functions, the &lt;code&gt;Math&lt;/code&gt; object also has some static values such as &lt;code&gt;Math.PI&lt;/code&gt; - they are listed on that page as well.&lt;/p&gt;

&lt;p&gt;Hopefully, you learned a lot from this article! If you did, I'd be stoked if you &lt;a href="https://codetheweb.blog/2018/03/18/javascript-math/#share" rel="noopener noreferrer"&gt;shared it&lt;/a&gt; on social media.&lt;/p&gt;

&lt;p&gt;Also, it takes me a lot of time to write these articles. So far I've spent 1 hour and 45 minutes on this article, and I spend over 3 hours on some articles! At the time of writing, I currently don't have any ads on here, so the only way that I can get support for all this content is via donations.&lt;/p&gt;

&lt;p&gt;If you want to give me a little thanks and make my entire day feel awesome, I'd really appreciate if you'd &lt;a href="https://buymeacoff.ee/CodeTheWeb" rel="noopener noreferrer"&gt;buy me a coffee ☕&lt;/a&gt;. It's only $4, and it makes a big difference. In fact, at the moment I'm only 49 cents short of covering my costs for Code The Web, and it would be really cool if you were the one to help me reach that milestone. Okie, enough about that 😉&lt;/p&gt;

&lt;p&gt;If you need any help with the topics covered in this article or want to give feedback (I love myself some scrumptious feedback), please do so in the &lt;a href="https://codetheweb.blog/2018/03/18/javascript-math/#disqus_thread" rel="noopener noreferrer"&gt;comments below&lt;/a&gt; or via the cool live chat widget that is probably in the bottom-right corner of your screen right now.&lt;/p&gt;

&lt;p&gt;Also, if you want the latest web development articles from Code The Web and around the internet in your inbox about once a week, enter your email below! You can unsubscribe at any time.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;Click here to sign up :D&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;That's it for today! Next time, I'll be writing about &lt;a href="https://codetheweb.blog/2018/03/25/for-and-while-loops-javascript/" rel="noopener noreferrer"&gt;for loops and while loops in JavaScript&lt;/a&gt; - they are really cool, because you can tell the browser to repeat bits of your code over and over again (even with different values each time)! See you then 🚀&lt;/p&gt;




&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Want more posts like this? &lt;a href="https://codetheweb.blog/newsletter/" rel="noopener noreferrer"&gt;Sign up to my newsletter&lt;/a&gt;.
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;I've worked hard on these tutorials and as of now do not make any money on them, so I'd really appreciate if you signed up ;)&lt;/strong&gt;&lt;/p&gt;


&lt;/blockquote&gt;

&lt;p&gt;This article was originally published at &lt;a href="https://codetheweb.blog" rel="noopener noreferrer"&gt;Code The Web&lt;/a&gt;, a fun and easy-to-understand blog to help you learn web development 🚀&lt;br&gt;
Learn: &lt;a href="https://codetheweb.blog/learn/html/" rel="noopener noreferrer"&gt;HTML&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/css/" rel="noopener noreferrer"&gt;CSS&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/javascript/" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>All about IF statements and booleans in JavaScript!</title>
      <dc:creator>Ethan</dc:creator>
      <pubDate>Wed, 28 Feb 2018 00:00:00 +0000</pubDate>
      <link>https://dev.to/codetheweb/all-about-if-statements-and-booleans-in-javascript-5com</link>
      <guid>https://dev.to/codetheweb/all-about-if-statements-and-booleans-in-javascript-5com</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UJhgMqk7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/if-statements-boolean-operators/cover.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UJhgMqk7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/if-statements-boolean-operators/cover.jpg" alt="All about IF statements and booleans in JavaScript!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If statements are another core part of JavaScript: they let you control what code is actually executed, based on comparing values and/or variables. I'll also teach you about all the cool stuff that you can do with booleans! Read on below...&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started!
&lt;/h2&gt;

&lt;p&gt;First of all, I want to encourage you to follow along in this article! Let's start by making a new HTML file with a &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag in it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;If statements are awesome!&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;JavaScript :)&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
            &lt;span class="c1"&gt;// Our script will go here!&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once that's done, open it up in your web browser and you're ready to go! (don't forget to save and reload the page every time you make a change)&lt;/p&gt;

&lt;h2&gt;
  
  
  What is an if statement?
&lt;/h2&gt;

&lt;p&gt;In essence, an if statement simply executes some code if a value is equivalent to &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h2&gt;
  
  
  Terminology
&lt;/h2&gt;

&lt;p&gt;In this article, I'll be using the terms 'brackets' and 'curly brackets'. When I say brackets I mean these: &lt;code&gt;( )&lt;/code&gt; And when  I say curly brackets I mean these: &lt;code&gt;{ }&lt;/code&gt;. The only reason that I am saying this is because I know that depending on which part of the world you come from, you may have different names for your square, curly and normal brackets (eg. parentheses).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The if statement syntax
&lt;/h2&gt;

&lt;p&gt;Here's what a simple if statement looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Yay!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's have a look at what's going on here. In essence, we're simply saying if the stuff inside the brackets is equivalent to &lt;code&gt;true&lt;/code&gt;, execute the code inside the curly brackets. Note here that I said &lt;em&gt;equivalent&lt;/em&gt; to &lt;code&gt;true&lt;/code&gt;. This doesn't mean that the text between the brackets literally has to say &lt;code&gt;true&lt;/code&gt;. It just means that it needs to be a statement that is true. For example: &lt;code&gt;1 + 3 == 4&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Don't worry, I'll get into how this works later (I'll be speaking more about JavaScript &lt;a href="https://codetheweb.blog/2018/03/18/javascript-math/"&gt;math&lt;/a&gt; in a later article). It's basically just 1 + 3 = 4. 1 + 3 &lt;em&gt;does&lt;/em&gt; equal 4, so it is equivalent to &lt;code&gt;true&lt;/code&gt;. Therefore, if we put this inside the brackets our code will run! Let's try it out. Put the following code in your &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag, then reload the page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Yay!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's try and make it so that the alert &lt;em&gt;doesn't&lt;/em&gt; run. We would do this by making the statement inside the brackets equivalent to &lt;code&gt;false&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Yay!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(your high school math teacher wouldn't be proud)&lt;/p&gt;

&lt;p&gt;Now, because the statement in the brackets is &lt;code&gt;false&lt;/code&gt;, the code inside the curly brackets will not run! Try it out yourself... It will no longer alert "Yay!"&lt;/p&gt;

&lt;p&gt;You have now learned the basic &lt;code&gt;if&lt;/code&gt; statement syntax!&lt;/p&gt;

&lt;h2&gt;
  
  
  Boolean operators
&lt;/h2&gt;

&lt;p&gt;It's time to take a bit of a closer look at what gives us &lt;code&gt;true&lt;/code&gt; and what gives us &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's use the statement from above as an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="cm"&gt;/* Returns true */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we're using the double equals sign (&lt;code&gt;==&lt;/code&gt;) to compare the two sides: &lt;code&gt;1 + 3&lt;/code&gt; and &lt;code&gt;4&lt;/code&gt;. This comparison sign says is saying "if they are &lt;em&gt;equal&lt;/em&gt;, then return &lt;code&gt;true&lt;/code&gt;". But we can compare in other ways as well! For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="cm"&gt;/* Returns false */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we're telling the computer to return &lt;code&gt;true&lt;/code&gt; if &lt;code&gt;1 + 3&lt;/code&gt; is &lt;em&gt;not&lt;/em&gt; equal to &lt;code&gt;4&lt;/code&gt;. &lt;code&gt;1 + 3&lt;/code&gt; is obviously equal to &lt;code&gt;4&lt;/code&gt;, so it returns &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;There are a few other comparisons that we can use - here is a list of the basic comparison signs:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Sign&lt;/th&gt;
&lt;th&gt;Returns &lt;code&gt;true&lt;/code&gt; &lt;em&gt;if&lt;/em&gt;...&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;==&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Both sides are &lt;strong&gt;equal&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;!=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Both sides are &lt;strong&gt;not equal&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The left side is &lt;strong&gt;less than&lt;/strong&gt; the right side&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The left side is &lt;strong&gt;greater than&lt;/strong&gt; the right side&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;lt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The left side is &lt;strong&gt;less than or equal to&lt;/strong&gt; the right side&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;&amp;gt;=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;The left side is &lt;strong&gt;greater than or equal to&lt;/strong&gt; the right side&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Let's try a few of them out... Challenge Time!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question 1:&lt;/strong&gt; Alert "Not fake news!" if &lt;code&gt;4&lt;/code&gt; is less than &lt;code&gt;410&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;410&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Not fake news!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Question 2:&lt;/strong&gt; Alert "5 is the greatest!" if &lt;code&gt;5&lt;/code&gt; is greater &lt;code&gt;6&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;5 is the greatest!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Question 3:&lt;/strong&gt; Alert "JavaScript is awesome!" if &lt;code&gt;3&lt;/code&gt; is less than or equal to &lt;code&gt;3&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;JavaScript is awesome!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Multiple true/false statements
&lt;/h2&gt;

&lt;p&gt;What if we want to combine multiple statements? For example, what if we want to say if &lt;code&gt;3 + 5&lt;/code&gt; equals &lt;code&gt;8&lt;/code&gt; &lt;em&gt;and&lt;/em&gt; &lt;code&gt;2 + 2&lt;/code&gt; equals &lt;code&gt;4&lt;/code&gt;? We have two main ways of combining statements like the one above: &lt;em&gt;and&lt;/em&gt; and &lt;em&gt;or&lt;/em&gt;. &lt;em&gt;And&lt;/em&gt; is simply &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt;, and &lt;em&gt;or&lt;/em&gt; is simply &lt;code&gt;||&lt;/code&gt; (that's 2x the key with the vertical line on it, usually it will be &lt;code&gt;SHIFT + backslash&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Here's how &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; (&lt;em&gt;and&lt;/em&gt;) works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="cm"&gt;/* Returns true */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="cm"&gt;/* Returns false */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="cm"&gt;/* Returns false */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here's how &lt;code&gt;||&lt;/code&gt; (&lt;em&gt;or&lt;/em&gt;) works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="cm"&gt;/* Returns true */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="cm"&gt;/* Returns true */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="cm"&gt;/* Returns false */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's important to not here that &lt;code&gt;true || true&lt;/code&gt; is equal to &lt;code&gt;true&lt;/code&gt;, not &lt;code&gt;false&lt;/code&gt;. This is because &lt;strong&gt;in JavaScript, &lt;em&gt;or&lt;/em&gt; actually means &lt;em&gt;and or&lt;/em&gt;&lt;/strong&gt;. Don't ask me why, programming languages sometimes have weird things like that.&lt;/p&gt;

&lt;p&gt;Now, let's substitute in a few real statements instead of just &lt;code&gt;true&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt;. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;65&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="cm"&gt;/* Returns true */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You don't need to have the brackets, but I've put them in brackets just to make it a bit clearer (you are allowed to do that in JavaScript). As you can see, the code above is simply this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="cm"&gt;/* Returns true */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The only difference is that &lt;code&gt;true&lt;/code&gt; has been replaced with &lt;code&gt;65 &amp;gt; 25&lt;/code&gt; which is &lt;em&gt;equivalent&lt;/em&gt; to &lt;code&gt;true&lt;/code&gt;, and similarly &lt;code&gt;false&lt;/code&gt; has been replaced with &lt;code&gt;5 + 1 == 5&lt;/code&gt; which is equivalent to &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Your turn to try! See if you can complete the following tasks:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question 1:&lt;/strong&gt; Alert "The Universe is not broken" if &lt;code&gt;5&lt;/code&gt; is equal to &lt;code&gt;5&lt;/code&gt; and &lt;code&gt;3&lt;/code&gt; is equal to &lt;code&gt;3&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;The Universe is not broken&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Question 2:&lt;/strong&gt; Alert "At least one of the statements is correct" if &lt;code&gt;1&lt;/code&gt; plus &lt;code&gt;2&lt;/code&gt; equals &lt;code&gt;4&lt;/code&gt; or &lt;code&gt;1&lt;/code&gt; plus &lt;code&gt;2&lt;/code&gt; equals &lt;code&gt;3&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;At least one of the statements is correct&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Question 3:&lt;/strong&gt; Alert "I am such a rebel" if &lt;code&gt;5&lt;/code&gt; plus &lt;code&gt;5&lt;/code&gt; is not equal to &lt;code&gt;10&lt;/code&gt; or &lt;code&gt;2&lt;/code&gt; plus &lt;code&gt;4&lt;/code&gt; is greater than or equal to &lt;code&gt;7&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I am such a rebel&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Question 4:&lt;/strong&gt; Alert "42 is between 21 and 47" if &lt;code&gt;42&lt;/code&gt; is greater than &lt;code&gt;21&lt;/code&gt; and &lt;code&gt;42&lt;/code&gt; is less than &lt;code&gt;47&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;21&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;42&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;47&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;42 is between 21 and 47&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Woo! Hopefully, you did okay 😉&lt;/p&gt;

&lt;h3&gt;
  
  
  One more thing on boolean operators...
&lt;/h3&gt;

&lt;p&gt;There's one final super-handy trick that you should know about booleans in JavaScript... By putting a single exclamation mark before a statement, you &lt;em&gt;reverse&lt;/em&gt; the boolean. For example, &lt;code&gt;!true&lt;/code&gt; would equal &lt;code&gt;false&lt;/code&gt; and &lt;code&gt;!false&lt;/code&gt; will equal &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If putting the exclamation before a statement with spaces or symbols in between (eg. &lt;code&gt;1 + 2 == 3&lt;/code&gt; as supposed to &lt;code&gt;true&lt;/code&gt;), don't forget to surround it with brackets! This ensures that the exclamation mark works for the whole statement. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Woo!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, the &lt;code&gt;5 + 2 &amp;lt; 3&lt;/code&gt; gets wrapped in brackets so that the exclamation mark applies to all of it.&lt;/p&gt;

&lt;p&gt;It's worth noting that in the example above, we didn't really need the exclamation mark in the first place - &lt;code&gt;!(5 + 2 &amp;lt; 3)&lt;/code&gt; is the same as &lt;code&gt;5 + 2 &amp;gt;= 3&lt;/code&gt;. However, it is still useful to know about this feature and can come in handy when making more complex statements.&lt;/p&gt;

&lt;h2&gt;
  
  
  ...Else?
&lt;/h2&gt;

&lt;p&gt;We can also give our if statement an &lt;code&gt;else&lt;/code&gt;, which will run if the code inside the first set of curly brackets &lt;em&gt;doesn't&lt;/em&gt; run - in other words, if the statement inside the normal brackets is &lt;code&gt;false&lt;/code&gt;. Here's what it looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="cm"&gt;/* some statement... */&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cm"&gt;/* some code to be run if that statement is true */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cm"&gt;/* some code to be run if that statement is not true */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try it out! Write some code that will alert "2 is less than 1" if &lt;code&gt;2&lt;/code&gt; is less than &lt;code&gt;1&lt;/code&gt; and will alert "2 is not less than 1" otherwise...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2 is less than 1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2 is not less than 1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There we go! Else statements are that simple! They simply run if the first set of curly brackets &lt;em&gt;doesn't&lt;/em&gt; run.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; It is very important that the &lt;code&gt;else&lt;/code&gt; comes straight after the end of the &lt;code&gt;if&lt;/code&gt;, with no other code in between.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Else if
&lt;/h2&gt;

&lt;p&gt;Wait, it could get even more confusing? Sort of. Here's what an &lt;code&gt;if&lt;/code&gt; statement looks like with both an &lt;code&gt;else if&lt;/code&gt; and an &lt;code&gt;else&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="cm"&gt;/* some statement... */&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cm"&gt;/* some code to be run if that statement is true */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="cm"&gt;/* another statement... */&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cm"&gt;/* some code to be run if the first statement is false and the else if statement is true */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cm"&gt;/* some code to be run if nothing has been run yet */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This may look confusing at first. However, let's pretend we're the computer and look at it from the computer's point of view.&lt;/p&gt;

&lt;p&gt;First of all, we have an &lt;code&gt;if&lt;/code&gt; statement. If the stuff inside the brackets is true, we execute the stuff in its set of curly and stop. If it is not true, we move on to the else if. If the stuff inside &lt;em&gt;that&lt;/em&gt; set of brackets is true, we run the stuff in &lt;em&gt;its&lt;/em&gt; set of curly brackets and stop. Finally, if we are still going and nothing has been true yet, we execute the stuff in the &lt;code&gt;else&lt;/code&gt;'s pair of curly brackets.&lt;/p&gt;

&lt;p&gt;Okay, you can stop being a computer now.&lt;/p&gt;

&lt;p&gt;Try doing one of these yourself - we'll use the example from before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2 is less than 1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2 is not less than 1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we want it to alert "2 is equal to 1" if &lt;code&gt;2 == 1&lt;/code&gt;, otherwise alert "2 is less than 1" if &lt;code&gt;2 &amp;lt; 1&lt;/code&gt; and alert "2 is greater than 1" if none of the others are true. Have a go!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2 is equal to 1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2 is less than 1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2 is greater than 1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the computer would evaluate &lt;code&gt;2 == 1&lt;/code&gt; - this is &lt;code&gt;false&lt;/code&gt;, so we move on to the next statement - our &lt;code&gt;else if&lt;/code&gt;, &lt;code&gt;2 &amp;lt; 1&lt;/code&gt;. This is again &lt;code&gt;false&lt;/code&gt;, so we move on to the &lt;code&gt;else&lt;/code&gt; and execute the code inside of that set of curly brackets: &lt;code&gt;alert('2 is greater than 1')&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Extension:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Make a script where the &lt;code&gt;if&lt;/code&gt; code runs, one where the &lt;code&gt;else if&lt;/code&gt; code runs and one where the &lt;code&gt;else&lt;/code&gt; code runs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You can have multiple else if's in an if / else if / else statement!!&lt;/strong&gt; Try making one like the example below:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1 is 5&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1 is 4&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;1 is 3&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;None of those were correct!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why does any of this matter?
&lt;/h2&gt;

&lt;p&gt;In this article, I mainly used numbers to illustrate how if statements work more clearly. However, once we put variables in our if statements instead of just set values, they become a super-useful tool and one of the core parts of JavaScript!&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Woo! That was intense 🔥 🔥&lt;/p&gt;

&lt;p&gt;I hope you learned a lot today, and it helped you in your &lt;a href="https://codetheweb.blog/learn/js"&gt;quest to learn JavaScript&lt;/a&gt;! If it was helpful, I'd really appreciate it if you &lt;a href="https://codetheweb.blog/2018/02/28/if-statements-boolean-operators/#share"&gt;shared this article&lt;/a&gt; or &lt;a href="https://codetheweb.blog/newsletter"&gt;signed up to the newsletter&lt;/a&gt; to receive new posts fresh in your inbox!&lt;/p&gt;

&lt;p&gt;Also, I'd really appreciate it if you &lt;a href="https://buymeacoffee.com/CodeTheWeb"&gt;bought me a coffee&lt;/a&gt; ☕ - this article is over 2,500 words and has taken over 2.5 hours to write! And c'mon, it's only a few bucks. That said, I don't want you to feel like you have to. In fact, go ahead and don't. Be a rebel. I won't get offended and will love you all the same. I'm perfectly happy giving my content away free - otherwise, you would be paying to read this right now! 😉 🤑&lt;/p&gt;

&lt;p&gt;Okay, so that's it for today! Don't forget to head to the &lt;a href="https://codetheweb.blog/2018/02/28/if-statements-boolean-operators/#disqus_thread"&gt;comments&lt;/a&gt; if you have any questions or feedback.&lt;/p&gt;

&lt;p&gt;Next time, I'll be writing about some basic math in JavaScript. I'll be talking about stuff like multiplication, rounding, square roots and more - way beyond the simple &lt;code&gt;1 + 2&lt;/code&gt; that we learned today! See you &lt;a href="https://codetheweb.blog/2018/03/18/javascript-math/"&gt;next time&lt;/a&gt; 😉&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;P.S.&lt;/strong&gt; Tomorrow marks 5 months since my first article on Code The Web! 🎉 🎉  In that time, I've written nearly 50,000 words and 30 articles. I'm still really enjoying blogging, creating content and sharing my knowledge with Y'all, and love the chats that I have with &lt;a href="https://codetheweb.blog/newsletter"&gt;subscribers&lt;/a&gt; and other members of the community. Keep on being awesome, and if you wanna chat then feel free to &lt;a href="https://codetheweb.blog/contact"&gt;contact me!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(and if ya wanna say thanks, I wouldn't mind a &lt;a href="https://buymeacoffee.com/CodeTheWeb"&gt;coffee&lt;/a&gt; 😉 ☕)&lt;/p&gt;
&lt;/blockquote&gt;




&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Want more posts like this? &lt;a href="https://codetheweb.blog/newsletter/"&gt;Sign up to my newsletter&lt;/a&gt;.
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;I've worked hard on these tutorials and as of now do not make any money on them, so I'd really appreciate if you signed up ;)&lt;/strong&gt;&lt;/p&gt;


&lt;/blockquote&gt;

&lt;p&gt;This article was originally published at &lt;a href="https://codetheweb.blog"&gt;Code The Web&lt;/a&gt;, a fun and easy-to-understand blog to help you learn web development 🚀&lt;br&gt;
Learn: &lt;a href="https://codetheweb.blog/learn/html/"&gt;HTML&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/css/"&gt;CSS&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/javascript/"&gt;JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Variables in JavaScript</title>
      <dc:creator>Ethan</dc:creator>
      <pubDate>Mon, 19 Feb 2018 00:00:00 +0000</pubDate>
      <link>https://dev.to/codetheweb/variables-in-javascript-3m52</link>
      <guid>https://dev.to/codetheweb/variables-in-javascript-3m52</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LyeGMs-k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/javascript-variables/cover.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LyeGMs-k--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/javascript-variables/cover.jpg" alt="Variables in JavaScript"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Variables are a core part of JavaScript - in fact, they are a core part of almost any programming language. They let you store information, and are the basis of what makes JavaScript so powerful. Learn all about them in this article...&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a variable?
&lt;/h2&gt;

&lt;p&gt;A variable is simply a place to store something. In fact, you can think of a variable like a cupboard. First, we need to &lt;em&gt;create&lt;/em&gt; the cupboard to store stuff in. Next, we'll want to put something in the cupboard. Then later, we'll want to retrieve the item and use it. We might also want to replace the item with another item.&lt;/p&gt;

&lt;p&gt;Time to see it in use! Let's say we wanted to alert the number &lt;code&gt;25&lt;/code&gt;. Normally, we'd do it like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But what about doing this using a variable? Here's how:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's take a look at what's going on here- first of all, we're &lt;em&gt;creating&lt;/em&gt; (aka &lt;em&gt;declaring&lt;/em&gt;) our variable called &lt;code&gt;x&lt;/code&gt; by saying &lt;code&gt;var x&lt;/code&gt;. On this same line, we're also giving the variable an initial value to store by saying &lt;code&gt;= 25&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now, when we run this code it will alert &lt;code&gt;25&lt;/code&gt;! This is because &lt;code&gt;x&lt;/code&gt; is now just a placeholder for the number 25. It is just like if you were editing a document and wanted to replace all instances of the word "banana" - in this case, the browser goes through our code and replaces all instances of the variable &lt;code&gt;x&lt;/code&gt; with &lt;code&gt;25&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;PS: Follow along! Create a new file called &lt;code&gt;index.html&lt;/code&gt; and add the following code:&lt;/p&gt;


&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Hello world in JavaScript!&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;JavaScript :)&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
            &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;You can now put all of your JavaScript inside the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag! 🎉&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But why does any of this matter? Well, the true power of variables is the fact that you can &lt;em&gt;change&lt;/em&gt; them. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;85&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, setting a variable that had already been declared is as simple as saying &lt;code&gt;x = 85&lt;/code&gt;. You don't need the &lt;code&gt;var&lt;/code&gt; bit, as it's already declared.&lt;/p&gt;

&lt;p&gt;Now, we can alert &lt;code&gt;85&lt;/code&gt; without even changing the line where it says &lt;code&gt;alert&lt;/code&gt;! This might seem weird now, but variables are one of the core parts of JavaScript and will come in handy more as you write more complicated code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types of variables
&lt;/h2&gt;

&lt;p&gt;In JavaScript, there are different variable &lt;em&gt;types&lt;/em&gt;. This is because it needs to know what type of data we are giving the variable, because, well, computers are dumber than you are. Note that &lt;strong&gt;you can change a variable to a different type after it has been declared, it doesn't need to stay the same type.&lt;/strong&gt; Here are some of the basic data types in JavaScript:&lt;/p&gt;

&lt;h3&gt;
  
  
  Strings
&lt;/h3&gt;

&lt;p&gt;A &lt;em&gt;string&lt;/em&gt; is another way of saying some text. We have to surround it in quotes because otherwise it would be considered a variable. Here is an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;I am a string!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It doesn't matter if you have single or double quotes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I am a string!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Numbers
&lt;/h3&gt;

&lt;p&gt;Obviously, we can also set a variable to a &lt;em&gt;number&lt;/em&gt; - like we did before! It can be a whole number:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or a decimal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;3.14&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Booleans
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Booleans&lt;/em&gt; are simply &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt; values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This may sound very simple, but they can come in handy when using &lt;a href="https://codetheweb.blog/2018/02/28/if-statements-boolean-operators/"&gt;&lt;code&gt;if&lt;/code&gt; statements&lt;/a&gt; - which let you execute bits of your code based on whether statements equal &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Yay! You now know all about variables! Let's go through what we've learned today.&lt;/p&gt;

&lt;p&gt;First of all, we learned how to declare, set and change variables:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="cm"&gt;/* Declared and set a variable */&lt;/span&gt;

&lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Helloooo!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="cm"&gt;/* Change a variable (you can change it to a different type) */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We also learned about some of the basic types of data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;2.71&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="cm"&gt;/* Number */&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;I &amp;lt;3 JavaScript!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="cm"&gt;/* String */&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="cm"&gt;/* Boolean */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'm honored to be part of your coding journey, and I hope you found this useful! If so, why don't you &lt;a href="https://codetheweb.blog/newsletter/"&gt;join the newsletter&lt;/a&gt; and receive more articles like this in your inbox? Plus, I'll love you in return &amp;lt;3&lt;/p&gt;

&lt;p&gt;Also, if you are &lt;em&gt;really&lt;/em&gt; nice and have $4 to spare, I'd really appreciate it if you &lt;a href="https://buymeacoffee.com/CodeTheWeb/"&gt;buy me a coffee ☕&lt;/a&gt;. Thanks!&lt;/p&gt;

&lt;p&gt;And if there's anyone who you think this article would really help out, don't forget to &lt;a href="https://codetheweb.blog/2018/02/25/javascript-variables/#share"&gt;share it with them!&lt;/a&gt; Finally, if you wanna chat with me (or other people), head down to the &lt;a href="https://codetheweb.blog/2018/02/25/javascript-variables/#disqus_thread"&gt;comments below&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;See you next time, when I'll be talking about &lt;a href="https://codetheweb.blog/2018/02/28/if-statements-boolean-operators/"&gt;if statements in JavaScript&lt;/a&gt;, as well as how we can compare variables to create &lt;code&gt;true&lt;/code&gt; and &lt;code&gt;false&lt;/code&gt; values. See you then!&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Want more posts like this? &lt;a href="https://codetheweb.blog/newsletter/"&gt;Sign up to my newsletter&lt;/a&gt;.
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;I've worked hard on these tutorials and as of now do not make any money on them, so I'd really appreciate if you signed up ;)&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This article was originally published at &lt;a href="https://codetheweb.blog"&gt;Code The Web&lt;/a&gt;, a fun and easy-to-understand blog to help you learn web development 🚀&lt;br&gt;
Learn: &lt;a href="https://codetheweb.blog/learn/html/"&gt;HTML&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/css/"&gt;CSS&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/javascript/"&gt;JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Getting started with JavaScript!</title>
      <dc:creator>Ethan</dc:creator>
      <pubDate>Mon, 12 Feb 2018 00:00:00 +0000</pubDate>
      <link>https://dev.to/codetheweb/getting-started-with-javascript-4oaj</link>
      <guid>https://dev.to/codetheweb/getting-started-with-javascript-4oaj</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vRT0NsO1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/hello-javascript/cover.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vRT0NsO1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/hello-javascript/cover.png" alt="Getting started with JavaScript!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;JavaScript is a programming language that makes websites &lt;em&gt;do stuff&lt;/em&gt;. It can store variables, do certain actions based on logic and more. You can even change the HTML of a page and add CSS using JavaScript! It is a language that every web developer must learn at some point because it is just so &lt;em&gt;useful&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Many programming languages require you to download compilers to run the code on your computer, but JavaScript doesn't! One of the main advantages of JavaScript is that it works in any browser, on any computer. This makes it very accessible and extremely easy to get started - by the end of this article, you will already have run your first line of JavaScript.&lt;/p&gt;

&lt;p&gt;There's not really much point in continuing to convince you to learn JavaScript, because if you didn't already want to learn it then you wouldn't be on this page! 😜&lt;/p&gt;

&lt;h2&gt;
  
  
  How to run JavaScript
&lt;/h2&gt;

&lt;p&gt;Because JavaScript runs as part of websites, we execute it by having it in our HTML - there are two ways to do this.&lt;/p&gt;

&lt;p&gt;The first way is to stick our JavaScript inside a script tag. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class="c1"&gt;// Your JavaScript code here!&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might be wondering about the second line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Your JavaScript code here!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;//&lt;/code&gt; in front of the text makes the entire line (after the &lt;code&gt;//&lt;/code&gt;) a &lt;em&gt;comment&lt;/em&gt;. This means that it won't be run as JavaScript, and is simply a message for us human (or half-human anyway) coders to read.&lt;/p&gt;

&lt;p&gt;By now you're probably itching to write some code, and I don't blame you! First of all, create a new folder on your computer with an &lt;code&gt;index.html&lt;/code&gt; file inside. Next, let's add some boilerplate HTML code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Hello world in JavaScript!&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;JavaScript :)&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Time to add our &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag! It can be put in either the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; tags. Note that it executes &lt;em&gt;at its position in the HTML&lt;/em&gt;. This means that if we're modifying an &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; but then &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; is after the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag then it won't have been loaded yet, and the code will not work. Because of this, &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tags are usually placed just before the ending &lt;code&gt;&amp;lt;/body&amp;gt;&lt;/code&gt; tag, so everything has loaded first.&lt;/p&gt;

&lt;p&gt;Let's add it in!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Hello world in JavaScript!&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;JavaScript :)&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
            &lt;span class="c1"&gt;// Your JavaScript code here!&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you save and reload the page, nothing will have changed - this is because our script doesn't do anything yet!&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing some JavaScript!
&lt;/h2&gt;

&lt;p&gt;Get ready for it - you're just about to write your very first line of JavaScript (not including the comment of course 😜 )&lt;/p&gt;

&lt;p&gt;We're going to be creating a popup saying "Hello World!" - This is a classic message that programmers often use when they first try using a new technology or language.&lt;/p&gt;

&lt;p&gt;Here's the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello World!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;WAIT!&lt;/strong&gt; Don't copy the code into your editor yet! Before we try out this code, we need to understand what's going on here first. Do I see your mouse slowly moving over to your code editor? Just stay with me here a bit.&lt;/p&gt;

&lt;p&gt;This line is made up of a word, some brackets, some quotes with text inside them and a semicolon. The &lt;code&gt;alert(...)&lt;/code&gt; bit is called a &lt;em&gt;function&lt;/em&gt;. A function is basically a specific action that you tell the computer to do. A function can have &lt;em&gt;inputs&lt;/em&gt;, which are the bits in the brackets. If a function doesn't have inputs, we just leave the brackets empty (eg. &lt;code&gt;myFuction()&lt;/code&gt;). A function can also have outputs, which I will go into in &lt;a href="https://codetheweb.blog/newsletter"&gt;a later article&lt;/a&gt;. Here our &lt;code&gt;alert&lt;/code&gt; function doesn't have an output because it does something (in this case creates a popup) instead of returning a value. I'll go more into functions in a &lt;a href="https://codetheweb.blog/newsletter"&gt;later article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now let's have a look at what is &lt;em&gt;inside&lt;/em&gt; the brackets - the input for the &lt;code&gt;alert&lt;/code&gt; function. As you can see, we have our message, &lt;code&gt;Hello World!&lt;/code&gt;, inside some quotes. This signifies that the stuff inside the quotes is &lt;em&gt;text&lt;/em&gt;. Well isn't that obvious? Not really. Computers are dumb, and can't tell what is what. This is why we need to specifically tell it that this is text (a "String" in programmer-lingo) by putting it in quotes. In JavaScript, it doesn't really matter if you use single or double quotes as long as the one at the start is the same as the one at the end.&lt;/p&gt;

&lt;p&gt;Finally, there is a semicolon at the end of the line. Technically they are not always needed, but you should always put a semicolon at the end of each line. This can be quite hard to remember at first - that's why every JavaScripter wishes that one of these actually existed:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CF0O1vq0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/hello-javascript/semicolon-keyboard.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CF0O1vq0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/hello-javascript/semicolon-keyboard.png" alt="A keyboard with a giant semicolon key"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Source: &lt;a href="https://www.reddit.com/r/ProgrammerHumor/comments/283he1/if_somebody_were_to_make_this_keyboard_i_would/"&gt;Reddit&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Anyway, that's it! Now when you type your first line of JavaScript, you'll actually know what it does! Sorry for the wait 😂&lt;/p&gt;

&lt;p&gt;So, here's the moment you've been waiting for - go type the line inside your &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt;, under the comment...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Hello world in JavaScript!&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;JavaScript :)&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
            &lt;span class="c1"&gt;// Your JavaScript code here!&lt;/span&gt;
            &lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello World!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you're feeling super-inspired, type it yourself instead of being a copy-paste wizard 😉&lt;/p&gt;

&lt;p&gt;Reload the page, and see what happens...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HXv5k4Uz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/hello-javascript/alert.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HXv5k4Uz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/hello-javascript/alert.png" alt="An alert pops up!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Woo! You're now officially a JavaScripter! 🎉 🎉&lt;/p&gt;

&lt;p&gt;We're nearly done, I just want to tell you about another way of putting JavaScript in your HTML...&lt;/p&gt;

&lt;h2&gt;
  
  
  An alternate way to run your JavaScript
&lt;/h2&gt;

&lt;p&gt;You know how you can link &lt;code&gt;.css&lt;/code&gt; files for your CSS? Well, you can do a similar thing with JavaScript! However, instead of using a &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; tag we use a &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag. Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, we use the same &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag as before but leave it empty. Instead, we give the opening tag and &lt;code&gt;src&lt;/code&gt; attribute with the URL of the JavaScript file. Let's try it out! In the folder with your &lt;code&gt;index.html&lt;/code&gt;, create a &lt;code&gt;script.js&lt;/code&gt; file. Inside the file, add our JavaScript from earlier on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Your JavaScript code here!&lt;/span&gt;
&lt;span class="nx"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello World!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next in the HTML, update the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Hello world in JavaScript!&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;JavaScript :)&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"script.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if you reload the page, the script will still work! This is just an alternate way of writing our JavaScript, and can be especially good to prevent cluttering our HTML with a lot of JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Well done, you made it! You now know how to write some JavaScript, link it to our HTML and call a basic function!&lt;/p&gt;

&lt;p&gt;It is really awesome to have been able to help you write your first line of JavaScript, who knows where you'll be in a few years' time! If you liked this article and want to continue learning JavaScript, I will be releasing one JavaScript tutorial each week, which you can find &lt;a href="https://codetheweb.blog/learn/js"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Also, these articles take time and effort, so I'd really appreciate it if you &lt;a href="https://codetheweb.blog/2018/02/12/hello-javascript/#share"&gt;shared it&lt;/a&gt; :)&lt;/p&gt;

&lt;p&gt;If you want to stay up to date and get these articles in your inbox as I write them (a great way to stay motivated to keep learning JavaScript), &lt;a href="https://codetheweb.blog/newsletter"&gt;enter your email here!&lt;/a&gt; - I'd really appreciate it 😉&lt;/p&gt;

&lt;p&gt;Finally, if you have any questions or feedback, &lt;a href="https://codetheweb.blog/2018/02/12/hello-javascript/#disqus_thread"&gt;tell me about it in the comments&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;See you next time, where I'll be talking about &lt;a href="https://codetheweb.blog/2018/02/25/javascript-variables/"&gt;variables&lt;/a&gt; - one of the &lt;em&gt;most important&lt;/em&gt; parts of JavaScript. See you then!&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Want more posts like this? &lt;a href="https://codetheweb.blog/newsletter/"&gt;Sign up to my newsletter&lt;/a&gt;.
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;I've worked hard on these tutorials and as of now do not make any money on them, so I'd really appreciate if you signed up ;)&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This article was originally published at &lt;a href="https://codetheweb.blog"&gt;Code The Web&lt;/a&gt;, a fun and easy-to-understand blog to help you learn web development 🚀&lt;br&gt;
Learn: &lt;a href="https://codetheweb.blog/learn/html/"&gt;HTML&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/css/"&gt;CSS&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/javascript/"&gt;JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A beginner’s guide to getting your website online with GitHub Pages</title>
      <dc:creator>Ethan</dc:creator>
      <pubDate>Sun, 04 Feb 2018 00:00:00 +0000</pubDate>
      <link>https://dev.to/codetheweb/a-beginners-guide-to-getting-your-website-online-with-github-pages-12fg</link>
      <guid>https://dev.to/codetheweb/a-beginners-guide-to-getting-your-website-online-with-github-pages-12fg</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fcover.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fcover.png" alt="A beginner’s guide to getting your website online with GitHub Pages"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Do you have an awesome website that is finally ready to share with the world? Are you finally ready to stop running it on your local server or opening up your files in the browser, and ready to launch it onto the great and powerful &lt;em&gt;internet&lt;/em&gt;?&lt;/p&gt;

&lt;p&gt;I know I was in this situation at one stage. Going from a something running on your computer to something that anyone on the internet can access can be very intimidating.&lt;/p&gt;

&lt;p&gt;I wrote more about &lt;a href="https://codetheweb.blog/2017/10/05/how-the-internet-works/" rel="noopener noreferrer"&gt;how the internet works&lt;/a&gt; in a previous article, but I'll briefly go over how your site is going to get to people.&lt;/p&gt;

&lt;p&gt;First, your site needs to be &lt;em&gt;hosted&lt;/em&gt; somewhere. What this means is that there needs to be a computer that will send the HTML files to someone when they load the website. This is commonly known as a server, but any computer can be used (the internet is just a massive network of computers).&lt;/p&gt;

&lt;p&gt;However, hosting a website can be very scary for multiple reasons. First of all, you have to leave the server running and connected to the internet 24/7. This means that either you're going to have to install a big server in your basement or never turn your computer off. Because of this, using your computer as a server is not a practical idea (unless you have an old computer that you never use).&lt;/p&gt;

&lt;p&gt;That's not the only problem. Even if you &lt;em&gt;do&lt;/em&gt; buy a server, you will have to continually maintain it and make sure that it has enough processing power to serve your website. Ever heard of Google's data centers? Here's a pic:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fgoogle-data-center.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fgoogle-data-center.jpg" alt="Rows and rows of servers..."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Photo credit: &lt;a href="https://www.google.com/about/datacenters/gallery/#/all/images/35" rel="noopener noreferrer"&gt;Google&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;See all those things on racks? They're all servers. Google needs this many servers (they have centers like these all over the world) because of the sheer amount of people who access Google.&lt;/p&gt;

&lt;p&gt;Obviously you won't have as many users as Google, but my point is that the more people view your site, the better your server needs to be. Also, bad servers can make your page load reeaaaally slowly.&lt;/p&gt;

&lt;p&gt;The final and most scary problem with hosting your own site is security. You will have to connect your server up to your Wi-Fi router, meaning that people from anywhere in the world will be able to access your home network. While there are security measures in place, it does leave you very vulnerable to hacking.&lt;/p&gt;

&lt;h2&gt;
  
  
  The alternative?
&lt;/h2&gt;

&lt;p&gt;Because of all these complications, people usually don't host their websites themselves - instead they pay for hosting. This means that you pay to put your HTML files on a server somewhere in the world in a data center similar to the one above, and they will take care and maintain the servers for you.&lt;/p&gt;

&lt;p&gt;This can cost anywhere from about $4 a month to about $100 a month, depending on the speed and features of the server. (According to this &lt;a href="https://www.whoishostingthis.com/blog/2014/07/29/website-cost/" rel="noopener noreferrer"&gt;great infographic&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Okay, so you can get hosting for relatively cheap if you want, but still - why pay for stuff when you don't have to?&lt;/p&gt;

&lt;h2&gt;
  
  
  The &lt;em&gt;free&lt;/em&gt; alternative?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fcover.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fcover.png" alt="GitHub Pages"&gt;&lt;/a&gt;&lt;br&gt;
Let me introduce you to something called &lt;a href="https://pages.github.com/" rel="noopener noreferrer"&gt;GitHub Pages&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;GitHub Pages hosts your website &lt;em&gt;100% for free&lt;/em&gt;. The single drawback is that other people can view all the files in your site, although often this can be a good thing. It means that anyone visiting your page on GitHub can see the work that went into making your site. In fact, often employers even select people due to their projects on GitHub (don't worry, you can always delete them later if you feel they're not your best work).&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; I know that it sounds like I'm paid to promote GitHub or something, but I'm really not. I just really like using GitHub pages, and think that you should too 😉&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In this tutorial, I'm going to show you how to host your site on GitHub pages and sync GitHub to your computer so that you can make edits easily!&lt;/p&gt;

&lt;p&gt;Note that this tutorial assumes you already have a folder with a website in it. If not, create a new folder and add basic &lt;code&gt;index.html&lt;/code&gt; and &lt;code&gt;style.css&lt;/code&gt; files.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;First of all, you're going to need to sign up for an account at &lt;a href="https://github.com" rel="noopener noreferrer"&gt;Github.com&lt;/a&gt;. I'll be right here when you get back!&lt;/p&gt;

&lt;p&gt;Next, you need to install &lt;a href="https://desktop.github.com/" rel="noopener noreferrer"&gt;GitHub Desktop on your computer&lt;/a&gt; - I'll give you a sec to do that too (not really, I'm not writing this live as you're reading it 😜)&lt;/p&gt;

&lt;p&gt;Once you have installed GitHub Desktop, sign into your account (&lt;a href="https://help.github.com/desktop/guides/getting-started-with-github-desktop/authenticating-to-github/" rel="noopener noreferrer"&gt;as detailed here&lt;/a&gt;). First, you need to create your repository. A repository is the place where you store all the files for your website, similar to the folder on your computer that contains your website.&lt;/p&gt;

&lt;p&gt;Each repository has a URL where the hosted site ends up. There are two types of repositories: user repositories and project repositories.&lt;/p&gt;

&lt;p&gt;For this example, let's say your username was 'example'. Your user repository would be hosted at &lt;code&gt;example.github.io&lt;/code&gt;. Now let's say you did a random number generator and called the repository &lt;code&gt;randomnumber&lt;/code&gt; - then it would be hosted at &lt;code&gt;example.github.io/randomnumber&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In this case, let's say we've coded our main website - so we want it to be our user site. This means that instead of naming our repository something like &lt;code&gt;randomnumber&lt;/code&gt; we need to name it &lt;code&gt;example.github.io&lt;/code&gt;. For example, my GitHub repository name is &lt;code&gt;booligoosh.github.io&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a repository
&lt;/h2&gt;

&lt;p&gt;Okay, let's create our repository now! Click the left option (Create new repository):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fgh-desktop-create-new-repo-button.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fgh-desktop-create-new-repo-button.png" alt="Click the left option - Create new repository"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you click it, a dialogue will come up. Enter in your repository name (&lt;code&gt;whateveryourusernameis.github.io&lt;/code&gt;) and choose where to save the repository folder on your computer. Leave all the other options as they are, then click "Create Repository":&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fgh-desktop-create-new-repo-dialogue.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fgh-desktop-create-new-repo-dialogue.png" alt="Enter in your repository name ( raw `whateveryourusernameis.github.io` endraw ) and choose where to save the repository folder on your computer. Leave all the other options as they are, then click "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding your code
&lt;/h2&gt;

&lt;p&gt;Now, it's time to add our code! Move all of your website files into the repository folder on your computer, then go back to GitHub Desktop - it should now look something along the lines of this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fgh-desktop-commit-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fgh-desktop-commit-1.png" alt="Fill out the summary saying what you did, then click "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Fill out the summary saying what you did, then click "Commit to master". This is just tech-lingo for "save my changes to the repository".&lt;/p&gt;

&lt;h2&gt;
  
  
  Publishing to GitHub
&lt;/h2&gt;

&lt;p&gt;Next, click "Publish Repository" in the top right-hand corner - this will send your code to the GitHub servers to be hosted!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fgh-desktop-publish-repo-button.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fgh-desktop-publish-repo-button.png" alt="Click "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Leave all the fields as they are, but &lt;strong&gt;untick "Keep this code private"&lt;/strong&gt; (you have to pay for that). Click "Publish Repository":&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fgh-desktop-publish-repo-dialogue.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fgh-desktop-publish-repo-dialogue.png" alt="Leave all the fields as they are, but UNTICK "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we need to configure the settings for our website to be hosted! Go to &lt;code&gt;github.com/yourusername/yourusername.github.io&lt;/code&gt; (eg. &lt;code&gt;github.com/Booligoosh/booligoosh.github.io&lt;/code&gt; for me) and click on the 'Settings' tab.&lt;/p&gt;

&lt;p&gt;Scroll down to where it says GitHub Pages, then click on the dropdown. Select "master branch", then click "Save".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fgh-pages-settings.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fgh-pages-settings.png" alt="Scroll down to where it says GitHub Pages, then click on the dropdown. Select "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yay! Now click on the link to take you to your new site!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fgh-pages-settings-link.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fgh-pages-settings-link.png" alt="Click on the link to take you to your new site!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You now have a website!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fsite-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fsite-1.png" alt="You now have a website!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Making changes
&lt;/h2&gt;

&lt;p&gt;We're nearly done! The last thing to do is to make a change to our website, from our computer! First, slightly modify your code in some way.&lt;/p&gt;

&lt;p&gt;Now, go back to GitHub Desktop - it will even show you a summary of what you changed! Fill out your commit summary and hit the commit button!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fgh-desktop-commit-2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fgh-desktop-commit-2.png" alt="Fill out your commit summary and hit the commit button!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, click "Push origin" in the top right-hand corner (where the publish button used to be). This is just tech-lingo for "Upload my changes to GitHub's servers".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fgh-desktop-push-origin.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fgh-desktop-push-origin.png" alt="Click "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, wait for a few minutes. The time may vary, but often your site could take ~5mins to update (keep reloading the page to check). Eventually the changes will load!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fsite-2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fgithub-pages-free-hosting%2Fsite-2.png" alt="The updated website!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I hope you learned a lot today! You now know how to take your site from files on your computer to a real website on the internet! My goal is to teach people like you who are learning web development how to do so, and I'd really appreciate if you supported me in my mission either by &lt;a href="https://codetheweb.blog/2018/02/04/github-pages-free-hosting/#share" rel="noopener noreferrer"&gt;sharing this&lt;/a&gt; or &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;signing up to my newsletter&lt;/a&gt;. (you will get new articles in your inbox! 🎉 )&lt;/p&gt;

&lt;p&gt;Next week I'll be talking about how to use GitHub pages to host your website on a custom domain (so instead of your website being at &lt;code&gt;username.github.io&lt;/code&gt; it could be at &lt;code&gt;example.com&lt;/code&gt; or &lt;code&gt;example.io&lt;/code&gt; or &lt;code&gt;example.blog&lt;/code&gt;). You &lt;em&gt;do&lt;/em&gt; have to pay a (small) fee for the domain name, but this way you still get free hosting! &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;Stay tuned for that :)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Oh! And if you have any feedback, need any help or just wanna say howdy, do so in the &lt;a href="https://codetheweb.blog/2018/02/04/github-pages-free-hosting/#disqus_thread" rel="noopener noreferrer"&gt;comments below&lt;/a&gt;. Don't forget to &lt;a href="https://codetheweb.blog/2018/02/04/github-pages-free-hosting/#share" rel="noopener noreferrer"&gt;share&lt;/a&gt;, &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;subscribe&lt;/a&gt;, and I'll see you next time!&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Want more posts like this? &lt;a href="https://codetheweb.blog/newsletter/" rel="noopener noreferrer"&gt;Sign up to my newsletter&lt;/a&gt;.
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;I've worked hard on these tutorials and as of now do not make any money on them, so I'd really appreciate if you signed up ;)&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This article was originally published at &lt;a href="https://codetheweb.blog" rel="noopener noreferrer"&gt;Code The Web&lt;/a&gt;, a fun and easy-to-understand blog to help you learn web development 🚀&lt;br&gt;
Learn: &lt;a href="https://codetheweb.blog/learn/html/" rel="noopener noreferrer"&gt;HTML&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/css/" rel="noopener noreferrer"&gt;CSS&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/javascript/" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>github</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>CSS text properties, and how to use Google Fonts on your website</title>
      <dc:creator>Ethan</dc:creator>
      <pubDate>Wed, 17 Jan 2018 00:00:00 +0000</pubDate>
      <link>https://dev.to/codetheweb/css-text-properties-and-how-to-use-google-fonts-on-your-website-43ni</link>
      <guid>https://dev.to/codetheweb/css-text-properties-and-how-to-use-google-fonts-on-your-website-43ni</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fcover.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fcover.png" alt="CSS text properties, and how to use Google Fonts on your website"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Learn how to change the way text appears on a website, and learn how to use the most extensive and powerful free font database in the world!&lt;/p&gt;

&lt;p&gt;Hey everyone! Welcome back to another year of Code The Web! Hopefully, you had a good New Year's, and have made some good resolutions for 2018...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fnew-year-1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fnew-year-1.jpg" alt="What exactly is a "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Today I'm going to be talking about text-related CSS properties, as well as how to spice up your website with this nifty thing called &lt;a href="https://fonts.google.com/" rel="noopener noreferrer"&gt;Google Fonts&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let's get going!&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;I recommend following along in all of my tutorials, as it really helps you get a better grasp on the subject. If you want to follow along through this tutorial, here's how to get started.&lt;/p&gt;

&lt;p&gt;First, create a new project folder with blank &lt;code&gt;index.html&lt;/code&gt; and &lt;code&gt;style.css&lt;/code&gt; files inside.&lt;/p&gt;

&lt;p&gt;Next, let's write some basic HTML to test our font properties on. Add the following to your &lt;code&gt;index.html&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;CSS Fonts!&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"style.css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;span&amp;gt;&lt;/span&gt;Look at me, I am some awesome text!&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open your &lt;code&gt;index.html&lt;/code&gt; file in a browser - it should look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fbase-code.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fbase-code.png" alt="A blank page with the text "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we're good to go!&lt;/p&gt;

&lt;h2&gt;
  
  
  font-size
&lt;/h2&gt;

&lt;p&gt;You may already know about &lt;code&gt;font-size&lt;/code&gt; because it is a very common property, but I'll go through it anyway (you can skip if you want).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;font-size&lt;/code&gt; is quite straight-forward, it determines the size of the text. It accepts a value in any &lt;a href="https://codetheweb.blog/2017/12/04/css-units/" rel="noopener noreferrer"&gt;CSS unit&lt;/a&gt;. Let's try it out!&lt;/p&gt;

&lt;p&gt;Open up your &lt;code&gt;style.css&lt;/code&gt; file, and style the &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt; to have a &lt;code&gt;font-size&lt;/code&gt; of &lt;code&gt;50px&lt;/code&gt; - see if you can work out the code on your own...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;span&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Ffont-size.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Ffont-size.png" alt="The text is now much larger"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  font-weight
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;font-weight&lt;/code&gt; sets the thickness of the text (eg. &lt;strong&gt;bold&lt;/strong&gt;). It takes the following values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;lighter&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;normal&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bold&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bolder&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;One of the following numbers: &lt;code&gt;100&lt;/code&gt;, &lt;code&gt;200&lt;/code&gt;, &lt;code&gt;300&lt;/code&gt;, &lt;code&gt;400&lt;/code&gt;, &lt;code&gt;500&lt;/code&gt;, &lt;code&gt;600&lt;/code&gt;, &lt;code&gt;700&lt;/code&gt;, &lt;code&gt;800&lt;/code&gt;, &lt;code&gt;900&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The numbers go from &lt;code&gt;100&lt;/code&gt; being the thinnest to &lt;code&gt;900&lt;/code&gt; being the thickest. &lt;code&gt;400&lt;/code&gt; is equivalent to &lt;code&gt;normal&lt;/code&gt; and &lt;code&gt;700&lt;/code&gt; is equivalent to &lt;code&gt;bold&lt;/code&gt;. &lt;strong&gt;Note that the numbers &lt;em&gt;do not&lt;/em&gt; have a unit after them.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's try making our font &lt;code&gt;lighter&lt;/code&gt; - add the following to your CSS file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;span&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;lighter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Add this line */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Ffont-size.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Ffont-size.png" alt="Nothing happened!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What?! Nothing happened! This is because &lt;em&gt;&lt;strong&gt;not all fonts come with all weights&lt;/strong&gt;&lt;/em&gt;. This is because the designer of the font needs to design each weight of the font individually, and lots of font designers will not end up designing up to 9 versions of the same font. In this case, the designer of this font has not made a &lt;code&gt;lighter&lt;/code&gt; version - so the browser just shows the closest equivalent which is &lt;code&gt;normal&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In my &lt;a href="https://codetheweb.blog/newsletter/" rel="noopener noreferrer"&gt;next article&lt;/a&gt;, I'll go into the behind-the-scenes of how the different font weight files are actually specified.&lt;/p&gt;

&lt;p&gt;Okay, let's try making our text &lt;code&gt;bold&lt;/code&gt; - the designer of this font &lt;em&gt;has&lt;/em&gt; made a &lt;code&gt;bold&lt;/code&gt; version...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;span&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bold&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Change this line */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Ffont-weight-bold.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Ffont-weight-bold.png" alt="The text is now bold!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Woo! Let's move on...&lt;/p&gt;
&lt;h2&gt;
  
  
  line-height
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;line-height&lt;/code&gt; basically controls how high each line of text is. The larger the &lt;code&gt;line-height&lt;/code&gt;, the more vertical space between the text.&lt;/p&gt;

&lt;p&gt;Like &lt;code&gt;font-size&lt;/code&gt;, &lt;code&gt;line-height&lt;/code&gt; accepts a value in any &lt;a href="https://codetheweb.blog/2017/12/04/css-units/" rel="noopener noreferrer"&gt;CSS unit&lt;/a&gt;. Let's try it out!&lt;/p&gt;

&lt;p&gt;First of all, let's split our text onto two lines so we can see the &lt;code&gt;line-height&lt;/code&gt; properly by adding a &lt;code&gt;&amp;lt;br&amp;gt;&lt;/code&gt; in our HTML:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;CSS Fonts!&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"style.css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;span&amp;gt;&lt;/span&gt;Look at me, &lt;span class="nt"&gt;&amp;lt;br&amp;gt;&lt;/span&gt;I am some awesome text!&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!-- Change this line --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Ftwo-lines.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Ftwo-lines.png" alt="The text is now on two lines"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, let's try setting our &lt;code&gt;line-height&lt;/code&gt; to &lt;code&gt;200px&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;span&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bold&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Add this line */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, take a look at the result:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fline-height-200px.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fline-height-200px.png" alt="There is now much more space between the lines of text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, there is now much more space between the lines of text.&lt;/p&gt;

&lt;p&gt;But you may be wondering - how does the line &lt;em&gt;height&lt;/em&gt; create more space &lt;em&gt;between&lt;/em&gt; the lines? This is because technically, there is no space between the lines. The lines are each &lt;code&gt;200px&lt;/code&gt; high, and the text is &lt;em&gt;vertically centered&lt;/em&gt; on the lines. This means that as the &lt;code&gt;line-height&lt;/code&gt; gets bigger but the &lt;code&gt;font-size&lt;/code&gt; stays the same, the gaps between the actual text will get bigger. Here is a diagram:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fline-height-200px-annotated.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fline-height-200px-annotated.png" alt="Each line has a line-height of 200px, but the text itself is not that high"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;line-height&lt;/code&gt; works well when using &lt;a href="https://codetheweb.blog/2017/12/04/css-units/#em" rel="noopener noreferrer"&gt;&lt;code&gt;em&lt;/code&gt; units&lt;/a&gt; because it means you can set the &lt;code&gt;line-height&lt;/code&gt; relative to the &lt;code&gt;font-size&lt;/code&gt;. For example, &lt;code&gt;line-height: 2em&lt;/code&gt; would make the &lt;code&gt;line-height&lt;/code&gt; double the size of the text.&lt;/p&gt;
&lt;h2&gt;
  
  
  letter-spacing
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;letter-spacing&lt;/code&gt; determines the amount of space in between each letter and takes a value in any CSS unit. Let's jump right in and try it out!&lt;/p&gt;

&lt;p&gt;Try giving the text a &lt;code&gt;letter-spacing&lt;/code&gt; of &lt;code&gt;5px&lt;/code&gt;...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;span&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bold&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;letter-spacing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Add this line */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's the result:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fletter-spacing.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fletter-spacing.png" alt="The letters are much more spread out"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, the letters are much more spread out. This example looks kind of ridiculously spread out to make the &lt;code&gt;letter-spacing&lt;/code&gt; clear, but often it is good for minor adjustments (similar thing goes for &lt;code&gt;line-height&lt;/code&gt;).&lt;/p&gt;
&lt;h2&gt;
  
  
  font-family
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;font-family&lt;/code&gt; tells the browser which font to display the text in. Here are the default fonts available:&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span&gt;serif&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;sans-serif&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;cursive&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;fantasy&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span&gt;monospace&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's try setting our font to &lt;code&gt;fantasy&lt;/code&gt; (don't ask me why it is called that):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;span&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bold&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;letter-spacing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;fantasy&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Add this line */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the result:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Ffont-family-fantasy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Ffont-family-fantasy.png" alt="The text is now in the 'fantasy' font from above!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Awesome!&lt;/p&gt;

&lt;p&gt;Note that the default fonts &lt;em&gt;might be different on different computers or browsers&lt;/em&gt; because it is what the browser deems to be the default font for that category. Generally, the fonts will look similar though.&lt;/p&gt;

&lt;p&gt;You can also specify any font name that is installed on the computer system (if the font name contains a space, surround it with quotes eg. &lt;code&gt;font-family: "Modern Sans"&lt;/code&gt;). The problem is, &lt;em&gt;&lt;strong&gt;the font will not work if it is not installed on the user's machine&lt;/strong&gt;&lt;/em&gt;. This is where Google Fonts comes in...&lt;/p&gt;
&lt;h2&gt;
  
  
  Google Fonts
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://fonts.google.com/" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fcover.png" alt="Google Fonts"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://fonts.google.com/" rel="noopener noreferrer"&gt;Google Fonts&lt;/a&gt; is a library filled with thousands of awesome (and free 😋 ) fonts.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Talking of free: Always be careful when using a font online, sometimes the license doesn't allow it to be used online or for commercial use, or you may have to buy a license. Luckily all the fonts on Google Fonts are completely free, so you don't have to worry!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The good thing about using a font from Google Fonts is that they host and create a font stylesheet for you. This means that all you need to do is link to one of their files and the font will work for everyone - even if the user doesn't have it installed on their computer.&lt;/p&gt;

&lt;p&gt;Let's add a font from Google Fonts to our website!&lt;/p&gt;

&lt;p&gt;First of all, go to the &lt;a href="https://fonts.google.com/" rel="noopener noreferrer"&gt;Google Fonts website&lt;/a&gt; if you haven't already. When you get there, you will see a bunch of font specimens:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fg-fonts-home.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fg-fonts-home.png" alt="Google Fonts"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is also a search box and many advanced filters to find your favorite font - you can even filter by things such as thickness or width!&lt;/p&gt;

&lt;p&gt;In this case, I have chosen the font &lt;a href="https://fonts.google.com/specimen/Ribeye+Marrow" rel="noopener noreferrer"&gt;Ribeye Marrow&lt;/a&gt;. You can either follow along with me using that font or pick your own.&lt;/p&gt;

&lt;p&gt;Once you have a font, click the red plus button - the image below shows how to do it on a specific font page or straight from the home page:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fg-fonts-select-font.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fg-fonts-select-font.png" alt="The position of the red plus button on the font specimen pages and home page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After doing this, a small panel will appear in the bottom right corner of your screen:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fg-fonts-selected-panel-closed.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fg-fonts-selected-panel-closed.png" alt="A small panel will appear in the bottom right corner of your screen"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open it by clicking on it...&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fg-fonts-selected-panel-opened.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fg-fonts-selected-panel-opened.png" alt="The opened panel"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First of all, we will need to link to the font so that the browser knows where to find the files. There are two ways to do this: using HTML (standard) or CSS (@import). Personally, I prefer CSS as the font is part of the styling of the page so it makes sense to put it together.&lt;/p&gt;

&lt;p&gt;To use the CSS option, click on "@IMPORT"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fg-fonts-css-import-button.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fg-fonts-css-import-button.png" alt="Click on "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, copy the &lt;em&gt;middle line&lt;/em&gt; of code (the one with &lt;code&gt;@import&lt;/code&gt; in it):&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fg-fonts-css-import-copy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Fg-fonts-css-import-copy.png" alt="Copy the middle line of code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we need to paste it into our CSS code - but where? &lt;code&gt;@import&lt;/code&gt; statements must always be outside of the curly brackets, but it really doesn't matter where in the document - &lt;em&gt;as long as it is above the place where the font is used&lt;/em&gt; (the &lt;code&gt;font-family&lt;/code&gt; property). As a general rule, I like to put Google Font imports &lt;em&gt;at the top&lt;/em&gt; of CSS files so that the rest of the CSS file has access to it.&lt;/p&gt;

&lt;p&gt;I'll explain more about CSS &lt;code&gt;@import&lt;/code&gt;s in &lt;a href="https://codetheweb.blog/newsletter/" rel="noopener noreferrer"&gt;another article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let's paste in our line of code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="sx"&gt;url('https://fonts.googleapis.com/css?family=Ribeye+Marrow')&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Add this line */&lt;/span&gt;

&lt;span class="nt"&gt;span&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bold&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;letter-spacing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;fantasy&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reload the page - you will see that nothing has changed! This is because we still need to declare the font using &lt;code&gt;font-family&lt;/code&gt;. The reason for using the &lt;code&gt;@import&lt;/code&gt; line is so that the font will work even if it is not installed on the user's computer.&lt;/p&gt;

&lt;p&gt;Let's use our font! We simply do this by giving the name of the font as a value to the &lt;code&gt;font-family&lt;/code&gt; property:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@import&lt;/span&gt; &lt;span class="sx"&gt;url('https://fonts.googleapis.com/css?family=Ribeye+Marrow')&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nt"&gt;span&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;50px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-weight&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bold&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;200px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;letter-spacing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;"Ribeye Marrow"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* Change this line */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember to include quotation marks if the name has a space!&lt;/p&gt;

&lt;p&gt;Here is the result:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Ffont-family-ribeye-marrow.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fcss-text-properties-and-google-fonts%2Ffont-family-ribeye-marrow.png" alt="Our text is now in the font Ribeye Marrow!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now our text is in the font Ribeye Marrow!&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Woo! That's it for today! Hopefully, this article was useful and helped you along your coding journey. As always, if there was anything that you didn't get or if you have any feedback, &lt;a href="https://codetheweb.blog/2018/01/17/css-text-properties-and-google-fonts/#disqus_thread" rel="noopener noreferrer"&gt;tell me in the comments&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Also, these articles don't come out of thin air! Looking at my &lt;a href="https://en.wikipedia.org/wiki/Pomodoro_Technique" rel="noopener noreferrer"&gt;Pomodoro Timer&lt;/a&gt;, so far I've spent 3 hours and 20 minutes on this article, and have just passed to 40,000 word mark on this blog!&lt;/p&gt;

&lt;p&gt;While your nice comments and knowing that I am helping you all make it worthwhile, I'd really appreciate it if you &lt;a href="https://codetheweb.blog/2018/01/17/css-text-properties-and-google-fonts/#share" rel="noopener noreferrer"&gt;shared this&lt;/a&gt; or &lt;a href="https://codetheweb.blog/#share" rel="noopener noreferrer"&gt;this blog&lt;/a&gt; with your friends or &lt;a href="https://codetheweb.blog/newsletter/" rel="noopener noreferrer"&gt;signed up to the newsletter&lt;/a&gt; to get the latest articles in your inbox.&lt;/p&gt;

&lt;p&gt;See you next time, where I'll be talking about &lt;a href="https://codetheweb.blog/newsletter/" rel="noopener noreferrer"&gt;using custom font files&lt;/a&gt; to extend your font choices beyond Google Fonts. See you then! Have a great and productive 2018 filled with lots of coding fun! 䢜 🎆 🚀&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Want more posts like this? &lt;a href="https://codetheweb.blog/newsletter/" rel="noopener noreferrer"&gt;Sign up to my newsletter&lt;/a&gt;.
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;I've worked hard on these tutorials and as of now do not make any money on them, so I'd really appreciate if you signed up ;)&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This article was originally published at &lt;a href="https://codetheweb.blog" rel="noopener noreferrer"&gt;Code The Web&lt;/a&gt;, a fun and easy-to-understand blog to help you learn web development 🚀&lt;br&gt;
Learn: &lt;a href="https://codetheweb.blog/learn/html/" rel="noopener noreferrer"&gt;HTML&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/css/" rel="noopener noreferrer"&gt;CSS&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/javascript/" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>6 Reference sites to help you learn web development in 2018 and beyond… 🚀</title>
      <dc:creator>Ethan</dc:creator>
      <pubDate>Sat, 16 Dec 2017 00:00:00 +0000</pubDate>
      <link>https://dev.to/codetheweb/6-reference-sites-to-help-you-learn-web-development-in-2018-and-beyond--edn</link>
      <guid>https://dev.to/codetheweb/6-reference-sites-to-help-you-learn-web-development-in-2018-and-beyond--edn</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fweb-development-reference-sites%2Fcover.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2Fassets%2Fimg%2Fposts%2Fweb-development-reference-sites%2Fcover.jpg" alt="6 Reference sites to help you learn web development in 2018 and beyond… 🚀"&gt;&lt;/a&gt;&lt;br&gt;
As a person learning web development, you should always be looking things up that you don't know. Because, let's face it - in today's world, it's silly to know &lt;em&gt;every single&lt;/em&gt; feature of a coding language. Instead, we as developers look things up! Today, I'm going to show you six of the best web development reference sites for those moments when you can't quite remember how that specific thing works.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a reference site?
&lt;/h2&gt;

&lt;p&gt;A reference site is where you go if you need to know a specific thing - let’s say what values the &lt;code&gt;margin&lt;/code&gt; property takes in CSS or how to find the square root of a number in JavaScript. It is an easy way to get an answer to a very specific question.&lt;/p&gt;

&lt;h2&gt;
  
  
  How is a reference site different to a tutorial site?
&lt;/h2&gt;

&lt;p&gt;A tutorial site such as this one aims to explain something to you. So, for example, in my &lt;a href="https://codetheweb.blog/2017/11/29/advanced-background-images/" rel="noopener noreferrer"&gt;CSS background images&lt;/a&gt; tutorial, I teach you how all the different background image properties work in an easy-to-understand way. If it were a reference site, it would say something like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The background-position property takes one or more comma-separated &amp;lt;position&amp;gt; values. If multiple background images have been specified, each &amp;lt;position&amp;gt; is applied to a corresponding background image (first &amp;lt;position&amp;gt; for the first image, second &amp;lt;position&amp;gt; for the second image, and so on).&lt;/p&gt;

&lt;p&gt;(From the Codrops CSS Reference)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As you can see, this is much more succinct and is good if you need a quick reference or reminder, however it is not as good if you are learning it for the first time and need help, examples and, guidance.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. W3Schools
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2F%2Fassets%2Fimg%2Fposts%2Fweb-development-reference-sites%2Fw3.png" alt="W3Schools"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.w3schools.com/" rel="noopener noreferrer"&gt;W3Schools&lt;/a&gt; is a tutorials website, but they are more brief and reference-like. They also have dedicated reference pages for most web development languages. Their format is very good. For each language reference, they have a sidebar with a list of pages, so it is very easy to find what you are looking for - I never even need to use the search bar! The reference is also very succinct and to-the-point which is good for when you need a quick reminder of something. I would say that W3Schools has the best explanations by far.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reference links:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/tags/" rel="noopener noreferrer"&gt;HTML Reference&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/cssref/" rel="noopener noreferrer"&gt;CSS Reference&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.w3schools.com/jsref/" rel="noopener noreferrer"&gt;JavaScript Reference&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They also have many other references for things such as &lt;a href="https://www.w3schools.com/jquery/" rel="noopener noreferrer"&gt;jQuery&lt;/a&gt;, &lt;a href="https://www.w3schools.com/php/" rel="noopener noreferrer"&gt;PHP&lt;/a&gt;, and &lt;a href="https://www.w3schools.com/sql/" rel="noopener noreferrer"&gt;SQL&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. DevDocs
&lt;/h2&gt;

&lt;p&gt;&lt;a href="http://devdocs.io/" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2F%2Fassets%2Fimg%2Fposts%2Fweb-development-reference-sites%2Fdevdocs.png" alt="DevDocs"&gt;&lt;/a&gt;&lt;a href="http://devdocs.io/" rel="noopener noreferrer"&gt;DevDocs&lt;/a&gt; is very similar to freeCodeCamp in that is has many different languages (not only web development), from very popular ones to lesser-known ones. I really like the layout - it is similar to W3Schools and especially freeCodeCamp with the sidebar and drop-downs. The reference is really great and in-depth, but also easy to skim and find what you need.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reference links:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://guide.freecodecamp.org/html" rel="noopener noreferrer"&gt;HTML Reference&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://guide.freecodecamp.org/css" rel="noopener noreferrer"&gt;CSS Reference&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://guide.freecodecamp.org/javascript" rel="noopener noreferrer"&gt;JavaScript Reference&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;And basically everything else 😂&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. freeCodeCamp Guides
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://guide.freecodecamp.org/" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2F%2Fassets%2Fimg%2Fposts%2Fweb-development-reference-sites%2Ffcc.png" alt="freeCodeCamp Guides"&gt;&lt;/a&gt;&lt;a href="https://guide.freecodecamp.org/" rel="noopener noreferrer"&gt;freeCodeCamp guides&lt;/a&gt; are made by the community, for the community. They have a &lt;a href="https://github.com/freeCodeCamp/guides/tree/master/src/pages" rel="noopener noreferrer"&gt;GitHub repository&lt;/a&gt; where you can actually contribute! This is something I’ve done and it’s pretty rewarding. Anyway, with so many nice people working on it day and night, it is a great reference. The layout is also very nice - similar to W3Schools, it has a sidebar with all the different pages. However, &lt;em&gt;every single language&lt;/em&gt; is in that sidebar, meaning navigations is really simple.&lt;/p&gt;

&lt;p&gt;To visit a page for a particular language, just click the arrow next to it in the sidebar and a drop-down will appear with all the pages. Another awesome thing about freeCodeCamp guides is that it isn’t just for HTML, CSS, and JavaScript. They have a bunch of other languages including C, Ruby, PHP, and more. They also have extra guides such as &lt;a href="https://guide.freecodecamp.org/working-in-tech" rel="noopener noreferrer"&gt;Working in tech&lt;/a&gt; and &lt;a href="https://guide.freecodecamp.org/visual-design" rel="noopener noreferrer"&gt;design&lt;/a&gt; which are very helpful.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reference links:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://guide.freecodecamp.org/html" rel="noopener noreferrer"&gt;HTML Reference&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://guide.freecodecamp.org/css" rel="noopener noreferrer"&gt;CSS Reference&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://guide.freecodecamp.org/javascript" rel="noopener noreferrer"&gt;JavaScript Reference&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;A bunch of other stuff (see the sidebar)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that these links go to the main language pages, to see all the sub-pages of that language you will need to expand it in the sidebar.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. MDN Web Docs (Mozilla Developer Network)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/docs/Web/Reference" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2F%2Fassets%2Fimg%2Fposts%2Fweb-development-reference-sites%2Fmdn.png" alt="MDN Web Docs (Mozilla Developer Network)"&gt;&lt;/a&gt;The &lt;a href="https://developer.mozilla.org/docs/Web/Reference" rel="noopener noreferrer"&gt;MDN Web Docs&lt;/a&gt; is made by Mozilla, the people who built Firefox. So as you can imagine, they are also a great authority on web development! Personally, I am not a fan of MDN’s layout, however, it is a lot more detailed that W3Schools and provides more examples.&lt;/p&gt;

&lt;p&gt;I suppose it depends on what you are looking for - If you are looking for a quick reference to something you forgot, go to w3schools. If you are looking for more in-depth documentation outlining &lt;em&gt;everything&lt;/em&gt; about what you are looking for, choose MDN. Ultimately, it’s up to you. Have a look at both and see which you prefer. Personally, I’m not a fan of MDN overall, but many people would disagree with me.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reference links:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/docs/Web/HTML" rel="noopener noreferrer"&gt;HTML Reference&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/docs/Web/CSS" rel="noopener noreferrer"&gt;CSS Reference&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/docs/Web/JavaScript" rel="noopener noreferrer"&gt;JavaScript Reference&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They also have some &lt;a href="https://developer.mozilla.org/docs/Web" rel="noopener noreferrer"&gt;other more specific references&lt;/a&gt; such as ones for &lt;a href="https://developer.mozilla.org/docs/Web/SVG" rel="noopener noreferrer"&gt;SVG&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/docs/Web/API/Canvas_API" rel="noopener noreferrer"&gt;canvas&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Codrops CSS Reference
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://tympanus.net/codrops/css_reference/" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2F%2Fassets%2Fimg%2Fposts%2Fweb-development-reference-sites%2Fcodrops.png" alt="Codrops CSS Reference"&gt;&lt;/a&gt;Last but definitely not least, the &lt;a href="https://tympanus.net/codrops/css_reference/" rel="noopener noreferrer"&gt;Codrops CSS Reference&lt;/a&gt; has a really great layout and is easy to navigate and use. They have &lt;em&gt;every single&lt;/em&gt; CSS property, function, data type, rule and more. When you click on one it takes you a page with the official syntax, values, examples and more. It even shows you which browsers support the feature!&lt;/p&gt;

&lt;p&gt;Much like MDN, it is very in-depth. However, I like it much more than MDN because even though there is a lot of content, it is organized in a much better way and is easier to navigate and find what you are looking for. Unfortunately, Codrops only has a CSS reference, not an HTML or JavaScript one :( If they did, that would be awesome, but for the moment I’m glad that the CSS one exists.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reference links:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://tympanus.net/codrops/css_reference/" rel="noopener noreferrer"&gt;CSS Reference&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6. Stack Overflow
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://stackoverflow/" rel="noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2F%2Fassets%2Fimg%2Fposts%2Fweb-development-reference-sites%2Fstackoverflow.png" alt="Stack Overflow"&gt;&lt;/a&gt;While &lt;a href="https://stackoverflow/" rel="noopener noreferrer"&gt;Stack Overflow&lt;/a&gt; is not strictly a reference site, it is an invaluable place to get answers to programming questions or issues. Most of the time when you have a question, you will find that it has already been answered on the site - look no further! If not, you can post a question and someone will usually get back to you within an hour (often less) of posting the question (unless it’s really obscure or tricky). The Stack Overflow community is helpful, kind, generous, and smart and will help you through whatever your issue is.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://stackoverflow/tour" rel="noopener noreferrer"&gt;There is a great tour page explaining how it works here.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  My cheat-sheets! (coming soon)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2F%2Fassets%2Fimg%2Fbanner.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcodetheweb.blog%2F%2Fassets%2Fimg%2Fbanner.png" alt="My cheat-sheets!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Haha, what’s a good article without some self-promotion 😉&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, early next year I’m gonna be making some cheat-sheets on HTML and CSS (and JavaScript late next year). While they won’t be full-on references, I hope to make them a good place to refer to for a basic summary of the language. If you have any ideas as to what you, as a reader, would like them to contain, &lt;a href="https://codetheweb.blog/contact" rel="noopener noreferrer"&gt;send me an email&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;In the meantime, stay tuned!&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Hopefully, this list helped you! If there’s anything that you think should have been on there or want to have a heated discussion on which is the best, the comments are the place for you. Also, I love feedback! Tell me there 👇&lt;/p&gt;

&lt;p&gt;Here is a quick recap of the websites I talked about today:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Website&lt;/th&gt;
&lt;th&gt;Links&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;W3Schools&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://www.w3schools.com/tags/" rel="noopener noreferrer"&gt;HTML&lt;/a&gt;, &lt;a href="https://www.w3schools.com/cssref/" rel="noopener noreferrer"&gt;CSS&lt;/a&gt;, &lt;a href="https://www.w3schools.com/jsref/" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DevDocs&lt;/td&gt;
&lt;td&gt;
&lt;a href="http://devdocs.io/html/" rel="noopener noreferrer"&gt;HTML&lt;/a&gt;, &lt;a href="http://devdocs.io/css/" rel="noopener noreferrer"&gt;CSS&lt;/a&gt;, &lt;a href="http://devdocs.io/javascript/" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;freeCodeCamp Guides&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://guide.freecodecamp.org/html" rel="noopener noreferrer"&gt;HTML&lt;/a&gt;, &lt;a href="https://guide.freecodecamp.org/css" rel="noopener noreferrer"&gt;CSS&lt;/a&gt;, &lt;a href="https://guide.freecodecamp.org/javascript" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;MDN Web Docs&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://developer.mozilla.org/docs/Web/HTML" rel="noopener noreferrer"&gt;HTML&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/docs/Web/CSS" rel="noopener noreferrer"&gt;CSS&lt;/a&gt;, &lt;a href="https://developer.mozilla.org/docs/Web/JavaScript" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Codrops CSS Reference&lt;/td&gt;
&lt;td&gt;&lt;a href="https://tympanus.net/codrops/css_reference/" rel="noopener noreferrer"&gt;CSS&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Stack Overflow&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://stackoverflow/" rel="noopener noreferrer"&gt;Homepage&lt;/a&gt;, &lt;a href="https://stackoverflow/tour" rel="noopener noreferrer"&gt;Tour page&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If you liked this article and want to inspire some fellow coders or soon-to-be coders, I’d really appreciate it if you shared this article. Thanks! Also, if you want to receive new posts I’d be stoked if you &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;signed up to the newsletter&lt;/a&gt;! If you do, you’re officially awesome in my eyes 😎 and deserve a taco 🌮&lt;/p&gt;

&lt;p&gt;Have a great 2018 and hopefully these websites I shared will help you along your coding journey! Stay tuned for next time, where I’ll be talking about &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;free resources to test your website&lt;/a&gt;. This is a great way to see how you can improve your website going into 2018 📆 🎆 . See you then!&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Want more posts like this? &lt;a href="https://codetheweb.blog/newsletter/" rel="noopener noreferrer"&gt;Sign up to my newsletter&lt;/a&gt;.
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;I've worked hard on these tutorials and as of now do not make any money on them, so I'd really appreciate if you signed up ;)&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This article was originally published at &lt;a href="https://codetheweb.blog" rel="noopener noreferrer"&gt;Code The Web&lt;/a&gt;, a fun and easy-to-understand blog to help you learn web development 🚀&lt;br&gt;
Learn: &lt;a href="https://codetheweb.blog/learn/html/" rel="noopener noreferrer"&gt;HTML&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/css/" rel="noopener noreferrer"&gt;CSS&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/javascript/" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>learning</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>The complete guide to HTML icons — iOS, Android, desktop and more…</title>
      <dc:creator>Ethan</dc:creator>
      <pubDate>Thu, 14 Dec 2017 00:00:00 +0000</pubDate>
      <link>https://dev.to/codetheweb/the-complete-guide-to-html-icons--ios-android-desktop-and-more-5j</link>
      <guid>https://dev.to/codetheweb/the-complete-guide-to-html-icons--ios-android-desktop-and-more-5j</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frdhujqt304tk5gj4h1wq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frdhujqt304tk5gj4h1wq.png" alt="The complete guide to HTML icons — iOS, Android, desktop and more…" width="800" height="461"&gt;&lt;/a&gt;&lt;br&gt;
Learn how to make an icon for iOS, Android, desktop and more using HTML in this article…&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;Feel free to follow along! You may not have all the devices, operating systems or browsers I will be talking about, but you will at least be able to test one or two 😉&lt;/p&gt;

&lt;p&gt;To get started create an HTML file with the following basic code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
    &amp;lt;head&amp;gt;
        &amp;lt;title&amp;gt;HTML Icons&amp;lt;/title&amp;gt;
    &amp;lt;/head&amp;gt;
    &amp;lt;body&amp;gt;
        &amp;lt;h1&amp;gt;HTML icons!&amp;lt;/h1&amp;gt;
    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open it up in a browser - it should look like this: &lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpfgmaf3tnpff2cfi0nmd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpfgmaf3tnpff2cfi0nmd.png" alt="An HTML page with the words " width="800" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you’re ready to go!&lt;/p&gt;

&lt;h2&gt;
  
  
  The icon
&lt;/h2&gt;

&lt;p&gt;In the examples today, we’ll be using this waffle icon that I made (with ice-cream on top of course 🍦 😉): &lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv2ouhl6nrlms1q5k64gl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv2ouhl6nrlms1q5k64gl.png" alt="Waffle icon" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Doesn’t that look delicious!&lt;/p&gt;
&lt;h2&gt;
  
  
  Browser tab icons (favicons)
&lt;/h2&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you take a look at the little icon on your tab right now (these are also known as favicons), it will just give us a boring default icon - nobody wants that!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz9ofizkf14ctvqe342wf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz9ofizkf14ctvqe342wf.png" alt="The default 'page' icon" width="332" height="119"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note that depending on what browser you’re using, the tabs and default icon might look slightly different. This and most of the other browser screenshots in this article are taken in Google Chrome.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, let’s add our own one! Simply add this line of code inside your &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;link rel="icon" type="image/png" sizes="64x64" href="https://codetheweb.blog/assets/img/posts/html-icons/icon64.png"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;type&lt;/code&gt; attribute depends on the image we are using. In this case, we are using a &lt;code&gt;.png&lt;/code&gt; file, so we’ll set our &lt;code&gt;type&lt;/code&gt; to &lt;code&gt;image/png&lt;/code&gt;. There are other &lt;code&gt;type&lt;/code&gt;s you can use such as &lt;code&gt;image/ico&lt;/code&gt; for &lt;code&gt;.ico&lt;/code&gt; files.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Favicon#File_format_support" rel="noopener noreferrer"&gt;Click here for a list of supported file types.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, make sure that your icon is either &lt;code&gt;16px&lt;/code&gt; by &lt;code&gt;16px&lt;/code&gt;, &lt;code&gt;32px&lt;/code&gt; by &lt;code&gt;32px&lt;/code&gt; or &lt;code&gt;64px&lt;/code&gt; by &lt;code&gt;64px&lt;/code&gt;. You need to make sure that the &lt;em&gt;actual image&lt;/em&gt; has those dimensions as well as the &lt;code&gt;sizes&lt;/code&gt; attribute - you can resize your images online. Note that other sizes also work, but they are not supported by all browsers. In this case, our image is &lt;code&gt;64px&lt;/code&gt; by &lt;code&gt;64px&lt;/code&gt; - I recommend that you use this size because it is the highest resolution out of the three.&lt;/p&gt;

&lt;p&gt;Anyway, here is the result: &lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fazuspnnxr4sy2hf7nx4e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fazuspnnxr4sy2hf7nx4e.png" alt="Our favicon now shows up!" width="800" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is now an icon next to our page title! 🎉 🎉 &lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzqi75eq3fufwv13u9y48.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzqi75eq3fufwv13u9y48.png" alt="A close up of the favicon" width="332" height="119"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Safari home screen and bookmark icons
&lt;/h2&gt;

&lt;p&gt;If we &lt;a href="https://www.wikihow.com/Add-a-Link-Button-to-the-Home-Screen-of-an-iPhone" rel="noopener noreferrer"&gt;add our website to the home screen&lt;/a&gt; on iOS, it will give us a very ugly and weirdly-sized screenshot by default: &lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj27vrm082qh6vfky2sr3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj27vrm082qh6vfky2sr3.png" alt="A very ugly and weirdly-sized screenshot as the website icon" width="800" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s add our own icon instead! To do so, add this line below your favicon line in your &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;link rel="apple-touch-icon" sizes="180x180" href="https://codetheweb.blog/assets/img/posts/html-icons/icon180.png"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, this is very similar to how we declare our favicon, except that we use &lt;code&gt;apple-touch-icon&lt;/code&gt; as the &lt;code&gt;rel&lt;/code&gt; attribute instead. Make sure that your icon is always &lt;code&gt;180px&lt;/code&gt; by &lt;code&gt;180px&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now if we add it to the home screen again, we get a much better result! &lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxiktn10clc07su45lmk3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxiktn10clc07su45lmk3.png" alt="Now our waffle icon is on the home screen!" width="800" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This also gives our website an icon for Safari bookmarks on iOS: &lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foo932wchx23hb6fzfcb6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foo932wchx23hb6fzfcb6.png" alt="Bookmark icon on iOS" width="800" height="586"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And on Mac: &lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frh148dxoeqsstz34c1r6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frh148dxoeqsstz34c1r6.png" alt="Bookmark icon on Mac" width="800" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Android icons
&lt;/h2&gt;

&lt;p&gt;Websites can also be added to the home screen using Google Chrome on Android. Luckily, we don’t need to specify icons just for Android! It will either use the favicon or an &lt;code&gt;apple-touch-icon&lt;/code&gt; if you have one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Windows tiles
&lt;/h2&gt;

&lt;p&gt;On Windows, if you don’t know already, there are these things called tiles: &lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsup432scl4q3bvywup9e.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsup432scl4q3bvywup9e.jpg" alt="Windows tiles" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;They are also used on Windows phones: &lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5fbofzwfnprvppchoi8p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5fbofzwfnprvppchoi8p.png" alt="Windows phone tiles" width="800" height="534"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see in the photos above, we also need to create a rectangular version of our logo, for if the tile is rectangular. Here is a rectangular version of the waffle that I made: &lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fthd8xacyqqxy9kv8ely7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fthd8xacyqqxy9kv8ely7.png" alt="Rectangular waffle icon" width="800" height="387"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In our HTML, we need to define this icon as well as three square icon sizes: &lt;code&gt;70px&lt;/code&gt; by &lt;code&gt;70px&lt;/code&gt;, &lt;code&gt;150px&lt;/code&gt; by &lt;code&gt;150px&lt;/code&gt; and &lt;code&gt;310px&lt;/code&gt; by &lt;code&gt;310px&lt;/code&gt;. Our rectangular icon needs to be &lt;code&gt;310px&lt;/code&gt; wide by &lt;code&gt;150px&lt;/code&gt; high.&lt;/p&gt;

&lt;p&gt;One important thing though: &lt;strong&gt;When making icons for Windows tiles, always have a transparent background.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here are our icons but with a transparent background: &lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fncxm3esk4uuthccmmxu9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fncxm3esk4uuthccmmxu9.png" alt="Square icon with transparent background" width="800" height="800"&gt;&lt;/a&gt; &lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnlmlzmte2qk0j09b8ile.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnlmlzmte2qk0j09b8ile.png" alt="Rectangular icon with transparent background" width="800" height="387"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is the HTML - add it below your Safari icon and favicon in the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta name="msapplication-square70x70logo" content="https://codetheweb.blog/assets/img/posts/html-icons/icon70.png"&amp;gt;
&amp;lt;meta name="msapplication-square150x150logo" content="https://codetheweb.blog/assets/img/posts/html-icons/icon150.png"&amp;gt;
&amp;lt;meta name="msapplication-wide310x150logo" content="https://codetheweb.blog/assets/img/posts/html-icons/icon310.png"&amp;gt;
&amp;lt;meta name="msapplication-square310x310logo" content="https://codetheweb.blog/assets/img/posts/html-icons/icon-rect-310.png"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are slightly different to the icon types we’ve discussed so far, because they use &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tags instead of &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; tags.&lt;/p&gt;

&lt;p&gt;But if the icons have a transparent background, won’t it look weird? &lt;strong&gt;Yes.&lt;/strong&gt; The reason that they need to have a transparent background is so that Windows can put a color beneath them. Take this tile as an example: &lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1qa3lozw9f9exw4nowgt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1qa3lozw9f9exw4nowgt.png" alt="Map icon tile" width="136" height="136"&gt;&lt;/a&gt;Here, the map icon would be the image (with a transparent background), and then Windows would put the pink/purple color beneath it. But how do we tell Windows which color? This is where the &lt;code&gt;msapplication-TileColor&lt;/code&gt; meta tag comes in handy. In this case our waffle icon background &lt;a href="https://codetheweb.blog/2017/11/15/basic-css-properties/#hex-values" rel="noopener noreferrer"&gt;hex color&lt;/a&gt; is &lt;code&gt;#2e2e2e&lt;/code&gt;. With that in mind, add this line underneath our icons inside the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta name="msapplication-TileColor" content="#2e2e2e"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the result of the icons and tile color meta tags: &lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuobssn451zolkbvp2c5q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuobssn451zolkbvp2c5q.png" alt="The square and rectangular icons as Windows tiles" width="264" height="392"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  If you’re too lazy… 😴
&lt;/h2&gt;

&lt;p&gt;There is this awesome website called &lt;a href="https://realfavicongenerator.net/" rel="noopener noreferrer"&gt;Real Favicon Generator&lt;/a&gt; which generates favicons, Safari icons, Windows icons and more for you. &lt;strong&gt;However, I recommend that you don’t use this until you are quite confident with doing it yourself&lt;/strong&gt; - otherwise, you will never learn. That said, you can always look it up if you need. So it’s up to you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Woo! That’s all there is for today. Hopefully, you learned something! If you did, I’d love it if you shared it or &lt;a href="https://codetheweb.blog/newsletter" rel="noopener noreferrer"&gt;signed up to the newsletter&lt;/a&gt; to get new posts in your inbox. If you do either of these things, you are awesome and deserve a space-taco if that’s even a thing! 😎 🌮 🚀&lt;/p&gt;

&lt;p&gt;I talked about icons for lots of different platforms today, and you don’t have to use all of them - although it’s a good idea. But for a start, you could just try getting used to favicons (the first part).&lt;/p&gt;

&lt;p&gt;If you need help, have feedback or wanna say hi 👋 then I’d be stoked if you did so in the comments below.&lt;/p&gt;

&lt;p&gt;Next time, I’ll be doing a special post on &lt;a href="https://codetheweb.blog/2017/12/16/web-development-reference-sites/" rel="noopener noreferrer"&gt;Quick-reference sites to help you along your coding journey&lt;/a&gt;. See you then!&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Want more posts like this? &lt;a href="https://codetheweb.blog/newsletter/" rel="noopener noreferrer"&gt;Sign up to my newsletter&lt;/a&gt;.
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;I've worked hard on these tutorials and as of now do not make any money on them, so I'd really appreciate if you signed up ;)&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This article was originally published at &lt;a href="https://codetheweb.blog" rel="noopener noreferrer"&gt;Code The Web&lt;/a&gt;, a fun and easy-to-understand blog to help you learn web development 🚀&lt;br&gt;
Learn: &lt;a href="https://codetheweb.blog/learn/html/" rel="noopener noreferrer"&gt;HTML&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/css/" rel="noopener noreferrer"&gt;CSS&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/javascript/" rel="noopener noreferrer"&gt;JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>html</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Styling a navigation bar using CSS</title>
      <dc:creator>Ethan</dc:creator>
      <pubDate>Tue, 12 Dec 2017 00:00:00 +0000</pubDate>
      <link>https://dev.to/codetheweb/styling-a-navigation-bar-using-css-4b7</link>
      <guid>https://dev.to/codetheweb/styling-a-navigation-bar-using-css-4b7</guid>
      <description>&lt;p&gt;You can find navigation bars on almost any website on the internet. Learn how to code and style one in this article!&lt;/p&gt;

&lt;h2&gt;
  
  
  The final product
&lt;/h2&gt;

&lt;p&gt;Here is what we'll be making today:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--B3vBNc-t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/final-product.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--B3vBNc-t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/final-product.png" alt="The final product"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://codetheweb.blog/demo/style-a-navigation-bar-css/"&gt;You can see a live demo here.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Terminology
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Lol, this sounds like the start of a legal agreement 😂&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For the purposes of this article, a navigation bar (nav-bar) is the same thing as a header. I'll be using the term "nav-bar" in this article, but just know that they are basically the same.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;I recommend that you follow along in each of my tutorials - it will really help you learn and grasp the concepts faster. Especially in tutorials like this, it will be fun to code along.&lt;/p&gt;

&lt;p&gt;To get started, create a new project folder and create blank &lt;code&gt;index.html&lt;/code&gt; and &lt;code&gt;style.css&lt;/code&gt; files inside. Let's get going and fill them up!&lt;/p&gt;

&lt;h2&gt;
  
  
  The HTML
&lt;/h2&gt;

&lt;p&gt;As you know, the HTML is the start of any website. Add the following to your &lt;code&gt;index.html&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Navigation bar DEMO&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"style.css"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;header&amp;gt;&lt;/span&gt;
           &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://codetheweb.blog/assets/img/icon2.png"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;nav&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Home&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;About&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Pricing&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Terms of use&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
                    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Contact&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;/nav&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/header&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;main&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. In consequat libero eget magna commodo, quis pharetra tellus pretium. Sed viverra ante in mauris finibus dapibus. Maecenas congue dapibus nulla, eu gravida orci consequat eu. Phasellus nec nunc malesuada, aliquam massa ac, accumsan metus. Fusce sed dignissim lectus. Nunc elit tellus, sollicitudin ac accumsan ut, egestas et dui. Maecenas aliquam est a ligula scelerisque, in aliquam neque sodales. Nullam condimentum euismod dictum. Curabitur non ex elementum, pretium enim ut, ornare ipsum.&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/main&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the body, we have the header and navigation elements. If you are not familiar with this structure of a navigation bar in HTML, &lt;a href="https://codetheweb.blog/2017/10/29/lists-and-navigation/#navigation"&gt;take a look at this article&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Below the header, we have some dummy text inside the &lt;code&gt;&amp;lt;main&amp;gt;&lt;/code&gt; element. This is so that we can see problems that will arise later in the tutorial.&lt;/p&gt;

&lt;p&gt;Open up your &lt;code&gt;index.html&lt;/code&gt; file in a browser - at this point, it should look like so:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ydhvkUCz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/base-html.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ydhvkUCz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/base-html.png" alt="The basic HTML viewed in our browser"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Not that you will probably have to scroll down unless you are reeeaaaally zoomed out because our image is massive!&lt;/p&gt;

&lt;p&gt;Time for our CSS...&lt;/p&gt;

&lt;h2&gt;
  
  
  The basic CSS
&lt;/h2&gt;

&lt;p&gt;First of all, our image is waaaaaay too big. Let's shrink it down to a height of &lt;code&gt;80px&lt;/code&gt; - this will be the height of our nav-bar. Add the following to your &lt;code&gt;style.css&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mmMOzHxu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/fixed-image-height.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mmMOzHxu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/fixed-image-height.png" alt="The image is now a good size!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Phew, I can breathe now 😅&lt;/p&gt;

&lt;p&gt;Next, let's set our styling up so we will be able to see what's going on. First of all, we want to be able to scroll - we can do this by setting the &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; height to &lt;code&gt;125vh&lt;/code&gt; (&lt;a href="https://codetheweb.blog/2017/12/04/css-units/#vw--vh"&gt;viewport height&lt;/a&gt;). We want to be able to &lt;em&gt;see&lt;/em&gt; when we are scrolling down, and we can do this by adding a &lt;code&gt;background-image&lt;/code&gt;. While we're at it, let's set our font to &lt;code&gt;sans-serif&lt;/code&gt; so it doesn't look as terrible. Here's the CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;125vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sx"&gt;url('https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/background.jpg')&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cover&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One more thing, let's add a &lt;code&gt;color&lt;/code&gt; to our &lt;code&gt;&amp;lt;main&amp;gt;&lt;/code&gt; so that we can see the dummy text better:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;125vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sx"&gt;url('https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/background.jpg')&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cover&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's the result of all that:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0mOv8ydL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/base-css.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0mOv8ydL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/base-css.png" alt="The result of the styles so far"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Don't worry about changing the colors of the links because we will be styling those later anyway.&lt;/p&gt;
&lt;h2&gt;
  
  
  Positioning the nav-bar
&lt;/h2&gt;

&lt;p&gt;Okay, now our website is looking alright - but not our nav-bar! It still looks like a list, because &lt;strong&gt;whenever you make a navigation bar, it has to have &lt;a href="https://codetheweb.blog/2017/10/29/lists-and-navigation/#navigation"&gt;a specific structure&lt;/a&gt;&lt;/strong&gt; (the one containing an &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt;). This is because it is easier for web crawlers to navigate, and also &lt;a href="//%7B%7Bsite.newsletter%7D%7D"&gt;Google will like you&lt;/a&gt; 😉&lt;/p&gt;

&lt;p&gt;First of all, let's start by positioning the actual &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt; element. We'll also want to give the &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt; a &lt;code&gt;background-color&lt;/code&gt; so that we can see its position. Let's add some styles!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;125vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sx"&gt;url('https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/background.jpg')&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cover&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;fixed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here' we're positioning the &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt; element &lt;a href="https://codetheweb.blog/2017/11/21/css-position-property/#position-fixed"&gt;using&lt;code&gt;position : fixed&lt;/code&gt;&lt;/a&gt;. Then, we also set the &lt;code&gt;height&lt;/code&gt; to &lt;code&gt;80px&lt;/code&gt; like I mentioned earlier (the only reason that we're using that specific is because it looks good).&lt;/p&gt;

&lt;p&gt;Here is the result:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WQImW8Ys--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/header-positioning.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WQImW8Ys--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/header-positioning.png" alt="The header is now positioned!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yay, our header/nav-bar is now positioned! However, the dummy text in the &lt;code&gt;&amp;lt;main&amp;gt;&lt;/code&gt; has been obscured 😕&lt;/p&gt;

&lt;p&gt;Now that the nav-bar has a &lt;code&gt;position&lt;/code&gt; of  &lt;code&gt;fixed&lt;/code&gt;, the rest of the content on the page moves up. This means that the main text is actually &lt;em&gt;underneath&lt;/em&gt; our nav-bar!&lt;/p&gt;

&lt;p&gt;To fix this, we simply need to give the body a &lt;code&gt;margin-top&lt;/code&gt; equal to the height of the nav-bar, &lt;code&gt;80px&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;125vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sx"&gt;url('https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/background.jpg')&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cover&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;fixed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LKig8PCU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/body-margin-top.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LKig8PCU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/body-margin-top.png" alt="The main text is no longer hidden under the nav-bar!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Woo! The only thing is that now the text is right up against the bottom of the nav-bar 😕 Let's fix it by adding some &lt;code&gt;padding&lt;/code&gt; (I totally didn't mean for that to rhyme 😂) - here is the CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;125vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sx"&gt;url('https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/background.jpg')&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cover&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;fixed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C7bNlSJ6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/body-padding.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C7bNlSJ6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/body-padding.png" alt="Now the text has some padding"&gt;&lt;/a&gt;&lt;br&gt;
Much better!&lt;/p&gt;

&lt;p&gt;Here are the &lt;code&gt;margin&lt;/code&gt; and &lt;code&gt;padding&lt;/code&gt; of the body visualized:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KM6l0_pK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/body-margin-padding-visualized.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KM6l0_pK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/body-margin-padding-visualized.png" alt="The margin and padding of the body visualized"&gt;&lt;/a&gt;&lt;br&gt;
(the margin is orange, the padding is green and the main part of the body is blue)&lt;/p&gt;

&lt;p&gt;Congrats, now we've got our page pretty much working! However, not the stuff inside the &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt; - it is overlapping the rest of the text and looks bad.&lt;/p&gt;
&lt;h2&gt;
  
  
  Styling the contents of the nav-bar
&lt;/h2&gt;

&lt;p&gt;Now, let's position the items inside the nav-bar! First of all, we want to make the items go horizontally instead of vertically. We can do this using &lt;code&gt;display: inline&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;125vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sx"&gt;url('https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/background.jpg')&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cover&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;fixed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;inline&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we are using the selector &lt;code&gt;header *&lt;/code&gt;. The &lt;code&gt;*&lt;/code&gt; is a wildcard and can mean any element. So &lt;code&gt;header *&lt;/code&gt; basically means any element inside the &lt;code&gt;header&lt;/code&gt;. Also, note that when we use &lt;code&gt;display: inline&lt;/code&gt;, the bullet points go away. The reason that the bullet points appear in the first place is that by default &lt;code&gt;&amp;lt;li&amp;gt;&lt;/code&gt; elements have a &lt;code&gt;display&lt;/code&gt; type of &lt;code&gt;list-item&lt;/code&gt;. So when we override this and change it to &lt;code&gt;inline&lt;/code&gt;, the bullet points disappear.&lt;/p&gt;

&lt;p&gt;Here is the result:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--opKlL5oy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/header-items-inline.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--opKlL5oy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/header-items-inline.png" alt="The header items are now displayed horizontally"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, our links now go to the bottom of the nav-bar! We can make them go to the top of the nav-bar by giving our &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt; element a &lt;code&gt;display&lt;/code&gt; property of &lt;a href="https://codetheweb.blog/2017/12/05/css-flexboxes/"&gt;&lt;code&gt;flex&lt;/code&gt;&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;125vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sx"&gt;url('https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/background.jpg')&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cover&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;fixed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;inline&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qLzcordE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/header-display-flex.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qLzcordE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/header-display-flex.png" alt="The nav-bar items are now at the top of the screen"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, the text is still not vertically aligned to the middle of the nav-bar. We can vertically align our items in the nav-bar using &lt;code&gt;align-items: center&lt;/code&gt;. If you don't know about &lt;code&gt;display: flex&lt;/code&gt; or &lt;code&gt;align-items: center&lt;/code&gt;, check out my &lt;a href="https://codetheweb.blog/2017/12/05/css-flexboxes/"&gt;flexbox tutorial&lt;/a&gt;. Here is the CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;125vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sx"&gt;url('https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/background.jpg')&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cover&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;fixed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;inline&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O3nXz-vt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/align-items-center.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O3nXz-vt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/align-items-center.png" alt="Woo! Our nav-bar items are finally vertically aligned!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, all the links in the nav-bar are very squished together - we can space them out more by giving them a &lt;code&gt;margin&lt;/code&gt; property:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;125vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sx"&gt;url('https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/background.jpg')&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cover&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;fixed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;inline&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WyKISiFH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/header-items-margin.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WyKISiFH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/header-items-margin.png" alt="The items in the nav-bar are now much more spaced out"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That looks better! Now that our nav-bar items are positioned, it's time to give them some styles! We want to take away the ugly default link styles, so let's go ahead and do that - we can set the &lt;code&gt;color&lt;/code&gt; to &lt;code&gt;black&lt;/code&gt; and the &lt;code&gt;text-decoration&lt;/code&gt; to &lt;code&gt;none&lt;/code&gt; (normally it would be &lt;code&gt;underline&lt;/code&gt;). Here is the CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;125vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sx"&gt;url('https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/background.jpg')&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cover&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;fixed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;inline&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;text-decoration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--b4aGN9yS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/link-styling-override.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--b4aGN9yS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/link-styling-override.png" alt="The links in our nav-bar are now rid of the default styling :)"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We're on the final stretch now! Our logo (well, my logo technically 😜) looks a bit weird, so let's fix up the positioning by adding a &lt;code&gt;margin-left&lt;/code&gt;! Here is the CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin-left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;125vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sx"&gt;url('https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/background.jpg')&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cover&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;fixed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;inline&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;text-decoration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Result:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HULsi4Ax--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/logo-margin-left.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HULsi4Ax--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/logo-margin-left.png" alt="There we are, the logo spacing looks better now"&gt;&lt;/a&gt;&lt;br&gt;
Much more aesthetically pleasing! 😘&lt;/p&gt;

&lt;p&gt;Okay, this is the last thing for today, and it's very cool. We're going to add a shadow to our navigation bar. What? A shadow? I thought that was stuff that you could only do in Photoshop???&lt;/p&gt;

&lt;p&gt;Well, believe it or not, CSS has its own way of making shadows - in fact, multiple ways! In another article, I'll be going through &lt;a href="//%7B%7Bsite.newsletter%7D%7D"&gt;all the different types of CSS shadows&lt;/a&gt; in more depth.&lt;/p&gt;

&lt;p&gt;For the moment, we'll be using the &lt;code&gt;box-shadow&lt;/code&gt; property. It simply creates a rectangular shadow around an element.&lt;/p&gt;

&lt;p&gt;Here is the syntax for the &lt;code&gt;box-shadow&lt;/code&gt; property:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m-YBo3tS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/box-shadow-syntax.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m-YBo3tS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/box-shadow-syntax.png" alt="box-shadow: {x-offset} {y-offset} {blur} {spread}"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;x-offset&lt;/code&gt; and &lt;code&gt;y-offset&lt;/code&gt; are how far to the side and up/down the shadow is, &lt;code&gt;blur&lt;/code&gt; is how blurred the shadow is, and &lt;code&gt;spread&lt;/code&gt; is how far out of the element the shadow spreads. All of these values can be negative, except for &lt;code&gt;blur&lt;/code&gt;. Afterwards, we have the color that we want the shadow to be. Let's add a very simple (but effective) shadow to our nav-bar:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin-left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;125vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-image&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sx"&gt;url('https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/background.jpg')&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cover&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;main&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;white&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;fixed&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;80px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;box-shadow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;25px&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;inline&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;header&lt;/span&gt; &lt;span class="nt"&gt;li&lt;/span&gt; &lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;text-decoration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, we're really only using the &lt;code&gt;blur&lt;/code&gt; here - we are setting rest of the values (&lt;code&gt;x-offset&lt;/code&gt;, &lt;code&gt;y-offset&lt;/code&gt; and &lt;code&gt;spread&lt;/code&gt;) to &lt;code&gt;0&lt;/code&gt;. Here is the result:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--B3vBNc-t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/final-product.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--B3vBNc-t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://codetheweb.blog/assets/img/posts/style-a-navigation-bar-css/final-product.png" alt="The nav-bar now has a shadow!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Awesome!!! Our navigation bar now has a shadow!!! 🎉&lt;/p&gt;

&lt;p&gt;That's it for today 😉&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;So, I hope you learned a lot in this article! Now you can go forth and make your own navigations bars. They are used by almost every website you visit, so are a very important thing to know how to code.&lt;/p&gt;

&lt;p&gt;In future, I'll be writing a tutorial on &lt;a href="//%7B%7Bsite.newsletter%7D%7D"&gt;how to style a &lt;em&gt;responsive&lt;/em&gt; navigation bar&lt;/a&gt;, meaning that it will adapt to different screen sizes (eg. show a 'menu' icon on mobile).&lt;/p&gt;

&lt;p&gt;In the meantime, I'd really love it if you &lt;a href="https://codetheweb.blog/2017/12/12/style-a-navigation-bar-css/#share"&gt;shared this&lt;/a&gt; or &lt;a href="https://codetheweb.blog/newsletter"&gt;subscribed to the newsletter&lt;/a&gt; to receive new posts in your inbox. If you do either of those things, you are awesome and I will give you a lifetime supply of tacos 🌮 (not really, just my new marketing tactic 😜 ).&lt;/p&gt;

&lt;p&gt;Have fun, keep coding and I'll see you next time, where I'll be talking about &lt;a href="https://codetheweb.blog/2017/12/14/html-icons/"&gt;website icons in HTML&lt;/a&gt; (I thought I'd change it up a bit and do an HTML one). See you then!&lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Want more posts like this? &lt;a href="https://codetheweb.blog/newsletter/"&gt;Sign up to my newsletter&lt;/a&gt;.
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;I've worked hard on these tutorials and as of now do not make any money on them, so I'd really appreciate if you signed up ;)&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This article was originally published at &lt;a href="https://codetheweb.blog"&gt;Code The Web&lt;/a&gt;, a fun and easy-to-understand blog to help you learn web development 🚀&lt;br&gt;
Learn: &lt;a href="https://codetheweb.blog/learn/html/"&gt;HTML&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/css/"&gt;CSS&lt;/a&gt; | &lt;a href="https://codetheweb.blog/learn/javascript/"&gt;JavaScript&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
