Ruby Iterating Over the Hash 7/8


#1

I have been working on exercise 7/8 in Ruby for an hour and I am not sure what I am doing wrong. My code is below

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

Thank you in advance
Josh


#2

each needs a block, either do..end or {..} Add a do just before the block parameters.


#3

I did that and it is still not working. My code is below.

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


#4

Let's have a look at your completed code, please. It could be something else. I don't see any issue with the code above.


#5

here you go

puts "Type something here"
text = gets.chomp
word = text.split
frequencies = Hash.new (0)
words.each do |word| frequencies[word] +=1
puts frequencies 
frequencies = frequencies.sort_by do |word, count|
frequencies.reverse!
frequencies.each do |word, frequency| 
puts word + " " + frequency.to_s
end

#6

I would comment out that line.

The above line is incomplete/incorrect.


#8