0
\$\begingroup\$

I'm writing very simple programs. "Crawl before you walk..." they say.

How could I clean this up? And/or simplify?

While I am very new, technical lanquage is necessary because it helps me learn the lessons I need to learn

puts "What is my favorite ice cream flavor?"
ice_cream_1 = gets.chomp.capitalize
while ice_cream_1 != "Vanilla"
 puts "Wrong answer; what is my favorite ice cream flavor?"
 my_favorite_ice_cream_flavor = gets.chomp.capitalize
 if my_favorite_ice_cream_flavor == "Vanilla"
 break
 end
end
puts "Now that's my jam"
asked Sep 2, 2017 at 1:51
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

There is no need to write the gets and the string comparison code twice. The following code is equivalent:

puts "What is my favorite ice cream flavor?"
while gets.chomp.capitalize != "Vanilla"
 puts "Wrong answer; what is my favorite ice cream flavor?"
end
puts "Now that's my jam"
answered Sep 2, 2017 at 3:32
\$\endgroup\$
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.