Migrate docs from the other repo
This commit is contained in:
65
docs/reference/js/lessons/digi-yoyo/challenges.md
Normal file
65
docs/reference/js/lessons/digi-yoyo/challenges.md
Normal file
@ -0,0 +1,65 @@
|
||||
# digi yoyo challenges
|
||||
|
||||
Coding challenges for the digi yoyo.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/microbit/lessons/digi-yoyo/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
let count = 0
|
||||
while (count < 10) {
|
||||
basic.pause(1000)
|
||||
basic.showNumber(count, 150)
|
||||
count = count + 1
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
How about we create a counter that counts backwards from 10 to 1? Let's add a while loop that executes only when `count` is greater than 0.
|
||||
|
||||
```
|
||||
let count1 = 0
|
||||
while (count1 < 10) {
|
||||
basic.pause(1000)
|
||||
basic.showNumber(count1, 150)
|
||||
count1 = count1 + 1
|
||||
}
|
||||
while (count1 > 0) {
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
### @video td/videos/digi-yoyo-1-2
|
||||
|
||||
Inside of the while loop, let's add `pause->(1000)` so that we have a pause between each number as it's counting down. Also, let's show `count`!
|
||||
|
||||
```
|
||||
let count2 = 0
|
||||
while (count2 < 10) {
|
||||
basic.pause(1000)
|
||||
basic.showNumber(count2, 150)
|
||||
count2 = count2 + 1
|
||||
}
|
||||
while (count2 > 0) {
|
||||
basic.pause(1000) // ***
|
||||
basic.showNumber(count2, 150) // ***
|
||||
}
|
||||
```
|
||||
|
||||
* Run the code to see if it works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Now, we need `count` to decrease by one after the BBC micro:bit has displayed the value of `count`.
|
||||
|
||||
We can do this by adding this line:
|
||||
|
||||
`count := count - 1`
|
||||
|
34
docs/reference/js/lessons/digi-yoyo/quiz-answers.md
Normal file
34
docs/reference/js/lessons/digi-yoyo/quiz-answers.md
Normal file
@ -0,0 +1,34 @@
|
||||
# digi yoyo quiz answers
|
||||
|
||||
Answers for digi yoyo quiz.
|
||||
|
||||
This is the answer key for the [digi yoyo quiz](/microbit/lessons/digi-yoyo/quiz).
|
||||
|
||||
## 1. Describe what a "while loop" does?
|
||||
|
||||
<br/>
|
||||
|
||||
A loop that repeats code while a condition is true.
|
||||
|
||||
## 2. Write the code that will create a **variable** called `count` and set the variable to 0.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
let count = 0
|
||||
```
|
||||
|
||||
## 3. Create a `while loop` that will loop until the **variable** `count` equals 4.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
while (count < 5) {
|
||||
count = count + 1
|
||||
}
|
||||
```
|
||||
|
28
docs/reference/js/lessons/digi-yoyo/quiz.md
Normal file
28
docs/reference/js/lessons/digi-yoyo/quiz.md
Normal file
@ -0,0 +1,28 @@
|
||||
# digi yoyo quiz
|
||||
|
||||
Create a counter with a while loop
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [digi yoyo tutorial](/microbit/lessons/digi-yoyo/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Describe what a "while loop" does?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the code that will create a variable called count and set the variable to 0.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the code for a while loop that will loop until the variable count equals 4.
|
||||
|
||||

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