Rock-Paper-Scissors Game Using Code.org (Block-Based Coding)
Overview
Build an interactive Rock-Paper-Scissors game in Code.org using block-based programming. Students learn variables, events, random numbers, conditional statements, and user interaction while creating a fun game.
Activity Materials Required
- Computer/Laptop
- Internet
- Code.org Account
- Web Browser
- Keyboard and Mouse
Learning Objectives
- Understand event-driven programming.
- Use block-based coding.
- Generate random choices.
- Apply If-Else conditions.
- Display results.
- Develop logical thinking.
Step-by-Step Instructions
Block-Based Coding Logic
- Start the Program
The game waits until the player clicks one of the three buttons: Rock, Paper, or Scissors. - Detect the Button Click
An on Event block identifies which button the player selected. - Store the Player’s Choice
The selected option is saved in a variable called Player Choice. - Generate a Random Number
The program uses the random Number(1,3) block to generate a random value for the computer. - Assign the Computer’s Choice
- If the random number is 1, Computer Choice = Rock.
- If the random number is 2, Computer Choice = Paper.
- If the random number is 3, Computer Choice = Scissors.
- Compare Both Choices
The program uses if-else blocks to compare the player’s choice with the computer’s choice. - Check for a Draw
If both choices are the same, the program displays “It’s a Draw!” - Check Winning Conditions
The program checks whether:- Rock beats Scissors.
- Paper beats Rock.
- Scissors beats Paper.
If any of these conditions are true, the player wins.
- Check Losing Conditions
If none of the winning conditions are met and it is not a draw, the computer wins. - Display the Result
The program shows the computer’s choice and displays the final result, such as “You Win!”, “Computer Wins!”, or “It’s a Draw!” - Wait for the Next Round
The game remains active, allowing the player to click another button and play again without restarting the program.
Expected Output
- Player Selects an Option
The player clicks either the Rock, Paper, or Scissors button. The program immediately records the selected option and prepares to compare it with the computer’s choice. - Computer Generates a Random Choice
The computer automatically selects Rock, Paper, or Scissors using a random number generator. Since the choice is random, every round is different and unpredictable. - Both Choices Are Compared
The program compares the player’s choice with the computer’s choice using if-else conditional statements. It checks whether the game is a draw, a player win, or a computer win according to the rules of Rock-Paper-Scissors. - Game Result Is Displayed
The screen displays both the Player’s Choice and the Computer’s Choice, followed by the result. Possible outputs include “You Win!”, “Computer Wins!”, or “It’s a Draw!”, depending on the comparison. - Game Is Ready for the Next Round
After displaying the result, the application remains active. The player can click any of the three buttons again to start a new round without restarting the program. - Interactive User Experience
Every button click triggers the complete game logic, giving instant feedback. This allows users to repeatedly play the game while learning how events, variables, random number generation, and conditional statements work together in a block-based programming environment. - The player clicks Rock, Paper, or Scissors.
- The computer chooses an option randomly.
- The program compares both choices.
- If both choices are the same, it shows “It’s a Draw!”
- If the player wins, it shows “You Win!”
- If the computer wins, it shows “Computer Wins!”
- The player’s choice and the computer’s choice are displayed.
- The game is ready to play again with another button click.
STEM Concepts Covered
- Computer Science
- Programming Logic
- Algorithms
- Variables
- Conditional Statements
- Random Number Generation
- User Interface Design
Real-World Applications
- Games
- Educational apps
- Artificial Intelligence
- Decision-making systems
- Interactive applications
Tips for Students
- Test all outcomes.
- Add score tracking.
- Include sounds and animations.
- Create a Best of 5 mode.
Conclusion
Creating a Rock-Paper-Scissors game in Code.org is a fun way to learn programming fundamentals such as variables, events, conditional logic, and random number generation. It encourages creativity, logical thinking, and problem-solving while providing a strong foundation for developing more advanced interactive applications.
Frequently Asked Questions (FAQs)
- Why does the computer always make different choices?
It uses a random number generator.
- What coding concept is most important?
Conditional statements (If-Else).
- Can I keep score?
Yes, by creating score variables.
- Can I add animations?
Yes, Code.org supports animations and sounds.
- Why use random numbers?
To make the game fair and unpredictable.















