moving out outdated js docs
This commit is contained in:
103
olddocs/js/lessons/2-player-pong.md
Normal file
103
olddocs/js/lessons/2-player-pong.md
Normal file
@ -0,0 +1,103 @@
|
||||
# 2 player pong lesson
|
||||
|
||||
make a game to test your focus on the moving ball.
|
||||
|
||||
## Topic
|
||||
|
||||
Functions
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [tutorial](/lessons/2-player-pong/tutorial)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to create **functions**, `function()` as a unit of code that performs a specific task and returns a result. We will be learning how to create the hat game app using functions, global variables, input on button pressed, if (conditionals), mod, random, Boolean, as well as simple commands such as show animation.
|
||||
|
||||
## What the teacher needs to know/QuickStart Computing Glossary
|
||||
|
||||
* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective.
|
||||
* Command: An instruction for the computer to execute, written in a particular programming language.
|
||||
* Data: A structured set of numbers, possibly representing digitised text, images, sound or video, which can be processed or transmitted by a computer, also used for numerical (quantitative) information.
|
||||
* Hardware: The physical systems and components of digital devices; see also software.
|
||||
* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors.
|
||||
* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program.
|
||||
* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.
|
||||
* Repetition: Executing a section of computer code a number of times as part of the program.
|
||||
* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character.
|
||||
* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met.
|
||||
* Sequence: To place program instructions in order, with each executed one after the other.
|
||||
* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games.
|
||||
* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the user’s name.
|
||||
|
||||
## Documentation
|
||||
|
||||
* **functions** : [read more...](/js/function)
|
||||
* **on button pressed** : [read more...](/reference/input/on-button-pressed)
|
||||
* **for** : [read more...](/reference/loops/for)
|
||||
* **if** : [read more...](/reference/logic/if)
|
||||
* **show animation** : [read more...](/reference/basic/show-animation)
|
||||
|
||||
## Resources
|
||||
|
||||
* Activity: [tutorial](/lessons/2-player-pong/tutorial)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks
|
||||
* learn how to learn how to conditionally run code depending on whether a condition is true or no
|
||||
* learn how to show a series of image frames on the LED screen
|
||||
* learn how to run code when an input button is pressed
|
||||
|
||||
## Links to the National Curriculum Programmes of Study for Computing
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL)
|
||||
* Uses diagrams to express solutions.(AB)
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Declares and assigns variables(AB)
|
||||
* Uses post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL)
|
||||
* Understands the difference between, and appropriately uses if and if, then and else statements(AL)
|
||||
* Uses a variable and relational operators within a loop to govern termination (AL) (GE)
|
||||
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
|
||||
* Selects the appropriate data types(AL) (AB
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Understands the difference between data and information(AB)
|
||||
* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV)
|
||||
* Defines data types: real numbers and Boolean (AB)
|
||||
|
||||
#### Hardware & Processing
|
||||
|
||||
* Knows that computers collect data from various input devices, including sensors and application software (AB)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organizes, and presents data and information in digital content (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
|
||||
* Recognises ethical issues surrounding the application of information technology beyond school.
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/lessons/2-player-pong/tutorial)
|
||||
|
||||
## Intended follow on
|
||||
|
||||
Publish script to the classroom.
|
||||
|
91
olddocs/js/lessons/2-player-pong/quiz-answers.md
Normal file
91
olddocs/js/lessons/2-player-pong/quiz-answers.md
Normal file
@ -0,0 +1,91 @@
|
||||
# 2 player pong quiz answers
|
||||
|
||||
a two-player game of Pong using TWO BBC micro:bits!.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [2 player pong tutorial](/lessons/2-player-pong/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the two global variables that record if the player has the ball and if the game is running, and assign these variables to their initial values.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
hasBall = false
|
||||
gameRunning = false
|
||||
```
|
||||
|
||||
## 2. Write the global variable that keeps track of the game state in which whoever presses button A first will get to start the ball. Assign this variable to its initial value.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
claimBall = true
|
||||
```
|
||||
|
||||
## 3. Write the code that creates a condition to know when Button A is pressed. Then write the 'If statement' to ensure that 'claim ball' is true. If the claim ball is true, then write the code that sets P0 to 1 to signal to the other device that the player has claimed the ball.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
if (claimBall) {
|
||||
pins.digitalWritePin("P0", 1)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## 4. Write the code to move the paddle right when button B is pressed. Be sure to check if the game is running and if the paddle is not already on the rightmost edge.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
if (gameRunning) {
|
||||
if (paddleX != 0) {
|
||||
led.unplot(paddleX, 4)
|
||||
paddleX = paddleX - 1
|
||||
led.plot(paddleX, 4)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 5. What are the three pieces of information that we send to the other device when transferring the ball? (Hint: look in your "transfer ball" function, and look for any places that contain "transfer byte").
|
||||
|
||||
<br/>
|
||||
|
||||
The device first transfers a bit of 1 to indicate that the device is going to transfer the data of the ball. After that, the device transfers the x-coordinate of the ball, and then the x-velocity of the ball.
|
||||
|
||||
## 6. Using the function "read velocity", write the code that reads the x-coordinate and the x-velocity of the ball. (Hint: look at the function "read ball".)
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
ballX = micro_bitTransfer.readByte()
|
||||
ballXVelocity = readVelocity()
|
||||
```
|
||||
|
||||
## 7. Write the code that updates 'ball x velocity'. (Hint: look at the "update velocity" function.)
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
if (ballX == 0 || ballX == 4) {
|
||||
ballXVelocity = ballXVelocity * (-1)
|
||||
}
|
||||
```
|
||||
|
||||
## 8. Write the code to move the ball. To move the ball, unplot the ball's original position, update its position variables, and then plot the ball's new position.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
led.unplot(ballX, 0)
|
||||
ballX = ballX + ballXVelocity
|
||||
ballY = ballY + ballYVelocity
|
||||
led.plot(ballX, ballY)
|
||||
```
|
||||
|
70
olddocs/js/lessons/2-player-pong/quiz.md
Normal file
70
olddocs/js/lessons/2-player-pong/quiz.md
Normal file
@ -0,0 +1,70 @@
|
||||
# 2 player pong quiz
|
||||
|
||||
a two-player game of Pong using TWO BBC micro:bits!.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [2 player pong tutorial](/lessons/2-player-pong/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the two global variables that record if the player has the ball and if the game is running, and assign these variables to their initial values.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the global variable that keeps track of the game state in which whoever presses button A first will get to start the ball. Assign this variable to its initial value.
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the code that creates a condition to know when Button A is pressed. Then write the 'If statement' to ensure that 'claim ball' is true. If the 'claim ball' is true, then write the code that sets P0 to 1 to signal to the other device that the player has claimed the ball.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the code to move the paddle right when button B is pressed. Be sure to check if the game is running and if the paddle is not already on the rightmost edge.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 5. What are the three pieces of information that we send to the other device when transferring the ball? (Hint: look in your "transfer ball" function, and look for any places that contain "transfer byte").
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 6. Using the function "read velocity", write the code that reads the x-coordinate and the x-velocity of the ball. (Hint: look at the function "read ball".)
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 7. Write the code that updates 'ball x velocity'. (Hint: look at the "update velocity" function.)
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 8. Write the code to move the ball. To move the ball, unplot the ball's original position, update its position variables, and then plot the ball's new position.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
59
olddocs/js/lessons/accelerometer/challenges.md
Normal file
59
olddocs/js/lessons/accelerometer/challenges.md
Normal file
@ -0,0 +1,59 @@
|
||||
# zoomer challenges
|
||||
|
||||
The acceleration function.
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
Great job! You have successfully completed the [zoomer tutorial](https://test.microbit.co.uk/td/lessons/zoomer/challenges) . You have created a script that measures the acceleration on the micro:bit in the "z" direction of a 3D world.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
let millig = input.acceleration("z")
|
||||
basic.showNumber(millig, 150)
|
||||
basic.pause(100)
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
Create a new variable called milliX that holds the acceleration in the "x" direction or the horizontal direction.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
let millig1 = input.acceleration("z")
|
||||
basic.showNumber(millig1, 150)
|
||||
basic.pause(100)
|
||||
let milliX = input.acceleration("x") // ***
|
||||
})
|
||||
```
|
||||
|
||||
* Run the code to see if it works as expected.
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
If Button `A` is pressed, we want to show the acceleration in the "x" direction by adding an if statement that checks to see if Button `A` is pressed and then calling the show number method passing in milliX as the number.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
let millig2 = input.acceleration("z")
|
||||
basic.showNumber(millig2, 150)
|
||||
basic.pause(100)
|
||||
let milliX1 = input.acceleration("x")
|
||||
if (input.buttonIsPressed("A")) {
|
||||
basic.showNumber(milliX1, 150) // ***
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
* Run the code to see if it works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
If Button `B` is pressed, program the micro:bit to display the acceleration in the "y" direction.
|
||||
|
||||
You can do this by storing the acceleration in a variable: `var milliY := input->acceleration("y")`.
|
||||
|
||||
Then add an `if` statement that checks if Button `B` is pressed: `if input-> button is pressed ("B") then`.
|
||||
|
||||
Inside of the `if` statement, add `basic->show number(milliY, 150)`, which will display the acceleration in the "y" direction.
|
||||
|
79
olddocs/js/lessons/blinks-rectangle/challenges.md
Normal file
79
olddocs/js/lessons/blinks-rectangle/challenges.md
Normal file
@ -0,0 +1,79 @@
|
||||
# rectangle explosion challenges
|
||||
|
||||
These challenges will allow you to make an exploding rectangle. #docs
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
This [guided tutorial](https://test.microbit.co.uk/td/lessons/blinks-rectangle/tutorial) will help you show an animation forever!
|
||||
|
||||
First, let's make a small rectangle blink forever.
|
||||
|
||||
```blocks
|
||||
basic.forever(() => {
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . .
|
||||
. # # # . . . . . .
|
||||
. # # # . . . . . .
|
||||
. . . . . . . . . .
|
||||
. . . . . . . . . .
|
||||
`, 400)
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
Let's begin creating our explosion effect by adding another rectangle animation that displays a slightly larger rectangle after the first one.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . .
|
||||
. # # # . . . . . .
|
||||
. # # # . . . . . .
|
||||
. . . . . . . . . .
|
||||
. . . . . . . . . .
|
||||
`, 400)
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . .
|
||||
# # # # # . . . . .
|
||||
# # # # # . . . . .
|
||||
# # # # # . . . . .
|
||||
. . . . . . . . . .
|
||||
`, 400)
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
To finalize our explosion effect, let's add a rectangle that is bigger than the last two we have created.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . .
|
||||
. # # # . . . . . .
|
||||
. # # # . . . . . .
|
||||
. . . . . . . . . .
|
||||
. . . . . . . . . .
|
||||
`, 400)
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . .
|
||||
# # # # # . . . . .
|
||||
# # # # # . . . . .
|
||||
# # # # # . . . . .
|
||||
. . . . . . . . . .
|
||||
`, 400)
|
||||
basic.showAnimation(`
|
||||
# # # # # . . . . .
|
||||
# # # # # . . . . .
|
||||
# # # # # . . . . .
|
||||
# # # # # . . . . .
|
||||
# # # # # . . . . .
|
||||
`, 400)
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
If you notice, the rectangle explodes fairly slow. Let's make it explode faster by decreasing the intervals of the animation from 400 to 200.
|
||||
|
91
olddocs/js/lessons/boolean-fun/challenges.md
Normal file
91
olddocs/js/lessons/boolean-fun/challenges.md
Normal file
@ -0,0 +1,91 @@
|
||||
# speed button challenges
|
||||
|
||||
This challenging script will create a game in which the user needs to press button A fast enough. You will get practice with using booleans in "if" statements. #docs
|
||||
|
||||
### Challenge 0
|
||||
|
||||
Welcome! This [guided tutorial](https://live.microbit.co.uk/td/lessons/speed-button/tutorial) will help you begin creating this game!
|
||||
|
||||
```
|
||||
counter = 0
|
||||
fastPress = false
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
counter = counter + 1
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
We need to know when the user has hit button `A` 15 times. The user wins when he/she is able to accomplish this in less than 3500 milliseconds (3.5 seconds). We can check for both conditions by using an `and` operator. When using an `and` operator, both conditions need to be true in order for the condition to be true.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
fastPress = false
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
counter = counter + 1
|
||||
if (counter == 15 && input.runningTime() < 3500) {
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
Next, if the user has won, let's set our boolean to true. This indicates that he or she has won.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
fastPress = false
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
counter = counter + 1
|
||||
if (counter == 15 && input.runningTime() < 3500) {
|
||||
fastPress = true // ***
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
We want to set `fastPress` to false if the user was too slow. To do so, we need another condition to see if the user took more than 3500 milliseconds (3.5 seconds). In the `if` statement, set `fastPress` to false.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
fastPress = false
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
counter = counter + 1
|
||||
if (counter == 15 && input.runningTime() < 3500) {
|
||||
fastPress = true
|
||||
}
|
||||
if (counter == 15 && input.runningTime() > 3499) {
|
||||
fastPress = false // ***
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Now let's display if the user won or lost. To do so, we need to check the status of `fastPress` when the game is finished, and then show the correct message.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
fastPress = false
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
counter = counter + 1
|
||||
if (counter == 15 && input.runningTime() < 3500) {
|
||||
fastPress = true
|
||||
}
|
||||
if (counter == 15 && input.runningTime() > 3499) {
|
||||
fastPress = false
|
||||
}
|
||||
if (counter == 15 && fastPress) {
|
||||
basic.showString("YOU WIN!", 150) // ***
|
||||
}
|
||||
if (counter == 15 && ! fastPress) {
|
||||
basic.showString("TOO SLOW!", 150) // ***
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
* Click the `run` button to see if the code runs properly.
|
||||
|
||||
### Challenge 4
|
||||
|
||||
Modify the code to change the difficulty level. Increasing the time will make it easier, while decreasing the time will make it harder. For example, changing the 3500 milliseconds to 4500 milliseconds will make the difficulty easier.
|
||||
|
108
olddocs/js/lessons/bounce-image.md
Normal file
108
olddocs/js/lessons/bounce-image.md
Normal file
@ -0,0 +1,108 @@
|
||||
# bounce image lesson
|
||||
|
||||
scroll an image across the screen.
|
||||
|
||||
### @video td/videos/bounce-image-0
|
||||
|
||||
## Topic
|
||||
|
||||
Basic- Show Animation
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [tutorial](/lessons/bounce-image/tutorial)
|
||||
* [quiz](/lessons/bounce-image/quiz)
|
||||
* [quiz answers](/lessons/bounce-image/quiz-answers)
|
||||
* [challenges](/lessons/bounce-image/challenges)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning / place of lesson in scheme of work
|
||||
|
||||
Learn how to creating an **animation**, `basic->show animation` to display a series of images. We will be learning how to create a counter app using a forever loop, the input on shake, and show animation.
|
||||
|
||||
## What the teacher needs to know / QuickStart Computing Glossary
|
||||
|
||||
* Algorithm: An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective.
|
||||
* Command: An instruction for the computer to execute, written in a particular programming language.
|
||||
* Hardware: The physical systems and components of digital devices; see also software.
|
||||
* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors.
|
||||
* Loop: A block of code repeated automatically under the program’s control.
|
||||
* Output: The information produced by a computer system for its user, typically on a screen, through speakers or on a printer, but possibly through the control of motors in physical systems.
|
||||
* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program.
|
||||
* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.
|
||||
* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met.
|
||||
* Sequence: To place program instructions in order, with each executed one after the other.
|
||||
* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games.
|
||||
|
||||
## Documentation
|
||||
|
||||
* **forever** : [read more...](/reference/basic/forever)
|
||||
* **show animation** : [read more...](/reference/basic/show-animation)
|
||||
* **on shake** : [read more...](/reference/input/on-gesture)
|
||||
|
||||
## Resources
|
||||
|
||||
* Activity: [tutorial](/lessons/bounce-image/tutorial)
|
||||
* Activity: [quiz](/lessons/bounce-image/quiz)
|
||||
* Extended Activity: [challenges](/lessons/bounce-image/challenges)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to repeat code in the background forever
|
||||
* learn how to show a series of image frames on the LED screen, pausing the specified time after each frame
|
||||
* learn how to run code when the micro:bit is shaken; when running code in the web browser, moving the mouse quickly simulates shaking
|
||||
|
||||
## Links to the National Curriculum Programmes of Study for Computing
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Uses diagrams to express solutions.(AB)
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
|
||||
* Understands that iteration is the repetition of a process such as a loop (AL)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Selects the appropriate data types(AL) (AB)
|
||||
|
||||
#### Hardware & Processing
|
||||
|
||||
* Knows that computers collect data from various input devices, including sensors and application software (AB)
|
||||
|
||||
#### Communication Networks
|
||||
|
||||
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organizes, and presents data and information in digital content (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
|
||||
* Recognises ethical issues surrounding the application of information technology beyond school.
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/lessons/bounce-image/tutorial)
|
||||
* [quiz](/lessons/bounce-image/quiz)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/lessons/bounce-image/challenges)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/lessons/bounce-image/challenges)
|
||||
|
||||
## Intended follow on
|
||||
|
||||
Publish script to the classroom.
|
||||
|
90
olddocs/js/lessons/bounce-image/challenges.md
Normal file
90
olddocs/js/lessons/bounce-image/challenges.md
Normal file
@ -0,0 +1,90 @@
|
||||
# bounce image challenges
|
||||
|
||||
Coding challenges for the bounce image tutorial. #docs
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/lessons/bounce-image/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.showAnimation(`
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . #
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . #
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . #
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . #
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . #
|
||||
`, 200)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
### @video td/videos/bounce-image-1
|
||||
|
||||
Now, let's add frames to reverse the animation so it looks like the bar is bouncing off the right edge of the display.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.showAnimation(`
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
`, 200) // ***
|
||||
})
|
||||
```
|
||||
|
||||
* Run the code to see if it works as expected.
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Let's add a condition for on shake!
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.showAnimation(`
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
`, 200)
|
||||
})
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
}) // ***
|
||||
```
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
### @video td/videos/bounce-image-2-3
|
||||
|
||||
When the BBC micro:bit is shaken we want to show a new animation. Here is an example, but you can create your own. Be creative!
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.showAnimation(`
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
# . . . . . # . . . . . # . . . . . # . . . . . # . . . # . . . # . . . # . . . # . . . .
|
||||
`, 200)
|
||||
})
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . . # # # # # . . . . . . . . . .
|
||||
. . . . . . # # # . # # # # # . # # # . . . . . .
|
||||
. . # . . . # # # . # # # # # . # # # . . . # . .
|
||||
. . . . . . # # # . # # # # # . # # # . . . . . .
|
||||
. . . . . . . . . . # # # # # . . . . . . . . . .
|
||||
`, 200) // ***
|
||||
})
|
||||
```
|
||||
|
||||
* Run the code to see if it works as expected.
|
60
olddocs/js/lessons/bounce-image/quiz-answers.md
Normal file
60
olddocs/js/lessons/bounce-image/quiz-answers.md
Normal file
@ -0,0 +1,60 @@
|
||||
# bounce image quiz answers
|
||||
|
||||
scroll an image on the BBC micro:bit.
|
||||
|
||||
This is the answer key for the [bounce image quiz](/lessons/bounce-image/quiz).
|
||||
|
||||
## 1. What does it mean to 'add frames' ?
|
||||
|
||||
Adding frames modifies the animation by including more still images in each animation.
|
||||
|
||||
## 2. Write the code that will display this animation.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
# . . . .
|
||||
# . . . .
|
||||
# . . . .
|
||||
# . . . .
|
||||
# . . . .
|
||||
`, 400)
|
||||
```
|
||||
|
||||
## 3. Write the code that will display this animation with two frames.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
# . . . . . # . . .
|
||||
# . . . . . # . . .
|
||||
# . . . . . # . . .
|
||||
# . . . . . # . . .
|
||||
# . . . . . # . . .
|
||||
`, 400)
|
||||
```
|
||||
|
||||
## 4. Write the code that will display this animation with three frames.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
# . . . . . # . . . . . # . .
|
||||
# . . . . . # . . . . . # . .
|
||||
# . . . . . # . . . . . # . .
|
||||
# . . . . . # . . . . . # . .
|
||||
# . . . . . # . . . . . # . .
|
||||
`, 400)
|
||||
```
|
||||
|
||||
<br/>
|
||||
|
40
olddocs/js/lessons/bounce-image/quiz.md
Normal file
40
olddocs/js/lessons/bounce-image/quiz.md
Normal file
@ -0,0 +1,40 @@
|
||||
# bounce image quiz
|
||||
|
||||
scroll an image on the BBC micro:bit.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this document to guide your work in the [bounce image tutorial](/lessons/bounce-image/tutorial) !
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What does it mean to 'add frames' ?
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the code that will display this animation.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the code that will display this animation with two frames.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the code that will display this animation with three frames.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
85
olddocs/js/lessons/boxer-mania/challenges.md
Normal file
85
olddocs/js/lessons/boxer-mania/challenges.md
Normal file
@ -0,0 +1,85 @@
|
||||
# boxer mania challenges
|
||||
|
||||
My script. #docs
|
||||
|
||||
This [guided tutorial](/lessons/boxer-mania/tutorial) will help you create an animation!
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
Let's create and show a series of frames on the LED screen; this is an animation!
|
||||
|
||||
We will use multiple frames to make it look like a square is rotating on the micro:bit screen!
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
. # . . .
|
||||
# . . . .
|
||||
. # . . .
|
||||
. . # . #
|
||||
. . . # .
|
||||
`, 400)
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
Let's create the next frame to make it look like the square is spinning clock-wise!
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
. # . . .
|
||||
# . . . .
|
||||
. # . . .
|
||||
. . # . #
|
||||
. . . # .
|
||||
`, 400)
|
||||
basic.showAnimation(`
|
||||
# # # # #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# # # # #
|
||||
`, 400) // ***
|
||||
```
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
Add the next two frames to show a complete rotation for the square!
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
. # . . .
|
||||
# . . . .
|
||||
. # . . .
|
||||
. . # . #
|
||||
. . . # .
|
||||
`, 400)
|
||||
basic.showAnimation(`
|
||||
# # # # #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# . . . #
|
||||
# # # # #
|
||||
`, 400)
|
||||
basic.showAnimation(`
|
||||
. # . . . # # # # #
|
||||
# . # . . # . . . #
|
||||
. . . # . # . . . #
|
||||
. . . . # # . . . #
|
||||
. . . # . # # # # #
|
||||
`, 400) // ***
|
||||
```
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
Do you want to show the same animation with fewer lines of codes? We can do this by combining all the frames into one show animation function call!
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
. # . . . # # # # # . # . . . # # # # #
|
||||
# . . . . # . . . # # . # . . # . . . #
|
||||
. # . . . # . . . # . . . # . # . . . #
|
||||
. . # . # # . . . # . . . . # # . . . #
|
||||
. . . # . # # # # # . . . # . # # # # #
|
||||
`, 400) // ***
|
||||
```
|
||||
|
86
olddocs/js/lessons/break/challenges.md
Normal file
86
olddocs/js/lessons/break/challenges.md
Normal file
@ -0,0 +1,86 @@
|
||||
# break challenges
|
||||
|
||||
This guide will show you how to use a break statement within a while loop. #docs
|
||||
|
||||
### Challenge 0
|
||||
|
||||
Welcome! This [guided tutorial](/lessons/break/tutorial) will assist you with this activity.
|
||||
|
||||
```
|
||||
count = 0
|
||||
shouldBreak = false
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
shouldBreak = true
|
||||
})
|
||||
while (true) {
|
||||
if (shouldBreak) {
|
||||
basic.showString("I'M OUT!", 150)
|
||||
images.createImage(`
|
||||
# . . . #
|
||||
# . . . #
|
||||
. . # . .
|
||||
# . . . #
|
||||
. # # # .
|
||||
`).showImage(0)
|
||||
break
|
||||
}
|
||||
count = count + 1
|
||||
basic.showNumber(count, 150)
|
||||
basic.pause(1000)
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Try to remove the `break` in the `if` loop. What problem does this create?
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Now let's resume the timer again once button `B` is pressed! To do so, begin by creating a condition to know when button `B` is pressed.
|
||||
|
||||
```
|
||||
// **. . .**
|
||||
while (true) {
|
||||
if (shouldBreak) {
|
||||
basic.showString("I'M OUT!", 150)
|
||||
break
|
||||
}
|
||||
count = count + 1
|
||||
basic.showNumber(count, 150)
|
||||
basic.pause(1000)
|
||||
}
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
}) // ***
|
||||
```
|
||||
|
||||
Next, set `shouldBreak` back to false to indicate we want to run the `while` loop again.
|
||||
|
||||
```
|
||||
// **. . .**
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
shouldBreak = false // ***
|
||||
})
|
||||
```
|
||||
|
||||
And now copy the code from the previous while loop into the condition of `input->on button pressed("B")`. This will resume the counter.
|
||||
|
||||
```
|
||||
// **. . .**
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
shouldBreak = false
|
||||
while (true) {
|
||||
if (shouldBreak) {
|
||||
basic.showString("I'M OUT!", 150) // ***
|
||||
break // ***
|
||||
}
|
||||
count = count + 1 // ***
|
||||
basic.showNumber(count, 150) // ***
|
||||
basic.pause(1000) // ***
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Notice that the two `while` loops are identical. Clean up this redundancy in your code by creating another method and then placing the `while` loop in the method.
|
||||
|
52
olddocs/js/lessons/button/challenges.md
Normal file
52
olddocs/js/lessons/button/challenges.md
Normal file
@ -0,0 +1,52 @@
|
||||
# button challenges
|
||||
|
||||
My script. #docs
|
||||
|
||||
### Challenge 0
|
||||
|
||||
Howdy! This [guided tutorial](/rxqgzy) will help you complete this activity!
|
||||
|
||||
In this guide, you will learn how to use buttons and show text on the screen. Let's start by adding to respond **when the left button is pressed**.
|
||||
|
||||
```
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
})
|
||||
```
|
||||
|
||||
All the code inside `input->on button pressed` runs when the button is pressed. Let's add the code to show some text.
|
||||
|
||||
```
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("hello", 150)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Let's add an event handler for Button `B`.
|
||||
|
||||
```
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("hello", 150)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Display `bye` when the `B` button is pressed.
|
||||
|
||||
```
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("hello", 150)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
basic.showString("bye", 150)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Change the strings so that they display some other text. In order to do so, you will need to edit what is inside the quotation marks in `basic->show string`.
|
||||
|
128
olddocs/js/lessons/cascade/quiz.md
Normal file
128
olddocs/js/lessons/cascade/quiz.md
Normal file
@ -0,0 +1,128 @@
|
||||
# strobe lightquiz
|
||||
|
||||
Learn how to create a blinking LED script with a for loop.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [light column cascade tutorial](/js/light-column-cascade/tutorial).
|
||||
|
||||
Answer the questions below while working on or after you finish the tutorial. Pay attention to the dialogs!
|
||||
|
||||
## 1. What is a for loop?
|
||||
|
||||
## 2. Consider the following code
|
||||
|
||||
```
|
||||
for (let i = 0; i < 5; i++) {
|
||||
for (let j = 0; j < 5; j++) {
|
||||
led.plot(i, j)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately all the locations where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
## 3. Consider the following code
|
||||
|
||||
```
|
||||
for (let i1 = 0; i1 < 3; i1++) {
|
||||
for (let j1 = 0; j1 < 3; j1++) {
|
||||
led.plot(i1, j1)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately all the locations where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
## 4. Consider the following code
|
||||
|
||||
```
|
||||
for (let i2 = 0; i2 < 2; i2++) {
|
||||
for (let j2 = 0; j2 < 2; j2++) {
|
||||
led.plot(i2, j2)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
******************************
|
||||
|
||||
## ANSWER KEY
|
||||
|
||||
## Directions
|
||||
|
||||
Answer the questions below while working on or after you finish the tutorial.
|
||||
|
||||
## 1. What is a for loop?
|
||||
|
||||
Answers will vary. In general, for loop refers to the code that repeats for a fixed number of times. We specify the LED using x, y coordinates.
|
||||
|
||||
## 2. Consider the following code
|
||||
|
||||
```
|
||||
for (let i3 = 0; i3 < 5; i3++) {
|
||||
for (let j3 = 0; j3 < 5; j3++) {
|
||||
led.plot(i3, j3)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates. The code lights on the LEDs
|
||||
|
||||
x - the x coordinate or horizontal position (0,1,2,3,4)
|
||||
|
||||
y - the y coordinate or vertical position (0,1,2,3,4)
|
||||
|
||||
## 3. Consider the following code
|
||||
|
||||
```
|
||||
for (let i4 = 0; i4 < 3; i4++) {
|
||||
for (let j4 = 0; j4 < 3; j4++) {
|
||||
led.plot(i4, j4)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates.
|
||||
|
||||
x - the x coordinate or horizontal position (0,1,2)
|
||||
|
||||
y - the y coordinate or vertical position (0,1,2)
|
||||
|
||||
## 4. Consider the following code
|
||||
|
||||
```
|
||||
for (let i5 = 0; i5 < 2; i5++) {
|
||||
for (let j5 = 0; j5 < 2; j5++) {
|
||||
led.plot(i5, j5)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates.
|
||||
|
||||
x - the x coordinate or horizontal position (0,1)
|
||||
|
||||
y - the y coordinate or vertical position (0,1)
|
||||
|
77
olddocs/js/lessons/clear-screen/challenges.md
Normal file
77
olddocs/js/lessons/clear-screen/challenges.md
Normal file
@ -0,0 +1,77 @@
|
||||
# clear screen challenges
|
||||
|
||||
My script. #docs
|
||||
|
||||
### Challenge 0
|
||||
|
||||
Welcome! This [guided tutorial](/hzckbb) will help you create the script to clear the screen!
|
||||
|
||||
Your goal is to clear the screen after displaying an animation. Begin by showing and displaying an animation. Remember that the `show animation` is in the `basic` namespace. We then need to detect when the "A" button is pressed. Finally, clear the screen by typing in `basic->clear screen`.
|
||||
|
||||
Your main function should look like this:
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
. . . . . # # # # # # # # # # . . . . .
|
||||
. . . . . # # # # # # # # # # # # # # #
|
||||
. . . . . . . . . . . . . . . # # # # #
|
||||
`, 400)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.clearScreen()
|
||||
})
|
||||
```
|
||||
|
||||
* tap the `run` button to view the script on the monitor.
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Create an event handler for Button "B".
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
. . . . . # # # # # # # # # # . . . . .
|
||||
. . . . . # # # # # # # # # # # # # # #
|
||||
. . . . . . . . . . . . . . . # # # # #
|
||||
`, 400)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.clearScreen()
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Replay the animation when the "B" button is pressed by typing in `basic->show animation(..., 400)`.
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
. . . . . # # # # # # # # # # . . . . .
|
||||
. . . . . # # # # # # # # # # # # # # #
|
||||
. . . . . . . . . . . . . . . # # # # #
|
||||
`, 400)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.clearScreen()
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
basic.showAnimation(`
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
. . . . . # # # # # # # # # # . . . . .
|
||||
. . . . . # # # # # # # # # # # # # # #
|
||||
. . . . . . . . . . . . . . . # # # # #
|
||||
`, 400) // ***
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Show an animation that scrolls back up when you press button "B".
|
||||
|
||||
* tap the `run` button to view your final product!
|
128
olddocs/js/lessons/column/quiz.md
Normal file
128
olddocs/js/lessons/column/quiz.md
Normal file
@ -0,0 +1,128 @@
|
||||
# cascade quiz
|
||||
|
||||
Learn how to create a blinking LED script with a for loop.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [light column cascade tutorial](/js/light-column-cascade/tutorial).
|
||||
|
||||
Answer the questions below while working on or after you finish the tutorial. Pay attention to the dialogs!
|
||||
|
||||
## 1. What is a for loop?
|
||||
|
||||
## 2. Consider the following code
|
||||
|
||||
```
|
||||
for (let i = 0; i < 5; i++) {
|
||||
for (let j = 0; j < 5; j++) {
|
||||
led.plot(i, j)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately all the locations where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
## 3. Consider the following code
|
||||
|
||||
```
|
||||
for (let i1 = 0; i1 < 3; i1++) {
|
||||
for (let j1 = 0; j1 < 3; j1++) {
|
||||
led.plot(i1, j1)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately all the locations where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
## 4. Consider the following code
|
||||
|
||||
```
|
||||
for (let i2 = 0; i2 < 2; i2++) {
|
||||
for (let j2 = 0; j2 < 2; j2++) {
|
||||
led.plot(i2, j2)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
******************************
|
||||
|
||||
## KEY
|
||||
|
||||
## Directions
|
||||
|
||||
Answer the questions below while working on or after you finish the tutorial.
|
||||
|
||||
## 1. What is a for loop?
|
||||
|
||||
Answers will vary. In general, for loop refers to the code that repeats for a fixed number of times. We specify the LED using x, y coordinates.
|
||||
|
||||
## 2. Consider the following code
|
||||
|
||||
```
|
||||
for (let i3 = 0; i3 < 5; i3++) {
|
||||
for (let j3 = 0; j3 < 5; j3++) {
|
||||
led.plot(i3, j3)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates. The code lights on the LEDs
|
||||
|
||||
x - the x coordinate or horizontal position (0,1,2,3,4)
|
||||
|
||||
y - the y coordinate or vertical position (0,1,2,3,4)
|
||||
|
||||
## 3. Consider the following code
|
||||
|
||||
```
|
||||
for (let i4 = 0; i4 < 3; i4++) {
|
||||
for (let j4 = 0; j4 < 3; j4++) {
|
||||
led.plot(i4, j4)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates.
|
||||
|
||||
x - the x coordinate or horizontal position (0,1,2)
|
||||
|
||||
y - the y coordinate or vertical position (0,1,2)
|
||||
|
||||
## 4. Consider the following code
|
||||
|
||||
```
|
||||
for (let i5 = 0; i5 < 1; i5++) {
|
||||
for (let j5 = 0; j5 < 1; j5++) {
|
||||
led.plot(i5, j5)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates.
|
||||
|
||||
x - the x coordinate or horizontal position (0,1)
|
||||
|
||||
y - the y coordinate or vertical position (0,1)
|
||||
|
79
olddocs/js/lessons/compare-machine/challenges.md
Normal file
79
olddocs/js/lessons/compare-machine/challenges.md
Normal file
@ -0,0 +1,79 @@
|
||||
# compare machine challenges
|
||||
|
||||
These challenges allow you to set the value of a counter to 1 when button B is pressed. #docs
|
||||
|
||||
### Challenge 0
|
||||
|
||||
Welcome! This [guided tutorial](/lessons/comparison/tutorial) will assist you with using the comparison operator.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
counter = counter + 1
|
||||
if (counter == 10) {
|
||||
counter = 1
|
||||
}
|
||||
basic.showNumber(counter, 150)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Now let's do something special when the micro:bit reaches the number `5`. Instead of just showing the number `5`, let's show the string `HALF WAY!`. Begin by setting an if statement to know when `counter = 5`.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
counter = counter + 1
|
||||
if (counter == 10) {
|
||||
counter = 1
|
||||
}
|
||||
if (counter == 5) {
|
||||
}
|
||||
basic.showNumber(counter, 150)
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Let's continue our plan of displaying `HALF WAY!` when `counter = 5`. To do so, add the following line of code inside the if statement.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
counter = counter + 1
|
||||
if (counter == 10) {
|
||||
counter = 1
|
||||
}
|
||||
if (counter == 5) {
|
||||
basic.showString("HALF WAY!", 150) // ***
|
||||
}
|
||||
basic.showNumber(counter, 150)
|
||||
})
|
||||
```
|
||||
|
||||
* Run your code to see if it works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
You may notice a problem right now. When `counter = 5`, the micro:bit will show both the message `HALF WAY!` and the number `5`. In order to fix this problem, let's take advantage of the `else` at the end of the if statement.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
counter = counter + 1
|
||||
if (counter == 10) {
|
||||
counter = 1
|
||||
}
|
||||
if (counter == 5) {
|
||||
basic.showString("HALF WAY!", 150)
|
||||
} else {
|
||||
basic.showNumber(counter, 150) // ***
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 4
|
||||
|
||||
When `counter = 8`, display the message `ALMOST THERE!` on the micro:bit. You will need to add an `else if` after the if statement of `counter = 5`.
|
||||
|
133
olddocs/js/lessons/digital-pet.md
Normal file
133
olddocs/js/lessons/digital-pet.md
Normal file
@ -0,0 +1,133 @@
|
||||
# digital pet lesson
|
||||
|
||||
a display of pet images for the BBC micro:bit.
|
||||
|
||||
### @video td/videos/digital-pet-0
|
||||
|
||||
## Topic
|
||||
|
||||
Functions
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [tutorial](/lessons/digital-pet/tutorial)
|
||||
* [quiz](/lessons/digital-pet/quiz)
|
||||
* [quiz answers](/lessons/digital-pet/quiz-answers)
|
||||
* [challenges](/lessons/digital-pet/challenges)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to create **functions**, `function()` that perform a specific task and returns a result. We will be learning how to create a digital pet app using functions, global variables, forever loop, input button in pressed, input on shake as well as simple commands, such as show string, show number, and pause.
|
||||
|
||||
## What the teacher needs to know
|
||||
|
||||
* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective.
|
||||
* Command: An instruction for the computer to execute, written in a particular programming language.
|
||||
* Data: A structured set of numbers, possibly representing digitised text, images, sound or video, which can be processed or transmitted by a computer, also used for numerical (quantitative) information.
|
||||
* Hardware: The physical systems and components of digital devices; see also software.
|
||||
* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors.
|
||||
* Output: The information produced by a computer system for its user, typically on a screen, through speakers or on a printer, but possibly through the control of motors in physical systems.
|
||||
* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program.
|
||||
* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.
|
||||
* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character.
|
||||
* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met.
|
||||
* Sequence: To place program instructions in order, with each executed one after the other.
|
||||
* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games.
|
||||
* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the user’s name.
|
||||
|
||||
**QuickStart Computing Glossary
|
||||
|
||||
## Documentation
|
||||
|
||||
* **function** : [read more...](/js/function)
|
||||
* **call** : [read more...](/js/call)
|
||||
* **global variable** : [read more...](/js/data)
|
||||
* **assignment operator** : [read more...](/reference/variables/assign)
|
||||
* **forever** : [read more...](/reference/basic/forever)
|
||||
* **button is pressed** : [read more...](/reference/input/button-is-pressed)
|
||||
* **show string** : [read more...](/reference/basic/show-string)
|
||||
* **show number** : [read more...](/reference/basic/show-number)
|
||||
* **create image** : [read more...](/reference/images/create-image)
|
||||
* **show image** : [read more...](/reference/images/show-image)
|
||||
* **pause** : [read more...](/reference/basic/pause)
|
||||
|
||||
## Resources
|
||||
|
||||
* Activity: [tutorial](/lessons/digital-pet/tutorial)
|
||||
* Activity: [quiz](/lessons/digital-pet/quiz)
|
||||
* Extended Activity: [challenges](/lessons/digital-pet/challenges)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create a function as a unit of code that performs a specific task and returns a result
|
||||
* learn how to call an existing function in your script
|
||||
* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks
|
||||
* learn how to set or change the value of a global variable
|
||||
* learn how to repeat code in the background forever
|
||||
* learn how to get the state of an input button
|
||||
* learn how to show a number on the micro:bit's LED screen
|
||||
* learn how to show a string on the micro:bit's LED screen
|
||||
* learn how to create an image to show on the micro:bit's LED screen
|
||||
* learn how to show an image on the micro:bit's LED screen
|
||||
* learn how to pause your code for the specified number of milliseconds
|
||||
|
||||
## Links to the National Curriculum Programmes of Study for Computing
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL)
|
||||
* Uses diagrams to express solutions.(AB)
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Declares and assigns variables(AB)
|
||||
* Uses post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL)
|
||||
* Understands the difference between, and appropriately uses if and if, then and else statements(AL)
|
||||
* Uses a variable and relational operators within a loop to govern termination (AL) (GE)
|
||||
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
|
||||
* Selects the appropriate data types(AL) (AB
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Defines data types: real numbers and Boolean (AB)
|
||||
|
||||
#### Communication Networks
|
||||
|
||||
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organizes, and presents data and information in digital content (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
|
||||
* Uses criteria to evaluate the quality of solutions, can identify improvements making some refinements to the solution, and future solutions (EV)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/lessons/digital-pet/tutorial)
|
||||
* [quiz](/lessons/digital-pet/quiz)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/lessons/digital-pet/challenges)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/lessons/digital-pet/challenges)
|
||||
|
||||
## Intended follow on
|
||||
|
||||
Publish script to the classroom.
|
||||
|
129
olddocs/js/lessons/digital-pet/challenges.md
Normal file
129
olddocs/js/lessons/digital-pet/challenges.md
Normal file
@ -0,0 +1,129 @@
|
||||
# digital pet challenges
|
||||
|
||||
Coding challenges for the digital pet tutorial.
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/lessons/digital-pet/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
if (input.buttonIsPressed("A")) {
|
||||
setSleep()
|
||||
basic.pause(5000)
|
||||
} else {
|
||||
setAwake()
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Now let's feed the pet! Add an **ELSE IF** statement that checks if button `B` is pressed. Click on the **ELSE** and type **IF** next to it to get the **ELSE IF**.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
if (input.buttonIsPressed("A")) {
|
||||
setSleep()
|
||||
basic.pause(5000)
|
||||
} else if (input.buttonIsPressed("B")) {
|
||||
|
||||
}
|
||||
else {
|
||||
setAwake()
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
### @video td/videos/digital-pet-2
|
||||
|
||||
Now we want to show your eating pet! Let's create a function called `set eat` that will do create an image. Store that image in a variable and then show it.
|
||||
|
||||
```
|
||||
export function setEat() {
|
||||
let img = images.createImage(`
|
||||
. # . # .
|
||||
. . # . .
|
||||
. . # . .
|
||||
. # . # .
|
||||
. . # . .
|
||||
`)
|
||||
img.showImage(0)
|
||||
}
|
||||
```
|
||||
|
||||
Once you create the function `set eat`, call it in the **ELSE IF** statement that checks if button `B` is pressed.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
if (input.buttonIsPressed("A")) {
|
||||
setSleep()
|
||||
basic.pause(5000)
|
||||
} else if (input.buttonIsPressed("B")) {
|
||||
setEat()
|
||||
}
|
||||
else {
|
||||
setAwake()
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
### @video td/videos/digital-pet-3
|
||||
|
||||
Have your pet tell you when it is going to sleep! Do this inside of the **IF** statement that checks if button `A` is pressed before you call the function `set sleep`.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
if (input.buttonIsPressed("A")) {
|
||||
basic.showString("I am going to sleep.", 150) // ***
|
||||
setSleep()
|
||||
basic.pause(5000)
|
||||
} else if (input.buttonIsPressed("B")) {
|
||||
setEat()
|
||||
}
|
||||
else {
|
||||
setAwake()
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 4
|
||||
|
||||
### @video td/videos/digital-pet-4
|
||||
|
||||
Now, how about we keep track of how many times our pet eats? Add a global variable called `feed` that keeps track of how many times you feed your pet. If button `B` is pressed, increment `feed` by one. Add a condition `on shake` to check your total.
|
||||
|
||||
```
|
||||
feed = 0 // ***
|
||||
basic.forever(() => {
|
||||
if (input.buttonIsPressed("A")) {
|
||||
basic.showString("I am going to sleep.", 150)
|
||||
setSleep()
|
||||
basic.pause(5000)
|
||||
} else if (input.buttonIsPressed("B")) {
|
||||
feed = feed + 1 // ***
|
||||
setEat()
|
||||
}
|
||||
else {
|
||||
setAwake()
|
||||
}
|
||||
})
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.showNumber(feed, 150) // ***
|
||||
}) // ***
|
||||
```
|
||||
|
||||
### Challenge 5
|
||||
|
||||
Program your pet to say that it is hungry after 60 seconds.
|
||||
|
||||
**Hint**: use `input->running time`
|
||||
|
60
olddocs/js/lessons/digital-pet/quiz-answers.md
Normal file
60
olddocs/js/lessons/digital-pet/quiz-answers.md
Normal file
@ -0,0 +1,60 @@
|
||||
# digital pet quiz answers
|
||||
|
||||
A display of pet images for the BBC micro:bit
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [digital pet tutorial](/lessons/digital-pet/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What is a 'function'?
|
||||
|
||||
<br/>
|
||||
|
||||
A function is a unit of code that performs a specific task and may return a result.
|
||||
|
||||
## 2. Write the steps to create the function called set awake()
|
||||
|
||||
<br/>
|
||||
|
||||
Click on "+ add new" and then "function". Click on the function name (by default it is "set awake"), and rename it to "set awake()".
|
||||
|
||||
## 3. Write the code inside the function "set awake()" that shows an image of the pet awake
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
let img = images.createImage(`
|
||||
. # . # .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. # # # .
|
||||
. . . . .
|
||||
`)
|
||||
img.showImage(0)
|
||||
```
|
||||
|
||||
## 4. Write the steps to create the function called set sleep, function set sleep()
|
||||
|
||||
<br/>
|
||||
|
||||
Click on "+ add new" and then "function". Click on the function name (by default it is "set sleep"), and rename it to "set sleep()".
|
||||
|
||||
## 5. Write the code inside the function "set sleep()" that shows an image of the pet asleep
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
img = images.createImage(`
|
||||
# # . # #
|
||||
. . # . .
|
||||
. . . . .
|
||||
. # # # .
|
||||
. . . . .
|
||||
`)
|
||||
img.showImage(0)
|
||||
```
|
||||
|
32
olddocs/js/lessons/digital-pet/quiz.md
Normal file
32
olddocs/js/lessons/digital-pet/quiz.md
Normal file
@ -0,0 +1,32 @@
|
||||
# digital pet quiz
|
||||
|
||||
A display of pet images for the BBC micro:bit
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [digital pet tutorial](/lessons/digital-pet/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What is a 'function'?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the steps to create the function called set awake()
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the code inside the function "set awake()" that shows an image of the pet awake
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the steps to create the function called set sleep, function set sleep()
|
||||
|
||||
<br/>
|
||||
|
||||
## 5. Write the code inside the function "set sleep()" that shows an image of the pet asleep
|
||||
|
||||
<br/>
|
||||
|
87
olddocs/js/lessons/flipping-bird/challenges.md
Normal file
87
olddocs/js/lessons/flipping-bird/challenges.md
Normal file
@ -0,0 +1,87 @@
|
||||
# flipping bird challenges
|
||||
|
||||
Coding challenges for flipping bird. #docs
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/lessons/flipping-bird/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
counter = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
counter = counter + 1
|
||||
if (math.mod(counter, 2) == 1) {
|
||||
basic.plotImage(`
|
||||
# # . # #
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
We handled the case of when `math->mod(counter,2) = 1`. We haven't done anything when the remainder is 0! Add an if statement to handle this case.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
counter = counter + 1
|
||||
if (math.mod(counter, 2) == 1) {
|
||||
basic.plotImage(`
|
||||
# # . # #
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
if (math.mod(counter, 2) == 0) {
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
### @video td/videos/flipping-bird-2
|
||||
|
||||
Inside of that `if` statement you created in challenge 1, add `basic->plot image()` and display an upside down flying bird.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
counter = counter + 1
|
||||
if (math.mod(counter, 2) == 1) {
|
||||
basic.plotImage(`
|
||||
# # . # #
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
if (math.mod(counter, 2) == 0) {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
# # . # #
|
||||
`) // ***
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
* `Run` the code to see if it works as expected.
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
Display a check mark and question mark instead of flipping birds. Or better yet, come up with your own pair of opposites to display!
|
||||
|
50
olddocs/js/lessons/flipping-bird/quiz-answers.md
Normal file
50
olddocs/js/lessons/flipping-bird/quiz-answers.md
Normal file
@ -0,0 +1,50 @@
|
||||
# flipping bird quiz answers
|
||||
|
||||
use modulo with a conditional.
|
||||
|
||||
This is the answer key for the [flipping bird quiz](/lessons/flipping-bird/quiz).
|
||||
|
||||
## 1. What does "modulo" mean in math?
|
||||
|
||||
<br/>
|
||||
|
||||
Modulo (or Mod) is the remainder of a division problem.
|
||||
|
||||
## 2. Consider the following code
|
||||
|
||||
If the rectangle below represents the BBC micro:bit, shade in the LEDs that show the value being stored into the **global variable**, `count`. Explain why that particular area is shaded.
|
||||
|
||||
```
|
||||
count = 1
|
||||
count_ = count_ + 2
|
||||
```
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||

|
||||
|
||||
The variable `count` is now equal to 3.
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Consider the following directions
|
||||
|
||||
Modulo (Mod) tells us what the remainder of a division is. For example, `15 mod 4 is 3` since 15 divided by 4 has a remainder of 3.
|
||||
|
||||
```
|
||||
count = 12
|
||||
count = math.mod(count, 5)
|
||||
```
|
||||
|
||||
If the rectangle below represents the BBC micro:bit, shade in the LEDs that show the value being stored into the **global variable**, `count`. Explain why that particular area is shaded.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||

|
||||
|
||||
The display will show `2` because the remainder of 12 divided by 5 is 2.
|
||||
|
60
olddocs/js/lessons/flipping-bird/quiz.md
Normal file
60
olddocs/js/lessons/flipping-bird/quiz.md
Normal file
@ -0,0 +1,60 @@
|
||||
# flipping bird quiz
|
||||
|
||||
use modulo with a conditional.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [flipping bird tutorial](/lessons/flipping-bird/tutorial).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What does "modulo" mean in math?
|
||||
|
||||
## 2. Consider the following directions
|
||||
|
||||
If the rectangle below represents the BBC micro:bit, shade in the LEDs that show the value being stored into the **global variable**, `count`.
|
||||
|
||||
```
|
||||
count = 1
|
||||
```
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Consider the following code
|
||||
|
||||
If the rectangle below represents the BBC micro:bit, shade in the LEDs that show the value being stored into the **global variable**, `count`. Explain why that particular area is shaded.
|
||||
|
||||
```
|
||||
count = 1
|
||||
count_ = count_ + 2
|
||||
```
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Consider the following directions
|
||||
|
||||
Modulo (Mod) tells us what the remainder of a division is. For example, `15 mod 4 is 3` since 15 divided by 4 has a remainder of 3.
|
||||
|
||||
```
|
||||
count = 12
|
||||
count = math.mod(count, 5)
|
||||
```
|
||||
|
||||
If the rectangle below represents the BBC micro:bit, shade in the LEDs that show the value being stored into the **global variable**, `count`. Explain why that particular area is shaded.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
41
olddocs/js/lessons/for-loop/challenges.md
Normal file
41
olddocs/js/lessons/for-loop/challenges.md
Normal file
@ -0,0 +1,41 @@
|
||||
# looper challenges
|
||||
|
||||
These challenges will allow you to create a counter from 0-5 and then from 5-0. #docs
|
||||
|
||||
### Challenge 0
|
||||
|
||||
Welcome! This [guided tutorial](/bcvgkf) will assist you with the following activity:
|
||||
|
||||
```
|
||||
for (let i = 0; i < 6; i++) {
|
||||
led.showNumber(i, 150)
|
||||
basic.pause(2000)
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Go through the loop faster by changing the length of the pause. This is the line you will be editing: `basic->pause(2000)`
|
||||
|
||||
```
|
||||
for (let i1 = 0; i1 < 6; i1++) {
|
||||
basic.showNumber(i1, 150)
|
||||
basic.pause(500) // ***
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Now, let's count down from 5 instead of counting up to 5. Change the line `basic->show number(i, 150)` to `basic->show number(5 - i, 150)`.
|
||||
|
||||
```
|
||||
for (let i2 = 0; i2 < 6; i2++) {
|
||||
basic.showNumber(5 - i2, 150) // ***
|
||||
basic.pause(2000)
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Have the number count up in 2's from zero. It should go: 0, 2, 4, 6, 8, 10.
|
||||
|
56
olddocs/js/lessons/glowing-image/challenges.md
Normal file
56
olddocs/js/lessons/glowing-image/challenges.md
Normal file
@ -0,0 +1,56 @@
|
||||
# glowing mountain challenges
|
||||
|
||||
These challenges will help you display a glowing image that fades in and out at different speeds. #docs
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
[This guided tutorial](https://test.microbit.co.uk/td/lessons/glowing-mountain/tutorial) will teach you how to create a mountain that fades out.
|
||||
|
||||
```
|
||||
images.createImage(`
|
||||
. . . . .
|
||||
. . # . .
|
||||
. # # # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
`).showImage(0)
|
||||
led.fadeOut(700)
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
Now, let's add `basic->pause(1000)` after the fade in so that there will be a 1000 millisecond delay after the fade out.
|
||||
|
||||
```
|
||||
images.createImage(`
|
||||
. . . . .
|
||||
. . # . .
|
||||
. # # # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
`).showImage(0)
|
||||
led.fadeOut(700)
|
||||
basic.pause(1000) // ***
|
||||
```
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
After the pause, let's add `led->fade in(2000)` so that we can create a glowing effect.
|
||||
|
||||
```
|
||||
images.createImage(`
|
||||
. . . . .
|
||||
. . # . .
|
||||
. # # # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
`).showImage(0)
|
||||
led.fadeOut(700)
|
||||
basic.pause(1000)
|
||||
led.fadeIn(2000) // ***
|
||||
```
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
Now add another `basic->pause(1000)` and `led->fade out(900)` so that the mountain can fade out again.
|
||||
|
64
olddocs/js/lessons/glowing-mountain/challenges.md
Normal file
64
olddocs/js/lessons/glowing-mountain/challenges.md
Normal file
@ -0,0 +1,64 @@
|
||||
# glowing sword challenges
|
||||
|
||||
These challenges will help you display a glowing image that fades in and out at different speeds. #docs
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
### @video vimeo/134649269
|
||||
|
||||
[This guided tutorial](https://test.microbit.co.uk/td/lessons/glowing-mountain/tutorial) will teach you how to create a mountain that fades out.
|
||||
|
||||
```
|
||||
images.createImage(`
|
||||
. . . . #
|
||||
# . . # .
|
||||
# # # . .
|
||||
. # # . .
|
||||
# . # # .
|
||||
`).showImage(0)
|
||||
led.fadeOut(700)
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
Now, let's add `basic->pause(1000)` after the fade in so that there will be a 1000 millisecond delay after the fade out.
|
||||
|
||||
```
|
||||
images.createImage(`
|
||||
. . . . #
|
||||
# . . # .
|
||||
# # # . .
|
||||
. # # . .
|
||||
# . # # .
|
||||
`).showImage(0)
|
||||
led.fadeOut(700)
|
||||
basic.pause(1000) // ***
|
||||
```
|
||||
|
||||
* Run the code to see if it works as expected.
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
### @video vimeo/134674595
|
||||
|
||||
After the pause, let's add `led->fade in(2000)` so that we can create a glowing effect.
|
||||
|
||||
```
|
||||
images.createImage(`
|
||||
. . . . #
|
||||
# . . # .
|
||||
# # # . .
|
||||
. # # . .
|
||||
# . # # .
|
||||
`).showImage(0)
|
||||
led.fadeOut(700)
|
||||
basic.pause(1000)
|
||||
led.fadeIn(2000) // ***
|
||||
```
|
||||
|
||||
* Run the code to see if it works as expected.
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
Now add another `basic->pause(1000)` and `led->fade out(900)` so that the mountain can fade out again.
|
||||
|
97
olddocs/js/lessons/glowing-sword.md
Normal file
97
olddocs/js/lessons/glowing-sword.md
Normal file
@ -0,0 +1,97 @@
|
||||
# glowing sword lesson
|
||||
|
||||
make a glowing sword.
|
||||
|
||||
### @video td/videos/glowing-sword-0
|
||||
|
||||
## Topic
|
||||
|
||||
Fade Out
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/glowing-sword/activity)
|
||||
* [quiz](/lessons/glowing-sword/quiz)
|
||||
* [quiz answers](/lessons/glowing-sword/quiz-answers)
|
||||
* [challenges](/lessons/glowing-sword/challenges)
|
||||
* [tutorial](/lessons/glowing-sword/tutorial)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to manipulate an image through **fade out**, `led->fade out` to gradually decrease the LED screen brightness until the LED lights are turned off. We will be learning how to fade an image using simple commands, such as plot image, fade out, pause, and fade in.
|
||||
|
||||
## What the teacher needs to know/QuickStart Computing Glossary
|
||||
|
||||
* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective.
|
||||
* Computational thinking: Thinking about systems or problems in a way that allows computer systems to be used to model or solve these.
|
||||
* Hardware: The physical systems and components of digital devices; see also software.
|
||||
* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program.
|
||||
* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character.
|
||||
* Sequence: To place program instructions in order, with each executed one after the other.
|
||||
* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games.
|
||||
|
||||
## Documentation
|
||||
|
||||
* **plot image** : [read more...](/reference/led/plot-image)
|
||||
* **fade out** : [read more...](/reference/led/fade-out)
|
||||
* **pause** : [read more...](/reference/basic/pause)
|
||||
* **fade in** : [read more...](/reference/led/fade-in)
|
||||
|
||||
## Resources
|
||||
|
||||
* Activity: [tutorial](/lessons/glowing-sword/tutorial)
|
||||
* Activity: [quiz](/lessons/glowing-sword/quiz)
|
||||
* Extended Activity: [challenges](/lessons/glowing-sword/challenges)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to plot an image
|
||||
* learn how to gradually decrease the LED screen brightness until the LED lights are turned off
|
||||
* pause your code for the specified number of milliseconds
|
||||
* learn how to gradually increase the LED screen brightness until the LED lights are turned on
|
||||
|
||||
## Links to the National Curriculum Programmes of Study for Computing
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Uses diagrams to express solutions.(AB)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Selects the appropriate data types(AL) (AB)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organizes, and presents data and information in digital content (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
|
||||
* Recognises ethical issues surrounding the application of information technology beyond school.
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/lessons/glowing-sword/tutorial)
|
||||
* [quiz](/lessons/lucky-7/quiz)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/lessons/glowing-sword/challenges)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/lessons/glowing-sword/challenges)
|
||||
|
||||
## Intended follow on
|
||||
|
||||
Publish script to the classroom.
|
||||
|
63
olddocs/js/lessons/glowing-sword/activity.md
Normal file
63
olddocs/js/lessons/glowing-sword/activity.md
Normal file
@ -0,0 +1,63 @@
|
||||
# glowing sword activity
|
||||
|
||||
Make glowing sword.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
### @video td/videos/glowing-sword-0
|
||||
|
||||
In this activity, we will learn how to fade in and out the screen to create a glowing animation. Let's get started!
|
||||
|
||||
### ~
|
||||
|
||||
Let's start by adding the code to display an image. Use `basic->plot image` to draw your favorite image.
|
||||
|
||||
```
|
||||
basic.plotImage(`
|
||||
. . . . #
|
||||
# . . # .
|
||||
. # # . .
|
||||
. # # . .
|
||||
# . . # .
|
||||
`) // ***
|
||||
```
|
||||
|
||||
We can control the brightness of the LED screen with code. That's just what we need to create a **glowing** animation: first we **fade out**, then **fade in**. Add a new line of code to **fade out** the screen.
|
||||
|
||||
```
|
||||
basic.plotImage(`
|
||||
. . . . #
|
||||
# . . # .
|
||||
. # # . .
|
||||
. # # . .
|
||||
# . . # .
|
||||
`)
|
||||
led.fadeOut(700) // ***
|
||||
```
|
||||
|
||||
Run your script to make sure it works as expected then add another line of code to **fade in** the screen.
|
||||
|
||||
```
|
||||
led.fadeIn(700)
|
||||
```
|
||||
|
||||
Finally, add a `basic->forever` loop and move the fade out and fade in code into the forever to repeat the glow pattern.
|
||||
|
||||
```
|
||||
basic.plotImage(`
|
||||
. . . . #
|
||||
# . . # .
|
||||
. # # . .
|
||||
. # # . .
|
||||
# . . # .
|
||||
`)
|
||||
led.fadeOut(700) // ***
|
||||
led.fadeIn(700) // ***
|
||||
```
|
||||
|
||||
### ~avatar boothing
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/glowing-sword/challenges)!
|
||||
|
||||
### ~
|
||||
|
62
olddocs/js/lessons/glowing-sword/challenges.md
Normal file
62
olddocs/js/lessons/glowing-sword/challenges.md
Normal file
@ -0,0 +1,62 @@
|
||||
# glowing sword challenges
|
||||
|
||||
Coding challenges for the glowing sword tutorial. #docs
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the [glowing sword](/lessons/glowing-sword/activity) activity and your code will look like this:
|
||||
|
||||
```
|
||||
basic.plotImage(`
|
||||
. . . . #
|
||||
# . . # .
|
||||
. # # . .
|
||||
. # # . .
|
||||
# . . # .
|
||||
`)
|
||||
led.fadeOut(700)
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Now, let's add `basic->pause(1000)` after the fade in so that there will be a 1000 millisecond (1 second) delay after the fade out.
|
||||
|
||||
```
|
||||
basic.plotImage(`
|
||||
. . . . #
|
||||
# . . # .
|
||||
. # # . .
|
||||
. # # . .
|
||||
# . . # .
|
||||
`)
|
||||
led.fadeOut(700)
|
||||
basic.pause(1000) // ***
|
||||
```
|
||||
|
||||
* `run main` the code to see if it works as expected.
|
||||
|
||||
### Challenge 2
|
||||
|
||||
### @video td/videos/glowing-sword-2
|
||||
|
||||
After the pause, let's add `led->fade in(2000)` so that we can create a glowing effect.
|
||||
|
||||
```
|
||||
basic.plotImage(`
|
||||
. . . . #
|
||||
# . . # .
|
||||
. # # . .
|
||||
. # # . .
|
||||
# . . # .
|
||||
`)
|
||||
led.fadeOut(700)
|
||||
basic.pause(1000)
|
||||
led.fadeIn(2000) // ***
|
||||
```
|
||||
|
||||
* `run main` the code to see if it works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Now add another `basic->pause(1000)` and `led->fade out(900)` so that the sword can fade out again.
|
||||
|
48
olddocs/js/lessons/glowing-sword/quiz-answers.md
Normal file
48
olddocs/js/lessons/glowing-sword/quiz-answers.md
Normal file
@ -0,0 +1,48 @@
|
||||
# glowing sword quiz answers
|
||||
|
||||
The answers for the glowing sword quiz.
|
||||
|
||||
This is the answer key for the [glowing sword quiz](/lessons/glowing-sword/quiz).
|
||||
|
||||
## 1. What is "fade out" ?
|
||||
|
||||
Fade out is a method that gradually decreases the LED screen brightness until the LED lights are turned off.
|
||||
|
||||
## 2. Consider the following code
|
||||
|
||||
```
|
||||
basic.plotImage(`
|
||||
. . . . #
|
||||
# . . # .
|
||||
. # # . .
|
||||
. # # . .
|
||||
# . . # .
|
||||
`)
|
||||
led.fadeOut(700)
|
||||
```
|
||||
|
||||
Rewrite the second line of code to decrease the speed of the fade out for the longest amount of time (Hint: 1000 milliseconds is longest amount of time for a fade out).
|
||||
|
||||
<br/>
|
||||
|
||||
led->fade out(1000)
|
||||
|
||||
## 4. Consider the following code
|
||||
|
||||
```
|
||||
basic.plotImage(`
|
||||
. . . . #
|
||||
# . . # .
|
||||
. # # . .
|
||||
. # # . .
|
||||
# . . # .
|
||||
`)
|
||||
led.fadeOut(1000)
|
||||
```
|
||||
|
||||
What will cause the image to fade back in twice as fast as it faded out?
|
||||
|
||||
<br/>
|
||||
|
||||
led->fade in(500)
|
||||
|
46
olddocs/js/lessons/glowing-sword/quiz.md
Normal file
46
olddocs/js/lessons/glowing-sword/quiz.md
Normal file
@ -0,0 +1,46 @@
|
||||
# glowing sword quiz
|
||||
|
||||
make a glowing sword.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [glowing sword tutorial](/lessons/glowing-sword/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Describe what "led -> fade out" does?
|
||||
|
||||
<br />
|
||||
|
||||
## 2. Rewrite the second line of code to decrease the speed of the fade out for the longest amount of time Hint: 1000 milliseconds is longest amount of time for a fade out.
|
||||
|
||||
```
|
||||
basic.plotImage(`
|
||||
. . . . #
|
||||
# . . # .
|
||||
. # # . .
|
||||
. # # . .
|
||||
# . . # .
|
||||
`)
|
||||
led.fadeOut(700)
|
||||
```
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. What will cause the image to fade back in twice as fast as it faded out?
|
||||
|
||||
```
|
||||
basic.plotImage(`
|
||||
. . . . #
|
||||
# . . # .
|
||||
. # # . .
|
||||
. # # . .
|
||||
# . . # .
|
||||
`)
|
||||
led.fadeOut(1000)
|
||||
```
|
||||
|
||||
<br/>
|
||||
|
24
olddocs/js/lessons/hack-your-headphones.md
Normal file
24
olddocs/js/lessons/hack-your-headphones.md
Normal file
@ -0,0 +1,24 @@
|
||||
# hack your headphones lesson
|
||||
|
||||
display beautiful images on the BBC micro:bit.
|
||||
|
||||
## Topic
|
||||
|
||||
Hack your headphone
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [activity](/lessons/hack-your-headphones/activity)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to convert your BBC micro:bit into a music player using pins P0 and GND, headphones (or speakers), as well as crocodile clips (or spring clips).
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to setup the BBC micro:bit with headphones to play music
|
||||
|
108
olddocs/js/lessons/jailbreak.md
Normal file
108
olddocs/js/lessons/jailbreak.md
Normal file
@ -0,0 +1,108 @@
|
||||
# jailbreak lesson
|
||||
|
||||
break out of a counting loop by pressing button "A".
|
||||
|
||||
### @video td/videos/jailbreak-0
|
||||
|
||||
## Topic
|
||||
|
||||
Break
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [tutorial](/lessons/jailbreak/tutorial)
|
||||
* [quiz](/lessons/jailbreak/quiz)
|
||||
* [quiz answers](/lessons/jailbreak/quiz-answers)
|
||||
* [challenges](/lessons/jailbreak/challenges)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to create a **break**, `break` to exit a while or for loop before the loop is complete. We will be learning how to create a break using global variables, Boolean, If (conditionals), a While Loop as well as simple commands, such as show string, plot image, show number, and pause.
|
||||
|
||||
## Documentation
|
||||
|
||||
* **Global Variable** : [read more...](/js/data)
|
||||
* **Boolean** : [read more...](/reference/types/boolean)
|
||||
* **On Button Pressed** : [read more...](/reference/input/on-button-pressed)
|
||||
* **While Loop** : [read more...](/js/while)
|
||||
* **Break** : [read more...](/js/break)
|
||||
* **If (Conditional)** : [read more...](/reference/logic/if)
|
||||
* **Show String** : [read more...](/reference/basic/show-string)
|
||||
* **Plot Image ** : [read more...](/reference/led/plot-image)
|
||||
* **Show Number** : [read more...](/reference/basic/show-number)
|
||||
* **Pause** : [read more...](/reference/basic/pause)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create global variables to store data so that you can use it later in your code, functions, and in nested code blocks
|
||||
* learn how to use the variables to declare a new local Boolean variable that will have one of two possible values: true or false
|
||||
* learn how to run code when an input button is pressed
|
||||
* learn how to repeat code while a condition is true
|
||||
* learn how to exit a while loop before the loop is complete
|
||||
* learn how to conditionally run code depending on whether a condition is true or not
|
||||
* learn how to show a string on the LED screen one character at a time
|
||||
* learn how to turn on LED lights on the LED screen
|
||||
* learn how to show a number on the LED screen, one digit at a time
|
||||
* learn how to pause your code for the specified number of milliseconds
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL)
|
||||
* Uses diagrams to express solutions.(AB)
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
|
||||
* Recognises that different solutions exist for the same problem (AL) (AB) Understands that iteration is the repetition of a process such as a loop (AL)
|
||||
* Recognises that different algorithms exist for the same problem (AL) (GE)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Declares and assigns variables(AB)
|
||||
* Uses post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL)
|
||||
* Understands the difference between, and appropriately uses if and if, then and else statements(AL)
|
||||
* Uses a variable and relational operators within a loop to govern termination (AL) (GE)
|
||||
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
|
||||
* Selects the appropriate data types(AL) (AB
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV)
|
||||
* Defines data types: real numbers and Boolean (AB)
|
||||
|
||||
#### Hardware & Processing
|
||||
|
||||
* Knows that computers collect data from various input devices, including sensors and application software (AB)
|
||||
|
||||
#### Communication Networks
|
||||
|
||||
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organizes, and presents data and information in digital content (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
|
||||
* Recognises ethical issues surrounding the application of information technology beyond school.
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/lessons/jailbreak/tutorial)
|
||||
* [quiz](/lessons/jailbreak/quiz)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/lessons/jailbreak/challenges)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/lessons/jailbreak/challenges)
|
||||
|
104
olddocs/js/lessons/jailbreak/challenges.md
Normal file
104
olddocs/js/lessons/jailbreak/challenges.md
Normal file
@ -0,0 +1,104 @@
|
||||
# jailbreak challenges
|
||||
|
||||
Coding challenges for the jailbreak tutorial.#docs
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/lessons/jailbreak/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
count = 0
|
||||
shouldBreak = false
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
shouldBreak = true
|
||||
})
|
||||
while (true) {
|
||||
if (shouldBreak) {
|
||||
basic.showString("I'M OUT!", 150)
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
. # . # .
|
||||
. . . . .
|
||||
# . . . #
|
||||
. # # # .
|
||||
`)
|
||||
break
|
||||
}
|
||||
count = count + 1
|
||||
basic.showNumber(count, 150)
|
||||
basic.pause(1000)
|
||||
}
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
Try to remove the `break` in the `if` loop. What problem does this create?
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
Now let's resume the timer again once button `B` is pressed! To do so, begin by creating a condition to know when button `B` is pressed.
|
||||
|
||||
```
|
||||
// **. . .**
|
||||
while (true) {
|
||||
if (shouldBreak) {
|
||||
basic.showString("I'M OUT!", 150)
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
. # . # .
|
||||
. . . . .
|
||||
# . . . #
|
||||
. # # # .
|
||||
`)
|
||||
break
|
||||
}
|
||||
count = count + 1
|
||||
basic.showNumber(count, 150)
|
||||
basic.pause(1000)
|
||||
}
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
}) // ***
|
||||
```
|
||||
|
||||
Next, set `should break` back to false to indicate we want to run the `while` loop again.
|
||||
|
||||
```
|
||||
// **. . .**
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
shouldBreak = false // ***
|
||||
})
|
||||
```
|
||||
|
||||
And now copy the code from the previous while loop into the condition of `input->on button pressed("B")`. This will resume the counter.
|
||||
|
||||
```
|
||||
// **. . .**
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
shouldBreak = false
|
||||
while (true) {
|
||||
if (shouldBreak) {
|
||||
basic.showString("I'M OUT!", 150) // ***
|
||||
basic.plotImage(`
|
||||
. # . # .
|
||||
. # . # .
|
||||
. . . . .
|
||||
# . . . #
|
||||
. # # # .
|
||||
`) // ***
|
||||
break // ***
|
||||
}
|
||||
count = count + 1 // ***
|
||||
basic.showNumber(count, 150) // ***
|
||||
basic.pause(1000) // ***
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
Notice that the two `while` loops are identical. Clean up this redundancy in your code by creating another method and then placing the `while` loop in the method.
|
||||
|
46
olddocs/js/lessons/jailbreak/quiz-answers.md
Normal file
46
olddocs/js/lessons/jailbreak/quiz-answers.md
Normal file
@ -0,0 +1,46 @@
|
||||
# jailbreak quiz answers
|
||||
|
||||
break out of a counting loop by pressing button "A".
|
||||
|
||||
This is the answer key for the [jailbreak quiz](/lessons/jailbreak/quiz).
|
||||
|
||||
## 1. What does a 'break' statement do to a 'loop' ?
|
||||
|
||||
Exit a while or for loop before the loop is complete.
|
||||
|
||||
## 2. Consider the following directions
|
||||
|
||||
Write the line of code that will initialize a number `variable` to 0. Then create a second `variable` that tells us when we should `break` out of the loop. Set the `break` to false.
|
||||
|
||||
```
|
||||
count = 0
|
||||
shouldBreak = false
|
||||
```
|
||||
|
||||
## 3. Consider the following directions
|
||||
|
||||
Write the line of code to stop incrementing `count` when the button is pressed. (Hint: This will set `should break` to true).
|
||||
|
||||
```
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
shouldBreak = true
|
||||
})
|
||||
```
|
||||
|
||||
## 4. Consider the following directions
|
||||
|
||||
Add an `if` statement to determine whether or not we should break out of the loop. Then include the message "I'm Out!" and a smiley face **image** displayed. This will happen right before you `break` from the `while` loop. **Do not include the break **
|
||||
|
||||
```
|
||||
if (shouldBreak) {
|
||||
basic.showString("I'M OUT!", 150)
|
||||
images.createImage(`
|
||||
. # . # .
|
||||
. # . # .
|
||||
. . . . .
|
||||
# . . . #
|
||||
. # # # .
|
||||
`).showImage(0)
|
||||
}
|
||||
```
|
||||
|
34
olddocs/js/lessons/jailbreak/quiz.md
Normal file
34
olddocs/js/lessons/jailbreak/quiz.md
Normal file
@ -0,0 +1,34 @@
|
||||
# jailbreak quiz
|
||||
|
||||
break out of a counting loop by pressing button "A".
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [jailbreak tutorial](/lessons/jailbreak/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What does a 'break' statement do to a 'loop' ?
|
||||
|
||||
## 2. Consider the following directions
|
||||
|
||||
Write the line of code that will initialize a number variable to 0. Then create a second variable that tells us when we should `break` out of the loop. Set the `break` to false.
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Consider the following directions
|
||||
|
||||
Write the line of code to stop incrementing `count` when the button is pressed. (Hint: This will set `should break` to true).
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Consider the following directions
|
||||
|
||||
Add an `if` statement to determine whether or not we should break out of the loop. Then include the message "I'm Out!" and a smiley face **image** displayed. This will happen right before you `break` from the `while` loop. **Do not include the break **
|
||||
|
||||
<br />
|
||||
|
||||
<br/>
|
||||
|
8
olddocs/js/lessons/landslide.md
Normal file
8
olddocs/js/lessons/landslide.md
Normal file
@ -0,0 +1,8 @@
|
||||
# landslide
|
||||
|
||||
Turn a LED on and off. #docs
|
||||
|
||||
Detect and show an image when the micro:bit falls.
|
||||
|
||||
* [tutorial](/lessons/landslide/tutorial)
|
||||
* [challenges](/lessons/landslide/challenges)
|
77
olddocs/js/lessons/landslide/challenges.md
Normal file
77
olddocs/js/lessons/landslide/challenges.md
Normal file
@ -0,0 +1,77 @@
|
||||
# landslide challenges
|
||||
|
||||
Coding challenges for the landslide tutorial.
|
||||
|
||||
### ~avatar avatar fail
|
||||
|
||||
Don't drop me on the ground without protection! I'm very fragile. Ouch!
|
||||
|
||||
### ~
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/lessons/landslide/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
input.onFall(() => {
|
||||
images.createImage(`
|
||||
. . # . .
|
||||
. . # . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
`).showImage(0) // ***
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Add a pause within `input->on fall` after displaying `!`. This will allow us to display another image in the next challenge.
|
||||
|
||||
```
|
||||
input.onFall(() => {
|
||||
images.createImage(`
|
||||
. . # . .
|
||||
. . # . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
`).showImage(0)
|
||||
basic.pause(2000) // ***
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Create and show an `X` image after the pause from Challenge 1.
|
||||
|
||||
```
|
||||
input.onFall(() => {
|
||||
images.createImage(`
|
||||
. . # . .
|
||||
. . # . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
`).showImage(0)
|
||||
basic.pause(2000)
|
||||
images.createImage(`
|
||||
# . . . #
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
# . . . #
|
||||
`).showImage(0) // ***
|
||||
})
|
||||
```
|
||||
|
||||
* `Run` the program to see if it works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Now let's display a third image when the micro:bit falls! First, add `basic->pause(2000)` followed by another image of your choice. Be creative!
|
||||
|
116
olddocs/js/lessons/letter-up.md
Normal file
116
olddocs/js/lessons/letter-up.md
Normal file
@ -0,0 +1,116 @@
|
||||
# letter up lesson
|
||||
|
||||
create a guessing game that can be played with your friends.
|
||||
|
||||
## Topic
|
||||
|
||||
String Functions
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [tutorial](/lessons/letter-up/tutorial)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to create a guessing game with **global variables** `var str: "this is a string" ` and **strings functions**, ` var first char := str -> at(0) ` , to develop a sequence of characters and get a character within a string . We will be learning how to create a guessing game using local variables, strings functions, input on logo up, string related functions, on screen up, the game library as well as simple commands, such as show string and show number.
|
||||
|
||||
## What the teacher needs to know
|
||||
|
||||
* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective.
|
||||
* Command: An instruction for the computer to execute, written in a particular programming language.
|
||||
* Data: A structured set of numbers, possibly representing digitised text, images, sound or video, which can be processed or transmitted by a computer, also used for numerical (quantitative) information.
|
||||
* Decomposing: The process through which problems or systems are broken down into their component parts, each of which may then be considered separately.
|
||||
* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors.
|
||||
* Output: The information produced by a computer system for its user, typically on a screen, through speakers or on a printer, but possibly through the control of motors in physical systems.
|
||||
* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program.
|
||||
* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.
|
||||
* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character.
|
||||
* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met.
|
||||
* Sequence: To place program instructions in order, with each executed one after the other.
|
||||
* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games.
|
||||
* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the user’s name.
|
||||
|
||||
**QuickStart Computing Glossary
|
||||
|
||||
## Documentation
|
||||
|
||||
* **string** : [read more...](/reference/types/string)
|
||||
* **string functions** : [read more...](/reference/types/string-functions)
|
||||
* **show string** : [read more...](/reference/basic/show-string)
|
||||
* **local variables** : [read more...](/reference/variables/var)
|
||||
* **assignment operator** : [read more...](/reference/variables/assign)
|
||||
* **on logo up** [read more...](/functions/on-logo-up)
|
||||
* **on screen down** [read more...](/functions/on-screen-down)
|
||||
* **on screen up** [read more...](/functions/on-screen-up)
|
||||
* **math random** : [read more...](/js/math)
|
||||
* **game library** [read more...](/js/game-library)
|
||||
|
||||
## Resources
|
||||
|
||||
* Activity: [tutorial](/lessons/letter-up/tutorial)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create a sequences of characters
|
||||
* learn how to get a character within a string, using the specified index
|
||||
* learn how to show a string on the LED screen
|
||||
* learn how to create a local variable to store data so that you can use it later in your code
|
||||
* learn how to set and change the value of a local variable
|
||||
* learn how to register an event handler that executes whenever the LED screen is perpendicular to the ground and the BBC micro:bit logo is above the LED screen
|
||||
* learn how to register an event handler that executes whenever the LED screen is facing the floor
|
||||
* learn how to register an event handler that executes whenever the LED screen is facing the ceiling/sky
|
||||
* learn how to return a random number
|
||||
* learn how to use the game library to set the score, lives, and countdown
|
||||
|
||||
## Links to the National Curriculum Programmes of Study for Computing
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Declares and assigns variables(AB)
|
||||
* Uses a variable and relational operators within a loop to govern termination (AL) (GE)
|
||||
* Has practical experience of a high-level textual language, including using standard libraries when programming(AB) (AL)
|
||||
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
|
||||
* Selects the appropriate data types(AL) (AB
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Understands the difference between data and information(AB)
|
||||
* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV)
|
||||
|
||||
#### Hardware & Processing
|
||||
|
||||
* Knows that computers collect data from various input devices, including sensors and application software (AB)
|
||||
|
||||
#### Communication Networks
|
||||
|
||||
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organizes, and presents data and information in digital content (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
|
||||
* Uses criteria to evaluate the quality of solutions, can identify improvements making some refinements to the solution, and future solutions (EV)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/lessons/letter-up/tutorial)
|
||||
|
||||
## Intended follow on
|
||||
|
||||
Publish script to the classroom.
|
||||
|
128
olddocs/js/lessons/light-column-cascade/quiz.md
Normal file
128
olddocs/js/lessons/light-column-cascade/quiz.md
Normal file
@ -0,0 +1,128 @@
|
||||
# cascade quiz
|
||||
|
||||
Learn how to create a blinking LED script with a for loop.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [light column cascade tutorial](/js/light-column-cascade/tutorial).
|
||||
|
||||
Answer the questions below while working on or after you finish the tutorial. Pay attention to the dialogs!
|
||||
|
||||
## 1. What is a for loop?
|
||||
|
||||
## 2. Consider the following code
|
||||
|
||||
```
|
||||
for (let i = 0; i < 5; i++) {
|
||||
for (let j = 0; j < 5; j++) {
|
||||
led.plot(i, j)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately all the locations where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
## 3. Consider the following code
|
||||
|
||||
```
|
||||
for (let i1 = 0; i1 < 3; i1++) {
|
||||
for (let j1 = 0; j1 < 3; j1++) {
|
||||
led.plot(i1, j1)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately all the locations where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
## 4. Consider the following code
|
||||
|
||||
```
|
||||
for (let i2 = 0; i2 < 2; i2++) {
|
||||
for (let j2 = 0; j2 < 2; j2++) {
|
||||
led.plot(i2, j2)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
******************************
|
||||
|
||||
## KEY
|
||||
|
||||
## Directions
|
||||
|
||||
Answer the questions below while working on or after you finish the tutorial.
|
||||
|
||||
## 1. What is a for loop?
|
||||
|
||||
Answers will vary. In general, for loop refers to the code that repeats for a fixed number of times. We specify the LED using x, y coordinates.
|
||||
|
||||
## 2. Consider the following code
|
||||
|
||||
```
|
||||
for (let i3 = 0; i3 < 5; i3++) {
|
||||
for (let j3 = 0; j3 < 5; j3++) {
|
||||
led.plot(i3, j3)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates. The code lights on the LEDs
|
||||
|
||||
x - the x coordinate or horizontal position (0,1,2,3,4)
|
||||
|
||||
y - the y coordinate or vertical position (0,1,2,3,4)
|
||||
|
||||
## 3. Consider the following code
|
||||
|
||||
```
|
||||
for (let i4 = 0; i4 < 3; i4++) {
|
||||
for (let j4 = 0; j4 < 3; j4++) {
|
||||
led.plot(i4, j4)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates.
|
||||
|
||||
x - the x coordinate or horizontal position (0,1,2)
|
||||
|
||||
y - the y coordinate or vertical position (0,1,2)
|
||||
|
||||
## 4. Consider the following code
|
||||
|
||||
```
|
||||
for (let i5 = 0; i5 < 1; i5++) {
|
||||
for (let j5 = 0; j5 < 1; j5++) {
|
||||
led.plot(i5, j5)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
If the rectangle below represents a board that is 5 LEDs wide and 5 LEDs tall, place an X approximately where the LED is lighted. Explain why the LED is lighted there.
|
||||
|
||||

|
||||
|
||||
This code turns on specific LED. Plot turns on the specified LED on the LED screen. We specify the LED using x, y coordinates.
|
||||
|
||||
x - the x coordinate or horizontal position (0,1)
|
||||
|
||||
y - the y coordinate or vertical position (0,1)
|
||||
|
96
olddocs/js/lessons/line-of-fire.md
Normal file
96
olddocs/js/lessons/line-of-fire.md
Normal file
@ -0,0 +1,96 @@
|
||||
# line of fire lesson
|
||||
|
||||
create a game that relies on precise instincts and timing reflexes #if #.
|
||||
|
||||
### @video td/videos/timing-game-0
|
||||
|
||||
## Topic
|
||||
|
||||
Functions
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [tutorial](/lessons/line-of-fire/tutorial)
|
||||
* [quiz](/lessons/line-of-fire/quiz)
|
||||
* [quiz answers](/lessons/line-of-fire/quiz-answers)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to create **functions**, `function()` that perform a specific task and returns a result. We will be learning how to create a pong game using functions, global variable forever loop, global variables, Boolean, for loop, input on button pressed, if statements, as well as simple commands, such as plot, unplot and pause.
|
||||
|
||||
## Documentation
|
||||
|
||||
* **function** : [read more...](/js/function)
|
||||
* **return** : [read more...](/js/return)
|
||||
* **call** : [read more...](/js/call)
|
||||
* **global variable** : [read more...](/js/data)
|
||||
* **arithmetic operator** : [read more...](/reference/types/number)
|
||||
* **Boolean** : [read more...](/reference/types/boolean)
|
||||
* **forever** : [read more...](/reference/basic/forever)
|
||||
* **on button pressed** : [read more...](/reference/input/on-button-pressed)
|
||||
* **if** : [read more...](/reference/logic/if)
|
||||
* **clear screen** : [read more...](/reference/basic/clear-screen)
|
||||
* **show string** : [read more...](/reference/basic/show-string)
|
||||
* **plot** : [read more...](/reference/led/plot)
|
||||
* **unplot** : [read more...](/reference/led/unplot)
|
||||
* **pause** : [read more...](/reference/basic/pause)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create a function as a unit of code that performs a specific task and returns a result
|
||||
* learn how a return statement exits a function and returns a value to the code
|
||||
* learn how to call an existing function in your script
|
||||
* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks
|
||||
* learn how arithmetic operators operate on numbers and return a number
|
||||
* learn how a Boolean type has one of two possible values: true or false
|
||||
* learn how to repeat code in the background forever
|
||||
* learn how to conditionally run code depending on whether a condition is true or not
|
||||
* learn how to run code when an input button is pressed
|
||||
* learn how to show a string on the micro:bit's LED screen
|
||||
* learn how to turn on a LED light on the LED screen. Learn how to specify which LED using x, y coordinates
|
||||
* learn how to turn off a LED light on the LED screen. Learn how to specify which LED using x, y coordinates
|
||||
* learn how to pause your code for the specified number of milliseconds
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL)
|
||||
* Uses diagrams to express solutions.(AB)
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Declares and assigns variables(AB)
|
||||
* Uses post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL)
|
||||
* Understands the difference between, and appropriately uses if and if, then and else statements(AL)
|
||||
* Uses a variable and relational operators within a loop to govern termination (AL) (GE)
|
||||
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
|
||||
* Selects the appropriate data types(AL) (AB
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Defines data types: real numbers and Boolean (AB)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/lessons/line-of-fire/tutorial)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [quiz](/lessons/line-of-fire/quiz)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [quiz](/lessons/line-of-fire/quiz)
|
||||
|
140
olddocs/js/lessons/line-of-fire/quiz-answers.md
Normal file
140
olddocs/js/lessons/line-of-fire/quiz-answers.md
Normal file
@ -0,0 +1,140 @@
|
||||
# line of fire quiz answers
|
||||
|
||||
create a game that relies on precise instincts and timing reflexes.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [line of fire tutorial](/lessons/line-of-fire/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the names of the two Global Variable used to store the mode of the game. Which of these variables is set to true when we are displaying the score?
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
dotRunning = true
|
||||
displayingStats = false
|
||||
```
|
||||
|
||||
`displaying stats` is set to `true` when we are displaying the score.
|
||||
|
||||
## 2. Write the name of the Global Variable that represents the velocity and assign it to its initial value. Next, write the name of the Global Variable that represents the position of the dot and assign it to its initial value.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
dotX = 2
|
||||
dotXVelocity = 1
|
||||
```
|
||||
|
||||
## 3. Write the name of the two variables that keep track of the score, and assign them to their initial values.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
wins = 0
|
||||
losses = 0
|
||||
```
|
||||
|
||||
## 4. Write the For Loop that will plot the 'line of fire'.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
for (let i = 0; i < 5; i++) {
|
||||
led.plot(2, i)
|
||||
}
|
||||
```
|
||||
|
||||
## 5. If the dot is running, write the 'nested If statements' that will see when to change the direction by flipping the sign of the velocity. This occurs if the dot is on the edge of the board.
|
||||
|
||||
<br/>
|
||||
|
||||
**Questions 6-8 concern with moving the dot.**
|
||||
|
||||
## 6. Write the code to unplot the dot's current position. NOTE- if dotX was originally 2, then we must plot instead of unplot the dot's original position.
|
||||
|
||||
<br/>
|
||||
|
||||
Solution 1:
|
||||
|
||||
```
|
||||
if (dotX == 2) {
|
||||
led.plot(dotX, 2)
|
||||
} else {
|
||||
led.unplot(dotX, 2)
|
||||
}
|
||||
```
|
||||
|
||||
Alternative Solution:
|
||||
|
||||
```
|
||||
if (dotX != 2) {
|
||||
led.unplot(dotX, 2)
|
||||
} else {
|
||||
led.plot(dotX, 2)
|
||||
}
|
||||
```
|
||||
|
||||
## 7. Update its position variables by adding the velocity to the dot's current position.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
dotX = dotX + dotXVelocity
|
||||
```
|
||||
|
||||
## 8. Finally, plot the dot's new position. NOTE- if dotX is now 2, then we must unplot instead of plot the dot's new position.
|
||||
|
||||
<br/>
|
||||
|
||||
Solution 1:
|
||||
|
||||
```
|
||||
led.plot(dotX, 2)
|
||||
if (dotX == 2) {
|
||||
led.unplot(dotX, 2)
|
||||
}
|
||||
```
|
||||
|
||||
Alternative Solution:
|
||||
|
||||
```
|
||||
if (dotX == 2) {
|
||||
led.unplot(dotX, 2)
|
||||
} else {
|
||||
led.plot(dotX, 2)
|
||||
}
|
||||
```
|
||||
|
||||
## 9. Write the code that plots and unplots the dot 10 times when button A is pressed. Pause for 60 milliseconds in between plotting and unplotting the dot. (Don't include any if statements, and don't worry about updating 'dot running'.)
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
for (let j = 0; j < 10; j++) {
|
||||
led.plot(dotX, 2)
|
||||
basic.pause(60)
|
||||
led.unplot(dotX, 2)
|
||||
basic.pause(60)
|
||||
}
|
||||
```
|
||||
|
||||
## 10. Write the code that will display the score when button B is pressed. (Don't include any IF statements, and don't worry about updating 'dot running' and 'displaying stats'.)
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
basic.showString("WINS", 150)
|
||||
basic.showNumber(wins, 150)
|
||||
basic.pause(500)
|
||||
basic.showString("LOSSES", 150)
|
||||
basic.showNumber(losses, 150)
|
||||
basic.pause(500)
|
||||
})
|
||||
```
|
||||
|
84
olddocs/js/lessons/line-of-fire/quiz.md
Normal file
84
olddocs/js/lessons/line-of-fire/quiz.md
Normal file
@ -0,0 +1,84 @@
|
||||
# line of fire quiz
|
||||
|
||||
create a game that relies on precise instincts and timing reflexes.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [line of fire tutorial](/lessons/line-of-fire/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the names of the two Global Variable used to store the mode of the game. Which of these variables is set to true when we are displaying the score?
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the name of the Global Variable that represents the velocity and assign it to its initial value. Next, write the name of the Global Variable that represents the position of the dot and assign it to its initial value.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the name of the two variables that keep track of the score, and assign them to their initial values.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the For Loop that will plot the 'line of fire'.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 5. If the dot is running, write the 'nested If statements' that will see when to change the direction by flipping the sign of the velocity. This occurs if the dot is on the edge of the board.
|
||||
|
||||
<br/>
|
||||
|
||||
**Questions 6-8 concern with moving the dot.**
|
||||
|
||||
## 6. Write the code to unplot the dot's current position. NOTE- if dot x was originally 2, then we must plot instead of unplot the dot's original position.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 7. Update its position variables by adding the velocity to the dot's current position.
|
||||
|
||||
<br/>
|
||||
|
||||
## 8. Finally, plot the dot's new position. NOTE- if dot x is now 2, then we must unplot instead of plot the dot's new position.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 9. Write the code that plots and unplots the dot 10 times when button A is pressed. Pause for 60 milliseconds in between plotting and unplotting the dot. (Don't include any if statements, and don't worry about updating 'dot running'.)
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 10. Write the code that will display the score when button B is pressed. (Don't include any IF statements, and don't worry about updating 'dot running' and 'displaying stats'.)
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
75
olddocs/js/lessons/logo-pointer/challenges.md
Normal file
75
olddocs/js/lessons/logo-pointer/challenges.md
Normal file
@ -0,0 +1,75 @@
|
||||
# magic logo challenges
|
||||
|
||||
These challenges will help you show arrows that point which way the logo is pointing! #docs
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
### @video vimeo/134638098
|
||||
|
||||
This [guided tutorial](/zysycw) will help you display an arrow pointing the direction the logo is oriented!
|
||||
|
||||
Let's display and upward pointing arrow when the logo is up!
|
||||
|
||||
```
|
||||
input.onLogoUp(() => {
|
||||
images.createImage(`
|
||||
. . # . .
|
||||
. # # # .
|
||||
# # # # #
|
||||
. . # . .
|
||||
. . # . .
|
||||
`).showImage(0)
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
How about when the logo is down? We should display the arrow pointing downward!
|
||||
|
||||
Let's start by adding a condition for if the logo is down.
|
||||
|
||||
```
|
||||
input.onLogoUp(() => {
|
||||
images.createImage(`
|
||||
. . # . .
|
||||
. # # # .
|
||||
# # # # #
|
||||
. . # . .
|
||||
. . # . .
|
||||
`).showImage(0)
|
||||
})
|
||||
input.onLogoDown(() => {
|
||||
}) // ***
|
||||
```
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
### @video vimeo/134639918
|
||||
|
||||
Now we need to display the arrow!
|
||||
|
||||
```
|
||||
input.onLogoUp(() => {
|
||||
images.createImage(`
|
||||
. . # . .
|
||||
. # # # .
|
||||
# # # # #
|
||||
. . # . .
|
||||
. . # . .
|
||||
`).showImage(0)
|
||||
})
|
||||
input.onLogoDown(() => {
|
||||
images.createImage(`
|
||||
. . # . .
|
||||
. . # . .
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`).showImage(0) // ***
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
Let's show a spinning arrow when the micro:bit is shaken. We can do this by adding an on shake condition and showing an animation of the arrow spinning!
|
||||
|
83
olddocs/js/lessons/looper/challenges.md
Normal file
83
olddocs/js/lessons/looper/challenges.md
Normal file
@ -0,0 +1,83 @@
|
||||
# looper challenges
|
||||
|
||||
Coding challenges for the looper tutorial. #docs
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/lessons/looper/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
for (let i = 0; i < 6; i++) {
|
||||
basic.showNumber(i, 150)
|
||||
basic.pause(2000)
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
### @video td/videos/looper-1
|
||||
|
||||
What if we want to count up to lucky number 7 instead? Let's do that by changing the ending value to `8` instead of `6`.
|
||||
|
||||
```
|
||||
for (let i1 = 0; i1 < 8; i1++) {
|
||||
basic.showNumber(i1, 150) // ***
|
||||
basic.pause(2000)
|
||||
}
|
||||
```
|
||||
|
||||
* Run the program now to see your changes.
|
||||
|
||||
### Challenge 2
|
||||
|
||||
### @video td/videos/looper-2
|
||||
|
||||
What about 9? Let's do that by changing the ending value to `10`.
|
||||
|
||||
```
|
||||
for (let i2 = 0; i2 < 10; i2++) {
|
||||
basic.showNumber(i2, 150)
|
||||
basic.pause(2000)
|
||||
}
|
||||
```
|
||||
|
||||
* Run your code to see the new counter.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
### @video td/videos/looper-3
|
||||
|
||||
Now let's start counting from `3` instead! Our for loop will always start at `0` so we simply add `3` to the `i` variable when passing it to `basic->show number`.
|
||||
|
||||
```
|
||||
for (let i3 = 0; i3 < 8; i3++) {
|
||||
basic.showNumber(i3 + 3, 150) // ***
|
||||
basic.pause(2000)
|
||||
}
|
||||
```
|
||||
|
||||
Run it on the simulator!
|
||||
|
||||
### Challenge 4
|
||||
|
||||
### @video td/videos/looper-4
|
||||
|
||||
Now, let's **count down from 9**. Change the line `basic->show number(i + 3, 150)` to `basic->show number(9 - i, 150)`.
|
||||
|
||||
```
|
||||
for (let i4 = 0; i4 < 10; i4++) {
|
||||
basic.showNumber(9 - i4, 150) // ***
|
||||
basic.pause(2000)
|
||||
}
|
||||
```
|
||||
|
||||
* Run the code to make sure it is doing what is expected.
|
||||
|
||||
### Challenge 5
|
||||
|
||||
After counting down from `9` let's show the string `BOOOM`!
|
||||
|
105
olddocs/js/lessons/looper/lesson.md
Normal file
105
olddocs/js/lessons/looper/lesson.md
Normal file
@ -0,0 +1,105 @@
|
||||
# looper lesson
|
||||
|
||||
Learn to control blinking LEDs.
|
||||
|
||||
### @video vimeo/134453504
|
||||
|
||||
## Topic
|
||||
|
||||
For loop - Blinking LED
|
||||
|
||||
## Quick links
|
||||
|
||||
* [tutorial](/lessons/looper/tutorial)
|
||||
* [quiz](/lessons/looper/quiz)
|
||||
* [quiz answers](/lessons/looper/quiz-answers)
|
||||
* [challenges](/lessons/looper/challenges)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to control a blinking LED. We will be learning how to create a blinking app using the for loop as well as simple commands, such as plot and pause.
|
||||
|
||||
## What the teacher needs to know
|
||||
|
||||
**Program:** A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.**
|
||||
|
||||
**Algorithm:** An unambiguous set of rules or a precise step-by-step guide to solve a problem or achieve a particular objective. The guided tutorial follows a algorithm and is a precise step-by-step guide to solve a problem**
|
||||
|
||||
**Loop:** A block of code repeated automatically under the program’s control. ** The blink program introduces a While Loop. While Loop is a while loop that will repeat code forever while - true.
|
||||
|
||||
**Command:** An instruction for the computer to execute, written in a particular programming language.**
|
||||
|
||||
**QuickStart Computing Glossary
|
||||
|
||||
## Documentation
|
||||
|
||||
* **plot**: [read more...](/reference/led/plot)
|
||||
* **pause**: [read more...](/reference/basic/pause)
|
||||
* **for**: [read more...](/reference/loops/for)
|
||||
|
||||
## Resources
|
||||
|
||||
* Activity: [tutorial](/lessons/looper/tutorial)
|
||||
* Activity: [quiz](/lessons/looper/quiz)
|
||||
* Extended Activity: [challenges](/lessons/looper/challenges)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to blink a light
|
||||
* create a for loop that will loop through each x-value, y-value from 0 to 4.
|
||||
* learn how to pause the light on and off
|
||||
* learn how to repeat turning on and off the light
|
||||
|
||||
## Links to the National Curriculum Programmes of Study for Computing
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs. (AL)
|
||||
* Understands that iteration is the repetition of a process such as a loop. (AL)
|
||||
* Represents solutions using a structured notation. (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals. (AL)
|
||||
* Uses a variable and relational operators within a loop to govern termination. (AL) (GE)
|
||||
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Understands the difference between data and information. (AB)
|
||||
* Defines data types: real numbers and Boolean. (AB)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organises and presents data and information in digital content. (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution. (EV)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 10 min.
|
||||
* [tutorial](/lessons/looper/tutorial)
|
||||
* [quiz](/lessons/looper/quiz)
|
||||
* assessment opportunities: loops, plot, pause, clear screen
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/lessons/looper/challenges)
|
||||
* assessment opportunities: loops, plot, pause, clear screen
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/lessons/looper/challenges)
|
||||
|
||||
## Intended follow on
|
||||
|
||||
Publish script to the classroom.
|
||||
|
99
olddocs/js/lessons/meteorite.md
Normal file
99
olddocs/js/lessons/meteorite.md
Normal file
@ -0,0 +1,99 @@
|
||||
# meteorite lesson
|
||||
|
||||
a game in which you must dodge the meteorites with your ship.
|
||||
|
||||
## Topic
|
||||
|
||||
Functions
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [tutorial](/lessons/meteorite/tutorial)
|
||||
* [quiz](/lessons/meteorite/quiz)
|
||||
* [quiz answers](/lessons/meteorite/quiz-answers)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to create **functions**, `function()` that perform a specific task and returns a result. We will be learning how to create a meteorite game using functions, forever loop, global variables, for loop, input on button pressed, if statements, math random, input on shake as well as simple commands, such as show string, show number, and pause.
|
||||
|
||||
## Documentation
|
||||
|
||||
* **function** : [read more...](/js/function)
|
||||
* **call** : [read more...](/js/call)
|
||||
* **global variable** : [read more...](/js/data)
|
||||
* **arithmetic operators** : [read more...](/reference/types/number)
|
||||
* **math random** : [read more...](/js/math)
|
||||
* **forever** : [read more...](/reference/basic/forever)
|
||||
* **for** : [read more...](/reference/loops/for)
|
||||
* **fade out** : [read more...](/reference/led/fade-out)
|
||||
* **fade in** : [read more...](/reference/led/fade-in)
|
||||
* **on button pressed** : [read more...](/reference/input/on-button-pressed)
|
||||
* **if** : [read more...](/reference/logic/if)
|
||||
* **show string** : [read more...](/reference/basic/show-string)
|
||||
* **show number** : [read more...](/reference/basic/show-number)
|
||||
* **show string** : [read more...](/reference/basic/show-string)
|
||||
* **plot** : [read more...](/reference/led/plot)
|
||||
* **plot all** : [read more...](/reference/led/plot-all)
|
||||
* **pause** : [read more...](/reference/basic/pause)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create a function as a unit of code that performs a specific task and returns a result
|
||||
* learn how to call an existing function in your script
|
||||
* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks
|
||||
* learn how arithmetic operators operate on numbers and return a number
|
||||
* learn how to return a random number
|
||||
* learn how to repeat code in the background forever
|
||||
* learn how to gradually decrease the LED screen brightness until the LED lights are turned off
|
||||
* learn how to gradually increase the LED screen brightness until the LED lights are turned on
|
||||
* learn how to conditionally run code depending on whether a condition is true or not
|
||||
* learn how to run code when an input button is pressed
|
||||
* learn how to show a number on the micro:bit's LED screen
|
||||
* learn how to show a string on the micro:bit's LED screen
|
||||
* learn how to turn on a LED light on the LED screen. Learn how to specify which LED using x, y coordinates
|
||||
* learn how to turn on all the 25 LEDs on the LED screen
|
||||
* learn how to pause your code for the specified number of milliseconds
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL)
|
||||
* Uses diagrams to express solutions.(AB)
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Declares and assigns variables(AB)
|
||||
* Uses post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL)
|
||||
* Understands the difference between, and appropriately uses if and if, then and else statements(AL)
|
||||
* Uses a variable and relational operators within a loop to govern termination (AL) (GE)
|
||||
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
|
||||
* Selects the appropriate data types(AL) (AB
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Defines data types: real numbers and Boolean (AB)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/lessons/meteorite/tutorial)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [quiz](/lessons/meteorite/quiz)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [quiz](/lessons/meteorite/quiz)
|
||||
|
88
olddocs/js/lessons/meteorite/quiz-answers.md
Normal file
88
olddocs/js/lessons/meteorite/quiz-answers.md
Normal file
@ -0,0 +1,88 @@
|
||||
# meteorite quiz answers
|
||||
|
||||
create the game meteorite.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
This is the answer key for the [meteorite quiz](/lessons/meteorite/quiz)
|
||||
|
||||
## 1. Write the code that sets up the position variables of meteorite 1. (Hint: look inside the function "initialize game".)
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
meteorite_1X = Math.random(5)
|
||||
meteorite_1Y = -4
|
||||
```
|
||||
|
||||
## 2. Write the code that plots the initial position of the ship. (Hint: look inside the function "initialize game".)
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
led.plot(shipLeftX, 4)
|
||||
led.plot(shipLeftX + 1, 4)
|
||||
```
|
||||
|
||||
## 3. Write the code that will detect if a meteorite 1 collided with the ship. (Hint: look inside the function "move meteorite 1".
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
if (meteorite_1X == 4 && (shipLeftX == meteorite_1X || shipLeftX + 1 == meteorite_1X)) {
|
||||
gameOver()
|
||||
}
|
||||
```
|
||||
|
||||
## 4. Write the code that increase the difficulty by making the game run faster.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
pauseDifficulty = (pauseDifficulty * 49) / 50
|
||||
```
|
||||
|
||||
## 5. Write the code that moves the ship left.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
led.unplot(shipLeftX + 1, 4)
|
||||
shipLeftX = shipLeftX - 1
|
||||
led.plot(shipLeftX, 4)
|
||||
```
|
||||
|
||||
## 6. Write the code that moves the ship right.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
led.unplot(shipLeftX, 4)
|
||||
shipLeftX = shipLeftX + 1
|
||||
led.plot(shipLeftX + 1, 4)
|
||||
```
|
||||
|
||||
## 7. Write the function that checks if moving the ship resulted in a collision with meteorite 1.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
if (shipLeftX == meteorite_1X && meteorite_1Y == 4) {
|
||||
gameOver()
|
||||
}
|
||||
```
|
||||
|
||||
## 8. Write the code that flashes all the LEDs thee times to create the effect of a crash. (Hint: look at the function "game over".)
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
led.plotAll()
|
||||
for (let i = 0; i < 3; i++) {
|
||||
led.fadeIn(400)
|
||||
led.fadeOut(400)
|
||||
}
|
||||
```
|
||||
|
44
olddocs/js/lessons/meteorite/quiz.md
Normal file
44
olddocs/js/lessons/meteorite/quiz.md
Normal file
@ -0,0 +1,44 @@
|
||||
# meteorite quiz
|
||||
|
||||
create the game meteorite.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [meteorite tutorial](/lessons/meteorite/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the code that sets up the position variables of meteorite 1. (Hint: look inside the function "initialize game".)
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the code that plots the initial position of the ship. (Hint: look inside the function "initialize game".)
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the code that will detect if a meteorite 1 collided with the ship. (Hint: look inside the function "move meteorite 1".
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the code that increase the difficulty by making the game run faster.
|
||||
|
||||
<br/>
|
||||
|
||||
## 5. Write the code that moves the ship left.
|
||||
|
||||
<br/>
|
||||
|
||||
## 6. Write the code that moves the ship right.
|
||||
|
||||
<br/>
|
||||
|
||||
## 7. Write the function that checks if moving the ship resulted in a collision with meteorite 1.
|
||||
|
||||
<br/>
|
||||
|
||||
## 8. Write the code that flashes all the LEDs thee times to create the effect of a crash. (Hint: look at the function "game over".)
|
||||
|
||||
<br/>
|
||||
|
112
olddocs/js/lessons/minesweeper.md
Normal file
112
olddocs/js/lessons/minesweeper.md
Normal file
@ -0,0 +1,112 @@
|
||||
# minesweeper lesson
|
||||
|
||||
A game that tests your memory for placing a LED mine then finding the hidden LED mine.
|
||||
|
||||
### @video td/videos/minesweeper-0
|
||||
|
||||
## Topic
|
||||
|
||||
Global Variables
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [tutorial](/lessons/minesweeper/tutorial)
|
||||
* [quiz](/lessons/minesweeper/quiz)
|
||||
* [quiz answers](/lessons/minesweeper/quiz-answers)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to create a minesweeper game with **plot**, `led->plot` , **unplot**, `led->unplot`, **global variables** to keep track of the coordinates that the player is selecting. We will be learning how to create a minesweeper game using global variables, if (conditionals), input on button pressed, math random as well as simple commands such as led plot, led unplot, show string, and pause.
|
||||
|
||||
## What the teacher needs to know
|
||||
|
||||
* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective.
|
||||
* Command: An instruction for the computer to execute, written in a particular programming language.
|
||||
* Data: A structured set of numbers, possibly representing digitised text, images, sound or video, which can be processed or transmitted by a computer, also used for numerical (quantitative) information.
|
||||
* Decomposing: The process through which problems or systems are broken down into their component parts, each of which may then be considered separately.
|
||||
* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors.
|
||||
* Output: The information produced by a computer system for its user, typically on a screen, through speakers or on a printer, but possibly through the control of motors in physical systems.
|
||||
* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program.
|
||||
* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.
|
||||
* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met.
|
||||
* Sequence: To place program instructions in order, with each executed one after the other.
|
||||
* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games.
|
||||
* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the user’s name.
|
||||
|
||||
**QuickStart Computing Glossary
|
||||
|
||||
## Documentation
|
||||
|
||||
* **global variables** : [read more...](/js/data)
|
||||
* **math random number** : [read more...](/js/math)
|
||||
* **plot** : [read more...](/reference/led/plot)
|
||||
* **unplot** : [read more...](/reference/led/unplot)
|
||||
* **on button pressed** : [read more...](/reference/input/on-button-pressed)
|
||||
* **if** : [read more...](/reference/logic/if)
|
||||
* **show string** : [read more...](/reference/basic/show-string)
|
||||
* **pause** : [read more...](/reference/basic/pause)
|
||||
|
||||
## Resources
|
||||
|
||||
* Activity: [tutorial](/lessons/minesweeper/tutorial)
|
||||
* Activity: [quiz](/lessons/minesweeper/quiz)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks
|
||||
* learn how to return a random number
|
||||
* learn how to turn on a LED light on the LED screen
|
||||
* learn how to turn off a LED light on the LED screen
|
||||
* learn how to run code when an input button is pressed
|
||||
* learn how to conditionally run code depending on whether a condition is true or not
|
||||
* learn how to show a string of the LED screen one character at a time (scrolling left to right)
|
||||
* learn how to pause your code for the specified number of milliseconds
|
||||
|
||||
## Links to the National Curriculum Programmes of Study for Computing
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL)
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Declares and assigns variables(AB)
|
||||
* Understands the difference between, and appropriately uses if and if, then and else statements(AL)
|
||||
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
|
||||
* Selects the appropriate data types(AL) (AB
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Understands the difference between data and information(AB)
|
||||
* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV)
|
||||
|
||||
#### Hardware & Processing
|
||||
|
||||
* Knows that computers collect data from various input devices, including sensors and application software (AB)
|
||||
|
||||
#### Communication Networks
|
||||
|
||||
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organizes, and presents data and information in digital content (AB)
|
||||
* Uses criteria to evaluate the quality of solutions, can identify improvements making some refinements to the solution, and future solutions (EV)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/lessons/minesweeper/tutorial)
|
||||
* [quiz](/lessons/minesweeper/quiz)
|
||||
|
55
olddocs/js/lessons/minesweeper/quiz-answers.md
Normal file
55
olddocs/js/lessons/minesweeper/quiz-answers.md
Normal file
@ -0,0 +1,55 @@
|
||||
# minesweeper quiz answers
|
||||
|
||||
make a game to test your memory for placing a LED mine then finding the hidden LED mine.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [minesweeper tutorial](/lessons/minesweeper/tutorial).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the code that randomly generates a number between 0 and 4 and stores that value in a global variable called 'mine x'.
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
mineX = Math.random(5)
|
||||
```
|
||||
|
||||
## 2. Write the code to plot the point with coordinates of (select x, select y) as shown. Your code should apply the concept of `led->plot ( , )`
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
selectX = 0
|
||||
selectY = 0
|
||||
led.plot(selectX, selectY)
|
||||
```
|
||||
|
||||
## 3. Write the code to plot the point with coordinates of (select x, select y) as shown. Your code should apply the concept of `led->plot ( , )`
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
selectX = 2
|
||||
selectY = 2
|
||||
led.plot(selectX, selectY)
|
||||
```
|
||||
|
||||
## 4. How do you check if a dot is one away from given x and y coordinates?
|
||||
|
||||
<br />
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
if (mineX + 2 > selectX && selectX > mineX - 2 && mineY + 2 > selectY && selectY > mineY - 2) {
|
||||
}
|
||||
```
|
||||
|
34
olddocs/js/lessons/minesweeper/quiz.md
Normal file
34
olddocs/js/lessons/minesweeper/quiz.md
Normal file
@ -0,0 +1,34 @@
|
||||
# minesweeper quiz
|
||||
|
||||
make a game to test your memory for placing a LED mine then finding the hidden LED mine.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [minesweeper tutorial](/lessons/minesweeper/tutorial).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the code that randomly generates a number between 0 and 4 and stores that value in a global variable called 'mine x'.
|
||||
|
||||
<br />
|
||||
|
||||
## 2. Write the code to plot the point with coordinates of (select x, select y) as shown. Your code should apply the concept of `led->plot ( , )`
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
||||
## 3. Write the code to plot the point with coordinates of (select x, select y) as shown. Your code should apply the concept of `led->plot ( , )`
|
||||
|
||||

|
||||
|
||||
<br />
|
||||
|
||||
## 4. How do you check if a dot is one away from given x and y coordinates?
|
||||
|
||||
<br />
|
||||
|
||||
<br />
|
||||
|
207
olddocs/js/lessons/number-psych/quiz-answers.md
Normal file
207
olddocs/js/lessons/number-psych/quiz-answers.md
Normal file
@ -0,0 +1,207 @@
|
||||
# number psych quiz answers
|
||||
|
||||
a 4-player game in which each player must outwit his opponents.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [number psych console tutorial](/lessons/number-psych-console/tutorial) and the [number psych controller tutorial](/lessons/number-psych-controller/tutorial).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
**Questions 1-9 are concerned with 'number pysch console tutorial'**
|
||||
|
||||
## 1. Create a 'collection of options' and save them in a local variable named 'options'.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
let options = (<number[]>[])
|
||||
```
|
||||
|
||||
## 2. Add the options '1', '3', and '5' into the local variable 'options'.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
options.push(1)
|
||||
options.push(3)
|
||||
options.push(5)
|
||||
```
|
||||
|
||||
## 3. Create a collection of scores and add four values of '0' into the collection.
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
let scores = (<number[]>[])
|
||||
```
|
||||
|
||||
## 4. Write the code that reads a byte that indicates a controller is asking for a player number. (Don't bother checking if the byte received is 255.) Next, write the code that transfers the player number to the controller.
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
scores = (<number[]>[])
|
||||
for (let i2 = 0; i2 < 4; i2++) {
|
||||
scores.push(0)
|
||||
}
|
||||
```
|
||||
|
||||
## 5.Write the code that transfers the three options.
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
for (let i5 = 0; i5 < 3; i5++) {
|
||||
micro_bitTransfer.transferByte(options[i5])
|
||||
basic.pause(200)
|
||||
}
|
||||
```
|
||||
|
||||
## 6.Write the code that requests each player to send their choice in the player order number. Don't worry about reading their choice. (Hint: look at the four loop with 'k' as the index.)
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
for (let k = 0; k < 4; k++) {
|
||||
micro_bitTransfer.transferByte(101 + k)
|
||||
}
|
||||
```
|
||||
|
||||
## 7.Write the code to create two collections. One collection ("choices") stores all the choices, while the other collection ("has common") stores whether or not the choice is unique. (If the choice is not unique, then "has common" will be set to true for that particular choice.)
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
let choices = (<number[]>[])
|
||||
let hasCommon = (<boolean[]>[])
|
||||
```
|
||||
|
||||
## 8. Write the code that compares each of the choices with each other. If the two choices are the same, then set the appropriate value inside 'has common' to true. (Hint: look at the for loops with 'l' and 'n' as their indexes.)
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
for (let l = 0; l < 4; l++) {
|
||||
for (let n = 0; n < 4; n++) {
|
||||
// ### ~avatar avatar
|
||||
// If the choice at `l` and `n` are the same, assuming `l` isn't equal to `n`, then there is a match.
|
||||
// {stcode}
|
||||
// MACRO: stcode
|
||||
// ### ~
|
||||
if (choices[l] == choices[n] && ! (l == n)) {
|
||||
// ### ~avatar avatar
|
||||
// Set `has common` at `l` and `n` to true.
|
||||
// {stcode}
|
||||
// MACRO: stcode
|
||||
// ### ~
|
||||
hasCommon[l] = true
|
||||
hasCommon[n] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 9. For each value inside 'has common', transfer a '1' if there is a match and transfer a '0' if there isn't a match. Add a pause of 100 milliseconds at the beginning of each transfer.)
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
for (let i4 = 0; i4 < 4; i4++) {
|
||||
basic.pause(100)
|
||||
if (hasCommon[i4]) {
|
||||
micro_bitTransfer.transferBit(1)
|
||||
} else {
|
||||
micro_bitTransfer.transferBit(0)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Questions 10-14 are concerned with 'number pysch controller tutorial'**
|
||||
|
||||
## 10. Write the code that asks for a player number if button 'A' is pressed on the BBC controller micro:bit.
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
if (gameMode == 0 && playerNumber == 0) {
|
||||
micro_bitTransfer.transferByte(255)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## 11. Write the code that adds the three transferred options to the "options" collection. (Hint: look at the for loop with 'k' as the index.)
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
for (let k1 = 0; k1 < 3; k1++) {
|
||||
options.push(micro_bitTransfer.readByte())
|
||||
}
|
||||
```
|
||||
|
||||
## 12. Write the code that detects when button 'B' is pressed. Inside this condition, if 'game mode' is 2, set 'game mode' back to 1 and plot a waiting image.
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
if (gameMode == 2) {
|
||||
gameMode = 1
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. # # # .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## 13. Create a while loop that first reads which controller the console micro:bit is requesting data from. Plot a waiting image, and then write an IF statement to check if the request corresponds to the controller. (Don't worry about writing anything inside the if statement).
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
while (true) {
|
||||
let playerRequest = micro_bitTransfer.readByte()
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. # # # .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`)
|
||||
if (playerRequest == 100 + playerNumber) {
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 14. Write the code that displays an "X" on the BBC micro:bit if 'result' is 1. Otherwise, display a "check mark".
|
||||
|
||||
<br />
|
||||
|
||||
```
|
||||
if (result == 1) {
|
||||
basic.plotImage(`
|
||||
# . . . #
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
# . . . #
|
||||
`)
|
||||
} else {
|
||||
basic.plotImage(`
|
||||
. . . . .
|
||||
. . . . #
|
||||
. . . # .
|
||||
# . # . .
|
||||
. # . . .
|
||||
`)
|
||||
}
|
||||
```
|
||||
|
116
olddocs/js/lessons/number-psych/quiz.md
Normal file
116
olddocs/js/lessons/number-psych/quiz.md
Normal file
@ -0,0 +1,116 @@
|
||||
# number psych quiz
|
||||
|
||||
a 4-player game in which each player must outwit his opponents.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [number psych console tutorial](/lessons/number-psych-console/tutorial) and the [number psych controller tutorial](/lessons/number-psych-controller/tutorial).
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
**Questions 1-9 are concerned with 'number pysch console tutorial'**
|
||||
|
||||
## 1. Create a 'collection of options' and save them in a local variable named 'options'.
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Add the options '1', '3', and '5' into the local variable 'options'.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Create a collection of scores and add four values of '0' into the collection.
|
||||
|
||||
<br />
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the code that reads a byte that indicates a controller is asking for a player number. (Don't bother checking if the byte received is 255.) Next, write the code that transfers the player number to the controller.
|
||||
|
||||
<br />
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 5.Write the code that transfers the three options.
|
||||
|
||||
<br />
|
||||
|
||||
<br/>
|
||||
|
||||
## 6.Write the code that requests each player to send their choice in the player order number. Don't worry about reading their choice. (Hint: look at the four loop with 'k' as the index.)
|
||||
|
||||
<br />
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 7.Write the code to create two collections. One collection ("choices") stores all the choices, while the other collection ("has common") stores whether or not the choice is unique. (If the choice is not unique, then "has common" will be set to true for that particular choice.)
|
||||
|
||||
<br />
|
||||
|
||||
<br/>
|
||||
|
||||
## 8. Write the code that compares each of the choices with each other. If the two choices are the same, then set the appropriate value inside 'has common' to true. (Hint: look at the for loops with 'l' and 'n' as their indexes.)
|
||||
|
||||
<br />
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 9. For each value inside 'has common', transfer a '1' if there is a match and transfer a '0' if there isn't a match. Add a pause of 100 milliseconds at the beginning of each transfer.)
|
||||
|
||||
<br />
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
**Questions 10-14 are concerned with 'number pysch controller tutorial'**
|
||||
|
||||
## 10. Write the code that asks for a player number if button 'A' is pressed on the BBC controller micro:bit.
|
||||
|
||||
<br />
|
||||
|
||||
<br/>
|
||||
|
||||
## 11. Write the code that adds the three transferred options to the "options" collection. (Hint: look at the for loop with 'k' as the index.)
|
||||
|
||||
<br />
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 12. Write the code that detects when button 'B' is pressed. Inside this condition, if 'game mode' is 2, set 'game mode' back to 1 and plot a waiting image.
|
||||
|
||||
<br />
|
||||
|
||||
<br/>
|
||||
|
||||
## 13. Create a while loop that first reads which controller the console micro:bit is requesting data from. Plot a waiting image, and then write an IF statement to check if the request corresponds to the controller. (Don't worry about writing anything inside the if statement).
|
||||
|
||||
<br />
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 14. Write the code that displays an "X" on the BBC micro:bit if 'result' is 1. Otherwise, display a "check mark".
|
||||
|
||||
<br />
|
||||
|
||||
<br/>
|
||||
|
69
olddocs/js/lessons/on-fall/challenges.md
Normal file
69
olddocs/js/lessons/on-fall/challenges.md
Normal file
@ -0,0 +1,69 @@
|
||||
# landslide challenges
|
||||
|
||||
The on fall function.
|
||||
|
||||
### Challenge 0
|
||||
|
||||
Welcome! This [guided tutorial](https://live.microbit.co.uk/td/lessons/on-fall/tutorial) will show you how to detect when the micro:bit is falling. Your goal is to write a program that detects when the micro:bit falls!
|
||||
|
||||
```
|
||||
input.onFall(() => {
|
||||
images.createImage(`
|
||||
. . # . .
|
||||
. . # . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
`).showImage(0) // ***
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Add a pause within `input->on fall`. This will allow us to display another image in the next challenge.
|
||||
|
||||
```
|
||||
input.onFall(() => {
|
||||
images.createImage(`
|
||||
. . # . .
|
||||
. . # . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
`).showImage(0)
|
||||
basic.pause(2000) // ***
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Create and display an `X` after the pause from Challenge 1
|
||||
|
||||
```
|
||||
input.onFall(() => {
|
||||
images.createImage(`
|
||||
. . # . .
|
||||
. . # . .
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
`).showImage(0)
|
||||
basic.pause(2000)
|
||||
images.createImage(`
|
||||
# . . . #
|
||||
. # . # .
|
||||
. . # . .
|
||||
. # . # .
|
||||
# . . . #
|
||||
`).showImage(0) // ***
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Create a loop so that the micro:bit alternates between the exclamation point and "X" images when the micro:bit falls. You will need a `forever` loop and a pause at the end of the loop to do this.
|
||||
|
||||
## See Also
|
||||
|
||||
[on shake](/reference/input/on-gesture)
|
||||
|
67
olddocs/js/lessons/on-logo-up-and-down/challenges.md
Normal file
67
olddocs/js/lessons/on-logo-up-and-down/challenges.md
Normal file
@ -0,0 +1,67 @@
|
||||
# on logo up and down challenges
|
||||
|
||||
My script. #docs
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
This [guided tutorial](/zysycw) will help you display an arrow pointing the direction the logo is orientated!
|
||||
|
||||
Let's display and upward pointing arrow when the logo is up!
|
||||
|
||||
```
|
||||
input.onLogoUp(() => {
|
||||
images.createImage(`
|
||||
. . # . .
|
||||
. # # # .
|
||||
# # # # #
|
||||
. . # . .
|
||||
. . # . .
|
||||
`).showImage(0)
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
How about when the logo is down? We should display the arrow pointing downward!
|
||||
|
||||
Let's start by adding a condition for if the logo is down.
|
||||
|
||||
```
|
||||
input.onLogoUp(() => {
|
||||
images.createImage(`
|
||||
. . # . .
|
||||
. # # # .
|
||||
# # # # #
|
||||
. . # . .
|
||||
. . # . .
|
||||
`).showImage(0)
|
||||
})
|
||||
input.onLogoDown(() => {
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
Now we need to display the arrow!
|
||||
|
||||
```
|
||||
input.onLogoUp(() => {
|
||||
images.createImage(`
|
||||
. . # . .
|
||||
. # # # .
|
||||
# # # # #
|
||||
. . # . .
|
||||
. . # . .
|
||||
`).showImage(0)
|
||||
})
|
||||
input.onLogoDown(() => {
|
||||
images.createImage(`
|
||||
. . # . .
|
||||
. . # . .
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`).showImage(0) // ***
|
||||
})
|
||||
```
|
||||
|
83
olddocs/js/lessons/on-shake/challenges.md
Normal file
83
olddocs/js/lessons/on-shake/challenges.md
Normal file
@ -0,0 +1,83 @@
|
||||
# flipping bird challenges
|
||||
|
||||
These challenges will allow you to create and display a flipping image of a bird when the micro:bit is shaken. #docs
|
||||
|
||||
### Challenge 0
|
||||
|
||||
### @video vimeo/134449611
|
||||
|
||||
Greetings! This [guided tutorial](/lessons/flipping-bird/tutorial) will begin to show you how to flip a bird.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
counter = counter + 1
|
||||
if (math.mod(counter, 2) == 1) {
|
||||
images.createImage(`
|
||||
# # . # #
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`).showImage(0)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
We handled the case of when `math->mod(counter,2) = 1`. We haven't done anything when the remainder is 0! Add an if statement to handle this case.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
counter = counter + 1
|
||||
if (math.mod(counter, 2) == 1) {
|
||||
images.createImage(`
|
||||
# # . # #
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`).showImage(0)
|
||||
}
|
||||
if (math.mod(counter, 2) == 0) {
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Inside of that `if` statement you created in challenge 1, add `image->create image()->show image(0)` and display an upside down flying bird.
|
||||
|
||||
```
|
||||
counter = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
counter = counter + 1
|
||||
if (math.mod(counter, 2) == 1) {
|
||||
images.createImage(`
|
||||
# # . # #
|
||||
. . # . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
`).showImage(0)
|
||||
}
|
||||
if (math.mod(counter, 2) == 0) {
|
||||
images.createImage(`
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . . . .
|
||||
. . # . .
|
||||
# # . # #
|
||||
`).showImage(0) // ***
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
* Run the code to see if it works as expected.
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Display a check mark and question mark instead of flipping birds. Or better yet, come up with your own pair of opposites to display!
|
||||
|
135
olddocs/js/lessons/pong.md
Normal file
135
olddocs/js/lessons/pong.md
Normal file
@ -0,0 +1,135 @@
|
||||
# pong lesson
|
||||
|
||||
code your own game of Pong on the micro:bit. #.
|
||||
|
||||
### @video td/videos/pong-0
|
||||
|
||||
## Topic
|
||||
|
||||
Functions
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [tutorial](/lessons/pong/tutorial)
|
||||
* [quiz](/lessons/pong/quiz)
|
||||
* [quiz answers](/lessons/pong/quiz-answers)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to create **functions**, `function()` that perform a specific task and returns a result. We will be learning how to create a pong game using functions, global variable forever loop, global variables, Boolean, for loop, input on button pressed, if statements, as well as simple commands, such as plot, unplot and pause.
|
||||
|
||||
## What the teacher needs to know
|
||||
|
||||
* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective.
|
||||
* Command: An instruction for the computer to execute, written in a particular programming language.
|
||||
* Data: A structured set of numbers, possibly representing digitised text, images, sound or video, which can be processed or transmitted by a computer, also used for numerical (quantitative) information.
|
||||
* Hardware: The physical systems and components of digital devices; see also software.
|
||||
* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors.
|
||||
* Output: The information produced by a computer system for its user, typically on a screen, through speakers or on a printer, but possibly through the control of motors in physical systems.
|
||||
* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program.
|
||||
* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.
|
||||
* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character.
|
||||
* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met.
|
||||
* Sequence: To place program instructions in order, with each executed one after the other.
|
||||
* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games.
|
||||
* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the user’s name.
|
||||
|
||||
**QuickStart Computing Glossary
|
||||
|
||||
## Documentation
|
||||
|
||||
* **function** : [read more...](/js/function)
|
||||
* **return** : [read more...](/js/return)
|
||||
* **call** : [read more...](/js/call)
|
||||
* **global variable** : [read more...](/js/data)
|
||||
* **arithmetic operator** : [read more...](/reference/types/number)
|
||||
* **Boolean** : [/td/Boolean]()
|
||||
* **forever** : [read more...](/reference/basic/forever)
|
||||
* **on button pressed** : [read more...](/reference/input/on-button-pressed)
|
||||
* **if** : [read more...](/reference/logic/if)
|
||||
* **clear screen** : [read more...](/reference/basic/clear-screen)
|
||||
* **show string** : [read more...](/reference/basic/show-string)
|
||||
* **plot** : [read more...](/reference/led/plot)
|
||||
* **unplot** : [read more...](/reference/led/unplot)
|
||||
* **pause** : [read more...](/reference/basic/pause)
|
||||
|
||||
## Resources
|
||||
|
||||
* Activity: [tutorial](/lessons/pong/tutorial)
|
||||
* Activity: [quiz](/lessons/pong/quiz)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create a function as a unit of code that performs a specific task and returns a result
|
||||
* learn how a return statement exits a function and returns a value to the code
|
||||
* learn how to call an existing function in your script
|
||||
* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks
|
||||
* learn how arithmetic operators operate on numbers and return a number
|
||||
* learn how a Boolean type has one of two possible values: true or false
|
||||
* learn how to repeat code in the background forever
|
||||
* learn how to conditionally run code depending on whether a condition is true or not
|
||||
* learn how to run code when an input button is pressed
|
||||
* learn how to show a string on the micro:bit's LED screen
|
||||
* learn how to turn on a LED light on the LED screen. Learn how to specify which LED using x, y coordinates
|
||||
* learn how to turn off a LED light on the LED screen. Learn how to specify which LED using x, y coordinates
|
||||
* learn how to pause your code for the specified number of milliseconds
|
||||
|
||||
## Links to the National Curriculum Programmes of Study for Computing
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL)
|
||||
* Uses diagrams to express solutions.(AB)
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Declares and assigns variables(AB)
|
||||
* Uses post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL)
|
||||
* Understands the difference between, and appropriately uses if and if, then and else statements(AL)
|
||||
* Uses a variable and relational operators within a loop to govern termination (AL) (GE)
|
||||
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
|
||||
* Selects the appropriate data types(AL) (AB
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Defines data types: real numbers and Boolean (AB)
|
||||
|
||||
#### Communication Networks
|
||||
|
||||
* Demonstrates responsible use of technologies and online services, and knows a range of ways to report concerns Understands how search engines rank search results (AL)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organizes, and presents data and information in digital content (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
|
||||
* Uses criteria to evaluate the quality of solutions, can identify improvements making some refinements to the solution, and future solutions (EV)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/lessons/pong/tutorial)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [quiz](/lessons/pong/quiz)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [quiz](/lessons/pong/quiz)
|
||||
|
||||
## Intended follow on
|
||||
|
||||
Publish script to the classroom.
|
||||
|
65
olddocs/js/lessons/pong/activity.md
Normal file
65
olddocs/js/lessons/pong/activity.md
Normal file
@ -0,0 +1,65 @@
|
||||
# pong activity
|
||||
|
||||
Building a game of pong with sprites.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
### @video td/videos/pong-0
|
||||
|
||||
Welcome! This tutorial will teach you how to build a simple pong game using sprites.
|
||||
|
||||
### ~
|
||||
|
||||
The game works as follow: the user moves a paddle on the left of the screen and a ball bounces on the other side. Let's start by creating the 2 sprites.
|
||||
|
||||
```
|
||||
let paddle = game.createSprite(0, 2)
|
||||
let ball = game.createSprite(4, 2)
|
||||
```
|
||||
|
||||
Let's make the ball start with an angle.
|
||||
|
||||
```
|
||||
ball.setDirection(-45)
|
||||
```
|
||||
|
||||
The user will control the paddle by pressing ``A`` to go up and ``B`` to go down. Let's add ``on button pressed`` event handlers to do that.
|
||||
|
||||
```
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
paddle.changeYBy(-1)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
paddle.changeYBy(1)
|
||||
})
|
||||
```
|
||||
|
||||
Let's add a ``forever`` loop to start the main game logic.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
// Leave the sprite on screen for a little while.
|
||||
basic.pause(400)
|
||||
// Let's move the ball in whatever direction it is currently going.
|
||||
ball.move(1)
|
||||
// The ball might be on the left side of the screen (``x = 0``), let's test for that.
|
||||
if (ball.x() == 0) {
|
||||
// Let's add a little pause to let the user know that the ball is on the side.
|
||||
basic.pause(400)
|
||||
// If the paddle is not at the same ``y`` coordinate, it missed the ball and we can trigger a game over. If not, we add a point to the score.
|
||||
if (paddle.y() != ball.y()) {
|
||||
game.gameOver()
|
||||
} else {
|
||||
game.addScore(1)
|
||||
basic.pause(500)
|
||||
}
|
||||
}
|
||||
// The ball moved and might be on a side, let's make sure it bounces.
|
||||
ball.ifOnEdge_Bounce()
|
||||
// If the ball is on the left side, slide it forward to change slightly the bouncing mechanics.
|
||||
if (ball.x() == 0) {
|
||||
ball.changeXBy(1)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
87
olddocs/js/lessons/pong/quiz-answers.md
Normal file
87
olddocs/js/lessons/pong/quiz-answers.md
Normal file
@ -0,0 +1,87 @@
|
||||
# pong quiz answers
|
||||
|
||||
create the game Pong.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [pong tutorial](/lessons/pong/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Create two variables that will keep track of the x-position and y-position of the ball, and assign the variables to their initial values.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
ballX = 2
|
||||
ballY = 1
|
||||
```
|
||||
|
||||
## 2. Create two variables that keeps track of the velocity (or the speed and direction) of the ball, and assign the variables to their initial values.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
ballXVelocity = 1
|
||||
ballYVelocity = 1
|
||||
```
|
||||
|
||||
## 3. Write the code that plots the initial position of the paddle and the ball.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
led.plot(0, paddleY)
|
||||
led.plot(ballX, ballY)
|
||||
```
|
||||
|
||||
## 4. Write the code that moves the paddle up when Button A is pressed. (Don't worry about setting 'game running' to true.)
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
if (paddleNotUp()) {
|
||||
led.unplot(0, paddleY)
|
||||
paddleY = paddleY - 1
|
||||
led.plot(0, paddleY)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## 5. Write the code that moves the paddle up when Button B is pressed. (Don't worry about setting 'game running' to true.)
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
if (paddleNotDown()) {
|
||||
led.unplot(0, paddleY)
|
||||
paddleY = paddleY + 1
|
||||
led.plot(0, paddleY)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## 6. Write the code to update the y-velocity. (Hint: look at the function "update y velocity".)
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
if (ballY == 4 || ballY == 0) {
|
||||
ballYVelocity = (-1) * ballYVelocity
|
||||
}
|
||||
```
|
||||
|
||||
## 7. Write the code to move the ball. (Hint: look at the function "move ball".)
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
led.unplot(ballX, ballY)
|
||||
ballX = ballX + ballXVelocity
|
||||
ballY = ballY + ballYVelocity
|
||||
```
|
||||
|
40
olddocs/js/lessons/pong/quiz.md
Normal file
40
olddocs/js/lessons/pong/quiz.md
Normal file
@ -0,0 +1,40 @@
|
||||
# pong quiz
|
||||
|
||||
create the game Pong.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [pong tutorial](/lessons/pong/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Create two variables that will keep track of the x-position and y-position of the ball, and assign the variables to their initial values.
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Create two variables that keeps track of the velocity (or the speed and direction) of the ball, and assign the variables to their initial values.
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the code that plots the initial position of the paddle and the ball.
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the code that moves the paddle up when Button A is pressed. (Don't worry about setting 'game running' to true.)
|
||||
|
||||
<br/>
|
||||
|
||||
## 5. Write the code that moves the paddle up when Button B is pressed. (Don't worry about setting 'game running' to true.)
|
||||
|
||||
<br/>
|
||||
|
||||
## 6. Write the code to update the y-velocity. (Hint: look at the function "update y velocity".)
|
||||
|
||||
<br/>
|
||||
|
||||
## 7. Write the code to move the ball. (Hint: look at the function "move ball".)
|
||||
|
||||
<br/>
|
||||
|
83
olddocs/js/lessons/rectangle-explosion/challenges.md
Normal file
83
olddocs/js/lessons/rectangle-explosion/challenges.md
Normal file
@ -0,0 +1,83 @@
|
||||
# snowflake fall challenges
|
||||
|
||||
These challenges will allow you to make an exploding rectangle. #docs
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
### @video vimeo/134649147
|
||||
|
||||
This [guided tutorial](https://test.microbit.co.uk/td/lessons/rectangle-explosion/tutorial) will help you create a snowflake animation!
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.showAnimation(`
|
||||
. . . . .
|
||||
. . # . .
|
||||
. # # # .
|
||||
. . # . .
|
||||
. . . . .
|
||||
`, 400)
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
### @video vimeo/134649148
|
||||
|
||||
Let's begin creating our falling effect by adding another snowflake with `show animation` that displays a different snowflake pattern after the first one.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.showAnimation(`
|
||||
. . . . .
|
||||
. . # . .
|
||||
. # # # .
|
||||
. . # . .
|
||||
. . . . .
|
||||
`, 400)
|
||||
basic.showAnimation(`
|
||||
. . . . . . . # . .
|
||||
. . # . . . # . # .
|
||||
. # # # . # . . . #
|
||||
. . # . . . # . # .
|
||||
. . . . . . . # . .
|
||||
`, 400) // ***
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
### @video vimeo/134649149
|
||||
|
||||
To finalize our snowflake fall, let's add a different snowflake pattern.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
basic.showAnimation(`
|
||||
. . . . .
|
||||
. . # . .
|
||||
. # # # .
|
||||
. . # . .
|
||||
. . . . .
|
||||
`, 400)
|
||||
basic.showAnimation(`
|
||||
. . . . . . . # . .
|
||||
. . # . . . # . # .
|
||||
. # # # . # . . . #
|
||||
. . # . . . # . # .
|
||||
. . . . . . . # . .
|
||||
`, 400)
|
||||
basic.showAnimation(`
|
||||
. . . . . . . # . . . # . # .
|
||||
. . # . . . # . # . # # . # #
|
||||
. # # # . # . . . # . . . . .
|
||||
. . # . . . # . # . # # . # #
|
||||
. . . . . . . # . . . # . # .
|
||||
`, 400) // ***
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
If you notice, we have three `basic->show animation()` functions. Try to create the snowflake fall effect by just using one `basic->show animation()`.
|
||||
|
46
olddocs/js/lessons/return/challenges.md
Normal file
46
olddocs/js/lessons/return/challenges.md
Normal file
@ -0,0 +1,46 @@
|
||||
# return challenges
|
||||
|
||||
This script will teach you how to create a function and use an output parameter. #docs
|
||||
|
||||
### Challenge 0
|
||||
|
||||
Welcome! This [guided tutorial](/lessons/return/tutorial) will help you code the following script!
|
||||
|
||||
```
|
||||
let original1 = 5
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let doubled = doubleIt_(5)
|
||||
basic.showNumber(doubled, 150) // ***
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Create a new function called `square` that returns squares the number passed into the function. (Squaring means that you multiply the number by itself.)
|
||||
|
||||
```
|
||||
export function squareIt(n: number) : number {
|
||||
let num: number
|
||||
return n * n
|
||||
return num
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Add a condition to know when button `B` is pressed. We will use this condition in the last challenge.
|
||||
|
||||
```
|
||||
let original = 5
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let one = doubleIt_(original)
|
||||
basic.showNumber(one, 150)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
When the `B` button is pressed, display the square of the original value. Use the function `square it`. You should get the value 25.
|
||||
|
@ -0,0 +1,235 @@
|
||||
# rock paper scissors book version
|
||||
|
||||
My script. #docs
|
||||
|
||||
Welcome! This guide will show you how to complete the challenges for the game of rock, paper, scissors!
|
||||
|
||||
## Challenge 1
|
||||
|
||||
### Step 16
|
||||
|
||||
Awesome! You have just created your game of rock paper scissors. However, why don't we add a little more to it? We can keep track of your score against the micro:bit using global variables. Create a global variable to keep track of the wins against the micro:bit. To do so, click on `add new`, then `Data`, and then `Number`.
|
||||
|
||||
```
|
||||
var wins: number = 0
|
||||
```
|
||||
|
||||
### Step 17
|
||||
|
||||
At the beginning of the game, you don't have any wins against the micro:bit. As a result, let's set the `data->wins` variable to 0 at the top of your main function.
|
||||
|
||||
```
|
||||
wins = 0 // ***
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img = images.createImage(`
|
||||
. . . . . # # # # # . . . . #
|
||||
. # # # . # . . . # # # . # .
|
||||
. # # # . # . . . # . # # . .
|
||||
. # # # . # . . . # # # . # .
|
||||
. . . . . # # # # # . . . . #
|
||||
`)
|
||||
let offset = 5 * Math.random(3)
|
||||
img.showImage(offset)
|
||||
})
|
||||
```
|
||||
|
||||
### Step 18
|
||||
|
||||
Now let's keep track of wins by using button `A`. Every time button `A` is pressed, we want to increment `data->wins` by 1. We can begin by adding a condition `input->on button pressed("A")`.
|
||||
|
||||
```
|
||||
wins = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img1 = images.createImage(`
|
||||
. . . . . # # # # # . . . . #
|
||||
. # # # . # . . . # # # . # .
|
||||
. # # # . # . . . # . # # . .
|
||||
. # # # . # . . . # # # . # .
|
||||
. . . . . # # # # # . . . . #
|
||||
`)
|
||||
let offset1 = 5 * Math.random(3)
|
||||
img1.showImage(offset1)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
}) // ***
|
||||
```
|
||||
|
||||
### Step 19
|
||||
|
||||
Nice! Now that we added the condition for when button `A` is pressed, we can increment `data->wins` by 1. Add the following statement in the condition.
|
||||
|
||||
```
|
||||
wins = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img2 = images.createImage(`
|
||||
. . . . . # # # # # . . . . #
|
||||
. # # # . # . . . # # # . # .
|
||||
. # # # . # . . . # . # # . .
|
||||
. # # # . # . . . # # # . # .
|
||||
. . . . . # # # # # . . . . #
|
||||
`)
|
||||
let offset2 = 5 * Math.random(3)
|
||||
img2.showImage(offset2)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
wins = wins + 1 // ***
|
||||
})
|
||||
```
|
||||
|
||||
### Step 20
|
||||
|
||||
You have tracked the number of wins you have against the micro:bit. However, how will you ever know how many wins you have? After we increment `data->wins`, let's display the total number of wins you have.
|
||||
|
||||
```
|
||||
wins = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img3 = images.createImage(`
|
||||
. . . . . # # # # # . . . . #
|
||||
. # # # . # . . . # # # . # .
|
||||
. # # # . # . . . # . # # . .
|
||||
. # # # . # . . . # # # . # .
|
||||
. . . . . # # # # # . . . . #
|
||||
`)
|
||||
let offset3 = 5 * Math.random(3)
|
||||
img3.showImage(offset3)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
wins = wins + 1
|
||||
basic.showString("WINS:", 150) // ***
|
||||
basic.showNumber(wins, 150) // ***
|
||||
})
|
||||
```
|
||||
|
||||
* Tap `run` to run the program on the simulator. Notice the number of wins you have against the micro:bit.
|
||||
|
||||
## Challenge 2
|
||||
|
||||
### Step 21
|
||||
|
||||
You have managed to keep score of the number of wins you have against the micro:bit. However, what about losses? Let's begin by creating another global variable to keep track of losses.
|
||||
|
||||
```
|
||||
var losses: number = 0
|
||||
```
|
||||
|
||||
### Step 22
|
||||
|
||||
Add a condition for when button `B` is pressed. When this occurs, we will increment your losses against the micro:bit by 1. Let's hope that this button will not be pressed too often!
|
||||
|
||||
```
|
||||
wins = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img4 = images.createImage(`
|
||||
. . . . . # # # # # . . . . #
|
||||
. # # # . # . . . # # # . # .
|
||||
. # # # . # . . . # . # # . .
|
||||
. # # # . # . . . # # # . # .
|
||||
. . . . . # # # # # . . . . #
|
||||
`)
|
||||
let offset4 = 5 * Math.random(3)
|
||||
img4.showImage(offset4)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
wins = wins + 1
|
||||
basic.showString("WINS:", 150)
|
||||
basic.showNumber(wins, 150)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
}) // ***
|
||||
```
|
||||
|
||||
### Step 23
|
||||
|
||||
Now let's continue where we left off. Just as we did for `data->wins` when button `A` is pressed, we need to increment `losses` by 1 when button `B` is pressed.
|
||||
|
||||
```
|
||||
wins = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img5 = images.createImage(`
|
||||
. . . . . # # # # # . . . . #
|
||||
. # # # . # . . . # # # . # .
|
||||
. # # # . # . . . # . # # . .
|
||||
. # # # . # . . . # # # . # .
|
||||
. . . . . # # # # # . . . . #
|
||||
`)
|
||||
let offset5 = 5 * Math.random(3)
|
||||
img5.showImage(offset5)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
wins = wins + 1
|
||||
basic.showString("WINS:", 150)
|
||||
basic.showNumber(wins, 150)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
losses = losses + 1 // ***
|
||||
})
|
||||
```
|
||||
|
||||
### Step 24
|
||||
|
||||
Let's also display the score when button `B` is pressed, just as we have done for button `A`. This will help us keep track of the number of wins and losses you have against the micro:bit.
|
||||
|
||||
```
|
||||
wins = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img6 = images.createImage(`
|
||||
. . . . . # # # # # . . . . #
|
||||
. # # # . # . . . # # # . # .
|
||||
. # # # . # . . . # . # # . .
|
||||
. # # # . # . . . # # # . # .
|
||||
. . . . . # # # # # . . . . #
|
||||
`)
|
||||
let offset6 = 5 * Math.random(3)
|
||||
img6.showImage(offset6)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
wins = wins + 1
|
||||
basic.showString("WINS:", 150)
|
||||
basic.showNumber(wins, 150)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
losses = losses + 1
|
||||
basic.showString("WINS", 150) // ***
|
||||
basic.showNumber(wins, 150) // ***
|
||||
basic.showString("LOSSES:", 150) // ***
|
||||
basic.showNumber(losses, 150) // ***
|
||||
})
|
||||
```
|
||||
|
||||
### Step 25
|
||||
|
||||
You have managed to keep track of both the wins and losses you have against the micro:bit! But did you notice that you haven't updated something? Take a look at condition of `input->on button pressed("A")`.
|
||||
|
||||
```
|
||||
wins = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img7 = images.createImage(`
|
||||
. . . . . # # # # # . . . . #
|
||||
. # # # . # . . . # # # . # .
|
||||
. # # # . # . . . # . # # . .
|
||||
. # # # . # . . . # # # . # .
|
||||
. . . . . # # # # # . . . . #
|
||||
`)
|
||||
let offset7 = 5 * Math.random(3)
|
||||
img7.showImage(offset7)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
wins = wins + 1
|
||||
basic.showString("WINS:", 150)
|
||||
basic.showNumber(wins, 150)
|
||||
basic.showString("LOSSES:", 150) // ***
|
||||
basic.showNumber(losses, 150) // ***
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
losses = losses + 1
|
||||
basic.showString("WINS", 150)
|
||||
basic.showNumber(wins, 150)
|
||||
basic.showString("LOSSES:", 150)
|
||||
basic.showNumber(losses, 150)
|
||||
})
|
||||
```
|
||||
|
||||
* Tap the `run` button to run your game on the simulator. See if you can get more wins than the micro:bit can!
|
||||
|
||||
Congratulations! You have successfully created a fully functional game of rock, paper, scissors against the micro:bit. Challenge your friends to see who can get a better score against the micro:bit.
|
||||
|
@ -0,0 +1,235 @@
|
||||
# rock paper scissors teacher guide
|
||||
|
||||
My script. #docs
|
||||
|
||||
Welcome! This guide will show you how to complete the challenges for the game of rock, paper, scissors!
|
||||
|
||||
## Challenge 1
|
||||
|
||||
### Step 16
|
||||
|
||||
Awesome! You have just created your game of rock paper scissors. However, why don't we add a little more to it? We can keep track of your score against the micro:bit using global variables. Create a global variable to keep track of the wins against the micro:bit. To do so, click on `add new`, then `Data`, and then `Number`.
|
||||
|
||||
```
|
||||
var wins: number = 0
|
||||
```
|
||||
|
||||
### Step 17
|
||||
|
||||
At the beginning of the game, you don't have any wins against the micro:bit. As a result, let's set the `data->wins` variable to 0 at the top of your main function.
|
||||
|
||||
```
|
||||
wins = 0 // ***
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img = images.createImage(`
|
||||
. . . . . # # # # # . . . . #
|
||||
. # # # . # . . . # # # . # .
|
||||
. # # # . # . . . # . # # . .
|
||||
. # # # . # . . . # # # . # .
|
||||
. . . . . # # # # # . . . . #
|
||||
`)
|
||||
let offset = 5 * Math.random(3)
|
||||
img.showImage(offset)
|
||||
})
|
||||
```
|
||||
|
||||
### Step 18
|
||||
|
||||
Now let's keep track of wins by using button `A`. Every time button `A` is pressed, we want to increment `data->wins` by 1. We can begin by adding a condition `input->on button pressed("A")`.
|
||||
|
||||
```
|
||||
wins = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img1 = images.createImage(`
|
||||
. . . . . # # # # # . . . . #
|
||||
. # # # . # . . . # # # . # .
|
||||
. # # # . # . . . # . # # . .
|
||||
. # # # . # . . . # # # . # .
|
||||
. . . . . # # # # # . . . . #
|
||||
`)
|
||||
let offset1 = 5 * Math.random(3)
|
||||
img1.showImage(offset1)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
}) // ***
|
||||
```
|
||||
|
||||
### Step 19
|
||||
|
||||
Nice! Now that we added the condition for when button `A` is pressed, we can increment `data->wins` by 1. Add the following statement in the condition.
|
||||
|
||||
```
|
||||
wins = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img2 = images.createImage(`
|
||||
. . . . . # # # # # . . . . #
|
||||
. # # # . # . . . # # # . # .
|
||||
. # # # . # . . . # . # # . .
|
||||
. # # # . # . . . # # # . # .
|
||||
. . . . . # # # # # . . . . #
|
||||
`)
|
||||
let offset2 = 5 * Math.random(3)
|
||||
img2.showImage(offset2)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
wins = wins + 1 // ***
|
||||
})
|
||||
```
|
||||
|
||||
### Step 20
|
||||
|
||||
You have tracked the number of wins you have against the micro:bit. However, how will you ever know how many wins you have? After we increment `data->wins`, let's display the total number of wins you have.
|
||||
|
||||
```
|
||||
wins = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img3 = images.createImage(`
|
||||
. . . . . # # # # # . . . . #
|
||||
. # # # . # . . . # # # . # .
|
||||
. # # # . # . . . # . # # . .
|
||||
. # # # . # . . . # # # . # .
|
||||
. . . . . # # # # # . . . . #
|
||||
`)
|
||||
let offset3 = 5 * Math.random(3)
|
||||
img3.showImage(offset3)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
wins = wins + 1
|
||||
basic.showString("WINS:", 150) // ***
|
||||
basic.showNumber(wins, 150) // ***
|
||||
})
|
||||
```
|
||||
|
||||
* Tap `run` to run the program on the simulator. Notice the number of wins you have against the micro:bit.
|
||||
|
||||
## Challenge 2
|
||||
|
||||
### Step 21
|
||||
|
||||
You have managed to keep score of the number of wins you have against the micro:bit. However, what about losses? Let's begin by creating another global variable to keep track of losses.
|
||||
|
||||
```
|
||||
var losses: number = 0
|
||||
```
|
||||
|
||||
### Step 22
|
||||
|
||||
Add a condition for when button `B` is pressed. When this occurs, we will increment your losses against the micro:bit by 1. Let's hope that this button will not be pressed too often!
|
||||
|
||||
```
|
||||
wins = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img4 = images.createImage(`
|
||||
. . . . . # # # # # . . . . #
|
||||
. # # # . # . . . # # # . # .
|
||||
. # # # . # . . . # . # # . .
|
||||
. # # # . # . . . # # # . # .
|
||||
. . . . . # # # # # . . . . #
|
||||
`)
|
||||
let offset4 = 5 * Math.random(3)
|
||||
img4.showImage(offset4)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
wins = wins + 1
|
||||
basic.showString("WINS:", 150)
|
||||
basic.showNumber(wins, 150)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
}) // ***
|
||||
```
|
||||
|
||||
### Step 23
|
||||
|
||||
Now let's continue where we left off. Just as we did for `data->wins` when button `A` is pressed, we need to increment `losses` by 1 when button `B` is pressed.
|
||||
|
||||
```
|
||||
wins = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img5 = images.createImage(`
|
||||
. . . . . # # # # # . . . . #
|
||||
. # # # . # . . . # # # . # .
|
||||
. # # # . # . . . # . # # . .
|
||||
. # # # . # . . . # # # . # .
|
||||
. . . . . # # # # # . . . . #
|
||||
`)
|
||||
let offset5 = 5 * Math.random(3)
|
||||
img5.showImage(offset5)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
wins = wins + 1
|
||||
basic.showString("WINS:", 150)
|
||||
basic.showNumber(wins, 150)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
losses = losses + 1 // ***
|
||||
})
|
||||
```
|
||||
|
||||
### Step 24
|
||||
|
||||
Let's also display the score when button `B` is pressed, just as we have done for button `A`. This will help us keep track of the number of wins and losses you have against the micro:bit.
|
||||
|
||||
```
|
||||
wins = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img6 = images.createImage(`
|
||||
. . . . . # # # # # . . . . #
|
||||
. # # # . # . . . # # # . # .
|
||||
. # # # . # . . . # . # # . .
|
||||
. # # # . # . . . # # # . # .
|
||||
. . . . . # # # # # . . . . #
|
||||
`)
|
||||
let offset6 = 5 * Math.random(3)
|
||||
img6.showImage(offset6)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
wins = wins + 1
|
||||
basic.showString("WINS:", 150)
|
||||
basic.showNumber(wins, 150)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
losses = losses + 1
|
||||
basic.showString("WINS", 150) // ***
|
||||
basic.showNumber(wins, 150) // ***
|
||||
basic.showString("LOSSES:", 150) // ***
|
||||
basic.showNumber(losses, 150) // ***
|
||||
})
|
||||
```
|
||||
|
||||
### Step 25
|
||||
|
||||
You have managed to keep track of both the wins and losses you have against the micro:bit! But did you notice that you haven't updated something? Take a look at condition of `input->on button pressed("A")`.
|
||||
|
||||
```
|
||||
wins = 0
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
let img7 = images.createImage(`
|
||||
. . . . . # # # # # . . . . #
|
||||
. # # # . # . . . # # # . # .
|
||||
. # # # . # . . . # . # # . .
|
||||
. # # # . # . . . # # # . # .
|
||||
. . . . . # # # # # . . . . #
|
||||
`)
|
||||
let offset7 = 5 * Math.random(3)
|
||||
img7.showImage(offset7)
|
||||
})
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
wins = wins + 1
|
||||
basic.showString("WINS:", 150)
|
||||
basic.showNumber(wins, 150)
|
||||
basic.showString("LOSSES:", 150) // ***
|
||||
basic.showNumber(losses, 150) // ***
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
losses = losses + 1
|
||||
basic.showString("WINS", 150)
|
||||
basic.showNumber(wins, 150)
|
||||
basic.showString("LOSSES:", 150)
|
||||
basic.showNumber(losses, 150)
|
||||
})
|
||||
```
|
||||
|
||||
* Tap the `run` button to run your game on the simulator. See if you can get more wins than the micro:bit can!
|
||||
|
||||
Congratulations! You have successfully created a fully functional game of rock, paper, scissors against the micro:bit. Challenge your friends to see who can get a better score against the micro:bit.
|
||||
|
7
olddocs/js/lessons/runaway-pacman.md
Normal file
7
olddocs/js/lessons/runaway-pacman.md
Normal file
@ -0,0 +1,7 @@
|
||||
# runaway pacman lessons
|
||||
|
||||
make a game to test hand-eye coordination.
|
||||
|
||||
Make a game to test hand-eye coordination
|
||||
|
||||
* [tutorial](/lessons/runaway-pacman/tutorial)
|
117
olddocs/js/lessons/runaway-pacman/quiz-answers.md
Normal file
117
olddocs/js/lessons/runaway-pacman/quiz-answers.md
Normal file
@ -0,0 +1,117 @@
|
||||
# runaway pacman quiz answers
|
||||
|
||||
create a game that is inspired by the classic arcade game Pac Man.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [runaway pacman tutorial](/lessons/runaway-pacman/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the the method name created that will set up the game board.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
initializeState()
|
||||
```
|
||||
|
||||
## 2. Write the the method name created that will draw the player and the monster(s)
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
redraw()
|
||||
```
|
||||
|
||||
## 3. Write the code that keeps track of how long a player has been playing. (Don't include any if statements.)
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
levelTime = levelTime + 12
|
||||
basic.pause(12)
|
||||
})
|
||||
```
|
||||
|
||||
## 4. Write the code that will reset the time and continue playing if we have been eaten.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
if ( ! playing) {
|
||||
levelTime = 0
|
||||
playing = true
|
||||
}
|
||||
```
|
||||
|
||||
## 5. Write 'If statement' that will determine if the player has been playing for more than 5 seconds.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
if (levelTime >= 5000) {
|
||||
}
|
||||
```
|
||||
|
||||
## 6. Suspend the game if we are advancing to the next level. (Hint: this requires setting a variable to true.)
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
gameSuspended = true
|
||||
```
|
||||
|
||||
## 7. Write the code to add a monster. (Hint: look in the function "add monster".)
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
let m = new Entity()
|
||||
monsters.push(m)
|
||||
totalMonsters = totalMonsters + 1
|
||||
```
|
||||
|
||||
## 8. Write the code that will restart the time to 0 after you begin the next level.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
levelTime = 0
|
||||
```
|
||||
|
||||
## 9. Write the code that makes the player go either North or East when button 'A' is pressed.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let temp = math.abs(person.dirX) * (-1)
|
||||
// {stcode}
|
||||
// MACRO: stcode
|
||||
person.dirX = math.abs(person.dirY) * (-1)
|
||||
// {stcode}
|
||||
// MACRO: stcode
|
||||
person.dirY = temp
|
||||
})
|
||||
```
|
||||
|
||||
## 10. Write the code that makes the player go either South or West when button 'B' is pressed.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
let temp1 = math.abs(person.dirX)
|
||||
// {stcode}
|
||||
// MACRO: stcode
|
||||
person.dirX = math.abs(person.dirY)
|
||||
// {stcode}
|
||||
// MACRO: stcode
|
||||
person.dirY = temp1
|
||||
})
|
||||
```
|
||||
|
60
olddocs/js/lessons/runaway-pacman/quiz.md
Normal file
60
olddocs/js/lessons/runaway-pacman/quiz.md
Normal file
@ -0,0 +1,60 @@
|
||||
# runaway pacman quiz
|
||||
|
||||
create a game that is inspired by the classic arcade game Pac Man.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [runaway pacman tutorial](/lessons/runaway-pacman/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. Write the the method name created that will set up the game board.
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the the method name created that will draw the player and the monster(s)
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the code that keeps track of how long a player has been playing. (Don't include any if statements.)
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the code that will reset the time and continue playing if we have been eaten.
|
||||
|
||||
<br/>
|
||||
|
||||
## 5. Write 'If statement' that will determine if the player has been playing for more than 5 seconds.
|
||||
|
||||
<br/>
|
||||
|
||||
## 6. Suspend the game if we are advancing to the next level. (Hint: this requires setting a variable to true.)
|
||||
|
||||
<br/>
|
||||
|
||||
## 7. Write the code to add a monster. (Hint: look in the function "add monster".)
|
||||
|
||||
<br/>
|
||||
|
||||
## 8. Write the code that will restart the time to 0 after you begin the next level.
|
||||
|
||||
<br/>
|
||||
|
||||
## 9. Write the code that makes the player go either North or East when button 'A' is pressed.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 10. Write the code that makes the player go either South or West when button 'B' is pressed.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
30
olddocs/js/lessons/running-time/challenges.md
Normal file
30
olddocs/js/lessons/running-time/challenges.md
Normal file
@ -0,0 +1,30 @@
|
||||
# running time challenges
|
||||
|
||||
My script. #docs
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
Great job! You have successfully completed the [Running Time tutorial](/lessons/running-time/tutorial) . You have a forever loop that declares a variable in it that holds the running time in milliseconds of the micro:bit and then shows the seconds on the LED screen.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
let now = input.runningTime()
|
||||
basic.showNumber(now / 1000, 150)
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
When button A is pressed, reset the time by subtracting the current time from the variable now.
|
||||
|
||||
```
|
||||
basic.forever(() => {
|
||||
let now1 = input.runningTime()
|
||||
basic.showNumber(now1 / 1000, 150)
|
||||
})
|
||||
if (input.buttonIsPressed("A")) {
|
||||
let now2 = 0 // ***
|
||||
}
|
||||
```
|
||||
|
||||
* Run the code to see if it works as expected.
|
64
olddocs/js/lessons/screen-up-and-down/challenges.md
Normal file
64
olddocs/js/lessons/screen-up-and-down/challenges.md
Normal file
@ -0,0 +1,64 @@
|
||||
# screen up and down challenges
|
||||
|
||||
The on screen up function.
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
Congratulations! You have completed the [Screen Up/Down tutorial](/hqjwkb) . You should have an image of a heart created and shown when the screen is moved up.
|
||||
|
||||
```
|
||||
input.onScreenUp(() => {
|
||||
images.createImage(`
|
||||
# # . # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`).showImage(0)
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
Now have the Micro:bit do something when the screen is moved downward. You can do this by calling the on screen down method. Do not do anything when you call the on screen down method.
|
||||
|
||||
```
|
||||
input.onScreenUp(() => {
|
||||
images.createImage(`
|
||||
# # . # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`).showImage(0)
|
||||
})
|
||||
input.onScreenDown(() => {
|
||||
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
When the Micro:bit is moved downward, create and show an image of an upside down heart.
|
||||
|
||||
```
|
||||
input.onScreenUp(() => {
|
||||
images.createImage(`
|
||||
# # . # #
|
||||
# # # # #
|
||||
# # # # #
|
||||
. # # # .
|
||||
. . # . .
|
||||
`).showImage(0)
|
||||
})
|
||||
input.onScreenDown(() => {
|
||||
images.createImage(`
|
||||
. . # . .
|
||||
. # # # .
|
||||
# # # # #
|
||||
# # # # #
|
||||
# # . # #
|
||||
`).showImage(0) // ***
|
||||
})
|
||||
```
|
||||
|
47
olddocs/js/lessons/screen-wipe/activity.md
Normal file
47
olddocs/js/lessons/screen-wipe/activity.md
Normal file
@ -0,0 +1,47 @@
|
||||
# screen wipe activity
|
||||
|
||||
Clear the screen by pressing buttons on the BBC micro:bit.
|
||||
|
||||
### ~avatar avatar
|
||||
|
||||
### @video td/videos/screen-wipe-0
|
||||
|
||||
This activity will teach how to clear the screen by pressing button ``A`` on the BBC micro:bit.
|
||||
|
||||
### ~
|
||||
|
||||
You can use the `basic->clear screen` function to turn off all the LED on the screen. Let's illustrate this concept with a small script where the user has to press the button ``A`` to turn off the screen. Let's start by adding the code to show an animation.
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
. . . . . # # # # # # # # # # . . . . .
|
||||
. . . . . # # # # # # # # # # # # # # #
|
||||
. . . . . . . . . . . . . . . # # # # #
|
||||
`, 400) // ***
|
||||
```
|
||||
|
||||
We add another line of code that registers an **event handler** on the `input->on button pressed(A)` and calls `basic->clear screen`.
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
. . . . . # # # # # # # # # # . . . . .
|
||||
. . . . . # # # # # # # # # # # # # # #
|
||||
. . . . . . . . . . . . . . . # # # # #
|
||||
`, 400)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.clearScreen() // ***
|
||||
}) // ***
|
||||
```
|
||||
|
||||
Run the script in the simulator or on the BBC micro:bit to see how this works!
|
||||
|
||||
### ~avatar boothing
|
||||
|
||||
Excellent, you're ready to continue with the [challenges](/lessons/screen-wipe/challenges)!
|
||||
|
||||
### ~
|
||||
|
73
olddocs/js/lessons/screen-wipe/challenges.md
Normal file
73
olddocs/js/lessons/screen-wipe/challenges.md
Normal file
@ -0,0 +1,73 @@
|
||||
# screen wipe challenges
|
||||
|
||||
Coding challenges for the screen wipe tutorial. #docs
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the [screen wipe](/lessons/screen-wipe) activity and your code will look like this:
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
. . . . . # # # # # # # # # # . . . . .
|
||||
. . . . . # # # # # # # # # # # # # # #
|
||||
. . . . . . . . . . . . . . . # # # # #
|
||||
`, 400)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.clearScreen()
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
Create an event handler for Button "B".
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
. . . . . # # # # # # # # # # . . . . .
|
||||
. . . . . # # # # # # # # # # # # # # #
|
||||
. . . . . . . . . . . . . . . # # # # #
|
||||
`, 400)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.clearScreen()
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
### @video td/videos/screen-wipe-2
|
||||
|
||||
Replay the animation when the "B" button is pressed by typing in `basic->show animation(..., 400)`.
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
. . . . . # # # # # # # # # # . . . . .
|
||||
. . . . . # # # # # # # # # # # # # # #
|
||||
. . . . . . . . . . . . . . . # # # # #
|
||||
`, 400)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.clearScreen()
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
basic.showAnimation(`
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
. . . . . # # # # # # # # # # . . . . .
|
||||
. . . . . # # # # # # # # # # # # # # #
|
||||
. . . . . . . . . . . . . . . # # # # #
|
||||
`, 400) // ***
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
Show an animation that scrolls back up when you press button "B".
|
||||
|
||||
* tap the `run` button to view your final product!
|
45
olddocs/js/lessons/screen-wipe/quiz-answers.md
Normal file
45
olddocs/js/lessons/screen-wipe/quiz-answers.md
Normal file
@ -0,0 +1,45 @@
|
||||
# screen wipe quiz answers
|
||||
|
||||
clear the screen by pressing the "A" button after an animation has been played.
|
||||
|
||||
This is the answer key for the [screen wipe quiz](/lessons/screen-wipe/quiz).
|
||||
|
||||
## 1. What does the function "clear screen" do on the BBC micro:bit?
|
||||
|
||||
This function turns off all the LED lights on the LED screen.
|
||||
|
||||
## 2. Write the line of code that creates and displays this animation.
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
# # # # . # # # # # . . . . . . . . . .
|
||||
# # # # # # # # # # . . . . . . . . . .
|
||||
. . . . . # # # # # # # # # # . . . . .
|
||||
. . . . . # # # # # # # # # # # # # # #
|
||||
. . . . . . . . . . . . . . . # # # # #
|
||||
`, 400)
|
||||
```
|
||||
|
||||
## 3. Write the condition that will detect when the BBC micro:bit is shaken.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
})
|
||||
```
|
||||
|
||||
## 4. Write the code that will clear an animation from the screen after shaking the BBC micro:bit.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
basic.clearScreen()
|
||||
})
|
||||
```
|
||||
|
32
olddocs/js/lessons/screen-wipe/quiz.md
Normal file
32
olddocs/js/lessons/screen-wipe/quiz.md
Normal file
@ -0,0 +1,32 @@
|
||||
# screen wipe quiz
|
||||
|
||||
clear the screen by pressing the "A" button after an animation has been played.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [screen wipe tutorial](/lessons/screen-wipe/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What does the function "clear screen" do on the BBC micro:bit?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. We can show all of these images in one line of code. What method can we use to do this?
|
||||
|
||||

|
||||
|
||||
<br/>
|
||||
|
||||
## 3. How can the BBC micro:bit detect when it is shaken?
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the code that will clear an animation from the screen after shaking the BBC micro:bit.
|
||||
|
||||
<br/>
|
||||
|
54
olddocs/js/lessons/set-brightness/challenges.md
Normal file
54
olddocs/js/lessons/set-brightness/challenges.md
Normal file
@ -0,0 +1,54 @@
|
||||
# set brightness challenges
|
||||
|
||||
These challenges will allow you to change the brightness of the micro:bit. docs
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
### @video vimeo/133782335
|
||||
|
||||
[This tutorial](/lessons/set-brightness/tutorial) will show you how to set the brightness on the micro:bit.
|
||||
|
||||
```
|
||||
led.setBrightness(255)
|
||||
led.plotAll()
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
led.setBrightness(64)
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
### @video vimeo/133782335
|
||||
|
||||
What if we want to turn off all the LEDs? Let's do this by setting the brightness to `0` when button `B` is pressed. Add a condition for `input->on button pressed("B")`.
|
||||
|
||||
```
|
||||
led.setBrightness(255)
|
||||
led.plotAll()
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
led.setBrightness(64)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
}) // ***
|
||||
```
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
Inside of the condition `input->on button pressed("B")`, add `led->set brightness(0)` to turn off the LEDs.
|
||||
|
||||
```
|
||||
led.setBrightness(255)
|
||||
led.plotAll()
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
led.setBrightness(64)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
led.setBrightness(0) // ***
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
Now, in the condition `input->on button pressed("B")`, add `basic->pause(1000)` and then set the brightness to a new value!
|
||||
|
||||
* `Run` your script to see the LEDs change brightness.
|
39
olddocs/js/lessons/show-number/challenges.md
Normal file
39
olddocs/js/lessons/show-number/challenges.md
Normal file
@ -0,0 +1,39 @@
|
||||
# show number challenges
|
||||
|
||||
My script. #docs
|
||||
|
||||
### Challenge 0
|
||||
|
||||
Welcome! This [guided tutorial](/xvogbz) will help you show a number on the LED screen!
|
||||
|
||||
Show a number on the LED screen! One digit will display at a time, scrolling from left to right.
|
||||
|
||||
Make lucky number 7 display on the screen!
|
||||
|
||||
```
|
||||
basic.showNumber(7, 150)
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
But we also should pause before showing another number.
|
||||
|
||||
```
|
||||
basic.showNumber(7, 150)
|
||||
basic.pause(500) // ***
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Let's display the next multiple of 7 on the screen!
|
||||
|
||||
```
|
||||
basic.showNumber(7, 150)
|
||||
basic.pause(500)
|
||||
basic.showNumber(14, 150) // ***
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Keep displaying multiples of 7 such as 21 and 28, but don't forget to add pauses between the numbers!
|
||||
|
38
olddocs/js/lessons/show-string/challenges.md
Normal file
38
olddocs/js/lessons/show-string/challenges.md
Normal file
@ -0,0 +1,38 @@
|
||||
# show string challenges
|
||||
|
||||
My script. #docs
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
Welcome! This [guided tutorial](/pxjkww) introduces the basic show string method on the micro:bit.
|
||||
|
||||
Let's show the string 'Hello' on the LED screen. The string will scroll one character at a time from left to right.
|
||||
|
||||
```
|
||||
basic.showString("Hello ", 150)
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
Now, let's show the string 'World' on the LED screen.
|
||||
|
||||
```
|
||||
basic.showString("Hello ", 150)
|
||||
basic.showString("World", 150) // ***
|
||||
```
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
Let's display another string to introduce yourself!
|
||||
|
||||
After 'Hello World' we want to display the string 'My name is '.
|
||||
|
||||
```
|
||||
basic.showString("Hello World", 150)
|
||||
basic.showString("Good Night World ", 150) // ***
|
||||
```
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
Add Micro's response to Good Night World!
|
||||
|
71
olddocs/js/lessons/the-hat-game.md
Normal file
71
olddocs/js/lessons/the-hat-game.md
Normal file
@ -0,0 +1,71 @@
|
||||
# the hat game lesson
|
||||
|
||||
make a game to test your focus on the moving ball.
|
||||
|
||||
## Topic
|
||||
|
||||
Functions
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [tutorial](/lessons/the-hat-game/tutorial)
|
||||
* [quiz](/lessons/the-hat-game/quiz)
|
||||
* [quiz answers](/lessons/the-hat-game/quiz-answers)
|
||||
* [challenges](/lessons/the-hat-game/challenges)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to create **functions**, `function()` as a unit of code that performs a specific task and returns a result. We will be learning how to create the hat game app using functions, global variables, input on button pressed, if (conditionals), mod, random, Boolean, as well as simple commands such as show animation.
|
||||
|
||||
## Documentation
|
||||
|
||||
* **functions** : [read more...](/js/function)
|
||||
* **on button pressed** : [read more...](/reference/input/on-button-pressed)
|
||||
* **for** : [read more...](/reference/loops/for)
|
||||
* **if** : [read more...](/reference/logic/if)
|
||||
* **mod** : [read more...](/js/math)
|
||||
* **show animation** : [read more...](/reference/basic/show-animation)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create a global variable as a place where you can store data so that you can use it later in your code, accessible across functions and in nested code blocks
|
||||
* learn how to learn how to conditionally run code depending on whether a condition is true or false
|
||||
* learn how to return the modulus
|
||||
* learn how to show a series of image frames on the LED screen
|
||||
* learn how to run code when an input button is pressed
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Designs solutions (algorithms) that use repetition and two-way selection, ie if, then and else.(AL)
|
||||
* Uses diagrams to express solutions.(AB)
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Declares and assigns variables(AB)
|
||||
* Uses post-tested loop e.g.‘until’,and a sequence of selection statements in programs,including an if,then and else statement(AL)
|
||||
* Understands the difference between, and appropriately uses if and if, then and else statements(AL)
|
||||
* Uses a variable and relational operators within a loop to govern termination (AL) (GE)
|
||||
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
|
||||
* Selects the appropriate data types(AL) (AB
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Understands the difference between data and information(AB)
|
||||
* Performs more complex searches for information e.g. using Boolean and relational operators(AL) (GE) (EV)
|
||||
* Defines data types: real numbers and Boolean (AB)
|
||||
|
||||
#### Hardware & Processing
|
||||
|
||||
* Knows that computers collect data from various input devices, including sensors and application software (AB)
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
174
olddocs/js/lessons/the-hat-game/challenges.md
Normal file
174
olddocs/js/lessons/the-hat-game/challenges.md
Normal file
@ -0,0 +1,174 @@
|
||||
# the hat game challenges
|
||||
|
||||
The all famous Hat Game -- one of 3 hats has the ball, which is revealed at the beginning. The hats then swap with each other. You goal is to chose the hat with the ball after the hats have finished swapping. #docs
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/lessons/the-hat-game/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
initializeGame()
|
||||
playLevel()
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
selectHat()
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
chooseHat()
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Modify `play level()` to customize your difficulty levels. Simply increase the `swap speed` to make the game easier, or decrease it to make the game harder.
|
||||
|
||||
```
|
||||
/**
|
||||
* **. . .**
|
||||
*/
|
||||
export function playLevel_() {
|
||||
let swaps = 5 + 10 * level
|
||||
if (level == 1) {
|
||||
swaps = 100 // ***
|
||||
} else if (level == 2) {
|
||||
swapSpeed = 40 // ***
|
||||
}
|
||||
else {
|
||||
swapSpeed = 20 // ***
|
||||
}
|
||||
// **. . .**
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
Let's make the game a little more fun and devious! Let's add a `fake swap` function that pretends to swap the hats, but doesn't actually swap them.
|
||||
|
||||
```
|
||||
export function fakeSwap(hat_1: number, hat_2: number, pauseDifficulty: number) {
|
||||
if (hat_1 == 0 && hat_2 == 1) {
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . . # . . . . . # . . . # . . . . . . . . . . . . . .
|
||||
. . . . . # . . . . . . . . . . . . . . . . . . . # . . . . . . . . .
|
||||
# . # . # . . . . # . . . . # . . . . # . . . . # . . . . # # . # . #
|
||||
. . . . . . . # . . . . . . . . . . . . . . . . . . . # . . . . . . .
|
||||
. . . . . . . . . . . . # . . . # . . . . . # . . . . . . . . . . . .
|
||||
`, pauseDifficulty)
|
||||
}
|
||||
if (hat_1 == 1 && hat_2 == 0) {
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . . . . # . . . # . . . . . # . . . . . . . . . . . .
|
||||
. . . . . . . # . . . . . . . . . . . . . . . . . . . # . . . . . . .
|
||||
# . # . # . . . . # . . . . # . . . . # . . . . # . . . . # # . # . #
|
||||
. . . . . # . . . . . . . . . . . . . . . . . . . # . . . . . . . . .
|
||||
. . . . . . . . . . # . . . . . # . . . # . . . . . . . . . . . . . .
|
||||
`, pauseDifficulty)
|
||||
}
|
||||
if (hat_1 == 1 && hat_2 == 2) {
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . . . . # . . . . . # . . . # . . . . . . . . . . . .
|
||||
. . . . . . . # . . . . . . . . . . . . . . . . . . . # . . . . . . .
|
||||
# . # . # # . . . . # . . . . # . . . . # . . . . # . . . . # . # . #
|
||||
. . . . . . . . . # . . . . . . . . . . . . . . . . . . . # . . . . .
|
||||
. . . . . . . . . . . . . . # . . . # . . . . . # . . . . . . . . . .
|
||||
`, pauseDifficulty)
|
||||
}
|
||||
if (hat_1 == 2 && hat_2 == 1) {
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . . . . . . # . . . # . . . . . # . . . . . . . . . .
|
||||
. . . . . . . . . # . . . . . . . . . . . . . . . . . . . # . . . . .
|
||||
# . # . # # . . . . # . . . . # . . . . # . . . . # . . . . # . # . #
|
||||
. . . . . . . # . . . . . . . . . . . . . . . . . . . # . . . . . . .
|
||||
. . . . . . . . . . . . # . . . . . # . . . # . . . . . . . . . . . .
|
||||
`, pauseDifficulty)
|
||||
}
|
||||
if (hat_1 == 0 && hat_2 == 2) {
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . . # . . . . . # . . . . . # . . . # . . . # . . . . . . . . . . . . . .
|
||||
. . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . . . . .
|
||||
# . # . # . . # . . . . # . . . . # . . . . # . . . . # . . . . # . . . . # . . # . # . #
|
||||
. . . . . . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . .
|
||||
. . . . . . . . . . . . . . # . . . # . . . # . . . . . # . . . . . # . . . . . . . . . .
|
||||
`, pauseDifficulty)
|
||||
}
|
||||
if (hat_1 == 2 && hat_2 == 0) {
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . . . . . . # . . . # . . . # . . . . . # . . . . . # . . . . . . . . . .
|
||||
. . . . . . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . .
|
||||
# . # . # . . # . . . . # . . . . # . . . . # . . . . # . . . . # . . . . # . . # . # . #
|
||||
. . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . . . . .
|
||||
. . . . . . . . . . # . . . . . # . . . . . # . . . # . . . # . . . . . . . . . . . . . .
|
||||
`, pauseDifficulty)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 3
|
||||
|
||||
Now let's implement our `fake swap` function inside `play level`. Let's make a third of the swaps fake. This can be most efficiently accomplished through mod.
|
||||
|
||||
```
|
||||
/**
|
||||
* **. . .**
|
||||
*/
|
||||
export function playLevel_1() {
|
||||
let swaps = 5 + 10 * level
|
||||
// **. . .**
|
||||
for (let i = 0; i < swaps; i++) {
|
||||
let swapType = Math.random(3) // ***
|
||||
let not = Math.random(3)
|
||||
if (swapType < 2) {
|
||||
swapHats(math.mod(not + 1, 3), math.mod(not + 2, 3), swapSpeed) // ***
|
||||
} else {
|
||||
fakeSwap(math.mod(not + 1, 3), math.mod(not + 2, 3), swapSpeed) // ***
|
||||
}
|
||||
}
|
||||
index = -1
|
||||
choosingHat = true
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 4
|
||||
|
||||
For a swap of two given hats, one of the hats will always go up while the other goes down. For example, if the first and third hats are swapping, the first hat will always go down and the third will go up. Let's randomize the orientation of each swap by switching the parameters of each swap function half the time.
|
||||
|
||||
```
|
||||
/**
|
||||
* **. . .**
|
||||
*/
|
||||
export function playLevel_2() {
|
||||
let swaps = 5 + 10 * level
|
||||
// **. . .**
|
||||
for (let i = 0; i < swaps; i++) {
|
||||
let swapType = Math.random(3)
|
||||
let not = Math.random(3)
|
||||
let swapOrientation = Math.random(2) // ***
|
||||
if (swapType < 2) {
|
||||
if (swapOrientation == 0) {
|
||||
swapHats(math.mod(not + 1, 3), math.mod(not + 2, 3), swapSpeed) // ***
|
||||
} else {
|
||||
swapHats(math.mod(not + 2, 3), math.mod(not + 1, 3), swapSpeed) // ***
|
||||
}
|
||||
}
|
||||
else {
|
||||
swapOrientation = Math.random(2) // ***
|
||||
if (swapOrientation == 0) {
|
||||
fakeSwap(math.mod(not + 1, 3), math.mod(not + 2, 3), swapSpeed) // ***
|
||||
}
|
||||
else {
|
||||
fakeSwap(math.mod(not + 2, 3), math.mod(not + 1, 3), swapSpeed) // ***
|
||||
}
|
||||
}
|
||||
}
|
||||
index = -1
|
||||
choosingHat = true
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 5
|
||||
|
||||
Create your own swap animation. See if you can get all three hats to move at the same time!
|
||||
|
87
olddocs/js/lessons/the-hat-game/quiz-answers.md
Normal file
87
olddocs/js/lessons/the-hat-game/quiz-answers.md
Normal file
@ -0,0 +1,87 @@
|
||||
# the hat game quiz answers
|
||||
|
||||
The all famous Hat Game -- one of 3 hats has the ball, which is revealed at the beginning. The hats then swap with each other. You goal is to chose the hat with the ball after the hats have finished swapping.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [the hat game tutorial](/lessons/the-hat-game/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What is the name of the first function you created? What does it do?
|
||||
|
||||
<br/>
|
||||
|
||||
Initialize game() is the name of the first function. It helps set up the game state.
|
||||
|
||||
## 2. Write a for loop that plots the points (0, 2), (2, 2), and (4, 2).
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
for (let i = 0; i < 3; i++) {
|
||||
led.plot(i * 2, 2)
|
||||
}
|
||||
```
|
||||
|
||||
## 3. How can you increase the difficulty of the game?
|
||||
|
||||
<br/>
|
||||
|
||||
Decrease the swap speed value. This will reduce the pause between each frame, and will thus make the game run faster.
|
||||
|
||||
## 4. Consider the following code
|
||||
|
||||
```
|
||||
cupSelect = "LMR"
|
||||
index = -1
|
||||
```
|
||||
|
||||
Write the code that displays the next letter of the string in "cup select" when button A is pressed.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
index = index + 1
|
||||
if (index > 2) {
|
||||
index = 0
|
||||
}
|
||||
basic.showString(cupSelect[index], 150)
|
||||
})
|
||||
```
|
||||
|
||||
## 5. Write the line of code that shows the swapping animation of two hats swapping if hat 1 = 0 and hat 2 = 2.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
basic.showAnimation(`
|
||||
. . . . . . . . . . # . . . . . # . . . . . # . . . . . # . . . . . # . . . . . . . . . .
|
||||
. . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . .
|
||||
# . # . # . . # . . . . # . . . . # . . . . # . . . . # . . . . # . . . . # . . # . # . #
|
||||
. . . . . . . . . # . . . . . . . . . . . . . . . . . . . . . . . . . # . . . . . . . . .
|
||||
. . . . . . . . . . . . . . # . . . # . . . # . . . # . . . # . . . . . . . . . . . . . .
|
||||
`, 400)
|
||||
```
|
||||
|
||||
## 6. Consider the following code
|
||||
|
||||
```
|
||||
let not = Math.random(3)
|
||||
```
|
||||
|
||||
Given the hat we are not going to swap, how can we calculate the other two hats that we are going to swap? Use these two values to call "swap hats()" with a swap speed of 50.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
swapHats(math.mod(not + 1, 3), math.mod(not + 2, 3), 50)
|
||||
```
|
||||
|
||||
<br/>
|
||||
|
59
olddocs/js/lessons/the-hat-game/quiz.md
Normal file
59
olddocs/js/lessons/the-hat-game/quiz.md
Normal file
@ -0,0 +1,59 @@
|
||||
# the hat game quiz
|
||||
|
||||
The all famous Hat Game -- one of 3 hats has the ball, which is revealed at the beginning. The hats then swap with each other. You goal is to choose the hat with the ball after the hats have finished swapping.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [the hat game tutorial](/lessons/the-hat-game/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What is the name of the first function you created? What does it do?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write a for loop that plots the points (0, 2), (2, 2), and (4, 2).
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. How can you increase the difficulty of the game?
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Consider the following code
|
||||
|
||||
```
|
||||
cupSelect = "LMR"
|
||||
index = -1
|
||||
```
|
||||
|
||||
Write the code that displays the next letter of the string in "cup select" when button A is pressed.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
||||
## 5. Write the line of code that shows the swapping animation of two hats swapping if hat 1 = 0 and hat 2 = 2.
|
||||
|
||||
<br/>
|
||||
|
||||
## 6. Consider the following code
|
||||
|
||||
```
|
||||
let not = Math.random(3)
|
||||
```
|
||||
|
||||
Given the hat we are not going to swap, how can we calculate the other two hats that we are going to swap? Use these two values to call "swap hats()" with a swap speed of 50.
|
||||
|
||||
<br/>
|
||||
|
||||
<br/>
|
||||
|
9
olddocs/js/lessons/timing-game.md
Normal file
9
olddocs/js/lessons/timing-game.md
Normal file
@ -0,0 +1,9 @@
|
||||
# timing game
|
||||
|
||||
make a game to test hand-eye coordination.
|
||||
|
||||
### @video td/videos/timing-game-0
|
||||
|
||||
Make a game to test hand-eye coordination
|
||||
|
||||
* [tutorial](/lessons/timing-game/tutorial)
|
44
olddocs/js/lessons/transformer/quiz.md
Normal file
44
olddocs/js/lessons/transformer/quiz.md
Normal file
@ -0,0 +1,44 @@
|
||||
# transformers quiz
|
||||
|
||||
Use functions to return values.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [transformer tutorial](/lessons/transformer/tutorial)
|
||||
|
||||
Answer the questions below while working on or after you finish the tutorial. Pay attention to the dialogs!
|
||||
|
||||
## 1. What is a 'function'?
|
||||
|
||||
## 2. Consider the following directions
|
||||
|
||||
Write the line of code to create a number variable that is initially 5.
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Consider the following directions
|
||||
|
||||
Write the line of code to use the condition 'on button pressed ("A")'
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Consider the following directions
|
||||
|
||||
Write the code that creates a function.
|
||||
|
||||
<br/>
|
||||
|
||||
## 5. Consider the following directions
|
||||
|
||||
Write the code to call the function that doubles the input number. (the function is going to provide the doubled value after it is called). The code will assign the new value (10) to a variable which we will call `doubled`.
|
||||
|
||||
<br/>
|
||||
|
||||
## 6. Consider the following picture
|
||||
|
||||
Write the code to show number 20 on the BBC micro:bit. Please add the variable called `doubled` Refer to the finished code on the tutorial.
|
||||
|
||||
<br/>
|
||||
|
125
olddocs/js/lessons/transformers.md
Normal file
125
olddocs/js/lessons/transformers.md
Normal file
@ -0,0 +1,125 @@
|
||||
# transformers lesson
|
||||
|
||||
use functions to return values.
|
||||
|
||||
### @video td/videos/transformers-0
|
||||
|
||||
## Topic
|
||||
|
||||
Return
|
||||
|
||||
## Quick Links
|
||||
|
||||
* [tutorial](/lessons/transformers/tutorial)
|
||||
* [quiz](/lessons/transformers/quiz)
|
||||
* [quiz answers](/lessons/transformers/quiz-answers)
|
||||
* [challenges](/lessons/transformers/challenges)
|
||||
|
||||
## Class
|
||||
|
||||
Year 7
|
||||
|
||||
## Prior learning/place of lesson in scheme of work
|
||||
|
||||
Learn how to create **functions**, ` function() ` to make your code easier to read, debug, and update. We will be learning how to create functions as well as a global variable, input on button pressed as well simple commands such as show number.
|
||||
|
||||
## What the teacher needs to know
|
||||
|
||||
* Algorithm: An unambiguous set of rules or a precise step-bystep guide to solve a problem or achieve a particular objective.
|
||||
* Command: An instruction for the computer to execute, written in a particular programming language.
|
||||
* Data: A structured set of numbers, possibly representing digitised text, images, sound or video, which can be processed or transmitted by a computer, also used for numerical (quantitative) information.
|
||||
* Decomposing: The process through which problems or systems are broken down into their component parts, each of which may then be considered separately.
|
||||
* Hardware: The physical systems and components of digital devices; see also software.
|
||||
* Input: Data provided to a computer system, such as via a keyboard, mouse, microphone, camera or physical sensors.
|
||||
* Output: The information produced by a computer system for its user, typically on a screen, through speakers or on a printer, but possibly through the control of motors in physical systems.
|
||||
* Programmable toys: Robots designed for children to use, accepting input, storing short sequences of simple instructions and moving according to this stored program.
|
||||
* Program: A stored set of instructions encoded in a language understood by the computer that does some form of computation, processing input and/or stored data to generate output.
|
||||
* Script: A computer program typically executed one line at a time through an interpreter, such as the instructions for a Scratch character.
|
||||
* Selection: A programming construct in which one section of code or another is executed depending on whether a particular condition is met.
|
||||
* Sequence: To place program instructions in order, with each executed one after the other.
|
||||
* Simulation: Using a computer to model the state and behaviour of real-world (or imaginary) systems, including physical or social systems; an integral part of most computer games.
|
||||
* Variables: A way in which computer programs can store, retrieve or change data, such as a score, the time left, or the user’s name.
|
||||
|
||||
**QuickStart Computing Glossary
|
||||
|
||||
## Documentation
|
||||
|
||||
* **function** : [read more...](/js/function)
|
||||
* **return** : [read more...](/js/return)
|
||||
* **call** : [read more...](/js/call)
|
||||
* **global variable** : [read more...](/js/data)
|
||||
* **on button pressed** : [read more...](/reference/input/on-button-pressed)
|
||||
* **local variable** : [read more...](/reference/variables/var)
|
||||
* **show number** : [read more...](/reference/basic/show-number)
|
||||
|
||||
## Resources
|
||||
|
||||
* Activity: [tutorial](/lessons/transformers/tutorial)
|
||||
* Activity: [quiz](/lessons/transformers/quiz)
|
||||
* Extended Activity: [challenges](/lessons/transformers/challenges)
|
||||
|
||||
## Objectives
|
||||
|
||||
* learn how to create a function that performs a specific task to make your code easier to read, debug, and update
|
||||
* learn how the return statement exits a function and returns a value to the code
|
||||
* learn how to call an existing function in your script
|
||||
* learn how to create a global variable to store data so that you can use it later in your code and accessible across functions and in nested code blocks
|
||||
* learn how to run code when an input button is pressed
|
||||
* learn how to create a local variable to store data, so that you can use it in your code
|
||||
* learn how to show a number on the LED screen
|
||||
|
||||
## Links to the National Curriculum Programmes of Study for Computing
|
||||
|
||||
## Progression Pathways / Computational Thinking Framework
|
||||
|
||||
#### Algorithms
|
||||
|
||||
* Uses diagrams to express solutions.(AB)
|
||||
* Uses logical reasoning to predict outputs, showing an awareness of inputs (AL)
|
||||
* Designs solutions by decomposing a problem and creates a sub-solution for each of these parts. (DE) (AL) (AB)
|
||||
* Represents solutions using a structured notation (AL) (AB)
|
||||
|
||||
#### Programming & Development
|
||||
|
||||
* Creates programs that implement algorithms to achieve given goals (AL)
|
||||
* Declares and assigns variables(AB)
|
||||
* Uses a variable and relational operators within a loop to govern termination (AL) (GE)
|
||||
* Uses a range of operators and expressions e.g. Boolean, and applies them in the context of program control. (AL)
|
||||
* Selects the appropriate data types(AL) (AB
|
||||
|
||||
#### Data & Data Representation
|
||||
|
||||
* Uses filters or can perform single criteria searches for information.(AL)
|
||||
* Defines data types: real numbers and Boolean (AB)
|
||||
|
||||
#### Hardware & Processing
|
||||
|
||||
* Knows that computers collect data from various input devices, including sensors and application software (AB)
|
||||
|
||||
#### Information Technology
|
||||
|
||||
* Collects, organizes, and presents data and information in digital content (AB)
|
||||
* Makes appropriate improvements to solutions based on feedback received, and can comment on the success of the solution (EV)
|
||||
* Recognises ethical issues surrounding the application of information technology beyond school.
|
||||
|
||||
Computational Thinking Concept: AB = Abstraction; DE = Decomposition; AL = Algorithmic Thinking; EV = Evaluation; GE = Generalisation
|
||||
|
||||
## Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [tutorial](/lessons/transformers/tutorial)
|
||||
* [quiz](/lessons/transformers/quiz)
|
||||
|
||||
## Extended Activity
|
||||
|
||||
* time: 20 min.
|
||||
* [challenges](/lessons/transformers/challenges)
|
||||
|
||||
## Homework
|
||||
|
||||
* Extended Activity: [challenges](/lessons/transformers/challenges)
|
||||
|
||||
## Intended follow on
|
||||
|
||||
Publish script to the classroom.
|
||||
|
54
olddocs/js/lessons/transformers/challenges.md
Normal file
54
olddocs/js/lessons/transformers/challenges.md
Normal file
@ -0,0 +1,54 @@
|
||||
# transformers challenges
|
||||
|
||||
Coding challenges for the transformers tutorial. #docs
|
||||
|
||||
## Before we get started
|
||||
|
||||
Complete the following guided tutorial:
|
||||
|
||||
* [tutorial](/lessons/transformers/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
let inital = 5
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let doubled1 = double(initial)
|
||||
basic.showNumber(doubled1, 150) // ***
|
||||
})
|
||||
```
|
||||
|
||||
### Challenge 1
|
||||
|
||||
Create a new function called `square` that returns the square of the number passed into the function.
|
||||
|
||||
(Squaring means that you multiply the number by itself)
|
||||
|
||||
```
|
||||
export function square(n: number) : number {
|
||||
let num: number
|
||||
return n * n
|
||||
return num
|
||||
}
|
||||
```
|
||||
|
||||
### Challenge 2
|
||||
|
||||
### @video td/videos/transformers-2
|
||||
|
||||
Add a condition for when button `B` is pressed. We will use this condition in the last challenge.
|
||||
|
||||
```
|
||||
initial = 5
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
let doubled = double(initial)
|
||||
basic.showNumber(doubled, 150)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
}) // ***
|
||||
```
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
When the `B` button is pressed, display the square of the initial value. Use the function `square`. You should get the value 25.
|
||||
|
65
olddocs/js/lessons/transformers/quiz-answers.md
Normal file
65
olddocs/js/lessons/transformers/quiz-answers.md
Normal file
@ -0,0 +1,65 @@
|
||||
# transformers quiz answers
|
||||
|
||||
Use functions to return values.
|
||||
|
||||
This is the answer key for the [transformers quiz](/lessons/transformers/quiz).
|
||||
|
||||
## 1. What is a 'function'?
|
||||
|
||||
A function is a unit of code that performs a specific task and returns a result.
|
||||
|
||||
## 2. Write the line of code to create a number variable called "x" is equal to 5.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
let x = 5
|
||||
```
|
||||
|
||||
## 3. Write the line of code to create a condition for 'on button pressed ("A")'
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
})
|
||||
```
|
||||
|
||||
## 4. Write the steps to create a function.
|
||||
|
||||
<br/>
|
||||
|
||||
Click on `script`, then `add new`, and select `function`.
|
||||
|
||||
## 5. Create a function called double that will double whatever input parameter is passed into it.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
export function double(n: number) : number {
|
||||
let r: number
|
||||
return n * 2
|
||||
return r
|
||||
}
|
||||
```
|
||||
|
||||
## 6. Consider the following directions
|
||||
|
||||
Call the `function` that doubles the variable **x**. (The `function` is going to return the doubled value after it is called). Assign the new value (10) to a variable which we will call `doubled`.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
let doubled = double(x)
|
||||
```
|
||||
|
||||
## 7. Refer to Question 6
|
||||
|
||||
Write the code to call the function that doubles our new `variable` doubled. Assign the new value 20 to a variable we will call doubled twice.
|
||||
|
||||
<br/>
|
||||
|
||||
```
|
||||
let doubleTwice = double(doubled)
|
||||
```
|
||||
|
40
olddocs/js/lessons/transformers/quiz.md
Normal file
40
olddocs/js/lessons/transformers/quiz.md
Normal file
@ -0,0 +1,40 @@
|
||||
# transformers quiz
|
||||
|
||||
Use functions to return values.
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [transformers tutorial](/lessons/transformers/tutorial)
|
||||
|
||||
Answer the questions while completing the tutorial. Pay attention to the dialogues!
|
||||
|
||||
## 1. What is a 'function'?
|
||||
|
||||
<br/>
|
||||
|
||||
## 2. Write the line of code to create a number variable called **x** that is equal to 5.
|
||||
|
||||
<br/>
|
||||
|
||||
## 3. Write the line of code to create a condition for 'on button pressed ("A")'
|
||||
|
||||
<br/>
|
||||
|
||||
## 4. Write the steps to create a function.
|
||||
|
||||
<br/>
|
||||
|
||||
## 5. Create a function called **double** that will double whatever input parameter is passed into it.
|
||||
|
||||
<br/>
|
||||
|
||||
## 6. Consider the following directions. Call the function that doubles the variable original. The function is going to return the doubled value after it is called. Assign the new value (10) to a variable which we will call doubled.
|
||||
|
||||
<br/>
|
||||
|
||||
## 7. Refer to Question 6. Write the code to call the function that doubles our new variable doubled. Assign the new value 20 to a variable we will call doubled twice.
|
||||
|
||||
<br/>
|
||||
|
80
olddocs/js/lessons/typing-game/challenges.md
Normal file
80
olddocs/js/lessons/typing-game/challenges.md
Normal file
@ -0,0 +1,80 @@
|
||||
# typing game challenges
|
||||
|
||||
My script. #docs
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
This [guided tutorial](/lessons/typing-game/tutorial) will teach you how to use the method concat to connect to pieces of text together.
|
||||
|
||||
```
|
||||
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
index = 0
|
||||
name = ""
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
led.showString(alphabet.substr(index, 1), 0)
|
||||
index = index + 1
|
||||
})
|
||||
if (index > 25) {
|
||||
index = 0
|
||||
}
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
name = name.concat(alphabet.substr(index - 1, 1))
|
||||
})
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
led.showString(name, 150)
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
After you have shown the string in the condition `on shake`, make the name variable hold nothing in it again so people can add a new name after they have shaken it.
|
||||
|
||||
```
|
||||
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
index = 0
|
||||
name = ""
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
led.showString(alphabet.substr(index, 1), 0)
|
||||
index = index + 1
|
||||
})
|
||||
if (index > 25) {
|
||||
index = 0
|
||||
}
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
name = name.concat(alphabet.substr(index - 1, 1))
|
||||
})
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
led.showString(name, 150)
|
||||
name = "" // ***
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
After you have cleared the name variable to hold nothing, make `index := 0` so that when button `A` is pressed, the first letter of the alphabet will be displayed.
|
||||
|
||||
```
|
||||
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
index = 0
|
||||
name = ""
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
led.showString(alphabet.substr(index, 1), 0)
|
||||
index = index + 1
|
||||
})
|
||||
if (index > 25) {
|
||||
index = 0
|
||||
}
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
name = name.concat(alphabet.substr(index - 1, 1))
|
||||
})
|
||||
input.onGesture(Gesture.Shake, () => {
|
||||
led.showString(name, 150)
|
||||
name = ""
|
||||
index = 0 // ***
|
||||
})
|
||||
```
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
Give Micro a nickname and display it on the micro:bit!
|
||||
|
65
olddocs/js/lessons/while-counting/challenges.md
Normal file
65
olddocs/js/lessons/while-counting/challenges.md
Normal file
@ -0,0 +1,65 @@
|
||||
# digi yoyo challenges
|
||||
|
||||
These challenges will teach you how to create a counter 10 to 1. #docs
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
### @video vimeo/134459911
|
||||
|
||||
[This guided tutorial](/lessons/digi-yoyo/tutorial) will teach you how to make a counter from 0-9 using a while loop.
|
||||
|
||||
```
|
||||
count = 1
|
||||
while (count < 10) {
|
||||
basic.pause(1000)
|
||||
basic.showNumber(count, 150)
|
||||
count = count + 1
|
||||
}
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
How about we create a counter that counts backwards from 10 to 1? Let's add a while loop that executes only when `count` is greater than 0.
|
||||
|
||||
```
|
||||
count = 1
|
||||
while (count < 10) {
|
||||
basic.pause(1000)
|
||||
basic.showNumber(count, 150)
|
||||
count = count + 1
|
||||
}
|
||||
while (count > 0) {
|
||||
}
|
||||
```
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
Inside of the while loop, let's add `pause->(1000)` so that we have a pause between each number as it's counting down. Also, let's show `count`!
|
||||
|
||||
```
|
||||
count = 1
|
||||
while (count < 10) {
|
||||
basic.pause(1000)
|
||||
basic.showNumber(count, 150)
|
||||
count = count + 1
|
||||
}
|
||||
while (count > 0) {
|
||||
basic.pause(1000) // ***
|
||||
basic.showNumber(count, 150) // ***
|
||||
}
|
||||
```
|
||||
|
||||
* Run the code to see if it works as expected.
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
### @video vimeo/134449661
|
||||
|
||||
Now, we need `count` to decrease by one after the micro:bit has displayed the value of `count`.
|
||||
|
||||
We can do this by adding this line:
|
||||
|
||||
```
|
||||
count = count - 1
|
||||
```
|
||||
|
49
olddocs/js/lessons/yes-no/challenges.md
Normal file
49
olddocs/js/lessons/yes-no/challenges.md
Normal file
@ -0,0 +1,49 @@
|
||||
# yes no challenges
|
||||
|
||||
My script. #docs
|
||||
|
||||
**Challenge 0**
|
||||
|
||||
This [guided tutorial](/lessons/yes-no/challenges) will show you how to display text on the micro:bit!
|
||||
|
||||
```
|
||||
basic.showString("ASK ME A QUESTION", 150)
|
||||
```
|
||||
|
||||
**Challenge 1**
|
||||
|
||||
### @video vimeo/134142879
|
||||
|
||||
Now we need to reply after someone asks Micro a yes or no question. We want to respond `YES` when button `A` is pressed. Add a condition for button `A` and inside it show the string `YES`.
|
||||
|
||||
```
|
||||
basic.showString("ASK ME A QUESTION", 150)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("YES", 150) // ***
|
||||
}) // ***
|
||||
```
|
||||
|
||||
* `Run` the code to see if it works as expected.
|
||||
|
||||
**Challenge 2**
|
||||
|
||||
### @video vimeo/134142673
|
||||
|
||||
What if Micro's answer to the question is no? Let's have `NO` be displayed when button `B` is pressed. Add a condition for button `B` and inside it show the string `NO`.
|
||||
|
||||
```
|
||||
basic.showString("ASK ME A QUESTION", 150)
|
||||
input.onButtonPressed(Button.A, () => {
|
||||
basic.showString("YES", 150)
|
||||
})
|
||||
input.onButtonPressed(Button.B, () => {
|
||||
basic.showString("NO", 150) // ***
|
||||
}) // ***
|
||||
```
|
||||
|
||||
* `Run` the code to see if it works as expected.
|
||||
|
||||
**Challenge 3**
|
||||
|
||||
When you are asked a yes or no question, do you always say yes or no? Add a condition for `on shake` that displays `MAYBE`.
|
||||
|
Reference in New Issue
Block a user