pxt-calliope/docs/lessons/counter.md

49 lines
1.4 KiB
Markdown

# counter lesson
Learn how to create a counter with with on button pressed.
## Topic
Variables
## Quick Links
* [activity](/lessons/counter/activity)
* [challenges](/lessons/counter/challenges)
* [quiz](/lessons/counter/quiz)
* [quiz answers](/lessons/counter/quiz-answers)
## Prior learning/place of lesson in scheme of work
Learn how to creating a **variable** to keep track of the current count. We will be learning how to create a counter app using a variable as well as simple commands, such as on button pressed, and show number.
## Documentation
```cards
input.compassHeading()
basic.forever(() => {})
let x = 0
if (true) {}
basic.showString("Hello!")
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .
`)
```
* **variable**: [read more...](/blocks/variables)
* **arithmetic operators**: [read more...](/reference/types/number)
* **on button pressed** : [read more...](/reference/input/on-button-pressed)
* **show number** : [read more...](/reference/basic/show-number)
## Objectives
* learn how to create a variable as a place where you can store data so that you can use it later in your code, accessible across all functions, and in nested code blocks
* learn how arithmetic operators operate on numbers and return a number
* learn how to run code when an input button is pressed
* learn how to show a number on the LED screen, one digit at a time (scrolling from left to right)