Exercice 9/15

Bonjour, la fin de l’exercice n’est pas si simple : Utilisez .each pour itérer sur le tableau strings. 3 Pour chaque s dans string, utilisez to_sym pour convertir s en symbole et utilisez push pour ajouter ce symbole au tableau symboles.
je ne saisi pas bien comment convertir chaque “s” de string en symbole? Help please
Début de code

strings = [“HTML”, “CSS”, “JavaScript”, “Python”, “Ruby”]

Ajoutez votre code ci-dessous

symboles =
strings.each do |string|

??

symboles.push(string)

end
end
print symboles

Merci d’avance

Hello, I can’t find any solution for this exercise can you help? Ruby => Hashes and Symbols 9/15
strings = [“HTML”, “CSS”, “JavaScript”, “Python”, “Ruby”]

symboles =
strings.each do |string|

"string".to_sym
symboles.push(string)

end
end
print symboles

I don’t understand how I can only show the “s” of string

strings = [“HTML”, “CSS”, “JavaScript”, “Python”, “Ruby”]
symbols=
strings.each do |z|
z = z.to_sym
symbols.push(z)
end

6 Likes

Thank you so much!! Very nice

@devmaster41371
Why do you have to have
z = z.to_sym

as opposed to

“z”.to-sym

In the instructions it doesn’t say anything about having that syntax… or am I missing something?

Thanks!

You misunderstand the question. Your not looking for the s in the strings. s is simply the iterator. I use the word letter as the iterator in my code:

strings = [“HTML”, “CSS”, “JavaScript”, “Python”, “Ruby”]

symbols =

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

3 Likes

ca ne marche pas avec moi, je suis bloque aidez moi

j’ai toujours la meme reponse
Oups, merci de réessayer. Vous n’avez pas ajouté tous les symboles dans le tableau.

@tracifong Hi there, the reason why he uses:

z = z.to_sym

as opposed to

"z".to_sym

is because z is the placeholder that is iterating over every element in the array and “z” is not.

This is correct. I misunderstood the question until I read this reply. The question isn’t asking you to find every “s” in the strings array, it is telling you to use s as the placeholder

It’s much easier that I thought:

strings = [“HTML”, “CSS”, “JavaScript”, “Python”, “Ruby”]

symbols =
strings.each {|s| symbols.push (s.to_sym)}