-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sockets - Sarah #43
base: master
Are you sure you want to change the base?
Sockets - Sarah #43
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
def is_vowel?(letter) | ||
vowels = ["a", "e", "i", "o", "u"] | ||
if vowels.include?(letter.downcase) | ||
return true | ||
end | ||
return false | ||
end | ||
|
||
|
||
def get_word_from_user(word) | ||
puts "What is the #{word} to combine?" | ||
word = gets.chomp.to_s | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also advise against reusing this variable again for a different purpose! Part of your job is to convey the semantic meaning of your code with variable names, so using |
||
while word.length < 2 || word.include?(" ") | ||
puts "Word must be at least 2 characters long, and must not contain any spaces." | ||
word = gets.chomp.to_s | ||
end | ||
return word | ||
end | ||
|
||
|
||
def chop_first_word(first_word) | ||
stop_index = first_word.length - 1 | ||
|
||
first_word.reverse.each_char do |letter| | ||
if is_vowel?(letter) | ||
return first_word[0...stop_index] | ||
end | ||
stop_index -= 1 | ||
end | ||
stop_index = first_word.length | ||
return first_word[0...stop_index] | ||
end | ||
|
||
|
||
def chop_second_word(second_word) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I bet you could find a clever way to combine |
||
start_index = 0 | ||
|
||
second_word.each_char do |letter| | ||
if is_vowel?(letter) | ||
return second_word[start_index..second_word.length] | ||
end | ||
start_index += 1 | ||
end | ||
start_index = 0 | ||
return second_word[start_index..second_word.length] | ||
end | ||
|
||
|
||
def run_generator | ||
first_word = get_word_from_user("first word") | ||
second_word = get_word_from_user("second word") | ||
|
||
first_half = chop_first_word(first_word) | ||
second_half = chop_second_word(second_word) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This this beautiful! Great use of methods! |
||
|
||
new_word = first_half + second_half | ||
|
||
puts "#{first_word} + #{second_word} is #{new_word}" | ||
end | ||
|
||
|
||
run_generator | ||
play_again = true | ||
|
||
while play_again | ||
puts "Wasn't that fun? if you would like to try again, please enter 'yes'." | ||
responce = gets.chomp.to_s | ||
if responce == "yes" | ||
run_generator | ||
else | ||
play_again = false | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
word
as a variable on its own is weird here. My own (admittedly fiddly) opinion is that it's not descriptive enough. Maybeword_num
, orcardinal
?