pxt-calliope/docs/lessons/magic-8/quiz-answers.md

61 lines
1.4 KiB
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# magic 8 quiz answers
2016-04-02 01:22:47 +02:00
create a magic 8 ball on the BBC micro:bit.
2016-03-26 00:47:20 +01:00
## Name
## Directions
2016-04-16 00:02:26 +02:00
Use this activity document to guide your work in the [magic 8 activity](/lessons/magic-8/activity).
2016-03-26 00:47:20 +01:00
Answer the questions while completing the tutorial. Pay attention to the dialogues!
## 1. Define what an 'if statement' is.
<br />
An if statement will conditionally run code depending on whether or not a condition is true.
## 2. Create a Variable called ``x`` and assign it to a random number between 0 and 2.
2016-03-30 22:41:01 +02:00
```blocks
2016-03-26 00:47:20 +01:00
let x = Math.random(3)
```
## 3. Write the 'if statement' to check if ``x`` is equal to 2. Inside the 'if statement', display the string "Yes".
2016-03-30 22:41:01 +02:00
```blocks
2016-03-31 00:54:19 +02:00
let x = Math.random(3)
2016-03-26 00:47:20 +01:00
if (x == 2) {
basic.showString("Yes", 150)
}
```
2016-03-31 00:54:19 +02:00
## 4. Write the 'if statement' to check if ``x`` is equal to 1. Inside the 'if statement', display the string "No."
2016-03-26 00:47:20 +01:00
2016-03-30 22:41:01 +02:00
```blocks
let x = Math.random(3)
2016-03-26 00:47:20 +01:00
if (x == 2) {
basic.showString("Yes", 150)
} else if (x == 1) {
basic.showString("No", 150)
}
```
## 5. Write the code to display the string "I don't know" if the Variable ``x`` is neither 2 nor 1.
2016-03-30 22:41:01 +02:00
```blocks
let x = Math.random(3)
2016-03-26 00:47:20 +01:00
if (x == 2) {
basic.showString("Yes", 150)
} else if (x == 1) {
basic.showString("No", 150)
}
else {
basic.showString("I don't know", 150)
}
```
Note: Students are only required to write the bottom half of this answer (starting with "else").