Created
January 8, 2016 21:05
-
-
Save Ebonkuab/96ad3a4cf6b7231b290d to your computer and use it in GitHub Desktop.
ruby code for interaction with shakil the dog (LIGHTHOUSE DEV BOOTCAMP)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Save this file to your computer so you can run it | |
# via the command line (Terminal) like so: | |
# $ ruby shakil_the_dog.rb | |
# | |
# Your method should wait for user input, which corresponds | |
# to you saying something to your dog (named Shakil). | |
# You'll probably want to write other methods, but this | |
# encapsulates the core dog logic | |
def shakil_the_dog | |
shakilWordsArray = Array.new | |
puts " shakil the dog is barking, what does he want" | |
puts " let me tell him some few words" | |
wordsSpokenToShakil = gets.chomp.downcase | |
shakilWordsArray = wordsSpokenToShakil.split.push | |
# different responses from Shakil based on the words written by the user | |
if shakilWordsArray.include?('woof') == true | |
puts "SHAKIL: WOOF WOOF WOOF" | |
elsif shakilWordsArray.include?('shakil stop') || shakilWordsArray.include?('shakil stop!') | |
puts " " | |
elsif shakilWordsArray.include?('meow') == true | |
puts "SHAKIL: woof woof woof woof woof" | |
elsif shakilWordsArray.include?('* treat *') == true | |
puts "Shakil keeps quiet" | |
elsif shakilWordsArray.include?('go away') == true | |
exit | |
else | |
puts "SHAKIL: woof" | |
end | |
end | |
### Continous while loop to constantly come up for the user to give input | |
userResponse = "yes" | |
while (userResponse == "yes") do | |
puts " is Shakil the dog Barking? yes or no" | |
userResponse =gets.chomp.downcase | |
if userResponse=="no" | |
break | |
elsif userResponse=="yes" | |
userResponse = "yes" | |
shakil_the_dog | |
else | |
break | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment