Converting Between Symbols and Strings


"Looks like each symbolized string is not in the symbols array" is my error message

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

# Add your code below!

symbols = []
strings.each do |word|
  $i = 0
  lowercase = word.downcase
  letters = lowercase.split("")
  while $i <= letters.length  do
    if letters[$i] == "s"
      symbolized = letters[$i].to_sym
      symbols.push symbolized
    $i +=1

print symbols

I'm getting an array with [:s, :s, :s] which is what the question is asking for


Uh.. Are the strings to convert the ones on line 1?
Because [:s, :s, :s] doesn't really resemble those strings does it?

And if the only thing that's supposed to be iterated through is a list of strings, then what is the other loop in your code doing?

Why is there special mention of the string "s" in the code? Why is that significant?


Here are the directions:

We have an array of strings we'd like to later use as hash keys, but we'd rather they be symbols.

Create a new variable, symbols, and store an empty array in it.
Use .each to iterate over the strings array.
For each s in strings, use .to_sym to convert s to a symbol and use .push to add that new symbol to symbols

My understanding is that we're supposed to push each "s" as a symbol to the symbols array am I miss interpreting this?


There is no "s" in strings, none of the elements are equal to that value. Some elements do themselves contain that character, but that's not what they're saying. They're using s to refer to each element of strings

"For each s in strings" is analogous to:

strings.each do |s|


ok, wow I was making this way more complicated I got it now thanks for your help


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.