<?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 Aubrey Loudenslager on Medium]]></title>
        <description><![CDATA[Stories by Aubrey Loudenslager on Medium]]></description>
        <link>https://medium.com/@aubrey.d.webster?source=rss-4ce7438b327a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*O2kCfEdP27EMN7oPPgThKg.jpeg</url>
            <title>Stories by Aubrey Loudenslager on Medium</title>
            <link>https://medium.com/@aubrey.d.webster?source=rss-4ce7438b327a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 06:13:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aubrey.d.webster/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[Constraints and Validations in Flask, SQLAlchemy]]></title>
            <link>https://medium.com/@aubrey.d.webster/constraints-and-validations-in-flask-sqlalchemy-3248084d24e4?source=rss-4ce7438b327a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3248084d24e4</guid>
            <category><![CDATA[constraints]]></category>
            <category><![CDATA[validation]]></category>
            <category><![CDATA[sqlalchemy]]></category>
            <category><![CDATA[flask]]></category>
            <dc:creator><![CDATA[Aubrey Loudenslager]]></dc:creator>
            <pubDate>Wed, 24 May 2023 17:31:04 GMT</pubDate>
            <atom:updated>2023-05-24T17:40:06.717Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/943/1*5aaSt6ZEFlmvAJQv2UyOAA.jpeg" /></figure><p>In web development, data validation plays a crucial role in ensuring the integrity and security of the application. They are also put in place to prevent invalid data from making its way onto your application. Flask, a micro web framework written in Python, provides a integration with SQLAlchemy, an open-source SQL toolkit and object-relational mapper(ORM). Together, they offer many ways for validating data in a Flask application. In this blog post, we will explore the different approaches and techniques for implementing validations using Flask, SQLAlchemy, and Python.</p><h4><strong>Constraints</strong></h4><p>You can use constraints as you are defining models in your flask app. The constraints will ensure that no invalid data types are being used in your database. The most common constraints used are nullable, and unique.</p><p>The nullable constraint ensures that the values that are being added to the column are never empty, or null. Heres what that would like like in a user model in models.py.</p><pre>class User(db.Model):<br>    __tablename__ = &#39;users&#39;<br>    <br>    id = db.Column(db.Integer, primary_key=True)<br>    username = db.Column(db.String, nullable=False)<br>    password = db.Column(db.String, nullable=False)</pre><p>Here we use the nullable constraint on name and password. What this is doing is making sure that any users who use the application have a username and password set. The app will not let a new user be created without setting a username or password.</p><p>The unique constraint is just how it sounds. It ensures that each value for that column is unique from the rest of the values.</p><pre>class User(db.Model):<br>    __tablename__ = &#39;users&#39;<br>    <br>    id = db.Column(db.Integer, primary_key=True)<br>    username = db.Column(db.String, nullable=False, unique=True)<br>    password = db.Column(db.String, nullable=False)</pre><p>Now we have that same table in models.py, but we added a unique key to the username. This means that every user in the application will have a unique username.</p><h4><strong>Validating With SQLAlchemy</strong></h4><p>Server-side validation is crucial for ensuring data integrity and security, as client-side validation can be bypassed. In Flask, server-side validation is typically performed using SQLAlchemy models and Python code. SQLAlchemy provides a rich set of data types that can be used to define validation rules. By utilizing SQLAlchemy’s built-in validation mechanisms, such as relationships, and custom validators, you can enforce logic and ensure that only valid data is persisted in the database.</p><p>SQLAlchemy has a built in helped method for using validations, validates(). Here is what a validation might look like using the same model, User.</p><pre>class User(db.Model):<br>    __tablename__ = &#39;users&#39;<br>    <br>    id = db.Column(db.Integer, primary_key=True)<br>    username = db.Column(db.String)<br>    password = db.Column(db.String)<br><br>@validates(&#39;username&#39;)<br>def validate_username(self, key, value):<br>    if not value:<br>        raise ValueError(&quot;Must have a username&quot;)<br>    return address</pre><p>What this is doing is making sure that a username is included, while also providing a message to be displayed if a username is not included. If a username is given, you app will just return the given username as usual.</p><p>Validating data is a crucial aspect of web application development. Flask, SQLAlchemy, and Python offer powerful tools and frameworks for implementing data validations. By leveraging client-side validation, server-side validation with SQLAlchemy, you can enforce data integrity, improve user experience, and enhance application security. Furthermore, the flexibility to implement custom validations allows you to address specific business requirements. By incorporating these constraint and validation techniques into your Flask applications, you can ensure the reliability of your data while delivering a seamless user experience. I hope that you were able to learn something new from this and happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3248084d24e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Productivity]]></title>
            <link>https://medium.com/@aubrey.d.webster/productivity-ca43c8e9047a?source=rss-4ce7438b327a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca43c8e9047a</guid>
            <category><![CDATA[workplace]]></category>
            <category><![CDATA[health]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[productivity]]></category>
            <dc:creator><![CDATA[Aubrey Loudenslager]]></dc:creator>
            <pubDate>Wed, 10 May 2023 14:59:28 GMT</pubDate>
            <atom:updated>2023-05-10T15:17:32.827Z</atom:updated>
            <content:encoded><![CDATA[<p>Making the most of your time and resources to set yourself up for success.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p3oANATSEUTUgeix-atFww.png" /></figure><p>I am 12 weeks into my new life as a coder and man oh man has it been a ride. Yes I’ve learned a lot about development and computers but I’ve also learned a ton about myself and the human brain in general. Sitting on a computer all day can be tough. Not only can it be hard to focus, but sitting can also take a huge toll on our physical health. Here are some tips that I’ve learned over the past three months that have helped me be a better student and make the most of my time in front of my computer.</p><h4><strong>Attention Span</strong></h4><p>In February of 2023, the American Phycology Association published an article about the constantly decreasing attention span of humans. They did a study and found that the average attention span for adults was just 47 seconds, compared to their previous study conducted in 2012 where they found the average attention span was 75 seconds. 47 seconds?!? That’ it?! I know what you&#39;re thinking, <em>how does one get anything done if our attention span is just 47 seconds</em>? I’m wondering the exact same thing. With this being said, taking breaks throughout the day is extremely important in ones ability to retain information. Something that I’ve personally found helpful is creating a timeline and small goals for myself. Telling myself <em>work hard for 20 minutes and then I can get a 5 minute break , </em>or more accurately, <em>work for 20 minutes and then you can play on your phone for a bit.</em></p><p>A study from GoRemotely found that “Engaged employees are more productive, resulting in a 21% increase in profits.” Letting yourself take necessary breaks will improve how well you can pay attention and the quality of work that you’re doing.</p><p>I think the most important thing you need to do when trying to work is being aware of how you work the best. I know that I am able to produce the best work when I have music on in the background, when I have minimal distractions and when I have a timeline laid out for my day. Knowing how you work best is going to help you be the most productive, and it’ll help get rid of the possibility to procrastinate. Remember to not be too hard on yourself if you’re lacking focus, step away for a minute to give your brain a break and then come back to work when you feel refreshed!</p><h4><strong>Environment</strong></h4><p>At the start of my coding journey, I was facing constant distractions that made it extremely difficult to focus for longer than 5 minutes. I personally get the most work done when I am surrounded by other people who are working. A working environment helps you get into a focused mindset. Wherever you do your work, make sure that you have limited distractions if possible so that you’re setting yourself up for success.</p><p>Another huge part of putting yourself in an environment that is helpful to your ability to work is by ensuring that the job you are in has your best interest. This means researching a company before you decide to work with them and ensuring that the culture they have created is positive and encouraging. HR Cloud writes, “Positivity is a luxury in the contemporary world, for humans tend to be more impressed by negative thoughts. In such a scenario, if employers and HR managers can foster a culture of positivity in the workplace, it can do wonders to enhance individual productivity… These [positivities]include empathy, gratitude, employee wellness, team building, cordial workplace interactions, and so on.” They go on to say, “In such a [positive]workplace, people will not have any other concerns than focusing on the quality of their work and organizational goals.” Being involved in a work place that is causing unnecessary stress or drama will not only negatively impact the quality of work that you are able to complete, but it will also take a toll on your mental health. Knowing the kind of culture that you desire before starting your job search would be a great way to ensure that you end up at a job that you’re truly excited about.</p><h4>Healthy Habits</h4><p>What we do on our off time majorly effects how productive we are when it’s time to get to work. In my opinion, one of the best things you can do for yourself is fuel your body properly. The Harvard Medical school published an article in 2022 that reads,</p><p>“<a href="https://www.health.harvard.edu/mind-and-mood/serotonin-the-natural-mood-booster">Serotonin</a> is a neurotransmitter that helps regulate sleep and appetite, mediate moods... Since about 95% of your serotonin is produced in your gastrointestinal tract, it makes sense that the inner workings of your digestive system don’t just help you digest food, but also guide your emotions.”</p><p>Not only are we going to be able to work better when we eat better, but we can also help ourselves have a better mindset throughout the day. A <a href="https://hero-health.org/wp-content/uploads/2013/06/Presenteeism_8_6_2012.pdf">Population Health Management study</a> found that people with an unhealthy diet were 66% less productive than those who regularly ate whole grains, fruits and vegetables. Make sure that you’re taking breaks often and fueling yourself when needed.</p><p>Another extremely important habit is getting enough sleep. The recommended amount of sleep that a person between the ages of 18–60 is seven or more hours per night. The National Institute of Health states, “ Sleep has been proven to improve memory recall, regulate metabolism, and reduce mental fatigue.” A good sleeping schedule helps with a lot more than just improving our ability to focus. The SleepFoundation.org recently did a study in 2023 and one of the statistics they stated was, “Lack of sleep or poor sleep results in unplanned absences from work that cost the U.S. economy $44.6 billion each year”. They went on to say, “According to estimates, 50 million to 70 million people in the U.S. have ongoing sleep disorders” and “Drowsy driving is responsible for more than 6,000 fatal car crashes”. Sleep is extremely beneficial to your body and mind and it’s proven to actually be dangerous to yourself if you aren’t getting enough sleep.</p><p>Lastly, taking care of ourselves physically is going to directly effect our brain function. The Cleveland Clinic writes,</p><p>“Exercising can increase the thickness of your cerebral cortex and improve the integrity of your white matter (the nerve fibers that connect areas of the brain’s nerve-cell-rich gray matter). Exercise also promotes neuroplasticity, which is your brain’s ability to form new neural connections — in other words, your ability to learn throughout your life.”</p><p>Human bodies work together in incredible ways. Being proactive in your physical health will directly impact your mental and emotional health. The life of a developer sure does make it difficult to stay active, but stretching and taking a short walk midday makes a world of difference. An active break will also help your eye health.</p><p>Dr. Muriel Schornack, a Mayo Clinic optometrist stated in an interview from 2022,</p><p>“Whenever we’re doing anything that requires distinct attention to visual detail, our blink rate goes down… Blinking is huge. It’s hugely important. It can go a long way toward keeping us more comfortable. It’s obviously inexpensive, and it’s readily available…”</p><p>Staying aware of how long you’ve been sitting on a screen by setting timers would be a great way to ensure that you are giving your body and eyes the rest they need.</p><h4><strong>My Takeaways</strong></h4><p>Taking care of yourself first is going to be the most beneficial thing to improve your productivity. Finding a place to work that cares about your well-being and mental state is extremely important. No job should be worth sacrificing your physical or mental health. Find a routine that works for you and remember to give yourself enough breaks, fuel your body, and get up and stretch every once in a while!</p><p>Thanks for reading! I hope you were able to take something away from this to help you become the best version of yourself!</p><h4>Sources</h4><p><a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4651462/">PMC4651462</a></p><p><a href="https://www.apa.org/news/podcasts/speaking-of-psychology/attention-spans">attention-spans</a></p><p><a href="https://www.sleepfoundation.org/how-sleep-works/sleep-facts-statistics">sleep-facts-statistics</a></p><p><a href="https://health.clevelandclinic.org/exercise-and-brain-health/#:~:text=In%20one%20recent%20study%2C%20researchers,2.2%20years%20less%20brain%20aging.%E2%80%9D">exercise-and-brain-health</a></p><p><a href="https://hbr.org/2014/10/what-you-eat-affects-your-productivity">what-you-eat-affects-your-productivity</a></p><p><a href="https://www.businessnewsdaily.com/2963-healthy-diet-impacts-productivity.html#">2963-healthy-diet-impacts-productivity.html</a></p><p><a href="https://www.health.harvard.edu/blog/nutritional-psychiatry-your-brain-on-food-201511168626">nutritional-psychiatry-your-brain-on-food-201511168626</a></p><p><a href="https://newsnetwork.mayoclinic.org/discussion/mayo-clinic-minute-how-staring-at-screens-can-affect-your-vision/">mayo-clinic-minute-how-staring-at-screens-can-affect-your-vision</a></p><p><a href="https://www.hrcloud.com/blog/five-ways-in-which-work-environment-affects-employee-productivity">five-ways-in-which-work-environment-affects-employee-productivity</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca43c8e9047a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Syntax and Data Types]]></title>
            <link>https://medium.com/@aubrey.d.webster/python-syntax-and-data-types-1b7fc505f75d?source=rss-4ce7438b327a------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b7fc505f75d</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <dc:creator><![CDATA[Aubrey Loudenslager]]></dc:creator>
            <pubDate>Tue, 18 Apr 2023 18:15:06 GMT</pubDate>
            <atom:updated>2023-04-18T20:57:21.290Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*z6ypqdWK9RYeLM7XkJmrfw.jpeg" /></figure><p>Python has become one of the most popular programming languages since its release in the 1990’s. A dutch programmer named Guido Van Rossum created it to be an intuitive language that can be easily interpreted in plain English. It is an object-oriented(programming paradigm that uses objects and classes), high-level language that can be used for both back, and front end development, though it is most commonly used for backend purposes. If you’re getting into code, you will definitely run into python, so it’s always good to know a bit of background to be able to use python in its full potential.</p><h4><strong>Python Syntax</strong></h4><p>Like I stated earlier, Python was created to be easy to read, which means a lot of the python key words are easy to memorize and understand. Let’s take a look at a code block example of a basic python command.</p><pre># We&#39;re going to tell the computer to write out some words!<br>print(&quot;Wow! This python stuff is so easy!&quot;)<br># Aren&#39;t you glad I didn&#39;t say Hello, world?</pre><p>If your’e learning python after already going through JavaScript, the key word “print()” has the same purpose as “console.log()”, however it’s a bit easier to understand. All we’re doing is telling the computer <em>hey I would like you to </em><strong><em>print</em></strong><em> out these words in the terminal for me.</em></p><h4><strong>Small Details to Note</strong></h4><ol><li>The octothorp(#) is we use in python to add a comment line. The equivalent in Javascript was a double forward slash(//).</li><li>Python is very picky about indentation so make sure to always indent four spaces when writing out the inside of functions.</li><li>Python was made to be readable, so it is best to keep your character count on each line below 80. This isn’t always possible but learning to wrap functions might be a helpful tool!</li></ol><h4><strong>Data Types in Python</strong></h4><p>Let’s dig into some of the data types you will be getting familiar with. Python has many built-in data types, including but not limited to, string, integer, float, list, tuple, range, dictionaries, set, etc. You will most likely be using all of these in python, but if you can’t remember every one, don’t worry, google most likely knows the answer! Here are some examples of data types and how to print them out using our handy dandy key word, “print()”.</p><p><strong>Strings(str)</strong></p><p>A string in python is anything thats wrapped in quotations. It can consist of words or other characters. Python strings cannot be changed once they are created, making them immutable. These are pretty similar to JavaScript strings. Here’s an easy example of making a variable equal to a string, and then using Pythons key word, type, to make the computer tell you what kind of data type the variable is equal to.</p><pre>a = &quot;This is a string.&quot;<br>print(a)<br># Output: &quot;This is a string.&quot;<br>print(type(a))<br># Output: str</pre><p><strong>Integer(int) and float</strong></p><p>An integer is any whole number, positive or negative, that <strong>does not</strong> include any decimal points. The key word to define an integer in Python is “int”.</p><pre>b = 5<br>print(b)<br># Output: 5<br>print(type(b))<br># Output: int</pre><p>Float is also a type of number in Python, however unlike integer, float numbers are any numbers, positive or negative, that are decimals or fraction numbers.</p><pre>c = 5.5<br>print(c)<br># Output: 5.5<br>print(type(c))<br># Output: float</pre><p><strong>List and tuple</strong></p><p>Lists are ordered collections of objects. This means that they can include any data type. Lists are mutable, meaning you can change whats inside of them.</p><pre>d = [&quot;chocolate&quot;, &quot;vanilla&quot;, &quot;strawberry&quot;]<br>print(d)<br># Output: [&quot;chocolate&quot;, &quot;vanilla&quot;, &quot;strawberry&quot;]<br>print(type(d))<br># Output: list</pre><p>A tuple is similar to a list, in that they can store multiple types of objects. However, unlike lists, tuples cannot have repeating object values and they are immutable.</p><pre>e = (&quot;chocolate&quot;, &quot;vanilla&quot;, &quot;strawberry&quot;)<br>print(e)<br># Output: (&quot;chocolate&quot;, &quot;vanilla&quot;, &quot;strawberry&quot;)<br>print(type(e))<br># Output: tuple</pre><p><strong>Range</strong></p><p>Ranges return a sequence of numbers that increment by one. They will start at zero, unless stated otherwise. The computer will print out the list of numbers and stop at the number right <strong>before </strong>the number that was passed in. For example, if the given number is 50, the greatest number that the command line gives you will be 49. If you don’t want the starting number to be zero, simply add in the number into the parenthesis that you would like to start with, followed by a comma, and the number one above what you would like to end with(ex: range(2, 5) will print 2, 3, 4).</p><pre>for f in range(5):<br>    print(f)<br># Output: 0 1 2 3 4</pre><p><strong>Dictionaries(dict)</strong></p><p>A dictionary is “Python’s implementation of a data structure that is more generally known as an associative array”. Dictionaries can be defined using the key word “dict” and consist of one or more key-value pairs wrapped inside a set of curly brackets. Here’s an example of how to set a variable equal to a dictionary that is defining characteristics of my dog, Jack.</p><pre>g = {<br>    &quot;name&quot; : &quot;Jack&quot;, <br>    &quot;breed&quot; : &quot;labrador retriever&quot;, <br>    &quot;age&quot; : 3<br>}<br>print(g)<br># Output: {&quot;name&quot; : &quot;Jack&quot;, &quot;breed&quot; : &quot;labrador retriever&quot;, &quot;age&quot; : 3}<br>print(type(g))<br># Output: dict</pre><p><strong>Set</strong></p><p>Sets are used to store multiple items inside of a variable. Sets are also immutable, but they are unordered and unindexed, so when you print them, the computer will print it out in a random order.</p><pre>h = {&quot;chocolate&quot;, &quot;vanilla&quot;, &quot;strawberry&quot;}<br>print(h)<br># Output: {&quot;strawberry&quot;, &quot;chocolate&quot;, &quot;vanilla&quot;}<br>print(type(h))<br># Output: set</pre><p>Keep in mind that there are a few more data types in python, these are just the few that I have personally encountered multiple times. My biggest piece of advice to someone learning Python is to keep your code clean. Not to be redundant, but Python was made to be easily readable so make sure that another developer could look at your code and know what it’s saying, meaning try not to make your code too wordy!</p><p>I hope you were able to learn something new and feel a bit more comfortable with Python! Thanks for reading, and happy coding!</p><h4><strong>Sources:</strong></h4><p><a href="https://flatironschool.com/blog/python-popularity-the-rise-of-a-global-programming-language/">python-popularity-the-rise-of-a-global-programming-language</a></p><p><a href="https://www.coursera.org/articles/what-is-python-used-for-a-beginners-guide-to-using-python">what-is-python-used-for-a-beginners-guide-to-using-python</a></p><p><a href="https://www.w3schools.com/python/python_datatypes.asp">python_datatypes.asp</a></p><p><a href="https://realpython.com/lessons/dictionary-python/">dictionary-python</a></p><p><a href="https://www.python.org/doc/essays/blurb/">blurb</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b7fc505f75d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Basics]]></title>
            <link>https://medium.com/@aubrey.d.webster/react-basics-723f262bcd65?source=rss-4ce7438b327a------2</link>
            <guid isPermaLink="false">https://medium.com/p/723f262bcd65</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[basics]]></category>
            <category><![CDATA[components]]></category>
            <dc:creator><![CDATA[Aubrey Loudenslager]]></dc:creator>
            <pubDate>Wed, 29 Mar 2023 19:45:22 GMT</pubDate>
            <atom:updated>2023-03-29T20:02:03.647Z</atom:updated>
            <content:encoded><![CDATA[<h4>Learning React when all you know is JavaScript.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QIiH9ttQaC0voKZnrWthjA.jpeg" /></figure><p>You’re all done learning JavaScript, congratulations! Only a little bit longer until you’re a senior level dev(lol). if you liked learning JavaScript, this next phase will be super easy for ya. We’re going to incorporate everything that you just learned about code, and we’re just going to tweak the layout a bit. Super easy, right?</p><h4><strong>So what is React?</strong></h4><p>React is a component based-framework that is built entirely out of JavaScript. React is <strong>declarative</strong> which means that it’s a type of programming that describes what the end result should be. Component based means that we are able to structure our website using individual files called “components” and use these all together to form the application we are creating.</p><h4><strong>Basic Setup</strong></h4><p>What are the files that we’re used to seeing in vanilla JavaScript? Usually we would have a README.md, index.html, index.js, db.json and style.css. When using React, you’re still going to see a couple files that will be familiar like index.css, index.js, db.json, and of course, a README.md. Some new files that you’ll need to learn are package.json, App.js and a Components folder that is filled with files of components that you get to name. You will not need an index.html anymore when using React, but we’ll get into that a little bit more later.</p><h4><strong>What are components?</strong></h4><p>The definition of the word component is “a part or element of a larger whole, especially part of a machine or vehicle”. <em>How does this relate to coding with React? </em>Awesome question! Let’s take a familiar code in JavaScript to explain this a bit better. Say you have a pretty basic app that’s displaying pictures of milkshakes on the top of the page. When you click on the milkshakes picture, the page renders a detailed description of the milkshake. Your JavaScript code in index.js would look a little bit like this.</p><pre>function fetchMilkshakes() {<br>    fetch(&#39; http://localhost:3000/milkshakes&#39;)<br>    .then(res =&gt; res.json())<br>    .then(results =&gt; renderAllMilkshakes(results))<br>}<br><br>function renderAllMilkshakes(results) {<br>    const milkshakeTab = document.getElementById(&quot;milkshakes-menu&quot;)<br>    results.forEach((milkshakes) =&gt; {<br>        const milkshakePhotos = document.createElement(&#39;img&#39;)<br>        milkshakePhotos.src = milkshakes.image<br>        milkshakeTab.append(milkshakePhotos)<br><br>        milkshakePhotos.addEventListener(&#39;click&#39;, () =&gt; {<br>            const milkshakeDetail = document.getElementById(&#39;milkshake-detail&#39;)<br><br>            const detailImage = document.querySelector(&#39;.detail-image&#39;)<br>            detailImage.src = milkshakes.image<br>            detailImage.style.width = &quot;640px&quot;<br>            detailImage.style.height = &quot;640px&quot;<br><br>            const detailName = document.querySelector(&#39;.name&#39;)<br>            detailName.innerText = milkshakes.name<br><br>            const detailIngredients = document.querySelector(&#39;.ingredients&#39;)<br>            detailIngredients.innerText = milkshakes.ingredients<br><br>            const detailRating = document.querySelector(&#39;#rating-display&#39;)<br>            detailRating.innerText = milkshakes.rating<br>        })<br>    })<br>}<br>document.addEventListener(&quot;DOMContentLoaded&quot;, fetchMilkshakes)</pre><p>and your index.html file for the page would look a little bit like this.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br><br>&lt;head&gt;<br>  &lt;meta charset=&quot;utf-8&quot; /&gt;<br>  &lt;title&gt;Milkshakes!&lt;/title&gt;<br>  &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;styles.css&quot; /&gt;<br>  &lt;script defer type=&quot;text/javascript&quot; src=&quot;./src/index.js&quot;&gt;&lt;/script&gt;<br>&lt;/head&gt;<br><br>&lt;body&gt;<br>  &lt;header&gt;<br>    &lt;h3&gt;Milkshakes!&lt;/h3&gt;<br>  &lt;/header&gt;<br><br>  &lt;!-- Milkshake Menu --&gt;<br>  &lt;div id=&quot;milkshake-menu&quot;&gt;<br>    &lt;!-- Milkshake Images Here --&gt;<br>  &lt;/div&gt;<br><br>  &lt;!-- Milkshake Details --&gt;<br>  &lt;div id=&quot;milkshake-detail&quot;&gt;<br>    &lt;img class=&quot;detail-image&quot; src=&quot;./assets/image-placeholder.jpg&quot; alt=&quot;Insert Name Here&quot; /&gt;<br>  &lt;/div&gt;<br><br>  &lt;h2 class=&quot;name&quot;&gt;Insert Name Here&lt;/h2&gt;<br>  &lt;h3 class=&quot;restaurant&quot;&gt;Insert Ingredients Here&lt;/h3&gt;<br>  &lt;h4&gt;Rating:&lt;/h4&gt;<br>  &lt;p&gt;<br>    &lt;span id=&#39;rating-display&#39;&gt;Insert rating here&lt;/span&gt; / 10<br>  &lt;/p&gt;<br><br>&lt;/body&gt;<br><br>&lt;/html&gt;</pre><p>Now what if we were to create this same application using React? Here’s a layout of what the page might look like before adding in any information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4WWYnPc97v2dCUSXt7UG2w.jpeg" /></figure><p>Each box that you see is a component on the page, which means that they will each have their own file in the components folder.</p><p>Things to note about components.</p><ol><li>Components must be converted to JSX.</li><li>Components have to be capitalized.</li><li>Each component must be imported to its parent component.</li></ol><p>Here is an example of what the parent component, App, might look like.</p><pre>import React from &quot;.react&quot;<br>import Title from &quot;./Title&quot;<br>import MilkshakeTab from &quot;./MilkshakeTab&quot;<br>import MilkshakeResults from &quot;./MilkshakeResults&quot;<br><br>function App() {<br>  return (<br>    &lt;div&gt;<br>      &lt;Title /&gt;<br>      &lt;MilkshakeTab /&gt;<br>      &lt;MilkshakeResults /&gt;<br>    &lt;/div&gt;<br>  );<br><br><br>export default App;</pre><p>We are in a file called App.js, which is in a folder called components. We have to import each of the children that we want to render onto the app page and then return them to your App function in the order you want them rendered. As you can see, we are incorporating some text that we would usually find in our index.html, but with React, we can use index.html tags in our components to make them render how we want. Based off our picture of the full application, we can also conclude that MilkshakeImage, MilkshakeName, MilkshakeIngredients and MilkshakeRating are going to be the children of our MilkshakeResults component. Heres a break down of what the full application would look like from your components tab when you inspect the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q_56s1PvS-cxlZpF-nyhLg.jpeg" /></figure><p>Using the inspect page on your website is a great way to keep track of which components should go where!</p><h4><strong>Takeaways</strong></h4><p>Being confident in knowing the basics of how to code in React is super important because you’ll need to know all of this information in any application that you want to create using React. When you reach the point of learning prop passing, useState, and hooks, you’ll need to know which component holds all of that code, and further more, which components need access to that code. You’’ll start to get comfortable with everything and React will (hopefully) be a really fun tool for you. I hope this was helpful, and if you’re interested in learning more, down below are some sources that I found helpful when learning about React!</p><p><a href="https://www.youtube.com/watch?v=JPT3bFIwJYA">watch</a></p><p><a href="https://www.w3schools.com/REACT/DEFAULT.ASP">DEFAULT.ASP</a></p><p><a href="https://legacy.reactjs.org/docs/components-and-props.html">components-and-props.html</a></p><p><a href="https://www.geeksforgeeks.org/reactjs-components/">reactjs-components</a></p><p><a href="https://overreacted.io/writing-resilient-components/">writing-resilient-components</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=723f262bcd65" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Objects & Arrays-and understanding why we use them.]]></title>
            <link>https://medium.com/@aubrey.d.webster/objects-arrays-and-understanding-why-we-use-them-f385f225fb18?source=rss-4ce7438b327a------2</link>
            <guid isPermaLink="false">https://medium.com/p/f385f225fb18</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[objects-in-javascript]]></category>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Aubrey Loudenslager]]></dc:creator>
            <pubDate>Wed, 08 Mar 2023 01:03:04 GMT</pubDate>
            <atom:updated>2023-03-08T19:55:03.440Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*F0ledGXjO0pouUREjVURyQ.jpeg" /></figure><p>Fully understanding objects and arrays was one of the most beneficial things I did when learning to code. Let’s break these down.</p><h4><strong>What is an Object?</strong></h4><p>An object is a independent structure, consisting of properties and types , that is defined inside of a set of curly brackets{}.</p><p>Think of a car. Cars have their own properties like color, make, model, etc. A car is an object. Easy enough right? Here’s an example of how it would look to code a specific car to be an object.</p><pre>myFavoriteCar = {<br>        make : &quot;Toyota&quot;,<br>        model : &quot;4Runner&quot;,<br>        year : &quot;2018&quot;,<br>        color : &quot;light blue&quot;<br>    }</pre><p>The words before the colon(:) are the <strong>keys</strong> and what comes after are the <strong>values</strong>. Now we know that my favorite car is a light blue 2018 Toyota 4Runner.</p><p>Here is how you would access one specific key to return its value.</p><pre>myFavoriteCar = {<br>        make : &quot;Toyota&quot;,<br>        model : &quot;4Runner&quot;,<br>        year : &quot;2018&quot;,<br>        color : &quot;light blue&quot;<br>    }<br><br>myFavoriteCar.model;<br>//=&gt; &quot;4Runner&quot;</pre><h4>Wait, how did you get that return value?!</h4><p>Wow, great question! I used something called “object.keys method”. Using <strong>dot notation</strong>, we are able to get a specific return value from the object by writing the name of the object, followed by a period and then writing the name of one of the keys!</p><h4><strong>But wait, what if one of the keys is a string?</strong></h4><p>Wow, another awesome question! In that case, we would use a similar format, but instead of using dot notation, we would place square brackets around the key(better known as <strong>bracket notation</strong>). Here’s an example of when that would come in handy.</p><pre>myFavoriteSongs = {<br>  &quot;Highway Tune&quot; : &quot;Greta Van Fleet&quot;,<br>  &quot;Strawberry Suncreen&quot; : &quot;Lostboycrow&quot;,<br>  &quot;Float&quot; : &quot;HARBOUR&quot;,<br>  &quot;Color of You&quot; : &quot;Austin Cain&quot;<br>}<br><br>myFavoriteSongs[&quot;Float&quot;];<br>//=&gt; &quot;HARBOUR&quot;</pre><p>We are still able to go into the object and find a specific value. Dot notation and bracket notation are interchangeable, but most of the time it it easier to just use dot notation! You will really only need to use bracket notation if your key is a string.</p><h4><strong>What is an array?</strong></h4><p>An array is a collection that holds multiple pieces of data under a single name, or more appropriately, a list, that is defined inside of a set of square brackets[]. Let’s use the car example again, but this time we’ll use the specific make, Toyota. Toyota has tons of models but for this example we’ll use RAV4, Tacoma, 4Runner and Tundra. You would have an array, named Toyota cars, and the models, or the pieces of data inside.</p><pre>toyotaCars = [&quot;RAV4&quot;, &quot;Tacoma&quot;, &quot;4Runner&quot;, &quot;Tundra&quot;]</pre><p>Array’s do not have any keys, only listed values. However, we can still grab a specific value in an array because each element in an array has their own index value. This means that the array listed above is different than this array…</p><pre>cars = [&quot;Tundra&quot;, &quot;4Runner&quot;, &quot;Tacoma&quot;, &quot;RAV4&quot;]</pre><p>Yes, the array contains the same number of elements, and the values look the same, but in the first array, “RAV4” is the first element, and in the second array, “RAV4” is the last element.</p><p>When we want to return one of the elements, we use bracket notation, and in the brackets we write the corresponding index value to the element that we want to return. Here’s an example of what that would look like with our toyotaCars array!</p><pre>toyotaCars[1];<br>//=&gt; &quot;RAV4&quot;</pre><p>You would think this would be correct, right? Unfortunately programmers are odd and they like to start their counting with the number 0. This means that the first element in an array will always have an index value of “0”, the second element in an array will always have an index value of “1”, and so on. Lets fix our return now with this new information!</p><pre>toyotaCars[0];<br>//=&gt; &quot;RAV4&quot;<br><br>toyotaCars[1];<br>//=&gt; &quot;Tacoma&quot;<br><br>toyotaCars[2];<br>//=&gt; &quot;4Runner&quot;<br><br>toyotaCars[3];<br>//=&gt; &quot;Tundra&quot;<br><br>toyotaCars[4];<br>//=&gt; undefined</pre><p>Trying to return an element that doesn’t exist will always return undefined. There is no more elements after the index value of 3 in our toyotaCars array, so the computer has no information to give us.</p><h4><strong>Things to note about keys.</strong></h4><p>Keys need to be original, but values can be repetitive.</p><pre>cars = {<br>  toyota : &quot;4Runner&quot;,<br>  toyota : &quot;Tacoma&quot;,<br>  toyota : &quot;RAV4&quot;<br>};</pre><p>Above, we are talking about three different cars, but when you try to access these keys, only the first key’s value with that name will be returned.</p><pre>cars.toyota;<br>//=&gt;&quot;4Runner&quot;</pre><p>To avoid this, make sure to give the keys original names. Here’s a way we might fix that.</p><pre>cars = {<br>  toyota1 : &quot;4Runner&quot;,<br>  toyota2 : &quot;Tacoma&quot;,<br>  toyota3 : &quot;RAV4&quot;<br>};<br><br>cars.toyota1;<br>//=&gt; &quot;4Runner&quot;<br><br>cars.toyota2;<br>//=&gt; &quot;Tacoma&quot;<br><br>cars.toyota3;<br>//=&gt;&quot;RAV4&quot;</pre><p>Now some fun stuff! Say we’re at a dealership and they have a list of cars that they currently have on the lot. You might create a database for the dealership that looks a little bit like this.</p><pre>const cars = {<br>  toyota : {<br>    tacoma : &quot;6&quot;,<br>    &quot;4 Runner&quot; : &quot;3&quot;,<br>    &quot;RAV4&quot; : &quot;4&quot;,<br>    tundra : &quot;9&quot;<br>  },<br>  volkswagen : {<br>    beetle : &quot;5&quot;,<br>    jetta : &quot;4&quot;,<br>    passat : &quot;8&quot;,<br>    golf : &quot;4&quot;<br>};</pre><p>I know what you’re thinking, <em>a dealership that only sells Toyota and Volkswagen?</em> <em>What in the world? </em>But that’s beside the point. What we did up top is something called a <strong>nested object</strong>. This is an object inside of another object. The key “toyota” is now its own object with new nested keys (tacoma, 4 Runner, RAV4 and tundra), and these nested keys now have their own values too! Fun right?</p><h4>Lets put them together!</h4><p>We’ve learned a good amount of information about objects and arrays. We know their similarities and we know their differences. But what if we take these two things and smash them together?</p><p><em>Whhaaaaattt? Is that even possible???</em></p><p>Yes! Very possible, and actually very common! Lets take a look at an example of an object that has an array inside of it!</p><pre>const cars = {<br>  toyota : {<br>    tacoma = [&quot;2012&quot;, &quot;2014&quot;, &quot;2018&quot;, &quot;2018&quot;, &quot;2022&quot;, &quot;2023&quot;],<br>    &quot;4 Runner&quot; = [&quot;2014&quot;, &quot;2018&quot;, &quot;2022&quot;],<br>    &quot;RAV4&quot; = [&quot;2016&quot;, &quot;2016&quot;, &quot;2018&quot;, &quot;2023&quot;],<br>    tundra = [&quot;2012&quot;, &quot;2012&quot;, &quot;2014&quot;, &quot;2016&quot;, &quot;2016&quot;, &quot;2018&quot;, &quot;2022&quot;, &quot;2023&quot;, &quot;2023&quot;]<br>  },<br>  volkswagen : {<br>    beetle = [&quot;2016&quot;, &quot;2016&quot;, &quot;2018&quot;, &quot;2023&quot;, &quot;2023&quot;],<br>    jetta = [&quot;2018&quot;, &quot;2020&quot;, &quot;2020&quot;, &quot;2022&quot;],<br>    passat = [&quot;2016&quot;, &quot;2016&quot;, &quot;2017&quot;, &quot;2018&quot;, &quot;2020&quot;, &quot;2020&quot;, &quot;2022&quot;, &quot;2023&quot;],<br>    golf = [&quot;2018&quot;, &quot;2020&quot;, &quot;2020&quot;, &quot;2023&quot;]<br>};</pre><p>This looks similar to the nested object example, however now we can see the specific years of the cars that the dealership has in stock! This option gives us a lot more information than the nested object did</p><p><em>But how we would access a specific return value for an array </em><strong><em>inside </em></strong><em>of an object?</em></p><p>You are just full of great questions! To get a return value from this object of arrays, you are going to use <strong>both </strong>of the notations that we learned earlier.</p><pre>cars.toyota.tundra;<br>//=&gt; &quot;2012&quot;, &quot;2012&quot;, &quot;2014&quot;, &quot;2016&quot;, &quot;2016&quot;, &quot;2018&quot;, &quot;2022&quot;, &quot;2023&quot;, &quot;2023&quot;<br><br>cars.toyota.tundra[2];<br>//=&gt; &quot;2014&quot;<br><br>cars.toyota.tundra[7];<br>//=&gt; &quot;2023&quot;</pre><p>Combing dot notation and bracket notation, you get to have access to <strong>everything</strong> inside of the cars object!</p><h4><strong>Okay okay, get to the point already. Why do I need to know this to code?</strong></h4><p>You are going to run into array’s and object’s in just about everything you do. Instagram, Pinterest, the website to your favorite recipe, and even this blog, all have a database that they are pulling from. Whether it’s to select a photo, create a list, access a specific name in a file, <em>everything </em>has a database and array’s and object’s are the heart of those databases. Having a clear understanding of what these are, how to use them, and their syntax will prevent lots of mistakes and headaches for your future self. Eventually you’ll be able to write lines of code like this, where you access the database to put information onto a website.</p><pre>{<br>   &quot;cars&quot;: [<br>      {<br>        &quot;id&quot;: 1,<br>        &quot;make&quot;: &quot;Toyota&quot;,<br>        &quot;model&quot;: &quot;4Runner&quot;,<br>        &quot;image&quot;: &quot;./images/IMG_1.jpeg&quot;,<br>      },<br>      {<br>        &quot;id&quot;: 2,<br>        &quot;make&quot;: &quot;Toyota&quot;,<br>        &quot;model&quot;: &quot;Tacoma&quot;,<br>        &quot;image&quot;: &quot;./images/IMG_2.jpeg&quot;,<br>      },<br>   ]<br> }<br><br>const carLot= document.getElementById(&quot;car-lot-list&quot;)<br><br>    results.forEach((car) =&gt; {<br>        const carPhoto = document.createElement(&#39;img&#39;)<br>        carPhoto.src = cars.image<br>        carLot.append(carPhoto)<br><br>        carPhoto.addEventListener(&#39;click&#39;, () =&gt; {<br><br>            const carImage = document.getElementById(&quot;car-image&quot;)<br>            carImage.src = cars.image<br><br>            const carMake = document.getElementByClass(&quot;car-make&quot;)<br>            carMake.innerText = cars.make<br><br>            const carModel = document.querySelector(&quot;.car-model&quot;)<br>            carModel.innerText = cars.model<br>        })<br>    })<br>}</pre><p>Here, we are accessing the database and appending, or displaying, that information onto a website that is listing cars, Butttt all of that can just be a problem for your future self! For now, just make sure to really dive into the foundations of code. Embrace the questions and confusion as part of the learning process and you’ll really start to fall in love with what you’re doing!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f385f225fb18" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>