Student workbook - Unit 4 Conditionals

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Introduction to Computer

Science

Unit 4:
Conditionals

Student workbook
makecode.microbit.org
Table of Contents

Overview......................................................................................................................................... 3
Unit summary............................................................................................................................... 3
Learning goals.............................................................................................................................. 3
Lesson A: Conditionals in daily life.................................................................................................. 4
Lesson B: Rock, paper, scissors...................................................................................................... 5
Lesson C: Code a board game........................................................................................................ 7
Glossary of key terms................................................................................................................... 14

Overview

Introduction to Computer Science Unit 4: Conditionals | 2


Unit summary
This unit introduces the Logic blocks, such as ‘If…then’ and ‘If…then…else’. You will practice
skills of creativity, problem solving, and collaboration. You will learn what conditional statements
are, and why and when to use them in a program. In the unplugged activity, you will experience
conditionals through acting them out in real life. Then you will code a game of “Rock, paper,
scissors” with the micro:bit via the programmable buttons and the LED screen. In the final
project, you will design, build, and code your own unique micro:bit-based board game using
conditionals.

Learning goals
During this unit, you will:

 Understand what conditional statements are and why and when to use them in a program.
 Learn how to use the Logic blocks ‘If…then’ and ‘If…then…else’.
 Practice using the Logic blocks so different conditions yield specified outcomes.
 Demonstrate understanding and apply skills by collaborating with classmates to create a
game that uses a micro:bit and a program that correctly and effectively uses conditionals.

Introduction to Computer Science Unit 4: Conditionals | 3


Lesson A: Conditionals in daily life
Overview: Conditionals
Computer programs are instructions telling the computer how to process input and deliver
output. An important part of programming is telling the computer WHEN to perform a certain
task. For this, we use something called conditionals. Conditionals get their name because a
certain condition or rule must be met in order for an action to be carried out.

You are all already familiar with the concept of conditionals in your daily life!

Have you ever heard your parents say:

 “If you clean your room, you can go out with your friends.”
 “If your homework is done, you can play video games.”
 “If you do your chores all week, you get your allowance, else you are grounded.”

These are all conditionals! Conditionals follow the format of IF this, THEN that.

IF (condition is met), THEN (action performed)

IF (condition is met), THEN (action performed), ELSE (different action performed)

IF it is snowing, THEN wear boots, ELSE wear shoes.

The ELSE portion makes sure that a different action is performed in either case. Without the ELSE
action, you might be barefoot!

Introduction to Computer Science Unit 4: Conditionals | 4


Lesson B: Rock, paper, scissors
Coding activity: Rock, paper, scissors
Recall the classic “Rock, paper, scissors”
game that you played in Unit 3 Variables.

 What are the rules of the game?


 What are the conditionals?

Example: If Player A gets rock and Player


B gets scissors, then Player A wins.

Write the pseudocode for how to play the


game on the micro:bit

Use this space to write your pseudocode

Introduction to Computer Science Unit 4: Conditionals | 5


Use this space to write your pseudocode

Coding
Working from the pseudocode specifications, work in pairs to try to code a Rock, paper, scissors
game on your own.

Ideas for mods

 Add a way to keep score


 Mod the game to use different images or to add more options like Rock, paper, scissors,
lizard, Spock

Introduction to Computer Science Unit 4: Conditionals | 6


Lesson C: Code a board game
Activity: Board game

Introduction
Many board games use an electronic toy to signal moves or provide clues. There are some funny
examples online if you search for “electronic board game”. Here are some examples:

 Dark Tower (featuring Orson Welles) at youtu.be/cxrY7MWEkwE (0:32): This is an example


of a circular board game in which the pieces start on the edges and move in toward the
middle.
 Electronic Dream Phone Board Game Commercial - 1992 at youtu.be/pqYsQgDqlmg (0:30):
This board game is really a logic puzzle. There are printed clues that illustrate relationships
and the phone provides clues that help you narrow down possibilities by a process of
elimination.
 Stop Thief Electronic Board Game commercial -1979 at youtu.be/q3wpPRdDy4E (0:30): This
board game uses a device to give audio clues that help you to figure out what to do on the
game board. It’s a good example of how you might use sound as a clue.

Introduction to Computer Science Unit 4: Conditionals | 7


Assignment
You will work with a partner to create an original board game project in which micro:bit is a
central feature, and the rules of their board game should use conditionals.

You will need to work together to come up with:

 A set of written rules (how to play)


 A game board
 A program for the micro:bit
 Photo documentation of the different game pieces, cards, or other components of the
game with the micro:bit included as well as a screenshot of your micro:bit code. Each
photo must have a caption that describes what the photo is documenting.
 Reflection: A diary entry describing your team’s game-making process and each
