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


#1



https://www.codecademy.com/courses/ruby-beginner-en-693PD/0/7?curriculum_id=5059f8619189a5000201fbcb


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 = Hash.new(0)
words.each {|word| frequencies[word] += 1 }
frequencies = frequencies.sort_by {|word, count| count}
frequencies.reverse!
frequencies.each do |word, count|
    puts word + " " + count.to_s
end


#2

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

Enter your text here: 
 
[]

#3

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?


#4

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.


#5

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: "

#6

I see now. thank you.


#7

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