Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Alphonse Cuccurullo
Alphonse Cuccurullo
2,513 Points

Having trouble converting to symbols.

strings = ["HTML", "CSS", "JavaScript", "Python", "Ruby"]

Add your code below!

symbols = Array.new strings.to_sym.each do |i| if i !=1 symbols.push(i) end end

puts symbols

This pops up "It looks like you didn't add each symbolized string to the symbols array."

The goal is to iterate over the string and convert them to symbols and add them to a seperate array.

1 Answer

Tim Knight
Tim Knight
28,888 Points

Hi Alphonse,

What about something like this:

strings = ["HTML", "CSS", "JavaScript", "Python", "Ruby"]

# Creates a new empty array
symbols = []

strings.each do |string|
  symbols.push(string.to_sym)
end

This converts each item in the string array to a symbol and then adds it to a symbols array. I'm not sure what your intention was with if != 1 but this at least addresses the array of symbols.

You can test it with:

symbols.each do |sym|
  puts sym.class
end

# => Symbol
# => Symbol
# => Symbol
# => Symbol
# => Symbol
# => => [:HTML, :CSS, :JavaScript, :Python, :Ruby]