Migrate docs from the other repo
This commit is contained in:
87
docs/reference/js/lessons/spinner/activity.md
Normal file
87
docs/reference/js/lessons/spinner/activity.md
Normal file
@ -0,0 +1,87 @@
|
||||
# spinner activity
|
||||
|
||||
create an arrow that randomly points to a player. #docs
|
||||
|
||||
To create a new script, go to the [Create Code](/microbit/create-code) page and tap *New Project* under **Touch Develop**.
|
||||
|
||||
Let's begin by adding an `input->on shake` condition to know when the BBC micro:bit is shaken.
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
})
|
||||
```
|
||||
|
||||
Now let's randomly generate a number from 0 to 3 so that we can randomly display an arrow in a given direction.
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let randomArrow = Math.random(4)
|
||||
})
|
||||
```
|
||||
|
||||
Now let's handle each of the cases by displaying the appropriate arrow. (Let's display an up arrow if `random arrow` is 0.
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let randomArrow1 = Math.random(4)
|
||||
if (randomArrow1 == 0) {
|
||||
basic.showLeds(`
|
||||
. . # . .
|
||||
. # # # .
|
||||
# # # # #
|
||||
. . # . .
|
||||
. . # . .
|
||||
`, 400)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
Now let's handle the rest of the cases for `random arrow`.
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let randomArrow2 = Math.random(4)
|
||||
if (randomArrow2 == 0) {
|
||||
basic.showLeds(`
|
||||
. . # . .
|
||||
. # # # .
|
||||
# # # # #
|
||||
. . # . .
|
||||
. . # . .
|
||||
`, 400)
|
||||
} else if (randomArrow2 == 1) {
|
||||
basic.showLeds(`
|
||||
. . # . .
|
||||
. . # . .
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`, 400)
|
||||
}
|
||||
else if (randomArrow2 == 2) {
|
||||
basic.showLeds(`
|
||||
. . # . .
|
||||
. . # # .
|
||||
# # # # #
|
||||
. . # # .
|
||||
. . # . .
|
||||
`, 400)
|
||||
}
|
||||
else if (randomArrow2 == 3) {
|
||||
basic.showLeds(`
|
||||
. . # . .
|
||||
. # # . .
|
||||
# # # # #
|
||||
. # # . .
|
||||
. . # . .
|
||||
`, 400)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/microbit/lessons/spinner/challenges)!
|
||||
|
||||
### ~
|
||||
|
156
docs/reference/js/lessons/spinner/challenges.md
Normal file
156
docs/reference/js/lessons/spinner/challenges.md
Normal file
@ -0,0 +1,156 @@
|
||||
# spinner challenges
|
||||
|
||||
create an arrow that randomly points to a player. #docs
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/microbit/lessons/spinner/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let randomArrow = Math.random(4)
|
||||
if (randomArrow == 0) {
|
||||
basic.plotImage(`
|
||||
. . # . .
|
||||
. # # # .
|
||||
# # # # #
|
||||
. . # . .
|
||||
. . # . .
|
||||
`)
|
||||
}
|
||||
if (randomArrow == 1) {
|
||||
basic.plotImage(`
|
||||
. . # . .
|
||||
. . # . .
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`)
|
||||
}
|
||||
if (randomArrow == 2) {
|
||||
basic.plotImage(`
|
||||
. . # . .
|
||||
. . # # .
|
||||
# # # # #
|
||||
. . # # .
|
||||
. . # . .
|
||||
`)
|
||||
}
|
||||
if (randomArrow == 3) {
|
||||
basic.plotImage(`
|
||||
. . # . .
|
||||
. # # . .
|
||||
# # # # #
|
||||
. # # . .
|
||||
. . # . .
|
||||
`)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Modify the random number generator so that it can include new arrows we will create in the next challenge.
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let randomArrow1 = Math.random(8) // ***
|
||||
// **. . .**
|
||||
if (randomArrow1 == 4) {
|
||||
basic.plotImage(`
|
||||
# # # # .
|
||||
# # # . .
|
||||
# # # . .
|
||||
# . . # .
|
||||
. . . . #
|
||||
`)
|
||||
}
|
||||
if (randomArrow1 == 5) {
|
||||
basic.plotImage(`
|
||||
. # # # #
|
||||
. . # # #
|
||||
. . # # #
|
||||
. # . # #
|
||||
# . . . .
|
||||
`)
|
||||
}
|
||||
if (randomArrow1 == 6) {
|
||||
basic.plotImage(`
|
||||
# . . . .
|
||||
. # . . #
|
||||
. . # # #
|
||||
. . # # #
|
||||
. # # # #
|
||||
`)
|
||||
}
|
||||
if (randomArrow1 == 7) {
|
||||
basic.plotImage(`
|
||||
. . . . #
|
||||
# . . # .
|
||||
# # # . .
|
||||
# # # . .
|
||||
# # # # .
|
||||
`)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
* Do **not** run the code yet because it will not work until you have conditions for every random number.
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Let's add four more arrows that point diagonally.
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let randomArrow2 = Math.random(4)
|
||||
// **. . .**
|
||||
if (randomArrow2 == 4) {
|
||||
basic.plotImage(`
|
||||
# # # # .
|
||||
# # # . .
|
||||
# # # . .
|
||||
# . . # .
|
||||
. . . . #
|
||||
`) // ***
|
||||
}
|
||||
if (randomArrow2 == 5) {
|
||||
basic.plotImage(`
|
||||
. # # # #
|
||||
. . # # #
|
||||
. . # # #
|
||||
. # . # #
|
||||
# . . . .
|
||||
`) // ***
|
||||
}
|
||||
if (randomArrow2 == 6) {
|
||||
basic.plotImage(`
|
||||
# . . . .
|
||||
. # . . #
|
||||
. . # # #
|
||||
. . # # #
|
||||
. # # # #
|
||||
`) // ***
|
||||
}
|
||||
if (randomArrow2 == 7) {
|
||||
basic.plotImage(`
|
||||
. . . . #
|
||||
# . . # .
|
||||
# # # . .
|
||||
# # # . .
|
||||
# # # # .
|
||||
`) // ***
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
* Run your code to see if it works as expected
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Add some other arrows if there are more than 8 players.
|
||||
|
56
docs/reference/js/lessons/spinner/quiz-answers.md
Normal file
56
docs/reference/js/lessons/spinner/quiz-answers.md
Normal file
@ -0,0 +1,56 @@
|
||||
# spinner quiz answers
|
||||
|
||||
a spin the BBC micro:bit game with the input on shake #math #random #docs #shake
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [spinner tutorial](/microbit/lessons/spinner/tutorial).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the code that stores a random number between 0 and 3 into a local variable named 'random arrow'.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
let randomArrow = Math.random(4)
|
||||
```
|
||||
|
||||
## 2. Write the if statement that will display this down arrow from your code. Hint- This occurs if the local variable 'random arrow' returns 1.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
if (randomArrow == 1) {
|
||||
basic.plotImage(`
|
||||
. . # . .
|
||||
. . # . .
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`)
|
||||
}
|
||||
```
|
||||
|
||||
## 3. Write the if statement that will display this right arrow. Hint- This occurs if the local variable 'random arrow' returns 2.
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
if (randomArrow == 2) {
|
||||
basic.plotImage(`
|
||||
. . # . .
|
||||
. . # # .
|
||||
# # # # #
|
||||
. . # # .
|
||||
. . # . .
|
||||
`)
|
||||
}
|
||||
```
|
||||
|
28
docs/reference/js/lessons/spinner/quiz.md
Normal file
28
docs/reference/js/lessons/spinner/quiz.md
Normal file
@ -0,0 +1,28 @@
|
||||
# spinner quiz
|
||||
|
||||
a spin the BBC micro:bit game with the input on shake #math #random #docs #shake
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [spinner tutorial](/microbit/lessons/spinner/tutorial).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the code that stores a random number between 0 and 3 into a local variable named 'random arrow'.
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the if statement that will display this down arrow from your code. Hint- This occurs if the local variable 'random arrow' returns 1.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the if statement that will display this right arrow. Hint- This occurs if the local variable 'random arrow' returns 2.
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
Reference in New Issue
Block a user