pxt-calliope/docs/projects/coin-flipper.md
Sam El-Husseini 2e9cb3c43b
Fix tutorial authoring for getting started (#885)
* Fix tutorial authoring for getting started

Remove extra new lines

* Fix other tutorials
2018-06-21 16:02:19 -07:00

65 lines
1.4 KiB
Markdown

# Coin Flipper
## Step 1
Place a ``||input:on button pressed||`` block to run code when button **A** is pressed.
```blocks
input.onButtonPressed(Button.A, () => {
})
```
## Step 2
Place a **if** block and check the value returned by the ``||Math:pick random true or false||`` block.
``||Math:pick random true or false||`` returns ``true`` or ``false`` randomly.
```blocks
input.onButtonPressed(Button.A, () => {
if (Math.randomBoolean()) {
} else {
}
});
```
## Step 3
Place a ``||basic:show icon||`` block under the **if** and pick one of the images.
```blocks
input.onButtonPressed(Button.A, () => {
if (Math.randomBoolean()) {
basic.showIcon(IconNames.Skull)
} else {
basic.showIcon(IconNames.Square)
}
});
```
## Step 4
Click ``|Download|`` to transfer your code in your @boardname@ and press button **A** to try it out.
## Step 5
Place multiple ``||basic:show icon||`` blocks before the **if** to create a coin flipping animation.
```blocks
input.onButtonPressed(Button.A, () => {
basic.showIcon(IconNames.Diamond)
basic.showIcon(IconNames.SmallDiamond)
basic.showIcon(IconNames.Diamond)
basic.showIcon(IconNames.SmallDiamond)
if (Math.randomBoolean()) {
basic.showIcon(IconNames.Skull)
} else {
basic.showIcon(IconNames.Square)
}
})
```
## Step 6
Click ``|Download|`` to transfer your code in your @boardname@ and press button **A** to try it out!