Skip to main content
Skip to main content

Visual to text coding
Lesson 4: Scissors, Paper, Rock

Years 5-6; 7-8

This is the fourth in a series of lessons to transition from visual coding to text-based coding with a General Purpose Programming language.

Included videos can be used by a beginner teacher and/or students to see how to code each of the simple programs step-by-step in all three languages: Scratch, Python and JavaScript.

This lesson may take two to three 45-minute periods. It introduces the combining of logical operators and and or for more complex decisions.

Next lesson    

Learning hook

For this group activity, students should work in small teams. Each team needs a copy of this handout, which contains logical operators, conditions and outcomes to be cut out with scissors.

Imagine your class is having a gift giving celebration. The rules are quite complicated.

Read these carefully as a class to make sure you understand how the game works:

  • A certain number of presents is placed together on a table, and everyone’s name is placed in a hat. Some names are written on green cards, and other names on red cards.
  • If your name is picked from the hat, your action will depend on what colour card your name is written on.
  • If it’s a green card, you must take and unwrap a present from the table. However, if no presents remain on the table, you must take the other action as if you have a red card.
  • If it’s a red card, you must choose a present to steal from the person who went before you. If that present has already been stolen twice, it is out of bounds and you get nothing! Otherwise, you successfully steal the present. (The victim must then obtain a replacement present by acting according to their own card colour.)

TASK: In your team construct three long, logical sentences to determine your actions when it's your turn in the celebration. Each sentence leads to one of the three outcomes. Note. you do not have to simulate the present giving celebration itself, unless doing so helps with understanding."

Decorative image of colourfule, gift-wrapped presents Commons,
CC BY-SA 3.0


(Solutions may vary, but they must be logically correct).

Learning map and outcomes

In this lesson, students will:

  1. access an online programming environment for visual code (Scratch) and for general purpose programming (Python or JavaScript),
  2. explore the design of a game that brings together user input, random numbers and complex winning conditions,
  3. plan and code the Scissors, paper, rock game, where the user plays against the computer.

Learning input

Begin by watching the overview video below:

As a class, write or type out the incomplete pseudocode below, filling in the gaps.

(Note this program is slightly simplified.)

2    randomNumber ← random choice of 0, 1 or 2
3    If randomNumber = 0 Then
4        computerPick ← ‘scissors’
5    Else If randomNumber = 1 Then
6        computerPick ← ______
7    Else If randomNumber = _ Then
8        ____________________
9    End If
11   Display ‘Scissors, paper or rock?’
12   userGuess ← input from user
14   If __________ = __________ Then
15       Display ‘Tie.’
16   Else 
17       If (computerPick = ‘scissors’ And userGuess = ‘paper’) Or
18          (computerPick = ‘paper’ And userGuess = ________) Or
19          (computerPick = ________ And userGuess = ‘scissors’) Then
20           Display ‘You lose.’
21       Else
22           Display ___________
23       End If
24   End If
25 END

This program has three sections (Lines 2-9, Lines 11-12 and Lines 14-24). Discuss the following questions to develop an understanding of the structure.

Q. What is the purpose of Lines 2 to 9?

A. This is where the computer’s pick (scissors, paper or rock) is chosen using a random number.

Q. What is the purpose of Lines 11 and 12?

A. This is where the user makes their pick.

Q. What is the purpose of Lines 14 to 24?

A. This is where the program determines who was the winner, or if there was a tie.

Learning construction

For more on setting up and choosing a language, see Setting Up.

Step 1: Coding the game

The below video demonstrates coding the solution in Scratch, Python and JavaScript. Try it yourself before checking the solution code below.

Solution code:

Step 2: Understanding validation

The game rejects invalid user input. If the user types anything other than ‘rock’, ‘paper’ or ‘scissors’, they must try again.

This is called electronic validation, and is an important part of the user experience. Ideally, a solution should reject invalid data, and provide useful feedback or error messages to the user.

Use the incomplete table below to discuss how different programs and user interfaces do electronic validation. You may be able to think of some more situations.

Step 3: Tinker task

Decorative image of dice

Jim Champion/Wikimedia Commons, CC BY-SA 3.0

Some people think that ‘rock’ should beat everything! Make a new version of the program where ‘rock’ always beats paper and scissors. (Keep your original game code somewhere else!)

Solution code:


These challenges use the skills covered so far. By writing or modifying their own programs, students have an opportunity to demonstrate Application and Creation.

  1. Edit the original game to work 'best out of three' – that is, the winner is the one who won the most games after three rounds.

    You’ll need to add an additional variable to keep track of the number of times the user has won, then check it at the end of three rounds. You might also need a variable to keep track of the number of the times the computer has won.

    Note: You do not need to use a loop, since loops will be officially covered later in this course. You may instead retype or copy and paste your existing code.

Solution code:

  1. (OPTIONAL) More advanced versions of Rock-Paper-Scissors have been invented, including RPS-5 (Rock-Paper-Scissors-Lizard-Spock), RPS-7, RPS-15 and even RPS-101!

    Can you code a program for RPS-5 (Rock-Paper-Scissors-Lizard-Spock)?

    Mind map showing the relationship between components of the Rock Paper Scissors Lizard Spock game. Scissors cuts paper, Paper covers Rock, Rock crushes Lizard, Lizard poisons Spock, Spock smashes Scissors, Scissors decapitates Lizard, Lizard eats Paper, Paper disproves Spock, Spock vaporises Rock and Rock crushes Scissors.

    Image credit: Rock Paper Scissors Lizard Spock by Sam Kass and Karen Bryla (CC-SA)

    Solution code:


  • Setting up online environments
  • Online environments for coding in each language
    • Scratch
    • an online environment suited to Python
    • JSFiddle: an online environment suited to JavaScript
  • Cheat sheets listing basic commands for coding:
    • Python Cheatsheet (from Grok Learning)
    • JavaScript CheatSheet (Tip: Press the little blue tabs to move Variables, Basics, Strings and Data Types to the top.)