5/8 Not adding


#1

puts "Please enter some text:"
text = gets.chomp
words = text.split

frequencies = Hash.new(0)

words.each do
|words| frequencies[words] += 1
puts frequencies
end

It passes the module, but the console prints:

Please enter some text:
It's not adding anything
{"It's"=>1}
{"It's"=>1, "not"=>1}
{"It's"=>1, "not"=>1, "adding"=>1}
{"It's"=>1, "not"=>1, "adding"=>1, "anything"=>1}
["It's", "not", "adding", "anything"]

Why is my code not giving hash entries additive numbers?


#2

@redhare,
Have a read through the explanation
https://discuss.codecademy.com/t/5-iterating-over-the-array/34206/2?u=leonhard.wettengmx.n


#3

Thank you for the reply, but unfortunately even a direct copy of that code doesn't result in the correct outcome. I still only get a value of 1 for each word.


#4

@redhare,
And what if you use
the text....

text="this is is a long long long text this is"

#5

Ahh, I see. I greatly misunderstood this. I assumed it wanted
The = 1
Numbers = 2
To = 3
Add = 4

Thanks Leonhard.


#6

actually your code already works, I don't know why it wasn't was working for you