<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Win Feigle on Medium]]></title>
        <description><![CDATA[Stories by Win Feigle on Medium]]></description>
        <link>https://medium.com/@winfeigle?source=rss-5cced126ea90------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pTTSpyuGVLqbiXYSiN7u6A.jpeg</url>
            <title>Stories by Win Feigle on Medium</title>
            <link>https://medium.com/@winfeigle?source=rss-5cced126ea90------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 09:59:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@winfeigle/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Basic Ruby enumerable and array methods with examples:]]></title>
            <link>https://medium.com/@winfeigle/basic-ruby-enumerable-and-array-methods-with-examples-c33c81a54b4c?source=rss-5cced126ea90------2</link>
            <guid isPermaLink="false">https://medium.com/p/c33c81a54b4c</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[methods]]></category>
            <category><![CDATA[enumerable]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[basic-ruby]]></category>
            <dc:creator><![CDATA[Win Feigle]]></dc:creator>
            <pubDate>Fri, 03 Feb 2023 14:52:47 GMT</pubDate>
            <atom:updated>2023-02-03T14:59:24.065Z</atom:updated>
            <content:encoded><![CDATA[<p>First things first. What is an array method, and what is the enumerable module? (Because it confused <em>me</em> at first)</p><p>An enumerable is a Ruby model that gives us the ability to traverse, search, and sort using its methods on collection classes. The enumerable module defines methods for working with collections of data: iterating through, filtering, and transforming elements.</p><p>Ruby has a multitude of built-in array methods, and some are more commonly used than others.</p><p><strong><em>Enumerable methods</em></strong> can be used on arrays and other objects that include the enumerable module, while A<strong><em>rray methods</em></strong> are specific to arrays and only arrays.</p><h4>Array Methods</h4><p>.concat combines elements from multiple arrays into one.</p><pre>arr_1 = [1,2,3]<br>arr_2 = [&quot;a&quot;,&quot;b&quot;,&quot;c&quot;]<br><br>puts arr_1.concat([arr2])<br>#=&gt; [1,2,3,&quot;a&quot;,&quot;b&quot;,&quot;c&quot;]</pre><p>.delete and .delete_at: Both remove an element from an array.</p><pre>arr = [&quot;win&quot;, &quot;lose&quot;, &quot;draw&quot;]<br><br>arr.delete(&quot;draw&quot;)<br>#=&gt; [&quot;win&quot;, &quot;lose&quot;]</pre><pre>arr = [&quot;win&quot;, &quot;lose&quot;, &quot;draw&quot;]<br><br>arr.delete_at(1)<br>#=&gt; [&quot;win&quot;, &quot;draw&quot;]</pre><p>.drop: Returns an array after <em>n </em>elements have been removed.</p><pre>arr = [&quot;a&quot;,&quot;b&quot;,&quot;c&quot;,&quot;d&quot;,&quot;e&quot;,&quot;f&quot;]<br><br>arr.drop(2)<br>#=&gt; [&quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;]</pre><p>.each: Used for iterating over the elements in an array.</p><pre>names = [&quot;Samantha&quot;,&quot;Wendy&quot;,&quot;Zeuss&quot;]<br><br>names.each {|name| puts &quot;Hello, #{name}.&quot;}<br><br>#=&gt; Hello, Samantha.<br>#=&gt; Hello, Wendy.<br>#=&gt; Hello, Zeuss.</pre><p>.map: Used for transforming each element in an array and returning the new, modified array with the results.</p><pre>nums = [1,2,3]<br><br>new_nums = nums.map { |num| num*num }<br><br>puts nums<br>#=&gt; [1,2,3]<br><br>puts new_nums<br>#=&gt; [1,4,9]</pre><p>.select: Used for filtering elements from an array based on a condition, you have to return something that evaluates to either true or false.</p><pre>nums = [1,2,3,4]<br><br>even_nums = nums.select { |num| num.even? }<br><br>puts even_nums<br>#=&gt; [2,4]</pre><p>.find: Used for finding the first element in an array that satisfies a given condition.</p><pre>nums = [1,2,3,4]<br><br>nums.find { |num| num.even? }<br><br>#=&gt; 2</pre><p>.sort: Used for sorting elements in an array.</p><pre>nums = [78, 8, 22, 42]<br><br>nums.sort<br>#=&gt; [8, 22, 42, 78]</pre><p>.reverse: Used for reversing the order of elements in an array. It’s important to note this doesn&#39;t <em>also </em>sort the array.</p><pre>nums = [8,78,22,42]<br><br>nums.reverse<br>#=&gt; [42, 22, 78, 8]<br><br>nums.sort.reverse<br>#=&gt; [78, 42, 22, 8]</pre><p>.size or .length: Used for determining the number of elements in an array. Returns an integer, and 0 if empty.</p><p>.first and .last: Used for accessing the first or last element in an array.</p><p>.empty?: Used for checking if an array is empty. Returns <em>true</em> or <em>false</em>.</p><p>.include?: Used for checking if an array contains a specific element. Returns <em>true </em>or <em>false</em>.</p><pre>nums = [1,2,3,4]<br><br>nums.include?(3)<br>#=&gt; true</pre><h4>Enumerable Methods</h4><p>There are a few enumerable methods that work in the same way as array methods, some of these include: .each, .map, .select, .find, .sort, among others.</p><p>.min and .max: Used for finding the minimum or maximum element in a collection.</p><pre>array = [3, 2, 5, 1, 4]<br>min_value = array.min<br>max_value = array.max<br><br>puts &quot;Min: #{min_value} Max: #{max_value}&quot;<br>#=&gt; Min: 1 Max: 5</pre><p>.flatten: Used to flatten nested arrays and return a single-dimensional array. The optional level argument can be used to control the level of flattening.</p><pre>array = [[1, 2, 3], [4, 5, 6]]<br>flattened_array = array.flatten<br><br>puts flattened_array<br># Output: [1, 2, 3, 4, 5, 6]</pre><p>.flatten<em> </em>example with level argument</p><pre>array = [[1, 2, [3, 4]], [5, 6]]<br>flattened_array = array.flatten(1)<br><br>puts flattened_array<br>#=&gt; Output: [1, 2, [3, 4], 5, 6]</pre><p>.with_index: Used in conjunction with the .each method to traverse an array, and it provides the index of each item in the array as it&#39;s being traversed.</p><pre>array = [&quot;dog&quot;, &quot;cat&quot;, &quot;bird&quot;]<br>array.each.with_index do |item, index|<br>  puts &quot;Index: #{index} Item: #{item}&quot;<br>end<br><br>#=&gt; Index: 0 Item: dog<br>#=&gt; Index: 1 Item: cat<br>#=&gt; Index: 2 Item: bird</pre><p>.all?: Used for checking if all elements in a collection satisfy a given condition.</p><pre>array = [1, 2, 3, 4, 5]<br>all_even = array.all? do |num|<br>  num.even?<br>end<br><br>puts all_even<br>#=&gt; false</pre><p>.any?: Used for checking if any elements in a collection satisfy a given condition.</p><pre>array = [1, 2, 3, 4, 5]<br>any_even = array.any? do |num|<br>  num.even?<br>end<br><br>puts any_even<br>#=&gt; true</pre><p>.reduce: Used for combining all elements in a collection into a single value.</p><pre>array = [1, 2, 3, 4, 5]<br>sum = array.reduce(0) do |total, num|<br>  total + num<br>end<br><br>puts sum<br>#=&gt; 15</pre><p>.group_by: Used for grouping elements in a collection based on a specific attribute.</p><pre>array = [1, 2, 3, 4, 5]<br>grouped_array = array.group_by do |num|<br>  num.even?<br>end<br><br>puts grouped_array<br># Output: {false=&gt;[1, 3, 5], true=&gt;[2, 4]}</pre><p>In conclusion… we’ve barely scratched the surface of using methods on arrays and collections. To learn more, here are some additional resources:</p><ul><li><a href="https://ruby-doc.org/core-3.1.1/Enumerable.html">https://ruby-doc.org/core-3.1.1/Enumerable.html</a></li><li><a href="https://ruby-doc.org/core-2.7.0/Array.html">https://www.freecodecamp.org/news/common-array-methods-in-ruby/</a></li><li><a href="https://launchschool.com/books/ruby/read/arrays">https://www.educative.io/blog/ruby-array-methods#arraymethods</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*uyuYKmgkzW3lz43H2O9G2Q.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c33c81a54b4c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to use binding.pry: An Oversimplified Ruby Step-by-Step Guide]]></title>
            <link>https://medium.com/@winfeigle/how-to-use-binding-pry-an-oversimplified-ruby-step-by-step-guide-96cfc2b2a915?source=rss-5cced126ea90------2</link>
            <guid isPermaLink="false">https://medium.com/p/96cfc2b2a915</guid>
            <category><![CDATA[ruby-development]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[pry]]></category>
            <category><![CDATA[binding-pry]]></category>
            <category><![CDATA[rubygems]]></category>
            <dc:creator><![CDATA[Win Feigle]]></dc:creator>
            <pubDate>Fri, 23 Dec 2022 23:25:56 GMT</pubDate>
            <atom:updated>2022-12-23T23:25:56.225Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to use binding.pry: An Oversimplified Step-by-Step Guide</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9lFKIKxUE7MGkvo4cLy9Vg.png" /></figure><blockquote>“Pry is a runtime developer console and IRB alternative with powerful introspection capabilities.”</blockquote><h4>Introduction:</h4><p>Pry is a tool we can use in Ruby to take a deeper look into how our program is running and executing code. It allows us to test individual methods, and as your program starts to get more complex, this can be a lifesaver. Pry has access to all of our variables, classes, instances, methods, etc.</p><p>By selectively placing <strong>binding.pry</strong> inside and outside of select elements, we can use the command line to identify how/what is being executed on. It’s important to note that if <strong>binding.pry </strong>is placed after invalid code, Pry will not run.</p><h4><strong>Installation:</strong></h4><p>Start by installing the pry gem in your projects’ <strong><em>Gemfile</em></strong><em>…</em></p><pre>source &quot;https://rubygems.org&quot;<br>gem &#39;pry&#39;, &#39;~&gt; 0.13.1&#39;</pre><p>or install it manually from the command line.</p><pre>gem install pry</pre><h4><strong>Basics of binding.pry:</strong></h4><p>A pry session is started as a command and has to start at the beginning of a line without any whitespace between, but it can be invoked anywhere in a running program.</p><p>First, <strong>require ‘pry’</strong> at the top of the file. Next, you can invoke pry on a specific object, using <strong>my_object.pry </strong>or <strong>binding.pry </strong>for use on the current binding. Both start a REPL session from the terminal, and the program halts any further execution until the pry session is ended.</p><pre>require &#39;pry&#39;<br><br><br>def say_hello<br>  name = &quot;Theodore&quot;<br>  puts &quot;Hello, #{name}!&quot; <br><br>  # starts a REPL session<br>  binding.pry<br>end<br><br># program resumes here (after pry session)<br>puts &quot;program resumes here.&quot;</pre><p>Pry session with <strong>binding.pry </strong>will allow you to read from within the object as long as it has a <strong>readLine</strong> method and allow you to write to any object with a <strong>puts</strong> method:</p><pre>pry(main)&gt; name<br>Theodore<br>=&gt; nil<br>pry(main)&gt; exit<br><br>program resumes here.</pre><h3><strong>Problem-Solving with Pry (Example)</strong></h3><p>Let’s say I want to create a method that returns an array of students, sorted by their name. I know how to create the array, and the method, but am not quite sure what code needs to go into my <strong>sort_students </strong>method to actually return this sorted array, see below:</p><pre># pry_practice.rb<br><br>require &#39;pry&#39;<br><br>students = [&quot;Daniella&quot;, &quot;Andrew&quot;, &quot;Carter&quot;, &quot;Brooke&quot;, &quot;Francis&quot;, &quot;Edwin&quot;]<br><br>def sort_students array<br><br>  # I dont know what code to write here...<br>  # So we can use binding.pry to test some code from the command line.<br><br>  binding.pry<br>end<br><br><br>sort_students(students)</pre><p>We’ll run the file by executing the following using the command line</p><pre>ruby pry_practice.rb</pre><p>Here’s what we get in return:</p><pre>From: /Users/winfeigle/Development/code/phase-3/phase-3-methods/pry_practice.rb:8 Object#sort_students:<br><br>    5: def sort_students array<br>    6: <br>    7:   <br> =&gt; 8:   binding.pry<br>    9: end<br><br>[1] pry(main)&gt;</pre><p>From the command line, we can access the <strong>students</strong> array that is passed into the sort_students method using <strong>array </strong>because that is the methods’ parameter, and we are inside the <strong>sort_students </strong>method.</p><pre>[1] pry(main)&gt; array<br>=&gt; [&quot;Daniella&quot;, &quot;Andrew&quot;, &quot;Carter&quot;, &quot;Brooke&quot;, &quot;Francis&quot;, &quot;Edwin&quot;]<br>[2] pry(main)&gt;</pre><p>We can test a few commands and see if any of them return the <strong>array </strong>sorted alphabetically as we’d hoped…</p><pre>[6] pry(main)&gt; array.order<br>NoMethodError: undefined method `order&#39; for [&quot;Daniella&quot;, &quot;Andrew&quot;, &quot;Carter&quot;, &quot;Brooke&quot;, &quot;Francis&quot;, &quot;Edwin&quot;]:Array<br>from (pry):6:in `sort_students&#39;<br>[7] pry(main)&gt; array.first<br>=&gt; &quot;Daniella&quot;<br>[8] pry(main)&gt; array.sort<br>=&gt; [&quot;Andrew&quot;, &quot;Brooke&quot;, &quot;Carter&quot;, &quot;Daniella&quot;, &quot;Edwin&quot;, &quot;Francis&quot;]<br>[9] pry(main)&gt; and we find that array.sort will return the array in the order w</pre><p>We tried <strong>array.order </strong>and that threw an error, next we tried <strong>array.first </strong>and that only returned the first name in the array, and last we tried <strong>array.sort</strong>, which worked! You can exit your console by running <strong>exit </strong>command<strong> </strong>or using the <strong><em>Ctrl+D</em></strong> shortcut key.</p><p>Now we can take our findings and implement them back into our method. Don’t forget to remove your <strong>binding.pry</strong> to the method can be fully executed!</p><pre>require &#39;pry&#39;<br><br>students = [&quot;Daniella&quot;, &quot;Andrew&quot;, &quot;Carter&quot;, &quot;Brooke&quot;, &quot;Francis&quot;, &quot;Edwin&quot;]<br><br>def sort_students array<br>    sorted = array.sort<br>    sorted<br>end<br><br><br>sort_students(students)<br># will now return [&quot;Andrew&quot;, &quot;Brooke&quot;, &quot;Carter&quot;, &quot;Daniella&quot;, &quot;Edwin&quot;, &quot;Francis&quot;]</pre><h4>So, why use Pry?</h4><p>Pry allows us to look inside a program while it’s running and examine the inside of objects, view methods, invoke methods, and more. Pry is able to retrieve documentation for methods that wouldn&#39;t normally be picked up by <strong>rdoc.</strong></p><p><strong>Sources:</strong></p><ol><li><a href="https://github.com/pry/pry">https://github.com/pry/pry</a></li><li><a href="https://dev.to/elimerrell/debugging-with-pry-a-beginners-guide-3p99#:~:text=The%20Ruby%20programmer%20can%20invoke,values%2C%20iterations%2C%20and%20more">https://dev.to/elimerrell/debugging-with-pry-a-beginners-guide-3p99#:~:text=The%20Ruby%20programmer%20can%20invoke,values%2C%20iterations%2C%20and%20more</a></li><li><a href="https://medium.com/@eddgr/the-absolute-beginners-guide-to-using-pry-in-ruby-b08681558fa6">https://medium.com/@eddgr/the-absolute-beginners-guide-to-using-pry-in-ruby-b08681558fa6</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96cfc2b2a915" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intro to React Router]]></title>
            <link>https://medium.com/@winfeigle/intro-to-react-router-4e8d10340aba?source=rss-5cced126ea90------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e8d10340aba</guid>
            <category><![CDATA[react-router]]></category>
            <category><![CDATA[react-router-dom]]></category>
            <dc:creator><![CDATA[Win Feigle]]></dc:creator>
            <pubDate>Mon, 22 Aug 2022 08:24:29 GMT</pubDate>
            <atom:updated>2022-12-23T23:30:08.036Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Bxw3BkDohxXiN7Q99F5AQ.png" /><figcaption>via React Router Docs</figcaption></figure><h3>Key Concepts</h3><ul><li><strong><em>React Router: </em></strong>A routing library that allows us to conditionally render components onto the page based on the URL being displayed. React Router gives us multiple tools (components and hooks) that work wherever React is rendering.</li><li><strong><em>Client Side Routing: </em></strong>The separation of different components onto different “pages” in an app, each with its own unique URL. With CSR, all the routing logic is handled with JavaScript, without making additional GET requests.</li></ul><p><strong>1.) Installing React Router</strong></p><p>In order to use React Router, we have to install react-router-dom:</p><p>$ npm install react-router-dom</p><p><strong>2.) Import React Router functions into index.js file</strong></p><p>Here, we are declaring how React Router will be used in our project:</p><p><em>.src/index.js</em></p><pre>import { BrowserRouter, Route} from &quot;react-router-dom&quot;;</pre><p><strong>3.) Define Client-Side Routes using &lt;Route&gt; components</strong></p><p>In the App component, &lt;Route&gt; will tell React to render certain components based on the current URL path. For this example, the Home component will render with the route path is just “/”</p><p><em>.src/components/App.js</em></p><pre>function App() {<br> return (<br>  &lt;Route path=&quot;/&quot;&gt;<br>   &lt;Home /&gt;<br>  &lt;/Route&gt;<br> );<br>}</pre><p><strong>4.) Wrap the Entire Application with &lt;BrowserRouter&gt; component</strong></p><p>We do this in order to provide all other components with React Router context features.</p><p><em>.src/index.js</em></p><pre>ReactDOM.render(<br>  &lt;BrowserRouter&gt;<br>    &lt;App /&gt;<br>  &lt;/BrowserRouter&gt;,<br>document.getElementById(&quot;root&quot;) );</pre><p><strong>5.) Adding additional Routes</strong></p><p>Create additional component, for example, an About component and a Contact component:</p><p><em>.src/components/About.js</em></p><pre>function About() {<br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;About!&lt;/h1&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p><em>..src/components/Contact.js</em></p><pre>function Contact() {<br>  return (<br>    &lt;div&gt;<br>      &lt;form&gt;Contact form here&lt;/form&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p><strong>6.) Add routes for newly created components (pages)</strong></p><p>From within index.js…</p><p><em>./src/index.js</em></p><pre>function App() {<br>  return (<br>    &lt;div&gt;<br>      &lt;Route path=&quot;/&quot;&gt;<br>        &lt;Home /&gt;<br>      &lt;/Route&gt;<br>      &lt;Route path=&quot;/about&quot;&gt;<br>        &lt;About /&gt;<br>      &lt;/Route&gt;<br>      &lt;Route path=&quot;/contact&quot;&gt;<br>        &lt;Contact /&gt;<br>      &lt;/Route&gt;<br>  &lt;/div&gt; );<br>}</pre><p><strong>7a. ) Implement &lt;Switch&gt; or “exact”</strong></p><p>Because all routes could potentially Include the first “/” in the URL, the Home component would render on every page. We use &lt;Switch&gt; to only render the first component that matches the URL path.</p><p><em>./src/index.js</em></p><pre>function App() {<br>  return (<br>    &lt;div&gt;<br>      &lt;Switch&gt;<br>        &lt;Route path=&quot;/&quot;&gt;<br>          &lt;Home /&gt;<br>        &lt;/Route&gt;<br>        &lt;Route path=&quot;/about&quot;&gt;<br>         &lt;About /&gt;<br>       &lt;/Route&gt;<br>       &lt;Route path=&quot;/contact&quot;&gt;<br>         &lt;Contact /&gt;<br>       &lt;/Route&gt;<br>      &lt;/Switch&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p><em>or use:</em></p><pre>&lt;Route exact path=&quot;/&quot;&gt;<br>  &lt;Home /&gt;<br>&lt;/Route&gt;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e8d10340aba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My First App]]></title>
            <link>https://medium.com/@winfeigle/my-first-app-768292b8d068?source=rss-5cced126ea90------2</link>
            <guid isPermaLink="false">https://medium.com/p/768292b8d068</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[first-post]]></category>
            <dc:creator><![CDATA[Win Feigle]]></dc:creator>
            <pubDate>Fri, 01 Jul 2022 22:34:45 GMT</pubDate>
            <atom:updated>2022-07-01T22:34:45.664Z</atom:updated>
            <content:encoded><![CDATA[<p>For my Phase One Project at Flatiron school, I created a single-page application that accesses compiled US Census Bureau data from <a href="https://datausa.io/">DATA USA</a>’s public API.</p><p>The app is a quality of life comparison tool that allows the user to search for information on nearly 30,000 cities across the United States. The front end is a simple HTML/CSS/JS build based on a preliminary mock-up I created using Adobe XD.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6UIfLnxD2LWK4liqXFuGgA.png" /><figcaption>Preliminary Adobe XD static mockup</figcaption></figure><p>My goal for this project was to create a minimalistic tool that would allow users to compare cities of interest with the location-specific information that mattered most to them. It was my hope, in the beginning, to allow the user to select the 4–5 data points of interest, that would populate into the page but that turned into more work than I’d initially thought, and also resulted in a much slower program.</p><h3><strong>Tackling the HTML</strong></h3><p>The HTML portion of the project went smoothly and didn&#39;t require too much work to set up the header, form, card container, and footer that would be the bare-bones components of the page.</p><p>The main challenge I ran into was deciding how I wanted to set up the form to capture the user’s search input. I’d initially considered prompting the user to submit multiple different location-specific inputs — <strong><em>City,</em></strong> <strong><em>State, </em></strong>and <strong><em>State Abbreviation </em></strong>— but soon realized if a user were to submit any misspelled information, it could jeopardize my fetch request that relies on the above input being correct.</p><p>I settled on a 2-part form that takes user text input for the city name, and then a drop-down selection box for the state name, with each state’s HTML value being the state’s two-letter abbreviation. This way, I could easily access the user&#39;s input as strings, for example:</p><blockquote><strong><em>‘Bozeman’, ‘Montana’, ‘MT’.</em></strong></blockquote><pre><strong>&lt;form id=&#39;search-form&#39;&gt;</strong></pre><pre> <strong> &lt;input</strong> id=&#39;city&#39; type=&#39;text&#39; name=&#39;city&#39; placeholder=&quot;City&quot;<strong>&gt;</strong></pre><pre>  <strong>&lt;select</strong> id=&quot;states&quot;<strong>&gt;</strong></pre><pre> <strong>   &lt;option</strong> value=&quot;AL&quot; class=&quot;Alabama&quot;&gt;Alabama<strong>&lt;/option&gt;</strong></pre><pre>    <strong>&lt;option</strong> value=&quot;AK&quot;&gt;Alaska<strong>&lt;/option&gt;</strong></pre><pre>  <strong>  &lt;option</strong> value=&quot;AZ&quot;&gt;Arizona<strong>&lt;/option&gt;</strong></pre><pre>    ...</pre><pre>  <strong>&lt;/select&gt;</strong></pre><pre> <strong> &lt;input</strong> id=&#39;search-btn&#39; type=&#39;submit&#39; name=&#39;submit&#39; value=&quot;Add&quot;<strong>/&gt;</strong></pre><pre><strong>&lt;/form&gt;</strong></pre><h3><strong>Challenges with JavaScript</strong></h3><p>The majority of the application is written in JavaScript. This is where I fetched data from the DATA USA API, added event listeners, and manipulated the DOM.</p><p>After creating the HTML form, I switched over to my <em>index.js </em>file to build out a ‘Handle Submit’ function to target the user’s input. For this function, I prevented the default form action of reloading the page, using <strong><em>e</em>.preventDefault(), </strong>and created a location Object<strong><em> </em></strong>with 4 keys and values pulled from the user’s search.</p><p>The <strong><em>newLocationObject </em></strong>held values that allowed me to fetch data — using the <strong><em>getData </em></strong>function—with custom URL queries that apply to the city/state being searched.</p><p>Finally, the <strong><em>form.reset() </em></strong>cleared the user’s text from the previous search.</p><pre><strong>function handleSubmit(<em>e</em>){</strong></pre><pre><em> </em><strong><em> e</em>.preventDefault()</strong></pre><pre>   <strong> let newLocationObject = {</strong></pre><pre>      <strong>city:</strong> <em>e</em>.target.city.value,</pre><pre>      <strong>st:</strong> <em>e</em>.target.states.value,</pre><pre>      <strong>state:</strong> states.options[states.selectedIndex].text,</pre><pre>      <strong>stateStr:</strong> `${<em>e</em>.target.city.value.replace(&#39; &#39;,&#39;- &#39;)}-${<em>e</em>.target.states.value}`.toLowerCase(),</pre><pre><strong>    }</strong></pre><pre><strong>getData(newLocationObject, renderCard)</strong></pre><pre><strong>form.reset()</strong></pre><pre><strong>}</strong></pre><p>For me, the most technical and challenging aspect of this js file was determining how to render a new ‘card’ to the DOM based on the user’s search input. After fetching the requested location data, I opted for a single function that takes multiple parameters pertaining to the returned data:</p><pre><strong>function renderCard</strong>(<em>location</em>, <em>income</em>, <em>age</em>, <em>property</em>, <em>population){}</em></pre><h3><strong>Finishing Touches with CSS</strong></h3><p>I am experienced with design, but inexperienced with CSS. So, when it came to implementing the styles I wanted to see into my app, it wasn’t as easy as I had initially hoped it would be. Changing font families, and adding colors, margins, and padding was a breeze… but figuring out how to center, use flex, justify, and align my content was a completely different story.</p><pre><strong>.card-container{</strong></pre><pre>  <strong>display:</strong> flex;</pre><pre>  <strong>flex-wrap:</strong> wrap;</pre><pre><strong>  margin:</strong> auto;</pre><pre>  <strong>max-width:</strong> 75%;</pre><pre>  <strong>justify-content:</strong> center;</pre><pre><strong>}</strong></pre><p>It took a few hours of trial and error before I had much of a clue about what I was actually tinkering around with. I happened to have some very helpful guides from <a href="https://css-tricks.com/snippets/css/complete-guide-grid/#aa-grid-properties"><strong>CSS-Tricks</strong></a><strong> </strong>that laid out the basic principles of containers, grids, and flexbox into beautiful infographics. Leveraging those infographics and utilizing Chrome dev tools allowed me to test out CSS adjustments in real-time rather than having to save my CSS file and re-launch my project with every new line of test code.</p><h3><strong>End Result</strong></h3><p>In the end, the app came just as I’d imagined it would. It is almost identical to my original Adobe XD mock-up, and considering this was my first full-fledged HTML/CSS/JS app, I was happy with my ability to deliver on my initial vision for the project. A link to the final project is listed below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tw6BRf3Z_Cb7FBiMquEzuw.png" /><figcaption>View the finished project <a href="https://github.com/winfeigle/phase-1-project">on my GitHub</a>.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=768292b8d068" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>