Created
August 21, 2019 01:47
-
-
Save harrisonmalone/16716566b9a74c3ba68b162c27d100de to your computer and use it in GitHub Desktop.
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
| # 1. Make two variables called name and age. Assign them values, e.g. name = "bob" age = 20. Use string interpolation to print "My name is Bob and I am 20 years old". | |
| # string | |
| name = "Bob" | |
| # integer | |
| age = 20 | |
| # p "My name is #{name} and I am #{age} years old" | |
| # 1. p | |
| # 2. puts | |
| # 3. print | |
| # 2. Here are two variables: x = 2, y = 3; Use string interpolation to print to screen: "The result of adding x to y is 5". | |
| x = 2 | |
| y = 3 | |
| # p "The result of adding x to y is #{x + y}" | |
| # escape characters | |
| # \n | |
| # makes a newline | |
| # puts "Hi my name is \"Harrison Malone\"" | |
| # to the power of | |
| string_number = "10" | |
| # p string_number.class | |
| int_number = string_number.to_i | |
| # p int_number.class | |
| result = int_number ** 3 | |
| # p result | |
| another_number = 100 | |
| another_number_as_a_string = another_number.to_s | |
| # p another_number_as_a_string.class | |
| sum = 5 / 2.to_f | |
| # p sum | |
| puts "number calculator" | |
| puts "whats your first number?" | |
| print "> " | |
| number_one = gets.chomp | |
| puts "whats your second number?" | |
| print "> " | |
| number_two = gets.chomp | |
| result = number_one.to_i + number_two.to_i | |
| p result | |
| # strip and chomp | |
| # name = gets.strip | |
| # p name | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment