put lessons back for Michael
This commit is contained in:
43
docs/lessons/counter/activity.md
Normal file
43
docs/lessons/counter/activity.md
Normal file
@ -0,0 +1,43 @@
|
||||
# counter activity
|
||||
|
||||
Display a number with a variable.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Welcome! This tutorial will teach you how to make a counter that increments when button A is pressed. Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
Let's start by creating a **local variable** `count` to keep track of the current count.
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
```
|
||||
|
||||
The code under ``on button pressed("A")`` will run each time the user presses A. Let's add a line of code that increments `count` by `1`.
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
count = count + 1
|
||||
})
|
||||
```
|
||||
|
||||
Since the count has changed, it's time to refresh the screen display. Let's add a line of code to display the count on screen.
|
||||
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
count = count + 1
|
||||
basic.showNumber(count)
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/counter/challenges)
|
||||
|
||||
### ~
|
||||
|
37
docs/lessons/counter/challenges.md
Normal file
37
docs/lessons/counter/challenges.md
Normal file
@ -0,0 +1,37 @@
|
||||
# counter challenges
|
||||
|
||||
Coding challenges for the counter.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following [guided tutorial](/lessons/counter/activity) At the end of the tutorial, click **keep editing**. Your code should look like this:
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
count = count + 1
|
||||
basic.showNumber(count)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Let's add the code to `count` when `B` is pressed. Add an event handler with `on button pressed(B)` then add the code to `count`.
|
||||
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
count = count + 1
|
||||
basic.showNumber(count)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
count = count - 1
|
||||
basic.showNumber(count)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Now let's try to reset the counter when the micro:bit is shaken. You will need to register an event handler with `on shake`.
|
||||
|
54
docs/lessons/counter/quiz-answers.md
Normal file
54
docs/lessons/counter/quiz-answers.md
Normal file
@ -0,0 +1,54 @@
|
||||
# counter quiz answers
|
||||
|
||||
Learn how to create a counter with the BBC micro:bit button.
|
||||
|
||||
This is the answer key for the [counter quiz](/lessons/counter/quiz).
|
||||
|
||||
## 1. What is a variable?
|
||||
|
||||
Answers may vary but a variable is a place where you can store and retrieve data
|
||||
|
||||
## 2. Draw the stored value for the variable called count
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
```
|
||||
|
||||

|
||||
|
||||
We create a **variable**, `count` to keep track of the current count. The number 0 is stored into memory of the variable.
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Draw which LEDs are ON after running this code and pressing button "A" once. Explain you chose to draw that number
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
count = count + 1
|
||||
basic.showNumber(count)
|
||||
})
|
||||
```
|
||||
|
||||

|
||||
|
||||
We are only pressing on button pressed once. So the number to display on the micro:bit is also one.
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Draw which LEDs are ON after running this code and pressing button "A" three times. Explain you chose to draw that number
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
count = + 1
|
||||
basic.showNumber(count)
|
||||
})
|
||||
```
|
||||
|
||||

|
||||
|
||||
We included the code ``on button pressed("A")`` that runs each time the user presses A. The code increments `count` by `1`. We increase `count` by 1 whenever the user presses the button. So the third time the A button is pressed on the BBC micro:bit, the number 3 is displayed
|
||||
|
||||
<br/>
|
||||
|
54
docs/lessons/counter/quiz.md
Normal file
54
docs/lessons/counter/quiz.md
Normal file
@ -0,0 +1,54 @@
|
||||
# counter quiz
|
||||
|
||||
Learn how to create a counter with the BBC micro:bit button.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [counter tutorial](/lessons/counter/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What is a variable?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Draw the stored value for the variable called count
|
||||
|
||||
```blocks
|
||||
let count = 0
|
||||
```
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Draw which LEDs are ON after running this code and pressing button "A" once. Explain you chose to draw that number
|
||||
|
||||
```blocks
|
||||
let counts = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
counts = counts + 1
|
||||
basic.showNumber(counts, 150)
|
||||
})
|
||||
```
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Draw which LEDs are ON after running this code and pressing button "A" three times. Explain you chose to draw that number
|
||||
|
||||
```blocks
|
||||
let counting= 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
counting = counting + 1
|
||||
basic.showNumber(counting, 100)
|
||||
})
|
||||
```
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
Reference in New Issue
Block a user