# 课程F-变量1-变量和计数器

• 年龄 10+
• 90 分钟
• MakeCode Editor

## 课堂活动

• 1块micro:bit
• 1根USB线
• 1个AAA电池组（可选）
• 2节AAA电池（可选）

### 编写文本

``````
basic.showNumber(1 - 1)
basic.showNumber(1 + 1)
basic.showNumber(1 * 1)
basic.showNumber(1 / 1)
``````

### 数学运算符

``````
input.onButtonPressed(Button.A, () => {

})

``````

### 当按钮被按下

``````
basic.showNumber(0)
``````

### showNumber

``````
let item = 0
item = 0
``````

4个步骤

## 指导练习

``````
let count = 0
input.onButtonPressed(Button.A, () => {
count = count + 1
basic.showNumber(count)
})
input.onButtonPressed(Button.B, () => {
count = count - 1
basic.showNumber(count)
})
input.onButtonPressed(Button.AB, () => {

})
count = 0
``````

## 挑战

### 挑战1

``````
let count = 0
input.onButtonPressed(Button.A, () => {
count = count + 1
basic.showNumber(count)
})
input.onButtonPressed(Button.B, () => {
count = count - 1
basic.showNumber(count)
})
input.onButtonPressed(Button.AB, () => {

})
count = 0
``````

### 挑战2

``````
let count = 0
input.onButtonPressed(Button.A, () => {
basic.showNumber(count)
})
input.onButtonPressed(Button.B, () => {
basic.showNumber(count)
})
input.onButtonPressed(Button.AB, () => {

})
count = 0
``````

### 挑战3

``````
let count = 0
input.onButtonPressed(Button.A, () => {
basic.showNumber(count)
})
input.onButtonPressed(Button.B, () => {
basic.showNumber(count)
})
input.onButtonPressed(Button.AB, () => {
count = 0
basic.showNumber(count)
})
count = 0
``````

## 问答

``````let count = 0
input.onButtonPressed(Button.A, () => {
count = count + 1
basic.showNumber(count)
})
input.onButtonPressed(Button.B, () => {
count = count - 1
basic.showNumber(count)
})
input.onButtonPressed(Button.AB, () => {

})
count = 0
``````