Created
April 11, 2018 17:54
-
-
Save barangerbenjamin/f38a0f0037fda4463586d4c89cafae89 to your computer and use it in GitHub Desktop.
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
# write test | |
# code method that takes sentence as parameter | |
# sentence needs to be broken down into words | |
# then into first letters of each word | |
# needs to return a string which is the acronym | |
def acronym(sentence) | |
string = "" | |
sentence.split(" ").each do |word| | |
string += word[0].upcase | |
end | |
return string | |
end | |
puts acronym("this is a sentence") | |
puts acronym("Frequently Asked Questions") == "FAQ" | |
puts acronym("Hello world") == "HW" | |
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
# Pick randomly a hand for the computer | |
# Ask the (human) player to pick a hand | |
# Check if the player hand is valid. If not, ask again until it is. | |
# Compare both hands! Outcome is Win / Lose / Draw | |
# Puts outcome and exit | |
computer_choice = ["rock", "paper", "scissors"].sample | |
player_choice = "" | |
until ["rock", "paper", "scissors"].include?(player_choice) | |
puts "Choose rock/paper/scissors?" | |
player_choice = gets.chomp | |
end | |
if player_choice == computer_choice | |
puts "DRAW BRAH" | |
elsif player_choice == "scissors" && computer_choice == "paper" | |
puts "Yay you win" | |
elsif player_choice == "rock" && computer_choice == "scissors" | |
puts "You Rock " | |
elsif player_choice == "paper" && computer_choice == "rock" | |
puts "You Win" | |
else | |
puts "You Lost" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment