Ruby Ruby Collections Ruby Hashes Working with Hash Values

Eliot Alderson
Eliot Alderson
2,152 Points

has_value? - Challenge not working

So i have asked whether it has a key of "bread" and then i am proceeding to updating the hash with a new key & value.

Hash = {"food" => "true"}

but it still fails, i tried to add the new key pair separately and then add it to the original but neither worked.

grocery_item = { "item" => "Bread", "quantity" => 1, "brand" => "Treehouse Bread Company", "food" => "true"}


1 Answer

Steven Parker
Steven Parker
203,700 Points

The test for the value needs to be part of an "if" statement that will control whether the other key is added or not.

The original contents of the hash should remain as they were originally if the test does not pass, so don't modify the line of code originally provided.