Can someone explain to me why I have to create a Hash and why this code doesn't work


#1

Can someone explain to me why I have to create a Hash and why this code doesn't work
thank you in advance :slight_smile:

puts "type my high enlightened King of Stutensee"
text = gets.chomp
words =text.split()

frequencies =Hash.new(0)
words.each { frequencies[word] += 1 }

`


#2

What makes you say that you need to create a hash?
When you say that it doesn't work, what do you mean that it is doing differently from what you want?


#3

I have to create a hash because that is the assignment here and it is just not working...


#4

Seems you need to think a bit more about what you mean by "not working", otherwise there isn't anything to change

A good start is to consider what it's supposed to be doing according to the instructions, and then testing the code to find out whether it's doing those things. The first thing that it isn't doing would then be what needs to be different


Presumably a hash supports some operations that are useful to carrying out the described tasks? There are probably many other ways of going about accomplishing the same thing.


#5

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