2016-05-26 15:24:10 -07:00
|
|
|
# dice roll quiz answers
|
2016-03-25 16:47:20 -07:00
|
|
|
|
2016-05-26 15:24:10 -07:00
|
|
|
Create a dice when the BBC micro:bit is shaken
|
2016-03-25 16:47:20 -07:00
|
|
|
|
2016-05-26 15:24:10 -07:00
|
|
|
These are the answers to the [dice roll quiz](/lessons/dice-roll/quiz).
|
2016-03-25 16:47:20 -07:00
|
|
|
|
|
|
|
## 1. Create a variable named 'roll' that will be randomly assigned to a number between 0 and 5.
|
|
|
|
|
|
|
|
<br/>
|
|
|
|
|
2016-03-30 13:41:01 -07:00
|
|
|
```blocks
|
2016-03-25 16:47:20 -07:00
|
|
|
let roll = Math.random(6)
|
|
|
|
```
|
|
|
|
|
|
|
|
## 2. If the variable "roll" equals 5, write the code that will plot the image below
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
<br/>
|
|
|
|
|
2016-03-30 13:41:01 -07:00
|
|
|
```blocks
|
|
|
|
let roll = Math.random(6)
|
2016-03-25 16:47:20 -07:00
|
|
|
if (roll == 5) {
|
2016-03-30 13:41:01 -07:00
|
|
|
basic.showLeds(`
|
2016-03-25 16:47:20 -07:00
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
. # . # .
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## 3. You will use an `else if` condition if "roll" is equal 4. Write the `else if` statement that will display the plot image below
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
2016-03-30 13:41:01 -07:00
|
|
|
```blocks
|
|
|
|
|
|
|
|
let roll = Math.random(6)
|
2016-03-25 16:47:20 -07:00
|
|
|
if (roll == 5) {
|
2016-03-30 13:41:01 -07:00
|
|
|
basic.showLeds(`
|
2016-03-25 16:47:20 -07:00
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
. # . # .
|
|
|
|
`)
|
|
|
|
} else if (roll == 4) {
|
2016-03-30 13:41:01 -07:00
|
|
|
basic.showLeds(`
|
2016-03-25 16:47:20 -07:00
|
|
|
. . . . .
|
|
|
|
. # . # .
|
|
|
|
. . # . .
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Note: students are only required to write the bottom half of this answer, starting with "else if".
|
|
|
|
|
|
|
|
## 4. You will use an `else if` condition if "roll" is equal 3. Write the `else if` statement that will display the plot image below
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
2016-03-30 13:41:01 -07:00
|
|
|
```blocks
|
|
|
|
let roll = Math.random(6)
|
2016-03-25 16:47:20 -07:00
|
|
|
if (roll == 4) {
|
2016-03-30 13:41:01 -07:00
|
|
|
basic.showLeds(`
|
2016-03-25 16:47:20 -07:00
|
|
|
. . . . .
|
|
|
|
. # . # .
|
|
|
|
. . # . .
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
`)
|
|
|
|
} else if (roll == 3) {
|
2016-03-30 13:41:01 -07:00
|
|
|
basic.showLeds(`
|
2016-03-25 16:47:20 -07:00
|
|
|
. . . . .
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Note: students are only required to write the bottom half of this answer, starting with "else if".
|
|
|
|
|
|
|
|
## 5. You will use an `else if` condition if "roll" is equal 2. Write the `else if` that will display the image below
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
2016-03-30 13:41:01 -07:00
|
|
|
```blocks
|
|
|
|
let roll = Math.random(6)
|
2016-03-25 16:47:20 -07:00
|
|
|
if (roll == 3) {
|
2016-03-30 13:41:01 -07:00
|
|
|
basic.showLeds(`
|
2016-03-25 16:47:20 -07:00
|
|
|
. . . . .
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
. # . # .
|
|
|
|
. . . . .
|
|
|
|
`)
|
|
|
|
} else if (roll == 2) {
|
2016-03-30 13:41:01 -07:00
|
|
|
basic.showLeds(`
|
2016-03-25 16:47:20 -07:00
|
|
|
# . . . .
|
|
|
|
. . . . .
|
|
|
|
. . # . .
|
|
|
|
. . . . .
|
|
|
|
. . . . #
|
|
|
|
`)
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
Note: students are only required to write the bottom half of this answer, starting with "else if".
|
|
|
|
|