teammate’s part in the creation of the game from brainstorming ideas through
construction, programming, and testing.

The micro:bit needs to work in conjunction with the game board and/or game pieces and should
be a central feature of the game. Ideally, it should be more than a simple substitute for a six-
sided die.

The micro:bit might:

 Simulate the results of a battle between two pieces


 Randomly point in a different direction of travel
 Generate a result based on its current incline
 Point randomly at players and kill them
 Display a dynamic score
 Let your imaginations run wild!

Ideally, you should be writing your own versions of micro:bit programs to do something original.

Introduction to Computer Science Unit 4: Conditionals | 8


Project examples

1. Battle pieces

In this example, pieces start out at full strength


and lose points based on random events on the
board.

Rules: When two pieces meet on the same space,


they battle.

 Press A to enter the strength of piece A.


 Then press B to enter the strength of piece
B.
 Shake the micro:bit to determine the winner
of the battle, which is proportionately
random to the strength of each piece.

2. Space Race by K. and S.

How to win: Starting from Earth, your goal is to


progress to Mars. The first person to reach Mars is
the winner.

Rules:

1. Shake the micro:bit to randomize how far you


get to advance.

2. If you land on a pink square, press B on the


micro:bit until your previous roll number
appears. Then press A and B at the same time
to see whether or not you move based upon
the number on the square.

3. Up to four players.

micro:bit holder

Introduction to Computer Science Unit 4: Conditionals | 9


Game pieces

Project expectations

Follow the design thinking approach and make sure your project meets these specifications:

 All game rules should be clear and complete.


 The game board should be complete, neat, and fit the theme of the game.
 The micro:bit must be an integral part of the game and the board.
 The program correctly uses conditionals, compiles and runs as intended, and includes
comments.
 Photo documentation that includes photos of game board, code, and captions.
 Provide the written Reflection Diary entry that includes your brainstorming ideas,
construction, programming, and beta testing (which we’ll talk about after you complete
your project).

The design thinking process:

1. Empathize by learning more about your target audience.

2. Define: Understand and identify your audience’s problems or needs.

3. Ideate: Brainstorm several possible creative solutions.

4. Prototype: Construct rough drafts or sketches of your ideas.

5. Test your prototype solutions and refine until you come up with the final version.

Introduction to Computer Science Unit 4: Conditionals | 10


Use this space to start your design thinking process:

Introduction to Computer Science Unit 4: Conditionals | 11


Project scoring rubric

Assessment
1 2 3 4
elements

Rules Most of the game More than one A game rule is All game rules are
rules are missing game rule is missing or not clear and
or it is not clear missing or not complete or not complete.
what the rules are complete or not clear.
clear.

Game board Game board Game board Game board Game board is:
meets only one of meets only two of meets only three
the conditions the conditions of the conditions
▪ Complete
listed for a score listed for a score listed for a score ▪ Neat
of 4. of 4. of 4.
▪ Fits with the
theme of the
game
▪ micro:bit is a
central part of
the game

Photo A photo is missing Multiple photos Most photos Complete photo


documentation or of poor quality and/or captions and/or captions documentation
or a caption is missing or of poor are missing or of that includes
missing. quality. poor quality. photos of game
board, code, and
captions.

micro:bit program micro:bit program micro:bit program micro:bit program micro:bit program:
lacks three or lacks two of the lacks one of the
more of the required elements. required elements.
▪ Uses the
micro:bit in a
required elements. way that is
integral to the
game
▪ Uses
conditionals
correctly
▪ Compiles and
runs as
intended
▪ Uses
meaningful
comments in
code

Introduction to Computer Science Unit 4: Conditionals | 12


Reflection Diary
Expectations

Write a reflection of about 150–300 words addressing the following points:

 Explain how you decided, as a pair, on your particular board game idea.
 What was something that was surprised you about the process of creating this game?
 Describe a difficult point in the process of designing this game and explain how you
resolved it.
 What feedback did your beta testers give you? How did that help you improve your game?
What were the Conditionals that you used as part of your game rules?
 Publish your MakeCode program and include the link.

Diary entry scoring rubric

Assessment
1 2 3 4
elements

Diary entry Diary entry is Diary entry is Diary entry is Diary entry
missing three missing two of missing one of addresses all
or more of the the required the required elements,
required elements. elements. including:
elements.
▪ Brainstormin
g ideas
▪ Construction
▪ Programmin
g
▪ Beta testing

Introduction to Computer Science Unit 4: Conditionals | 13


Glossary of key terms
Conditional statement: Also known as an IF THEN or IF THEN ELSE statement. The part of a
computer program or code that tells a computer when to perform an action.

Introduction to Computer Science Unit 4: Conditionals | 14

You might also like