Data Structures:Accessing Hash Values


#1

This is lesson 9 for Data Structures in Ruby it keeps telling it looks like you didn't print anything in the console. Ive looked the other Hash value threads and cannot figure out what I'm doing wrong. Please help!

pets = Hash.new
"Charlie" => "cat",
"Poptart" => "first",
"Cloe" => "oldest"

puts pets["Charlie"]


#2

HI you have two ways for create a Hash

1

hash = {
  "stevie" => "cat",
}

2

pets = Hash.new
pets["Stevie"] = "cat"

HOpe tha could help you...


#3

yes it did I used curly brackets and did puts["name here"] for all three makes and it went.
Thank you!

if I use the curly bracket do I always have to use => and then if I use Hash.new do I always have to use ["name here"] if use them both am I mixing code?


#4

Yes

yes, and it won't work.


#5

Thank you!

Makes sense now :slight_smile: