7/8. Iterating over the hash


#1

Here's my code.

puts "Text:"
text = gets.chomp

words = text.split(" ")

frequencies = Hash.new(0)
words.each { |element| frequencies[element] += 1 }

frequencies = frequencies.sort_by {|a, b| b}
frequencies.reverse!

frequencies.each do |word, frequency|
puts word + " " + frequency.to_s
end

I keep getting the error: It looks like you aren't printing each key-value pair to the console correctly. Make sure to put a space between each key and value!


#2

Hi try to refresh the page.


#3

Still came up with the same error message.


#4

Hi ran you code and it's woks .
When you save & submit the code you should write something in the console and then click on Enter


#5

Thank you so much it worked!