<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: G Hewitt</title>
    <description>The latest articles on DEV Community by G Hewitt (@ghewitt95).</description>
    <link>https://dev.to/ghewitt95</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1664373%2F4574d1fa-1330-485d-a75f-9392d3ba3d1d.jpg</url>
      <title>DEV Community: G Hewitt</title>
      <link>https://dev.to/ghewitt95</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ghewitt95"/>
    <language>en</language>
    <item>
      <title>Water Intake Program in Ruby: Part 2</title>
      <dc:creator>G Hewitt</dc:creator>
      <pubDate>Tue, 26 Nov 2024 23:56:13 +0000</pubDate>
      <link>https://dev.to/ghewitt95/water-intake-program-in-ruby-part-2-2kbp</link>
      <guid>https://dev.to/ghewitt95/water-intake-program-in-ruby-part-2-2kbp</guid>
      <description>&lt;p&gt;After taking some time to familiarize myself with Ruby, I decided to take a look back at the Water Intake Program I created a few months earlier with the purpose of applying what I learned and (hopefully) simplify my code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the Program
&lt;/h2&gt;

&lt;p&gt;The first major difference you will see in my code is that it starts with the addition of a &lt;strong&gt;&lt;u&gt;class&lt;/u&gt;&lt;/strong&gt;. The best way to describe a class is as a blueprint for creating objects, which makes sense because Ruby is an object-orientated language.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;WaterIntakeCalculator&lt;/span&gt;
  &lt;span class="nb"&gt;attr_accessor&lt;/span&gt; &lt;span class="ss"&gt;:name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:weight&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:minutes_exercised&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:temperature&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:pregnant&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After naming the class, I added attributes by using &lt;u&gt;&lt;strong&gt;attr_accessor&lt;/strong&gt;&lt;/u&gt;. It is best described as a shortcut that creates methods for each attribute, so we don't have to define these methods individually. &lt;/p&gt;

&lt;p&gt;Next, I created instance variables using "@" and put them inside the initialize method to set the starting values for each instance of my WaterIntakeCalculator class. This method should run every time a new object is created from the class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;initialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minutes_exercised&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;temperature&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pregnant&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="vi"&gt;@name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;name&lt;/span&gt;
    &lt;span class="vi"&gt;@weight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;weight&lt;/span&gt;
    &lt;span class="vi"&gt;@minutes_exercised&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;minutes_exercised&lt;/span&gt;
    &lt;span class="vi"&gt;@temperature&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;temperature&lt;/span&gt;
    &lt;span class="vi"&gt;@pregnant&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pregnant&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I had trouble understanding the concept of &lt;strong&gt;&lt;u&gt;Instance Variables&lt;/u&gt;&lt;/strong&gt;. It started to make more sense once someone explained it to me using this real world example:&lt;/p&gt;

&lt;p&gt;Imagine kids sitting at the same table with their lunchboxes from home. Inside their lunchbox, they each have their own food and snacks that make it uniquely theirs. One child might have a turkey sandwich while someone else might have a fruit cup.&lt;/p&gt;

&lt;p&gt;In this analogy, the lunchbox is the object I created from the class, the food inside it represents the instance variables, each holding specific values that belong only to their lunchbox.&lt;/p&gt;

