94 lines
1.5 KiB
Markdown
Raw Normal View History

2016-03-25 16:47:20 -07:00
# smiley blocks challenges
Coding challenges for the smiley.
## Before we get started
2016-04-13 08:27:45 -07:00
Complete the [smiley activity](/lessons/smiley/activity) and your code will look like this:
2016-03-25 16:47:20 -07:00
```blocks
2016-03-30 15:11:05 -07:00
basic.showLeds(`
2016-03-25 16:47:20 -07:00
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
`)
2016-03-30 15:11:05 -07:00
basic.showLeds(`
2016-03-25 16:47:20 -07: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-30 15:11:05 -07:00
basic.showLeds(`
2016-03-25 16:47:20 -07:00
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
`)
2016-03-30 15:11:05 -07:00
basic.showLeds(`
2016-03-25 16:47:20 -07:00
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`)
input.onButtonPressed(Button.A, () => {
})
```
### Challenge 2
2016-05-26 15:24:10 -07:00
2016-03-25 16:47:20 -07:00
Now, we want to show a frowny face when this button is pressed. Let's show the LEDs.
```blocks
2016-03-30 15:11:05 -07:00
basic.showLeds(`
2016-03-25 16:47:20 -07:00
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
`)
2016-03-30 15:11:05 -07:00
basic.showLeds(`
2016-03-25 16:47:20 -07:00
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
`)
input.onButtonPressed(Button.A, () => {
2016-03-30 15:11:05 -07:00
basic.showLeds(`
2016-03-25 16:47:20 -07: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.