<?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: klofnod</title>
    <description>The latest articles on DEV Community by klofnod (@klofnod).</description>
    <link>https://dev.to/klofnod</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F893972%2Faef9d907-d69d-4312-91c8-9eb86ca49c04.jpg</url>
      <title>DEV Community: klofnod</title>
      <link>https://dev.to/klofnod</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/klofnod"/>
    <language>en</language>
    <item>
      <title>Adding Unique Outcomes With Random Numbers</title>
      <dc:creator>klofnod</dc:creator>
      <pubDate>Mon, 12 Sep 2022 14:54:46 +0000</pubDate>
      <link>https://dev.to/klofnod/adding-unique-outcomes-with-random-numbers-2o97</link>
      <guid>https://dev.to/klofnod/adding-unique-outcomes-with-random-numbers-2o97</guid>
      <description>&lt;h2&gt;
  
  
  The Idea
&lt;/h2&gt;

&lt;p&gt;I decided to create a rogue-like text based adventure game for my final capstone project while I was in Flatiron. It was a ton of fun, and a good learning experience. I was challenged to find ways to keep elements randomized but not to the point that the game would be impossible. It helped me grow my understanding and ability in Ruby as well as React.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;Most coding languages have a nice and easy way to create a random number upon being called. This is a great start but has some issues. One is if you want a progression system you will have to tweak your formula in order to things relevant to your progression. There are many different approaches to this problem. Here I am going to show how I tackled this issue.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Set Up
&lt;/h2&gt;

&lt;p&gt;In my game I was allowing a user to create a character, I wanted their starting stats to be randomized but within a range. Ruby makes this super easy.&lt;br&gt;
&lt;code&gt;rand(3..8)&lt;br&gt;
 rand(3...8)&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Both of these methods allow us to create a random number within the range specified. The difference between them are .. runs from the beginning to the end inclusively where as ...  excludes the end value. This is an easy solve and doesn't require and additional logic to be checked.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Challenge
&lt;/h2&gt;

&lt;p&gt;Now I wanted to be able to present that character with a encounter and an enemy to fight. This is where it gets a bit tricky but not crazy. For the encounter I set a Round to be incremented and then checked, with a simple case statement. When the round was 1..3 I would select from a sorted array of encounters by index, and then just repeated that till round 12. For the enemy spawn It was basically the same thing. Sort enemies by power and then select weaker enemies when the round was low and stronger enemies when the round was higher.&lt;/p&gt;

&lt;h2&gt;
  
  
  Loot
&lt;/h2&gt;

&lt;p&gt;What would the game be without loot? Now I wanted to create a chest system that would reward completed encounters with loot. I was able to solve this using most of the same logic from my encounter and enemy logic so that was a nice moment. When could you wrote before was reusable for another function with just some minor modifications. The game itself is linked in linkedin profile which can be found at jeremy-francis-klofnod on linkedin. Feel free to reach out and ask and questions or comments you have about the project&lt;/p&gt;

