Iterating over Array code errors


I cannot get past this part and everything seems alright, any insights anyone? :confused:

The following is the printed error message along with the code:

(ruby):6: syntax error, unexpected '|', expecting '}'
words.each = {|word| frequencies[word] += 1}
(ruby):6: syntax error, unexpected '}', expecting $end

puts "type in something:"
text = gets.chomp

words = text.split ("")

frequencies =
words.each = {|word| frequencies[word] += 1}


get rid of the equals sign, the correct syntax is

words.each { |word| frequencies[word] += 1 }

Also, this isn't throwing an error, but i suggest just using
words = text.split()
instead of
words = text.split("")
because the latter puts each letter in it's own array


I realized the extra '=' after posting it :stuck_out_tongue: but thanks for pointing it out!
and thanks for the advice on the .split; I'll change the ("") to () :slight_smile:


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