You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/courses/blocks-to-javascript/complex-conditionals.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@
5
5
Sometimes there is code you want to run if two or more conditions are true. The ``||logic:if then||`` block lets you combine conditions with the ``||logic:and||`` and the ``||logic:or||`` blocks. For example, if we want to see if a random number is between `0` and `9`, we can put two conditions in an ``||logic:if then||`` and connect them with an ``||logic:and||``.
6
6
7
7
```blocks
8
-
let rando = Math.randomRange(-20, 20)
8
+
let rando = randint(-20, 20)
9
9
if (rando >= 0 && rando < 10) {
10
10
basic.showNumber(rando)
11
11
}
@@ -14,7 +14,7 @@ if (rando >= 0 && rando < 10) {
14
14
This is how to check if a result is within a range of values, in this case it's from `0` to `9`. What if we want to include the values between `15` and `18` too? We just add another range check and connect them with an ``||logic:or||``.
Having all of these conditions in one ``||logic:if then||`` makes a large and complicated block. It can be hard to see how the complete conditional does both of the range checks. At times, it's easier to read the code in the JavaScript editor to better see the order and connections of the conditions.
24
24
25
25
```typescript
26
-
let rando =Math.randomRange(-20, 20)
26
+
let rando =randint(-20, 20)
27
27
if ((rando>=0&&rando<10) || (rando>=15&&rando<18)) {
28
28
basic.showNumber(rando)
29
29
}
@@ -36,7 +36,7 @@ As you can see, reading the code for this conditional is might seem easier in Ja
36
36
If one ``||logic:if then||`` block is placed inside another, then each condition for checking the random number is placed in its own ``||logic:if then||``. This give the same result as before with the two conditions in the ``||logic:if then||``.
37
37
38
38
```block
39
-
let rando = Math.randomRange(-20, 20)
39
+
let rando = randint(-20, 20)
40
40
if (rando >= 0) {
41
41
if (rando < 10) {
42
42
basic.showNumber(rando)
@@ -47,7 +47,7 @@ if (rando >= 0) {
47
47
When we switch the editor to JavaScript view, we see that the second ``if ()`` statement is indented and contained inside the `{ }` of the first. This matches the second ``||logic:if then||`` block that fits inside the first one. These are called _nested_ if statements.
48
48
49
49
```typescript
50
-
let rando =Math.randomRange(-20, 20)
50
+
let rando =randint(-20, 20)
51
51
if (rando>=0) {
52
52
if (rando<10) {
53
53
basic.showNumber(rando)
@@ -138,4 +138,4 @@ To set the variable based on the result of the expression, the value options are
138
138
let heatMessage =input.temperature() <10?"COLD":"WARM"
139
139
```
140
140
141
-
The ``heatMeassage`` variable is set to the string saying ``"COLD"`` if the temperature is less than `10` degrees celsius or to ``"WARM"`` when it's `10` degrees or warmer.
141
+
The ``heatMeassage`` variable is set to the string saying ``"COLD"`` if the temperature is less than `10` degrees celsius or to ``"WARM"`` when it's `10` degrees or warmer.
Copy file name to clipboardExpand all lines: docs/courses/csintro/arrays/activity.md
+14-14
Original file line number
Diff line number
Diff line change
@@ -6,12 +6,12 @@ Create an array of words that can be used as part of a charades-type game.
6
6
This activity is based on a very popular phone app invented by Ellen DeGeneres (https://bits.blogs.nytimes.com/2013/05/03/ellen-degeneres-iphone-game/).
7
7
8
8

9
-
9
+
10
10
* Create a new variable and give it a name like arrayWords.
11
-
* Insert a 'set' variable block into the 'on start' block.
11
+
* Insert a 'set' variable block into the 'on start' block.
12
12
* Change the default variable name to this new variable name.
13
13
* From the Array Toolbox drawer, drag an 'array of' block to the coding workspace.
14
-
* Attach this array block to the end of the 'set' variable block.
14
+
* Attach this array block to the end of the 'set' variable block.
* Fill each string with one word. Choose words that will be fun for a game of charades. Example:
30
30
31
-
```blocks
31
+
```blocks
32
32
let arrayWords = ["cat", "guitar", "flashlight", "cupcake", "tree", "frisbee"]
33
33
```
34
34
35
35
Now, we need a way to access one word at a time from this array of words.
36
-
* We can use the 'show string' block from the Basic Toolbox drawer, and the 'on screen up' event handler from the Input Toolbox drawer (this is a drop-down menu choice of the 'on shake' block) to tell the micro:bit to display a word when we tilt the micro:bit up.
36
+
* We can use the 'show string' block from the Basic Toolbox drawer, and the 'on screen up' event handler from the Input Toolbox drawer (this is a drop-down menu choice of the 'on shake' block) to tell the micro:bit to display a word when we tilt the micro:bit up.
37
37
* For this version, we’ll display the words one at a time in the order they were first placed into the array.
38
38
* We’ll use the index of the array to keep track of what word to display at any given time, so you'll need to create an 'index' variable.
We have a limited number of elements in our array, so to avoid an error, we need to check and make sure we are not already at the end of the array before we change the index.
90
90
91
91
* Under the Arrays Toolbox drawer, drag out a 'length of' block. The 'length of' block returns the number of items (elements) in an array. For our array, the length of block will return the value 6.
92
-
* But because computer programmers start counting at zero, the index of the final (6th) element is 5.
92
+
* But because computer programmers start counting at zero, the index of the final (6th) element is 5.
93
93
94
94
Some pseudocode for our algorithm logic:
95
95
* When the player places the micro:bit screen down:
There are different ways you can play charades with our program. Here is one way you can play with a group of friends.
143
143
144
-
* With the micro:bit on and held so Player A cannot see the screen, another player starts the program to see the first word.
144
+
* With the micro:bit on and held so Player A cannot see the screen, another player starts the program to see the first word.
145
145
* The other players act out this word charades-style for Player A to guess.
146
-
* When Player A guesses correctly or decides to pass on this word, a player places the micro:bit screen down.
146
+
* When Player A guesses correctly or decides to pass on this word, a player places the micro:bit screen down.
147
147
* When ready for the next word, a player turns the micro:bit screen up. Play continues until all the words in the array have been used.
148
148
149
149
## Mod this!
@@ -197,15 +197,15 @@ Review the use of the random block in the Math category.
197
197
* Create a block that will plot a single dot at a random location on the screen by choosing a random number from 0 to 4 for the x axis and a random number from 0 to 4 for the y axis.
The above code takes the first value in the array and creates that many stars at random locations. Now, all we need to do is iterate through the entire array and do the same thing for each of the values. We will put the above code inside another loop that will run the same number of times as the length of the array (in this case, 5). You should also use a 'pause' block and a 'clear screen' block in between each constellation.
241
241
242
-
Finally, you might attach the code that shows the constellations to an 'on button A pressed' event handler.
242
+
Finally, you might attach the code that shows the constellations to an 'on button A pressed' event handler.
Copy file name to clipboardExpand all lines: docs/courses/csintro/booleans/project.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3

4
4
5
-
This is an assignment for students to come up with a micro:bit program that uses Boolean variables, Boolean operators, and possibly the random function.
5
+
This is an assignment for students to come up with a micro:bit program that uses Boolean variables, Boolean operators, and possibly the random function.
6
6
7
7
## Input
8
8
Remind the students of all the different inputs available to them through the micro:bit.
@@ -205,7 +205,7 @@ let player1Turn = false
205
205
let spin = 0
206
206
let delay = 0
207
207
input.onGesture(Gesture.Shake, () => {
208
-
if (player1Turn == true && Math.randomRange(0, 4) < 3) {
0 commit comments