Last active
February 19, 2020 19:10
-
-
Save marcoranieri/12ea49c9835598c5e06a475ef09d66de to your computer and use it in GitHub Desktop.
Flow & Array
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
def acronomize(sentence) | |
return "" if sentence == "" | |
#retrieve each word from sentence (from string to array) | |
sentence_array = sentence.split(" ") | |
#take just first letter from each word and capitalize | |
acronym = [] | |
sentence_array.each do |word| | |
#store in new array | |
acronym.push(word[0].upcase) | |
end | |
#join array and return (as string!) | |
return acronym.join | |
end | |
puts acronomize("be right back") | |
puts acronomize("laugh out loud") | |
puts acronomize("be right back") == "BRB" | |
puts acronomize("laugh out loud") == "LOL" | |
puts acronomize("") == "" |
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
# Define our OPTIONS | |
OPTIONS = ["rock", "paper", "scissors"] # OPTIONS is a Constant | |
# Computer input | |
computer = OPTIONS.sample | |
# User input | |
puts "Choose an option: #{OPTIONS.join(" - ")}" | |
choice = gets.chomp | |
# Compare the choices + display the outcome | |
if choice == computer | |
puts "Draw" | |
elsif (choice == "rock") && (computer == "scissors") || | |
(choice == "paper") && (computer == "rock") || | |
(choice == "scissors") && (computer == "paper") | |
puts "You win!" | |
else | |
puts "You lose!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment