<?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: Asher Scott</title>
    <description>The latest articles on DEV Community by Asher Scott (@asherscott).</description>
    <link>https://dev.to/asherscott</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%2F831850%2F194aec78-7476-4721-b363-f8b6e2966af0.png</url>
      <title>DEV Community: Asher Scott</title>
      <link>https://dev.to/asherscott</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/asherscott"/>
    <language>en</language>
    <item>
      <title>My last week at Flatiron</title>
      <dc:creator>Asher Scott</dc:creator>
      <pubDate>Mon, 30 May 2022 19:29:03 +0000</pubDate>
      <link>https://dev.to/asherscott/my-last-week-at-flatiron-24im</link>
      <guid>https://dev.to/asherscott/my-last-week-at-flatiron-24im</guid>
      <description>&lt;p&gt;For the past 14 weeks, I've have been attending a 15 week, full-time online bootcamp at Flatiron School for Software Engineering. While it isn't quite over just yet, I think now is a good time to reflect on my experience and share it with anyone who might be thinking about taking that next big step; plus I still need to write one more blog post to graduate. :)&lt;/p&gt;

&lt;p&gt;The Live program, which is the full-time program that I chose; consists of five phases. Each phase is three weeks long. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;First is learning week, during this week, you'll spend your time reading, working on lessons, attending lectures, and helping your fellow classmates within your table-group. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next comes Code Challenge Week, where you are tested on the things you have learned. If you don't like timed tests, worry not, because you have two attempts on all Code Challenges, with the ability to redo ONE phase if don't pass both times. This week also includes everything from week one.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, Project Week! This week, you are paired with a partner to work on a project of your own choosing, you are free to essentially do whatever you want, as long as you meet some very broad requirements. At the end of project week are project presentations, where you present your project to your classmates. I know, I know, presenting anything is usually a massive pain, full of anxiety; but these presentations are extremely laid back, no time requirements, or any requirements at all actually. I can can honestly say that I looked forward to every single project week and presentation.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As for what each phase is about, the course may get reordered or changed every once and awhile, but this is how it was set up when I attended:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Vanilla JavaScript - here you will learn the basics of programming: syntax, data types, iterating through arrays and objects, almost entirely frontend. If your new to programming, this may be the most difficult phase. &lt;/li&gt;
&lt;li&gt;React - what it is, how to use it. You'll learning about hooks: &lt;code&gt;useState&lt;/code&gt; and &lt;code&gt;useEffect&lt;/code&gt;. You'll also be using a backend, but not a &lt;em&gt;real&lt;/em&gt; backend. Takes a while to get used to, can be difficult.&lt;/li&gt;
&lt;li&gt;Ruby - Third phase is all about the backend, and connecting it to your frontend. This is a difficult phase, lots and lots of information in a very short time: ruby, active record, sql and sinatra. &lt;/li&gt;
&lt;li&gt;Ruby on Rails - You've learned how to do everything the long and hard way last phase, now you get rails to do all that for you. You'll also learn Authorization. A pretty laid back phase. &lt;/li&gt;
&lt;li&gt;Final Project - This phase is quite different from the previous phases, instead of one week each for learning, testing, and creating; this week entirely consists of you creating your capstone project. This project is done on your own (no partners), and has more requirements (but by this point its not a big deal). While you'll be used to starting and completing a project in a single week, your final project will take all three weeks of the phase, and will also end with presentations.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After Graduating, you'll be paired with a Career Coach who will help you find a job, As I have yet to graduate, I can't speak much on that. &lt;/p&gt;

&lt;p&gt;Overall, I have found my experience at Flatiron to be incredible, and have loved every second. While I was initially apprehensive, after the first phase I was sold. Working with groups is a joy because everyone chose to be there, and are motivated to the best they can (no slackers). The instructors were immensely helpful, and always happy to help, many being previous graduates of the program themselves!&lt;/p&gt;

