Migrate docs from the other repo
This commit is contained in:
54
docs/reference/js/lessons/transformers/challenges.md
Normal file
54
docs/reference/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](/microbit/lessons/transformers/tutorial)
|
||||
|
||||
At the end of the tutorial, click `keep editing`. Your code should look like this:
|
||||
|
||||
```
|
||||
let inital = 5
|
||||
input.onButtonPressed("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("A", () => {
|
||||
let doubled = double(initial)
|
||||
basic.showNumber(doubled, 150)
|
||||
})
|
||||
input.onButtonPressed("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
docs/reference/js/lessons/transformers/quiz-answers.md
Normal file
65
docs/reference/js/lessons/transformers/quiz-answers.md
Normal file
@ -0,0 +1,65 @@
|
||||
# transformers quiz answers
|
||||
|
||||
Use functions to return values #LED #number #math #functions #return #docs
|
||||
|
||||
This is the answer key for the [transformers quiz](/microbit/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("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
docs/reference/js/lessons/transformers/quiz.md
Normal file
40
docs/reference/js/lessons/transformers/quiz.md
Normal file
@ -0,0 +1,40 @@
|
||||
# transformers quiz
|
||||
|
||||
Use functions to return values #LED #number #math #functions #return #docs
|
||||
|
||||
## Name
|
||||
|
||||
## Directions
|
||||
|
||||
Use this activity document to guide your work in the [transformers tutorial](/microbit/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/>
|
||||
|
Reference in New Issue
Block a user