Iterating over the hash: I have read all the Q&A for this topic and still cannot get my code to work. As soon as I solve one error, I have created another


Oops, try again.
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!

puts "Enter your text here: "
text = gets.chomp
words = text.split(" ")
frequencies =
words.each {|word| frequencies[word] += 1 }
frequencies = frequencies.sort_by {|word, count| count}
frequencies.each do |word, count|
    puts word + " " + count.to_s


This error occurs if you do not enter any text at the prompt. Just hitting Enter will cause this,

Enter your text here: 


To make sure I understand . . . I hit "save and submit code", then when the [ ] appears on the console screen, I enter a message inside the brackets. Am I correct?


You are correct. When the [ ] cursor appeared on the screen, i typed some text. Got the green go ahead. Where is the instruction to do this? I missed it completely.


The text should be typed at the prompt, then hit enter. The above example shows what happens when no text is entered.

puts "Enter your text here: "


I see now. thank you.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.