pxt-calliope/olddocs/lessons/smiley/challenges.md

94 lines
1.5 KiB
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# smiley blocks challenges
Coding challenges for the smiley.
## Before we get started
2016-04-13 17:27:45 +02:00
Complete the [smiley activity](/lessons/smiley/activity) and your code will look like this:
2016-03-26 00:47:20 +01:00
```blocks
2016-03-31 00:11:05 +02:00
basic.showLeds(`
2016-03-26 00:47:20 +01:00
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
`)
2016-03-31 00:11:05 +02:00
basic.showLeds(`
2016-03-26 00:47:20 +01:00
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`)
```
### Challenge 1
What if we want to make the face to frown on button pressed A?
Let's make add code that will run when button A is pressed!
```blocks
2016-03-31 00:11:05 +02:00
basic.showLeds(`
2016-03-26 00:47:20 +01:00
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
`)
2016-03-31 00:11:05 +02:00
basic.showLeds(`
2016-03-26 00:47:20 +01:00
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`)
input.onButtonPressed(Button.A, () => {
})
```
### Challenge 2
2016-05-27 00:24:10 +02:00
2016-03-26 00:47:20 +01:00
Now, we want to show a frowny face when this button is pressed. Let's show the LEDs.
```blocks
2016-03-31 00:11:05 +02:00
basic.showLeds(`
2016-03-26 00:47:20 +01:00
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
`)
2016-03-31 00:11:05 +02:00
basic.showLeds(`
2016-03-26 00:47:20 +01:00
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`)
input.onButtonPressed(Button.A, () => {
2016-03-31 00:11:05 +02:00
basic.showLeds(`
2016-03-26 00:47:20 +01:00
. # . # .
. # . # .
. . . . .
. # # # .
# . . . #
`)
})
```
* Run your code to see if it works as expected.
### Challenge 3
When *button B* is pressed, let's change the sad face back to a happy face. To do this, begin by adding a condition for `on button pressed` *B*. Next, show LEDs as a smiley face inside the condition.