Migrate docs from the other repo
This commit is contained in:
44
docs/lessons/looper/activity.md
Normal file
44
docs/lessons/looper/activity.md
Normal file
@ -0,0 +1,44 @@
|
||||
# looper blocks activity
|
||||
|
||||
Display a series of numbers with a for loop.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
### @video td/videos/looper-0
|
||||
|
||||
### ~
|
||||
|
||||
Welcome! This activity will teach how to display a series of numbers for a for loop. Let's get started!
|
||||
|
||||
Let's create a for loop where `0` is the loop's starting value, `i` is the index variable, and `5` is the ending value. The index variable `i` starts at 0 and increases by 1 each time through the loop. The loop ends when `i = 5`.
|
||||
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 6; i++) {
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
We will show the number of times the loop has been executed. It will go from zero to five times.
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 6; i++) {
|
||||
basic.showNumber(i)
|
||||
}
|
||||
```
|
||||
|
||||
The for loop while cycle through to six immediately unless we pause for a little bit in between each loop.
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 6; i++) {
|
||||
basic.showNumber(i)
|
||||
basic.pause(2000)
|
||||
}
|
||||
```
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/microbit/lessons/looper/challenges)!
|
||||
|
||||
### ~
|
||||
|
93
docs/lessons/looper/challenges.md
Normal file
93
docs/lessons/looper/challenges.md
Normal file
@ -0,0 +1,93 @@
|
||||
# looper block challenges
|
||||
|
||||
Coding challenges for the looper.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided activity:
|
||||
|
||||
* [activity](/microbit/lessons/looper/activity)
|
||||
|
||||
At the end of the activity, your code should look like this:
|
||||
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 6; i++) {
|
||||
basic.showNumber(i)
|
||||
basic.pause(2000)
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
### @video td/videos/looper-1
|
||||
|
||||
What if we want to count up to lucky number 7 instead? Let's do that by changing the ending value to `7` instead of `5`.
|
||||
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 8; i++) {
|
||||
basic.showNumber(i)
|
||||
basic.pause(2000)
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
* Run the program now to see your changes.
|
||||
|
||||
### Challenge 2
|
||||
|
||||
### @video td/videos/looper-2
|
||||
|
||||
What about 9? Let's do that by changing the ending value to `9`.
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 10; i++) {
|
||||
basic.showNumber(i)
|
||||
basic.pause(2000)
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
* Run your code to see the new counter.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
### @video td/videos/looper-3
|
||||
|
||||
Now let's start counting from `3` instead! Our for loop will always start at `0` so we simply add `3` to the `i` variable when passing it to `show number`.
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 10; i++) {
|
||||
basic.showNumber(i+3)
|
||||
basic.pause(2000)
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
|
||||
Run it on the simulator!
|
||||
|
||||
### Challenge 4
|
||||
|
||||
### @video td/videos/looper-4
|
||||
|
||||
Now, let's **count down from 9**. Change the line `show number(i + 2, 150)` to `show number(9 - i, 150)`.
|
||||
|
||||
```blocks
|
||||
for (let i = 0; i < 10; i++) {
|
||||
basic.showNumber(9-i)
|
||||
basic.pause(2000)
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
* Run the code to make sure it is doing what is expected.
|
||||
|
||||
### Challenge 5
|
||||
|
||||
After counting down from `9` let's show the string `BOOOM`!
|
||||
|
Reference in New Issue
Block a user