&lt;p&gt;The end of the program brings a scary, uncertain time that is the job hunt, but with this experience under my belt, I can face that time confidently. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Using React Google Charts</title>
      <dc:creator>Asher Scott</dc:creator>
      <pubDate>Sat, 28 May 2022 18:45:23 +0000</pubDate>
      <link>https://dev.to/asherscott/using-react-google-charts-3ae5</link>
      <guid>https://dev.to/asherscott/using-react-google-charts-3ae5</guid>
      <description>&lt;p&gt;While working on a financial tracking application, I realized I need some way to display all of that data. So began my search for a chart library, after trying out a few, and stumbling my way upon a library that cost over $200. I finally settled on using &lt;a href="https://www.react-google-charts.com/"&gt;React Google Charts&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;While certainly not as robust or flashy as many other libraries, it had one thing that others didn't; it was free, and I could actually figure out how to use it.&lt;/p&gt;

&lt;p&gt;The link above will take you to the official website, where there are plenty of examples, a quick guide to get you started, more examples, info on component props, and many, many, many examples.&lt;/p&gt;

&lt;p&gt;If you're anything like me, you like examples because instead of actually learning how stuff works, you can simply copy an already existing one that's close enough, and adjust it to your liking (or adjust it as best you can since you don't know how anything works). &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P12MlOPt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9aibaqivx9m5iwy266dg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P12MlOPt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9aibaqivx9m5iwy266dg.png" alt="Pie Chart" width="306" height="285"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;(huge shoutout to this &lt;a href="https://colordesigner.io/gradient-generator"&gt;Gradient Generator&lt;/a&gt;, it's pretty great for generating color gradients, color schemes, and all of your color needs)&lt;/em&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;Chart
          chartType="PieChart"
          width="100%"
          height="400px"
          data={budgetPieData}
          options={{
            pieSliceText: "none",
            pieHole: 0.6,
            backgroundColor: "none",
            colors: [
              "#26cd4d",
              "#00c065",
              "#00b377",
              "#00a483",
              "#00958a",
              "#00858b",
              "#007685",
              "#00667b",
              "#0f576b",
              "#2a4858",
              "#28687d",
              "#168ba0",
              "#00b0be",
              "#00d6d6",
              "#05fce8",
              "#00fed9",
              "#00ffc6",
              "#00ffb0",
              "#00ff96",
              "#00ff78",
            ],
          }}
        /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While it is certainly functional, and gives a fair amount of customizability, I did find that it became increasingly difficult to work with the more complex my needs (formatting data for stacked Column Charts is a bit of a nightmare), but I found that it overall worked out good enough.&lt;/p&gt;

&lt;p&gt;Have you used React Google Charts? Do you know of something even better? I would definitely love to hear about it; but in the mean time, good luck and get coding!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Rails generators</title>
      <dc:creator>Asher Scott</dc:creator>
      <pubDate>Mon, 23 May 2022 14:16:20 +0000</pubDate>
      <link>https://dev.to/asherscott/rails-generators-3fil</link>
      <guid>https://dev.to/asherscott/rails-generators-3fil</guid>
      <description>&lt;p&gt;Rails comes with many helpful ways to speedup backend development. One really convenient tool are generators.&lt;/p&gt;

&lt;p&gt;Generators are used to quickly create your backend structure by taking care of repetitive code, allowing you to focus on the more unique aspects of your application. &lt;/p&gt;

&lt;p&gt;There are several different things able to be created with rails generate, the most common ones you might encounter are:&lt;br&gt;
&lt;/p&gt;

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

controller
migration
model
resource
scaffold
serializer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Model
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;rails g model &amp;lt;model_name&amp;gt;&lt;/code&gt; creates a migration file, including any column names for your table if passed as an argument. &lt;br&gt;
E.g. &lt;code&gt;rails g model Pen brand color price:integer&lt;/code&gt; would create the following migration file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# 20220507194429_create_pens.rb

class CreatePens &amp;lt; ActiveRecord::Migration[6.1]
  def change
    create_table :pens do |t|
      t.string :brand
      t.string :color
      t.integer :price

      t.timestamps
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;model file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# pen.rb

class Pen &amp;lt; ApplicationRecord
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and spec file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# pen_spec.rb

require 'rails_helper'

RSpec.describe Pen, type: :model do
  pending "add some examples to (or delete) #{__FILE__}"
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Resource
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;rails g resource Pen brand color price:integer&lt;/code&gt; will create all of the above files, along with a serializer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# pen_serializer.rb

class PenSerializer &amp;lt; ActiveModel::Serializer
  attributes :id, :brand, :color, :price
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;controller:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# pens_controller.rb

class PensController &amp;lt; ApplicationController
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;your routes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# routes.rb

Rails.application.routes.draw do
  resources :pens
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and some additional specs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scaffold
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;rails g scaffold Pen brand color price:integer&lt;/code&gt; creates all of the above, but adds full CRUD capability for your controller:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# pens_controller.rb

class PensController &amp;lt; ApplicationController
  before_action :set_pen, only: [:show, :update, :destroy]

  # GET /pens
  def index
    @pens = Pen.all

    render json: @pens
  end

  # GET /pens/1
  def show
    render json: @pen
  end

  # POST /pens
  def create
    @pen = Pen.new(pen_params)

    if @pen.save
      render json: @pen, status: :created, location: @pen
    else
      render json: @pen.errors, status: :unprocessable_entity
    end
  end

  # PATCH/PUT /pens/1
  def update
    if @pen.update(pen_params)
      render json: @pen
    else
      render json: @pen.errors, status: :unprocessable_entity
    end
  end

  # DELETE /pens/1
  def destroy
    @pen.destroy
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_pen
      @pen = Pen.find(params[:id])
    end

    # Only allow a list of trusted parameters through.
    def pen_params
      params.require(:pen).permit(:brand, :color, :price)
    end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and more spec files.&lt;/p&gt;

&lt;p&gt;Of course it's important to know how all of this code works, and why. However, once you've worked on a few rails projects, generators are a great way to quickly and painlessly create the basic framework for most applications.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Moving Background using CSS</title>
      <dc:creator>Asher Scott</dc:creator>
      <pubDate>Mon, 23 May 2022 14:16:13 +0000</pubDate>
      <link>https://dev.to/asherscott/moving-background-using-css-1k5f</link>
      <guid>https://dev.to/asherscott/moving-background-using-css-1k5f</guid>
      <description>&lt;p&gt;A moving background is a really simple way to spice up your website. It is also surprisingly simple to do.&lt;/p&gt;

&lt;p&gt;HTML:&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;div id="background"&amp;gt;
      &amp;lt;div id="effect"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here are our two divs that will contain our static background image, and our moving overlay for that image. Note that you can have any number of these divs, moving or not.&lt;/p&gt;

&lt;p&gt;CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#background {
  background-image: url("../public/transport1_touchup.png");
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
  width: 100%;
  height: 100vh;
  z-index: -200;
}

#effect {
  position: absolute;
  background-image: url("../public/transport1_effects.png");
  width: 200vw;
  height: 100vh;
  animation: slide 20s ease-in-out infinite;
}

