Skip to content

Commit 88fc83c

Browse files
committed
Ruby Blanks solution. ⛰
1 parent 798a0ac commit 88fc83c

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

challenges/ruby-blanks-solution.rb

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
11
#!usr/bin/env ruby
22

3-
game_title = 'Ruby Blanks Game'
3+
# Title of the game
4+
puts '-' * 19
5+
puts '| Ruby Blanks Game|'
6+
puts '-' * 19
47

5-
# Wraps the game title with dashes.
6-
game_title = "| #{game_title} |"
7-
game_title.length.times do
8-
print '-'
9-
end
10-
11-
puts "\n#{game_title}"
8+
# Sets a value to look for blanks in sentences.
9+
blanks = ['noun', 'noun', 'adjective', 'verb']
1210

13-
game_title.length.times do
14-
print '-'
11+
# Prompts user to fill in the blanks, one by one.
12+
answers = blanks.map do |blank|
13+
indefinite_article = blank.start_with?('a') ? 'an' : 'a'
14+
print "Give me #{indefinite_article} #{blank}: "
15+
response = gets.chomp
1516
end
16-
puts
1717

18-
# I went to ____ and found a ____, it looked like _____ so I _____.
19-
# Next thing you know, the _____ was _____ like everyone else. It was ______ and ______.
18+
# Fills the blanks in the sentence with captured answers.
19+
text = "I went to visit a #{answers[0]} and found a #{answers[1]}, it looked #{answers[2]} so I started to #{answers[3]}."
2020

21-
blanks = ['noun', 'noun', 'adjective', 'verb']
22-
responses = []
23-
# blanks = ['noun', 'verb', 'adjective', 'adjective']
24-
25-
for blank in blanks
26-
indefinite_article = blank.start_with?('a') ? 'an' : 'a'
27-
print "Give me a #{blank}: "
28-
responses << gets.chomp
29-
end
21+
# Shows complete sentence to the user.
22+
puts text

0 commit comments

Comments
 (0)