2016-03-26 00:47:20 +01:00
|
|
|
# digi yoyo challenges
|
|
|
|
|
|
|
|
Coding challenges for the digi yoyo.
|
|
|
|
|
|
|
|
## Before we get started
|
|
|
|
|
2016-04-13 17:27:45 +02:00
|
|
|
Complete the following [guided tutorial](/lessons/digi-yoyo/activity), your code should look like this:
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
let count = 0;
|
|
|
|
while (count < 10) {
|
|
|
|
basic.pause(100);
|
|
|
|
basic.showNumber(count);
|
|
|
|
count = count + 1;
|
|
|
|
basic.pause(20);
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Challenge 1
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
let count = 0;
|
|
|
|
while (count < 10) {
|
|
|
|
basic.pause(100);
|
|
|
|
basic.showNumber(count);
|
|
|
|
count = count + 1;
|
|
|
|
basic.pause(20);
|
|
|
|
}
|
|
|
|
while (count > 0) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Challenge 2
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
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`!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
let count = 0;
|
|
|
|
while (count < 10) {
|
|
|
|
basic.pause(100);
|
|
|
|
basic.showNumber(count);
|
|
|
|
count = count + 1;
|
|
|
|
}
|
|
|
|
while (count > 0) {
|
|
|
|
basic.pause(100);
|
|
|
|
basic.showNumber(count);
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
* Run the code to see if it works as expected.
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Challenge 3
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-11-02 01:44:37 +01:00
|
|
|
Now, we need `count` to decrease by one after the @boardname@ has displayed the value of `count`.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
We can do this by adding this line:
|
|
|
|
|
|
|
|
```blocks
|
2016-03-31 00:54:19 +02:00
|
|
|
let count = 0;
|
|
|
|
count = count + (count - 1);
|
|
|
|
|
2016-03-26 00:47:20 +01:00
|
|
|
```
|