9. Converting Between Symbols and Strings



So when I write code it gives me this result: ["HTML", "CSS", "JavaScript", "Python", "Ruby"]
And this error message: "Oops, try again. It looks like you didn't add each symbolized string to the symbols array."
I'm really stuck, tried a lot of possible options, but none works. Please help =)

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

# Add your code below!

symbols = Array.new
strings.each do |i|
    if i == "s"
       puts "something went wrong"


 if i == "s"

you have to convert all the string values to symbols. so you don't need any condition.


Okay, so I've written only this:


and it works, but the result is still the same. shouldn't it return only CSS and Javaschirpt?


Why would it only return those two?
You've told it to convert all strings in the array into symbols and pushed them into another 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.

here s is just a placeholder name. you used i instead of s .

so each i in strings, use .to_sym to convert i to a symbol.

I don't think so.because that time your if condition was false so it didn't convert any strings to symbol. i can't be 's'. first of all consider what is i .

i hope you've understand now :slight_smile:


Hi there, may someone help me please .. I wrote something that seems right but I don't get why I have that asnwer:

strings = ["HTML", "CSS", "JavaScript", "Python", "Ruby"]
symboles = []
strings.each do |string|

And the answer is: ["HTML", "CSS", "JavaScript", "Python", "Ruby"]

It's false right ? I'm supposed to convert those strings into symbols .. aaarg :grimacing:
Thanks guys !


symbols NOT symboles :slight_smile:


Yes, now I understand. No I just thought, that in variable symbols should only go words that contain letter "s". Now I get it, thanks a lot.


This is actually irrelevant, as it's a variable name. He just happened to write it in French (which I tried, and it worked, despite instructions).

Anyway, the code is correct – but the console doesn't output symbols. Not sure why.


if you put, print symbols at the end, you'll see the strings did turn into symbol, hope that helps


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