move lessons out of web site
will move select lessons back to "educators" section
This commit is contained in:
122
olddocs/lessons/magic-8/activity.md
Normal file
122
olddocs/lessons/magic-8/activity.md
Normal file
@ -0,0 +1,122 @@
|
||||
# magic 8 activity
|
||||
|
||||
Welcome! This activity will help you create a magic 8 ball on the micro:bit. Let's get started!
|
||||
|
||||
Show a string to instruct the user how to play Magic 8! The magic 8 ball can only answer true or false questions.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.showString("ASK A QUESTION")
|
||||
```
|
||||
|
||||
Display the number 8.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.showString("ASK A QUESTION")
|
||||
basic.showNumber(8)
|
||||
```
|
||||
|
||||
Create a condition for when the micro:bit is shaken. Then use the block `clear screen` to clear the 8 from the display.
|
||||
|
||||
```blocks
|
||||
basic.showString("ASK A QUESTION")
|
||||
basic.showNumber(8)
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.clearScreen()
|
||||
});
|
||||
```
|
||||
|
||||
Create a variable of type number called **randomNumber**. Set **randomNumber** to a random number with a limit of 2. Remember the random function in the math library, picks a random number from 0 to the limit, but not including the limit unless it is 0.
|
||||
|
||||
```blocks
|
||||
basic.showString("ASK A QUESTION")
|
||||
basic.showNumber(8)
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.clearScreen()
|
||||
let randomNumber = Math.random(3)
|
||||
|
||||
});
|
||||
```
|
||||
|
||||
Create an if statement for the condition `if randomNumber = 2`. If **randomNumber** is 2, display the string 'Yes'
|
||||
|
||||
|
||||
```blocks
|
||||
basic.showString("ASK A QUESTION")
|
||||
basic.showNumber(8)
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.clearScreen();
|
||||
let randomNumber = Math.random(3);
|
||||
if (randomNumber == 2) {
|
||||
basic.showString("YES");
|
||||
}
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
|
||||
Create an if statement for the condition `if randomNumber = 1`. If randomNumber is 1, display the string 'No'
|
||||
|
||||
```blocks
|
||||
basic.showString("ASK A QUESTION")
|
||||
basic.showNumber(8)
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.clearScreen()
|
||||
let randomNumber = Math.random(3)
|
||||
if (randomNumber == 2) {
|
||||
basic.showString("YES")
|
||||
} else if (randomNumber == 1) {
|
||||
basic.showString("NO")
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
If **randomNumber** is not 2 or 1, it must be 0. This is the else condition. If **randomNumber** is 0, display the string 'I don't know'
|
||||
|
||||
```blocks
|
||||
basic.showString("ASK A QUESTION")
|
||||
basic.showNumber(8)
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.clearScreen()
|
||||
let randomNumber = Math.random(3)
|
||||
if (randomNumber == 2) {
|
||||
basic.showString("YES")
|
||||
} else if (randomNumber == 1) {
|
||||
basic.showString("NO")
|
||||
} else {
|
||||
basic.showString("I DON'T KNOW")
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
Display the number 8 so users know they can ask the magic 8 ball another question!
|
||||
|
||||
|
||||
```blocks
|
||||
basic.showString("ASK A QUESTION")
|
||||
basic.showNumber(8)
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.clearScreen()
|
||||
let randomNumber = Math.random(3)
|
||||
if (randomNumber == 2) {
|
||||
basic.showString("YES")
|
||||
} else if (randomNumber == 1) {
|
||||
basic.showString("NO")
|
||||
} else {
|
||||
basic.showString("I DON'T KNOW")
|
||||
}
|
||||
basic.showNumber(8)
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/magic-8/challenges)!
|
||||
|
||||
### ~
|
||||
|
105
olddocs/lessons/magic-8/challenges.md
Normal file
105
olddocs/lessons/magic-8/challenges.md
Normal file
@ -0,0 +1,105 @@
|
||||
# magic 8 challenges
|
||||
|
||||
Coding challenges for the magic 8 tutorial
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following [guided tutorial](/lessons/magic-8/activity), and your code should look like this:
|
||||
|
||||
```blocks
|
||||
basic.showString("ASK A QUESTION")
|
||||
basic.showNumber(8)
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.clearScreen()
|
||||
let randomNumber = Math.random(2)
|
||||
if (randomNumber == 2) {
|
||||
basic.showString("YES")
|
||||
} else if (randomNumber == 1) {
|
||||
basic.showString("NO")
|
||||
} else {
|
||||
basic.showString("I DON'T KNOW")
|
||||
|
||||
}
|
||||
basic.showNumber(8)
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Now let's increase the number of responses the magic 8 ball can give. How about 5 responses instead? Let's change the limit of `pick random` to 4.
|
||||
|
||||
```blocks
|
||||
basic.showString("ASK A QUESTION")
|
||||
basic.showNumber(8)
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.clearScreen()
|
||||
let randomNumber = Math.random(4)
|
||||
if (randomNumber == 2) {
|
||||
basic.showString("YES")
|
||||
} else if (randomNumber == 1) {
|
||||
basic.showString("NO")
|
||||
} else {
|
||||
basic.showString("I DON'T KNOW")
|
||||
|
||||
}
|
||||
basic.showNumber(8)
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Now have the magic 8 ball respond "Try again" if **randomNumber** is 3.
|
||||
|
||||
|
||||
```blocks
|
||||
basic.showString("ASK A QUESTION")
|
||||
basic.showNumber(8)
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.clearScreen()
|
||||
let randomNumber = Math.random(4)
|
||||
if (randomNumber == 3) {
|
||||
basic.showString("TRY AGAIN")
|
||||
} else if (randomNumber == 2) {
|
||||
basic.showString("YES")
|
||||
} else if (randomNumber == 1) {
|
||||
basic.showString("NO")
|
||||
} else {
|
||||
basic.showString("I DON'T KNOW")
|
||||
}
|
||||
basic.showNumber(8)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Now what about if **randomNumber** is 4? Let's have the magic 8 ball respond "Definitely!".
|
||||
|
||||
```blocks
|
||||
basic.showString("ASK A QUESTION")
|
||||
basic.showNumber(8)
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.clearScreen()
|
||||
let randomNumber = Math.random(4)
|
||||
if (randomNumber == 4) {
|
||||
basic.showString("DEFINATELY")
|
||||
} else if (randomNumber == 3) {
|
||||
basic.showString("TRY AGAIN")
|
||||
} else if (randomNumber == 2) {
|
||||
basic.showString("YES")
|
||||
} else if (randomNumber == 1) {
|
||||
basic.showString("NO")
|
||||
}
|
||||
else {
|
||||
basic.showString("I DON'T KNOW")
|
||||
}
|
||||
basic.showNumber(8)
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 4**
|
||||
|
||||
Add 3 more responses so your magic 8 ball has 8 possible responses. Be creative!
|
||||
|
60
olddocs/lessons/magic-8/quiz-answers.md
Normal file
60
olddocs/lessons/magic-8/quiz-answers.md
Normal file
@ -0,0 +1,60 @@
|
||||
# magic 8 quiz answers
|
||||
|
||||
create a magic 8 ball on the BBC micro:bit.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [magic 8 activity](/lessons/magic-8/activity).
|
||||
|
||||
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.
|
||||
|
||||
```blocks
|
||||
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".
|
||||
|
||||
```blocks
|
||||
let x = Math.random(3)
|
||||
if (x == 2) {
|
||||
basic.showString("Yes", 150)
|
||||
}
|
||||
```
|
||||
|
||||
## 4. Write the 'if statement' to check if ``x`` is equal to 1. Inside the 'if statement', display the string "No."
|
||||
|
||||
```blocks
|
||||
let x = Math.random(3)
|
||||
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.
|
||||
|
||||
```blocks
|
||||
let x = Math.random(3)
|
||||
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").
|
||||
|
32
olddocs/lessons/magic-8/quiz.md
Normal file
32
olddocs/lessons/magic-8/quiz.md
Normal file
@ -0,0 +1,32 @@
|
||||
# magic 8 quiz
|
||||
|
||||
create a magic 8 ball on the BBC micro:bit.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [magic 8 tutorial](/lessons/magic-8/activity).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Define what an 'if statement' is.
|
||||
|
||||
<br />
|
||||
|
||||
## 2. Create a Variable called ``x`` and assign it to a random number between 0 and 2.
|
||||
|
||||
<br />
|
||||
|
||||
## 3. Write the 'if statement' to check if ``x`` is equal to 2. Inside the 'if statement', display the string "Yes".
|
||||
|
||||
<br />
|
||||
|
||||
## 4. Write the 'if statement' to check if ``x`` is equal to 1. Inside the 'if statement', display the string "No."
|
||||
|
||||
<br />
|
||||
|
||||
## 5. Write the code to display the string "I don't know" if the Variable ``x`` is neither 2 nor 1.
|
||||
|
||||
<br />
|
||||
|
27
olddocs/lessons/magic-8/tutorial.md
Normal file
27
olddocs/lessons/magic-8/tutorial.md
Normal file
@ -0,0 +1,27 @@
|
||||
# Magic 8 tutorial
|
||||
|
||||
Show a string to instruct the user how to play Magic 8! The magic 8 ball can only answer questions with "YES", "NO", or "MAYBE"...
|
||||
|
||||
### Rebuild the game!
|
||||
|
||||
The blocks have been shuffled! Put them back together so that...
|
||||
* show "ASK A QUESTION" on the screen
|
||||
* when the micro:bit is shaken,
|
||||
* generate a random number between 0 and 2.
|
||||
* if the number is `2`, show "YES"
|
||||
* if the number is `1`, show "NO"
|
||||
* otherwise show "MAYBE"...
|
||||
|
||||
```shuffle
|
||||
basic.showString("ASK A QUESTION")
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let randomNumber = Math.random(3)
|
||||
if (randomNumber == 2) {
|
||||
basic.showString("YES")
|
||||
} else if (randomNumber == 1) {
|
||||
basic.showString("NO")
|
||||
} else {
|
||||
basic.showString("MAYBE")
|
||||
}
|
||||
})
|
||||
```
|
Reference in New Issue
Block a user