2016-03-26 00:47:20 +01:00
|
|
|
# transformers challenges
|
|
|
|
|
|
|
|
Coding challenges for the transformers tutorial. #docs
|
|
|
|
|
|
|
|
## Before we get started
|
|
|
|
|
|
|
|
Complete the following guided tutorial:
|
|
|
|
|
2016-04-13 17:27:45 +02:00
|
|
|
* [tutorial](/lessons/transformers/tutorial)
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
|
|
|
|
|
|
|
```
|
|
|
|
let inital = 5
|
2016-03-30 06:17:57 +02:00
|
|
|
input.onButtonPressed(Button.A, () => {
|
2016-03-26 00:47:20 +01:00
|
|
|
let doubled1 = double(initial)
|
|
|
|
basic.showNumber(doubled1, 150) // ***
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
### Challenge 1
|
|
|
|
|
|
|
|
Create a new function called `square` that returns the square of the number passed into the function.
|
|
|
|
|
|
|
|
(Squaring means that you multiply the number by itself)
|
|
|
|
|
|
|
|
```
|
|
|
|
export function square(n: number) : number {
|
|
|
|
let num: number
|
|
|
|
return n * n
|
|
|
|
return num
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Challenge 2
|
|
|
|
|
|
|
|
Add a condition for when button `B` is pressed. We will use this condition in the last challenge.
|
|
|
|
|
|
|
|
```
|
|
|
|
initial = 5
|
2016-03-30 06:17:57 +02:00
|
|
|
input.onButtonPressed(Button.A, () => {
|
2016-03-26 00:47:20 +01:00
|
|
|
let doubled = double(initial)
|
|
|
|
basic.showNumber(doubled, 150)
|
|
|
|
})
|
2016-03-30 06:17:57 +02:00
|
|
|
input.onButtonPressed(Button.B, () => {
|
2016-03-26 00:47:20 +01:00
|
|
|
}) // ***
|
|
|
|
```
|
|
|
|
|
|
|
|
**Challenge 3**
|
|
|
|
|
|
|
|
When the `B` button is pressed, display the square of the initial value. Use the function `square`. You should get the value 25.
|
|
|
|
|