<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Brice Duke</title>
    <description>The latest articles on Forem by Brice Duke (@briceduke).</description>
    <link>https://forem.com/briceduke</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F600639%2F9d37fb30-c105-40f5-b7a1-90ba51a2776a.jpg</url>
      <title>Forem: Brice Duke</title>
      <link>https://forem.com/briceduke</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/briceduke"/>
    <language>en</language>
    <item>
      <title>Javascript, ASAP 🌐</title>
      <dc:creator>Brice Duke</dc:creator>
      <pubDate>Tue, 20 Apr 2021 04:29:55 +0000</pubDate>
      <link>https://forem.com/briceduke/javascript-asap-27gh</link>
      <guid>https://forem.com/briceduke/javascript-asap-27gh</guid>
      <description>&lt;p&gt;👋 &lt;em&gt;Oh hello, didn't see you there!&lt;/em&gt; Today I'll be giving you a snappy rundown of Javascript. It's my favorite language, and I think that it's extremely useful; everyone should know it!&lt;/p&gt;

&lt;h4&gt;
  
  
  Why do I love it so much?
&lt;/h4&gt;

&lt;p&gt;Simply put, Javascript can be used for so many different things, from game development to web development and even machine learning; we'll be focusing on Javascript that's run in the browser for now, though.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: This course is intended for complete coding beginners, although more experienced coders are more than welcome to take a gander!&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  What you'll learn
&lt;/h4&gt;

&lt;p&gt;You will learn the basic fundamentals of Javascript - hopefully enough to determine whether you'd like to dig deeper into the language. Big paragraphs are boring though, so I thought it'd be fun to learn it by building mini-projects! 🏗&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's get started with Javascript, as Soon as Possible!
&lt;/h3&gt;

&lt;p&gt;If you're on anything with a keyboard, you'll be able to follow along with the projects. Here's how to get set up:&lt;/p&gt;

&lt;p&gt;Do &lt;code&gt;ctrl&lt;/code&gt;+&lt;code&gt;shift&lt;/code&gt;+&lt;code&gt;J&lt;/code&gt; (&lt;code&gt;cmd&lt;/code&gt;+&lt;code&gt;shift&lt;/code&gt;+&lt;code&gt;J&lt;/code&gt; on Mac) to open up your browser console; that'll be our workspace for this crash course! Feel free to resize the console window by dragging on the edges of it.&lt;/p&gt;

&lt;p&gt;Let's begin with the basics:&lt;/p&gt;

&lt;h3&gt;
  
  
  Operators
&lt;/h3&gt;

&lt;p&gt;In your console, go ahead and try typing in your favorite number, followed by a &lt;code&gt;+&lt;/code&gt;, and lastly, type &lt;code&gt;10&lt;/code&gt;. Now hit enter, and voila, you added 10 to your favorite number! That's how easy math operations are in Javascript. Here's a list of the main operators:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;+&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt;, and &lt;code&gt;/&lt;/code&gt; are self-explanatory&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;%&lt;/code&gt; is the modulo operation, which is the remainder of a division; type in &lt;code&gt;7 % 4&lt;/code&gt; and see for yourself!&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;**&lt;/code&gt; represents exponents... Typing in &lt;code&gt;7**2&lt;/code&gt; will return &lt;code&gt;49&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;===&lt;/code&gt; will compare two things and return &lt;code&gt;true&lt;/code&gt; if they're equivalent. If you type in &lt;code&gt;7 === 4&lt;/code&gt;, what happens?&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;!==&lt;/code&gt; will compare two things and return &lt;code&gt;True&lt;/code&gt; if they're not equivalent, so &lt;code&gt;7 !== 4&lt;/code&gt; should be true!&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;&lt;/code&gt; compare two things to see if they're greater or less than (&lt;code&gt;7 &amp;gt; 4&lt;/code&gt; returns &lt;code&gt;true&lt;/code&gt;, and &lt;code&gt;7 &amp;lt; 4&lt;/code&gt; returns &lt;code&gt;false&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;gt;=&lt;/code&gt; and &lt;code&gt;&amp;lt;=&lt;/code&gt; are greater/less than OR equal to (&lt;code&gt;7 &amp;gt;= 7&lt;/code&gt; is &lt;code&gt;true&lt;/code&gt;, &lt;code&gt;4 &amp;lt;= 7&lt;/code&gt; is also &lt;code&gt;true&lt;/code&gt; - but don't take my word for it, try it out!)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;||&lt;/code&gt; compares two things and returns true if one condition is met (think of it like "or")&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; compares two things and returns true if both conditions are met (think of it like "and")&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Typing in &lt;code&gt;(1 + 2) * 3&lt;/code&gt; will give us 9. &lt;strong&gt;Operators follow the order of operations&lt;/strong&gt;, so Javascript would evaluate math in the parenthesis first!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fav0y5iy6glrnt5q2bqxc.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fav0y5iy6glrnt5q2bqxc.gif" alt="Alt Text" width="220" height="140"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What a stud 💪, let's keep going! Clear your console by clicking the little 🚫 icon in the console window.&lt;/p&gt;




