<?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: informathemusic</title>
    <description>The latest articles on DEV Community by informathemusic (@informathemusic).</description>
    <link>https://dev.to/informathemusic</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%2F245540%2Fde09adf8-80d0-4dde-be3d-1288d07db713.png</url>
      <title>DEV Community: informathemusic</title>
      <link>https://dev.to/informathemusic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/informathemusic"/>
    <language>en</language>
    <item>
      <title>Keep calm and Learn Javascript!</title>
      <dc:creator>informathemusic</dc:creator>
      <pubDate>Wed, 09 Oct 2019 11:16:25 +0000</pubDate>
      <link>https://dev.to/informathemusic/keep-calm-and-learn-javascript-1m69</link>
      <guid>https://dev.to/informathemusic/keep-calm-and-learn-javascript-1m69</guid>
      <description>&lt;p&gt;There are many reasons to know javascript:&lt;br&gt;
-Make a &lt;a href="https://dev.to/thomasbnt/create-your-own-bot-discord-2hco"&gt;discord bot&lt;/a&gt;&lt;br&gt;
-Make your &lt;a href="https://dev.to/jochemstoel/bundle-your-node-app-to-a-single-executable-for-windows-linux-and-osx-2c89"&gt;first executable&lt;/a&gt;&lt;br&gt;
&lt;del&gt;-Look cool with your &lt;a href="https://dev.to/gnsp/making-the-matrix-effect-in-javascript-din"&gt;matrix-like node.js script&lt;/a&gt;&lt;/del&gt;&lt;br&gt;
-Create &lt;a href="https://dev.to/inspiratory/creating-a-book-cover-using-javascript-and-p5js"&gt;beautiful animations&lt;/a&gt;&lt;br&gt;
-Etc,etc,etc...&lt;/p&gt;

&lt;p&gt;And there is also a secret reason: I hate people that show me their dumb errors (Unexpected token "}" at line 5 character 11) and then says: "I don't understand this error, fix this for me". It's okay for the first time, but not the second.&lt;/p&gt;

&lt;p&gt;We're using node js, &lt;a href="https://dev.to/bettercodingacademy/here-s-how-to-install-node-js-in-under-5-minutes-3igi"&gt;see this for help&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'm going to start with the beginning,&lt;/p&gt;
&lt;h1&gt;
  
  
  0. The setup
&lt;/h1&gt;

&lt;p&gt;Firstly, create a file called "script.js" in a folder newly created (I guess). Of course, you can change "script" to anything you want&lt;/p&gt;

&lt;p&gt;Then, run this command in the folder:&lt;br&gt;
&lt;code&gt;npm init&lt;/code&gt;&lt;br&gt;
and answer.&lt;/p&gt;

&lt;p&gt;Note: Every change is applied to script.js  &lt;/p&gt;

&lt;p&gt;Done!&lt;/p&gt;
&lt;h1&gt;
  
  
  1. Script output
&lt;/h1&gt;

&lt;p&gt;To output a string in a script, you can type: &lt;code&gt;console.log("String");&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then run &lt;br&gt;
&lt;code&gt;node script.js&lt;/code&gt; &lt;br&gt;
and you get your very first output!&lt;/p&gt;
&lt;h1&gt;
  
  
  2. Variables
&lt;/h1&gt;

&lt;p&gt;I'm taking an example: hp in Minecraft&lt;br&gt;
I get 20 hearts at the beginning&lt;br&gt;
I'm falling from a mountain; I'm losing 4 hearts.&lt;br&gt;
I'm drinking a healing potion; I'm getting 4 hearts more.&lt;br&gt;
No! A skeleton! I lost 1 heart.&lt;/p&gt;

&lt;p&gt;To initialize a variable, you can use &lt;strong&gt;var&lt;/strong&gt; or &lt;strong&gt;let&lt;/strong&gt;; I prefer &lt;strong&gt;let&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here's our 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;let&lt;/span&gt; &lt;span class="nx"&gt;hp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//Hey! I'm a comment! NodeJS doesn't care about me but the code reader does!&lt;/span&gt;
&lt;span class="cm"&gt;/*Also this is
a multiline
comment!*/&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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;I have &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;hp&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; hp!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;//OOF&lt;/span&gt;
&lt;span class="nx"&gt;hp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nx"&gt;hp&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;//hp=20-4&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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;I now have &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;hp&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; hp!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;hp&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;//This is included in the js syntax&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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;I now have &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;hp&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; hp!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;hp&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;//This is also an integrated syntax&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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;I now have &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;hp&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; hp!&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;h1&gt;
  
  
  3. Functions
&lt;/h1&gt;

&lt;p&gt;Do you remember our messy code?&lt;br&gt;
Well, I'm gonna pimp that up!&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;hp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;addRemoveHp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="nx"&gt;hp&lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="nx"&gt;val&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="nx"&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;I now have &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="nx"&gt;hp&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; hp!&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="nx"&gt;addRemoveHp&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="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;addRemoveHp&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;addRemoveHp&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;blockquote&gt;
&lt;p&gt;Gosh, it's working! But  what the hell is "function addRemoveHp(val){[...]}"???&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Welcome to the fabulous world of functions!&lt;/p&gt;

&lt;p&gt;A function is formatted like this:&lt;br&gt;
&lt;code&gt;function NAME(ARG1, ARG2, ARG3, [...], ARG_N){/*You get your code here*/}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can replace NAME, ARG1, ARG2, ARG3, ARG_N ant the multiline comment with whatever you want, like&lt;br&gt;
&lt;code&gt;function sayHp(hp){console.log("You now have"+hp+"hp!");}&lt;/code&gt;&lt;br&gt;
or&lt;br&gt;
&lt;code&gt;function addHp(){hp++;}&lt;/code&gt;&lt;br&gt;
or&lt;br&gt;
&lt;code&gt;function removeHp(){hp--;}&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  4. Conditions
&lt;/h1&gt;

&lt;p&gt;It's coming...&lt;/p&gt;

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