&lt;p&gt;Just like I did in the first version of this program, I made two methods, one to calculate weight intake and the other to calculate exercise intake. These will come in handy later:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculate_weight_intake&lt;/span&gt;
    &lt;span class="vi"&gt;@weight&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculate_exercise_intake&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="vi"&gt;@minutes_exercised&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;30.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To wrap it all together, I created a method that calculates the total water intake by combining the weight and exercise intake. This method will also adjust based on the needs of the user. Adding 32 extra ounces if your pregnant, and an additional 16 ounces if the current temperature is higher than 70°F. (In the future, I plan to integrate an API to automatically adjust intake based on real-time temperature.) Finally, I added a method that will convert the total intake into glasses of water (8 ounces each).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;calculate_total_intake&lt;/span&gt;
    &lt;span class="n"&gt;intake&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;calculate_weight_intake&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;calculate_exercise_intake&lt;/span&gt;

    &lt;span class="n"&gt;intake&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="vi"&gt;@pregnant&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;downcase&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'yes'&lt;/span&gt;

    &lt;span class="n"&gt;intake&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="vi"&gt;@temperature&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;70&lt;/span&gt;

    &lt;span class="n"&gt;intake&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;glasses_of_water&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;calculate_total_intake&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to_i&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt; 
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To complete the class above, I added the final 'end' to close the WaterIntakeCalculator class definition, while also making sure the code is properly structured and error-free.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;home&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Enter your name:"&lt;/span&gt;
  &lt;span class="nb"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chomp&lt;/span&gt;

  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Hello &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;,
This is a water intake program that will estimate the amount of water you'll have to drink today. 
It will take into consideration:
 - Weight
 - Activity Level
 - Outdoor Temperature
 Let's get started! Are you currently pregnant or breastfeeding? (yes/no)"&lt;/span&gt;
 &lt;span class="n"&gt;pregnant&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chomp&lt;/span&gt;

 &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Next, enter your weight (in pounds):"&lt;/span&gt;
 &lt;span class="n"&gt;weight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chomp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_f&lt;/span&gt;

 &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Please enter the amount of minutes exercised today:"&lt;/span&gt;
 &lt;span class="n"&gt;minutes_exercised&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chomp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_f&lt;/span&gt;

 &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Now let's take into consideration the weather. What is the current temperature?:"&lt;/span&gt;
 &lt;span class="n"&gt;temperature&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chomp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_i&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything above may look familiar if you read the first part of my Water Intake post. In the previous version, this script was scattered all across various sections. This time around, I organized it all under the method named 'home' (I couldn't think of a better name). Doing this made my code feel cleaner and easier to follow.&lt;/p&gt;

&lt;p&gt;The next few lines following is where things get different:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;calculator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;WaterIntakeCalculator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minutes_exercised&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;temperature&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pregnant&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

 &lt;span class="n"&gt;daily_intake&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;calculate_total_intake&lt;/span&gt;
 &lt;span class="n"&gt;glasses_of_water&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;calculator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;glasses_of_water&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, I'm creating a new instance for the WaterIntakeCalculator class to hold the user's data for when the program calls for the 'calculate_total_intake' and 'glasses_of_water' methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt; &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Thank you &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;. Your water intake for today is &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;daily_intake&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; ounces. That equates to around &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;glasses_of_water&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; glasses of water. Stay hydrated, my friend!"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;home&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, I closed the 'home' method and called it at the end of the file. When I run this program, it will execute everything within that method. Everything runs smoothly!&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I’ve transformed my Water Intake Program by structuring it with a class and organizing my code into methods, making it cleaner and easier to understand. It’s exciting to see my growth in Ruby as I apply these concepts to enhance my projects. I look forward to continuing this journey and refining my skills further!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Water Intake Program in Ruby</title>
      <dc:creator>G Hewitt</dc:creator>
      <pubDate>Tue, 27 Aug 2024 21:41:07 +0000</pubDate>
      <link>https://dev.to/ghewitt95/water-intake-program-in-ruby-24m2</link>
      <guid>https://dev.to/ghewitt95/water-intake-program-in-ruby-24m2</guid>
      <description>&lt;p&gt;To avoid getting stuck in tutorial hell, I decided to create a few small projects to apply the Ruby skills that I'm currently learning and record my progress on my blog. &lt;/p&gt;

&lt;p&gt;After spending too many hours wondering what my first official project should be, I decided to work on a water intake program.&lt;/p&gt;

&lt;p&gt;The goal of this program is to calculate how many ounces of water a person should drink daily based on their:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Weight&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Daily Exercise&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Special Circumstances (Pregnant/Breastfeeding, Outdoor temperature, etc.)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After calculating the required ounces of water, I will then tell the program to translate that into glasses of water, where 8 Ounces = 1 Glass. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;u&gt;Water Intake Research
&lt;/u&gt;
&lt;/h3&gt;



&lt;p&gt;The sources I used to research the calculations for this program are: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.umsystem.edu/totalrewards/wellness/how-to-calculate-how-much-water-you-should-drink" rel="noopener noreferrer"&gt;University of Missouri System&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://resourcecenter.kinetico.com/water-home-health/water-consumption/" rel="noopener noreferrer"&gt;Kinetico Water Systems&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;According to both sources, The first thing to calculate when finding out your daily water intake is your weight. The formula for that is: &lt;/p&gt;

&lt;p&gt;weight * 0.5 = ounces of water per day&lt;/p&gt;

&lt;p&gt;The next step is to find out how many ounces to add to the previous result based on the amount of time you spend exercising that day. It is recommended to add 12 ounces every 30 minutes that you spend exercising. The formula would look like: &lt;/p&gt;

&lt;p&gt;previous result + (minutes of exercise / 30 * 12) = ounces of water per day&lt;/p&gt;

&lt;p&gt;Lastly, There are special situations where more ounces might be added to the total intake. For example, If someone is pregnant or breastfeeding, they will need to increase their intake by 32 ounces. &lt;/p&gt;

&lt;p&gt;The temperature also plays a role in water consumption. In this program, If the current temperature is over 70 degrees, another 16 ounces will be added to the total daily intake.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating Program
&lt;/h2&gt;

&lt;p&gt;Since each user will have their own results, I decided to make the program more personal by starting off with asking for their name. To do this, I used the method 'puts' followed by the "Enter your name:" in quotations. doing so will print the string to the console. &lt;/p&gt;

&lt;p&gt;Afterwards, the console needs to read input from the the user. That is done by using the 'gets.chomp' the first of these methods, 'gets' allows the user to type their input, in this case, 'name', and turn it into a string. While 'chomp' is used to remove the new line character from the captured string. So far, the editor should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Enter your name:"&lt;/span&gt;

&lt;span class="nb"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chomp&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From now on in the program, whatever the user input for 'name' string was, will show up anytime #{name} is present. This is called String Interpolation. After the user provides the program with their name, They will be introduced to text that explains how the program works, and ask if the user is pregnant.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Hello &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;!
This is a water intake program that will estimate the amount of water you'll have to drink today.
It will take into consideration:
- Weight
- Activity Level
- Outdoor Temperature
Let's get started! Are you currently pregnant or breastfeeding? If so, It is recommended to increase your daily intake by 32 ounces"&lt;/span&gt;

&lt;span class="n"&gt;pregnant_response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chomp&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The 'pregnant_response' string will look for either a 'yes' or 'no' response. This will play a part in the program later on. After the user enters a response, the program will set the 'daily_intake' integer to 0. Doing so allows the variable of 'daily_intake' to start at zero and lets the program track the intake from there. &lt;/p&gt;

&lt;p&gt;The program will then ask the user to put in their weight and the amount of minutes that they exercised today. We'll use the same 'gets.chomp' that we used earlier when asked to type your name, but with the addition of '.to_f'. This converts the string into a floating-point number. Which is a number with a decimal point.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;daily_intake&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;

&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Next, enter your weight:"&lt;/span&gt;

&lt;span class="n"&gt;weight&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chomp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_f&lt;/span&gt;

&lt;span class="n"&gt;weight_intake&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_f&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;

&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Please enter the amount of minutes exercised today."&lt;/span&gt;

&lt;span class="n"&gt;minutes_exercised&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chomp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_f&lt;/span&gt;

&lt;span class="n"&gt;exercise_intake&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;minutes_exercised&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_f&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;

&lt;span class="n"&gt;daily_intake&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;exercise_intake&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;weight_intake&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might have noticed the two expressions that are typed out under both 'get.chomp' strings. These expressions are what we use to calculate the value of the variable. In the case of the 'weight_intake' variable, we use 'weight' variable multiplied by 0.5. Then we calculate the 'exercise_intake' variable by dividing the 'minutes_exercised' variable by 30 and multiplying that answer by 12.&lt;/p&gt;

&lt;p&gt;the final expression shown above takes the answer from both the 'weight_intake' and 'exercise_intake' and adds them together giving you the 'daily_intake' variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Now let's take into consideration the weather. What is the current temperature?:"&lt;/span&gt;

&lt;span class="n"&gt;temperature&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chomp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_i&lt;/span&gt;


&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;pregnant_response&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"yes"&lt;/span&gt; 
  &lt;span class="n"&gt;daily_intake&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;temperature&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;70&lt;/span&gt;
  &lt;span class="n"&gt;daily_intake&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;glasses_of_water&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;daily_intake&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;

&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Thank you &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;. You water intake for today is &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;daily_intake&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; ounces. That equates to
around &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;glasses_of_water&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_i&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; glasses of water. Stay hydrated, my friend."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is where the special circumstances come into play. Earlier in the code, the user was asked if they were pregnant or breastfeeding. If the answered 'yes' to that question. 32 ounces gets added to the final 'daily_intake' number. If the user entered an integer that was greater than  70 when asked what the temperature was, 16 ounces is also added to the final 'daily_intake' number. &lt;/p&gt;

&lt;p&gt;Our last expression in the code is used to convert the amount of water in ounces to glasses of water by dividing our final 'daily_intake' by 8. &lt;/p&gt;

&lt;p&gt;You might notice that 'glasses_of_water' has a string of '.to_i' instead of '.to_f'. This will round the variable to the nearest whole number. instead of a number with a decimal. &lt;/p&gt;

&lt;p&gt;Creating this water intake program was a great way to apply the Ruby skills that I have been learning. I'm excited to continue working on more projects like this and sharing my progress on the blog!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>ruby</category>
      <category>git</category>
    </item>
    <item>
      <title>TIL: The Basics of GitHub</title>
      <dc:creator>G Hewitt</dc:creator>
      <pubDate>Wed, 26 Jun 2024 15:56:05 +0000</pubDate>
      <link>https://dev.to/ghewitt95/til-the-basics-of-github-307a</link>
      <guid>https://dev.to/ghewitt95/til-the-basics-of-github-307a</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;"Every morning we are born again. What we do today is what matters most." — Buddha&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When I began writing blog posts earlier this year, I would start off with a quote that reflected my current outlook on life. I think it would be a good idea to continue that tradition here.&lt;/p&gt;

&lt;p&gt;Today I learned how to store a static webpage on GitHub. GitHub is used to store code, and keep track of the revisions made to your files. I feel like this will be very useful for collaborating with others.&lt;/p&gt;

&lt;p&gt;In addition, I used Codespaces, which is a cloud code editor that is based on VSCode. I was relieved when I saw this because the only code editor I had experience with before this apprenticeship was VSCode. So I felt right at home with Codespaces&lt;/p&gt;

&lt;p&gt;After creating a simple "Hello world!" webpage, I deployed the app by using Render. Render is a hosting provider that allows your page to be viewed by anyone. &lt;/p&gt;

&lt;p&gt;I had to plug this code into my Codespace in a new file called 'render.yaml'&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;services:
  - type: web
    name: hello-world
    env: ruby
    plan: free
    buildCommand: "./bin/render-build.sh"
    startCommand: "./bin/render-start.sh" 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After doing this and creating a blueprint, I went back to GitHub Pages to deploy my site! I know it's not much, But i feel like this will be a milestone that I will look back on!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>todayilearned</category>
      <category>github</category>
    </item>
  </channel>
</rss>
