2016-03-26 00:47:20 +01:00
# typing game challenges
My script. #docs
**Challenge 0**
2016-04-13 17:27:45 +02:00
This [guided tutorial ](/lessons/typing-game/tutorial ) will teach you how to use the method concat to connect to pieces of text together.
2016-03-26 00:47:20 +01:00
```
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
index = 0
name = ""
2016-03-30 06:17:57 +02:00
input.onButtonPressed(Button.A, () => {
2016-03-26 00:47:20 +01:00
led.showString(alphabet.substr(index, 1), 0)
index = index + 1
})
if (index > 25) {
index = 0
}
2016-03-30 06:17:57 +02:00
input.onButtonPressed(Button.B, () => {
2016-03-26 00:47:20 +01:00
name = name.concat(alphabet.substr(index - 1, 1))
})
input.onGesture(Gesture.Shake, () => {
led.showString(name, 150)
})
```
**Challenge 1**
After you have shown the string in the condition `on shake` , make the name variable hold nothing in it again so people can add a new name after they have shaken it.
```
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
index = 0
name = ""
2016-03-30 06:17:57 +02:00
input.onButtonPressed(Button.A, () => {
2016-03-26 00:47:20 +01:00
led.showString(alphabet.substr(index, 1), 0)
index = index + 1
})
if (index > 25) {
index = 0
}
2016-03-30 06:17:57 +02:00
input.onButtonPressed(Button.B, () => {
2016-03-26 00:47:20 +01:00
name = name.concat(alphabet.substr(index - 1, 1))
})
input.onGesture(Gesture.Shake, () => {
led.showString(name, 150)
name = "" // ** *
})
```
**Challenge 2**
After you have cleared the name variable to hold nothing, make `index := 0` so that when button `A` is pressed, the first letter of the alphabet will be displayed.
```
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
index = 0
name = ""
2016-03-30 06:17:57 +02:00
input.onButtonPressed(Button.A, () => {
2016-03-26 00:47:20 +01:00
led.showString(alphabet.substr(index, 1), 0)
index = index + 1
})
if (index > 25) {
index = 0
}
2016-03-30 06:17:57 +02:00
input.onButtonPressed(Button.B, () => {
2016-03-26 00:47:20 +01:00
name = name.concat(alphabet.substr(index - 1, 1))
})
input.onGesture(Gesture.Shake, () => {
led.showString(name, 150)
name = ""
index = 0 // ** *
})
```
**Challenge 3**
2016-11-02 01:44:37 +01:00
Give Micro a nickname and display it on the @boardname @!
2016-03-26 00:47:20 +01:00