Iterating over hash error


#1

I've been looking through problems other people have been having with this particular lesson, and nothing has really helped. I've double-checked my code, and I can't find anything wrong with it, but I keep getting the same error message: undefined local variable or method `word' for #
What am I doing wrong?

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

puts "Enter text"
text = gets.chomp
words = text.split
frequencies = Hash.new[0]
    word.each do |word|
    frequecies[word] += 1 
    puts frequencies[word]
end

#2

I haven't looked too deep into the code, but what I've noticed is, that the quoted code should have round brackets instead of rectangular one.


#3

I've tried that and got a similar message


#4

use frequencies as a variable.

Then iterate through words.


#6

I can't post my solution here. But my solution doesn't have this:


#7

Ok I'll try changing it thx :slight_smile:


#8

So far, nothing I've tried has worked (even switching browsers, as I've seen has been a fix for some users with the same code). I fixed the piece of code that lett mentioned, but I'm still stuck.


#9

Iterate over the container object (array)

words.each

#11

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