Username Generator

ScratchEasy

In this lesson you will create a robot that first asks you some questions and then generates a username for you based on your answers!

1

Create a new Scratch project

Create a new Scratch project and delete the cat sprite.

2

Edit the backdrop

We want to show the text 'Username Generator' at the top of the screen, follow these steps to edit the backdrop:

  1. Click on the Stage backdrop in the bottom left of the project editor.
  2. Then click on the 'Backdrops' tab at the top of the Block Palette. This displays the backdrop editor.
  3. Select the text tool by clicking the T button.
  4. Choose a colour for your text from the colour palette.
  5. Choose a font.
  6. Click on the top of the back drop to add your text there.
  7. Type 'Username Generator' and then click anywhere on the screen.
  8. Make the text a bit bigger by dragging a corner of the bounding box.
  9. Move the text into the middle of the backdrop (but still at the top).

3

Add the Retro Robot sprite

We're going to use a robot sprite to ask you some questions. The answers to these will help make your username!

Once you've added the 'Retro Robot' sprite form the library, drag it to the middle of the stage area.


4

Create a username variable

We will need to create a variable called 'username' to store the text of our username as we build it.

When you create a variable, a small orange rectangle appears in the stage area that displays the current value of that variable. We don't need to this display so we're going to add the following code to hide it:

when green flag clicked hide variable [username v]

5

Say the instructions

Our robot is going to give the instructions for using the username generator. Add the following code at the bottom of the 'when green flag clicked' blocks of code:

when green flag clicked say [I am the random username generator robot!] for [5] secs say [To get a username, answer these questions...] for [5] secs

6

Get the first letter of their name

The start of the username is going to be the first letter of the person's name. We can get this by asking the person what their name is and then taking the first letter of their answer. Add the following code at the bottom of the 'when green flag clicked' blocks of code:

when green flag clicked say [I am the random username generator robot!] for [5] secs say [To get a username, answer these questions...] for [5] secs // insert the new code below here ask [Whats your first name?] and wait set [username v] to (letter (1) of (answer))

7

Get their favourite animal

Next we'll ask them what their favourite animal is and add that to the username. Add the following code at the bottom of the 'when green flag clicked' blocks of code:

when green flag clicked say [I am the random username generator robot!] for [5] secs say [To get a username, answer these questions...] for [5] secs ask [Whats your first name?] and wait set [username v] to (letter (1) of (answer)) // insert the new code below here ask [Whats your favourite animal?] and wait set [username v] to (join (username) (answer))

8

Get the year they were born

Next we'll ask them what year they were born and add that to the username. Add the following code at the bottom of the 'when green flag clicked' blocks of code:

when green flag clicked say [I am the random username generator robot!] for [5] secs say [To get a username, answer these questions...] for [5] secs ask [Whats your first name?] and wait set [username v] to (letter (1) of (answer)) ask [Whats your favourite animal?] and wait set [username v] to (join (username) (answer)) // insert the new code below here ask [What year were you born?] and wait set [username v] to (join (username) (answer))

9

Animate the robot

To make it look like the robot is doing some work to come up with their username, we're going to animate the robot by making it spin around. Add the following code at the bottom of the 'when green flag clicked' blocks of code:

when green flag clicked say [I am the random username generator robot!] for [5] secs say [To get a username, answer these questions...] for [5] secs ask [Whats your first name?] and wait set [username v] to (letter (1) of (answer)) ask [Whats your favourite animal?] and wait set [username v] to (join (username) (answer)) ask [What year were you born?] and wait set [username v] to (join (username) (answer)) // insert the new code below here repeat (36) turn cw (10) degrees end

10

Say the generated username!

Now that we've built the username from the person's answers, program the robot to say the username. Add the following code at the bottom of the 'when green flag clicked' blocks of code:

when green flag clicked say [I am the random username generator robot!] for [5] secs say [To get a username, answer these questions...] for [5] secs ask [Whats your first name?] and wait set [username v] to (letter (1) of (answer)) ask [Whats your favourite animal?] and wait set [username v] to (join (username) (answer)) ask [What year were you born?] and wait set [username v] to (join (username) (answer)) repeat (36) // insert the new code below here turn cw (10) degrees end say (join [Your username is ] (username))

11

Test it out!

Test to see if your username generator works by clicking the green flag and answering the questions. If it doesn't work properly try and find the piece of code were the mistake is so you can fix it.

Any other ideas?
Have you any other ideas for questions the robot could ask to build a username? If you can try adding the code to ask that question and add the answer to the username variable.


End of lesson
Copyright Notice
This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.

Scratch is developed by the Lifelong Kindergarten Group at the MIT Media Lab. It is available for free at https://scratch.mit.edu