+ 2
there are any thing wrong?
hash = {"x"=> 1, y: 2, "z" => '3'} e1 = gets.chomp() hash.each do |k, v| if e1 == k puts "found key#{k}" elsif e1 == v puts "found: value #{v}" end end
5 Réponses
+ 5
# Not sure what y: in first line means.
hash = {"x"=> 1, "y"=> 2, "z" => '3'} # changed y: to "y"=>
e1 = gets.chomp()
hash.each do |k, v|
if e1 == k
puts "found key#{k}"
# match integer values
elsif e1 == v || e1.to_i == v # added || ei.to_i == v
puts "found: value #{v}"
end
end
0
Ash[Melted 💜] , thanks for you feedback, but i was fix the code, i don't remember what was happening. I guess that, the code isn't getting the hash value and print it.