Create an Histogram


#1

could someone please explain section 8 in create an Histogram


#2

Would you be willing to share your lesson 7 code with us, so we have something to work with? Please and thank you.


#3

Thanks

puts " your text please"
text = gets.chomp
words = text.split
frequencies = Hash.new(0)
words.each do
   { |word|
frequencies[word] += 1}
end
puts frequencies[word]

Here it is...


#4

Can we start with this line? Is it correct?


#5

Yes it is ....................


#7

I don't really what it all stand for .. I'm very sorry but could you like break the whole code down....


#8

Short answer: No. That is not in my purview.


#9

Thanks ... I think I get it ...


#10

I copied exactly what you wrote and it's giving me a syntax error.


#11

I'm also getting a syntax error


#12

word is not defined in that scope, only in the block. To list the frequencies hash we need another loop: See lesson 1 for this example:

frequencies.each do |word, frequency|
    puts word + " " + frequency.to_s
end

The OP is missing some important code so hopefully nobody is trying to use it. Refer to lesson 1, and follow instructions closely.