there are any thing wrong? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

22nd Apr 2022, 11:51 PM
conta rascunho
conta rascunho - avatar
2 Answers
+ 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
23rd Apr 2022, 12:22 AM
John Wells
John Wells - avatar
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.
22nd May 2022, 5:57 PM
conta rascunho
conta rascunho - avatar