Introduction

British astronaut Tim Peake is going on the Principia mission to the International Space Station which is in orbit around Earth. Tim will be setting up Astro Pi computers running children’s code on the Space Station.

You are going to code an alien that will tell you how old you’d be if you lived on another planet.

Step 1: Storing your age

Activity Checklist

  • Open the ‘Space Age’ Scratch project. Your club leader will give you a copy of this project, or you can open it online at jumpto.cc/space-age-resources.

    You should see an alien and some planet sprites.

  • Let’s start by creating a variable to store your age on Earth.

    Click Data and then click ‘Make a Variable’. Call this variable age on Earth.

    screenshot
    screenshot
  • Now we can ask the user how old they are on Earth, and store their answer. Click on your ‘Alien’ sprite, and add this code:

        when flag clicked
        ask [What's your age on planet Earth?] and wait
        set [age on Earth v] to (answer)
        say [Click on a planet...] for (2) secs

    You can find the answer block in the sensing section.

  • Click the green flag to test your project. Enter your age when asked.

    screenshot
    screenshot

    Once you have entered your age, you should see that it has been stored in your age on Earth variable.

    screenshot
    screenshot

Save your project

Step 2: Your age on Mercury

Let’s calculate how old you’d be if you lived on Mercury.

Activity Checklist

  • Click on your ‘Mercury’ sprite (the smallest planet) and add this code:

        when this sprite clicked
        broadcast [Mercury v]

    To create the broadcast block, click the down arrow on the block and enter the text ‘Mercury’.

    screenshot
    screenshot

    Now, whenever your ‘Mercury’ sprite is clicked it will broadcast a message to all other sprites.

  • Click on your ‘Alien’ sprite, and add this code so that it responds to the message:

        when I receive [Mercury v]
        say [On Mercury, you'd be...] for (2) secs
  • Now test your project again. Clicking on Mercury should cause your Alien to say On Mercury, you'd be....

    screenshot
    screenshot
  • You also want your alien to say what your age would be on Mercury.

    To do this, firstly add another say block to your alien’s Mercury code.

    screenshot
    screenshot
  • One year on Earth is the time it takes for the Earth to orbit the sun, which is 365 days. Mercury only takes 88 days to orbit the sun, which means that there are 4.15 Mercury years per Earth year (365 ÷ 88 = 4.15).

    Let’s multiply your age on Earth by 4.15 to calculate your age on Mercury. In Scratch, the symbol for multiply is *. Add a multiply block to your Alien’s Mercury code.

    screenshot
    screenshot
  • To multiply your age on Earth by 4.15, drag your variable into the first space, and type 4.15 into the second space.

    screenshot
    screenshot
  • Test your project by clicking Mercury. Your alien should tell you how old you’d be if you lived on Mercury.

    screenshot
    screenshot

Save your project

Step 3: Travel to Mercury

Code your alien to travel to other planets!

Activity Checklist

  • Click your ‘Alien’ sprite and add a glide block just before your say block. Change the block so that the alien takes 2 seconds to glide.

    screenshot
    screenshot
  • You want your alien to glide to your ‘Mercury’ sprite, so you’ll need to know the x and y positions of Mercury.

    Click the sensing tab, and drag an x position of... block into your glide block. Make sure that ‘Mercury’ is selected.

    screenshot
    screenshot
  • Do the same for the y position. Make sure that y position and Mercury are selected.

    screenshot
    screenshot
  • You can also play a sound as the alien is moving.

    screenshot
    screenshot
  • If you prefer, you can even click the ‘Sounds’ tab and choose your own sound to play.

    screenshot
    screenshot
  • Test your project. Your alien should now travel to Mercury and play a sound when clicked.

    screenshot
    screenshot

Save your project

Challenge: Age on other planets

Can you code your alien to travel to other planets, and tell you your age there?

Here are the lengths of a year on each planet, relative to Earth:

Planet Years per Earth year
Mercury 4.15 Earth years
Venus 1.62 Earth years
Mars 0.53 Earth years
Jupiter 0.08 Earth years
Saturn 0.03 Earth years
Uranus 0.01 Earth years
Neptune 0.006 Earth years

Remember that each planet will need to broadcast a message when it has been clicked.

    when this sprite clicked
    broadcast [Mercury v]

You can also copy your alien’s code to use for your other planets. Right-click on the top of your code and click ‘duplicate’.

screenshot
screenshot

These are the bits of the duplicated code that you’ll need to change:

screenshot
screenshot

Save your project

Challenge: Age accuracy

In your project, the user enters their age in years. This isn’t very accurate if it’s been a while since your birthday.

Can you improve your project so that it asks you how old you are in months, years and days? Remember there are 365 days in a year and (on average) 30 days in a month.

Here are some code blocks that will help you:

    set [age in days v] to [0]
    ask [How old are you in years?] and wait
    change [age in days v] by ( (answer) * (365) )
    ask [How many months since your last birthday?] and wait
    change [age in days v] by ( (answer) * (30) )
    set [age on Earth v] to ( (age in days) / (365) )

Save your project