Learning Portal

Our hands-on, comprehensive lesson plans span a range of levels. Browse our free STEM and coding learning resources.

Marty Image

1.10: Choices with an If Statement

45 Minutes

Lesson Overview

Learners will get their first taste of giving a 'choice' to Marty. This is not quite the same as when we have a choice, it is really more about telling Marty if one thing is true, then an action will occur; if the thing is not true, the action is skipped.

Key vocabulary:

If

Then

True

False

Condition

Content Sections

  • Learning Objectives
  • Warm-up:
  • Get Learning:
  • Unknown block type "figure", please specify a serializer for it in the `serializers.types` prop
    Unknown block type "figure", please specify a serializer for it in the `serializers.types` prop
    Unknown block type "figure", please specify a serializer for it in the `serializers.types` prop
      Unknown block type "youtube", please specify a serializer for it in the `serializers.types` prop
      Unknown block type "youtube", please specify a serializer for it in the `serializers.types` prop
    • Time for Practice
    • Cool Down:
      • Extensions & Challenges
      • Extend:
        • Support:
          • Additional Reading
          • 1.10: Choices with an If Statement

            45 Minutes

            Lesson Overview

            Learners will get their first taste of giving a 'choice' to Marty. This is not quite the same as when we have a choice, it is really more about telling Marty if one thing is true, then an action will occur; if the thing is not true, the action is skipped.

            Key vocabulary:

            If

            Then

            True

            False

            Condition

            • Writing instructions, awareness of some MartyBlocks
            • iPad or Tablet with MartyBlocks
            • Marty the Robot v2

              Marty Workbook

              Tablets

              Access to the Marty Blocks editor

            Learning Objectives

            I can instruct Marty to perform an action if something else is true

            Warm-up:

            Share with learners the lesson objectives and success criteria from the presentation. The story text is presented with the PowerPoint so that learners can see video and graphics of Marty performing a variety of the tasks.

            Get Learning:

            The following parts of the lesson occur after the first part of the story. It is suggested that you continue the presentation until after learners have seen Marty act based on conditional statements and see where to access the blocks they will need for their program.

            Ask learners, "Who has ever been told something like, if you get ready really quickly, we might go somewhere nice, or exciting?" This idea that an action will occur if an earlier action occurs is instrumental to computational thinking and coding. The symbol that people in computing use to indicate that there are different possibilities in code is the same as the one for the repeat block. It is in the presentation and below. Encourage learners to use this symbol when they are planning their code. They can practice drawing it at the start of their workbooks and then use it again as part of their plan. This plan has an action that occurs before the if statement and then an action that occurs after the statement is true and a further action that occurs whether the if statement is true or false.

            This diagram is expanded on, in the presentation and below, to show the different actions that can occur.

            The program here has Marty take two steps and then presents a condition, Marty is on green: does the color sensor detect green? If the color sensor detects green then the answer is yes, or the statement, 'Marty is on green' is true, then Marty will dance and following that, Marty will take two steps. If the answer is no, or the statement, 'Marty is on green' is false, Marty will not dance but will still take the two steps forward.

            Show how MartyBlocks presents this code on the workspace:

            Explain to learners the need for something to be true or false. For Marty, this needs to be 'sensed'. Learners will need to visit a few different sections in the MartyBlocks environment to set this up:

            • the if then block is in the control section
            • the = block is in the operators section
            • the left color sensor block is in the sensing section
            • the dance block is in the motion section

            The above locations are modeled in a video, within the presentation; the walk forward blocks, from the video of Marty and the planning slide, are not included in this video but learners should know where to find that. Additionally, highlight that the text in the equality block must be changed from 50 to green. The reason should be clear but discuss what learners think will happen if the text remains as 50: will the color sensor ever be equal to 50?

            This video shows what happens when the conditional statement is true and when it is false.

            Have learners list a number of actions that Marty could perform after a condition is met. Record these somewhere so that there is a bank from which learners can draw. Tell learners that they will be writing instructions for Marty to perform one or more of these actions using the if-then blocks.

            Time for Practice

            At this point, learners should have Marty connected and be in Martyblocks.

            Once learners have seen Marty move and react, and have seen how to create the code for one condition, have learners talk in their groups about 1) what the condition will be and 2) what the result of the condition being met will be. There is space in their workbook for learners to plan their ideas. It is recommended that you show the diagram from the presentation that developers use when planning their code, this is highlighted in the workbook.

            Learners need to experiment with their movements to give Marty something interesting to do. Ideally, they should be able to have Marty visit an if-then block more than once. The initial video of Marty moving featured 3 color cards and Marty responded to each one differently. The starter video had Marty react to one color card only. Challenge learners to think about how they can move from a starting color to another, or more than one other, color.

            Cool Down:

            Bring learners back together to discuss the challenges they faced and overcame. Have groups share their instructions for getting a reaction from Marty. What actions did they choose, and what were the associated conditions?

            Suggested questions you might ask:

            • Do you prefer using if statements in your code or not?
            • What benefits or challenges do you see for using if statements?
            • What did you think of, when you wanted to have Marty check the color again?

            Carry out any end of lesson routines.

            Log off devices and clear everything away.

            Extensions & Support

            Extend:

            • Have learners explore the control blocks to see what it was that the initial video used to instruct Marty to stop and move no further, when on red.
            • Additionally, have learners have multiple actions for each color.

            Support:

            • The rhombus is sometimes tricky to draw. It may help to have physical 2D shapes that learners can use to draw around.
            • The idea of a choice for a computer is slightly different than it is for people. When we are presented with options, we get to decide what to do. A robot or computer can only perform as instructed. This is important to communicate. Make some funny examples to illustrate this clearly. This should support all learners to see how strict the 'if then' block really is.

            Additional Reading

            Educator’s Guide

            User Guide for MartyBlocks


            • Technologies: Computing Science
            • Literacy & English: Listening and Talking
            • Health and Wellbeing: Mental, Emotional, Social and Physical Wellbeing
            • Literacy & English: Writing
            • CSTA Education Standards
            • Elementary Technology Applications: Grade 3 to Grade 5
            • Digital Technologies, Design & technologies: Design & Technologies
            • Digital Technologies, Design & technologies: Digital Technologies
            • Computing, Design and Technology: Computing
            • International Society for Technology in Education (ISTE)