Help with Ruby;Hashes and Symbols:Nil: A formal introduction


#1

here is my code
creatures["Zoidberg"] = { "weasels" => 0,
"puppies" => 6,
"platypuses" => 3,
"canaries" => 1,
"Heffalumps" => 7,
"Tiggers" => 1
}

This is the error message i am recieving
Oops, try again. Did you try to access a key in the creatures hash that doesn't exist?

link


#2

You cannot access a key while also creating a hash that must be dine after your hash is already created for example if I wanted to access a key that wasn't there it would return nil,

// example hash
example = { "weasels" => 0,
  "puppies" => 6,
  "platypuses" => 3,
  "canaries" => 1,
  "Heffalumps" => 7,
  "Tiggers" => 1
}
// This key accessing would return nil
example["car"]

#3

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