Ruby Ruby Collections Ruby Hashes Working with Hash Keys

Simon Goldman
Simon Goldman
1,028 Points


cant figure out how to add a new variable to this??

hash = { "name" => "Bread", "quantity" => 1, "calories" => 100 }
hash.has_key?("calories")"food" => "true")

1 Answer

Amir Eskandari
Amir Eskandari
9,153 Points

Hi Simon,

You are very close but your last line is much more complicated than necessary. You just need to assign the boolean value true to a new variable called "food", like so:

food = true

Also, wrap your two lines of code in an 'if' statement. Let me know if you need any more help!