</description>
      <category>rails</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A Bit About Me</title>
      <dc:creator>klofnod</dc:creator>
      <pubDate>Tue, 19 Jul 2022 16:58:21 +0000</pubDate>
      <link>https://dev.to/klofnod/a-bit-about-me-n9g</link>
      <guid>https://dev.to/klofnod/a-bit-about-me-n9g</guid>
      <description>&lt;h2&gt;
  
  
  My Journey Before Starting Boot Camp
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zVDJvj0i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.pexels.com/photos/732550/pexels-photo-732550.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zVDJvj0i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.pexels.com/photos/732550/pexels-photo-732550.jpeg" alt="pic of prairies" width="880" height="587"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
   I was born in a small town of Weyburn Saskatchewan and moved to B.C when I was 4 years old because my dad had got a job there. While living in B.C my dad made friends with a mechanic named Eric. He helped my dad out with looking after our vehicles and was a very friendly guy. When I was 9 he would start to teach me about cars and how they worked and how to fix them. I fell in love with the intricacies of engines and other vehicle systems. As I grew older Eric would continue to teach me and spark my interest in learning more about cars. Anytime he would come over to work on our cars I would always be out there helping him. He then asked my dad if it was ok for me to work some side jobs with him and help him out and in exchange he would pay me and I would get to learn more, win win for everybody. My dad had no problem with it so I started to go with Eric on the weekends and fix cars with him. In mechanics there are times that a car computer fails or needs to be reprogrammed in order to work, this was an area that Eric did not have a ton of depth in but he would still do his best to explain to me. I found it very fascinating but felt like if Eric couldn’t fully understand it I would never be able to.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Building My Automotive Career
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--q9rJir28--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.pexels.com/photos/4489765/pexels-photo-4489765.jpeg%3Fauto%3Dcompress%26cs%3Dtinysrgb%26w%3D1260%26h%3D750%26dpr%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q9rJir28--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.pexels.com/photos/4489765/pexels-photo-4489765.jpeg%3Fauto%3Dcompress%26cs%3Dtinysrgb%26w%3D1260%26h%3D750%26dpr%3D1" alt="pic of mechanic" width="500" height="750"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
   My high school did offer a computer science course but at that time I felt like there was no way that I could learn it or be proficient in it. You make a career plan in high school and as I already had some experience in working on cars, I thought it would only be natural to move into it as a career. Right out of high school I took my first year of automotive at our local community college, after I graded I began looking for a job. I was first hired at a dodge dealership but they were only looking for a seasonal guy so after 3 months I was laid off. A friend from my automotive class was working at Kal-Tire at the time and offered to get me a job there, I happily accepted his offer and spent the next 3 years there.  During that time my jobs mainly focused around brakes, suspension jobs and general maintenance. I took my second year of automotive school during that time as well. I was a hard worker and dedicated to learning everything I could and I ended up catching the attention of a local engine rebuilding shop in town. They offer me a job at their shop helping them rebuild classic cars and fixing more complicated issues then I was being challenged with at Kal. I accepted their offer and said good bye to the team I was working with at Kal, they were sad to see me go but understood that the position I was going to was much better for my continued growth. During my time at the rebuild shop I would run into some more car computer issues, this further peaked my interest into programming but again felt it was way to over my head to even begin digging into. At the shop I ended up completing my third year of automotive so I only had one more year to go before I could challenge the red seal test and become a journey man. While I was in third year I entered a schooling competition which I ended going all the way to finals and winning. This was a huge boost to my confidence within mechanics and also brought me to the attention of some shops in my town. When I returned from school the engine rebuild shop had slowed down and there was not enough work to keep all the mechanics busy, being the newest guy I was laid off. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Main Life Experience
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AhbLvb23--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.pexels.com/photos/162553/keys-workshop-mechanic-tools-162553.jpeg%3Fauto%3Dcompress%26cs%3Dtinysrgb%26w%3D1260%26h%3D750%26dpr%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AhbLvb23--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.pexels.com/photos/162553/keys-workshop-mechanic-tools-162553.jpeg%3Fauto%3Dcompress%26cs%3Dtinysrgb%26w%3D1260%26h%3D750%26dpr%3D1" alt="pic of wrenches" width="880" height="587"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
   Being laid off was not the end of the world though because after winning the competition I was already offered a few job within my town and even some in other cities. I ended up accepting a job at a local shop that had been in business in my town for a very long time and was always owned by the same family. They were excited to have me onboard and very much enjoyed my work ethic and drive for more knowledge, they set me up with any extra work shop class I wanted to attend. They also wanted me to complete my fourth year as soon as possible, so I headed back for my final year and passed my red seal test and was now a full fledged journey man mechanic. When I returned to the shop, I continued to grow my knowledge and grasp more and more concepts within automotive. As time went on the head mechanic ended up leaving the shop and I took over his position. Now I had apprentices learning from me, it was a crazy feeling because I still felt like I had so much to learn and that I did not have enough knowledge in my head to teach anyone. They were super happy though and always said that my teaching style plus knowledge was helpful and sound. It was at this time that I started to get more computer issues. Most times it was removing the computer to be replaced or sent to the dealership to be reprogrammed, I grew a relationship with one of the dealerships and started to learn about the reprogramming side of repairs. In the shop its pretty simple as you mainly just hook it up to a computer which handles updating the software to the newest version. Most of the guys at the dealership were fine with that being all they needed to know. I however wanted to know more, for example why would they need to update the software wouldn’t they test all these thing before and why are they not thinking about colder climates when programming the computer. Questions like these kept me up at night I wanted to understand why but again was afraid of being overwhelmed or taking space in my brain away from automotive knowledge which at the end of the day was what I really need to know.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The First Taste Of Coding
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XWJ_0IX7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.pexels.com/photos/9510438/pexels-photo-9510438.jpeg%3Fauto%3Dcompress%26cs%3Dtinysrgb%26w%3D1260%26h%3D750%26dpr%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XWJ_0IX7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.pexels.com/photos/9510438/pexels-photo-9510438.jpeg%3Fauto%3Dcompress%26cs%3Dtinysrgb%26w%3D1260%26h%3D750%26dpr%3D1" alt="looking through hole in fence" width="484" height="750"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
   During my time at the local shop I also took in side jobs. One of my customers was a software engineer, he was always interested in learning like me. Anytime I would do a job for him he would always ask if it was ok for him to come watch what I was doing to see if he could learn something. I happily obliged and always tried my best to explain what I was doing and how it worked, he was always thankful and said he wanted to return the favor. He said I will teach you about coding and I honestly laughed and told him “I am a mechanic, there is no way my brain will be able to comprehend anything you teach me on that computer. I would love to learn but I think you might be wasting your time trying to teach me“ He did not accept this answer and told me that he had no background in anything mechanical but with my teaching felt like he could change his own tires and do his own brakes now and that the same would be true for me learning coding. He started with just basics, but surprisingly things started to click. As I learnt about this world I once thought was way over my head I started to realize it actually might be something I could comprehend. My knowledge was still very base level but the more I learned the more my passion for coding took over. I decided that if I was going to make a change that now was the time to do it so at 30 years old I decided to take a coding boot camp.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  8 Weeks Into Boot Camp
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5uItnc8H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.pexels.com/photos/177598/pexels-photo-177598.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5uItnc8H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://images.pexels.com/photos/177598/pexels-photo-177598.jpeg" alt="pic of comp screen" width="880" height="587"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
   I decided to take the chance and plunged into Flatirons software engineering online boot camp. It has been an intense journey with a lot of knowledge coming at you. Filled with lots of head scratching and then eureka moments after solving a problem. The teachers and staff are very friendly and accommodating, and really feel like they want you to learn and succeed. They have a great community as well and really try and foster a group feel in the classes. I am only 8 weeks into the program now but have already learned a great deal and am excited to continue on this path of knowledge growth on a subject I never felt like I would understand. I will write another Blog on my full experience once I have completed the program, but I hope that hearing this story might inspire others to challenge themselves to either grow their knowledge on subjects they know or to even expand into something they may have felt was impossible for them to learn before.
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>discuss</category>
      <category>community</category>
      <category>devjournal</category>
      <category>motivation</category>
    </item>
    <item>
      <title>Scope</title>
      <dc:creator>klofnod</dc:creator>
      <pubDate>Tue, 19 Jul 2022 14:29:08 +0000</pubDate>
      <link>https://dev.to/klofnod/scope-3gi8</link>
      <guid>https://dev.to/klofnod/scope-3gi8</guid>
      <description>&lt;ul&gt;
&lt;li&gt;
      This post is mainly about scope in vanilla JavaScript and different ways it can be used to our advantage. There are a lot of ways to look at scope to try and better understand it, my brain always goes to the analogy that if your app is a car then scope is the various compartments within the vehicle. Global scope is the interior of your car, from there you can open your hood and trunk but you do so with a “function” because you are in global scope. Your trunk is like block chain only accessible within itself (unless your rear seats fold down to give access to the trunk like naming a variable var within a block but for my example I am not referencing a car like that or naming a variable var within my block) you can pack as much as you want into your trunk but if you want access to it inside your interior you will have to pull it out of the trunk and put it into global. Your engine compartment is like function scope it is also self contained but there are many systems working with each other and handing down info to child subsystems to allow everything to work.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Global Scope
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
      Global scope can be used pretty safely within smaller app but as your app builds in size declaring variables within a global scope can lead to lots of debugging and headaches later down the line. It is best practice if you can to declare variables within the scope of where they will be used to avoid over writing their value or accessing the wrong variable with a function. Back to my example from above if you think about the inside of your car while you are sitting in the drivers seat you have access to the whole car you can reach over and open your glove box you can use your hood and trunk release and it is all within an arms reach which is really nice. You can not however pull something out of your engine compartment or from your trunk from the drivers seat, but you can affect those compartments from your drivers seat.
&lt;/li&gt;
&lt;/ul&gt;

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

//example 1

const varible1= "Hello world"

function showInConsoleLog(){
 console.log(varible1)
}

showInConsoleLog()

excepted return in console
console Hello World


//example 2 

const firstNumber = 2
const secondNumber = 4

