Skip to content

Why

To build a robot with legos, you will need to understand how to use conditionals to change the behavior of the robot.

What

In this lesson you will learn about conditionals and how use them in a simple program for the microbit.

How

You will create a program in Microsoft Makecode that utilizes conditionals and builds on the skills you learned about variables in the last lesson.

What you will need for this activity:
1. A laptop, desktop, or chromebook
2. An internet connection
3. A Microbit v2
4. USB cable to connect microbit to
computer

 

The Lesson

1. Open https://www.microsoft.com/en-us/makecode in a web
browser
2. Sign in with your free account by clicking the Sign in in the
top right of the screen
3. After signing in, click on the picture of the micro:bit, this
should take you to https://makecode.microbit.org/
4. Click on the purple New Project rectangle image to create a
new project
5. Enter “conditionals” for the name of your project, then
click the green Create button.

What are conditionals?  Have you ever burned your mouth trying to eat a piece of pizza or drinking from a cup of hot chocolate?  If you have, you probably learned a lesson after that.  You check if the food or drink is too hot before taking a bite or taking a drink.

You can think of conditionals as a test.  If pizza is not super hot then take a bite.  If hot chocolate is not super hot then take a sip.  The test could also take a form if pizza is not super hot then take a bite or else wait three minutes.

The test has to be something that is true.  For example, you can test if something is equal, greater than, or less than to some value.  If you are thinking about robots, you might of a test how close the robot is to the wall and make a decision to turn a different direction using conditionals.

Here are some general forms conditionals can take:

If True Then do X

If True Then do X Else do Y

If True Then do X Else If True Then do Y Else do Z

Challenge

Challenge and solution guide for this lesson is currently only available to subscribers.

Review

In this lesson you learned how use conditionals in your program.

Next lesson

In the next lesson you will learn about arrays and how to use them in your microbit programs.