Skip to content

Instantly share code, notes, and snippets.

@JackVCurtis
Created December 4, 2014 21:47
Show Gist options
  • Save JackVCurtis/62e3c493d6bfbbf6557b to your computer and use it in GitHub Desktop.
Save JackVCurtis/62e3c493d6bfbbf6557b to your computer and use it in GitHub Desktop.
get "/rps/:play" do
rps_plays = ["rock", "paper", "scissors", "rock"]
#outcomes = ["You win.", "You lose!", "It's a tie."]
unless rps_plays.include?(params["play"])
return "Try entering rock, paper, or scissors."
end
comp_play = rand(3)
user_play = rps_plays.find_index(params["play"])
if user_play == comp_play
return "Computer played #{rps_plays[comp_play]}. It's a tie."
elsif rps_plays[user_play] == rps_plays[comp_play + 1]
return "Computer played #{rps_plays[comp_play]}. You win!"
else
return "Computer played #{rps_plays[comp_play]}. You lose."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment