Created
April 2, 2015 14:45
-
-
Save phlipper/e5e677a56e389ac19c83 to your computer and use it in GitHub Desktop.
TECH603 Day 2 Warmup
This file contains 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. Create a `day_2` directory under the course directory. | |
# Check! | |
# 2. Save this file under the new folder as `warmup.rb`. | |
# Check! | |
# 3. Assign your favorite vacation location to a variable called `destination`. | |
destination = "Spain" | |
# 4. Assign the number of days you'd like to visit to a variable called | |
# `duration`. | |
duration = 100 | |
# 5. Assign any floating point number to a variable named `price`. | |
price = 1.23 | |
# 6. Output the following message: | |
# I would like to visit _ for _ days, and pay only _ for the whole trip. | |
puts "I would like to visit #{destination} for #{duration} days, and pay only #{price} for the whole trip." | |
puts "I would like to visit " + destination + " for " + duration.to_s + " days, and pay only " + price.to_s + " for the whole trip." | |
# 7. Add each of the previous variables to a collection. | |
vacation = [destination, duration, price] | |
# 8. Iterate through the collection and output each item. | |
vacation.each do |item| | |
puts item | |
end | |
for item in vacation | |
puts item | |
end | |
i = 0 | |
while i <= vacation.size | |
puts vacation[i].inspect | |
i = i + 1 | |
end | |
# 9. Create a dictionary called `vacation`. Use the previous variable names as | |
# keys and assign the values. | |
vacation = { | |
"destination" => "Spain", | |
"duration" => 100, | |
"price" => 1.23 | |
} | |
vacation2 = { | |
:destination => "Spain", | |
:duration => 100, | |
:price => 1.23 | |
} | |
vacation3 = { | |
destination: "Spain", | |
duration: 100, | |
price: 1.23 | |
} | |
# 10. Using the dictionary from the previous step, output the following message: | |
# I would like to visit _ for _ days, and pay only _ for the whole trip. | |
puts "I would like to visit #{vacation["destination"]} for #{vacation["duration"]} days, and pay only #{vacation["price"]} for the whole trip." | |
# 11. Create a function called `yell`. It should take a single argument and | |
# return an uppercase version of the input. | |
def yell(message) | |
string_message = message.to_s | |
return string_message.upcase | |
end | |
puts yell("hello") | |
puts yell(250) | |
puts yell(1.23) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment