Code a Dice – Build Your Own Virtual Dice

Code a Dice to Roll

This challenge has been written by Fabrizia Agnello and is part of the EU CODE WEEK CHALLENGES.

Duration

1 hour

Experience

Beginner

Target Audience

  1. Teachers and educators
  2. Primary School students (6 to 12 years)
  3. Lower Secondary School students (12 to 16 years)

Purpose

  1. To enhance creativity in coding.
  2. To code a simulation of a randomly moving object to be used if the real object is not available

Recommended Materials

  1. Scratch

Code a Dice to Roll

Teachers and educators

Primary School students (6 to 12 years)

Lower Secondary School students (12 to 16 years)

Description

In this challenge you will code a dice to randomly roll on your command. You can choose any type of dice with the number of faces you like, as those used in role play games, and add sounds as well.

Instructions

  1. Log in to Scratch
  2. Choose a backdrop
  3. Create your dice sprite or search for one on the web and upload it to your program
  4. Create as many costumes for the sprite as the number of faces of the chosen dice, each of them showing a different number
  5. Choose how you want the dice to start rolling (pressing a keyboard key, clicking on the sprite, etc.) and write the code
  6. Code the sprite to randomly change costume at the end of the roll
  7. Add sound effects

Share the link to your work in your Instagram Bio: tap the Edit Profile button on your Instagram and add the link to your work in the Website field. After that, create a new post, add a screenshot of your work, write “Link in Bio”, add the hashtag #EUCodeWeekChallenge and mention @CodeWeekEU.

Download this challenge as a word document