@keyframes slide {
  0%,
  100% {
    transform: translate(0px);
  }
  50% {
    transform: translate(-25vw);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is our css for our two divs, as well as the keyframes for our slide animation. For this particular effect, I needed to make sure the overlay effect was much wider than the background image, yours may be different depending on your needs.&lt;/p&gt;

&lt;p&gt;In some circumstances, it might make more sense to turn your effect into a repeating video or gif, and both have their pros and cons.&lt;/p&gt;

&lt;p&gt;I hope this post was helpful, go get creating!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Fun interactivity using react-stars!</title>
      <dc:creator>Asher Scott</dc:creator>
      <pubDate>Fri, 01 Apr 2022 22:47:59 +0000</pubDate>
      <link>https://dev.to/asherscott/fun-interactivity-using-react-stars-2n7n</link>
      <guid>https://dev.to/asherscott/fun-interactivity-using-react-stars-2n7n</guid>
      <description>&lt;p&gt;While working on my Phase-2 Flatiron Project, I stumbled upon this super useful react component called &lt;a href="https://github.com/ertanhasani/react-stars"&gt;react-stars&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--koJ6zr9b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4qhky061o49hppmbw8bg.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--koJ6zr9b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4qhky061o49hppmbw8bg.gif" alt="react-stars" width="249" height="64"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is an incredibly straightforward, flexible, and powerful component used for star rating systems. Check out the demo &lt;a href="https://codesandbox.io/s/elegant-mountain-w3ngk?file=/src/App.js"&gt;here&lt;/a&gt;!&lt;/p&gt;

&lt;h4&gt;
  
  
  Don't like boring old stars?
&lt;/h4&gt;

&lt;p&gt;-stars allows you to completely customize the rating characters, using either:&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;string&lt;/code&gt;;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--P2ihfoVe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b5cenb5tlzf7ullb9yoj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--P2ihfoVe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b5cenb5tlzf7ullb9yoj.png" alt="different characters" width="467" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Or an html element! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8jYdbM0Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7v6zowhkn0n4hxau89sk.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8jYdbM0Q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7v6zowhkn0n4hxau89sk.gif" alt="pixel star image" width="570" height="164"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Don't be afraid to get creative with it!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Lh3yeBTW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ik79x6phv6hvpp5q55z5.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Lh3yeBTW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ik79x6phv6hvpp5q55z5.gif" alt="gif image" width="376" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But lest you think this can only be used for ratings...&lt;/p&gt;

&lt;h4&gt;
  
  
  Mini Games!
&lt;/h4&gt;

&lt;p&gt;Here's a simple game I put together using react-stars&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--or1UOpuF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y7mp0054vvg7lspa1311.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--or1UOpuF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y7mp0054vvg7lspa1311.gif" alt="select the num" width="600" height="511"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Checkout the &lt;a href="https://github.com/ertanhasani/react-stars"&gt;github&lt;/a&gt; page for more information, including a &lt;a href="https://github.com/ertanhasani/react-stars#readme"&gt;README&lt;/a&gt; on how to begin using react-stars to take your react project to the new level!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Simple Grid Based Movement</title>
      <dc:creator>Asher Scott</dc:creator>
      <pubDate>Fri, 18 Mar 2022 16:48:38 +0000</pubDate>
      <link>https://dev.to/asherscott/simple-grid-based-movement-2li</link>
      <guid>https://dev.to/asherscott/simple-grid-based-movement-2li</guid>
      <description>&lt;h3&gt;
  
  
  1.) Set up initial files
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Create your HTML, JS, and CSS files&lt;/li&gt;
&lt;li&gt;Create initial HTML structure and link JS and CSS files&lt;/li&gt;
&lt;/ul&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpulp3evqclxxj3nohc93.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpulp3evqclxxj3nohc93.png" alt="initial setup"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2.) Create and Display your Sprite
&lt;/h3&gt;

&lt;p&gt;HTML&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;body&amp;gt;
        &amp;lt;div id="sprite"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CSS&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#sprite {
    background-color: black;
    height: 20px;
    width: 20px;
    position: absolute;
    /* Initial coordinates of sprite */
    left: 100px;
    bottom: 500px;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3.) Add an &lt;code&gt;addEventListener&lt;/code&gt; for keydown events
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// set equal to sprite's initial cooridinates
let position = {
    x: 100, 
    y: 500
};
// dimensions of the sprite
size = 20;

document.addEventListener('keydown', (event) =&amp;gt; chooseDirection(event));