function addNumberTogether(){
const numbersAddedTogether = (firstNumber + secondNumber)
console.log(numbersAddedTogether)
}

addNumberTogether()

excepted return in console
console 6


//example 3

const firstNumber = 2
const secondNumber = 4

function addNumberTogether(){
const numbersAddedTogether = (firstNumber + secondNumber)
}

/* 
This will not show up in console even though the function is invoked and the numbers are added together.
vvv The value of numbersAddedTogether is not declared Globally, so it cannot be seen by the console.log() which is in global scope. 
*/

console.log(numbersAddedTogether)

addNumberTogether()

excepted return in console
ReferenceError: numbersAddedTogether is not defined
}

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Block Scope
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
      Block scope and function scope are closely related but do have some differences. Function scope can be passed an argument when invoked and then can use the invoked argument within its scope. Block scope will cut off anything from the outside being able to access what is between the curly braces, it is useful if you have specific variables you only want to access within the block scope or to have two variables with the same name with different values available to the app depending on how the code resolves. This is again not true if your variable is declared with var instead of let or const. Block scope is useful for creating Block statements, which allows your code to use and or resolve multiple statements in places where javascript excepts only one statement. An example of that is if statements and for statements where we can name a variable to be referenced for a check, but not have access to that variable outside of that statement. Example 3 in global scope shows off block scope, as well as the example below
&lt;/li&gt;
&lt;/ul&gt;

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

//example 1

function increaseNumber() {
  for (let x = 0; x &amp;lt; 5; x++) {
    console.log(x)
  } 
}
increaseNumber()

excepted return in console
console 0
console 1
console 2
console 3
console 4


//example 2

function increaseNumber() {
  for (let x = 0; x &amp;lt; 5; x++) {
  } 

/*
This will not show up in console even though x is being increased and the code does know that, 
vvv x is not defined in within scope of the console log so it can not reference it vvv
*/
   console.log(x)
}
increaseNumber()

excepted return in console
ReferenceError: x is not defined

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Function Scope
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
     Function scope is a little bit more tricky then global and block scope. Function scope back to my analogy is like your cars engine compartment. Think of your dashboard it gives you a read out of what is happening inside your engine compartment, this is similar to returning in a function declared in global scope. It is allowing the results of the function to be viewed from outside the function, but that doesn’t mean you have access to the sensors interior variables only its result.  There is more info though from the engine compartment that you do not have access to from your dash, this is similar to a function declared within a function you can not directly see the results on your dash. Even though that info might be critical to making sure your car is working it does not need to be viewed by you(Global scope). Now lets talk about your gas pedal, its a function that is declared in global scope but can effect the engine. This is similar to using the argument passed into a function to use variables declared within a function scope with that global function. When the function is invoked within another scope is can access the data within that scope if it is passed the data as the argument while invoking. To put this back to the analogy when you push you gas pedal you are telling your car you want to go faster, it then takes that function and passes it to the engine. The engine will then decide by running that function with some other data as the argument if that is possible to do. So your function(gas pedal) actually has access to data that is well within another function scope(engine compartment) as long as when the function (gas pedal) is invoked within another function scope (engine compartment) it is passed the data as an argument. There are some issue with this analogy if you really break it down but hopefully this brief overview helped someone understand scope a little better.
&lt;/li&gt;
&lt;/ul&gt;

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

//example 1

function getNameFromFunctionScope(name){
    console.log(name)
}

function createFirstNameToRetrieve(){
   const firstName = 'John'

   const middleName = firstName + ' Paper'

   const lastName =middleName + ' Smith'

   getNameFromFunctionScope(lastName)

}

createFirstNameToRetrieve()

excepted return in console 
console John Paper Smith

/*
^^^ In this example even though the console.log() is in a separate scope lastName is available to it because, ^^^
it is invoked within the scope of lastName with lastName as an argument.
That argument is referenced as a parameter in the function and then console logged 
*/


//example 2

function getNameFromFunctionScope(name){
    console.log(name)
}

  function createFirstNameToRetrieve(){
    const firstName = 'John'

       const middleName = firstName + ' Paper'

         const lastName =middleName + ' Smith'

         getNameFromFunctionScope(middleName)


  }

createFirstNameToRetrieve()

excepted return in console 
console John Paper 

/* 
Similar to the above example. This is to show that even though the function creates a full name 
we can access the variables separately, if we use that varible as the parameter when we invoke our function.
*/




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

&lt;/div&gt;



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