5. Iterating over the Array issues


#1

Hi guys. I followed the instructions exactly as stated in the example, and it still isn't working. What am I doing wrong?
Here is my code:
puts "Text"
text=gets.chomp
words=text.split(" ")
frequencies=Hash.new(0)
frequencies={
"Text" => 21
}
words.each do |word| frequencies[word] +=1
end
puts frequencies[word]
Please help! Thanks (PS when I ran the code it kept telling me I had no key-value pairs, so I added one in and it still isn't working.)


#2

Take a closer look at your array name. You got it correct but you used "word" instead of "words"


#3

Did just that...it still says I haven't the frequencies hash correctly. Aaaaaahhhhhhh!!!!!!


#4

@microslayer00982 this worked for me:

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


#5

Tried...Still the same thing...


#6

I don't know where you got:

frequencies={
"Text" => 21
}

Try removing this and run the code I posted.
Also, it doesn't matter what you use inside | | it's just a placeholder.


#7

You should try this one instead, this worked for me

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

Happy Coding