Skip to content

Instantly share code, notes, and snippets.

@elskwid
Created September 25, 2014 23:36
Show Gist options
  • Save elskwid/582e7f06d0d64ed3f212 to your computer and use it in GitHub Desktop.
Save elskwid/582e7f06d0d64ed3f212 to your computer and use it in GitHub Desktop.
# Remember: use `ruby exercise3.rb` to run this file
# 1. display the contents of the `my_variable` variable
my_variable = "100"
# 2. assign the integer 5 to a variable named 'number'
# 3. display the contents of the 'number' variable
# 4. change (coerce) the string in 'my_variable' into an integer
# 5. put the coerced string, now an integer, into a variable named 'new_number'
# 6. display the contents of the 'new_number' variable
# 7. add 'number' to 'new_number' and assign it to a variable named 'sum'
# 8. create an array with the values 1, 2, 4, and 5, assign it to a variable named `numbers`
# 9. display the contents of the array at index 1
# 10. display array element (contents) at index 10
# 11. use `each_with_index` to display the number and index for the `numbers` array
# 12. put a comment here that says what kind of operation `each_with_index` is
# Hint: comments start with a `#`
# 13. create a hash with the keys of one, two, three, four, five and the values of 1, 2, 3, 4, 5
# Hint: "one" => 1
# 14. use `each` to display the key and value for each member of the hash
# Question: did you remember to put the hash in a variable?
# 15. change the display of the hash to say:
# "The value of 'one' is 1" for each member of the hash, so 'two' is 2, and 'three' is 3, etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment