Getting stuck on chapter 8:
Type as many words as we want
One word per line, continuing until we just press Enter on an empty line
Repeats the words back to us in alphabetical order.
Use ‘sort’
So, here’s what I got to, but I’m having funny issues with not getting the first word to push into the array [among other things]
# alphabetting
puts 'Tell us some of your favorite things!'
# create an array
words = []
while gets.chomp != ''
words.push gets.chomp
words.sort
puts words
end
Did this and it works now… Do I have to have “thing” in there though? Seems naughty to assign within a ‘while’ loop.
puts 'Tell us some of your favorite things!'
words = []
puts words
while (thing = gets.chomp) != ''
words.push thing
end
puts words.sort
Your first
getscall is not referred to by anything, and is thrown out. It is not just the first word, but every other word that is going to be thrown out. The output routine should also be outside of the loop. A fix is: