Iterating over the array exercise 5


#1

I can't figure this out! I tired the forum to find some answers first however still not sure what I am doing wrong.

here is the code:
puts "some text here is needed"
text = gets.chomp
words = text.split(" ")
frequencies = Hash.new(0)
words.each { |word| frequencies[word] += 1 }

puts frequencies[word]

The error says:
Oops, try again. Your code doesn't look quite right. Check the Hint if you need help!

and also:
undefined local variable or method `word' for #


#2

Hello!

Please, what exercise are we looking at here? A link preferably.

By the way, word isn't defined but words is. Maybe, depending on the exercise, you should make all word to be words.


#3

sorry yes of course here is the link:

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


#4

So, the error is in this.

You wrote code to help split a text into words and then find how frequently it occurs. So, you should be finding the frequency of words and not word on the last line I pointed at, above.


#5

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