Skip to content

Instantly share code, notes, and snippets.

@elcortez
Created April 10, 2019 17:15
Show Gist options
  • Select an option

  • Save elcortez/76a98ee413759eb2ea5be6107ecf2507 to your computer and use it in GitHub Desktop.

Select an option

Save elcortez/76a98ee413759eb2ea5be6107ecf2507 to your computer and use it in GitHub Desktop.
def game
# create an array [rock, paper, scissors]
options = ["rock", "paper", "scissors"]
# create a random input
computer_input = options.sample
puts "Rock, paper, scissors?"
player_input = gets.chomp.downcase
# create player's input
unless options.include?(player_input)
puts "Game over!!! Wrong input"
end
# case for the 1st input
case player_input
when "rock"
if computer_input == "rock"
puts "Draw!Computer input was #{computer_input} "
elsif computer_input == "paper"
puts "You lose! Computer input was #{computer_input}"
else
puts "You win!Computer input was #{computer_input}"
end
when "paper"
if computer_input == "rock"
puts "You win!Computer input was #{computer_input} "
elsif computer_input == "paper"
puts "Draw! Computer input was #{computer_input}"
else
puts "You lose!Computer input was #{computer_input}"
end
when "scissors"
if computer_input == "rock"
puts "You lose!Computer input was #{computer_input} "
elsif computer_input == "paper"
puts "You win! Computer input was #{computer_input}"
else
puts "Draw!Computer input was #{computer_input}"
end
end
# compared input VS input PC
# return lose,win, draw
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment