Skip to content

Instantly share code, notes, and snippets.

@Jaltman429
Created June 10, 2013 21:34
Show Gist options
  • Save Jaltman429/5752544 to your computer and use it in GitHub Desktop.
Save Jaltman429/5752544 to your computer and use it in GitHub Desktop.
arrays.rb
# Construct an array with your favorite foods. It should have at least 5 elements.
# Write a puts which returns your most favorite food out of the array.
favorite_foods = ['pizza', 'bagel', 'sandwich', 'chicken', 'apple']
favorite_foods.each_with_index do |food, index|
puts (index + 1).to_s + ". " + food.capitalize
end
puts "Which is your favorite food? Please pick a number."
food = gets.strip.to_i
puts "Your favorite food is " + favorite_foods[(food-1)] +"."
# Construct an array with the colors of the rainbow (ROYGBIV)
# Slice the colors Red, Orange, and Yellow out of the array.
rainbows = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']
puts rainbows.slice(3,4)
# Create an empty array.
# Assign values to the the second and 6th position.
array = []
array[1] = 'jack'
array[5] = 'altman'
puts array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment