Sha256: db2eca63da6be64a18de1199206ef774408e9e87c25fd6882b57f8a930d60b16

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

---
layout: default
title: "Simple Code - RPSG"
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

$end
{% endhighlight %}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rpsg-0.3.1 docs/_pages/simple.txt