&lt;h3&gt;
  
  
  Variables and data types
&lt;/h3&gt;

&lt;p&gt;What's your favorite number? Mine is 7. Let's store our favorite number in our console so we can change it later. Type this in:&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;const&lt;/span&gt; &lt;span class="nx"&gt;favoriteNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="c1"&gt;// Replace 7 with your fav!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our favorite number is special, so we don't want it to be changed in the code later on. To prevent this, we can make the variable a &lt;strong&gt;constant&lt;/strong&gt; by writing &lt;code&gt;const&lt;/code&gt;. If we do want to change it later, we can replace &lt;code&gt;const&lt;/code&gt; with &lt;code&gt;let&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Notice the variable name's format, &lt;code&gt;favoriteNumber&lt;/code&gt;. That's called camel-casing 🐫, where the first word is lowercase, and the rest of the words after it are capitalized - no spaces in between, of course. This is how variable names should be formatted in JS!&lt;/p&gt;

&lt;p&gt;We give &lt;code&gt;favoriteNumber&lt;/code&gt; a value of 7, which is a &lt;code&gt;number&lt;/code&gt;. Variables don't have to be numbers, though. They can be &lt;code&gt;strings&lt;/code&gt; (letters wrapped in &lt;strong&gt;single or double quotes&lt;/strong&gt;), booleans (&lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;), or even &lt;code&gt;undefined&lt;/code&gt; (exactly what you think it is).&lt;/p&gt;

&lt;p&gt;The two slashes followed by words are comments, by the way. Nothing in comments gets run, so it's great for explaining what code does or even writing steamy romances, depending on the mood 🥰.&lt;/p&gt;

&lt;p&gt;Let's say we want to make a list of my favorite pizza toppings (in no particular order.) How would we go about that in JS? Answer: arrays. Let's see one in action:&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;let&lt;/span&gt; &lt;span class="nx"&gt;favoriteToppings&lt;/span&gt; &lt;span class="o"&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;green olives&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;pepperoni&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;onions&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;Do the same with your favorite toppings (list as many as you like!) 🍕&lt;/p&gt;

&lt;p&gt;If we want to access the first element in the array, we can do:&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;// console.log outputs stuff in its () to the console&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;favoriteToppings&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how we type 0 to get the first element - you aren't going insane, counting just starts from zero with programming 🙃&lt;/p&gt;

&lt;p&gt;Cool beans!&lt;/p&gt;




&lt;h3&gt;
  
  
  Conditionals
&lt;/h3&gt;

&lt;p&gt;If we want to find out whether or not your favorite number is between 20 and 30, we can use conditionals. Let's take a 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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;favoriteNumber&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;favoriteNumber&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cm"&gt;/* this code is executed if favoriteNumber is in between 20
       and 30 */&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Your number is in between 20 and 30!&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="nx"&gt;favoriteNumber&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// this code is executed if favoriteNumber is greater than 30&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Your number is greater than 30!&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="cm"&gt;/* this code is executed if favoriteNumber is not in between 20
      and 30 and not greater than 30 */&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Your number is less than 20!&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;We're using &lt;strong&gt;if/else statements&lt;/strong&gt; to check if conditions are met! If our favorite number is less than 30 &lt;strong&gt;and&lt;/strong&gt; our favorite number is greater than 20, let us know! Elsewise, if (&lt;strong&gt;else if&lt;/strong&gt;) our favorite number is greater than 30, let us know. Elsewise (&lt;strong&gt;else&lt;/strong&gt;), our number must be less than 20, so tell us.&lt;/p&gt;

&lt;p&gt;Heck yeah! 😎&lt;/p&gt;




&lt;h3&gt;
  
  
  Looping
&lt;/h3&gt;

&lt;p&gt;There are oodles of ways to loop through things like lists, so we'll focus on the two most essential methods:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For loops&lt;/strong&gt; can iterate through arrays 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="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;topping&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;favoriteToppings&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="nx"&gt;topping&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 saying that for each &lt;em&gt;topping&lt;/em&gt; (we can call this whatever we want, but topping makes the most sense) in our list of favorite toppings, we want to log that topping. Try it with your list of favorite toppings!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;While loops&lt;/strong&gt; will run its code while a condition is met. It won't stop until the condition becomes false or until the world ends! 😁&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="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;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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1 Doge = 1 Doge&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;em&gt;Disclaimer: I highly advise against running the above code, it's an infinite loop and could potentially open a black hole if left to run long enough.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Here, you need a break. Let this lava lamp hypnotize you for a bit.&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4e3g2d0oxfgcw7nwaxap.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4e3g2d0oxfgcw7nwaxap.gif" alt="Woahhhhh" width="480" height="272"&gt;&lt;/a&gt;&lt;br&gt;
Lava lamps are almost as cool as JS, amirite?&lt;/p&gt;


&lt;h3&gt;
  
  
  Functions
&lt;/h3&gt;

&lt;p&gt;Functions are the backbone of Javascript. They allow us to reuse code and clearly label what is what. Let's make a really cool math trick:&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;amazeMe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;favoriteNumber&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;prediction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;answer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;favoriteNumber&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;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="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;favoriteNumber&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Prediction: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;prediction&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Answer: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;answer&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;Go ahead and paste that into your console, then I'll explain what's going on here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First, we &lt;strong&gt;define&lt;/strong&gt; the function by using &lt;code&gt;function&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;We give it a name (&lt;code&gt;amazeMe&lt;/code&gt; in this case)&lt;/li&gt;
&lt;li&gt;We pass in &lt;strong&gt;parameters&lt;/strong&gt; (these are like variables that can only be used inside the function - parameters are optional though, so if you don't need any you can just write empty parenthesis)&lt;/li&gt;
&lt;li&gt;Inside the function, we define our prediction, as well as our magic algorithm&lt;/li&gt;
&lt;li&gt;We log our prediction, then log our answer&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;No matter what our favorite number is, the answer will always be 2! Crazy!&lt;/em&gt; 😮&lt;/p&gt;

&lt;p&gt;We just defined our function, now we can put it to use! Let's &lt;strong&gt;call&lt;/strong&gt; 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="nf"&gt;amazeMe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;favoriteNumber&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we call our function, we &lt;strong&gt;pass in&lt;/strong&gt; our &lt;code&gt;favoriteNumber&lt;/code&gt; variable that we defined a while back. The function now has access to that variable in its code! We can pass in any number though, which would look like 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;amazeMe&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Try it with different numbers; the answer is always 2!&lt;/p&gt;

&lt;h4&gt;
  
  
  Hey, you! You're done! 🎉
&lt;/h4&gt;

&lt;p&gt;If you like Javascript so far, I really recommend you learn some more and maybe build some cool things with it. Stay tuned to this series though; I plan on making more Javascript tutorials in the future!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before you leave, read this:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I'd like to thank you for giving this post a view, it really means a lot to me! Let me know how I'm doing in the comments, or leave a like, follow, or an infamous Unicorn if you really liked it 🦄&lt;/li&gt;
&lt;li&gt;Like I said, stay tuned because there are a lot more articles coming for every type of programmer!&lt;/li&gt;
&lt;li&gt;Never stop learning, never stop practicing. There's always something you can do to improve, so get out there and keep going! I believe in you 😇&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Practice Resources:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://youtube.com/playlist?list=PL4cUxeGkcC9haFPT7J25Q9GRB_ZkFrQAc"&gt;Modern JavaScript Tutorial&lt;/a&gt; is a great playlist made by my hero, The Net Ninja. If you're into Javascript, check it out!&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.jschallenger.com/"&gt;JSChallenger&lt;/a&gt; gives awesome challenges for you to practice and expand upon your JS skillz!&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript"&gt;MDN Web Docs&lt;/a&gt; is great for looking up random Javascript things if you're in a pinch; it's like the JS dictionary!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once again, thanks for reading - I hope you loved it! Bye! 🙋‍♂️&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Python, ASAP 🐍</title>
      <dc:creator>Brice Duke</dc:creator>
      <pubDate>Sun, 18 Apr 2021 15:44:06 +0000</pubDate>
      <link>https://forem.com/briceduke/python-asap-2bea</link>
      <guid>https://forem.com/briceduke/python-asap-2bea</guid>
      <description>&lt;p&gt;Hello there! I've been a DEV reader for a long time, but just recently I decided to make an account and maybe start posting. I want to share what I know with everyone, and even if I'm able to help one person, that'd be amazing.&lt;/p&gt;

&lt;p&gt;I've decided to start writing bite-sized articles that will provide you a crash course on the concept. I thought that if I start with the easier languages and concepts and move to more advanced ones, beginners could follow along with me!&lt;/p&gt;

&lt;p&gt;This specific article will be targeted towards complete beginners, as I will be going over basic programming concepts; more advanced programmers are certainly welcome to peruse, though!&lt;/p&gt;

&lt;h3&gt;
  
  
  So without further ado, I give you Python, as Soon as Possible!
&lt;/h3&gt;

&lt;p&gt;Let's start by clearing something up:&lt;/p&gt;

&lt;h4&gt;
  
  
  Programming is just a set of rules!
&lt;/h4&gt;

&lt;p&gt;All you're doing is telling a computer to do something, don't overthink it! You give it data and tell it what to do in what circumstances and it obediently does the work. That's all. It may be slightly different in different languages, but the concepts are the same. Alright, now that's off my chest, so here we go:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Let's look at operators&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;The math things!&lt;/p&gt;

&lt;p&gt;operators are "special symbols in Python that carry out arithmetic or logical computation."&lt;/p&gt;

&lt;p&gt;Here is a list of operators:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;+&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt;, and &lt;code&gt;/&lt;/code&gt; are self-explanatory&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;//&lt;/code&gt; divides and rounds down (e.g. &lt;code&gt;7 // 4&lt;/code&gt; will return &lt;code&gt;1&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;%&lt;/code&gt; is the modulo operation, which is the remainder of a division (e.g. &lt;code&gt;7 % 4&lt;/code&gt; will return &lt;code&gt;3&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;**&lt;/code&gt; represents exponents (e.g. &lt;code&gt;7**2&lt;/code&gt; will return &lt;code&gt;49&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;==&lt;/code&gt; will compare two things and return &lt;code&gt;True&lt;/code&gt; if they're equivalent (e.g. &lt;code&gt;7 == 4&lt;/code&gt; returns &lt;code&gt;False&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;!=&lt;/code&gt; will compare two things and return &lt;code&gt;True&lt;/code&gt; if they're not equivalent (e.g. &lt;code&gt;7 != 4&lt;/code&gt; returns &lt;code&gt;True&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;&lt;/code&gt; compare two things to see if they're greater or less than (&lt;code&gt;7 &amp;gt; 4&lt;/code&gt; returns &lt;code&gt;True&lt;/code&gt;, and &lt;code&gt;7 &amp;lt; 4&lt;/code&gt; returns &lt;code&gt;False&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;gt;=&lt;/code&gt; and &lt;code&gt;&amp;lt;=&lt;/code&gt; are greater/less than OR equal to (&lt;code&gt;7 &amp;gt;= 7&lt;/code&gt; is &lt;code&gt;True&lt;/code&gt;, &lt;code&gt;4 &amp;lt;= 7&lt;/code&gt; is also &lt;code&gt;True&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These also follow "order of operations" (think PEMDAS, students), so do be careful. In order to prioritize a certain part of your math operation, you can surround that part in parenthesis (e.g. &lt;code&gt;(1 + 2) * 3&lt;/code&gt; will add the two numbers first and then multiply the sum)&lt;/p&gt;

&lt;p&gt;Alright, enough math (for now 😉).&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Variables and data types&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;If we want to store something for later, we can assign it to a variable. Let's look at an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Snek&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We just made a variable called &lt;code&gt;name&lt;/code&gt; and gave it a value of Snek (by the way, words and letters are represented as &lt;strong&gt;strings&lt;/strong&gt; and can be in &lt;strong&gt;double quotes or single quotes&lt;/strong&gt;). We can now access &lt;code&gt;name&lt;/code&gt; later in our code.&lt;/p&gt;

&lt;p&gt;A benefit of this is that if we need to access &lt;code&gt;name&lt;/code&gt; multiple times, we'll only need to change its value (Snek) once 😎&lt;/p&gt;

&lt;p&gt;The best part is, variables don't even only have to be strings, they can be numbers, &lt;strong&gt;floats&lt;/strong&gt; (these are just decimals like 3.14), &lt;strong&gt;booleans&lt;/strong&gt; (these are just &lt;code&gt;True&lt;/code&gt; or &lt;code&gt;False&lt;/code&gt;, be sure to capitalize these!), or &lt;strong&gt;lists&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;What's a list, you say? Well, it's in the name. Lists are a way of storing multiple values. Let's say we need to store our favorite drinks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;favorite_drinks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;coffee&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;more coffee&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;wHoLe MiLk&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just add brackets and separate by a comma!&lt;/p&gt;

&lt;p&gt;If we want to look at items in a list, we can do so by accessing its &lt;strong&gt;index&lt;/strong&gt;. We'll use the &lt;code&gt;favorite_drinks&lt;/code&gt; example to illustrate this. Let's display "more coffee" from the list.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;favorite_drinks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;coffee&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;more coffee&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;wHoLe MiLk&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;favorite_drinks&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;"Woah, Brice! You told it to access 1, but it got the second item on the list! What's up with that?" Yeah, programmers decided to break all known laws of sanity and &lt;strong&gt;made counting start at zero&lt;/strong&gt;. The 0th position in &lt;code&gt;favorite_drinks&lt;/code&gt; would be "coffee"!&lt;/p&gt;

&lt;p&gt;We also saw a new thing called &lt;code&gt;print&lt;/code&gt; in that example. &lt;code&gt;print&lt;/code&gt; will take everything in its parenthesis (they can be variables like &lt;code&gt;name&lt;/code&gt;, data types, and more stuff we'll learn later) and display it for us!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;One thing to note:&lt;/em&gt; variable names in Python can only start with a letter or underscore, and typically multi-word names are separated by an underscore (e.g. &lt;code&gt;awesome_name&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;Easy enough, right?&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Conditionals&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;If we only want something to happen in certain circumstances, we can use &lt;strong&gt;conditionals&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let's say we want to print "caffeine addict" ONLY IF the first element in the list is "coffee":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;favorite_drinks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;coffee&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;more coffee&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;wHoLe MiLk&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;favorite_drinks&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;coffee&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
   &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;caffeine addict&lt;/span&gt;&lt;span class="sh"&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 would of course print caffeine addict because the first element (remember, it's in the 0th position) is in fact coffee!&lt;/p&gt;

&lt;p&gt;Let's look at an example and see if you can figure out what's going on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;favorite_drinks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;coffee&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;more coffee&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;wHoLe MiLk&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;favorite_drinks&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;more coffee&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
   &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;caffeine addict&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;favorite_drinks&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;coffee&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
   &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;slight caffeine addict&lt;/span&gt;&lt;span class="sh"&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="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;not a caffeine addict&lt;/span&gt;&lt;span class="sh"&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 it is in English: if the first element of favorite_drinks is more coffee, print "caffeine addict". Elsewise, if (&lt;strong&gt;elif&lt;/strong&gt;) the 0th element is coffee, print "slight caffeine addict". Elsewise (&lt;strong&gt;else&lt;/strong&gt;) print "not a caffeine addict".&lt;/p&gt;

&lt;p&gt;Cool! 👍&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Looping&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;There are a few ways we can loop through things like lists.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Loops&lt;/strong&gt; will loop through a specific amount that we define at the beginning of the loop. Let's look at two examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;favorite_drinks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;coffee&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;more coffee&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;wHoLe MiLk&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;drink&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;favorite_drinks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
   &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;drink&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Here, we will have access to each &lt;code&gt;drink&lt;/code&gt; in our list (we called it a &lt;code&gt;drink&lt;/code&gt; in the for loop) and we will print each drink.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We define the name of each element at the beginning of the for loop. This is perfectly valid:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;favorite_drink&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
   &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;This will still print each element in the list, even though the element is technically called &lt;code&gt;i&lt;/code&gt; (short for index)... You can name this whatever you want!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For loops can also be ranges. Let's say we wanted to print "wassup" 5 times:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&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="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;wassup&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Easy peasy, we just supply a range (5 is the range in this case) and it loops through the code 5 times! 😮&lt;/p&gt;

&lt;p&gt;Let's look at &lt;strong&gt;While Loops&lt;/strong&gt;! These will run while a condition is met, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;while&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;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
   &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Math is not broken&lt;/span&gt;&lt;span class="sh"&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 will print "Math is not broken" infinitely. Watch out though, even if math isn't broken, that infinite loop could break your computer... 💔&lt;/p&gt;

&lt;h3&gt;
  
  
  Whew, that's a lot! Keep this fireplace on your screen while you get a snack or stretch.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fagc84n2jn8by9rzvtmwb.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fagc84n2jn8by9rzvtmwb.gif" alt="cozy af fireplace" width="400" height="225"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Alrighty, back to the fun!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Exceptions&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;If we want to handle any errors that occur, we can use an exception. It's pretty easy, have a look:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;favorite_numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&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="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
   &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;favorite_numbers&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="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;IndexError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
   &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Item is not in the list!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See what I did there? All I did was tell it to try and find the 5th element in the &lt;code&gt;favorite_numbers&lt;/code&gt; array (which obviously doesn't exist 😋). I then told it to catch any index errors via an exception, and tell the user that the item isn't in the list! Wow!&lt;/p&gt;

&lt;p&gt;Okay, all of this stuff is nice, but how can I reuse it?&lt;/p&gt;

&lt;p&gt;Well, dear reader, I give you &lt;strong&gt;functions&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a&gt;Functions&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;What do they do? They represent a function (amazing right?). Let's take a look:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;print_a_word&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
   &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;a word&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;We start off by &lt;strong&gt;defining&lt;/strong&gt; the function (&lt;em&gt;def&lt;/em&gt;), then we give it a name (like variables, function names can start with letters and underscores and typically use underscores to separate words). The parenthesis at the end will come in handy later. 🕑&lt;br&gt;
Then we tell the function what to do (in this case we tell it to print "a word")&lt;br&gt;
Finally, we "call" the function (we had defined it but now we're putting it to use) by writing the function name and the parenthesis after it.&lt;/p&gt;

&lt;p&gt;Cool, but what if we want to pass in different things, similar to variables? Answer: &lt;strong&gt;parameters&lt;/strong&gt;.&lt;br&gt;
Allow me to shed some light 💡 on the subject:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;print_a_word&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
   &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print_a_word&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Borborygm&lt;/span&gt;&lt;span class="sh"&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 passing a parameter called &lt;code&gt;word&lt;/code&gt; into the function definition. This will allow us to use whatever the user passes in later throughout the function. When we go to call the function, we pass in "Borborygm" as the word, thus making the function print Borborygm. I could do this too:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;print_a_word&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
   &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print_a_word&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Borborygm&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print_a_word&lt;/span&gt;&lt;span class="p"&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;p&gt;This would print Borborygm, then 3.14 on the line below it, since we changed the parameter and called the function again!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;code&gt;In case you were wondering, Borborygm is a much better word (imo) for "stomach growling"&lt;/code&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Guess what? You've learned the absolute basics of Python (and programming for that matter) as soon as possible!!! 🎉
&lt;/h4&gt;

&lt;p&gt;Before you go, I have a few things to say:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Thank you for reading this, it really makes my day! I really would love to hear your feedback, positive or negative, via comments, likes, a follow, Unicorns (what are those, they sound cool! 🦄), or even DMs!&lt;/li&gt;
&lt;li&gt;I'll be pushing more programming language tutorials like this one, but stepping up to more challenging languages. I'll also be adding onto current languages by making more advanced tutorials (Python Pt. 2?)&lt;/li&gt;
&lt;li&gt;Practice Practice Practice! Good programmers practice until they get it right, but &lt;em&gt;great&lt;/em&gt; programmers practice until they can't get it wrong! I'll list some practice resources below 😊&lt;/li&gt;
&lt;li&gt;This is just a &lt;em&gt;basic&lt;/em&gt; introduction to Python and programming. We aren't even scratching the surface, but if this made you have even an inkling of interest in programming, I highly recommend you go further into Python. I'll be adding more Python tutorials soon though 😁&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Practice Resources:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.programiz.com/python-programming/online-compiler/"&gt;Programiz&lt;/a&gt;, a website where you can practice writing Python (they have a dark mode which is sick)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/watch?v=kqtD5dpn9C8"&gt;Python Tutorial for Beginners&lt;/a&gt;, a 1 hour long Python crash course on YouTube where you'll learn more about the language&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://edabit.com/challenges/python3"&gt;Edabit&lt;/a&gt;, a cool platform where you can practice Python by doing nifty challenges&lt;/li&gt;
&lt;li&gt;I have my own challenge for you. Write a &lt;strong&gt;function&lt;/strong&gt; that takes in someone's favorite snack as a &lt;strong&gt;parameter&lt;/strong&gt; and prints "My favorite snack is ____". Send your answer in the comments and don't cheat by looking at other answers (we're on the honor system here). &lt;em&gt;Note: I didn't teach you how to insert variables into strings, so you'll have to do some digging! Don't worry though, if you aren't able to find a good answer within a reasonable amount of time then please shoot me an SOS in the comments and I'll be glad to help!&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hope y'all enjoyed it; catch you later! 👋&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
