Add the 'Conditionals' lesson to csintro. (#428)

This commit is contained in:
Galen Nickel 2017-06-27 06:50:24 -07:00 committed by Peli de Halleux
parent c5b9c0691b
commit e598fc7855
15 changed files with 356 additions and 2 deletions

View File

@ -73,6 +73,12 @@
* [Activity](/courses/csintro/variables/activity)
* [Project](/courses/csintro/variables/project)
* [Standards](/courses/csintro/variables/standards)
* [Conditionals](/courses/csintro/conditionals)
* [Overview](/courses/csintro/conditionals/overview)
* [Unplugged](/courses/csintro/conditionals/unplugged)
* [Activity](/courses/csintro/conditionals/activity)
* [Project](/courses/csintro/conditionals/project)
* [Standards](/courses/csintro/conditionals/standards)
## #reference

View File

@ -34,7 +34,7 @@ UNDER CONSTRUCTION: We are still migrating the CSIntro content to this format...
1. [Making](/courses/csintro/making)
2. [Algorithms](/courses/csintro/algorithms)
3. [Variables](/courses/csintro/variables)
4. Conditionals
4. [Conditionals](/courses/csintro/conditionals)
5. Iteration
6. Review/Mini-Project
7. Coordinate Grid System

View File

@ -0,0 +1,31 @@
# Conditional statements
This lesson introduces the Logic blocks such as 'If...then' and 'If...then...else'.
Students practice skills of creativity, problem-solving, and collaboration.
## Lesson objectives
Students 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 skill by collaborating with classmates to create a game that uses a micro:bit and a program that correctly and effectively uses conditionals.
## Lesson structure
* Introduction: Conditionals in daily life
* Unplugged Activity: Red if, Green then
* Micro:bit Activity: Rock Paper Scissors
* Project: Board Game
* Assessment: Rubric for board game project
* Standards: Listed
## Lesson plan
1. [**Overview**: Conditional statements](/courses/csintro/conditionals/overview)
2. [**Unplugged**: Red light, green light](/courses/csintro/conditionals/unplugged)
3. [**Activity**: Rock, paper, scissors](/courses/csintro/conditionals/activity)
4. [**Project**: Board game](/courses/csintro/conditionals/project)
## Related standards
[Targeted CSTA standards](/courses/csintro/conditionals/standards)

View File

@ -0,0 +1,29 @@
# Activity: Rock, paper, scissors
For this activity, each student will need a micro:bit.
Everyone will create the same program, the classic rock paper scissor game.
![Rock, paper, scissors](/static/courses/csintro/conditionals/rock-paper-scissors.jpg)
## Introduce activity
* Have students recall the classic rock paper scissors game.
* 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.
* Have students write the pseudocode for how to play the game on the micro:bit.
>Example pseudocode:<br/>
On button A press: choose random number from 0-2
If random number = 0, then display rock icon,
Else if random number = 1, then display paper icon,
Else display scissors icon.
* Point out that because there are only three possibilities, we dont need to do a separate check to see if random number = 2. So we just use an else.
## micro:bit
* Working from the specifications, have students work in pairs to try to code a Rock Paper Scissors game on their own.
* If students get stuck, there is a tutorial at https://pxt.microbit.org/projects/rock-paper-scissors (steps 1 through 4), that leads students step-by-step through the process of coding a working rock paper scissor game for their micro:bit.
* Let them play the game against their program.
## Ideas for Mods
* Add a way to keep score: Steps 5 through 7 in the tutorial
* Mod the game to use different images or to add more options like Rock Paper Scissors Lizard Spock, Step 8 in the tutorial
See the activity online: [**Rock, paper, scissors**](https://makecode.microbit.org/_A6Xbepc3w4uu)

View File

@ -0,0 +1,30 @@
# Introduction
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 has to be met.
Students are all already familiar with the concept of conditionals in their daily lives!
Have they ever had their 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)
Have the students share a few conditionals from their own lives with the class or within small groups.
Note: For older students, you can have them add the ELSE portion of a conditional.
>**IF** (condition is met), **THEN** (action performed), **ELSE** (different action performed)
Example:
* 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, your students might be barefoot!
![If-Then workflow](/static/courses/csintro/conditionals/if-then-workflow.png)
Tell the students that they will be acting out some conditionals as though the whole class is a computer program for a game. Each student will perform a described action if the indicated condition is met.
**Note:** This activity can be done as a whole class or in smaller groups or as a pencil and paper activity.

View File

@ -0,0 +1,200 @@
# Project: Board Game
This is an assignment for students to create a board game. It should take two to three class periods. If your school has a makerspace or an art classroom where students can access materials such as cardboard, poster paints, or markers, you might schedule your classes to work there.
Once students have finished the first version of their games, schedule time for students to play each others games. Ideally, give them some time to give and gather feedback, then revise their games accordingly.
## 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](https://youtu.be/cxrY7MWEkwE) (featuring Orson Welles): 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](https://www.youtube.com/watch?v=pqYsQgDqlmg): This board game is really a logic puzzle. There are printed clues that illustrate relationships and the phone provides clues that help you to narrow down possibilities by a process of elimination.
[Stop Thief Electronic Board Game commercial 1979](https://www.youtube.com/watch?v=q3wpPRdDy4E): This board game uses a device to give audio clues that help you to figure out what to do on the game board. Its a good example of how you might use sound as a clue.
## Assignment
Students should work in pairs 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.
Students 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 text entry describing your teams game making process and each teammates part in the creation of the game from brainstorming ideas, through construction, programming, and beta 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, students should be writing their own versions of Micro:bit programs to do something original.
Here is one simple program to discuss and use as an example:
Battle Game Pieces
In this example, pieces start out at full strength and lose points based on random events on the board. 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.
```blocks
let p2 = 0
let p1 = 0
input.onButtonPressed(Button.A, () => {
p1 += 1
basic.showNumber(p1)
})
input.onButtonPressed(Button.B, () => {
p2 += 1
basic.showNumber(p2)
})
input.onGesture(Gesture.Shake, () => {
if (Math.random(p1 + p2 - 1 + 1) + 1 <= p1) {
basic.showString("A")
} else {
basic.showString("B")
}
})
```
See the [**BattleGame**](https://makecode.microbit.org/12149-80948-84778-40832) project online.
## Beta Testing
Give students a chance to play each others games. The following process works well:
* Have each pair of students set up their own project at their table.
* Leave a clipboard or a laptop on the table for taking notes.
* Rotate the students through each project, moving clockwise around the room:
>* Play the game (5 min)
>* Fill out a survey form (5 min)
Sample Survey questions
* How easy was it to figure out what to do?
* What is something about this project that works really well?
* What is something that would make this project even better?
* Any other comments or suggestions?
Many online survey tools will allow you to sort the comments by project and share them with project creators so they can make improvements based on that feedback.
## Reflection
Have students write a reflection of about 150300 words, addressing the following points:
* Explain how you decided, as a pair, on your particular board game idea.
* What was something that was surprising to 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?
## Board game example
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:<br/>
>**1** - Shake the micro:bit to randomize how far you get to advance.<br/>
**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.<br/>
**3** - Up to four players.
![Space race game](/static/courses/csintro/conditionals/space-race.jpg)
Finished game
![micro:bit holder square](/static/courses/csintro/conditionals/microbit-holder.jpg)
Micro:bit Holder
![Game pieces](/static/courses/csintro/conditionals/game-pieces.jpg)
Game pieces
```blocks
let yes_or_no = 0
let current_roll = 0
let previous_roll = 0
input.onButtonPressed(Button.AB, () => {
previous_roll = 0
if (4 <= previous_roll) {
yes_or_no = Math.random(8)
}
if (4 > previous_roll) {
yes_or_no = Math.random(5)
}
if (2 < yes_or_no) {
basic.showString("YES")
basic.clearScreen()
} else {
basic.showString("NO")
basic.clearScreen()
}
})
input.onGesture(Gesture.Shake, () => {
current_roll = Math.random(6)
basic.showNumber(current_roll + 1)
basic.pause(5000)
basic.clearScreen()
})
input.onButtonPressed(Button.B, () => {
previous_roll += 1
basic.showNumber(previous_roll)
})
input.onButtonPressed(Button.A, () => {
previous_roll += -1
basic.showNumber(previous_roll)
})
basic.showString("SPACE RACE")
previous_roll = 0
```
See the [SpaceRace](https://makecode.microbit.org/65306-07188-65044-14657) game online.
## Assessment
**Competency scores**: 4, 3, 2, 1
### Rules
>**4 =** All game rules are clear and complete.<br/>
**3 =** A game rule is missing or not complete or not clear.<br/>
**2 =** More than one game rule is missing or not complete or not clear<br/>
**1 =** Most of the game rules are missing or it is not clear what the rules are.
### Game board
>**4 =** Game board is:<br/>
`*` Complete<br/>
`*` Neat<br/>
`*` Fits with the theme of the game<br/>
`*` Micro:bit is a central part of the game<br/>
**3 =** Game board meets only 3 of the conditions listed for a score of 4.<br/>
**2 =** Game board meets only 2 of the conditions listed for a score of 4.<br/>
**1 =** Game board meets only 1 of the conditions listed for a score of 4.
### micro:bit program
>**4 =** micro:bit program:<br/>
`*` Uses the Micro:bit in a way that is integral to the game<br/>
`*` Uses conditionals correctly<br/>
`*` Compiles and runs as intended<br/>
`*` JavaScript includes comments in code<br/>
**3 =** micro:bit program lacks 1 of the required elements.<br/>
**2 =** micro:bit program lacks 2 of the required elements.<br/>
**1 =** micro:bit program lacks 3 of the required elements.
### Photo documentation
>**4 =** Complete photo documentation that includes photos of game board and code and captions.<br/>
**3 =** A photo is missing or of poor quality or a caption is missing.<br/>
**2 =** Multiple photos and/or captions missing or of poor quality.<br/>
**1 =** Most photos and/or captions missing or of poor quality.
### Collaboration reflection
>**4 =** Reflection piece includes:<br/>
`*` Brainstorming ideas<br/>
`*` Construction<br/>
`*` Programming<br/>
`*` Beta testing<br/>
**3 =** Reflection piece lacks 1 of the required elements.<br/>
**2 =** Reflection piece lacks 2 of the required elements.<br/>
**1 =** Reflection piece lacks 3 of the required elements.

View File

@ -0,0 +1,8 @@
# Standards
## CSTA K-12 Computer Science Standards
* CL.L2-03 Collaborate with peers, experts, and others using collaborative practices such as pair programming, working in project teams, and participating in group active learning activities.
* CL.L2-04 Exhibit dispositions necessary for collaboration: providing useful feedback, integrating feedback, understanding and accepting multiple perspectives, socialization.   
* CL.L3A-01 Work in a team to design and develop a software artifact.
* K-12 Computer Science Framework Core concept: Control Structures

View File

@ -0,0 +1,50 @@
# Unplugged: Red light, green light
![Red and green stoplight](/static/courses/csintro/conditionals/red-light-green-light.jpg)
## Objective
To reinforce the programming of basic conditionals by having students experience conditionals through acting them out in real life.
## Activity overview
Students will line up at one end of the classroom with the goal of reaching the other side of the classroom. The teacher, and then the students themselves will call out conditionals and all the students will advance or not depending on the specific conditional statement.
**Note:** As the teacher you will need to keep an eye out for any errors that occur during the running of the program.
## Materials
* Pencils and lined paper (if doing this activity seated). Students can advance across the paper instead of the room with one inch line equal to one step.
## Process
* Have the students line up at one side of the room.
* Explain the rules:
>* The object of the game is to get across the room first.
>* For `if...then` conditionals: If the condition called out is `true` for you, then perform the action described in the `then`. If the condition called out is `false` for you, then do nothing.
>* For `if...then...else` conditionals, listen carefully to the whole condition, as the `else` may apply to you.
## Example conditional statements
* If you are wearing something green, then take a step forward.
* If you have the letter e in your first name, then take two giant steps forward.
* If you are wearing sneakers, then take a step forward, else take 2 steps forward.
* If your birthday is this month, then take a giant hop forward.
The conditionals you use will depend on your individual class.
After the students get the idea of the game, allow them to make up and call out conditionals (that meet teacher approval).
They will need to be observant, as a conditional that moves them forward, will also move their competition forward!
## Tips
* SAFETY FIRST! Students, especially younger ones, can get quite silly with this and while it is meant to be fun and even funny, safety first!
* Student conditionals need to apply to at least two people in the class.
## Reflections
How did they do? Were there any run-time errors? Did a student miss a conditional being met or fail to correctly carry out the THEN or ELSE action?  Were there some conditions that could be evaluated as something other than True or False (maybe, sometimes)?
## Extensions/Variations
* Add AND, OR, AND/OR statements to the conditionals.
>Example: If you have brown hair AND brown eyes, then...
* Create nested IFs
>Example: If you are wearing sneakers, then... if you are also wearing white socks, take three steps forward.
* Let students create their own conditionals for future program runs with the class. (A very popular activity, though all conditionals should be run by the teacher first for approval.)
* Relate this activity to a system and have the students create the conditionals that would end in a product of some kind or the completion of some task, like writing a sentence or setting a table or constructing a simple structure.

View File

@ -31,7 +31,7 @@ Students will...
1. [**Overview**: Variables and constants](/courses/csintro/variables/overview)
2. [**Unplugged**: Keeping score](/courses/csintro/variables/unplugged)
3. [**Activity**: Scorekeeper](/courses/csintro/variables/activity)
4. [**Project**: Everyting counts](/courses/csintro/variables/project)
4. [**Project**: Everything counts](/courses/csintro/variables/project)
## Related standards

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 KiB