Help with hashes in Ruby


Why this didn't work? It says that nothing is displayed on the console, 
but it actually shows what I need. any help? thanks!!

mascotas = { "Bubbles" => "cat",
  "Happy" => "hamster",
  "Kevin" => "dog"

puts mascotas["Kevin"]


Can I have the link or name of the lesson?



I can't help, the link is to the Spanish lesson and it's not the same as the number 9 in the English lessons. I'm sorry! :slight_frown:


the lesson says something like that:

Access values ​​in a hash

As with the arrays, you can access the values ​​in a hash by scrolling (that is, using indexes). Each index in a hash is a key that you assign; Simply by entering the name of the key in the middle of brackets, we can access the value associated with that key.

so, when I try to submit code and look if I'm right, the console shows what I want, but the page says that "the console doesn't show the value associated in my hash" but actually does!
You know what I mean? thanks anyway :smiley:


Usa la notación de corchetes para acceder al par clave-valor que agregaste en mascotas, y usa puts para mostrar ese valor en la consola. Si necesitas ayuda revisa la Sugerencia.

Use bracket notation to access the key-value pair you added on pets, and use puts to display that value on the console. If you need help check the Tip.

I believe we are to use bracket notation to make the assignment, as well.

mascotas["Andy"] = "perro"
puts mascotas["Andy"]


thanks so much!!! it works!! :smile: :smile: :smile:


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