2016-03-26 00:47:20 +01:00
# jailbreak challenges
Coding challenges for the jailbreak tutorial.#docs
## Before we get started
Complete the following guided tutorial:
2016-04-13 17:27:45 +02:00
* [tutorial ](/lessons/jailbreak/tutorial )
2016-03-26 00:47:20 +01:00
At the end of the tutorial, click `keep editing` . Your code should look like this:
```
count = 0
shouldBreak = false
2016-03-30 06:17:57 +02:00
input.onButtonPressed(Button.A, () => {
2016-03-26 00:47:20 +01:00
shouldBreak = true
})
while (true) {
if (shouldBreak) {
basic.showString("I'M OUT!", 150)
basic.plotImage(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
`)
break
}
count = count + 1
basic.showNumber(count, 150)
basic.pause(1000)
}
```
**Challenge 1**
Try to remove the `break` in the `if` loop. What problem does this create?
**Challenge 2**
Now let's resume the timer again once button `B` is pressed! To do so, begin by creating a condition to know when button `B` is pressed.
```
// ** . . .**
while (true) {
if (shouldBreak) {
basic.showString("I'M OUT!", 150)
basic.plotImage(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
`)
break
}
count = count + 1
basic.showNumber(count, 150)
basic.pause(1000)
}
2016-03-30 06:17:57 +02:00
input.onButtonPressed(Button.B, () => {
2016-03-26 00:47:20 +01:00
}) // ** *
```
Next, set `should break` back to false to indicate we want to run the `while` loop again.
```
// ** . . .**
2016-03-30 06:17:57 +02:00
input.onButtonPressed(Button.B, () => {
2016-03-26 00:47:20 +01:00
shouldBreak = false // ** *
})
```
And now copy the code from the previous while loop into the condition of `input->on button pressed("B")` . This will resume the counter.
```
// ** . . .**
2016-03-30 06:17:57 +02:00
input.onButtonPressed(Button.B, () => {
2016-03-26 00:47:20 +01:00
shouldBreak = false
while (true) {
if (shouldBreak) {
basic.showString("I'M OUT!", 150) // ** *
basic.plotImage(`
. # . # .
. # . # .
. . . . .
# . . . #
. # # # .
`) // ** *
break // ** *
}
count = count + 1 // ** *
basic.showNumber(count, 150) // ** *
basic.pause(1000) // ** *
}
})
```
**Challenge 3**
Notice that the two `while` loops are identical. Clean up this redundancy in your code by creating another method and then placing the `while` loop in the method.