Sha256: 79ca3f9f8bb705076807b70832e9189a24ebe3f13285df943c4b150725ed20c8
Contents?: true
Size: 1.49 KB
Versions: 5
Compression:
Stored size: 1.49 KB
Contents
--- layout: default title: "Simple Code" permalink: /simple.html --- > This is what a beginner's RPS code might look like {% highlight ruby %} options = ["rock", "paper", "scissors"] computer_choice = options[rand(options.length)] puts "What's your choice?" puts "rock, paper, or scissors" user_input = gets.chomp.downcase # read user input and convert to lower case loop do if (user_input == "rock" || user_input == "paper" || user_input == "scissors") if (user_input == computer_choice) puts "We got the same, let's keep playing!" elsif (user_input == "rock" && computer_choice == "scissors") puts "computer choice is: " + computer_choice + ", you win! :)" elsif (user_input == "rock" && computer_choice == "paper") puts "computer choice is: " + computer_choice + ", computer wins :(" elsif (user_input == "paper" && computer_choice == "scissors") puts "computer choice is: " + computer_choice + ", computer wins :(" elsif (user_input == "paper" && computer_choice == "rock") puts "computer choice is: " + computer_choice + ", you win! :)" elsif (user_input == "scissors" && computer_choice == "rock") puts "computer choice is: " + computer_choice + ", computer wins :(" elsif (user_input == "scissors" && computer_choice == "paper") puts "computer choice is: " + computer_choice + ", you win! :)" end else puts "Invalid choice, enter Rock, Paper, or Scissors" end break end {% endhighlight %}
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
rpsg-0.2.9 | docs/simple.md |
rpsg-0.2.8 | docs/simple.md |
rpsg-0.2.7 | docs/simple.md |
rpsg-0.2.6 | docs/simple.md |
rpsg-0.2.5 | docs/simple.md |