D
danielj
puts 'Type in as many words as you want'
puts 'When you are finished, press \'ENTER\' on an empty line'
puts 'I\'ll give \'em all back to you in alphabetical order!'
stuff = []
user_input = gets.chomp
while user_input != ''
stuff.push(user_input)
user_input = gets.chomp
end
puts stuff.sort.join(', ')
Here is my code for the "array program" from chapter 7 and the
challenge is to now adapt the program to have the same output without
using the "sort" method.
I have no idea where to even start. I think we are supposed to iterate
over the array somehow but have no clue. Anybody got a hint for me?
Secondly, I have a question about this code for my Deaf Grandmother
program:
gcount = 0
puts "Hello child! How are yeah?"
while gcount < 3
r = gets.chomp
if r == r.downcase or r == r.capitalize
puts 'WHAT? YOU\'RE GONNA HAVE TO SPEAK UP!'
end
if (r == r.upcase and r != 'BYE')
puts 'NOT SINCE 19' + (rand(21)+30).to_s + '!'
end
if r == 'BYE'
puts 'NOT SINCE 19' + (rand(21)+30).to_s + '!'
gcount = gcount + 1
end
if r != 'BYE'
gcount = 0
end
end
The only problem with my program is when a user inputs something of
mixed case the program doesn't respond with "WHAT? YOU'RE GONNA HAVE
TO SPEAK UP!" like it should...
Any ideas?
Thanks a lot!
puts 'When you are finished, press \'ENTER\' on an empty line'
puts 'I\'ll give \'em all back to you in alphabetical order!'
stuff = []
user_input = gets.chomp
while user_input != ''
stuff.push(user_input)
user_input = gets.chomp
end
puts stuff.sort.join(', ')
Here is my code for the "array program" from chapter 7 and the
challenge is to now adapt the program to have the same output without
using the "sort" method.
I have no idea where to even start. I think we are supposed to iterate
over the array somehow but have no clue. Anybody got a hint for me?
Secondly, I have a question about this code for my Deaf Grandmother
program:
gcount = 0
puts "Hello child! How are yeah?"
while gcount < 3
r = gets.chomp
if r == r.downcase or r == r.capitalize
puts 'WHAT? YOU\'RE GONNA HAVE TO SPEAK UP!'
end
if (r == r.upcase and r != 'BYE')
puts 'NOT SINCE 19' + (rand(21)+30).to_s + '!'
end
if r == 'BYE'
puts 'NOT SINCE 19' + (rand(21)+30).to_s + '!'
gcount = gcount + 1
end
if r != 'BYE'
gcount = 0
end
end
The only problem with my program is when a user inputs something of
mixed case the program doesn't respond with "WHAT? YOU'RE GONNA HAVE
TO SPEAK UP!" like it should...
Any ideas?
Thanks a lot!