pxt-calliope/docs/reference/js/lessons/transformers/challenges.md
2016-03-25 16:47:20 -07:00

1.2 KiB

transformers challenges

Coding challenges for the transformers tutorial. #docs

Before we get started

Complete the following guided tutorial:

At the end of the tutorial, click keep editing. Your code should look like this:

let inital = 5
input.onButtonPressed("A", () => {
    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

@video td/videos/transformers-2

Add a condition for when button B is pressed. We will use this condition in the last challenge.

initial = 5
input.onButtonPressed("A", () => {
    let doubled = double(initial)
    basic.showNumber(doubled, 150)
})
input.onButtonPressed("B", () => {
}) // ***

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.