batch replace onButtonPressed(Button...
This commit is contained in:
@ -15,14 +15,14 @@ To create a new script, go to the [Create Code](/microbit/create-code) page and
|
||||
Add an event handler when button `A` is pressed.
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
})
|
||||
```
|
||||
|
||||
Create a local variable of type number `x` and set it to a random number using `math->random`. `math->random(10)` generates a random number between `0` and `10` **excluded**.
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.random(10)
|
||||
})
|
||||
```
|
||||
@ -30,7 +30,7 @@ input.onButtonPressed("A", () => {
|
||||
Show the random number on the screen.
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x1 = Math.random(10)
|
||||
basic.showNumber(x1, 150)
|
||||
})
|
||||
|
@ -11,7 +11,7 @@ Complete the following guided tutorial:
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x = Math.random(10)
|
||||
basic.showNumber(x, 150)
|
||||
})
|
||||
@ -24,11 +24,11 @@ input.onButtonPressed("A", () => {
|
||||
When button `B` is pressed, we want to clear the screen. This will make it so users can play your game over and over again! Add an event handler to handle this case.
|
||||
|
||||
```
|
||||
input.onButtonPressed("A", () => {
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let x1 = Math.random(10)
|
||||
basic.showNumber(x1, 150)
|
||||
})
|
||||
input.onButtonPressed("B", () => {
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
basic.clearScreen() // ***
|
||||
})
|
||||
```
|
||||
|
Reference in New Issue
Block a user