Skip to content

Instantly share code, notes, and snippets.

@switzersc
Created March 31, 2014 16:11
Show Gist options
  • Save switzersc/9895894 to your computer and use it in GitHub Desktop.
Save switzersc/9895894 to your computer and use it in GitHub Desktop.
blackjack game
game_decision = "yes"
while game_decision == "yes"
base_card = rand(10)
puts "Your number is #{base_card}."
puts "Continue? Yes or No"
answer = gets.chomp
my_cards = [base_card]
while answer.downcase == "yes"
next_card = rand(10)
my_cards << next_card
puts "Next card is #{next_card}"
sum = 0
my_cards.each { |card| sum += card }
puts "Your total card sum is #{sum}."
if sum == 21
puts "You win!"
exit
elsif sum > 21
puts "BUST"
exit
end
puts "Continue?"
answer = gets.chomp
end
puts "Play again? yes or no"
game_decision = gets.chomp
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment