pxt-calliope/docs/lessons/catch-the-egg-game/quiz-answers.md

59 lines
1.3 KiB
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# catch the egg game quiz answers
Programming a game of catch the egg using the accelerometer
## Name
## Directions
2016-04-13 17:27:45 +02:00
Use this activity document to guide your work in the [catch the egg tutorial](/lessons/catch-the-egg-game/tutorial)
2016-03-26 00:47:20 +01:00
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Write the data type for the global variables 'basket' and 'egg'.
<br/>
'Basket' and 'egg' are stored as **Number**.
## 2. Write the code to plot the initial position of the egg and the basket using the variables 'egg x', 'egg y', and 'basket x'. The code should arrange the egg and basket as shown below.
![](/static/mb/lessons/catch-the-egg-game-0.png)
<br/>
2016-03-31 00:11:05 +02:00
```blocks
let basketX = 2
let eggX = 2
let eggY = 0
2016-03-26 00:47:20 +01:00
led.plot(eggX, eggY)
led.plot(basketX, 4)
```
## 3. Write the three lines of code that moves the egg down. (You need to unplot the egg's current position, update its position variables, and plot its new position.
<br/>
2016-03-31 00:11:05 +02:00
```blocks
let basketX = 2
let eggX = 2
let eggY = 0
2016-03-26 00:47:20 +01:00
led.unplot(eggX, eggY)
eggY = eggY + 1
led.plot(eggX, eggY)
```
2016-03-31 00:11:05 +02:00
## 4. . Write the code that resets the egg after it has fallen past the bottom of the BBC micro:bit.
2016-03-26 00:47:20 +01:00
<br/>
2016-03-31 00:11:05 +02:00
```blocks
let eggX = 2
let eggY = 0
2016-03-26 00:47:20 +01:00
if (eggY > 4) {
eggY = -1
eggX = Math.random(5)
}
```