In Ruby I'm looking to create a short program where a user is able to enter a certain number of words (5 for now) and the program needs to spit the words back out to the user in alphabetical order, and each word must alternate from ALL CAPS to all lowercase letters.
This program can only use methods like (.each do, .sort, .upcase, .downcase), arrays, loops, and if/else statements. NOTHING ELSE ... so no indexes, dictionaries, modules, arguments, etc. The syntax shouldn't diverge too much from what I've already written.
This is the code I have so far ... I keep getting a no method error ... any help would be greatly appreciated.
words = []
5.times do
puts "Please enter a word"
words << gets.chomp
end
words.sort.each do |odd, even|
if odd puts words.upcase
elsif even puts words.downcase
end
end
words.sortwill give you and array of sorted words.eachthen passes each element of the sorted array to the block, assigning them to the first block variable,odd. Since a single string is passed each time, the block variableevenwill always equalnil. That's why the block is not performing as you would like. You might find it helpful to add the following at the beginning of the block:puts "odd=#{odd}, even=#{even}".