Last active
December 21, 2015 18:39
-
-
Save jendiamond/6348401 to your computer and use it in GitHub Desktop.
Exercise 5 - Learn Ruby the Hard Way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # The assignment operator = assigns the string 'Jen Diamond'to the variable name | |
| name = 'Jen Diamond' | |
| # The assignment operator = assigns the integer 44 to the variable age | |
| age = 44 # not a lie | |
| # The assignment operator = assigns the integer 69 to the variable height | |
| height = 69 # inches | |
| # The assignment operator = assigns the integer 101 to the variable weight | |
| weight = 101 # total lie | |
| # The assignment operator = assigns the string 'green' to the variable eyes | |
| eyes = 'green' | |
| # The assignment operator = assigns the string 'white-ish' to the variable teeth | |
| teeth = 'white-ish' | |
| # The assignment operator = assigns the string 'auburn-ish' to the variable hair | |
| hair = 'auburn-ish' | |
| # String interpolation | |
| # %s and %d are formatters they are flags; | |
| # s stands for string | |
| # d stands for decimal number | |
| # the method puts outputs the string and the embedded variable name | |
| puts "Let's talk about %s." % name | |
| # the method puts outputs the string and the embedded variable height | |
| puts "She's %d inches tall." % height | |
| # the method puts outputs the string and the embedded variable | |
| # which is an equation converting inches to centimeters using the variable of | |
| # height in inches multiplied by 2.54 | |
| puts "She is also %d centimeters tall which is the same thing." % [height * 2.54] | |
| # the method puts outputs the string and the embedded variable weight | |
| puts "Today she weighs %d " % weight + "but is exercising and dieting to improve this number." | |
| # the method puts outputs the string and the embedded variable | |
| # which is an equation converting pounds to kilograms using the variable of weight | |
| # in pounds multiplied by 2.2 | |
| puts "Kilos sound better. Today she weighs %d kilos." % [weight / 2.2] | |
| # the method puts outputs the string and the embedded variables for eyes and hair | |
| puts "She has %s eyes and %s hair." % [eyes, hair] | |
| # the method puts outputs the string and the embedded variable teeth | |
| puts "Her teeth are usually %s depending on how much tea she has had." % teeth | |
| # the method puts outputs the string and the embedded variables age, height, weight | |
| # and the sum of these variables | |
| puts "If I add %d, %d, and %d I get %d." % [age, height, weight, age + height + weight] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment