<?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 Jessica Bradham on Medium]]></title>
        <description><![CDATA[Stories by Jessica Bradham on Medium]]></description>
        <link>https://medium.com/@jessijokes?source=rss-acd37bc22d5c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ugKXuPCP4Sdo_DMt_kg_wQ.jpeg</url>
            <title>Stories by Jessica Bradham on Medium</title>
            <link>https://medium.com/@jessijokes?source=rss-acd37bc22d5c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 02:58:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jessijokes/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[One Button to Rule Them All: Making Accessible Buttons]]></title>
            <link>https://jessijokes.medium.com/one-button-to-rule-them-all-465e294cba82?source=rss-acd37bc22d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/465e294cba82</guid>
            <category><![CDATA[html]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[web-accessibility]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[accessibility]]></category>
            <dc:creator><![CDATA[Jessica Bradham]]></dc:creator>
            <pubDate>Sat, 23 Dec 2023 17:31:37 GMT</pubDate>
            <atom:updated>2024-01-03T07:43:18.180Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Gollum (from Lord of the Rings) holds the one ring between two fingers and peers up at it obsessively. Text indicates Gollum represents “me” and the ring is “accessible buttons”." src="https://cdn-images-1.medium.com/max/640/1*pU9uo3DY7o4N5eV3nvpYKA.jpeg" /><figcaption>One button to rule them all!</figcaption></figure><p>There are many aspects of Web Accessibility, and it can get quite complex, and feel very overwhelming. I’m hoping to do a whole series of posts, but for today I’m going to focus on just one small element; buttons.</p><figure><img alt="Sheldon (from Big Bang Theory) is looking at some printed papers. He shouts “Why?” then he shouts again with his eyes wide “Why!?” He repeats “Why?” the same as the first time. Then he looks calm and says, “Oh, that’s why.”" src="https://cdn-images-1.medium.com/max/989/1*EtN43ltpcCW2LrPLYxWazw.jpeg" /><figcaption>Why do we care?</figcaption></figure><p>When most people think about Web Accessibility, they are only thinking about standards and requirements. But let’s take one moment to think about <em>why </em>those standards exist.</p><p><a href="https://www.census.gov/library/stories/2023/06/disability-rates-higher-in-rural-areas-than-urban-areas.html#:~:text=Examining%20disability%20rates%20across%20geography,ACS)%201%2Dyear%20estimates.">In 2021 according to the census, nearly 42.5 million people (13% of the population) in the USA had a disability.</a></p><p><a href="https://ddt-vehss.cdc.gov/LP?Level1=Vision+Problems+and+Blindness&amp;Level2=Vision+Loss+and+Blindness&amp;Level3=VEHSS+Composite+Prevalence+Estimate:+Visual+Acuity+Loss&amp;Level4=Prevalence+of+Any+Visual+Acuity+Loss+(%E2%89%A420/32+Best+Corrected)&amp;LocationId=&amp;DataSourceId=PREV&amp;IndicatorId=QVLM~RVANY&amp;ShowFootnotes=true&amp;View=NationalMap&amp;CompareViewYear=1&amp;CompareId=&amp;CompareId2=&amp;YearId=YR9&amp;ResponseId=RVANY&amp;AgeId=AGEALL&amp;GenderId=GALL&amp;RaceId=ALLRACE&amp;RiskFactorId=RFPERS&amp;RiskFactorResponseId=RFTOT&amp;DataValueTypeId=CRDPREV&amp;MapClassifierId=quantile&amp;MapClassifierCount=4&amp;CountyFlag=N">According to the CDC 2.17% of the population is experiencing vision loss</a>.</p><p>I’ll admit, I tend to be the sentimental, idealistic type. I would love to live in a world where we are thinking of and considering all types of people when we build things.</p><p>But even if those ideals don’t concern you, imagine the prospect of up to 42.5 million people being unable to use your website? Purchase your product? Purchase your service? That should concern you. So how do we know if our websites/products/services are accessible?</p><figure><img alt="A man at a nightclub (labeled “programmer with a button that needs to be tested for accessibility”) is leaning toward a woman (labeled “vision impaired friend”) in order to speak to her. He is leaning so closely his nose is touching her face, and the woman looks extremely uncomfortable." src="https://cdn-images-1.medium.com/max/951/1*POIFDV1nCcadzahoXlW8sw.jpeg" /><figcaption>We just ask our vision impaired friend to test it right? Wrong.</figcaption></figure><p>The <a href="https://wcag.com/">Web Content Accessibility Guidelines (WCAG)</a> are a series of web accessibility guidelines published by the Web Accessibility Initiative of the World Wide Web Consortium, which is the international standards organization for the internet. This means you don’t have to bother a friend to test for you. There are set standards and guidelines for what it means to be accessible. You can look through them <a href="https://www.w3.org/WAI/standards-guidelines/wcag/">here</a> if you want to see them all. We’ll be using those as our guideline.</p><figure><img alt="A water bottle is pouring water into a glass. Next to it are the letters P, O, U, R going down to spell “pour”. “P” stands for “perceivable”, “O” stands for “Operable”, “U” stands for “Understandable”, “R” stands for “Robust”." src="https://cdn-images-1.medium.com/max/667/1*aTW7ynmWdXTHQTOu-jkAuw.jpeg" /><figcaption>POUR me some accessibility!</figcaption></figure><p>According to WCAG standards, in order for a button to be accessible, it needs the following aspects.</p><ul><li>Perceivable: The button must have a clear label that describes its purpose, either as text or as an alternative text for an image. The button must also have a sufficient color contrast with the background, and be resizable without losing information or functionality.</li><li>Operable: The button must be keyboard accessible, meaning that it can be focused and activated using the Tab and Enter keys. The button must also have a visible focus indicator, such as a border or a background color change, to show which element has keyboard focus. The button must also respond to touch and mouse events, and not rely on hover effects or double clicks.</li><li>Understandable: The button must have a consistent and predictable behavior, meaning that it should perform the same action every time it is activated. The button must also provide feedback to the user, such as changing its appearance or displaying a message, to indicate the result of the action.</li><li>Robust: The button must use standard HTML elements and attributes, such as &lt;button&gt; or &lt;input type=“button”&gt;, and avoid using &lt;div&gt; or &lt;span&gt; with role=“button”. The button must also use valid and semantic markup, and follow the best practices for writing HTML, CSS, and JavaScript.</li></ul><p>So let’s look at how we make this happen. We’re going to start with the HTML, and we’ll just pretend this is a “send” button for a feedback form.</p><pre>&lt;!-- HTML --&gt;<br>&lt;button id=&quot;button&quot;&gt;Send&lt;/button&gt;</pre><p>Let’s talk a little about some best practices here. Right off the bat we’re using the “button” html tag, so assistive technologies are aware this is a button. But we wouldn’t want to give a real functioning button an id like “button” because in all likelihood there will be multiple buttons on the page, and having multiple items with the same id is invalid html. (Which means it won’t find all the elements with the same id when they are needed and the things will break). So we’ll try this again.</p><pre>&lt;!-- HTML --&gt;<br>&lt;button id=&quot;send-feedback-btn&quot; aria-label=&quot;Send&quot;&gt;Send&lt;/button&gt;</pre><p>That’s better. If this was for a large company, we may even go a step further and specify the specific page/department. But for now this is fine. Let’s move on to the aria-label. But what is an aria-label? Should we ask Google?</p><figure><img alt="A screenshot of the google homepage, in the chrome browser, with “Images” highlighted in the dev tools inspect panel. The accessibility panel inside inspect is open, showing “Images” has an aria-label of “Search of Images (opens a new tab)”" src="https://cdn-images-1.medium.com/max/1024/1*UZo-PQTE4qU99OrszvRVZg.png" /><figcaption>Was this not the way you thought I was going to ask Google?</figcaption></figure><p>Aria labels are attributes we can add that give the user information about the element’s purpose, these attributes are used by assistive technologies like screen readers. So if a user were to focus on the “Images” link on google, it would be able to tell them it was a link (under “Role”), the name/text inside the link (“Images”), and the aria-label “Search for Images (opens a new tab)”. And now here’s a fun aside, because if I click that link it doesn’t open a new tab. So that just shows even the tech giants aren’t remembering to update their accessibility attributes when they work. (I reported the bug, I had no idea I’d be letting sending bug reports to Google when I started this article.) Back to the info though!</p><p>If we are pretending this is a send button for a feedback form, we want a user who is totally blind, using a screenreader to understand from the label what the button does when they click it. They will already get “Send” from the text inside the button. But send what? What if there’s another send on the page somewhere? One is to send a request to the chatbot for help and it’s on every page. The user needs to know which one does what so they can’t both just say “send”, they should be descriptive. “Send Feedback” is more appropriate. If it were going to take you off site, or open a new tab, like you saw in the Google example, that information would be helpful as well.</p><pre>&lt;!-- HTML --&gt;<br>&lt;button <br>  id=&quot;send-feedback-btn&quot; <br>  aria-label=&quot;Send Feedback&quot;<br>&gt;<br>  Send<br>&lt;/button&gt;</pre><p>Let’s move on, what is tabindex, and do we need it?</p><figure><img alt="A rockstar with a guitar shouts “What do we want?” and his fans shout “Tabindex”. The rockstar shouts back “How do we want it?” And the fans shout back “3 1 2.”" src="https://cdn-images-1.medium.com/max/583/1*t8CoglvxlbXBuapQdz0xGw.jpeg" /><figcaption>I swear I just put them in the right order… what happened tabindex!?</figcaption></figure><pre>&lt;!-- HTML --&gt;<br>&lt;button <br>  id=&quot;send-feedback-btn&quot; <br>  aria-label=&quot;Send feedback&quot;<br>  tabindex=&quot;0&quot; <br>&gt;<br>  Send<br>&lt;/button&gt;</pre><p>Setting the tabindex allows a developer to control if an element is keyboard focusable. But it is worth noting that by default most User Agents (the computer program that represents the person, often a Browser in this case) will automatically handle interactive elements like links and buttons by presuming they should be focusable. So you rarely need to set a tabindex manually unless you have an interactive element that <em>should not</em> be focusable, or you have a non-interactive element that <em>should</em> be focusable. A common mistake is manually attempting to order the tabindex, which can lead to confusing focus orders for the user and unmaintainable code. It’s considered a best practice to only use -1, or 0 as tab orders. You can read more <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex">here</a>. In our case, we have a button, it’s already focusable, and we don’t really need to add the tabindex attribute. And now it’s time to discuss titles.</p><figure><img alt="a queen, labled “programmer” is bestowing a title to a knight labled “button”" src="https://cdn-images-1.medium.com/max/500/1*3KkNhg6tHWanUpUlHUvrdw.jpeg" /><figcaption>Any more questions?</figcaption></figure><pre>&lt;!-- HTML --&gt;<br>&lt;button <br>  id=&quot;send-feedback-btn&quot; <br>  aria-label=&quot;Send feedback&quot;<br>  title=&quot;Send&quot;<br>&gt;<br>  Send<br>&lt;/button&gt;</pre><p>I know what you’re thinking, the aria-label is announcing “Send feedback” to the screen readers, and the text inside the button announced “Send” so why would the title have to do it? And you are totally correct. But what if the text inside the button was an icon? **<em>An additional note on icon usage can be found at the bottom of the article.</em></p><p>We don’t need it to announce “Send” because aria-label has our back for that. But what if the user hovers over the button? If I hovered over a bell icon, I’d normally see the word “notifications” or “alerts”. If we had an icon stand-in for our send button, we would want “send” as our hover. In our current case we don’t have an icon so we don’t need it, but it was worth taking a minute to discuss when we might. So lets move on and talk about focus styling.</p><pre>&lt;!-- HTML --&gt;<br>&lt;button <br>  id=&quot;send-feedback-btn&quot; <br>  aria-label=&quot;Send feedback&quot;<br>&gt;<br>  Send<br>&lt;/button&gt;</pre><pre>#send-feedback-btn:focus {<br>  outline: 2px solid #0000ff;<br>  /* Add custom focus styles */<br>}</pre><p>Focus styling is what the element looks like when your keyboard has focus. If you hit the “tab” key inside your browser multiple times, you’ll normally see a highlighted or outlined area, representing the active focused area. According to <a href="https://usability.yale.edu/web-accessibility/articles/focus-keyboard-operability#:~:text=Developers%20and%20designers%20are%20encouraged,background%20color%20changes%2C%20or%20animations.">Yale.edu</a></p><blockquote>Developers and designers are encouraged to design their own focus styles, including custom focus styles for particular elements.</blockquote><figure><img alt="Panel 1 image: A man stares at a paper, he’s squinting like it’s hard to read. Panel 1 text: “your actively focused elements on your website have no styling!?” Panel 2 image: The man is looking up at the camera looking disgusted. Panel 2 text: “I’m actually smiling. You probably just can’t see it. The same way I can’t see the actively focused elements on your website”" src="https://cdn-images-1.medium.com/max/500/1*4uoQK1DFpBVR8nzhL1Edgg.jpeg" /><figcaption>It’s a magic trick.</figcaption></figure><p>Play with this on your own, you’ll find numerous sites where the focus works, but sometimes elements don’t highlight. I was recently on a page where the main menu elements highlighted nicely, then everything else on the page included no indication of where the active focus was. It made it impossible to navigate. I was guessing, and eventually had to write down the order. That’s a very difficult experience if it’s your <em>only </em>way to navigate a website.</p><p>Those are the basics for making a *basic* button accessible, but every button is different. Different functions, and different styling, will impact this, and may have new requirements. It’s always a good idea to put your computer into voiceover and test how it’s working, or tab through it on your keyboard. Here are a few more accessibility notes for styling that apply to, not just buttons. We’ll start with color contrast.</p><figure><img alt="A colorblind test made up of orange circles, but has no contrasting green circles. (Normally there is a hidden message or image.)" src="https://cdn-images-1.medium.com/max/400/1*wOJY3GZwEtFFWjHsi_DHew.jpeg" /><figcaption>There’s nothing hidden in this colorblind test. I thought you should know what it feels like.</figcaption></figure><p>When styling buttons (or any element), you should ensure your color contrast meets certain standards. This is for people with visual impairments and color blindness. The best way I know to ensure you are meeting these standards is to visit <a href="https://accessibleweb.com/website-accessibility-checker/">accessibleweb</a> and use the free website scan tool, or the free chrome extension.</p><figure><img alt="A cat sits in front of a box with holes in it, batting its paws at fingers popping up from the holes." src="https://cdn-images-1.medium.com/max/425/1*TpG0xQccn1Azp39t3Vbr1Q.gif" /><figcaption>Ever had a button you just can’t press!?</figcaption></figure><p>Accessibility issues for dexterity have become so prevalent, we have a new word in the dictionary for them.</p><figure><img alt="screenshot from google shows the defition of fat fin·ger, INFORMAL • HUMOROUS, verb, past tense: fat-fingered; past participle: fat-fingered type (something) inaccurately by striking two keys at the same time with one finger." src="https://cdn-images-1.medium.com/max/1024/1*JlinlZo50aLRjIGEBnjhaQ.png" /><figcaption>That’s an official Oxford Language definition.</figcaption></figure><p>And while we may make jokes about having sent messages “Love you” to our co-worker “Dax”, instead of “Dad”, for many people dexterity accessibility is a real challenge in day to day life.</p><p>We can help ensure our websites are as accessible as possible by:</p><ul><li>Ensuring on computer screens buttons are at least 44x44px (or 7x7mm).</li><li>44x44px for touchscreens.</li><li>Ensuring there is enough spacing around clickable/touchable elements to prevent accidental activation. (The only thing more frustrating than not being able to hit a button, is accidentally hitting one your didn’t want to), and keeping that spacing consistent so the user it better able to understand the structure.</li><li>Making your designs responsive so buttons can display larger on smaller touchscreens where they may prove more difficult to target.</li><li>And as a stretch goal, letting users customize the size of buttons, so those with more dexterity challenges may be able to make the buttons larger and easier to touch. (For example Samsung phones have, or at least used to have, a fantastic mode called ‘Easy Mode’ which I have set up for many friend’s parents. The buttons are larger, the text is larger, and the interface is simpler. It makes using their phones far more comfortable for them. Good job Samsung.)</li></ul><figure><img alt="a picture of a trophy, and a glowing, sparkling sunburst. Text reads: “And the award goes to Samsung easy mode, for being an easy to set up accessible mode”" src="https://cdn-images-1.medium.com/max/581/1*BxySniIoeMhGZlEdNtkFlw.jpeg" /><figcaption>And I use an iphone.</figcaption></figure><p>**An addition note on icon usage:</p><p>Icons can be great for accessibility. When used properly, icons can transcend language or cognitive barriers (after all, you don’t need to be able to read, or read English to understand a save icon, or a back icon). But what counts as proper usage? <strong><em>Using</em></strong> <strong><em>established, known, intuitive, and commonly understood icons</em></strong>.</p><figure><img alt="A cropped view of Massimo Vignelli’s 1972 iconic redesign of the New York subway map." src="https://cdn-images-1.medium.com/max/1024/0*6zn4lLEn6DW7kAo6.jpg" /><figcaption>In 1972 iconic designer Massimo Vignelli redesigned the New York subway map in a way meant to be more user friendly, and that has influenced subway map designs to this day. The issue was, the map was <em>so far removed from what users expected and understood, it caused confusion even in its simplicity. Even when a design is in every way better, if it’s too far removed from what a user understands, it will fail in its purpose.</em></figcaption></figure><p>One of the best icons I can think of is a back arrow, which toddlers who aren’t yet verbal have proven to comprehend. The back arrow is established, known, intuitive, and commonly understood.</p><p>An established, known, commonly understood, but not intuitive icon would be a floppy disk as a save icon. We haven’t widely used floppy disks in over 20 years and younger generations may not know the object is, but it’s still widely recognized as meaning “save.”</p><p>The hamburger menu icon is a point of controversy within the design community. Despite being established, it’s not always known, it’s unintuitive, and often hard to notice. But having become standard makes it hard to replace. People don’t always look at a hamburger menu icon and immediately know what it will do, and this is why you see different solutions for this icon on different websites. Some may simply write “Menu.”</p><p>Bad icon usage would be using an unrecognized icon with no label. If you put a sad face icon in a menu, what does that mean? Is this icon for feedback? Support? A wall of shame? We can add a label and titles, but if it’s not generally understood, and intuitive, it may be best to re-think the icon.</p><p>I know this was a really long article to tell you to add just a few lines, because accessibility changes when our elements and components change, so I wanted to discuss what some of those changes involve. If you stuck with it to the end, an learned how to make a super simple button accessible, I encourage anybody who potentially read this far to try to remember that accessibility is not a frustrating extra step. It’s something we should all be thinking about, because if I walk to another level in a building, a person in a wheelchair should have a way to also access that level. If I navigate an online store to buy some new clothes, a visually impaired person should also be able to navigate that website to buy some new clothes. If I’m cruising through your website, somebody with tremors in their hands should be able to manage it as well.</p><p>And now that I made a strong closing statement I’m going to end this with a High School Musical meme.</p><figure><img alt="a scene of the teens dancing at the end of High School Musical, text says “We’re all in this together and it shows when stand hand in hand. Make our dreams come true.”" src="https://cdn-images-1.medium.com/max/1024/1*1FgV8710pmmPGiNSCAmeFQ.png" /><figcaption>I know Troy &amp; Gabriella are still together in the High School Musical world, and living happily ever after.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=465e294cba82" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Simple and Not Boring Guide to Rounding Accurately in Javascript]]></title>
            <link>https://jessijokes.medium.com/the-simple-and-not-boring-guide-to-rounding-accurately-in-javascript-98748810fccf?source=rss-acd37bc22d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/98748810fccf</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[math]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Jessica Bradham]]></dc:creator>
            <pubDate>Thu, 16 Nov 2023 07:47:38 GMT</pubDate>
            <atom:updated>2023-11-16T07:48:29.927Z</atom:updated>
            <content:encoded><![CDATA[<p>There is a big problem in javascript. You might have heard software engineers joke that Javascript is bad at math, and if you’ve ever tried to have Javascript do some math for you, for example</p><figure><img alt="a javascript console showing “.11 + .7” and the return value is “0.8099999999999999”" src="https://cdn-images-1.medium.com/max/288/1*4hInlsLytyh8_QMj0qg2cg.png" /><figcaption>Javascript says .11 + .7 = 0.809999999(…) but my calculator says it’s .81</figcaption></figure><p>Or perhaps you’ve tried some rounding, and gotten an unexpected result such as</p><figure><img alt="A javascript console showing “Math.round(1.005 * 100) / 100” and the return value is “1”" src="https://cdn-images-1.medium.com/max/456/1*ZdhXYL7PxtuZJ5GSP4OPVw.png" /><figcaption>If I make that number “1.0055” instead of “1.005” it returns “1.01” instead of “1”</figcaption></figure><p>There are a number of posts explaining the details about why this is happening, so I’m just going to focus on fixing it. Because it’s a lengthy explanation, and this post is just about fixing it.</p><p>A common solution is to use the method toFixed() in order to correct this mistake. And I can just hear you asking, “Well if it works, why not?”</p><figure><img alt="A meme says “The Loudest Sounds on Earth” and shows a bar chart, listing from quietest to loudest: Concert Speakers, Fireworks, Gunfire, Blue Whale, Space Shuttle, and finally “You asking ‘Why not use toFixed tho!?’”" src="https://cdn-images-1.medium.com/max/604/1*GMVox8bD1kdaebGWaSsnyg.jpeg" /><figcaption>Omg I’m getting to the answer!</figcaption></figure><p>Well there are a few reasons I wouldn’t recommend it, one of them being that toFixed is converting your float to a string, which means you have to run parseInt to convert the type back, and running parseInt leaves it prone to new inaccuracies. Doing all those conversions can all a lot of unnecessary time to your function (even these built in functions have a time cost.)</p><p>But my favorite reason to not use toFixed is it’s still not accurate.</p><figure><img alt="A javascript console shows “(1.005).toFixed(2)” and the return value is “‘1.00’”" src="https://cdn-images-1.medium.com/max/320/1*HPhYGyLOTxB9hxwRhMY8-Q.png" /><figcaption>Wasn’t that supposed to be 1.01? 😒</figcaption></figure><p>So don’t use it to try to fix rounding errors.</p><figure><img alt="A meme shows Sandy from spongebob on a platform with a megaphone shouting. Text says “Drop toFixed() and back away slowly”" src="https://cdn-images-1.medium.com/max/654/1*C032fm0gGyLSiwYVljAUDg.jpeg" /><figcaption>Don’t even look at it. If you use it, you better have a reason. Like you need a string returned.</figcaption></figure><p>On to the solution! What’s a poor Software Engineer who really just needs to round 1.005 to do!?</p><figure><img alt="A meme shows Steve Harvey playing family feud, looking uncertain. The question is “How to round floating points accurately in javascript!?” The answers are, “A: give up and cry”, “B: Read the rest of this blog”, “C: wish on a star”, “D: Blackmail a leprechaun”" src="https://cdn-images-1.medium.com/max/640/1*KrmXiOKoQM9pLr0LwkTi8g.jpeg" /><figcaption>Can I phone a friend?!</figcaption></figure><p>Well the answer looks scary, and sounds scary, but it isn’t as complicated as you’d imagine. We’re going to use exponential notation.</p><figure><img alt="An anime meme in three panels shows a girl labeled “exponential notation” following a boy labeled “you”. In the second panel, she starts to run and he runs away. In the third panel she is chasing him, and he’s running fast." src="https://cdn-images-1.medium.com/max/501/1*NuuahEiVUi-SnnguSVanqQ.jpeg" /><figcaption>Get back here! I said it wasn’t that scary!</figcaption></figure><p>Again. There are great articles breaking down exponential notation. I’m just going to show you how to use it! So no need to fear!</p><figure><img alt="A javascript console which says “Number(Math.round(1.005 + ‘e2’) + ‘e-2’)” and the return value reads, “1.01”" src="https://cdn-images-1.medium.com/max/622/1*SqQaXcDtH4sZr-USp696pg.png" /><figcaption>It’s that easy, we get to us ‘e2’ and ‘e-2’ as a shortcut.</figcaption></figure><p>So instead of (1.005 * 100) / 100 we’re going to be doing (e3 and e-3 if you want it rounding to the thousands place, e4 and e-4 for ten thousands, etc. This is e-notation in javascript).</p><figure><img alt="A meme of drake looking away and holding his hand up as if to stop something. The meme says “console.log((Number(Math.round(1.005 * 100) / 100)), in the second panel Drake looks happy and the meme says ‘console.log(Number(Math.round(1.005 + “e” + 2) + “e-” + 2))’" src="https://cdn-images-1.medium.com/max/500/1*ciXBdCvvDV_BfQUo7ncXRQ.jpeg" /><figcaption>this uses a setup where the 2 could be replaced with a variable, because I’m a lazy duck and copied some old code of mine and just wrote the two</figcaption></figure><p>And there we have it. It’s as simple as that. Enjoy your newfound powers of accurate rounding in Javascript, all without converting your data type.</p><figure><img alt="A meme of Meghan Trainer from the Music Video “All About that Bass” except it says “You know I’m all about that exponential notation, no string conversion”" src="https://cdn-images-1.medium.com/max/620/1*I27wvyMkZ-80Fl-mOEgzSQ.jpeg" /><figcaption>Because converting data types can lead to unexpected bugs. Ask me how I know? I once got assigned, and had to fix a bug where the number was being converted to a string, and then sent to an API that expected a number. I now feel like a wisened old exponential-notation war veteran, sitting in my rocking chair, warning the youth about the evils of toFixed.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98748810fccf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solving the Leetcode “Container with Most Water” problem in Javascript]]></title>
            <link>https://jessijokes.medium.com/solving-the-leetcode-container-with-most-water-problem-f720c4f0dacd?source=rss-acd37bc22d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f720c4f0dacd</guid>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[leetcode]]></category>
            <category><![CDATA[container-with-most-water]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Jessica Bradham]]></dc:creator>
            <pubDate>Wed, 01 Dec 2021 06:37:09 GMT</pubDate>
            <atom:updated>2021-12-08T05:16:56.147Z</atom:updated>
            <content:encoded><![CDATA[<p>A few years ago I went with a friend to an amusement park, and he challenged me to go on a ride with him called the Ripcord. If you don’t know what this ride is, they attach you to a harness, haul you up between three towers of scaffolding, then they drop you. It just seemed so doable until I was standing at the base of those towers in a harness, looking straight up. And honestly, that’s how some leetcode questions hard. The title says, “<a href="https://leetcode.com/problems/container-with-most-water/">Container With the Most Water</a>” and you think “Wow, that sounds so doable.” Then you open it and it just seems so intimidating. But that day, I got hauled 180 feet into the air, and dropped. As terrifying as it was <em>before </em>I did it, afterward I realized it wasn’t nearly as intimidating as it looked. This holds true for this leetcode question, and I’m here to walk you through it.</p><figure><img alt="A photo of a ripcord amusement park ride." src="https://cdn-images-1.medium.com/max/736/0*mEIfV6t_ZivXmzM7.jpg" /></figure><p>The first challenge for me with any leetcode question is understanding the actual problem, and that’s where a lot of the intimidation comes from at first. So let’s take a look at the instructions for the leetcode problem <a href="https://leetcode.com/problems/container-with-most-water/">Container with Most Water</a>. We’ll be doing this problem in Javascript just as a heads up.</p><pre>Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of the line i is at (i, ai) and (i, 0). Find two lines, which, together with the x-axis forms a container, such that the container contains the most water.</pre><pre><strong>Notice</strong> that you may not slant the container.</pre><p>Now maybe you read this and thought, “Yeah, that totally makes sense because I’m a smart intellectual.” And if so, dang. You are a smart intellectual. But I was sitting over here thinking, “Yup. Those are all words, and I can read them all.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*P4S3veZr0fkEclUo.jpg" /><figcaption>This was my reaction to reading the instructions for this problem for the first time.</figcaption></figure><p>So it took me a few minutes of reading, and rereading the instructions, and comparing them to the examples before I understood the actual problem. If you are more like me, let’s talk about what our actual goal is here.</p><p>If we look at example 1, it will help us better understand what we are looking for. In more plain words, we’re given an array of numbers, and those numbers represent bars/barriers/walls, (however you need to think of it) that you could pour water into and it would get trapped between them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/0*yToDk2bSCma8xIk9.jpg" /></figure><pre><strong>Input:</strong> height = [1,8,6,2,5,4,8,3,7]<br><strong>Output:</strong> 49<br><strong>Explanation:</strong> The above vertical lines are represented by array [1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.</pre><p>Here are a few important things to remember when we are taking on this challenge.</p><ol><li>This is a 2-dimensional grid, we aren’t worried about the depth of the space</li><li>We can’t simply select the two tallest bars, because the <em>space between the bars </em>will impact how much water can be held.</li><li>Likewise we can’t select the two furthest bars, because the <em>height </em>of the bars will impact how much water can be held.</li><li>A real key important fact here. It’s unlikely we’ll find 2 bars of the same height, and in that circumstance, the <em>smaller height bar </em>will dictate the amount of water being held.</li></ol><p>Keep these things in mind as we go forward. When I first approached this, it honestly felt a bit overwhelming. There was so much I needed to do and factor in, the varying heights, how to find the largest area, how to do the calculation, and on top of it, I wanted to get that O(n) time! My brain was spinning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*Z7VjDJf_91MoCJ37CVL1cQ.gif" /><figcaption>I relate to Lizzie McGuire so much.</figcaption></figure><p>We’re going to look for a brute force solution first. And we’re going to break this into steps. The first thing I did, was figure out how to calculate the area. So I literally pulled out a notepad and just wrote out some notes. What I came up with was this.</p><ol><li>I needed to determine which wall (number in the array) was bigger</li><li>I needed to figure out the distance between the walls by subtracting their indexes</li><li>I needed to multiply the value of the smaller wall, by the difference of the indexes</li></ol><p>At that point, everything just clicked. I knew how to get the area of two walls, so now all I had to do was compare them to get a brute force solution. So I set up a variable to contain the highest water total, created a double loop, then used the Math.max function in Javascript to run through each possible area, and always save the highest one. Here is what this looks like, and if you don’t understand it, don’t worry I’m still going to walk through it line by line. One thing to notice is that I changed the argument name from <strong><em>height</em></strong> to <strong><em>heights</em></strong> because it made more sense to me since it was taking in multiple values.</p><pre>var maxArea = function(heights) {<br>    let highestWater = 0<br>    for (let i = 0; i &lt; heights.length; i++) {<br>        for (let j = (i + 1); j &lt; heights.length; j++) {<br>            const smallerWater = Math.min(heights[i], heights[j])<br>            const currentWater = (smallerWater * (j-i))<br>            highestWater = Math.max(currentWater, highestWater)<br>        }<br>    }<br>    return highestWater<br>}</pre><p>Line by Line for the brute force solution:</p><pre>let highestWater = 0</pre><p>This one is pretty easy. This is a variable I set to hold my highest water. Since all values are non-negative, I felt pretty safe initiating it at zero.</p><p>Let’s talk about what this double loop is doing!</p><pre>for (let i = 0; i &lt; heights.length; i++) {<br>        for (let j = (i + 1); j &lt; heights.length; j++) {<br>  }<br>}</pre><p>If you are familiar with double loops in javascript, you can skip this ;) But if you don’t quite understand I’m going to walk you through it.</p><p>The first loop is going to run while i is less than heights.length, and it initiates at 0. So if there are 5 numbers in the heights array, the loop will run 4 times, because when it hits 5 it will now be equal to heights. So if our input array was [1,8,6,2], and we did a ‘console.log(heights[i])’ it would log 1, 8, 6, 2.</p><p>The second loop is similar in that it will also stop when it hits the end of the array length, BUT there is a crucial difference. I’m initiating the j variable as i + 1. The difference that will make is this. Let’s say we were to console log these values, again anticipating an input of [1,8,6,2].</p><pre>for (let i = 0; i &lt; heights.length; i++) {<br>    console.log(heights[i])<br>        for (let j = (i + 1); j &lt; heights.length; j++) {<br>        console.log(heights[j])<br>  }<br>}</pre><p>Our console would look like this. 1, 8, 6, 2, 8, 6, 2, 6, 2, 2. Does this make sense? If not here is another visual. I’m going to write this again with a (i) or (j) depending on which loop is logging the number. 1(i), 8(j), 6(j), 2(j), 8(i), 6(j), 2(j), 6(i), 2(j), 2(i). I’m essentially working with 2 points, i, and j.</p><p>The reason I’m doing it like this is because we only need to check each pair once. We need to know the value of 1 and 8, and the value of 8 and 1 would be exactly the same. Going backwards is the same distance, which bar is taller will still be the same, and the area will still be the same because the distance of the indexes is still the same. This also prevents me from having to write code to recognize when my pointers are at the same index (which could cause bugs in my code).</p><pre>const smallerWater = Math.min(heights[i], heights[j])</pre><p>In this line of code I’m using Math.min() which takes two arguments (or you can use the spread operator to spread an array as an argument) and it returns the smallest value. In this vase, I’m using it to assign the smaller index between my i pointer, and my j pointer. So it’s literally picking the smaller wall/bar. As an example, if my input was [1,8,6,2], and i was on index 1, and j was on index 3, smallerWater would be = to 2.</p><pre>const currentWater = (smallerWater * (j-i))</pre><p>Then I am calculating what the area of the water is between the bars my points are currently on by multiplying the value of the smaller bar, by the difference of the indexes. Remember that j starts at i+1, so j will ALWAYS be greater than i, so it’s safe to subtract j from i to get the distance. Following the example from the last paragraph, if j = 3, i=1, and smallerWater = 2, our math looks like this. (2 * (3–1)). 3–1 is in the parentheses so we subtract that first and get 2 and now we have (2 * 2), and 2*2 = 4. So currentWater would be = 4.</p><pre>highestWater = Math.max(currentWater, highestWater)</pre><p>The last thing I did was assign that variable we set outside the double loop, highestWater to be = to Math.max(currentWater, highestWater). Remember Math.min? Well Math.max literally does exactly the opposite. It returns the <em>higher </em>value. So it compares currentWater to what has been saved previously in highestWater, saves whichever is higher, and continues on with it’s loopy ways.</p><p>Now if you enter this solution into leetcode, it will accept it if you hit runcode. But it will not accept it if you hit Submit.</p><p>That’s because this is a level <strong>MEDIUM </strong>question and they expect better optimization than a brute force solution. This means one of the submit tests has a HUGE array that will time out your code. It doesn’t really want to be doing any double loop shenanigans. So now that we’ve figured out the brute force solution. It’s time to optimize.</p><p>There are a few things to consider when we look at optimization. First off</p><ol><li>Only the smaller bar mattered into our math, remember we picked between the larger and smaller bar</li><li>We don’t actually do anything in that outer loop. It was just a convenient way to check every item against itself.</li></ol><p>That being said, I knew the solution was going to be the 2 pointer method. But I did struggle a bit to implement it at first, because it was my first time actually putting it into practice. So, let’s talk about it. What’s the 2 pointer method?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/0*IO4TaSQ7ylfZMQ68.png" /></figure><p>Well really, it’s just using 2 pointers in a single loop and moving them through an array. Most frequently you’ll see this though. One pointer on the left, one pointer on the right, and they meet somewhere in the middle. This is often a great method for getting yourself out of a nested loop. Now keep in mind, only the smaller value matters when we are comparing these pointers, that makes it easier to decide which to move.</p><p>So let’s take a look at, and go line by line on the optimized solution.</p><pre>var maxArea = function(heights) {<br>    if (heights.length &lt;= 1) return 0<br>    let highestWater = 0;<br>    <br>    let p1 = 0<br>    let p2 = heights.length-1<br>    <br>    while (p1 &lt; p2) {<br>        const smallerWater = Math.min(heights[p1], heights[p2]);<br>        const width = p2 - p1;<br>        const currentWater = smallerWater * width;<br>        highestWater = Math.max(highestWater, currentWater);<br>        heights[p1] &lt;= heights[p2] ? p1++ : p2-- <br>        <br>    }<br>    return highestWater<br>}</pre><p>So first we’ll start with</p><pre>if (heights.length &lt;= 1) return 0</pre><p>If the length of the heights array is less than or equal to 1, then there is nothing to multiply, so we can safely return 0.</p><pre>let highestWater = 0;<br>    <br>let p1 = 0<br>let p2 = heights.length-1</pre><p>Next we are setting some initial variables. As before, highestWater = 0. Then I set variables for my pointers, you could name these left and right, i and j, or p1 and p2. Whatever makes the most sense to you. The left pointer will start at 0, and the right pointer will start at the length of the array minus 1 because remember, arrays start at 0, so if there are 5 elements in an array, those indexes are 0, 1, 2, 3, 4, which means we need our second pointer to start at heights.length-1 (or in my example, index 4).</p><pre>while (p1 &lt; p2) {<br>}</pre><p>This is pretty simple. A while loop. While pointer 1 is less than pointer 2. If they hit each other, it stops.</p><pre>const smallerWater = Math.min(heights[p1], heights[p2]);</pre><p>Does this bit of code look familiar? It should. It’s pretty much exactly the same as last time, except this time, it’s using the p1 and p2 variables to call the indexes.</p><pre>const width = p2 - p1;<br>const currentWater = smallerWater * width;</pre><p>This one is almost exactly the same but for readability I saved width to a variable of it’s own. But currentWater is still = to smallerWater * (p2-p1). So nothing has changed.</p><pre>highestWater = Math.max(highestWater, currentWater);</pre><p>Exactly the same. Is this blowing your mind? Here is the only difference.</p><pre>heights[p1] &lt;= heights[p2] ? p1++ : p2--</pre><p>So instead of having that double loop checking every value, here I’m using a ternary conditional to check if the first pointer’s value is less than or equal to the second pointer’s value. If it is, it increments the first pointer, and if not, it decrements the second pointer, moving them closer together. This works because the two major factors of our equation are width, and the smaller height of the column. Let’s look at an example.</p><p>Remember last time we used this as an example: [1,8,6,2]</p><p>P1 starts on 1 (index 0)| P2 starts on 2 (index 3)</p><p>It will calculate the max area. The width is 4, and the smaller column is 1. 1*3 is 3. This becomes our currentWater. Our highestWater is currently 0, so when it calculates the max, 3 becomes our highestWater.</p><p>Then it checks if 1 ≤= 2 ? 1 is in fact less than 2. So it increments the pointer on 1.</p><p>Now P1 is on 8 (index 1)| P2 is still on 2 (index 3)</p><p>The width of these is 2 (3–1), we take the smaller number (2) and multiply that by the width (2) and we have 4, which becomes the currentWater. The currentWater is greater than the highestWater so highestWater also becomes 4.</p><p>8 ≤= 2? nope. This means we decrement the pointer that was on 2.</p><p>So now our pointers are P1 is on 8 (index 1) | P2 is on 6 (index 2)</p><p>The width is 2–1 (1). We take the smaller number (8 vs 6, so we need 6), and multiply that by the width (1). 6x1 is 6, which becomes the currentWater. 6 is greater than 4 so it also becomes the highestWater.</p><p>Because our pointers are currently on 1 and 2, the next move of a pointer will make them equal and will break us out of our loop.</p><p>And this is the easy and most satisfying part. At this point, all we have to do is return our answer</p><pre>return highestWater</pre><p>And have the satisfaction of knowing that:</p><pre>Runtime: 76 ms, faster than 98.21% of JavaScript online submissions for Container With Most Water.</pre><pre>Memory Usage: 48.3 MB, less than 28.61% of JavaScript online submissions for Container With Most Water.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*c1HKvmVKocd9P4SV.jpg" /></figure><p>With all of these leetcode problems, just try to take them in small steps. Don’t try to get a perfect solution right off the bat. Sometimes getting something small, like figuring out how to calculate the area can be the key you need to unlocking the rest of the problem for yourself.</p><p>And the next time you are staring at an intimidating leetcode question, or possibly even an amusement park ride, I want you to remember this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*26AFOwefUGXsT0QD.jpeg" /><figcaption>You can do it. Danny Trejo believes in you.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f720c4f0dacd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Finding a Perfect Fit with React]]></title>
            <link>https://jessijokes.medium.com/finding-a-perfect-fit-with-react-74ea6a5b6cc5?source=rss-acd37bc22d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/74ea6a5b6cc5</guid>
            <category><![CDATA[jwt]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Jessica Bradham]]></dc:creator>
            <pubDate>Sat, 30 Oct 2021 00:09:03 GMT</pubDate>
            <atom:updated>2021-10-30T00:09:03.303Z</atom:updated>
            <content:encoded><![CDATA[<p>8 models, a custom written hash for my API, a dynamic form, submitting a nested dynamic object and dynamically creating all the objects from it, authentication with JWT tokens, utilizing hash router as opposed to the standard react router to utilize a single page application through github pages, and so much conditional rendering. Those are just some of the challenges I faced when I built my final project for Flatiron School. I’m going to talk about two of them today. Authentication, and my dynamic form.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TWdCYpT69vh8t2LX33TWmQ.png" /><figcaption>Culturefit is built in React and Rails</figcaption></figure><p>Culturefit is a web app built with React &amp; Redux, using Rails as an API for the backend. The app allows users to sign up as a “company” or a “job seeker”.</p><p>Companies can create screener surveys for job applicants, it’s important to note these are not quizzes, they are closer to personality tests. The idea being to help companies see past what is immediately on paper and find people who fit with their culture.</p><p>Job applicants can take screener surveys and their results will submit back for the companies to view and compare.</p><p>The very first challenge I faced was authentication. I’ve done authentication in php, sinatra, and rails before so I remember thinking, “This won’t be hard.” Famous last words! On the back end you are issuing and encoding a JWT token, on the front end you are storing that token in the local storage (which you can also use to keep the logged in state when you refresh the app), and use the “Authenticate” header to pass the token back to rails to make requests to the server. As another student and I found out though, CORS requests require an additional line in the headers to make authenticated server requests once logged in. “Access-Control-Allow-Headers” allows “Authorization” to pass to rails, otherwise rails will not receive it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*eUY9j3kT27zE4OWWVt0_BQ.png" /><figcaption>The missing link.</figcaption></figure><p>The next challenge I faced was setting up my dynamic form to create my surveys.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4n7_lErFNi_fr2wKsoLrHw.png" /><figcaption>The dynamic form to submit a new survey.</figcaption></figure><p>The concept was that companies could create really customized screener quizzes, whether that be true or false questions to look for outgoing/introverted employees or surveys with many answers that determine what attributes you prioritize as a programmer (for example, speed, readability in code, ram, etc. Different choices would add points to different attributes.)</p><p>This lead to a pretty complicated state, form tracking, and submission.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*odveI_9fuztlNO3a0Tqp4A.png" /><figcaption>This blank object is how we create the initial blank form.</figcaption></figure><p>Then I map the questions array, creating a label and input for each question. After that I map over the answers array and create a label and input for both the answers and attributes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*gdpp6Uqnb-YlOqzEXaOliQ.png" /><figcaption>A very complicated iteration.</figcaption></figure><p>As you can see I’m also assigning a few onChange events, these log the contents of the fields to the state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*lFQKIyb0-UQF8XQ_jVsefA.png" /><figcaption>Three handle change events to handle the state of the dynamic objects.</figcaption></figure><p>In order to handle these objects, we utilize the index of the array (which I’m tracking when I map over them). Each function takes in the index, or in the nested functions case the index of the outer and inner loop, so it can assign our values dynamically. First we save our questions array to a variable (using the spread operator), then we utilize the parameters passed through the function to update the specific element we are changing, then we use setState to update questions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/439/1*763pkBT1lMp4IWnnEQHeRA.png" /><figcaption>The buttons to add questions and answers.</figcaption></figure><p>The buttons to add questions and answers are using a similar method, I save a template of what a new question (or answer) looks like to a variable. Then I’m able to use the spread operator to combine the new information with the existing information, which adds the new object. React does the rest when state is updated, displaying the new field.</p><p>Creating it on the server side was an entirely different story. The first thing I had to do was learn how to deeply nest strong params since I was passing a deeply nested object, after that my create function required creating a survey, then checking if it saves, and if so, iterating through the questions and making each question, if the questions save, iterating through the answers/attributes and creating those. (Which I’m not showing off until I’ve refactored it.)</p><p>As for future goals for the project, I’m currently finishing up a message board with asynchronous posting utilized Redux Thunk, and I am hoping to get the site (which is *nearly* fully mobile friendly) fully responsive.</p><p>If you’d like to check out the project on github you can view the backend code here</p><p><a href="https://github.com/jessijoke/culturefit">GitHub - jessijoke/culturefit: A web application for screening job applicants.</a></p><p>Or the frontend here</p><p><a href="https://github.com/jessijoke/culturefit-front">GitHub - jessijoke/culturefit-front: Frontend of CultureFit</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74ea6a5b6cc5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Good Dog Javascript, Now Fetch!]]></title>
            <link>https://jessijokes.medium.com/good-dog-javascript-now-fetch-44a882b73205?source=rss-acd37bc22d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/44a882b73205</guid>
            <category><![CDATA[json]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[promises]]></category>
            <category><![CDATA[asynchronous]]></category>
            <category><![CDATA[fetch]]></category>
            <dc:creator><![CDATA[Jessica Bradham]]></dc:creator>
            <pubDate>Wed, 23 Jun 2021 21:26:48 GMT</pubDate>
            <atom:updated>2021-06-23T21:26:48.920Z</atom:updated>
            <content:encoded><![CDATA[<p>I don’t think I’m capable of writing an article about the Javascript Fetch API without making Dad jokes, and referencing cheesy memes, because there are just too many good ones. So brace yourself. We’re about to break down Fetch, Promises, and Json.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*Tgy9KViUJFQiesu8.jpg" /><figcaption>Stop trying to make Fetch happen!</figcaption></figure><p>The first thing to know is that Fetch requests are asynchronous. Asynchronous code behaves by creating independent stacks so your code can run separately, allowing multiple things to run at the same time. As opposed to synchronous code which is more like a really long to-do list where a task can’t be completed until it finishes the previous tasks. It can be tricky to keep these words separate, especially if you have ADD like I do, so I’m going to give you a pro tip. Try to associate the behavior with method. If somebody were to ask you to describe how Fetch requests are asynchronous, try to focus on how you know Fetch behaves, rather than the word itself. You know fetch doesn’t stop an entire program to complete its task. So you can use context to help keep the words straight.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*u6PMQOwQTqixYSXe.png" /><figcaption>Aren’t they though?</figcaption></figure><p>The next thing to know about Fetch is that it returns a promise. We can literally write:</p><p>console.log(fetch(‘<a href="https://pokeapi.co/api/v2/pokemon&#39;">https://pokeapi.co/api/v2/pokemon&#39;</a>));</p><p>We don’t need to write anything other than that, and we’ll see in our console that it has returned</p><p>Promise {&lt;pending&gt;}</p><p>So the next big question is, what is a promise?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1KttEFdhns_aP4v7.png" /><figcaption>Promises Promises, Check this hand cause I’m marvelous</figcaption></figure><p>Promises are objects that represent an asynchronous event and whatever results from it, whether it succeeds or fails, they are shamelessly promising results, they’re just being kind of vague about what those results are going to be, as you could see by my ‘pending’ promise.</p><p>In order to have our promise return successful we’re going to use .then to log the response of Fetch.</p><p>fetch(‘<a href="https://pokeapi.co/api/v2/pokemon&#39;">https://pokeapi.co/api/v2/pokemon&#39;</a>)<br>.then(resp =&gt; console.log(resp))</p><p>Promise {&lt;pending&gt;}</p><ol><li><em>Response {type: “basic”, url: “https://pokeapi.co/api/v2/pokemon&quot;, redirected: false, status: 200, ok: true, …}</em></li><li>body: (…)</li><li>bodyUsed: false</li><li>headers: Headers {}</li><li>ok: true</li><li>redirected: false</li><li>status: 200</li><li>statusText: “”</li><li>type: “basic”</li><li>url: “https://pokeapi.co/api/v2/pokemon&quot;</li><li>__proto__: Response</li></ol><p>At this point we can see a response but it is not usable data. But For example if I try typing</p><p>fetch(‘<a href="https://pokeapi.co/api/v2/pokemon&#39;">https://pokeapi.co/api/v2/pokemon&#39;</a>)<br>.then(resp =&gt; console.log(resp.body))</p><p>I’ll get</p><p>ReadableStream {locked: false}</p><p>But if I were to do this instead (and here I switched to a specific Pokemon to lower the amount of results I was getting).</p><p>fetch(‘<a href="https://pokeapi.co/api/v2/pokemon/3&#39;">https://pokeapi.co/api/v2/pokemon/3&#39;</a>)<br>.then(resp =&gt; resp.json()) //Converting the response to a JSON<br>.then(json =&gt; console.log(json.abilities)); //Logging the JSON and calling the .abilities key</p><p>I’m now able to access this data</p><ol><li><em>(2) [{…}, {…}]</em></li><li>0: {ability: {…}, is_hidden: false, slot: 1}</li><li>1: {ability: {…}, is_hidden: true, slot: 3}</li><li>length: 2</li><li>__proto__: Array(0)</li></ol><p>So I guess at this point it’s time to ask the question, what the heck is JSON anyway?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/0*Ysh6y1wmB3JMX1Dz.jpeg" /><figcaption>Me too Andy. Me too.</figcaption></figure><p>JSON stands for Javascript Object Notation. This is something I never remember when I’m asked if I’m going to be totally honest, and I’ve been using JSON files for <em>years. </em>Literally. I built a portfolio site a couple years ago that used a JSON file to populate all of the projects, and main information so it could be easily updated. I created a pizza website where I made a menu out of JSON file so it could be easily updated. I used to make Read Along Audio books where we had to create long JSON files of audio timestamp data for when each word in the audio file started. And Stopped. Started. And Stopped. JSON files are extremely versatile and valuable, and has a million uses. They are even used as databases! (Though I wouldn’t call it my favorite use case, I would probably say I prefer it to logging timestamped audio though. Let’s not to that again. Ever.)</p><p>So what is it? A really watered down explanation would be that JSON format allows us to store/handle/process information in a lightweight format using arrays and key value pairs (think Hashes). By converting our response to json, we are making it into a usable format.</p><p>Now I know what you’re thinking, it’s all well and good, but what happens if your Fetch request isn’t successful!?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/0*wfpQ7WJadKel30OY.jpg" /><figcaption>Don’t worry Gru, we’ve all been there.</figcaption></figure><p>Some nefarious user is trying to search for a Pokemon that doesn’t exist.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/0*mrGjDBCrbFpOKDZh.jpg" /><figcaption>You see that minion on the far left looking directly at the camera, almost not in the frame? I’m pretty sure it was him.</figcaption></figure><p>So what happens now!? Everything just breaks? Those little chicken mcnuggets wish! Because we have a solution for that, and it’s called Catch. So when those walking mischievous mini corndogs get up to no good, all we need is this extra line</p><p>Fetch(‘<a href="https://pokeapi.co/api/v2/pokemon/3&#39;">https://pokeapi.co/api/v2/pokemon/3&#39;</a>)<br>.then(resp =&gt; resp.json())<br>.then(json =&gt; console.log(json.abilities))<br>.catch(error =&gt; console.log(“Knock it off or I’m feeding you to the mean girl from the first meme!”))</p><p>And they’ll have a frightening warning delivered to them.</p><p>Now let’s look at customizing this Fetch request. Because right now this is pretty generic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*NMGADh_gyii3b1gl.jpg" /><figcaption>Some common http methods are POST, GET, PUT, &amp; DELETE. This horse seems to like POST best.</figcaption></figure><p>If we want to further customize our Fetch request we can open a block after the initial URL in the Fetch() like this.</p><p>fetch(‘<a href="https://pokeapi.co/api/v2/pokemon/3&#39;">https://pokeapi.co/api/v2/pokemon/3&#39;</a>, {<br>})<br>.then(resp =&gt; resp.json())<br>.then(json =&gt; console.log(json))<br>.catch(error =&gt; console.log(error))</p><p>And while there are TONS of options we could discuss in here, I’m going to specifically focus on 3 today. Method, Body, and Headers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*p48bPl596MtDPIZ3.jpg" /><figcaption>Did you think I’d be out of memes yet?</figcaption></figure><p>Method is where we are going to tell the fetch request what type of request we are making. As you saw in my previous examples, the default behavior is a GET method, but if you are wanting to create, delete, or update, you’ll need to explicitly state your method. Luckily this is pretty easy!</p><p>fetch(‘<a href="https://pokeapi.co/api/v2/pokemon/3&#39;">https://pokeapi.co/api/v2/pokemon/3&#39;</a>, {<br> method: ‘POST’<br>})<br>.then(resp =&gt; resp.json())<br>.then(json =&gt; console.log(json))<br>.catch(error =&gt; console.log(error))</p><p>I know you are sitting over there shouting “IT CAN’T BE THAT EASY!?” But it is. It really is. The next step though is to convert that data into something our program can understand easier. Just like how we converted the response to JSON, when we are posting an object we want to convert it to a JSON string for our program.</p><p>fetch(‘<a href="https://pokeapi.co/api/v2/pokemon/3&#39;">https://pokeapi.co/api/v2/pokemon/3&#39;</a>, {<br> method: ‘POST’,<br> body: JSON.stringify(data)<br>})<br>.then(resp =&gt; resp.json())<br>.then(json =&gt; console.log(json))<br>.catch(error =&gt; console.log(error))</p><p>An important thing to remember, straight from MDN docs, is that the header content type must match the body type. So if you are using JSON.stringify(data), you want to match your type with ‘Content-Type’: ‘application/json’ so they are both JSON types. Likewise ‘Accept’ will make it known which content types the client can understand.</p><p>fetch(‘<a href="https://pokeapi.co/api/v2/pokemon/3&#39;">https://pokeapi.co/api/v2/pokemon/3&#39;</a>, {<br> method: ‘POST’,<br> body: JSON.stringify(data),<br> headers: {<br> ‘Content-Type’: ‘application/json’,<br> ‘Accept’: ‘application/json’<br> }<br>})<br>.then(resp =&gt; resp.json())<br>.then(json =&gt; console.log(json))<br>.catch(error =&gt; console.log(error))</p><p>Well, that’s a pretty thorough breakdown of using fetch in Javascript. If you’d like to know more…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vmdwEhcaNRqp9iC-.jpg" /><figcaption>Did you really think there wouldn’t be one more meme?</figcaption></figure><p>Just kidding. Aliens don’t use fetch, they use probe. I’d rely on MDN for documentation. At least until the aliens give up the probes.</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch">Using the Fetch API - Web APIs | MDN</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44a882b73205" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Parallax Animations, Solar System Puzzles, and Polymorphic Associations]]></title>
            <link>https://jessijokes.medium.com/parallax-animations-solar-system-puzzles-and-polymorphic-associations-ba0e96c201d5?source=rss-acd37bc22d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba0e96c201d5</guid>
            <category><![CDATA[polymorphic-association]]></category>
            <category><![CDATA[rails-api]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[createjs]]></category>
            <dc:creator><![CDATA[Jessica Bradham]]></dc:creator>
            <pubDate>Sun, 20 Jun 2021 17:32:55 GMT</pubDate>
            <atom:updated>2021-06-20T17:32:55.385Z</atom:updated>
            <content:encoded><![CDATA[<p>They say if you have no idea what to do when you are decorating a room, pick a piece of furniture and design around it. This is the method I used to pick my project idea for phase 4 of Flatiron’s software development program. Since we were getting into javascript, I knew I wanted to use javascript to create a cursor based parallax animation, using the parallax effect to create fake depth. I felt the most intuitive and easiest concept for this was space, with layers of stars. This I was doing space, an Air and Space Museum website just seemed like the project that made the most sense.</p><p>So the first thing I worked on was a full view background of space that created a parallax animation based on your cursor, I started by looking up codepen examples to see how other people did it and the code was surprisingly simple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VyJlQ4whWbN9ADZDe2BALw.png" /><figcaption>Code for parallax background animation</figcaption></figure><p>You set up your div with multiple background images, set variables for your window height, width, mouse x and y position, create a separate depth for each of the layers of your background based on the mouse position and window size (you’ll notice they *.00001, it’s that multiplier that creates the sense of depth and creates the real magic). Then you save all of them to a variable, and set that to the backgroundPosition. All of this is updated on “mousemove”.</p><p>I wanted to take it a step further, so I looked up accessing the accelerometer of mobile devices. Javascript has built in functions for accessing the accelerometer, so it was just a matter of accessing “deviceorientation” and setting a timeout, then an if statement to check if the browser has access to DeviceOrientationEvent and onTouchStart in order to determine whether to use the mobile version or the desktop version.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h2WkHMJua-e6gXoLXj8WTQ.png" /><figcaption>Mobile version of parallax background animation</figcaption></figure><p>This code still needs some refining. Currently most of my background layers have flattened, and I’m not fully sure yet if that is due to the mobile browser being incompatible with multi-background css, or if there is another issue, but I’ll continue debugging that. I also will need to eventually set up a permission request (which you can see I’ve already started) for Apple Devices, which require permission to access the accelerometer. But I’ll continue to work on the mobile version of this effect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xytYqNTPMN7L9ohBa37zwA.png" /><figcaption>Solar System Puzzle</figcaption></figure><p>Another goal I had for this website was a little educational game. Since this was an Air and Space museum website, and museum’s always have little interactive educational elements on them, I wanted to make a little “put the solar system in order” puzzle. This was another surprisingly simple task. Though there were a few issues. I used the CreateJS library and Canvas to simplify the task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LIMmXzv0uAA9CzoCFKpbiw.png" /><figcaption>A simply drag and drop puzzle with CreateJS</figcaption></figure><p>The 2 issues I ran into were that javascript wasn’t able to access the scope of this.slot0.x from inside the function inside the loop. So my workaround for that was saving the x positions to an array. Then I ran into another issue, as my plan had been to use variable i from my loop to dynamically figure out which element in the array I needed, but I wasn’t able to access variable i from inside the function inside the loop either. So I ended up splitting the name of the target, and saving the number from the name to a new variable, and using that number to call the appropriate array number. This is how I’m determining when you are dropping the pieces in the correct place.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*aUeUS6LVeeQNPVY61sj5Mg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*h3VsM1S_OxPcd5M9P0VigA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*0bhk82Fi7wNqmg5zcLD0rw.png" /></figure><p>The next big task I had was my polymorphic associations. I had three main models in my project. Making reservations for the museum, the theater in the museum (museums always have those theaters, often 4D, with educational movies), and the cafeteria at the museum. All of these generated (has_many) tickets. So it made sense to set up a polymorphic association with a tickets model. This was my first time using this feature, but it turned out to be decently easy. Setting up my columns properly, and telling it to be polymorphic true.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*FwpLQN_AA1JrrNwTr0klmA.png" /></figure><p>The other challenges I faced were positioning iFrames, since I used 2. (My game, and the video I embedded on the front page.) But overall I’m decently happy with the final. Of course I don’t think I’ll ever call it totally finished. But how many people ever look at a project and say “Yeah, I think that’s finished”? ;)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba0e96c201d5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Biting Off More Than I Can Chew: A Lifestyle]]></title>
            <link>https://jessijokes.medium.com/biting-off-more-than-i-can-chew-a-lifestyle-ad966a9aa408?source=rss-acd37bc22d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad966a9aa408</guid>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[ruby-on-rails-development]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Jessica Bradham]]></dc:creator>
            <pubDate>Wed, 14 Apr 2021 03:06:29 GMT</pubDate>
            <atom:updated>2021-09-16T04:18:36.283Z</atom:updated>
            <content:encoded><![CDATA[<h3>Pokemon Simulator: A Ruby on Rails App</h3><p>Your teachers never straight up tell you, “You’ll never finish that.” They say, “Get the requirements done first.” That should always be your first sign that you probably aren’t going to get everything done you plan. I remember describing my plan to my cohort lead and he gave me the same exact look I gave countless art students as they pitched projects I knew would have them sacrificing their entire social schedule, or not completing. My goal was to build:</p><p>A rails based Pokemon game you could sign up for using facebook or google, that used the PokeAPI, that let you capture Pokemon in a gamified scenario, create teams, buy items from shops, look up and friend other users, battle their pokemon, play a canvas game to earn money, and have a live messaging system between users. I still have 5 days left, let me tell you where I am in this project and how I got there. :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*qNUuSvcuhJfj4K2Pki1DOw.png" /><figcaption>Pokemon Simulator Index Page</figcaption></figure><p>The first thing I did was worked on a semi-responsive index page, login/signup, and layout with a navigation bar for the site. I remember thinking I was going to crush through it because I had made a signup form in Sinatra, and then stumbling through the entire thing quite hard. Especially when it came to the third party authentication. All it took was one html tag contained in the wrong tag to lead to HOURS of debugging. Luckily I had a fantastic cohort lead who was able to help me troubleshoot it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*QuAENamvSYMm81G0kYPi1g.png" /><figcaption>Pro tip — Don’t ever put your third party auth buttons inside your form. You’re welcome.</figcaption></figure><p>After that I worked on the ability to make Pokemon. But a Pokemon game where you just type in a name and have that Pokemon is no fun. So I got a little creative. I incorporated Javascript an a little styling to create a capture the Pokemon screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*1hiTZXq7uCpz9EiZs-gswA.png" /><figcaption>Ruby, Javascript, and some handy dandy flexbox.</figcaption></figure><p>Let’s talk about how this is done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/1*nrHpgK6H_kN3fVKAFjX5-A.png" /></figure><p>In the controller, every time the page loads I’m creating a new random Pokemon through the API. Then I’m saving the info I need to create a Pokemon in my database to variables that I can access in my view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*aB108kWn8L7Jpjms7csWhg.png" /></figure><p>Then in Javascript, I have an array of failed capture messages that displayed if your Pokeball throw fails. A little logic to get the level of the Pokemon, then it establishes the difficulty to catch the Pokemon based on the level / 2. It chooses a random number between 0 and the level of the Pokemon divided by 2, and if that number is 0 it’s going to hide the throw Pokeball button, failed capture message, show the capture form, and change the styling of the continue searching button so it doesn’t slide when the throw pokeball button vanishes. If your throw fails, it will display a fail message at random, and ensure that everything is displaying properly.</p><p>When the capture form displays here is what is happening in the view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/393/1*UUvzgqhbG5RByeaC4-7JBA.png" /></figure><p>It’s using those variables from the controller and passing them through hidden fields, you only have to enter a nickname, (or none) and it will create a pokemon in the database for you when you submit your form. It’s as simple as that.</p><p>Another fun bit of code I did was the scope method for sorting Pokemon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*EU4nxgn0W8vdIp19zCFFaA.png" /></figure><p>You can very quickly end up with a LOT of Pokemon so I’m using a partial to create a mini navbar that loop’s through the types of Pokemon that the user has (so there are no types that the user doesn’t own in that navbar.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*TtM-CAhIU2_hauhhP1CNeA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*ZdPUGNWvJn_KDamQBqllvg.png" /></figure><p>These two bits of code work together. The controller passes the param the user is asking the website to sort the Pokemon by to the model, and the model returns just the Pokemon that the user asked for. Or in English. First my website is creating the navbar by looking at all the types of Pokemon and showing the user a list of types that they own. Then when the user selects the type, the website is showing them just that type of Pokemon, despite that fact that I never made those individual pages. It’s a small bit of code that packs a powerful punch. Let’s talk about teams!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*Y8VLyJWUX-W4-A8CYBsifg.png" /></figure><p>Currently you can make, view, and delete teams. You can also view other users teams. But I don’t currently have a battle system. It was a bit of a challenge getting the relationship, and figuring out how to get the Pokemon into that join table. But I did manage to do it with a loop which I was pretty happy with. Someday hopefully soon you will be able to battle them!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*WWIafW5RGPyz8-QdE8Pz4g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*ERSTXdHUijQiDzkbu_hKpQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*9LHFvmZ-3GznylztrNKzxw.png" /></figure><p>When it comes to items, currently you can buy, and own Pokeballs. But this is another one that has an interesting bit of code. User_items is a join table, so when you purchase an item, you input how many you want, and it should update the users current quantity if they already own that item or create it if they don’t. It should also take money from the user. The end result was this beast.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*L_uSEVHa8oNQ1-oiJ-Df2A.png" /></figure><p>At this point you can search for, and view users, and their Pokemon/teams. But I really need to get some additional styling in there before I am happy enough to show screenshots of that. The end goal for that is friend requests, messaging, and battles!</p><p>If you are thinking… What about the game? Well… I’m so glad you asked!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*EGt0MX66wJaqYQK3p38ebA.png" /><figcaption>Whack A Diglett!!!</figcaption></figure><p>Whack a Diglett is a fully functional html5 canvas javascript whack-a-mole style game. It’s pretty simple, but personally a lot of fun. Nothing about it is in the project requirements but I am wrapping up this blog with a link to this game and I hope you have a lot of fun playing it! :D</p><p><a href="https://jessijoke.github.io/whack-a-diglet/whack-a-diglet.html">whack-a-diglet</a></p><p>And here is a link to the source code for Pokemon Simulator if you’d like to check it out :)</p><p><a href="https://github.com/jessijoke/pokemonsimulator">https://github.com/jessijoke/pokemonsimulator</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad966a9aa408" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Improving Health with a Simple CRUD app]]></title>
            <link>https://jessijokes.medium.com/improving-health-with-a-simple-crud-app-c97a3e9bc98?source=rss-acd37bc22d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c97a3e9bc98</guid>
            <dc:creator><![CDATA[Jessica Bradham]]></dc:creator>
            <pubDate>Sun, 21 Feb 2021 02:37:36 GMT</pubDate>
            <atom:updated>2021-02-22T05:22:06.584Z</atom:updated>
            <content:encoded><![CDATA[<p>I have gotten severe chronic migraines since I was 4yrs old, at least, that is the earliest one I have memory of. I remember camping out in the living room, in my Barney sleeping bag, crying because the pain hurt so bad. My Mom had given me kids Tylenol and I wasn’t getting better, rather my condition had progressed to throwing up. She called my Grandpa and asked him if I should be taken to the hospital. I remember hearing her tell my dad later that my Grandpa had told her, “Kid’s don’t get headaches. She must have heard somebody mention a headache, and now she’s faking it for attention. She’s only throwing up because she cried hard enough to make herself sick.”</p><p>It’s that statement that had my migraines dubbed as dubious from a young age, despite having many throughout my childhood. It wasn’t until I was an adult that I was able to make an appointment with a doctor and discuss my migraines (which had gotten worst as I had gotten older). I left that appointment with an official diagnosis of Severe Chronic Migraines, and 3 prescriptions (one to take daily as a preventative) and a followup appointment scheduled for 2 weeks later. This appointment was intended to help me assess the effectiveness of my medication. It took <em>months </em>of followup appointments, increases in dosage, and a completely different medication for me to find a happy place that reduced my migraines. In that time, the followup appointments were always difficult. Trying to assess if my migraines had improved when the dosage had increased so slowly, and over so much time was difficult. The doctor recommended keeping a journal so I could easily look at my numbers over time. But I kept losing the notebook, forgetting to fill it out, or it was just difficult to see the changes in a handwritten notebook that spanned months. I thought to myself, “There has to be a simple medical app that lets you track a condition and shows you charts over time?” But I was wrong. The apps were complicated, and never displayed the data in an effective way.</p><p>Ever since having that thought I’ve very much wanted to build a simple tracking app. An app that let you log in, list a condition, and rate it, with maybe some comments. So I was especially excited to start building my CRUD app.</p><figure><img alt="A screenshot of the index page of Medigrowth" src="https://cdn-images-1.medium.com/max/1024/1*ybRBUwL0nXA1j74zkOjx0A.png" /><figcaption>The index page of Medigrowth</figcaption></figure><p>MediGrowth is a simple CRUD application, that is effective primarily due to it’s ability to display data. It is made to be simple, quick, and easy to use. I wanted to accomplish this:</p><ol><li>The ability to add conditions, and track your health through ratings</li><li>The ability to view and edit those entries</li><li>The ability to view your progress as charts</li><li>The ability to add a physician account as your physician</li><li>Physician accounts that view data of patients associated with them.</li></ol><p>The application is built using the Sinatra framework, and utilizes Activerecord, Rake, Sqlite, Bcrypt, Groupdate, and Chartkick.</p><p>The hardest gem to work with was easily Chartkick. I didn’t find the documentation to be extremely helpful in either installing or usage, I had to search the depths of the internet just to get my charts displaying (hint, restart your server after you install it), and I spent hours reading stackoverflow to figure out exactly how to format my queries so they pulled and grouped the data I needed properly. The end results looked something like this.</p><figure><img alt="A line of erb Ruby that displayed a chart with your ratings pulled in." src="https://cdn-images-1.medium.com/max/1024/1*zvM1wbPHuaHygrixbokPhg.png" /></figure><figure><img alt="A screenshot of Medigrowth’s ability to show charts for individual conditions" src="https://cdn-images-1.medium.com/max/1024/1*XujG9Bjlv8BWiLkOHTTAMQ.png" /><figcaption>You can view charts by individual condition</figcaption></figure><figure><img alt="A screenshot of Medigrowth’s ability to show charts for all conditions" src="https://cdn-images-1.medium.com/max/1024/1*4Yed1NN4uBKGJXKiRUPlxA.png" /><figcaption>Or you can view charts tracking all your conditions</figcaption></figure><p>The other important feature that gave me a bit of difficulty was adding doctors. Doctor accounts are kept in a separate table than User accounts, as doctors have a “Has Many” relationship with Users. Users can view all the available physicians, select one, and that physician has the option to view the user’s charts and notes. The physician has the option to remove a patient if they were mistakenly added, and the user can change physicians at any time.</p><p>The difficulty came in differentiating the two types of accounts so that Doctors can not access user functions, and users can not access Doctor functions. I ended up using 2 Helper methods to accomplish this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8cQp8Jg-fzb7LRce5EcAQg.png" /></figure><p>The first helper method, “current_user” tracks whoever is logged in based on their session, whether it is a doctor or a user. I accomplished this using the else if statement. Then I created a method that checks if you are a doctor, using a boolean stored in the database. All doctors have a 1, and users have a 0. This made it easy to say you can only access pages if you are logged in, and if this is a doctor page, you have to be a doctor. If it’s a user page, you have to be a user.</p><p>These methods were really helpful for one of the most important aspects of my website, which was that the app had to be <em>extremely </em>restrictive in who could view data, since this was a medical app. So every page is constantly checking, are you logged in? If so who are you? And only displaying data that directly relates to the users who are allowed to see it.</p><figure><img alt="A screenshot demonstrating how Doctors can view the charts of patients who have added them as a physician" src="https://cdn-images-1.medium.com/max/1024/1*VskJv2a2179xkyxbk7bLTQ.png" /><figcaption>Doctors can view the charts of patients who have added them as a physician</figcaption></figure><p>Building this app a major goal was to keep it as simple and easy to use as possible, and not overload it with unnecessary features. Since the goal of the app is to encourage people to log in daily, and track conditions, it’s meant to be as simple as possible. My future goal for this app is the get a mailing system added to remind people to log in daily, and I’d like to add a little additional styling to make the whole thing just a little prettier. But aside from that I’m extremely happy with the functionality of this application, and I hope to some day launch it as a tool that can help people.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c97a3e9bc98" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Wheel of Fortune: Building My First Ruby App]]></title>
            <link>https://jessijokes.medium.com/wheel-of-fortune-building-my-first-ruby-app-1723d1ff35c4?source=rss-acd37bc22d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/1723d1ff35c4</guid>
            <category><![CDATA[women-in-tech]]></category>
            <category><![CDATA[learn-to-code]]></category>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[wheel-of-fortune]]></category>
            <dc:creator><![CDATA[Jessica Bradham]]></dc:creator>
            <pubDate>Tue, 08 Dec 2020 05:18:05 GMT</pubDate>
            <atom:updated>2020-12-08T05:18:05.075Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*S_L-JqYJxkzxIsHPQTdljQ.jpeg" /><figcaption>Wheel of Fortune Banner Logo</figcaption></figure><p>Go big or go home right? When I started the bootcamp prep program for Flatiron in early September, I did their mini Javascript, and Ruby programs. Since my cohort didn’t start until mid October, I decided to practice by building a Wheel of Fortune game in Repl. Looking at it today, I can see everything I did wrong. So when I came to the end of Phase 1 in my cohort, with the opportunity to build a command line application in Ruby that utilized an API, I decided to go further than just going through an API. I rebuilt Wheel of Fortune.</p><p>I remember thinking. “I already built it once. How hard could it be to build it again?”</p><p>“How hard could it be?” Always famous last words.</p><p>The answer was ‘very hard’, you see my first app was technically object oriented but there was no separation of concerns and it relied entirely on if statements and iteration for problems that could’ve been solved much more efficiently. Everything was in one class. I don’t think I ended up reusing any of my old code.</p><p>So I had 3 major challenges to tackle in my project.</p><ol><li>Including the API</li><li>Remaking the project more efficiently</li><li>As a designer I really wanted to make the project more beautiful, the constraints of a text based project were rankling me.</li></ol><p><strong>Including the API</strong></p><p>The primary objective of the project was to utilize an API, so the very first thing I did was work on the API. I knew I could turn in the entire project if I had a working command line application that interacted with the API and returned results. The rest was all bonus. I selected Quote Garden as an easy to interact with API with a simple structure. I utilized net/http, and open-uri, and json to access the API, extract and parse the data. I set this up in a class of it’s own so I could pull quotes as needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*oYLhnBXyFfGuIVt7vCjbWg.png" /><figcaption>A screenshot of an API getting taken in and parsed</figcaption></figure><p><strong>Remaking the Project</strong></p><p>This was challenging, I was taking a project that had been built in one class, and rebuilding it to be more efficient, and with separation of issues. One of the big challenges was rebuilding how I rendered my game board. I needed to take the quote and convert it to dashes so the player knew the format of the quote they were guessing, and how many letters they had remaining to guess. Every time a letter was guessed, the board needed to re-render with the letter they had guessed included. In my old version I handled the board like this. I used an array of excluded characters (which included punctuation) to check if each character was in that array, and if it wasn’t I popped a “-” into a temporary array, if it was, I placed the character into the temporary array, then I joined the temporary array I had made, and displayed that. Obviously this was a lot. It meant iterating through every letter each turn. And it made handling vowels and consonants very difficult (since you have to buy a vowel and spin for consonants).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*xJBniZZZYe0tYh6ZAKY9ug.png" /><figcaption>The code I used to update my game board in my old Wheel of Fortune Application</figcaption></figure><p>When I went about rewriting this, I created a module that could be included in my CLI file. I used gsub then passed the quote solution, an array of remaining consonants, and an array of remaining vowels as arguments to the method and used the arguments in a regex with a case insensitive modifier. This allowed me to easily render the new puzzle board every turn with one line, using the same symbols I was using to track the players moves (so they couldn’t pick the same letter twice) which meant I didn’t need two different sets of information doing the similar jobs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*bo-UlCaNHUBa_ADWN4RnMw.png" /><figcaption>The refactored code I used to update my game board in my new Wheel of Fortune Application</figcaption></figure><p><strong>Making it Pretty</strong></p><p>The constraints of making a text based application were painful as a designer and I was really researching to see how I could add some great design to my application. My answer game in the form of Ruby Gems and ASCII banners.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iy6VmIz4dE72nVqfLuzpiQ.png" /><figcaption>ASCII banners</figcaption></figure><p>I started with ASCII banners and a few Ruby gems to help improve the formatting of my game. ASCII banners simply use text characters to build beautiful text banners. And gems like TTY-Prompt help make nicely formatted prompts. But I wanted to see if I could push it any further, and after hours of research I found a gem called Catpix. This lead me down a rabbit hole which included 4 Development dependencies, 2 Runtime dependencies, the need to upgrade Homebrew, installing a patch for one of the dependencies, and a custom modification to one of the links in one of the dependencies before I got Catpix working. Honestly, I wanted to give up at times. But the end result was WORTH IT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NxvZMoAOJ68Or72yQnRfhw.png" /><figcaption>The title banner of my Wheel of Fortune Application</figcaption></figure><p>Catpix works by taking an image, creating a text version of it using block characters (such as █), and then coloring them with an extended color palette. The gem does so much work it is a bit slow, so I am only using it once for the title image, but I’m extremely happy with the result.</p><p><strong>Final Thoughts</strong></p><p>I had said a few times, “I made it once before, how hard could it be?”</p><p>And there were honestly a few times I really thought I wasn’t going to be finished. I still have a few things I may go in and tweak, but at this point it’s all gold plating, and I’m currently extremely happy with what I’ve created.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1723d1ff35c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Isolation, Neopets, and a Coding Bootcamp]]></title>
            <link>https://jessijokes.medium.com/isolation-neopets-and-a-coding-bootcamp-51ebc7aa491?source=rss-acd37bc22d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/51ebc7aa491</guid>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[codingbootcamp]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[career-change]]></category>
            <dc:creator><![CDATA[Jessica Bradham]]></dc:creator>
            <pubDate>Sat, 24 Oct 2020 03:22:56 GMT</pubDate>
            <atom:updated>2020-10-24T18:32:48.645Z</atom:updated>
            <content:encoded><![CDATA[<p>I was raised by crazy people. That’s pretty much what I tell people, it’s the easiest way to describe being raised be people who isolated my sisters and I in a farmhouse in the middle of nowhere. (That farmhouse was owned by a family friend who was tired of seeing my parents get evicted from one place after the next, and my sisters and I sleeping in church parking lots.) I had no friends. I wasn’t allowed to watch most modern movies or tv. I wasn’t allowed to listen to secular music. I wasn’t allowed to cut my hair above my shoulder blades, or dye it more than one or two shades from it’s natural color (and even then, never with a permanent dye). In my tiny world, there was no Jurassic Park, Halloween, Taylor Swift, and I had never even heard of ABBA or Saturday Night Live. “Crap” was a swear word.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PF6UZiVc1lucLshYo6hlSA.png" /><figcaption>We lived right across the street from the airport, and next to a small warehouse. There was nothing else here but a red hawk who lived across the street. Apparently the area is now a huge industrial area.</figcaption></figure><p>I was homeschooled, and I use that word in the loosest sense. We didn’t always have books, and the books were very biased towards my parents religious beliefs. (My books taught me that evolution wasn’t real, and probably neither were dinosaurs.) I never had more than 1 book per subject per year. Sometimes I had less (one year in particular I had none). My Mom never helped with anything. She felt education was a waste of time, especially for women who were not “Called by God to lead.” In her mind, I should have gotten married, and been a good little submissive housewife who never went anywhere or did anything, and especially never talked back (this was a particular failing of mine). And I knew that life would never have made me happy. I was already miserable.</p><p>My whole world changed when my Dad brought home a computer and we got a dial up connection. The computer had a 40gb hard drive and less than 1gb of ram. At first I has dismissed the internet as some vague business concept. Then I saw my older sister playing Neopets, and I was hooked. The internet became my window to the outside world. I quickly learned to customize my Neopets page. I joined Myspace, Angelfire, I was drawing in Photoshop. I was building webpages with divs, frames (primarily using floats) and using <a href="http://www.flamingtext.com/">www.flamingtext.com</a> for everything.</p><figure><img alt="“I was so cool” In blue flames" src="https://cdn-images-1.medium.com/max/502/1*OvnVjq6q7n6e1GufUgEB2Q.gif" /><figcaption>You weren’t cool in the mid 2000s if your website didn’t have flaming text on it.</figcaption></figure><p>The thing that kept me hooked was the community. The internet was my portal. I learned who Avril Lavigne was. (Ironically a celebrity impersonator chose the wrong target and was very disappointed. I remember her saying “My name is Avril” And I said “That’s a cool name” And she said “I’m a singer” and I said “Oh I like to sing too” And she said “I live in Canada” and I said “Oh you shouldn’t tell people where you live online, it’s dangerous” looking back she must have been all kinds of frustrated. I had no clue.)</p><p>My community kept me hooked, but I began to get bored with making art (a product of my ADD), and quickly found I could make my art interactive with Flash (now Adobe Animate. Geesh I’m old.) The first thing I made was an e-card. The next thing I made was a simple whack a mole game, I remember it used a for loop, and I was baffled by the mysterious thing, but after a few more uses I quickly became hooked and was building small flash games that primarily relied on creative use of the for loop.</p><figure><img alt="Bubble Bounce: A Flash game I built, drew, and animated start to finish" src="https://cdn-images-1.medium.com/max/993/1*_3b0NlABjcHE5a65iaKXdg.png" /><figcaption>Bubble Bounce: A Flash game I built, drew, and animated start to finish</figcaption></figure><p>I had friends online. I had clients online. I had my own private world online, and I finally had moments to live for online. And I knew I wanted more than the life I had. Because all of these people talked about their family and friends. They would share pictures of their lives outside of this digital world. I had no life outside it to share.</p><p>With encouragement from my online friends, I utilized the library and studied hard,I got a .. not a great, but a decent ACT score, 21 if you are curious (nobody will be calling me a genius, but for being entirely self taught I’m allowing myself to accept it). My Great Aunt helped me sign up for the ACT, and paid for it since my Mom would have no part. My Great Aunt also helped me apply for the FAFSA and I got into college.</p><p>When I graduated college, I found a job almost immediately. I have been working there for 9 years now and in that time I have put my coding skills to use and even grown them. I built their ebooks, including multimedia and javascript books for Apple Books (my first jump into javascript). I used to build flash games for their website (before Flash pretty much died off entirely). I prototyped webpages for them using bootstrap, and even prototyped a couple apps in Unity.</p><figure><img alt="A screenshot of “Ups and Downs” an interactive ibook by School Zone Publishing" src="https://cdn-images-1.medium.com/max/856/1*PtwzbXB7_3qJIdBMu8cOjQ.png" /><figcaption>This is a screenshot from Ups and Downs, an ebook made for Apple Books that uses javascript to incorporate interactive elements. On the left page there is a ghost hidden in the picture that will light up when you tap it (not the pumpkin ghost, there is actually a hidden ghost) on the right, there is a basket with a spaceship pumpkin sticker you can place anywhere on the page. Tapping the ghost pumpkin will trigger audio that tells you a Halloween themed joke. The text on the top is read-along, and not only will it highlight as the audio reads it, but you can tap it anywhere to start it from that point.</figcaption></figure><p>About 4 years ago I was offered an opportunity to teach an interaction design course at my previous college, the course would be using HTML5 canvas with javascript, and I would have the summer to fully prepare, I was so excited, and the class quickly became one of my favorite parts of my week.</p><p>I dove deeper into javascript for that class, I helped students build simple interactive projects, with more focus on design, and they would always gasp at how smart I was (haha). I had an independent study student sit in on my class and I helped him build a portfolio with Bootstrap. When something broke he would ask me to fix it, and I would say, “Hm lets try…” tap a few keys, not even sure if it would work, and his eyes would go wide, and he would look at me like I was some kind of super genius and every time I would laugh. It was honestly all really simple basic stuff, but the simple code was so new to them, it was a HUGE confidence boost.</p><p>After 3 years of doing that, I finally had to ask myself. Why am I not really pursuing this? I love this. I love building things. I love figuring out how to break down a project, and solve these problems. I don’t just want to design, I want to build!</p><p>That was the moment I started seriously considering the option. I joined groups on Facebook, started watching Youtube videos, I completed the entire HTML, CSS, and Javascript sections of FreeCodeCamp, I spent an entire year doing tutorials, practicing javascript, learning ES6, I even volunteered at a local coding conference, but I was having trouble putting it together. I was struggling with using a framework, and I had no backend skills, and found the resources for those to be less straightforward. So I looked into coding bootcamps, and scholarships. And after finding a scholarship specifically for women who had shown dedication and interest in pursuing a career in technology, I feel like I am finally on my way.</p><p>The internet created a portal for me, it gave me access to information, communities, and opportunities that I would never have been able to reach without it. I truly believe technology can help make the world a better place, and I am so excited to have even the possibility of being a part of building that better place.</p><figure><img alt="A rhinoceros on a treadmill staring at a picture of a unicorn for inspiration" src="https://cdn-images-1.medium.com/max/710/1*qSTs40I9HLenOCES0DEEtA.gif" /><figcaption>The one thing I have learned, is even when people tell you that you don’t add up, and you can never be everything that you dream, that you just don’t have the qualifications, that there is something about you that means you will never qualify, sometimes, you just have to go for it anyway.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51ebc7aa491" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>