<?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 Stephen Risso on Medium]]></title>
        <description><![CDATA[Stories by Stephen Risso on Medium]]></description>
        <link>https://medium.com/@stevriss22?source=rss-57080c7f9dbb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QJ4plzpws7J0t09Bc7gc6Q.png</url>
            <title>Stories by Stephen Risso on Medium</title>
            <link>https://medium.com/@stevriss22?source=rss-57080c7f9dbb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 15:55:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stevriss22/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[Connecting Spring Boot Microservice to Oracle Datasource]]></title>
            <link>https://medium.com/@stevriss22/connecting-spring-boot-microservice-to-oracle-datasource-aae33008643a?source=rss-57080c7f9dbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/aae33008643a</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[oracle]]></category>
            <dc:creator><![CDATA[Stephen Risso]]></dc:creator>
            <pubDate>Fri, 12 Jul 2024 17:55:43 GMT</pubDate>
            <atom:updated>2024-07-12T17:55:43.854Z</atom:updated>
            <content:encoded><![CDATA[<p>This tutorial will go through each step required to create a new data source in your springboot microservice, connect to the datasource, create a prepared statement, and update the database with a new record.</p><p>We will be completing this tutorial in a Java Spring boot Microservice using Gradle. If you are interested in a tutorial on how to create a new springboot microservice from scratch, please leave a comment!</p><p><strong>Step By Step Guide:</strong></p><ol><li>Update Project Dependencies</li></ol><ul><li>Navigate to your ‘build.gradle’ or ‘pom.xml’ file to update dependencies for OracleDB with the below:</li></ul><pre>    compile(&quot;com.oracle:ojdbc7:$oracleVersion&quot;)</pre><ul><li>The current version I am using for Oracle is: 12.1.0</li></ul><p>2. Create External Configuration File</p><ul><li>To hold our database credentials, such as username / password / connectionURL, we will need to create an external properties file on the server the microservice is deployed.</li><li>We will then create a PropertyLoader within our project to grab and use these values</li></ul><pre>touch configuration-datasource.properties<br>#Now that file is create, use visual editor to create the below. When in Visual edito<br>#Use Arrow keys to navigate, use &#39;i&#39; key to insert, when complete use &#39;esc&#39; key<br>#to exit insert, and lastly type &#39;:wq&#39; to save and quit<br>vi configuration-datasource.properties<br><br>#add below:<br>oo.jdbc.connection.url =jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST={YOUR_DATABASE HOST})(PORT={YOUR_PORT}))(CONNECT_DATA=(SERVICE_NAME={YOUR_DB_NAME})(FAILOVER_MODE =(TYPE = SELECT)(METHOD = BASIC)(RETRIES = 180)(DELAY = 5))))<br>oo.jdbc.user =YOUR_USER<br>oo.jdbc.password =YOUR_PASSWORD<br>oo.jdbc.driver.class =oracle.jdbc.driver.OracleDriverClass</pre><p><strong>Address:</strong></p><ul><li>(ADDRESS=(PROTOCOL=TCP)(HOST={YOUR_DATABASE HOST})(PORT={YOUR_PORT})) - This defines the address of the database server.</li><li>(PROTOCOL=TCP) - Specifies the communication protocol as TCP/IP.</li><li>(HOST={YOUR_DATABASE HOST}) - Placeholder for the actual hostname or IP address of your Oracle database server. Replace {YOUR_DATABASE_HOST} with the correct hostname or IP.</li><li>(PORT={YOUR_PORT}) - Placeholder for the port number used by the Oracle listener service. Replace {YOUR_PORT} with the appropriate port number (typically 1521 by default).</li></ul><p><strong>Service Name:</strong></p><ul><li>(CONNECT_DATA=(SERVICE_NAME={YOUR_DB_NAME})(FAILOVER_MODE=(TYPE = SELECT)(METHOD = BASIC)(RETRIES = 180)(DELAY = 5)))) - This section specifies the service name of the database and connection failover configuration.</li><li>(SERVICE_NAME={YOUR_DB_NAME}) - Placeholder for the service name of the Oracle database instance you want to connect to. Replace {YOUR_DB_NAME} with the actual service name.</li><li>(FAILOVER_MODE=(TYPE = SELECT)(METHOD = BASIC)(RETRIES = 180)(DELAY = 5)) - This defines the failover behavior for the connection.</li><li>(TYPE = SELECT) - This indicates the failover mode is &quot;SELECT&quot;.</li><li>(METHOD = BASIC) - This specifies the failover method is &quot;BASIC&quot;.</li><li>(RETRIES = 180) - This sets the maximum number of attempts to retry connection on failure (180 in this case).</li><li>(DELAY = 5) - This defines the delay (in seconds) between retries (5 seconds in this case).</li></ul><p>3. Create PropertyLoader Class</p><ul><li>Now that we have created our properties file and populated with our connection details, now we must create a PropertyLoader within our application to grab those properties to be used in out application.</li><li>For each field we have in the properties file, we will create a getter. This getter method will grab the property value from the external config file and load it into a value to be used. See code below:</li></ul><pre>public class PropertyLoader {<br>  Properties prop = null;<br><br>  public PropertyLoader() {<br><br>    prop = new Properties();<br><br>    try (InputStream inputStream =<br>        new FileInputStream(new File(AppConstants.EXTERNAL_CONFIG_FILE))) {<br>      prop.load(inputStream);<br>    } catch (IOException e) {<br>      log.error(&quot;IOException &quot;, e);<br>    }<br>  }<br><br>  public String getDBUsername() {<br>    String result = null;<br>    try {<br>      result = prop.getProperty(&quot;oo.jdbc.user&quot;);<br>    } catch (MissingResourceException e) {<br>      log.error(&quot;Exception: &quot;, e);<br>      return result;<br>    }<br>    return result;<br>  }<br><br>  public String getDBPassword() {<br>    String result = null;<br>    try {<br>      result = prop.getProperty(&quot;oo.jdbc.password&quot;);<br><br>    } catch (MissingResourceException e) {<br>      log.error(&quot;Exception: &quot;, e);<br>      return result;<br>    }<br>    return result;<br>  }<br><br>  public String getDBUrl() {<br>    String result = null;<br>    try {<br>      result = prop.getProperty(&quot;oo.jdbc.connection.url&quot;);<br><br>    } catch (MissingResourceException e) {<br>      log.error(&quot;Exception: &quot;, e);<br>      return result;<br>    }<br>    return result;<br>  }<br>}</pre><p>4. Create Datasource connection in Main Class</p><ul><li>Now that our PropertyLoader is created, we need to use the properties to create the datasource connection in our project. We can do that by adding the following code to the main class of our project:</li></ul><pre>@SpringBootApplication<br>@EnableEurekaClient<br>@Slf4j<br>public class MyApplication{<br><br>  public static void main(String[] args) {<br>    SpringApplication.run(MyApplication.class, args);<br>  }<br><br>  @Bean<br>  DataSource dataSource() throws SQLException {<br>    log.info(&quot;--Initializing dataSource--&quot;);<br><br>    OracleDataSource dataSource = new OracleDataSource();<br><br>    PropertyLoader loader = new PropertyLoader();<br>    log.info(&quot;loader.getDBUsername():&quot; + loader.getDBUsername());<br>    log.info(&quot;loader.getDBUrl():&quot; + loader.getDBUrl());<br>    dataSource.setUser(loader.getDBUsername());<br>    dataSource.setPassword(loader.getDBPassword());<br>    dataSource.setURL(loader.getDBUrl());<br>    dataSource.setImplicitCachingEnabled(true);<br>    dataSource.setFastConnectionFailoverEnabled(true);<br>    dataSource.setDriverType(&quot;oracle.jdbc.driver.OracleDriver&quot;);<br>    return dataSource;<br>  }<br>}</pre><ul><li>Adding this bean to our main class will ensure that we connect to the datasource with the proper connection details.</li></ul><p>5. Test Connection by Adding records to DB table</p><ul><li>Now that we are connected, lets test it out by creating a ‘ProjectRepository.class’ in your project!</li><li>We will use this class to utilize the connection we just made and add records into our table:</li></ul><pre>@Slf4j<br>@Component<br>public class MyProjectRepository{<br><br>  @Autowired private DataSource dataSource;<br><br>  public void insert(List&lt;MyVO&gt; myVOList) {<br>    log.info(&quot;Preparing to create Datasource connection and prepared statement...&quot;);<br>    PreparedStatement preparedStatement = null;<br>    Connection connection = null;<br><br>    try {<br>      connection = dataSource.getConnection();<br>      String queryFile =<br>          &quot;insert into MYSCHEMA.MY_TABLE (id, first_name, last_name) VALUES (MYSCHEMA.MY_TABLE_ID_SEQ.NEXTVAL, ?, ?)&quot;;<br>      preparedStatement = connection.prepareStatement(queryFile);<br><br>      log.info(&quot;Preparing to loop through vo list and execute SQL INSERT...&quot;);<br>      for (MyVO vo: myVOList) {<br><br>        log.info(&quot;Building Prepared statement with member details&quot;);<br>        try {<br>          preparedStatement.setString(1, vo.getId());<br>          preparedStatement.setString(2, vo.getFirstName());<br>          if (vo.getLastName() != null) {<br>            preparedStatement.setString(3, vo.getLastName());<br>          } else {<br>            preparedStatement.setObject(3, null);<br>          }<br>          preparedStatement.executeUpdate();<br>          log.info(&quot;Update executed.&quot;);<br>        } catch (Exception e) {<br>          log.error(&quot;error inserting into table &quot; + e);<br>        }<br>      }<br>    } catch (SQLException ex) {<br>      log.error(&quot;error while instering SQL Statement&quot;, ex);<br>    }<br>  }<br>}</pre><ul><li>Lets go thorugh the above code and break it down!</li><li>First we want to bring in our new Datasource as a variable so that we can get the DB connection.</li><li>Then we will create our Connection (java.sql.statement) and our PreparedStatement (java.sql.statement).</li><li>Third, in order to create our prepared statement we need to create the SQL query that we will be executed. Since we are doing an insert, we need to make sure that our query’s columns and values match up with the rules of the DB table schema.</li><li>Fourth, after the query is ready use the .prepareStatement method from java.sql.statement</li><li>Fifth, loop thorugh our VO list and set our Query values with the values of our VO</li><li>Lastly, execute the update using .executeUpdate()</li></ul><p>6. Verify new records in database :)</p><p>I hope this tutorial was informative and helpful for anyone who reads. Please feel free to leave any questions or concerns below! Happy Coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aae33008643a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Ruby on Rails Back End from Scratch]]></title>
            <link>https://medium.com/@stevriss22/creating-ruby-on-rails-back-end-from-scratch-937fff6993ca?source=rss-57080c7f9dbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/937fff6993ca</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Stephen Risso]]></dc:creator>
            <pubDate>Tue, 22 Aug 2023 19:18:35 GMT</pubDate>
            <atom:updated>2023-08-22T19:18:35.059Z</atom:updated>
            <content:encoded><![CDATA[<p>This article will outline how to create a new rails application from scratch. We will also add a model and a controller to kick start our server! Ruby on Rails is a fantastic and powerful framework that employs the programming language Ruby to help make the lives of back end programmers easier. So with that, let’s learn the basics!</p><p><em>Note: ‘ $ gem install rails’ is the terminal command to install.</em></p><h3><strong>Step 1: Navigate to the directory where the application will be housed</strong></h3><p>The first thing to do is find or create a folder where your rails application will be found after its created. For this example we will use a directory called ‘practice’.</p><h3>Step 2: Create rails application using $ rails new</h3><p>Next you want to create the new rails application within the directory using the command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*71gO8zVnXHs3fI3nbH_rNw.png" /></figure><p>What this command will do is create a brand new rails back end server equipped with a README.md, app directory, database directory, and more!(see below) After the the command is entered the terminal will download these things and create the application. After the process in the terminal is finished, in your current directory you should see a new directory with the name you just gave. Open that directory in your text editor and voila you now have a new rails back end!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*WtTBm5Ve4TOzlbd6k-761A.png" /></figure><h3>Step 3: Generate a Model</h3><p>Now that we have the skeleton of a rails application lets play around with rails and use some of the generators. To generate a new model with some attributes run:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*aIzWfKq-evG8KXkizRWmZA.png" /></figure><p>This command generates a new model called Pizza and creates 3 new columns within the model. Toppings is a string, price is an integer, and good will be a boolean(true or false). This is a simple example, you can also throw model associations in the generator and have rails set them up!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*oTy8QQJO2lQqqDsIzXlsfA.png" /></figure><h3>Step 4: Migrate the new model</h3><p>Now that we have created a migration for a new model called Pizza, all that needs to be done is to migrate!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*tmdIKT_vkJBNgfgeoTMM1Q.png" /></figure><p>After the migration is finished, check the ‘db’ folder and you should see a new schema showing the new Pizza model!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*zOoZoW1FMZVdW3cynuMufg.png" /></figure><h3>Step 5: Generate a Controller</h3><p>The last thing we are going to cover is how we can generate a controller and its very similar to something we have seen already. See the command below to see how to generate one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/544/1*xFtxn9GxYbxcgcmnetT9Ng.png" /></figure><p>This command is generating a new pizzas_controller with TWO empty methods for two actions, ‘create’ and ‘index’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*WP5owWt6xdYnXXzSij0qjg.png" /></figure><p>This can be done with the other actions as well. Rails can make complex things much simpler and less time consuming, that’s why it is the obvious choice when creating a new back end!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=937fff6993ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java: How to Read a CSV File and Write Content as a JSON Array]]></title>
            <link>https://medium.com/@stevriss22/java-how-to-read-a-csv-file-and-write-content-as-a-json-array-c859245c9a09?source=rss-57080c7f9dbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/c859245c9a09</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[json]]></category>
            <dc:creator><![CDATA[Stephen Risso]]></dc:creator>
            <pubDate>Wed, 28 Jun 2023 17:07:35 GMT</pubDate>
            <atom:updated>2023-06-28T17:07:35.015Z</atom:updated>
            <content:encoded><![CDATA[<p>Breaking radio silence with a tutorial on how to read data contained in a Comma Separated Value (CSV) file and then write the content of that file into a JSON array. This method is extremely useful because it allows you to parse all lines of a CSV file and then manipulate the values however you see fit! When attempting to do this myself I noticed a lack of straightforward tutorials on the topic so I hope this is a easy to follow and simple tutorial!</p><p><strong>Disclaimer</strong>: I will just be going through the method to accomplish this task, the assumption is that you have a working environment to run it:)</p><p>First off, lets dive into exactly what a CSV file is. A CSV or Comma Separated Value file is a plain text file often used for exchanging data in between different applications. The data contained in the file is usually separated by a comma delimiter, BUT the data can also be separated using other characters other than the comma. Each row will contain values for each record, picture it as an excel file with 4 columns. Each column will have a value, in CSV files those values will be loaded onto one line and separated by a delimiter, see below for an example of this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*WphjpP2RgnNO8P0Kixl_7A.png" /><figcaption>Example of data in CSV file</figcaption></figure><p>Notice that each row contains data for an individual record and all values are delimited by a comma. Again, our goal in this tutorial is to take this data, read the individual values, and parse those values into a JSON Object. In order to accomplish this, the first thing we need to do is store our file somewhere easy to grab. I created a folder called ‘tmp’ and created a new CSV file called ‘attributesSuccess10.csv’ containing the data from the above screenshot. Once that is done, you are ready to hop into the code!</p><p>Below I will post a screenshot of the method we will be looking at and then go line by line and explain what is going on!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*969QPQfogDa0SuXDIgcSjA.png" /><figcaption>Method to read CSV file and parse it into a JSONObject</figcaption></figure><p>Line 1: Declare new void method. Void because if we are writing data to a file we are not returning anything</p><p>Line 2: We create a new string variable to store the value we will be using as our delimiter. In this case, since our file is separated by a comma we will use that.</p><p>Line 3: Create a new string variable called lineData. This will be used to hold the data read from each line of our file.</p><p>Line 4: Create a new File point it to the new folder you created containing the ‘attributesSuccess10.csv’ file.</p><p>Line 6: We make a new try/catch clause to catch any exceptions that might come from using a BufferedReader.</p><p>Line 8: Declare a new BufferedReader and use a FileReader to pass it your CSV file.</p><p>Line 9: Declare a new JSONArray to hold our JSONObjects. (NOTE: I am using the org.json package to access these classes)</p><p>Line 11: Create a new while loop to loop over the file until there are no more lines. We are setting the string variable we created before, ‘lineData’, to a line of the file and if the line is null we know we have reached the end of the file.</p><p>Line 13: This is where we get the individual values from the line. We are holding them in a string array and are getting them by using the ‘split()’ method. ‘split()’ will look for the provided delimiter, in this case the comma, and split the values wherever it sees one.</p><p>Line 15: Here we can see all of the values pulled from the current row. Each element in the string array correlates to one of the comma separated values in our file.</p><p>Line 18: Now we can create a our new JSONObject and add in our values held in the string array.</p><p>Line 19–22: We create a new field for each element and set it to the correlating value in the string array.</p><p>Line 24: Put the JSONObject we just create for that line of data into the JSONArray.</p><p>Line 28: Catch any exceptions thrown</p><p>Congrats, you just read a CSV file and parse it’s data into multiple JSONObjects and placed them all in a JSONArray! But what good is that if you cant actually see and use this newly formatted data?? There are a lot of things you can do with your JSON once it is stored, but we are just going to write it into a text file as a JSON string. The code below shows you how to do that!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*myl7IFBUku_Ndd8sKxmxIA.png" /><figcaption>Write our new JSONArray to a text file as a JSON string</figcaption></figure><p>Line 1: Open a new try/catch to catch any errors that may be throw as a result of using PrintWriter. As the parameter we are passing a PrintWriter, which will be used to write our data in text. As the parameter for that PrintWriter, we will pass a FileWriter pointing to the path where we want the new text file written. I am just writing it to a folder in my project, but you can write it anywhere you want!</p><p>Line 35: Write our JSONArray as a String to the file.</p><p>Line 37: Catch any exceptions.</p><p>Once you run your method you should now have a file that looks something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*wZOX8f4Gw0kvF5BMAK3QHg.png" /><figcaption>JSON string produced from PrintWriter</figcaption></figure><p>And if we convert that JSON string to normal JSON then it looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*KAcIvexqQ4f5Bi7Zwbq_YQ.png" /><figcaption>JSON string converted back to JSON array of objects</figcaption></figure><p>There you go, now you can read and parse a CSV file into JSON! Hope this tutorial was helpful!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c859245c9a09" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Two Sum Algorithm: Explained (JavaScript)]]></title>
            <link>https://medium.com/@stevriss22/two-sum-algorithm-explained-javascript-8d66aeb5e840?source=rss-57080c7f9dbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/8d66aeb5e840</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Stephen Risso]]></dc:creator>
            <pubDate>Tue, 29 Mar 2022 19:22:33 GMT</pubDate>
            <atom:updated>2022-03-29T19:22:33.742Z</atom:updated>
            <content:encoded><![CDATA[<p>The two sum algorithm asks us to create a function that takes two inputs: an array of integers and a target integer. The function must go through the array and return the indices of two integers that, when added together, equal the target integer. Don’t throw your computer just yet, even though it may sound tasking it is actually much more simple than some may think.</p><p>The first step to solving this problem is obvious: create a function that takes two inputs, an array and a target integer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/1*kWU3tNFyRc6y3AqNAxbdRA.png" /><figcaption>Our two inputs: an array of integers and a target integer</figcaption></figure><p>Next we are going to want to create an answer array so that we can store our answers later on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/1*cE7bDTPTwdQT540d7dnHYQ.png" /><figcaption>We will push our two indices into this array at the end</figcaption></figure><p>Now, lets loop! We are going to use two for loops to loop through our array. The first for loop is going to act as the first number in our array, while the second is going to act as the second number. With each loop the the values of array[i] and array[j] will change to each number in the array, array[j] being one index above array[i].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*of6egwJCPe9fs6ekzCdJ9w.png" /><figcaption>The first for loop’s index starts at the first number and the second for loop’s index starts at the second number.</figcaption></figure><p>Now that we can go through the array number by number, the next step is to add a condition that will tell the function to return if the sum of those two integers is equal to the target number. We will set the condition using an if statement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*uUv-3DE4-YIrWvgq5u7QWQ.png" /><figcaption>If array element with an index of i + array element with index of j = target integer</figcaption></figure><p>Finally, we can push our answers to our answer array using the .push() method, which is used to add elements into an existing array. And then of course we have to then return our answer array so that we can see our answers!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*P1ykRXkA59u9bkblZHFQCg.png" /><figcaption>Pushing i, j into the empty answer array and then returning the answer array</figcaption></figure><p>There you have it! You have now officially solved the two sum algorithm, hopefully with some hair left on your head. Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8d66aeb5e840" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Active Record methods: Getting Started]]></title>
            <link>https://medium.com/@stevriss22/active-record-methods-you-should-definitely-know-a8cc92ce4bf0?source=rss-57080c7f9dbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8cc92ce4bf0</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Stephen Risso]]></dc:creator>
            <pubDate>Tue, 23 Nov 2021 21:40:08 GMT</pubDate>
            <atom:updated>2021-11-24T19:41:57.654Z</atom:updated>
            <content:encoded><![CDATA[<p>Active Record is an ORM framework that will perform queries on the database and return or manipulate the data that you are looking for. <em>ORM</em> or <em>Object</em> <em>Relational</em> <em>Mapping</em> connects data stored in the database via rows and columns to the objects of an application. In other words, ORM allows users to grab data from a database and interact with that data as if it were an object in Ruby. Active Record falls under the ‘Model’ layer of the MVC Architecture, which means that it is responsible for representing logic and data. Active Record eliminates the need for wordy SQL commands and can make a user’s code much cleaner and more readable.</p><p>This article is going to dive into some important Active Record methods that every user should know before they get started. The methods we will go into fall into three categories: finder, condition, and ordering methods. Finder methods allow us to search through database and return specific data. Conditions allow us to limit the data being returned by specifying certain conditions that the data will have to meet. Ordering methods allow us to order the returned data in a particular way. Getting familiar with some of the methods in these categories will give any programmer a head start when it comes to working with databases!</p><p>For some of these methods we will be referring to this table of mechanics! ‘Mechanic’ is going to be the class that we will be calling our active record methods on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P6KMQ2kkqU-3Ocf8ZFkjCw.png" /><figcaption>Note: An active record method(.create) is being used to create new mechanics in our ‘Mechanic’ table</figcaption></figure><h3>Finder Methods</h3><p>These methods will assist users in <em>finding</em> data that matches specific criteria and then returning that data to the user so it can be viewed or manipulated. There are many different finder methods, but these are some that anyone working with databases should be acquainted with.</p><h4><strong>.all</strong></h4><p>The <em>.all method </em>is not really much of a finder method because it returns <strong>everything</strong> from the class it is attached to. Even though it is not a finder method, it is a good way to grab <strong>all</strong> of your data so that you can sort through it with finder methods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OKvjWlFKLQHw_R5XsfoRqw.png" /><figcaption>Note how much more readable the active record method(Mechanic.all) is than SQL command(SELECT “mechanics”.* FROM “mechanics”)</figcaption></figure><h4>.find</h4><p>The <em>.find</em> method allows us to find an object(s) that have the corresponding primary key. A primary key is an id number that is given to every table item upon creation to help keep track of them. For example to get the table item with an primary key(id) of four, it would look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*00X95POd56eO42eYB-k2FA.png" /><figcaption>Again note the readability of the active record method compared to the SQL command.</figcaption></figure><p>As you can see above, the item with an primary key(id) of four was returned. But, what if we wanted to find two items in our table? All you need to do is add the primary keys(ids) of what your looking for into an array within the find method like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qhDSUsR9gnclu351d14wcw.png" /><figcaption>Now we have two items returned with ids of four AND five</figcaption></figure><h4>.find_by</h4><p>Searching for items in a table only using their primary key could get confusing, thankfully <em>.find_by </em>allows us to find the <strong>first</strong> table item that matches the conditions we give it! So now instead of searching by primary key we can search by ‘name’ or ‘specialty’ and get the first item that matches our criteria returned to us. If no match is found ‘nil’ is returned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WNQmdCtV2UCIc5UGq00AYA.png" /><figcaption>Notice that only one item, <strong>the first item</strong>, that matches the conditions will be returned</figcaption></figure><h4>.first/.last</h4><p>These two methods are pretty self explanatory, but could be very useful when navigating databases. The <em>.first </em>method<em> </em>returns the <strong>first</strong> item in the table and the <em>.last </em>method returns the <strong>last</strong> item. in the table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Jp0dbimGL0HlFWudpSpyg.png" /><figcaption>First and last items of table being returned</figcaption></figure><h4>.select</h4><p>The <em>.select</em> method works in two ways. The first way will accept a code block and treat the object as an array and iterate through it to return items matching the conditions inside of a new array. The second way takes in a symbol of the column name you want to see, and will return a relation object of all the values corresponding to the column symbol. This is easier to understand by visualizing it, see the examples of the two ways below:</p><p><strong>First:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uJtKsP1KnxDoRzI-BP8oZQ.png" /><figcaption>Here is the first way to use the .select method, we are iterating through our newly created mechanics ARRAY and returning each ‘mechanic’ whose specialty is ‘Brakes’</figcaption></figure><p><strong>Second:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yE__vq97j-2e9j7soDvkoA.png" /><figcaption>The second way returns the specialties for all of our table items</figcaption></figure><h3>Conditions</h3><p>These methods will return the user data basic on certain conditions that the user sets. These methods accept really specific conditions so that the user is able to find exactly what they want, even if the database is massive.</p><h4>.where</h4><p>The <em>.where</em> method can accept different types of conditions and do a lot of different things, which makes it extremely useful. It can accept strings, arrays, and hashes and use them to return very specific things from our tables! It returns a relation object and can be called on the class itself. The examples below will explain each <em>.where</em> conditions:</p><p><strong>Strings</strong></p><figure><img alt="Mechanic.where(“specialty = ‘Brakes’ “)" src="https://cdn-images-1.medium.com/max/1024/1*cryROU_bizCJsjOltwClKg.png" /><figcaption>Here, .where takes a string containing the column key set equal to the value you want to see</figcaption></figure><p><strong>Arrays</strong></p><p>The first part of the array should act as a template to let the class know what your looking for. The second part will actually be what your looking for. There are <strong>two</strong> different ways that we can format this:</p><p>1:</p><figure><img alt="Mechanic.where([“name = ? and specialty = ?”, “Tom Braidey”, “Brakes”])" src="https://cdn-images-1.medium.com/max/1024/1*sfRQhwwz-x07DXhr5SFTWw.png" /><figcaption>This first way is a little confusing, but it is separated in to two parts: the template(name=? and specialty =?) and the values we want.</figcaption></figure><p>2:</p><figure><img alt="Mechanic.where([“name = :name and specialty = :specialty”, {name: “Tom Braidey”, specialty: “Brakes”}])" src="https://cdn-images-1.medium.com/max/1024/1*RrlfT5ulUiZB4XFHmwOyIQ.png" /><figcaption>The second way is much more readable than the first. It allows you to make a new hash with your condition</figcaption></figure><p><strong>Hash</strong></p><p>If you are putting a hash as a condition all you need to do it enter the hash with the specific criteria you want to return. Multiple examples below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7kOaM3hYDs3juhjVrZ7NQA.png" /><figcaption>Here we ask to return a specific mechanic with a specific specialty</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WKHPbqut3REyhayHXIZ7Ig.png" /><figcaption>Here we ask to return mechanics whose names match the given names</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ucPpyzJ0mYt2UTl91hWWPQ.png" /><figcaption>Here we ask to return mechanics whose specialties match the given specialties</figcaption></figure><h3>Order</h3><p>These methods will help the user order their data in different ways.</p><h4>.order</h4><p>The <em>.order</em> method is relatively simple, as it does exactly what it says it does which is order the data. This method can be called on a class and by default it will return ascending or alphabetical order. You can order data simply by giving the <em>.order</em> method a string of a key or the symbol of a key. Below are a couple of different examples of how tis method can be used:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HFd07shXQvMt5rldxFT8VA.png" /><figcaption>Orders the table by the ‘name’ key. It sorts in alphabetical order when the values are strings and ascending order when the values are numbers</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZHFY-Ti5hVdWrUMqWqpILQ.png" /><figcaption>Does the same thing as the above example, but this time we give a string of the key instead of the symbol</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2xuv2GqDoDc5acKcprcWiw.png" /><figcaption>Orders the table by id in ascending order</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cBqBS7pOEx8qGGiwuPcPPA.png" /><figcaption>Orders the table by id in descending order</figcaption></figure><p>This all may seem like a lot, but active record was made to make the lives of developers easier. Active Record has a bunch of different methods, having a good understanding of the ones outlined in this article will give any developer more confidence with Active Record as well as back-end programming!</p><h3>Sources</h3><ul><li><a href="https://apidock.com/rails/ActiveRecord/QueryMethods/order">order</a></li><li><a href="https://apidock.com/rails/ActiveRecord/QueryMethods/where">where</a></li><li><a href="https://apidock.com/rails/v4.0.2/ActiveRecord/QueryMethods/select">select</a></li><li><a href="https://guides.rubyonrails.org/active_record_querying.html">Active Record Query Interface - Ruby on Rails Guides</a></li><li><a href="https://guides.rubyonrails.org/active_record_basics.html">Active Record Basics - Ruby on Rails Guides</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8cc92ce4bf0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Forms with React]]></title>
            <link>https://medium.com/@stevriss22/creating-and-handling-forms-on-react-acb99bf12055?source=rss-57080c7f9dbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/acb99bf12055</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[forms]]></category>
            <dc:creator><![CDATA[Stephen Risso]]></dc:creator>
            <pubDate>Tue, 16 Nov 2021 20:06:58 GMT</pubDate>
            <atom:updated>2021-11-23T18:07:41.631Z</atom:updated>
            <content:encoded><![CDATA[<p>This article will show how to create and handle a basic form on React. A form allows a user to interact with an application in some way. Forms allow users to simply type or select options on a page, but they can also be used to send that user input elsewhere within the app or in some cases to the server. Form input can be used to do a variety of thing different things. Below is a very simple form that returns an empty input field that accepts text input from the user:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*4-dd3DJufldQD648Jfra0w.png" /><figcaption>Shows a simple form within a react component. Forms should have an input field(s) that allows the user to enter some sort of data(in this case text input). The input field(s) should be wrapped in &lt;form&gt; tags.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/1*dlfkDmg8P8GfGAT293kDxw.png" /></figure><p>As it is right now, the user can type any text into the form and it will be visible within the input field, but as it is right now nothing can be done with that input. In order to use that user text input to do something the form needs to be handled!</p><h3>Handling Forms</h3><p>Handling a form means: how data is going to be handled when the form is changed or submitted. For example, if a user wanted to post a comment on a social application all they have to do is type in the comment, click ‘Submit’, and BAM the comment magically appears under the post. This is actually just form handling! When the user clicks that ‘Submit’ button the data(or in this case ‘the comment’) will be sent somewhere within the application and something will be done to it or in other words, <em>the data will be handled</em>(in this case the comment will be posted underneath the post)! The screenshots below will break down the process of handling a form:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*24WXfMr6wvPBNwHhzbVGhQ.png" /><figcaption>This screenshot shows a simple form with a text input field and a submit button. Here, a ‘submit’ button has been added to our form.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/1*_IH1aQwpuXZN-bDNuuONHw.png" /></figure><p>As it is right now, when the user clicks the ‘Submit!’ button after the text input is entered the page will reload and the input will go away. In order for this form to do something with the input when we submit, we have to add some code into our form that is going to ‘handle’ our form data. In order to do this, we use event handlers! Event handlers tell the application what do when a certain event is triggered. In this case, we want the listener to handle the whole form when it is submitted(it will be telling our form what to do when ‘Submit!’ is clicked) so we attach an event listener to our <em>entire</em> form:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*cNVpbY-zu6HN9MEZ7vxOBg.png" /><figcaption>Do not be startled! The only change here is the ‘onSubmit’ event listener. The listener will wait until the event(e) is triggered and when it is triggered the listener will prevent the default of the event(e), which in this case is a page refresh.</figcaption></figure><p>Now when the user clicks the ‘Submit!’ button the entire form will be handled by our ‘onSubmit’ event listener. This time when the form is submitted, the default action of the event(a page reload) is prevented and the user input stays on the page!</p><p>Now that we have an event listener that will help the user <em>handle </em>the form data when an event is triggered, the user can now decide what exactly is to be done with that form data. From here there are a couple of routes the user can take to manipulate the form data. In the previous screenshot, we do what we want to do right inside of the listener callback function. While doing this will accomplish what you want in some cases, it is not always best practice. It is better that we have a <em>handler function</em> that can handle our event.</p><p>In this case, the form is just going to alert the user that the form has been submitted. The user perform this action by creating a <em>handler function</em>. This <em>handler function</em> is simply a function that is going to handle our event(e). Below is a screenshot of the same form, but with a handler function that handles our event and does something when the event is triggered:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*HyBVSXW9gXcONNJBBGJqFg.png" /><figcaption>This screenshot shows a form that has an ‘onSubmit’ event listener attached to it. When the ‘onSubmit’ listener is triggered(by clicking “Submit!”) the event(e) will then be passed to a handler function. This handler function will prevent the default action of a ‘submit’(page reload) and then alert the user that the form has been submitted!</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*Szv0cyjjn4MZcwckQGShVg.png" /></figure><p>This time when we click ‘Submit!’, the ‘onSubmit’ event listener will listen for the event(e) and pass it to our handler function where we will handle the event. Inside of the handler function, we prevent the default action(page reload) of the submit event and then send an alert to the user telling them that form is submitted!</p><p>Now we have finally created a form that will be handled if it is submitted. Obviously, users can do much more with the form data after obtaining it from the form, but for the sake of simplicity the handler function only alerted the user of the form submission. Thinking back to the example provided earlier of a social media comment, once the user grabs the form data(or the ‘comment’) maybe they have a function in the application that will take that form data and format it into a comment under the post. Or maybe they will format it right there in the handler function. It is completely up to the programmer who is working on the application.</p><p>Forms are a great way to make applications more dynamic and add many more possibilities when it comes to accepting data from the user and using or saving that data elsewhere in the application!</p><h3>Sources</h3><ul><li><a href="https://reactjs.org/docs/handling-events.html">Handling Events - React</a></li><li><a href="https://reactjs.org/docs/forms.html">Forms - React</a></li><li><a href="https://www.w3schools.com/react/react_forms.asp">React Forms</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=acb99bf12055" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a React Component from Scratch]]></title>
            <link>https://medium.com/@stevriss22/creating-a-react-component-from-scratch-b620a1788777?source=rss-57080c7f9dbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/b620a1788777</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[jsx]]></category>
            <dc:creator><![CDATA[Stephen Risso]]></dc:creator>
            <pubDate>Tue, 02 Nov 2021 21:12:41 GMT</pubDate>
            <atom:updated>2021-11-02T21:12:41.359Z</atom:updated>
            <content:encoded><![CDATA[<p>This article will dive into React components and everything a user should know about them before creating a components within a React application.</p><p>React components allow you to split up the user interface into independently functioning parts of the React application. Users can work on these components and make changes within them without affecting other components in the app. Components perform a specific function within the app and also tell the page what to render. The format of a React component may look similar to something the user has seen before if they have worked with ‘vanilla’ JavaScript in the past.</p><p>React components are formulated very much like JavaScript functions, with a few differences. Below is an example of an empty React component:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*fN9kWn2DA9vBzCFDS2LbvQ.png" /></figure><p>As seen in the example, the structure of the component is almost exactly that of a JavaScript function. Both have a ‘function’ key word, a function name, and a return value. Although, just because something looks similar to something else does not mean that they are similar. Some key differences to note about components: component names must start with a capital letter, components return what looks like the tags for an HTML element, and below the component there is some sort of export statement. These are what make React components unique.</p><h3>JSX</h3><p>Components return something called JSX, which is a syntax extension to JavaScript that can be used to describe what the pages should look like. JSX returns React elements which provide structure to the page when rendered. JSX is not HTML, but rather something that will render HTML on the page for the user. Users can nest JSX elements within each other(just like HTML) to add even more structure to the return value, but something important to note is that all JSX elements need to be nested within one overall container ‘div’. Styling attributes can also be added within JSX elements by entering the keyword ‘style’ as an attribute to the element. JavaScript can be embedded into JSX when enclosed between curly braces ({}) and can be used to create conditionals and other actions. Below are two examples of JSX syntax:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*VOAn4YjzcIEZg5fd_bv_Xw.png" /><figcaption>Creating a variable with its value being a JSX element.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qqViQJsxUdDDHfSHdqMwaA.png" /><figcaption>JSX element being returned from a react component.</figcaption></figure><h3>Imports and Exports</h3><p>In order for components to be used and reused throughout the app, the use must add import/export operations. The first operation we will look at will be the import. An example of an import is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*2Z0Kq0qhgrg0W0ZjiGMydw.png" /></figure><p>What this does is ‘import’ the default ‘export’ from the component that is being imported. In other words, the user will be importing the export value of ‘ReactComponent’ from the location(relative path)of the component, which is ‘./ReactComponent’. Importing will allow the user to the export value of one component inside of other components, which means the application can be more dynamic. From this, the user can derive what an ‘export’ is, an example of an export is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*rJn8S1naGWhyDEE9v_PfQg.png" /></figure><p>The export shown above is a ‘default’ export, which means that the user is going to export the default value from the component. User’s can also have named exports, which just specify a certain part of the component that is to be exported. The goal of an export is to package up what we want to use from a component and getting it ready to be imported into another component if needed. By importing and exporting components our React applications become way more dynamic and more organized.</p><p>An example of importing and exporting named values is shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*xSZGkRDdm8ErXLniJ5qSbQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*tHJtfG6wiDPO5pXL6BKIrA.png" /></figure><p>Using components in your React applications can make the application cleaner, clearer, and more dynamic. It can also eliminate the time and energy it takes hardcoding HTML and then manipulating the page with JavaScript! Now you should have the tools needed to create the structure of a basic component within your React application.</p><h4>Sources:</h4><ul><li><a href="https://www.geeksforgeeks.org/reactjs-importing-exporting/">ReactJS | Importing and Exporting - GeeksforGeeks</a></li><li><a href="https://reactjs.org/docs/introducing-jsx.html">Introducing JSX - React</a></li><li><a href="https://reactjs.org/docs/components-and-props.html">Components and Props - React</a></li><li><a href="https://www.tutorialspoint.com/reactjs/reactjs_jsx.htm">ReactJS - JSX</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b620a1788777" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Differences between .innerText(),  .textContent(), & .innerHTML()]]></title>
            <link>https://medium.com/@stevriss22/differences-between-innertext-textcontent-innerhtml-23268b2ac7b2?source=rss-57080c7f9dbb------2</link>
            <guid isPermaLink="false">https://medium.com/p/23268b2ac7b2</guid>
            <dc:creator><![CDATA[Stephen Risso]]></dc:creator>
            <pubDate>Tue, 26 Oct 2021 18:40:46 GMT</pubDate>
            <atom:updated>2021-11-23T21:42:58.119Z</atom:updated>
            <content:encoded><![CDATA[<h3>Learn Javascript: innerText vs. textContent vs. innerHTML</h3><p>In JavaScript, there are a couple different ways to manipulate or view inner text content of a node within the Document Object Model (‘DOM’). Navigating these different properties could be tricky if you don’t have the proper knowledge or experience. The first property we will look at, ‘.innerText’, shows the rendered inner text content of a node. The next properties, ‘.textContent’ &amp; ‘.innerHTML, both return the text content of all children of a parent node, but the actual text content they return differ. Each have their own unique differences and are to be used in certain ways. In some cases these properties will give back the same return value, giving the impression that they can be used interchangeably without consequence. This can cause confusion, especially if the user is not an experienced programmer. Below is an example of this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*TGA_4H1X487MkHUrJmo8iA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/1*ZYMrq2O9CwnDcHYxLLC_hw.png" /><figcaption>The return value for all three are the same in this case.</figcaption></figure><p>Users may see this and think there is no harm in using ‘.textContent’ instead of ‘.innerText’, but there are key differences between the three and the values they return especially when child nodes and styling become involved. You can see these differences illustrated in the screenshots below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*ZZFfGcef863WWA_T5VEQVw.png" /><figcaption>Here a &lt;strong&gt; style tag was added within the inner text content of the node.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*SxrEDYRrxk1MyJMzMBKh7w.png" /><figcaption>In this case, the return all three will have different return values. ‘.innerText’ will return the text with ‘BIG’ bolded. ‘.textContent. will return only the content of the node without any regard to styling. ‘.innerHTML’ will return the strict inner text of the node showing the styling tags.</figcaption></figure><p>Misusing these properties within your code can cause unexpected errors and A LOT of frustration. So skip the headache and get acquainted with each of them!</p><h3>“.innerText”</h3><p>If the user needs to grab the rendered inner text content, it is best to use ‘.innerText’. In other words, if a user wants to return text with CSS attributes(such as bolding, italics, etc.) and the same spacing as the node ‘.innerText’ is the way to go. In most cases when we are grabbing the inner text content of a node they want to bring its attributes with it, so this is the best route.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/324/1*ZZFfGcef863WWA_T5VEQVw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/256/1*zpJq2pIQ1nYfJHSgfQNkpA.png" /><figcaption>‘.innerText’. returns the rendered inner text content of the node it is called on. Any changes made using this property will render on the page.</figcaption></figure><h3>“.textContent”</h3><p>This property returns the inner text content of <strong>all</strong> children of the node it is called on. It ignores styling and is only looking for the non-rendered text content of the nodes. If a parent node has 400 child nodes and the ‘.textContent’ property is called on the parent node, the inner text content of ALL 400 child nodes will be displayed. If the ‘.textContent’ property is called on only one of the child nodes then only the inner text content of THAT SPECIFIC child node will be returned(W/o CSS attributes)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*EDqGOFOX7AFsd-Z3udV1bw.png" /><figcaption>Here a child node is added to the original code.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*eS8xiog5XtHPRD5QpN_HMA.png" /><figcaption>In this case, ‘.textContent’ returns the the inner text content of ALL child nodes.</figcaption></figure><h3>“.innerHTML”</h3><p>This property is the easiest to differentiate from the other two. ‘.innerHTML’, like ‘.textContent’, returns the inner text content of <strong>all</strong> child nodes. The difference is that ‘.innerHTML’ returns the non-rendered text content <strong>as well as</strong> the HTML tags of the child nodes. This means that HTML or CSS tags within the parent node will also be returned when it is called on a parent node. This can be seen below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*EDqGOFOX7AFsd-Z3udV1bw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ljHu1hHlh18b0S1B5e1NrQ.png" /><figcaption>Here, the inner HTML of the parent node is being shown.</figcaption></figure><p>These examples and explanations should help anyone conquer the beasts that are ‘.innerText’, .’textContent’, and ‘.innerHTML’!</p><p>Sources:</p><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML">Element: innerHTML property - Web APIs | MDN</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText">HTMLElement: innerText property - Web APIs | MDN</a></li></ul><p><a href="https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent">https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23268b2ac7b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>