# 课程F-变量2-变量和情感

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

## 课堂活动

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

### 编写文本

basic.forever(() => {})

### forever

for(let i = 0; i < 5; ++i) {
basic.showNumber(i)
}

### for

basic.showString("Hello!")

### showString

basic.showNumber(0)

let item = 0
item = 0

### setItem

function doSomething()  {
basic.showString("Hello!")
}

doSomething()

4个步骤

## 指导练习

let Result = ""
let What_to_give = ""
let Morning_Mood = ""
function How_Does_Baby_Brother_Feel_Now()  {
basic.showString(Morning_Mood)
for (let i = 0; i < 3; i++) {
basic.showLeds(`
. . # . .
. . # . .
# # # # #
. . # . .
. . # . .
`)
basic.clearScreen()
basic.pause(250)
}
basic.showString(What_to_give)
for (let i = 0; i < 5; i++) {
basic.showLeds(`
. . . . .
. # # # .
. . . . .
. # # # .
. . . . .
`)
basic.clearScreen()
basic.pause(100)
}
if (Result == "Happy") {
basic.showIcon(IconNames.Happy)
} else if (Result == "Sad") {
} else if (Result == "Confused") {
basic.showIcon(IconNames.Confused)
} else if (Result == "Angry") {
basic.showIcon(IconNames.Angry)
} else {
basic.showIcon(IconNames.Meh)
}
}
basic.forever(() => {
What_to_give = "Toy"
Result = "Happy"
How_Does_Baby_Brother_Feel_Now()
})

## 变量和情感挑战

### 挑战1

let Result = ""
let What_to_give = ""
let Morning_Mood = ""
function How_Does_Baby_Brother_Feel_Now()  {
basic.showString(Morning_Mood)
for (let i = 0; i < 3; i++) {
basic.showLeds(`
. . # . .
. . # . .
# # # # #
. . # . .
. . # . .
`)
basic.clearScreen()
basic.pause(250)
}
basic.showString(What_to_give)
for (let i = 0; i < 5; i++) {
basic.showLeds(`
. . . . .
. # # # .
. . . . .
. # # # .
. . . . .
`)
basic.clearScreen()
basic.pause(100)
}
if (Result == "Happy") {
basic.showIcon(IconNames.Happy)
} else if (Result == "Sad") {
} else if (Result == "Confused") {
basic.showIcon(IconNames.Confused)
} else if (Result == "Angry") {
basic.showIcon(IconNames.Angry)
} else {
basic.showIcon(IconNames.Meh)
}
}
basic.forever(() => {
Morning_Mood = "Hungry"
What_to_give = "Bottle"
Result = "Full"
How_Does_Baby_Brother_Feel_Now()
})

### 挑战2

let Result = ""
let Activity_to_do = ""
let Night_Mood = ""
function How_Does_Baby_Brother_Feel_Now()  {
basic.showString(Night_Mood)
for (let i = 0; i < 3; i++) {
basic.showLeds(`
. . # . .
. . # . .
# # # # #
. . # . .
. . # . .
`)
basic.clearScreen()
basic.pause(250)
}
basic.showString(Activity_to_do)
for (let i = 0; i < 5; i++) {
basic.showLeds(`
. . . . .
. # # # .
. . . . .
. # # # .
. . . . .
`)
basic.clearScreen()
basic.pause(100)
}
if (Result == "Happy") {
basic.showIcon(IconNames.Happy)
} else if (Result == "Sad") {
} else if (Result == "Confused") {
basic.showIcon(IconNames.Confused)
} else if (Result == "Angry") {
basic.showIcon(IconNames.Angry)
} else {
basic.showIcon(IconNames.Meh)
}
}
basic.forever(() => {
Night_Mood = "Bored"
Activity_to_do = "Play Ball"
How_Does_Baby_Brother_Feel_Now()
})

### 挑战3

let Result = ""
let Activity_to_do = ""
let Night_Mood = ""

basic.forever(() => {
Night_Mood = "Bored"
Activity_to_do = "Play Ball"
basic.showString("" + Night_Mood + Activity_to_do + Result)
})

## 问答

### 问题 3

set variable to "yes"
set variable to "no"
set variable to "maybe"
set variable to "oh... ok!"

show string variable