Is the has_key? challenge asking for an "if" statement?
So far this course has been straight forward and very simple, but I'm confused at what this particular statements is asking of me.
Using the has_key? method, check if the hash variable has a key called "calories". If it does, set a new variable called "food" to true.
Is it asking for an "if" statement? How would I solve this one?
Maciej Czuchnowski36,437 Points
You are on the right track, but this is enough:
food = true if hash.has_key?("calories")
if hash.has_key?("calories") food = true end
Remember that no matter what the exercise says, names of the variables are always without quotes. They also didn't ask you for any method definitions, so def will not pass this exercise.
Ian Crawford22,312 Points
You are correct in assuming it is asking for an if statement.
Inside the if statement it wants you to make food equal true if the statement is true.