mardi 2 février 2016

Every other result .upcase, and sorted alphabetically

I am writing a program that needs to do several things. First, it prompts the user to enter an names into an array. I then need to both sort the array items alphabetically and present every other item as .upcase.

I believe I have the first part figured out, but I can't figure out the formatting for the output. My guess and what I've shown below if using a conditional elsif.

I CANNOT USE WITH_INDEX , and the attached code is my attempt.

Any advice would be helpful. Thank you for your time!

names = []

5.times do
    puts "Please your amigo's names:"
    names << gets.chomp
end

sorted_names = names.sort

sorted_names.each do |name|
    if sorted_names.even
        puts "There once was a person named " + name.upcase + "."
    else
        puts "There once was a person named " + name.downcase + "."
end
end

Aucun commentaire:

Enregistrer un commentaire