Lesson 6 Error: It looks like you haven't set the frequencies hash correctly


#1

Hi,
i don't understand why i get this error: It looks like you haven't set the frequencies hash correctly.

here is my code:

uts "words"
text= gets.chomp
words = text.split(" ")
frequencies = Hash.new(0)
words.each {|element| frequencies[element]+=1}

frecuencies = frequencies.sort_by do |elem, count|
count
end
frecuencies.reverse!


#2

frequencies = frequencies.sort_by {|elem,count| count}
frequencies.reverse!

You're not yet asking your snippet to do anything just yet so you don't need 'do'. It's a little confusing when you're going off of the example. Since there is no 'do' you also don't need an end. All you're asking for your code to do is sort it on this line, (by your preferred sorting method involving the elements 'frequencies' currently has.) This way you're telling it to sort by the 'count' placeholder.


#3

You spelled frequencies wrong. You have it correct when you initially set the has, and then the following 2 times you spelled it with a "c" instead of a "q"


#4

Hello,

I spelled correctly checked multiple times. still keeps giving me the same error message. At this point I started feel like they are expecting me to figure out what answer they are thinking.

============ Here is my code =====================

puts "Text please:"
text = gets.chomp
words = text.split (" ")

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

frequencies = frequencies.sort_by { |a, b| b }
frequencies.reverse!
frequencies.each do |a, b|
puts a + " " + b.to_s
end

========== the end =====================


#5

Hi ,

I spelled correctly checked multiple times. still keeps giving me the same error message. At this point I started feel like they are expecting me to figure out what answer they are thinking.

============ Here is my code =====================

puts "Text please:"
text = gets.chomp
words = text.split (" ")

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

frequencies = frequencies.sort_by { |a, b| b }
frequencies.reverse!
frequencies.each do |a, b|
puts a + " " + b.to_s
end

========== the end =====================

Apologize for posting the same answer twice, I got stuck on this questions for the whole morning. trying to get a little bit more attention. ( :frowning: )