function chooseDirection(event) {
    // if key pressed = an arrow key --&amp;gt; change position
    switch(event.key) {
        case 'ArrowRight':
            position.x += size;
            sprite.style.left = position.x + 'px';
            break;
        case 'ArrowLeft':
            position.x -= size;
            sprite.style.left = position.x + 'px';
            break;
        case 'ArrowUp':
            position.y += size;
            sprite.style.bottom = position.y + 'px';
            break;
        case 'ArrowDown':
            position.y -= size;
            sprite.style.bottom = position.y + 'px';
            break;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it! Now using the arrow keys (or whatever keys you want!), you can move the sprite all across the screen.&lt;/p&gt;

&lt;h2&gt;
  
  
  Extras!
&lt;/h2&gt;

&lt;h3&gt;
  
  
  - Change based on window size
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;window.addEventListener('resize', displaySprite)

function displaySprite() {
    // remove any previous sprite
    document.querySelector('body').innerHTML = '';

    const sprite = document.createElement('div');
    sprite.id = 'sprite';
    document.querySelector('body').append(sprite);

    sprite.style.height = size + 'vmin';
    sprite.style.width  = size + 'vmin';
    sprite.style.left   = position.x + 'vmin';
    sprite.style.bottom = position.y + 'vmin';
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By changing from &lt;code&gt;px&lt;/code&gt; units to &lt;code&gt;vmin&lt;/code&gt; units, we can dynamically change the size of the sprite.&lt;/p&gt;

&lt;p&gt;For Example:&lt;br&gt;
&lt;code&gt;sprite.style.bottom = position.y + 'px'&lt;/code&gt; --&amp;gt; &lt;code&gt;sprite.style.bottom = position.y + 'vmin'&lt;/code&gt;&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb8abgu70axndodbj0x2s.gif" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb8abgu70axndodbj0x2s.gif" alt="changing window size"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  - Add a Grid
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function displayGrid() {
    const grid = document.createElement('div');
    grid.id = 'grid';
    document.querySelector('body').append(grid);

    let cellClass = 'darkerTile';
    let isDark = true;

    for(let i = 0; i &amp;lt; gridSize; i++) {
        const column = document.createElement('div');
        column.className = 'column';
        grid.append(column);

        for(let i = 0; i &amp;lt; gridSize; i++) {
            (isDark) ? cellClass = 'darkerTile' : cellClass = 'lighterTile';
            isDark = !isDark;

            const cell = document.createElement('div');
            cell.className = cellClass;
            cell.style.height = size + 'vmin';
            cell.style.width = size + 'vmin';

            column.append(cell);
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Don't forget the CSS!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#grid {
    display: flex;
    position: relative;
    width: fit-content;
    border: 2vmin solid darkgreen;
}

.darkerTile {
    background-color: green;
}

.lighterTile {
    background-color: lightgreen;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If your having trouble with your sprite aligning to your grid:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;try making your sprite the child of your grid element, and setting the grid's position to relative&lt;/li&gt;
&lt;li&gt;make sure your starting position aligns with the grid&lt;/li&gt;
&lt;li&gt;make sure all size related units are tied to the same variable&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  - Add border collision to contain your sprite
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const bounds = {
    min: 0,
    max: (gridSize - 1) * size
};

function chooseDirection(event) {
    switch(event.key) {
        case 'ArrowRight':
            isAtBorder('x', 'max') ? null : move('x', 'left', true);
            break;
        case 'ArrowLeft':
            isAtBorder('x', 'min') ? null : move('x', 'left', false);
            break;
        case 'ArrowUp':
            isAtBorder('y', 'max') ? null : move('y', 'bottom', true);
            break;
        case 'ArrowDown':
            isAtBorder('y', 'min') ? null : move('y', 'bottom', false);
            break;
    }
}

function isAtBorder(axis, boundary) {
    return (position[axis] === bounds[boundary]) ? true : false;
}

function move(spriteAxis, windowAxis, moveMaxy) {
    (moveMaxy === true) 
    ? position[spriteAxis] += size
    : position[spriteAxis] -= size;

    sprite.style[windowAxis] = position[spriteAxis] + 'vmin';
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  - Change your sprite's appearance
&lt;/h3&gt;

&lt;p&gt;Instead of a div, change your sprite to an img and mess around with different sources.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Product
&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9lhoa1s1fxkwn4waa5xg.gif" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9lhoa1s1fxkwn4waa5xg.gif" alt="final"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
