diff --git a/olddocs/js/bits.md b/olddocs/js/bits.md deleted file mode 100644 index 93901625..00000000 --- a/olddocs/js/bits.md +++ /dev/null @@ -1,67 +0,0 @@ -# Bits Library - -Functions in the Bits library. - -### @parent td/language - -The binary numeral system represents numeric values using values 0 and 1. This is how almost all modern computers store data. Each 0 or 1 digit is called a binary digit, or bit for short. - -The Bits library includes functions for bit-level manipulation of integers. In the [Touch Develop editor](/javascript/editor), click `bits` to see the following bit functions: - -## Bitwise and, or, and xor functions - -#### Syntax - -bits `->` *and/or/xor* uint32 (x : [Number](/types/number), y : [Number](/types/number)) *returns* [Number](/types/number) - -#### Parameters - -* x - an unsigned 32 bit integer [Number](/types/number) -* y - another unsigned 32 bit integer [Number](/types/number) - -### and uint32 - -performs bitwise AND; returns `1` at position i if both bits *x[i]* and *y[i]* are `1`, otherwise returns `0`. - -### or uint32 - -performs bitwise OR; returns `1` at position *i* if either bit *x[i]* or *y[i]* is `1`, otherwise returns `0`. - -### xor uint32 - -performs bitwise exclusive XOR; returns `1` at position *i* if *x[i]=1 and y[i]=0* or *x[i] = 0 and y[i] =1*; returns `0` otherwise - -## Rotate left and rotate right - -Rotate bits to the left or the right, by the specified number of positions. - -#### Syntax - -bits `->` rotate left unint32 (x : [Number](/types/number), bits : [Number](/types/number)) *returns* [Number](/types/number) - -bits `->` rotate right unint32 (x : [Number](/types/number), bits : [Number](/types/number)) *returns* [Number](/types/number) - -#### Parameters - -* x - [Number](/types/number); -* bits - [Number](/types/number); - -## Shift left and shift right - -Shift bits to the left or the right, by the specified number of positions. - -#### Syntax - -bits `->` shift left unint32 (x : [Number](/types/number), bits : [Number](/types/number)) *returns* [Number](/types/number) - -bits `->` shift right unint32 (x : [Number](/types/number), bits : [Number](/types/number)) *returns* [Number](/types/number) - -#### Parameters - -* x - [Number](/types/number); -* bits - [Number](/types/number); - -### See also - -[statements and operators](/javascript/statements), [math functions](/javascript/math), [Number](/types/number) - diff --git a/olddocs/js/break.md b/olddocs/js/break.md deleted file mode 100644 index 11e0dd10..00000000 --- a/olddocs/js/break.md +++ /dev/null @@ -1,33 +0,0 @@ -# Break - -Break statement; exit a for or while loop. - -### @parent javascript/language - - -Exit a [while](/javascript/while) or [for](/reference/loops/for) loop before the loop is complete. - -### Touch Develop syntax - -**break** - -### Example: count to a random number - -The following example counts from 0 to a random number from 0-9. When the for loop counter equals the random number (`i = x`), the `break` statement exits the loop: - -``` -let x = Math.random(10) -for (let i = 0; i < 10; i++) { - if (i == x) { - break - } else { - basic.showNumber(i, 0) - basic.pause(500) - } -} -``` - -### See also - -[for](/reference/loops/for), [while](/javascript/while) - diff --git a/olddocs/js/call.md b/olddocs/js/call.md deleted file mode 100644 index 821f600d..00000000 --- a/olddocs/js/call.md +++ /dev/null @@ -1,63 +0,0 @@ -# Call a Function - -How to call a function in your code. - -### @parent javascript/language - - -Type a function name in your code to call an existing [function](/javascript/function) in your script. - -### Call a function - -1. In the Touch Develop editor, click a line of code to open the on-screen [Code Keyboard](/javascript/editor). - -2. Click `code` to see the functions in your script. - -2. Click the function that you want to call. - -3. Click `store in var` to store the return value in a variable. - -### Example: the square function - -Here's a function called `square`, with a [Number](/types/number) input parameter: - -``` -/** - * // returns the square of the input parameter x - * @param x TODO - */ -export function square(x: number) : number { - let result: number - return x * x - return result -} -``` - -The following code calls the `square` function, passing it an input parameter (`x`), and storing the return value in the `result` variable: - -### ~hide - -``` -let x1 = 2 -``` - -### ~ - -``` -let result1 = square(x1) -``` - -Or this code, which displays the result of the `square` function (without first storing the value in a variable): - -``` -basic.showNumber(square(x1), 150) -``` - -### See all your functions - -To see a list of the functions in a script, open the script and then click `script` (in the upper-right corner). All of the functions appear under the **code** heading. Click on a function to open it in the editor. - -### See also - -[function parameters](/javascript/functionparameters), [create a function](/javascript/function), [return statement](/javascript/return) - diff --git a/olddocs/js/code.md b/olddocs/js/code.md deleted file mode 100644 index 060babfc..00000000 --- a/olddocs/js/code.md +++ /dev/null @@ -1,31 +0,0 @@ -# function - -A function with inputs and outputs. - -### @parent javascript/language - - -To add a **functions** to your script, click the `script` button, then click the `+` `add new function` button - -### functions - -A **function** takes [inputs](/actionparameters), runs code and (optionally) returns an output. - -TouchDevelop functions are similar to `mathematical functions`. Consider the function that computes the square of `x`: `square(x) = x*x`. In code, it would look like this: - -``` -export function square(x: number) : number { - let result: number - return x * x - return result -} -``` - -### private function - -An function can be marked as **private** in the properties. A private function is not visible outside a library (if the script is a library) - -### documentation - -The comment(s) at the beginning of a function used to provide a description of its purpose. This text will show in the help area when the function is called from the code editor. This is particularly useful for [libraries](/libraries). - diff --git a/olddocs/js/collections.md b/olddocs/js/collections.md deleted file mode 100644 index a71ed987..00000000 --- a/olddocs/js/collections.md +++ /dev/null @@ -1,111 +0,0 @@ -# The Collections Library - -#docs - -A collection allows you to store an arbitrary number of elements. If you have a collection of numbers, you can add new numbers to the collection; remove numbers; check if a number is in there; iterate over all the numbers in the collection. - -## Creation - -A collection is created as follows. Note that we are providing the *type* of the elements that are meant to go in the collection. - -``` -let c = ([]) -``` - -At the moment, you can create collections of numbers, booleans, strings, and any of the object types that you defined. - -**Important:** if your collection is a global variable, make sure you initialise it at the beginning of your script. - -``` -c = ([]) -``` - -Trying to use an uninitialised collection will crash the simulator, and display a sad face on the device. - -## Adding and finding elements; counting - -``` -c.push(3) -``` - -The line above just added the number `3` to the collection. One can think of a collection as a list, where `add` appends the element at the end of the list. - -At this stage, our collection has size `1`, meaning that the line below will display `1`. - -``` -basic.showNumber(c.length, 150) -``` - -We can add another number as follows. - -``` -c.push(5) -``` - -At this stage, the count of elements in the collection is `2`. We mentioned earlier that a collection is like a list: adding elements appends them at the end of the list. This means that, at this point in the program, the first element in the list is 3 (we added it earlier), and the second element in the list is 5 (we just added it). - -``` -basic.showNumber(c[0], 150) -``` - -Can you guess what the line above does? Remember that in computing, indexing starts at zero. This function takes the *first element* in the list. This means that the line above displays `3`. - -We can ask questions such as: "what is the index of this element"? The line below displays `1`, meaning that the number `5` is first found at index `1` (it is the *second* element in the list). - -``` -basic.showNumber(c.indexOf(5, 0), 150) -``` - -## Iterating over the elements - -A classic pattern consists in iterating over all the elements in the collection. Here's one way to do it: - -``` -for (let i = 0; i < c.length; i++) { - basic.showString("The element at index " + i.toString() + " is " + c[i].toString(), 150) -} -``` - -The code above will first print `The element at index 0 is 3`, then `The element at index 1 is 5`. - -## Modifying and removing elements - -One can modify an existing collection using `set at`, which changes the element *at a given index*. - -``` -c[0] = 7 -``` - -The line above modifies the collection `c` so that, after the line above, the first element of the collection is now `7`. - -Removing elements can be done in two different ways. We can remove the *first occurrence* of an element. - -``` -c.remove(5) -``` - -This removes the first occurrence of `5` in the list. At this point in the program, our list now has just one element (at index 0). If we wish, we can use `remove at` to remove the element at a given index. - -``` -c.splice(0, 1) -``` - -Now, the collection is empty. - -## Complete example - -This program will record the current acceleration measured on `x` when you press `A`; when you press `B`, the program will print out all the acceleration values that were measured, then will clear the collection. - -``` -let accelerations = ([]) -input.onButtonPressed(Button.A, () => { - accelerations.push(input.acceleration("x")) -}) -input.onButtonPressed(Button.B, () => { - for (let i1 = 0; i1 < accelerations.length; i1++) { - basic.showString(accelerations[i1].toString(), 150) - } - accelerations.clear() -}) -``` - diff --git a/olddocs/js/comment.md b/olddocs/js/comment.md deleted file mode 100644 index 60bba33e..00000000 --- a/olddocs/js/comment.md +++ /dev/null @@ -1,68 +0,0 @@ -# Comment - -A note in code. - -### @parent javascript/statement - - -A comment is a line of code that contains text, usually an explanation or a note. All comments are ignored during script execution. - -### Block - -Right click on any block and add a comment - -### Touch Develop syntax - -To insert a comment in a Touch Develop script: - -1. Click a line in your script. - -2. Click `+`. - -3. Click `// comment` and then type some text (your comment). - - -### Sample function with comments - -This function has comments that describe the purpose of the function: - -``` -/** - * // square function : - * // returns the square of the input parameter x - * @param x TODO - */ -export function square(x: number) : number { - return x * x -} -``` - -### Commenting out code - -During the debugging process, you may want to comment out a section of your code so that it doesn't run. - -To comment out a block of code: - -1. Click the first line of code that you want to comment out. - -2. Press and hold the Shift key, and then press the Down arrow key to select a block of code. - -3. In the block editing window, scroll down to **surround with** and click `comment out`. This adds an [if](/blocks/logic/if) statement around your code, like this: - -``` -if (false) { - // the commented code here... -} -``` - -When you want to uncomment your code, click the `if false then` statement in your code, and then click `uncomment`. - -### Library and function comments - -* Use [comments](/javascript/comment) at the beginning of a library to describe the library -* Use [comments](/javascript/comment) at the beginning of a [function](/javascript/function) to describe a function. The comment will appear in the help area of the Touch Develop editor when you insert the function - -### See also - -[markdown syntax](/javascript/markdown), [Touch Develop editor](/javascript/editor) - diff --git a/olddocs/js/compiler.md b/olddocs/js/compiler.md deleted file mode 100644 index 1df3cb3a..00000000 --- a/olddocs/js/compiler.md +++ /dev/null @@ -1,30 +0,0 @@ -# In-browser compiler - -The @boardname@ pins. - -## We listened to your feedback! - -Following the feedback from teachers, the following improvements were made: - -* compile without signing in -* compile offline -* save and load code using files - -## A new in-browser compiler - -The compilation from a script to ARM machine code is now done entirely in the browser (read the [in depth story](https://www.touchdevelop.com/docs/touch-develop-in-208-bits) about building the compiler). The new compiler is used by the Block Editor, Touch Develop and Code Kingdoms to create a .hex file solely within the confines of your web browser (no Internet connection is needed). The @boardname@ compilation process (see page 10 in the Quick Start book) has been updated below to reflect the new compiler architecture, shown below. - -![](/static/mb/offline-2.png) - -The C++ compiler now only is used to compile the @boardname@ runtime - this is done offline by the @boardname@ team and the precompiled runtime linked with your compiled script in the browser. - -## Save and load code using files - -![](/static/mb/offline-0.png) - -The @boardname@ automatically saves and synchronizes scripts for signed in users through the cloud. Unfortunately, this scenario would not work always so we decided to also support files. Users are now able to import and export scripts as files. For example, they can simply email it or submit them in their classroom portal. - -![](/static/mb/offline-1.png) - -Compiled .hex files can also be imported back into the web site. This make it easy for a teacher to review the source of a script by simply drag and dropping the file into the editor. - diff --git a/olddocs/js/contents.md b/olddocs/js/contents.md deleted file mode 100644 index bf5bb2fd..00000000 --- a/olddocs/js/contents.md +++ /dev/null @@ -1,211 +0,0 @@ -# @boardname@/JavaScript Documentation - -JavaScript docs for the @boardname@ - -### @section full - -### @parent reference - -### @short JavaScript - -### ~hint - -**Spotty internet? No problem!** (1) When online, go to https://www.microbit.co.uk/app/ and bookmark this URL; (2) use the bookmark to reload the web app, even without the internet. - -### ~ - -Welcome to the Touch Develop home page for the @boardname@. Below you will find resources about the Touch Develop programming language and code editor. Good places to start include: - -* [the Touch Develop Editor](/js/editor) -* [30+ @boardname@ lessons](/lessonss) -* [offline support](/offline) - -### ~column - -## Language {#pconst} - -### Variables - -* [local variables](/reference/variables/var) -* [global variables ](/js/data) - -### Types - -* [Number](/types/number) -* [Boolean](/types/boolean) -* [String](/types/string) -* [Image](/reference/images/image) - -### Statements and control structures - -* [assignment operator](/reference/variables/assign) `:=` -* [if](/reference/logic/if) -* [for](/reference/loops/for) -* [while](/js/while) -* [break](/js/break) -* [forever](/reference/basic/forever) -* [in background](/reference/control/in-background) -* [function](/js/function) -* [return](/js/return) - -### Maths - -* arithmetic operators (`+`, `-`, `*`, `/`, mod) on [Numbers](/types/number) -* comparison operators (such as `>`, `=`) on [Numbers](/types/number) -* the [math](/js/math) library -* the [bits](/js/bits) library - -### Logical - -* [Boolean](/types/boolean) values `true` and `false` -* Operations (`not`, `or`, `and`) on [Booleans](/types/boolean) - -### Strings - -* [string functions](/types/string-functions) - -### Functions - -* [create a function](/js/function) -* [function parameters](/js/functionparameters) -* [call a function](/js/call) - -### Collections - -* read the [collections tutorial](/js/collections) - -### Custom object types - -* see the [object types tutorial](/js/object-types) -* read the [object disclaimer](/js/object-disclaimer) if you're an advanced user - -### Libraries - -* [create and use libraries](/js/libraries) - -### Documentation - -* [comments](/js/comment) -* [markdown syntax](/js/markdown) - -### ~ - -### ~column - -## @boardname@ functions - -### Basic - -* [clear screen](/reference/basic/clear-screen) -* [forever](/reference/basic/forever) -* [pause](/reference/basic/pause) -* [show leds](/reference/basic/show-leds) -* [show animation](/reference/basic/show-animation) -* [show number](/reference/basic/show-number) -* [show string](/reference/basic/show-string) - -### LED - -* [brightness](/reference/led/brightness) -* [fade in](/reference/led/fade-in) -* [fade out](/reference/led/fade-out) -* [plot](/reference/led/plot) -* [plot all](/reference/led/plot-all) -* [point](/reference/led/point) -* [screenshot](/functions/screenshot) -* [set display mode](/functions/set-display-mode) -* [set brightness](/reference/led/set-brightness) -* [stop animation](/reference/led/stop-animation) -* [toggle](/reference/led/toggle) -* [toggle all](/reference/led/toggle-all) -* [unplot](/reference/led/unplot) - -### Input - -* [acceleration](/reference/input/acceleration) -* [rotation](/functions/rotation) -* [button is pressed](/reference/input/button-is-pressed) -* [compass heading](/reference/input/compass-heading) -* [temperature](/reference/input/temperature) -* [running time](/reference/input/running-time) -* [on shake](/reference/input/on-gesture) -* [on button pressed](/reference/input/on-button-pressed) -* [on pin pressed](/reference/input/on-pin-pressed) -* [pin is pressed](/reference/input/pin-is-pressed) - -### Image - -* [create image](/reference/images/create-image) -* [clear](/reference/basic/clear-screen) -* [pixel](/reference/images/pixel) -* [plot frame](/reference/led/plot-frame) -* [plot image](/reference/led/plot-image) -* [scroll image](/reference/images/scroll-image) -* [show frame](/functions/show-frame) -* [set pixel](/reference/images/set-pixel) -* [show image](/reference/images/show-image) -* [width](/functions/width) - -### Music - -* [play note](/functions/play-note) -* [note](/functions/note) -* [ring](/reference/music/ring) - -### Pins - -* [digital read pin](/reference/pins/digital-read-pin) -* [digital write pin](/reference/pins/digital-write-pin) -* [analog read pin](/reference/pins/analog-read-pin) -* [analog write pin](/reference/pins/analog-write-pin) -* [analog set period](/reference/pins/analog-set-period) -* [analog pitch](/reference/pins/analog-pitch) -* [analog set pitch pin](/reference/pins/analog-set-pitch-pin) -* [servo write pin](/reference/pins/servo-write-pin) -* [servo set pulse](/reference/pins/servo-set-pulse) -* [map](/functions/map) - -### Control - -* [in background](/reference/control/in-background) -* [reset](/functions/reset) - -### Devices - -Functions in this category require to be connected to a remote device. - -* [tell camera to](/reference/devices/tell-camera-to) -* [tell remote control to](/reference/devices/tell-remote-control-to) -* [raise alert to](/reference/devices/raise-alert-to) -* [on notified](/reference/devices/on-notified) - -### Libraries - -* [serial library](/js/serial-library) - -### ~ - -### ~column - -## Run - -* [scripts in the browser](/js/simulator) -* [scripts on your @boardname@](/device/usb) - -## Debugging - -* use the [serial library](/js/serial-library) to print data from your @boardname@ on your computer -* learn about the [device error codes](/device/errors) that are displayed when sad faces occur - -## Edit/Publish - -* [the Touch Develop Editor](/js/editor) -* [publish a script](/js/publishing) - -## Creating Tutorials - -* [create a tutorial](/js/create-tutorials) -* [markdown syntax](/js/markdown) - -### ~ - diff --git a/olddocs/js/event-handler.md b/olddocs/js/event-handler.md deleted file mode 100644 index 842ee066..00000000 --- a/olddocs/js/event-handler.md +++ /dev/null @@ -1,58 +0,0 @@ -# event handler - -Event handlers - how they work. - -An event handler is code that is associated with a particular event, such as "button A pressed". You create (or register) the association between an event and an event handler by calling a function named "on ". After registering an event handler with an event, then whenever that event occurs, the event handler code executes. - -### Registering an event handler - -Functions named "on " create an association between an event and the event handler code. For example, the following code registers the event handler (the code between the `do` and `end` keywords) with the event of a press of button A: - -``` -input.onButtonPressed(Button.A, () => { - basic.showString("hello", 150) -}) -``` - -After this code executes, then whenever button A is pressed in the future, the string "hello" will be printed. - -### Event handlers are active for the entire program execution - -Once you have registered an event handler for an event, like above, that event handler is active for the rest of the program execution. If you want to stop the string "hello" from printing each time button A is pressed then you need to arrange for the following code to execute: - -``` -input.onButtonPressed(Button.A, () => { -}) -``` - -The above code associated an event handler that does nothing with the event of a press of button A. - -### There is only one event handler per event - -The above example also illustrates that there is only one event handler for each event. What is the result of the following code? - -``` -input.onButtonPressed(Button.A, () => { - basic.showString("hello", 150) -}) -input.onButtonPressed(Button.A, () => { - basic.showString("goodbye", 150) -}) -``` - -The answer is that whenever button A is pressed, the string "goodbye" will be printed. If you want both the strings "hello" and "goodbye" to be printed, you need to write the code like this: - -``` -input.onButtonPressed(Button.A, () => { - basic.showString("hello", 150) - basic.showString("goodbye", 150) -}) -``` - -### To learn more - -To learn more about how the @boardname@ queues up and schedules event handlers, see [the @boardname@ - a reactive system](/device/reactive) - -### see also - -[on button pressed](/reference/input/on-button-pressed) diff --git a/olddocs/js/events.md b/olddocs/js/events.md deleted file mode 100644 index f24bb09d..00000000 --- a/olddocs/js/events.md +++ /dev/null @@ -1,79 +0,0 @@ -# Events Library - -The functions in the events namespace allow the @boardname@ to communicate with a separate (remote) device, such as a smartphone, over Bluetooth (Smart). The set of supported events will depend on the remote device and the @boardname@ apps available for the remote device. The events accessible from Touch Develop are listed below. - -### Remote control - -Control the presentation of media content available on a remote device using the `remote control` function - -``` -export function remoteControl(event: string) -``` - -The remote control specific events include: - -* play -* pause -* stop -* next track -* previous track -* forward -* rewind -* volume up -* volume down - -### Camera - -Access the photo/video-taking functionality of a remote device using the *camera* function: - -``` -export function camera(event: string) -``` - -The camera-specific events include: - -* toggle front-rear -* launch photo mode -* take photo -* stop photo mode -* launch video mode -* start video capture -* stop video capture -* stop video mode - -### Alert - -Raise an alert on a remote device using the `alert` function - -``` -export function alert(event: string) -``` - -The set of alerting-specific events include: - -* display toast -* vibrate -* play sound -* play ringtone -* find my phone -* alarm 1 -* alarm 2 -* alarm 3 -* alarm 4 -* alarm 5 -* alarm 6 - -### Audio recorder - -Access the audio recording capabilities of the device using the `audio recording` function - -``` -export function audioRecorder(event: string) -``` - -The set of audio recorder events include: - -* launch -* start capture -* end capture -* stop diff --git a/olddocs/js/for.md b/olddocs/js/for.md deleted file mode 100644 index 174fec81..00000000 --- a/olddocs/js/for.md +++ /dev/null @@ -1,81 +0,0 @@ -# For - -Repeat code a preset number of times. - -### @parent javascript/language - - -Repeat code a fixed number of times. - -### Block Editor - -The Block Editor *for* loop is different than the Touch Develop *for* loop in an important way. The above for loop will iterate *five* times, with the loop variable *i* taking on values 0, 1, 2, 3, and 4. The Touch Develop for loop shown below will iterate four times: - -``` -for (let k = 0; k < 4; k++) { -} -``` - -### Touch Develop - -### ~hide - -``` -let upper = 5 -``` - -### ~ - -``` -for (let k1 = 0; k1 < upper; k1++) { - // Add code to repeat here, also called the `loop body` -} -``` - -where - -* `0` is initial value of the loop index variable `k` -* the value of `k` increases by 1 after each execution of the `loop body` -* `upper` is the number of times the loop body will repeat - -In other words, the index variable (`k`) starts at 0 and increases by 1 each time the `loop body` executes, until `k = upper`. - -### Example: count to 5 - -The following example displays numbers 1 through 5 on the LED screen: - -``` -for (let i = 0; i < 5; i++) { - basic.showNumber(i + 1, 100) - basic.pause(500) -} -``` - -### Example: draw a box - -The [LED screen](/device/screen) has a fixed number of rows and columns (5x5), which is ideal for a for loop. This example uses a for loop to turn on the LEDs along the edge of the screen, making a square. - -``` -for (let i1 = 0; i1 < 5; i1++) { - led.plot(0, i1) - led.plot(4, i1) - led.plot(i1, 0) - led.plot(i1, 4) - basic.pause(500) -} -``` - -### ~hint - -Want to exit a loop early? The [break](/js/break) statement exits a loop before the end value is reached. - -### ~ - -### Lessons - -[looper](/lessons/looper), [strobe light](/lessons/strobe-light) - -### See also - -[while](/js/while), [break](/js/break), [if](/reference/logic/if) - diff --git a/olddocs/js/function.md b/olddocs/js/function.md deleted file mode 100644 index cc6f7204..00000000 --- a/olddocs/js/function.md +++ /dev/null @@ -1,117 +0,0 @@ -# Create a Function - -How to define a function with input and output parameters. - -### @parent javascript/language - - -A function is a unit of code that performs a specific task and returns a result. - -Functions are ideal when you need to perform an action multiple times. Instead of repeating a block of code in your script, you can put the code in a function and simply [call the function](/js/call) when needed. - -*Why use functions?* Functions makes your code easier to read, debug, and update. - -### Add a function - -To add a function to a Touch Develop script: - -1. Open a script and then click `script` (in the upper-right corner). - -2. Click `+` **add new**. - -3. Click **function()**. - -A new function appears, like this: - -``` -export function doStuff(p: number) { -} -``` - -Functions begin with the `function` keyword and end with `end function`. The function name appears after the `function` keyword (in this case, `do stuff`). - -### ~hint - -Click the function name to edit the function properties (i.e. change the name or add parameters - see below). - -### ~ - -### Function components - -Functions have three parts: - -* [input and output parameters](/js/functionparameters) -* the function *body* (the code that performs a task) - -- one or more [return](/js/return) statements (the output of the function) - -#### Example function - -``` -/** - * // returns the square of the input parameter x - * @param x TODO - */ -export function square(x: number) : number { - let result: number - return x * x - return result -} -``` - -In the above code... - -* ``x `` is the [input parameter](/js/functionparameters) ([Number](/types/number) type) -* ``result`` is the [output parameter](/js/functionparameters) ([Number](/types/number) type) -* `return x * x` is the function body (which returns the value of the expression `x * x`) - -### Add function parameters - -1. Open your function (if needed). To do this, open your script and then click `script` (in the upper-right corner). - -2. Under **code** click your function name. - -3. Click the function name in the code window. This opens the function panel. - -4. Click **add input parameter** or **add output parameter**. The parameter is added to your function. - -Click the parameter name to rename it and click the [type](/js/types) to change the variable type. For more info, see [function parameters](/js/functionparameters). - -### ~hide - -### Extract code into a function - -If you've already written some code that you'd like to have in a function, you can extract the code. Here's how: - -1. Click the first line of code that you want to extract. - -2. Press and hold the Shift key, and then press the Down arrow on your keyboard to select multiple lines of code. - -3. In the block editing window, scroll down to **extract selection into function** and click `extract`. - -### ~ - -### Function documentation - -Use a [comment](/js/comment) at the beginning of your functions to describe the function. When you insert a function into your code, the comment text appears in the help area of the Code Keyboard. - -### See all your functions - -To see all the functions in a script, open the script and then click `script` (in the upper-right corner). All of the functions in your script appear under **code**. - -### ~hide - -### Private functions - -If you don't want people to see the code in your function, you can make the function private. To do this, open the function, click the function name, and then mark the **private function** check box. Private functions have a locked icon instead of a play icon. - -### ~ - -### Lessons - -[digital pet](/lessons/digital-pet) - -### See also - -[function parameters](/js/functionparameters), [call a function](/js/call), [return from a function](/js/return) - diff --git a/olddocs/js/functionparameters.md b/olddocs/js/functionparameters.md deleted file mode 100644 index d500a328..00000000 --- a/olddocs/js/functionparameters.md +++ /dev/null @@ -1,66 +0,0 @@ -# Function Parameters - -How to use parameters to pass info in and out of an function. - -### @parent javascript/function - - -A [function](/js/function) can have multiple input parameters and/or a single output parameter. The parameters must be one of the supported variable [types](/js/types). - -When you first [create a function](/js/function), it looks like this: -``` -export function doStuff() { -} -``` - -### Add a function parameter - -1. Open your script (if needed) and then click `script` in the upper-right corner. - -2. Under **code** click your function name. - -3. Click the function name in your code (this opens the function panel). - -4. Click **add input parameter** or **add output parameter**. The parameter is added to your function. - -#### Input parameters - -The default type for an input parameter is [Number](/types/number): - -``` -export function oneInput(p: number) { -} -``` - -To change the default type, click the type ([Number](/types/number) in this case) and change it to [String](/types/string), [Boolean](/types/boolean), or [Image](/reference/image/image). You can add multiple input parameters to a function. - -#### Output parameter - -the default type for an output parameter is [Number](/types/number): - -``` -export function output() : number { - let r: number - return 42 - return r -} -``` - -To change the default type, click the type ([Number](/types/number) in this case) and change it to [String](/types/string), [Boolean](/types/boolean), or [Image](/reference/image/image). - -### Inputs and output function - -The following sample function has two inputs and one output parameter (all are the Number type): - -``` -export function inputsAndOutput(p: number, q: number) : number { - let r: number - return p + q - return r -} -``` - -### See also - -[call a function](/js/call), [create a function](/js/function), [return](/js/return) - diff --git a/olddocs/js/gallery.md b/olddocs/js/gallery.md deleted file mode 100644 index e4595981..00000000 --- a/olddocs/js/gallery.md +++ /dev/null @@ -1,105 +0,0 @@ -# Gallery - -Overview of Touch Develop lessons for the @boardname@. - -### @short Gallery - -### ~column - - -## Maker - -* [Telegraph](/pzeagwoudd), play the telegraph game between 2 @boardname@s -* [Ornament Chain](/rnvpgo), play the ornament chain game between 2 @boardname@s - -### ~hide - -* [The Watch](/lessons/the-watch), design and create The Watch -* [Hack your headphones](/lessons/hack-your-headphones), create music on the @boardname@ by hacking your headphones -* [Banana Keyboard](/lessons/banana-keyboard), create music with fruits - -### ~ - -## Beginner - -* [Night light](/vltwrzuqto), dim the LEDs with set brightness -* [Beautiful image](/nudwzmphyx), show a beautiful image with show LEDs -* [Smiley,](/zsohipimef) smiley and frowney with show animation -* [Lucky 7](/rqhxxqppqu), show a number on the LED screen with show number -* [Answering machine](/bnkmeqymuh), show a text message with show string -* [Snowflake fall](/zhcfmiejlg), repeat an animation with forever -* [Screen wipe](/hlnitnqjjk), turn off the LEDs with clear screen -* [Flashing heart](/bwmxfwqswx), display images with a pause -* [Blink](/jbbutifslm), turn an LED on and off with plot - -### ~hide - -* [Magic logo](/lessons/magic-logo), show an image on logo up -* [Glowing sword](/lessons/glowing-sword), make a glowing sword with fade in and fade out - -### ~ - -### ~column - -## Intermediate - -* [Zoomer](/fwrohhjqql), measure the force with acceleration -* [Strobe light](/jguqlzeayr), develop shapes with a nested for loops -* [Digi yoyo](/lppocrbpys), create a counter with a while loop -* [Die roll](/lzblatmknq), spin with more if statements -* [Spinner](/dzijduruek), spin the arrow with multiple if statements -* [Truth or dare](/filuzbwauo), a game that forces each player to reveal a secret or do something funny with if statement -* [Love meter](/rrmlrvojfa), create a love meter with on pin pressed -* [Guess the number](/ftsenbvqwz), guess a random number with random -* [Magic 8](/fyjinpjuqu), a fortune teller game with the @boardname@ -* [Counter](/rerlmjgjut), display a number with a variable -* [Glowing pendulum](/xrnsveuwxj), construct a pendulum that glows using acceleration -* [Looper](/nxcddtbizi), display a series of numbers with a for loop index - -### ~hide - -* [Rotation animation](/lessons/rotation-animation), control an animation with a boolean variable -* [Offset image](/lessons/offset-image), shift an image horizontally with image offset -* [Compass](/lessons/compass), displays the direction the @boardname@ is pointing - -### ~ - -### ~column - -## Advanced - -* [Rock paper scissors](/tnmtbvyyma), use image offsets with local variables -* [Digital pet](/vefocoajpb), a display of pet images with sub-functions -* [Catch the egg](/reczlreqob), catch falling eggs in a basket with an acceleration controller -* [Headbands](/bzrusu), create a charades game with a collection of strings that hold the words -* [Prank WiFi](/dceikq), create fake WiFi to trick your friends -* [Flipping bird](/lbhvywjzkv), use modulo with a conditional -* [Runaway pac man](/loafab), construct the game pac man with the @boardname@ -* [Line of Fire](/fzcoly), make a game to test hand-eye coordination -* [The hat game](/njynsd), make a game to test your focus on the moving ball -* [Pong](/xcenyy), a light bouncing from left to right -* [Meteorite](/zaidka), a game where meteorites are coming for you one by one -* [Minesweeper](/jaeeve), make a game to test your memory for placing a LED mine then finding the hidden LED mine -* [Bop it](/zlpndm), a game where you have to keep up with the commands -* [Letter Up](/ftlqjo), a guessing game with string operators with string at -* [Racing Buttons](/hcuxid), racing game to determine if player 1 presses Button A faster or if player 2 presses Button B faster - -### ~hide - -* [Transformers](/lessons/transformers), use functions to return values -* [Speed button](/lessons/speed-button), code a speed game with running time -* [Jailbreak](/lessons/jailbreak), break out of a counting loop by pressing button "A" -* [2 player pong](/bzycll), collaborate with a classmate to develop Pong on multiple @boardname@s - -### ~ - -### ~hide - -* [Number psych](/lessons/number-psych), collaborate with multiple classmates to develop a game on multiple @boardname@s and a breadboard - -### ~ - -### @section full - -The lessons promote computational thinking and computer science literacy[ read more...](/lessons/teach) - diff --git a/olddocs/js/game-library.md b/olddocs/js/game-library.md deleted file mode 100644 index 3b3fca02..00000000 --- a/olddocs/js/game-library.md +++ /dev/null @@ -1,153 +0,0 @@ -# Game Library - -The game library supports simple single-player time-based games. The player has a number of **lives** and a **score**. The game has a number of **levels** and a **countdown clock**. The general goal of a game will be to achieve a top score before time runs out or the number of lives goes to zero. - -## Touch Develop - -The code below shows a simple game where the user gets to press the button ``A`` as much times as possible in 10 seconds. - -``` -input.onButtonPressed(Button.A, () => { - game.addScore(1) -}) -game.startCountdown(10000) -``` - -### [Countdown](/js/game-library/start-countdown) - -If your game has a time limit, you can start a countdown in which case `game->current time` returns the remaining time. - -* start a countdown with the maximum duration of the game in milliseconds. - -``` -export function startCountdown(ms: number) -``` - -### [Game over](/js/game-library/game-over) - -If the `life` reaches zero or the time expires (see countdown), the game enters the **game over** mode. When the game is over, `game->is running` returns false - -* check if the game still running. - -``` -export function isRunning() : boolean -``` - -Indicates if the game is display the game over sequence. - -``` -export function isGameOver() : boolean -``` - -You can also end the game by calling the `game -> game over` function: - -``` -export function gameOver() -``` - -### Score - -When a player achieves a goal, you can increase the game score - -[Add Point to Score](/js/game-library/add-point-to-score) - -* add score points to the current score - -``` -export function addScore(points: number) -``` - -[Score](/js/game-library/score) - -* set the current score to a particular value. - -``` -export function setScore(value: number) -``` - -* get the current score value - -``` -export function score() : number -``` - -### Life - -Manage the player lives. When the life count reaches 0 or less, the game is over. - -* remove one or more lives - -``` -export function removeLife(life: number) -``` - -* add lives - -``` -export function addLife(lives: number) -``` - -* set the life to a particular value - -``` -export function setLife(value: number) -``` - -* get the current life value - -``` -export function life() : number -``` - -### Levels - -When the game increases in difficulty, you can increase the level and use that value in your game logic. - -* increase the level by 1 - -``` -export function levelUp() -``` - -* get the current level - -``` -export function level() : number -``` - -### Time - -The game immediately starts tracking the time from the moment the device started. - -* get the current time - -``` -export function currentTime() : number -``` - -You can start the time again by using `game->start stopwatch`. - -* start the game timer - -``` -game.startStopwatch() -``` - -### Blink - -Reports the blink duration of a `sprite` . - -``` -export function blink(_this: micro_bitSprites.LedSprite) : number -``` - -Sets the blink duration interval in milliseconds . - -``` -export function setBlink(sprite: micro_bitSprites.LedSprite, ms: number) -``` - -### Lessons - -[bop it](/lessons/bop-it) | [game of chance](/lessons/game-of-chance) | [game counter](/lessons/game-counter) - diff --git a/olddocs/js/game.md b/olddocs/js/game.md deleted file mode 100644 index 66691bbd..00000000 --- a/olddocs/js/game.md +++ /dev/null @@ -1,11 +0,0 @@ -# game - -A #microbit game library. - -Gets the current score - -``` -init() -return _score -``` - diff --git a/olddocs/js/games.md b/olddocs/js/games.md deleted file mode 100644 index a201a2f3..00000000 --- a/olddocs/js/games.md +++ /dev/null @@ -1,88 +0,0 @@ -# Game Tutorials - -Overview of Games for the @boardname@. - -### @short Games - -### ~column - -## Beginner Games - -* [The Watch](/lessons/the-watch/activity), design and create The Watch -* [Banana Keyboard](/lessons/banana-keyboard), create music with fruits - -### ~hide - -* [Smiley,](/lessons/smiley) smiley and frowney with show animation -* [Lucky 7](/lessons/lucky-7), show a number on the LED screen with show number -* [Snowflake fall](/lessons/snowflake-fall), repeat an animation with forever -* [Answering machine](/lessons/answering-machine), show a text message with show string -* [Magic logo](/lessons/magic-logo), show an image on logo up -* [Screen wipe](/lessons/screen-wipe), turn off the LEDs with clear screen -* [Blink](/lessons/blink), turn an LED on and off with plot -* [Flashing heart](/lessons/flashing-heart/tutorial), display images with a pause - -### ~ - -* [Night light](/lessons/night-light/tutorial), dim the LEDs with set brightness -* [Glowing sword](/lessons/glowing-sword/tutorial), make a glowing sword with fade in and fade out -* [Guess the number](/lessons/guess-the-number/tutorial), guess a random number with random -* [Rock paper scissors](/lessons/rock-paper-scissors/tutorial), use image offsets with local variables -* [Counter](/lessons/counter/tutorial), display a number with a variable -* [Love meter](/lessons/love-meter/tutorial), create a love meter with on pin pressed - -### ~column - -## Intermediate Games - -* [Truth or dare](/lessons/truth-or-dare/tutorial), a game that forces each player to reveal a secret or do something funny with if statement -* [Spinner](/lessons/spinner/tutorial), spin the arrow with multiple if statements -* [Die roll](/lessons/die-roll/tutorial), spin with more if statements -* [Looper](/lessons/looper/tutorial), display a series of numbers with a for loop index -* [Strobe light](/lessons/strobe-light/tutorial), develop shapes with a nested for loops -* [Digi yoyo](/lessons/digi-yoyo/tutorial), create a counter with a while loop -* [Magic 8](/lessons/magic-8/tutorial), a fortune teller game with the @boardname@ -* [Compass](/lessons/compass/tutorial), displays the direction the @boardname@ is pointing -* [Speed button](/lessons/speed-button/tutorial), code a speed game with running time - -### ~hide - -* [Zoomer](/lessons/zoomer/tutorial), measure the force with acceleration -* [Rotation animation](/lessons/rotation-animation/tutorial), control an animation with a boolean variable -* [Offset image](/lessons/offset-image/tutorial), shift an image horizontally with image offset - -### ~ - -### ~column - -## Advanced Games - -### ~hide - -* [Digital pet](/lessons/digital-pet/tutorial), a display of pet images with sub-functions -* [Jailbreak](/lessons/jailbreak/tutorial), break out of a counting loop by pressing button "A" -* [Transformers](/lessons/transformers/tutorial), use functions to return values -* [Flipping bird](/lessons/flipping-bird/tutorial), use modulo with a conditional - -### ~ - -* [Catch the egg](/lessons/catch-the-egg-game/tutorial), catch falling eggs in a basket with an acceleration controller -* [Headbands](/lessons/headbands/tutorial), create a charades game with a collection of strings that hold the words -* [Pong](/lessons/pong/tutorial), a light bouncing from left to right -* [Meteorite](/lessons/meteorite/tutorial), a game where meteorites are coming for you one by one -* [Minesweeper](/lessons/minesweeper/tutorial), make a game to test your memory for placing a LED mine then finding the hidden LED mine -* [Bop it](/lessons/bop-it/tutorial), a game where you have to keep up with the commands -* [Letter Up](/lessons/letter-up/tutorial), a guessing game with string operators with string at -* [Prank WiFi](/lessons/prank-wifi/tutorial), create fake WiFi to trick your friends -* [Runaway pac man](/lessons/runaway-pacman/tutorial), construct the game pac man with the @boardname@ -* [The hat game](/lessons/the-hat-game/tutorial), make a game to test your focus on the moving ball -* [2 player pong](/lessons/2-player-pong/tutorial), collaborate with a classmate to develop Pong on multiple @boardname@s - -### ~hide - -* [Glowing pendulum](/lessons/glowing-pendulum/tutorial), construct a pendulum that glows using acceleration -* [Line of Fire](/lessons/line-of-fire/tutorial), make a game to test hand-eye coordination -* [Number psych](/lessons/number-psych/tutorial), collaborate with multiple classmates to develop a game on multiple @boardname@s and a breadboard - -### ~ - diff --git a/olddocs/js/guides/basic-led-show.md b/olddocs/js/guides/basic-led-show.md deleted file mode 100644 index e6267462..00000000 --- a/olddocs/js/guides/basic-led-show.md +++ /dev/null @@ -1,84 +0,0 @@ -# basic LED show. - -### Challenge 0 - -You have successfully following the [guided tutorial] (https://live.microbit.co.uk/td/tutorials/blink). If not, we should make sure the @boardname@ script displays a blinking script on screen. We want to plot the x and y coordinates to 2, 2. Additionally, you will pause by 100 milliseconds then you will clear the screen of the @boardname@. Let's give it a go! - -``` -while (true) { - led.plot(2, 2) - basic.pause(200) - basic.clearScreen() - basic.pause(200) - -} -``` - -### Challenge 1 - -Use `basic->show string`  to display text after the blink. You will be writing a series of letters to display a series of letters. Try to unravel this secret code word: HELP. This line of code is within the  while  scope - -Make sure to add this line of code within the `while` scope! - -``` -while (true) { - led1.plot(2, 2) - basic1.pause(200) - basic1.clearScreen() - basic1.pause(200) - basic1.showString("HELP", 150) // *** -} -``` - -* run the code and see that it works as expected - -### Challenge 2 - -You can also display a number on screen using `basic‐>show number`. Add code under `basic‐>show string` to display the emergency number to call in the United Kingdom. (NOTE: 999 is the historic emergency number for the United Kingdom. All calls are answered by 999 operators. Calls are always free.) - -``` -while (true) { - led2.plot(2, 2) - basic2.pause(200) - basic2.clearScreen() - basic2.pause(200) - basic2.showString("HELP", 150) - basic2.showNumber(999, 150) // *** -} -``` - -Awesome! You have designed your message and a number to call in case of an emergency. - -### Challenge 3 - -* tap the `run` button to view the updated script on the simulator - -Add an associated animation after the emergency number . You can also create a cool animation on screen using `basic->show animation`. Add code under `basic->show number` to display an animation. - -``` -while (true) { - led3.plot(2, 2) - basic3.pause(200) - basic3.clearScreen() - basic3.pause(200) - basic3.showString("HELP", 150) - basic3.showNumber(999, 150) - basic3.showAnimation(` -# # . # # -. # . # . -. . # . . -# . . . # -# # # # # -`, 400) // *** -} -``` - -Awesome! We have implemented a string, number, and animation - -* run the code and see that it works as expected. - -### Challenge 4 - -Use the same logic `basic->string`, `basic->number`, or `basic->animation` to turn on the LEDs and display information!!! - -* run the code and see that it works as expected diff --git a/olddocs/js/guides/blink-symbols.md b/olddocs/js/guides/blink-symbols.md deleted file mode 100644 index 8d3b3bd1..00000000 --- a/olddocs/js/guides/blink-symbols.md +++ /dev/null @@ -1,109 +0,0 @@ -# blink symbols. - -### Challenge 0 - -You have successfully following the [blink tutorial](/hcwxud). If not, then let's start the tutorial now. Your @boardname@ script should start by displaying a blinking script on screen. We want to plot the x and y coordinates to 2, 2. Additionally, you will pause by 100 milliseconds then clear the screen of the @boardname@. - -Let's give it a go! - -``` -while (true) { - led.plot(2, 2) - basic.pause(200) - basic.clearScreen() - basic.pause(200) - -} -``` - -### Challenge 1 - -Make a `>` greater than symbol. Start in the upper left corner of the simulator when you plot coordinates. Make sure to add the line of code `led->plot (0,0)` under the last line of code - -``` -while (true) { - led1.plot(2, 2) - basic1.pause(200) - basic1.clearScreen() - basic1.pause(200) - led1.plot(0, 0) // *** -} -``` - -Design the top half of the `>` symbol by connecting a LED to the original center coordinate `2,2` and the upper left coordinate `0,0` Make sure to add the line of code `led->plot (1,1)` under the last line of code - -``` -while (true) { - led2.plot(2, 2) - basic2.pause(200) - basic2.clearScreen() - basic2.pause(200) - led2.plot(0, 0) - led2.plot(1, 1) // *** -} -``` - -Awesome! You have designed half of the `>` symbol. Now we should finish the lower half of the `>` symbol - -* tap the `run` button to view the updated script on the simulator - -Add the bottom half of the `>` symbol by plotting the most bottom - left LED first. Make sure to add the line of code `led->plot (0,5)` - -``` -while (true) { - led3.plot(2, 2) - basic3.pause(200) - basic3.clearScreen() - basic3.pause(200) - led3.plot(0, 0) - led3.plot(1, 1) - led3.plot(0, 4) // *** -} -``` - -Awesome! Now we must connect a LED to the original center coordinate `2,2` and the lower left coordinate `0,5` Make sure to add the line of code `led->plot (1,4)` - -Your `main` function should look like this: - -``` -while (true) { - led4.plot(2, 2) - basic4.pause(200) - basic4.clearScreen() - basic4.pause(200) - led4.plot(0, 0) - led4.plot(1, 1) - led4.plot(0, 4) - led4.plot(1, 3) // *** -} -``` - -* `run` the script and see that the program works as expected - -Congratulations! You made a `>` symbol. - -### Challenge 2 - -Use `led->plot` to create a exclamation design `!` Your `main` function should look like this. (notice the notation of `...` represents previous code in **Challenge 0** and **Challenge 1** - -Make sure to add these lines of code within the `while` loop - -Your `main` function should look like this: - -``` -while (true) { - // ... - led5.plot(4, 0) // *** - led5.plot(4, 1) // *** - led5.plot(4, 2) // *** - led5.plot(4, 4) // *** -} -``` - -* run the code and see that it works as expected. - -### Challenge 3 - -Use the same logic `led->plot` to turn on all the LED lights!!! - -* run the code and see that it works as expected diff --git a/olddocs/js/guides/light-column-cascade-activity.md b/olddocs/js/guides/light-column-cascade-activity.md deleted file mode 100644 index d2437b04..00000000 --- a/olddocs/js/guides/light-column-cascade-activity.md +++ /dev/null @@ -1,43 +0,0 @@ -# Light Column Cascade Worksheet - -My script. #docs - -**Challenge 0** - -Great Job! You have completed the Light Column Cascade tutorial having a nested for loop that plots each individual LED by column adding a delay between lighting each LED. - -``` -for (let i = 0; i < 5; i++) { - for (let j = 0; j < 5; j++) { - led.plot(i, j) - basic.pause(200) - } -} -``` - -**Challenge 1** - -Make the board light up faster by making the pause less time. - -``` -for (let i1 = 0; i1 < 5; i1++) { - for (let j1 = 0; j1 < 5; j1++) { - led1.plot(i1, j1) - basic1.pause(100) // *** - } -} -``` - -**Challenge 2** - -Make the board light up by rows instead of by columns by changing the i to the y position and j to the x position. - -``` -for (let i2 = 0; i2 < 5; i2++) { - for (let j2 = 0; j2 < 5; j2++) { - led2.plot(j2, i2) // *** - basic2.pause(100) - } -} -``` - diff --git a/olddocs/js/guides/light-column-cascade.md b/olddocs/js/guides/light-column-cascade.md deleted file mode 100644 index b4100ffc..00000000 --- a/olddocs/js/guides/light-column-cascade.md +++ /dev/null @@ -1,43 +0,0 @@ -# Light Column Cascade Activity - -My script. #docs - -**Challenge 0** - -Great Job! You have completed the Light Column Cascade tutorial having a nested for loop that plots each individual LED by column adding a delay between lighting each LED. - -``` -for (let i = 0; i < 5; i++) { - for (let j = 0; j < 5; j++) { - led.plot(i, j) - basic.pause(200) - } -} -``` - -**Challenge 1** - -Make the board light up faster by making the pause less time. - -``` -for (let i1 = 0; i1 < 5; i1++) { - for (let j1 = 0; j1 < 5; j1++) { - led1.plot(i1, j1) - basic1.pause(100) // *** - } -} -``` - -**Challenge 2** - -Make the board light up by rows instead of by columns by changing the i to the y position and j to the x position. - -``` -for (let i2 = 0; i2 < 5; i2++) { - for (let j2 = 0; j2 < 5; j2++) { - led2.plot(j2, i2) // *** - basic2.pause(100) - } -} -``` - diff --git a/olddocs/js/guides/scroll-image-docs.md b/olddocs/js/guides/scroll-image-docs.md deleted file mode 100644 index a5fd3616..00000000 --- a/olddocs/js/guides/scroll-image-docs.md +++ /dev/null @@ -1,22 +0,0 @@ -# Scroll Image Docs - -My script. #docs - -**Challenge 0** - -This [guided tutorial](/xuhkviyyxa) introduces how to make an image look like it's scrolling across the @boardname@! - -We can use an animation to make an image look like its moving! - -``` -basic.forever() -``` - -**Challenge 1** - -Now, let's reverse the animation so it looks like the bar is bouncing off the right edge of the display. - -``` -basic1.forever() -``` - diff --git a/olddocs/js/guides/touchdevelop-lessons.md b/olddocs/js/guides/touchdevelop-lessons.md deleted file mode 100644 index 2f3a0dbc..00000000 --- a/olddocs/js/guides/touchdevelop-lessons.md +++ /dev/null @@ -1,135 +0,0 @@ -# TouchDevelop Lessons - -Overview of TouchDevelop lessons for the @boardname@. - -### @section full - -### ~column - -### LED screen - -* [plot guided](/hcwxud) `guided tutorial ` `video available` -* [plots an LED](/njuzbvocit) [guided tutorial] -* [blink symbols](/rfchtfjmag) `docs` -* [clear screen](/jwqywu) -* [point](/reference/led/point) -* [set brightness](/tfrmcgdtxk) - -## @boardname@ - -## functions - -### Basic - -* [show number](/doxhko) -* [show string](/hgsfxg) -* [forever - show image](/bniyze) `guided tutorial` -* [forever - show animation - two frames 1a](/rwsjmubtaa) -* [forever - show animation - two frames 1c](/fomtaxxdkk) -* [forever - show animation - two frames 1 d](/huguhgjmmn) -* [forever - show animation - multliple frames](/tweyhx) - -## Language {#pconst} - -### Variables - -* [global variables ](/nkecii) `guided tutorial` -* [local variable - create image, show image](/dcvnwv) -* data types: [number](/types/number), [boolean](/types/boolean), [string](/types/string), [image](/reference/image/image) - -### Statements and control structures - -* [if](/reference/logic/if) -* [for](/reference/loops/for) -* [for loop nested - plot](/vpvhdnaqfm) **script** -* [while](/js/while) -* [while - show string, show number, show animation](/bidtzqdips) `docs` -* [while - create image ](/bnqbom) -* [return](/js/return) -* [break](/js/break) -* [function](/js/function) -* [assignment operation](/reference/variables/assign) `:=` - -### Maths - -* arithmetic operators (`+`, `-`, `*`, `/`, mod) on [numbers](/types/number) -* comparison operators (such as `>`, `=`) on [numbers](/types/number) -* the [math](/js/math) library -* the [bits](/js/bits) library - -### Logical - -* boolean operators (`not`, `or`, `and`) on [booleans](/types/boolean) - -### Strings - -* concat operator combines [strings](/types/string) - -### ~ - -### ~column - -### Input - -* [button is pressed](/reference/input/button-is-pressed) -* [on button pressed](/reference/input/on-button-pressed) -* [acceleration](/reference/input/acceleration) -* [compass heading](/reference/input/compass-heading) -* [calibrate](/functions/calibrate) -* [running time](/reference/input/running-time) - -### ~ - -### ~column - -### Authoring & Other Bits - -* [TouchDevelop editor](/js/editor) -* [markdown](/js/markdown) -* [creating interactive tutorials](/js/creatinginteractivetutorials) -* [run scripts in a web browser](/js/simulator) -* [run scripts on your @boardname@](/usb) -* [libraries](/js/libraries) - -### Functions and libraries - -* [creating functions](/js/function) -* [function parameters](/js/functionparameters) -* [calling functions](/js/call) -* [libraries](/js/libraries) - -### Images - -* [create image](/reference/images/create-image) -* [clear](/reference/basic/clear-screen) -* [set pixel](/reference/images/set-pixel) -* [pixel](/reference/images/pixel) -* [show image](/reference/images/show-image) -* [scroll image](/reference/images/scroll-image) -* [width](/functions/width) -* [show animation](/reference/basic/show-animation) - -### Pins - -* [analog read pin](/reference/pins/analog-read-pin) -* [analog write pin](/reference/pins/analog-write-pin) -* [digital read pin](/reference/pins/digital-read-pin) -* [digital write pin](/reference/pins/digital-write-pin) - -### Accessories - -* [forever](/reference/basic/forever) -* [in background](/reference/control/in-background) - -## Tutorials - -* [Blink](/script:hcwxud) -* [Button](/script:rxqgzy) -* [Compass](/script:fhhhwl) -* [Counter](/script:bqrria) -* [Digital pet](/script:lsqwsk) -* [Flashing heart](/script:bniyze) -* [Glowing image](/script:hydyrp) - -### ~ - diff --git a/olddocs/js/hourofcode.md b/olddocs/js/hourofcode.md deleted file mode 100644 index afd7d89d..00000000 --- a/olddocs/js/hourofcode.md +++ /dev/null @@ -1,60 +0,0 @@ -# Hour of Code - -learn how to run an Hour Of Code with the @boardname@. #docs - -The @boardname@ can be used to run an Hour Of Code™ events for beginner of all ages. This document provides a detailed guidance on how to prepare and deliver the event in your school. - -## preparing the room - -1) Computers - -* Ensure that each participant will have **a computer connected to a @boardname@ board via a micro-USB cable**. - -2) Internet - -* Ensure that each computer has access to **internet**. - -3) Website Access - -* [https://www.microbit.co.uk](https://www.microbit.co.uk) - -4) Raffle tickets and prizes (optional) - -* Reward students with raffle tickets to keep them engaged. Finishing an activity or challenge on paper should equal a raffle ticket. Perform a raffle throughout the hour and give away lots of cheap prizes (candy is always a nice choice). - -5) Music (optional) - -* We recommend playing the latest hits (loudly) while the students are coding. It creates a playful atmosphere and makes the entire experience more enjoyable. Many web sites offer streaming music, but be sure to try it in advance as certain sites may be blocked on your network. - -## preparing the student handouts - -Print the following **activities** (1 handout per student): - -* [answering machine](/lessons/answering-machine/activity) -* [happy birthday](/lessons/happy-birthday/activity) -* [love meter](/lessons/love-meter/activity) - -Print the following **challenges** (1 handout per student): - -* [answering machine](/lessons/answering-machine/challenges) -* [happy birthday](/lessons/happy-birthday/challenges) -* [love meter](/lessons/love-meter/challenges) - -## Timeline - -* ``00:00`` students enter the website address (see step 3) -* ``10:00`` [answering machine](/lessons/answering-machine/activity) -* ``25:00`` [happy birthday](/lessons/happy-birthday/activity) -* ``35:00`` [love meter](/lessons/love-meter/activity) -* ``55:00`` raffle -* ``60:00`` that's it! - -## Follow up - -After your Hour Of Code™, you will want to provide plenty of material for students to continue learning about coding. Here are some good places to start: - -* [more challenges](/js/games) are available with @boardname@ Tutorials -* [the Quick Start Guide for Teachers](http://www.slideshare.net/Microsofteduk/bbc-microbit-guide-from-hodder-education) are available within @boardname@ - -The 'Hour of Code™' is a nationwide initiative by [Computer Science Education Week](http://csedweek.org) and [Code.org](http://code.org) to introduce millions of students to one hour of computer science and computer programming. - diff --git a/olddocs/js/hourofcode/notes.md b/olddocs/js/hourofcode/notes.md deleted file mode 100644 index 2a0ff6c2..00000000 --- a/olddocs/js/hourofcode/notes.md +++ /dev/null @@ -1,48 +0,0 @@ -# Hour of Code notes - -learn how to run an Hour Of Code with the @boardname@. #docs - -The @boardname@ can be used to run an Hour Of Code™ event for beginner of all ages. This document provides a detailed guidance on how to prepare and deliver the event in your school. - -## Preparation - -1) Computers - -Each participant has **a computer connected to a @boardname@ via micro-USB**. - -2) Internet - -Ensure that each computer has access to **internet**. - -3) Accounts - -Create a classroom in https://www.microbit.co.uk and pre-populate the classroom with student accounts. **Print the student passwords** and cut out each password. - -4) Print the activity challenges (1 copy per participant): - -* [hour of code](/js/hourofcode/challenges) - -4) (optional) Raffle tickets and prizes - -Reward students with raffle tickets to keep them engaged. Finishing a tutorial or challenge on paper should equal a raffle ticket. Perform a raffle throughout the hour and give away lots of cheap prizes (candy is always a nice choice). - -5) (optional) Music - -Bring more energy in the room by playing music. - -## Timeline - -* ``00:00`` student sign in using **printed passwords** (see step 3) -* ``10:00`` [hour of code tutorial](/js/hourofcode) -* ``40:00`` raffle and demoes -* ``50:00`` that's it! - -## Follow up - -After your Hour Of Code™, you will want to provide plenty of material for students to continue learning about coding. Here are some good places to start: - -* [more challenges](/lessonss) are available for @boardname@ -* [the Quick Start Guide for Teachers](http://www.slideshare.net/Microsofteduk/bbc-microbit-guide-from-hodder-education) are available within @boardname@ - -_The Hour of Code™ is a nationwide initiative by [Computer Science Education Week](http://csedweek.org) and [Code.org](http://code.org) to introduce millions of students to one hour of computer science and computer programming._ - diff --git a/olddocs/js/if.md b/olddocs/js/if.md deleted file mode 100644 index 4a3ffd0b..00000000 --- a/olddocs/js/if.md +++ /dev/null @@ -1,99 +0,0 @@ -# If - -Run code based on a condition. - -### @parent javascript/language - - -Conditionally run code depending on whether a [Boolean](/types/boolean) condition is true or false. - -### Block Editor - -In the Block Editor, click on the dark blue gear icon (see above) to add an *else* or *if* to the current block. - -### Touch Develop - -### ~hide - -``` -let condition = true -``` - -### ~ - -``` -if (condition) { - // this code runs if `condition` is `true` -} else { - // this code runs if `condition` is `false` -} -``` - -### Example: adjusting screen brightness - -If the screen [brightness](/reference/led/brightness) is `< 100`, this code sets the brightness to `255`: - -``` -if (led.brightness() < 100) { - led.setBrightness(255) -} -``` - -You can leave the `then` or `else` blocks empty if they aren't needed. - -### Else if: multiple if statements - -You can chain together if statements by using `else if`. Like this: - -### ~hide - -``` -let otherCondition = true -``` - -### ~ - -``` -if (condition) { - // this code runs if `condition` is `true` -} else if (otherCondition) { - // this code runs if `other condition` is `true` -} -else { - // this code runs if neither `condition` or `other condition` are `true` -} -``` - -### Example: compass heading - -The following example gets the [compass heading](/reference/input/compass-heading) and then uses ``if-then-else`` statements to display a letter on the screen (N for north, E for East, S for South, and W for West). - -``` -while (true) { - let degrees = input.compassHeading() - if (degrees < 45) { - basic.showString("N", 100) - } else if (degrees < 135) { - basic.showString("E", 100) - } - else if (degrees < 225) { - basic.showString("S", 100) - } - else { - basic.showString("W", 100) - } -} -``` - -### Drag and drop - -You can move an entire ``if`` block by clicking the ``if`` keyword and dragging and dropping. - -### Lessons - -[love meter](/lessons/love-meter), [zoomer](/lessons/zoomer), [offset image](/lessons/offset-image) - -### See also - -[while loop](/js/while), [for](/reference/loops/for), [boolean](/types/boolean) - diff --git a/olddocs/js/image.md b/olddocs/js/image.md deleted file mode 100644 index d823d184..00000000 --- a/olddocs/js/image.md +++ /dev/null @@ -1,70 +0,0 @@ -# Image - -An image for the @boardname@ screen. - -### @parent javascript/language - -An *Image* is a matrix of pixels to show on the [LED screen](/device/screen) - -### Touch Develop editor: plot an image - -To display an image using the [Touch Develop editor](/js/editor): - -* click `image` , `plot image`, and then `edit` -* click the rectangles to create an image -* when you're done, click **ok** to return to your code - -![](/static/mb/plot-leds-0.png) - -You should see code similar to this: - -``` -basic.plotImage(` -. . . . . -. # . # . -. . # . . -. # . # . -. . . . . -`) -``` - -### Creating an image - -To create an image that you can later modify, see the [create image](/reference/images/create-image) function. - -### Block editor: create and show images - -To create images using the [Block editor](/blocks/editor): - -1. Click the **Images** category on the left. - -2. Drag and drop the **show image** block into your code. - -3. Drag and drop the **create image** or **create big image** block onto the **show image** block so that they connect. - -4. Make an image on the **create image** block by clicking on the squares. - -### Global image variables - -Images that you create in the [Touch Develop editor](/js/editor) are [local variables](/reference/variables/var). To promote a local image variable to a global variable, select the local image variable and click `promote to data`. The *var* keyword changes to the [data](/js/data) symbol `data->`. - -### Image functions - -* [create image](/reference/images/create-image): create an image from a series of on/off LED states -* [clear](/reference/basic/clear-screen): turn off all the pixels in an image -* [set pixel](/reference/images/set-pixel): set the state of a pixel in an image -* [pixel](/reference/images/pixel): get the state of a pixel in an image -* [plot-image](/reference/led/plot-image): show a single-frame image on the LED screen -* [show animation](/reference/basic/show-animation): show a series of image frames -* [show image](/reference/images/show-image): show an image on the screen -* [scroll image](/reference/images/scroll-image): scroll an image on the screen -* [width](/functions/width): get the width of an image - -### Lessons - -* [offset image](/lessons/offset-image) - -### See also - -[plot image](/reference/led/plot-image), [create image](/reference/images/create-image), [show image](/reference/images/show-image), [LED screen](/device/screen) - diff --git a/olddocs/js/lessons.md b/olddocs/js/lessons.md deleted file mode 100644 index 287da301..00000000 --- a/olddocs/js/lessons.md +++ /dev/null @@ -1,91 +0,0 @@ -# Touch Develop Lessons - -Overview of Touch Develop lessons for the @boardname@. - -### @short Lessons - -### ~column - -## Maker - -* [The Watch](/lessons/the-watch), design and create The Watch -* [Hack your Headphones](/lessons/hack-your-headphones), create music on the @boardname@ by hacking your headphones -* [Banana Keyboard](/lessons/banana-keyboard), create music with fruits -* [Telegraph](/lessons/telegraph), play the telegraph game between 2 @boardname@s -* [Ornament Chain](/lessons/ornament-chain), play the ornament chain game between 2 @boardname@s - -## Beginner - -* [Beautiful Image](/lessons/beautiful-image), show a beautiful image with show LEDs -* [Smiley,](/lessons/smiley) smiley and frowney with show animation -* [Lucky 7](/lessons/lucky-7), show a number on the LED screen with show number -* [Answering Machine](/lessons/answering-machine), show a text message with show string -* [Snowflake Fall](/lessons/snowflake-fall), repeat an animation with forever - -* [Magic Logo](/lessons/magic-logo), show an image on logo up -* [Screen Wipe](/lessons/screen-wipe), turn off the LEDs with clear screen -* [Flashing Heart](/lessons/flashing-heart), display images with a pause -* [Blink](/lessons/blink), turn an LED on and off with plot -* [Night Light](/lessons/night-light), dim the LEDs with set brightness -* [Glowing Sword](/lessons/glowing-sword), make a glowing sword with fade in and fade out - -### ~column - -## Intermediate - -* [Magic 8](/lessons/magic-8), a fortune teller game with the @boardname@ -* [Guess the Number](/lessons/guess-the-number), guess a random number with random -* [Rock Paper Scissors](/lessons/rock-paper-scissors), use image offsets with local variables -* [Counter](/lessons/counter), display a number with a variable -* [Love meter](/lessons/love-meter), create a love meter with on pin pressed -* [Zoomer](/lessons/zoomer), measure the force with acceleration -* [Glowing Pendulum](/lessons/glowing-pendulum), construct a pendulum that glows using acceleration -* [Truth or Dare](/lessons/truth-or-dare), a game that forces each player to reveal a secret or do something funny with if statement -* [Spinner](/lessons/spinner), spin the arrow with multiple if statements -* [Die Roll](/lessons/die-roll), spin with more if statements -* [Looper](/lessons/looper), display a series of numbers with a for loop index -* [Strobe Light](/lessons/strobe-light), develop shapes with a nested for loops -* [Digi Yoyo](/lessons/digi-yoyo), create a counter with a while loop -* [Rotation Animation](/lessons/rotation-animation), control an animation with a boolean variable -* [Offset Image](/lessons/offset-image), shift an image horizontally with image offset -* [Compass](/lessons/compass), displays the direction the @boardname@ is pointing - -### ~ - -### ~column - -## Advanced - -* [Digital Pet](/lessons/digital-pet), a display of pet images with sub-functions -* [Transformers](/lessons/transformers), use functions to return values -* [Speed Button](/lessons/speed-button), code a speed game with running time -* [Catch the Egg](/lessons/catch-the-egg-game), catch falling eggs in a basket with an acceleration controller -* [Headbands](/lessons/headbands), create a charades game with a collection of strings that hold the words -* [Prank WiFi](/lessons/prank-wifi), create fake WiFi to trick your friends -* [Jailbreak](/lessons/jailbreak), break out of a counting loop by pressing button "A" -* [Flipping Bird](/lessons/flipping-bird), use modulo with a conditional -* [Runaway Pac Man](/lessons/runaway-pacman), construct the game pac man with the @boardname@ -* [Line of Fire](/lessons/line-of-fire), make a game to test hand-eye coordination -* [The Hat Game](/lessons/the-hat-game), make a game to test your focus on the moving ball -* [2 Player Pong](/lessons/2-player-pong), collaborate with a classmate to develop Pong on multiple @boardname@s - -### Games - -* [Pong](/lessons/pong), a light bouncing from left to right -* [Meteorite](/lessons/meteorite), a game where meteorites are coming for you one by one -* [Minesweeper](/lessons/minesweeper), make a game to test your memory for placing a LED mine then finding the hidden LED mine -* [Bop it](/lessons/bop-it), a game where you have to keep up with the commands -* [Letter up](/lessons/letter-up), a guessing game with string operators with string at - -### ~ - -### ~hide - -* [Number Psych](/lessons/number-psych), collaborate with multiple classmates to develop a game on multiple @boardname@s and a breadboard - -### ~ - -### @section full - -The lessons promote computational thinking and computer science literacy[ read more...](/lessons/teach) - diff --git a/olddocs/js/lessons/2-player-pong.md b/olddocs/js/lessons/2-player-pong.md deleted file mode 100644 index 64422230..00000000 --- a/olddocs/js/lessons/2-player-pong.md +++ /dev/null @@ -1,103 +0,0 @@ -# 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. - diff --git a/olddocs/js/lessons/2-player-pong/quiz-answers.md b/olddocs/js/lessons/2-player-pong/quiz-answers.md deleted file mode 100644 index f2a09273..00000000 --- a/olddocs/js/lessons/2-player-pong/quiz-answers.md +++ /dev/null @@ -1,91 +0,0 @@ -# 2 player pong quiz answers - -a two-player game of Pong using TWO @boardname@s!. - -## 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. - -
- -``` -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. - -
- -``` -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. - -
- -``` -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. - -
- -``` -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"). - -
- -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".) - -
- -``` -ballX = micro_bitTransfer.readByte() -ballXVelocity = readVelocity() -``` - -## 7. Write the code that updates 'ball x velocity'. (Hint: look at the "update velocity" function.) - -
- -``` -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. - -
- -``` -led.unplot(ballX, 0) -ballX = ballX + ballXVelocity -ballY = ballY + ballYVelocity -led.plot(ballX, ballY) -``` - diff --git a/olddocs/js/lessons/2-player-pong/quiz.md b/olddocs/js/lessons/2-player-pong/quiz.md deleted file mode 100644 index e55976a4..00000000 --- a/olddocs/js/lessons/2-player-pong/quiz.md +++ /dev/null @@ -1,70 +0,0 @@ -# 2 player pong quiz - -a two-player game of Pong using TWO @boardname@s!. - -## 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. - -
- -
- -## 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. - -
- -## 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. - -
- -
- -
- -
- -## 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. - -
- -
- -
- -
- -## 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"). - -
- -
- -## 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".) - -
- -
- -
- -## 7. Write the code that updates 'ball x velocity'. (Hint: look at the "update velocity" function.) - -
- -
- -## 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. - -
- -
- -
- diff --git a/olddocs/js/lessons/accelerometer/challenges.md b/olddocs/js/lessons/accelerometer/challenges.md deleted file mode 100644 index bb231f60..00000000 --- a/olddocs/js/lessons/accelerometer/challenges.md +++ /dev/null @@ -1,59 +0,0 @@ -# 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 @boardname@ 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 @boardname@ 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. - diff --git a/olddocs/js/lessons/blinks-rectangle/challenges.md b/olddocs/js/lessons/blinks-rectangle/challenges.md deleted file mode 100644 index d676e6dc..00000000 --- a/olddocs/js/lessons/blinks-rectangle/challenges.md +++ /dev/null @@ -1,79 +0,0 @@ -# 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. - diff --git a/olddocs/js/lessons/boolean-fun/challenges.md b/olddocs/js/lessons/boolean-fun/challenges.md deleted file mode 100644 index 6767689c..00000000 --- a/olddocs/js/lessons/boolean-fun/challenges.md +++ /dev/null @@ -1,91 +0,0 @@ -# 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. - diff --git a/olddocs/js/lessons/boxer-mania/challenges.md b/olddocs/js/lessons/boxer-mania/challenges.md deleted file mode 100644 index c17bf7f1..00000000 --- a/olddocs/js/lessons/boxer-mania/challenges.md +++ /dev/null @@ -1,85 +0,0 @@ -# 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 @boardname@ 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) // *** -``` - diff --git a/olddocs/js/lessons/break/challenges.md b/olddocs/js/lessons/break/challenges.md deleted file mode 100644 index 4c4caf65..00000000 --- a/olddocs/js/lessons/break/challenges.md +++ /dev/null @@ -1,86 +0,0 @@ -# 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. - diff --git a/olddocs/js/lessons/button/challenges.md b/olddocs/js/lessons/button/challenges.md deleted file mode 100644 index 441ff77a..00000000 --- a/olddocs/js/lessons/button/challenges.md +++ /dev/null @@ -1,52 +0,0 @@ -# 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`. - diff --git a/olddocs/js/lessons/cascade/quiz.md b/olddocs/js/lessons/cascade/quiz.md deleted file mode 100644 index 734cca53..00000000 --- a/olddocs/js/lessons/cascade/quiz.md +++ /dev/null @@ -1,128 +0,0 @@ -# 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. - -![](/static/mb/empty-microbit.png) - -## 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. - -![](/static/mb/empty-microbit.png) - -## 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. - -![](/static/mb/empty-microbit.png) - -****************************** - -## 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. - -![](/static/mb/lessons/cascade-0.png) - -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. - -![](/static/mb/lessons/cascade-1.png) - -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. - -![](/static/mb/lessons/cascade-2.png) - -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) - diff --git a/olddocs/js/lessons/clear-screen/challenges.md b/olddocs/js/lessons/clear-screen/challenges.md deleted file mode 100644 index 6cc12e92..00000000 --- a/olddocs/js/lessons/clear-screen/challenges.md +++ /dev/null @@ -1,77 +0,0 @@ -# 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! diff --git a/olddocs/js/lessons/column/quiz.md b/olddocs/js/lessons/column/quiz.md deleted file mode 100644 index b9ccf639..00000000 --- a/olddocs/js/lessons/column/quiz.md +++ /dev/null @@ -1,128 +0,0 @@ -# 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. - -![](/static/mb/empty-microbit.png) - -## 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. - -![](/static/mb/empty-microbit.png) - -## 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. - -![](/static/mb/empty-microbit.png) - -****************************** - -## 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. - -![](/static/mb/lessons/cascade-0.png) - -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. - -![](/static/mb/lessons/column-0.png) - -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. - -![](/static/mb/lessons/column-1.png) - -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) - diff --git a/olddocs/js/lessons/compare-machine/challenges.md b/olddocs/js/lessons/compare-machine/challenges.md deleted file mode 100644 index 70155fb0..00000000 --- a/olddocs/js/lessons/compare-machine/challenges.md +++ /dev/null @@ -1,79 +0,0 @@ -# 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 @boardname@ 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 @boardname@ 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 @boardname@. You will need to add an `else if` after the if statement of `counter = 5`. - diff --git a/olddocs/js/lessons/digital-pet.md b/olddocs/js/lessons/digital-pet.md deleted file mode 100644 index 6a618386..00000000 --- a/olddocs/js/lessons/digital-pet.md +++ /dev/null @@ -1,131 +0,0 @@ -# digital pet lesson - -a display of pet images for the @boardname@. - -## 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 @boardname@'s LED screen -* learn how to show a string on the @boardname@'s LED screen -* learn how to create an image to show on the @boardname@'s LED screen -* learn how to show an image on the @boardname@'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. - diff --git a/olddocs/js/lessons/digital-pet/challenges.md b/olddocs/js/lessons/digital-pet/challenges.md deleted file mode 100644 index 8b87cacc..00000000 --- a/olddocs/js/lessons/digital-pet/challenges.md +++ /dev/null @@ -1,123 +0,0 @@ -# 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 - -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 - -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 - -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` - diff --git a/olddocs/js/lessons/digital-pet/quiz-answers.md b/olddocs/js/lessons/digital-pet/quiz-answers.md deleted file mode 100644 index 254ef8c5..00000000 --- a/olddocs/js/lessons/digital-pet/quiz-answers.md +++ /dev/null @@ -1,60 +0,0 @@ -# digital pet quiz answers - -A display of pet images for the @boardname@ - -## 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'? - -
- -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() - -
- -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 - -
- -``` -let img = images.createImage(` -. # . # . -. . # . . -. . . . . -. # # # . -. . . . . -`) -img.showImage(0) -``` - -## 4. Write the steps to create the function called set sleep, function set sleep() - -
- -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 - -
- -``` -img = images.createImage(` -# # . # # -. . # . . -. . . . . -. # # # . -. . . . . -`) -img.showImage(0) -``` - diff --git a/olddocs/js/lessons/digital-pet/quiz.md b/olddocs/js/lessons/digital-pet/quiz.md deleted file mode 100644 index 63936dab..00000000 --- a/olddocs/js/lessons/digital-pet/quiz.md +++ /dev/null @@ -1,32 +0,0 @@ -# digital pet quiz - -A display of pet images for the @boardname@ - -## 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'? - -
- -## 2. Write the steps to create the function called set awake() - -
- -## 3. Write the code inside the function "set awake()" that shows an image of the pet awake - -
- -## 4. Write the steps to create the function called set sleep, function set sleep() - -
- -## 5. Write the code inside the function "set sleep()" that shows an image of the pet asleep - -
- diff --git a/olddocs/js/lessons/flipping-bird/challenges.md b/olddocs/js/lessons/flipping-bird/challenges.md deleted file mode 100644 index 0108fec6..00000000 --- a/olddocs/js/lessons/flipping-bird/challenges.md +++ /dev/null @@ -1,85 +0,0 @@ -# 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 - -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! - diff --git a/olddocs/js/lessons/flipping-bird/quiz-answers.md b/olddocs/js/lessons/flipping-bird/quiz-answers.md deleted file mode 100644 index 2dcfef42..00000000 --- a/olddocs/js/lessons/flipping-bird/quiz-answers.md +++ /dev/null @@ -1,50 +0,0 @@ -# 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? - -
- -Modulo (or Mod) is the remainder of a division problem. - -## 2. Consider the following code - -If the rectangle below represents the @boardname@, 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 -``` - -
- -
- -![](/static/mb/lessons/flipping-bird-0.png) - -The variable `count` is now equal to 3. - -
- -## 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 @boardname@, shade in the LEDs that show the value being stored into the **global variable**, `count`. Explain why that particular area is shaded. - -
- -
- -![](/static/mb/lessons/flipping-bird-1.png) - -The display will show `2` because the remainder of 12 divided by 5 is 2. - diff --git a/olddocs/js/lessons/flipping-bird/quiz.md b/olddocs/js/lessons/flipping-bird/quiz.md deleted file mode 100644 index 9ede676a..00000000 --- a/olddocs/js/lessons/flipping-bird/quiz.md +++ /dev/null @@ -1,60 +0,0 @@ -# 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 @boardname@, shade in the LEDs that show the value being stored into the **global variable**, `count`. - -``` -count = 1 -``` - -![](/static/mb/empty-microbit.png) - -
- -
- -## 3. Consider the following code - -If the rectangle below represents the @boardname@, 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 -``` - -![](/static/mb/empty-microbit.png) - -
- -
- -## 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 @boardname@, shade in the LEDs that show the value being stored into the **global variable**, `count`. Explain why that particular area is shaded. - -![](/static/mb/empty-microbit.png) - -
- -
- diff --git a/olddocs/js/lessons/for-loop/challenges.md b/olddocs/js/lessons/for-loop/challenges.md deleted file mode 100644 index 470d7f6c..00000000 --- a/olddocs/js/lessons/for-loop/challenges.md +++ /dev/null @@ -1,41 +0,0 @@ -# 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. - diff --git a/olddocs/js/lessons/glowing-image/challenges.md b/olddocs/js/lessons/glowing-image/challenges.md deleted file mode 100644 index fb62fd4d..00000000 --- a/olddocs/js/lessons/glowing-image/challenges.md +++ /dev/null @@ -1,56 +0,0 @@ -# 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. - diff --git a/olddocs/js/lessons/glowing-mountain/challenges.md b/olddocs/js/lessons/glowing-mountain/challenges.md deleted file mode 100644 index da15ec76..00000000 --- a/olddocs/js/lessons/glowing-mountain/challenges.md +++ /dev/null @@ -1,60 +0,0 @@ -# glowing sword 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) // *** -``` - -* Run the code to see if it works as expected. - -### 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) // *** -``` - -* 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. - diff --git a/olddocs/js/lessons/glowing-sword.md b/olddocs/js/lessons/glowing-sword.md deleted file mode 100644 index bae73c16..00000000 --- a/olddocs/js/lessons/glowing-sword.md +++ /dev/null @@ -1,95 +0,0 @@ -# glowing sword lesson - -make a glowing sword. - -## 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. - diff --git a/olddocs/js/lessons/glowing-sword/activity.md b/olddocs/js/lessons/glowing-sword/activity.md deleted file mode 100644 index 1f5bc850..00000000 --- a/olddocs/js/lessons/glowing-sword/activity.md +++ /dev/null @@ -1,61 +0,0 @@ -# glowing sword activity - -Make glowing sword. - -### ~avatar avatar - -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)! - -### ~ - diff --git a/olddocs/js/lessons/glowing-sword/challenges.md b/olddocs/js/lessons/glowing-sword/challenges.md deleted file mode 100644 index 7fafb951..00000000 --- a/olddocs/js/lessons/glowing-sword/challenges.md +++ /dev/null @@ -1,60 +0,0 @@ -# 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 - -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. - diff --git a/olddocs/js/lessons/glowing-sword/quiz-answers.md b/olddocs/js/lessons/glowing-sword/quiz-answers.md deleted file mode 100644 index f06bcf94..00000000 --- a/olddocs/js/lessons/glowing-sword/quiz-answers.md +++ /dev/null @@ -1,48 +0,0 @@ -# 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). - -
- -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? - -
- -led->fade in(500) - diff --git a/olddocs/js/lessons/glowing-sword/quiz.md b/olddocs/js/lessons/glowing-sword/quiz.md deleted file mode 100644 index 1f50ec2e..00000000 --- a/olddocs/js/lessons/glowing-sword/quiz.md +++ /dev/null @@ -1,46 +0,0 @@ -# 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? - -
- -## 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) -``` - -
- -## 3. What will cause the image to fade back in twice as fast as it faded out? - -``` -basic.plotImage(` -. . . . # -# . . # . -. # # . . -. # # . . -# . . # . -`) -led.fadeOut(1000) -``` - -
- diff --git a/olddocs/js/lessons/hack-your-headphones.md b/olddocs/js/lessons/hack-your-headphones.md deleted file mode 100644 index 296f0b9e..00000000 --- a/olddocs/js/lessons/hack-your-headphones.md +++ /dev/null @@ -1,24 +0,0 @@ -# hack your headphones lesson - -display beautiful images on the @boardname@. - -## 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 @boardname@ 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 @boardname@ with headphones to play music - diff --git a/olddocs/js/lessons/jailbreak.md b/olddocs/js/lessons/jailbreak.md deleted file mode 100644 index ae600afd..00000000 --- a/olddocs/js/lessons/jailbreak.md +++ /dev/null @@ -1,106 +0,0 @@ -# jailbreak lesson - -Break out of a counting loop by pressing button "A". - -## 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...](/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) - diff --git a/olddocs/js/lessons/jailbreak/challenges.md b/olddocs/js/lessons/jailbreak/challenges.md deleted file mode 100644 index e3821667..00000000 --- a/olddocs/js/lessons/jailbreak/challenges.md +++ /dev/null @@ -1,104 +0,0 @@ -# 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. - diff --git a/olddocs/js/lessons/jailbreak/quiz-answers.md b/olddocs/js/lessons/jailbreak/quiz-answers.md deleted file mode 100644 index c4a2b03f..00000000 --- a/olddocs/js/lessons/jailbreak/quiz-answers.md +++ /dev/null @@ -1,46 +0,0 @@ -# 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) -} -``` - diff --git a/olddocs/js/lessons/jailbreak/quiz.md b/olddocs/js/lessons/jailbreak/quiz.md deleted file mode 100644 index a33bd51e..00000000 --- a/olddocs/js/lessons/jailbreak/quiz.md +++ /dev/null @@ -1,34 +0,0 @@ -# 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. - -
- -## 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). - -
- -## 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 ** - -
- -
- diff --git a/olddocs/js/lessons/landslide.md b/olddocs/js/lessons/landslide.md deleted file mode 100644 index bf071d87..00000000 --- a/olddocs/js/lessons/landslide.md +++ /dev/null @@ -1,8 +0,0 @@ -# landslide - -Turn a LED on and off. #docs - -Detect and show an image when the @boardname@ falls. - -* [tutorial](/lessons/landslide/tutorial) -* [challenges](/lessons/landslide/challenges) diff --git a/olddocs/js/lessons/landslide/challenges.md b/olddocs/js/lessons/landslide/challenges.md deleted file mode 100644 index a6faf1b2..00000000 --- a/olddocs/js/lessons/landslide/challenges.md +++ /dev/null @@ -1,77 +0,0 @@ -# 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 @boardname@ falls! First, add `basic->pause(2000)` followed by another image of your choice. Be creative! - diff --git a/olddocs/js/lessons/letter-up.md b/olddocs/js/lessons/letter-up.md deleted file mode 100644 index cae1cf47..00000000 --- a/olddocs/js/lessons/letter-up.md +++ /dev/null @@ -1,112 +0,0 @@ -# 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...](/types/string) -* **string functions** : [read more...](/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) -* **math random** : [read more...](/js/math) - -## 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 @boardname@ 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. - diff --git a/olddocs/js/lessons/light-column-cascade/quiz.md b/olddocs/js/lessons/light-column-cascade/quiz.md deleted file mode 100644 index b9ccf639..00000000 --- a/olddocs/js/lessons/light-column-cascade/quiz.md +++ /dev/null @@ -1,128 +0,0 @@ -# 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. - -![](/static/mb/empty-microbit.png) - -## 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. - -![](/static/mb/empty-microbit.png) - -## 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. - -![](/static/mb/empty-microbit.png) - -****************************** - -## 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. - -![](/static/mb/lessons/cascade-0.png) - -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. - -![](/static/mb/lessons/column-0.png) - -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. - -![](/static/mb/lessons/column-1.png) - -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) - diff --git a/olddocs/js/lessons/line-of-fire.md b/olddocs/js/lessons/line-of-fire.md deleted file mode 100644 index efd0636c..00000000 --- a/olddocs/js/lessons/line-of-fire.md +++ /dev/null @@ -1,94 +0,0 @@ -# line of fire lesson - -Create a game that relies on precise instincts and timing reflexes #if #. - -## 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...](/types/number) -* **Boolean** : [read more...](/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 @boardname@'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) - diff --git a/olddocs/js/lessons/line-of-fire/quiz-answers.md b/olddocs/js/lessons/line-of-fire/quiz-answers.md deleted file mode 100644 index eb4f8de0..00000000 --- a/olddocs/js/lessons/line-of-fire/quiz-answers.md +++ /dev/null @@ -1,140 +0,0 @@ -# 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? - -
- -``` -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. - -
- -``` -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. - -
- -``` -wins = 0 -losses = 0 -``` - -## 4. Write the For Loop that will plot the 'line of fire'. - -
- -``` -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. - -
- -**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. - -
- -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. - -
- -``` -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. - -
- -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'.) - -
- -``` -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'.) - -
- -``` -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) -}) -``` - diff --git a/olddocs/js/lessons/line-of-fire/quiz.md b/olddocs/js/lessons/line-of-fire/quiz.md deleted file mode 100644 index ab5574c3..00000000 --- a/olddocs/js/lessons/line-of-fire/quiz.md +++ /dev/null @@ -1,84 +0,0 @@ -# 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? - -
- -
- -## 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. - -
- -
- -## 3. Write the name of the two variables that keep track of the score, and assign them to their initial values. - -
- -
- -## 4. Write the For Loop that will plot the 'line of fire'. - -
- -
- -
- -## 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. - -
- -**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. - -
- -
- -
- -## 7. Update its position variables by adding the velocity to the dot's current position. - -
- -## 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. - -
- -
- -
- -## 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'.) - -
- -
- -
- -## 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'.) - -
- -
- -
- -
- -
- diff --git a/olddocs/js/lessons/logo-pointer/challenges.md b/olddocs/js/lessons/logo-pointer/challenges.md deleted file mode 100644 index 88885494..00000000 --- a/olddocs/js/lessons/logo-pointer/challenges.md +++ /dev/null @@ -1,71 +0,0 @@ -# magic logo challenges - -These challenges will help you show arrows that point which way the logo is pointing! #docs - -## Challenge 0 - -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 - -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 @boardname@ is shaken. We can do this by adding an on shake condition and showing an animation of the arrow spinning! - diff --git a/olddocs/js/lessons/looper/challenges.md b/olddocs/js/lessons/looper/challenges.md deleted file mode 100644 index 8836b5d4..00000000 --- a/olddocs/js/lessons/looper/challenges.md +++ /dev/null @@ -1,75 +0,0 @@ -# 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 - -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 - -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 - -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 - -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`! - diff --git a/olddocs/js/lessons/looper/lesson.md b/olddocs/js/lessons/looper/lesson.md deleted file mode 100644 index b9cb016c..00000000 --- a/olddocs/js/lessons/looper/lesson.md +++ /dev/null @@ -1,103 +0,0 @@ -# looper lesson - -Learn to control blinking LEDs. - -## 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. - diff --git a/olddocs/js/lessons/meteorite.md b/olddocs/js/lessons/meteorite.md deleted file mode 100644 index 8b2b97e1..00000000 --- a/olddocs/js/lessons/meteorite.md +++ /dev/null @@ -1,99 +0,0 @@ -# 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...](/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 @boardname@'s LED screen -* learn how to show a string on the @boardname@'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) - diff --git a/olddocs/js/lessons/meteorite/quiz-answers.md b/olddocs/js/lessons/meteorite/quiz-answers.md deleted file mode 100644 index 944b5a46..00000000 --- a/olddocs/js/lessons/meteorite/quiz-answers.md +++ /dev/null @@ -1,88 +0,0 @@ -# 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".) - -
- -``` -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".) - -
- -``` -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". - -
- -``` -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. - -
- -``` -pauseDifficulty = (pauseDifficulty * 49) / 50 -``` - -## 5. Write the code that moves the ship left. - -
- -``` -led.unplot(shipLeftX + 1, 4) -shipLeftX = shipLeftX - 1 -led.plot(shipLeftX, 4) -``` - -## 6. Write the code that moves the ship right. - -
- -``` -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. - -
- -``` -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".) - -
- -``` -led.plotAll() -for (let i = 0; i < 3; i++) { - led.fadeIn(400) - led.fadeOut(400) -} -``` - diff --git a/olddocs/js/lessons/meteorite/quiz.md b/olddocs/js/lessons/meteorite/quiz.md deleted file mode 100644 index 4b4f5a6e..00000000 --- a/olddocs/js/lessons/meteorite/quiz.md +++ /dev/null @@ -1,44 +0,0 @@ -# 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".) - -
- -## 2. Write the code that plots the initial position of the ship. (Hint: look inside the function "initialize game".) - -
- -## 3. Write the code that will detect if a meteorite 1 collided with the ship. (Hint: look inside the function "move meteorite 1". - -
- -## 4. Write the code that increase the difficulty by making the game run faster. - -
- -## 5. Write the code that moves the ship left. - -
- -## 6. Write the code that moves the ship right. - -
- -## 7. Write the function that checks if moving the ship resulted in a collision with meteorite 1. - -
- -## 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".) - -
- diff --git a/olddocs/js/lessons/minesweeper.md b/olddocs/js/lessons/minesweeper.md deleted file mode 100644 index 22df7175..00000000 --- a/olddocs/js/lessons/minesweeper.md +++ /dev/null @@ -1,110 +0,0 @@ -# minesweeper lesson - -A game that tests your memory for placing a LED mine then finding the hidden LED mine. - -## 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) - diff --git a/olddocs/js/lessons/minesweeper/quiz-answers.md b/olddocs/js/lessons/minesweeper/quiz-answers.md deleted file mode 100644 index b4b01533..00000000 --- a/olddocs/js/lessons/minesweeper/quiz-answers.md +++ /dev/null @@ -1,55 +0,0 @@ -# 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'. - -
- -``` -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 ( , )` - -![](/static/mb/lessons/blink-1.png) - -
- -``` -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 ( , )` - -![](/static/mb/lessons/blink-0.png) - -
- -``` -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? - -
- -
- -``` -if (mineX + 2 > selectX && selectX > mineX - 2 && mineY + 2 > selectY && selectY > mineY - 2) { -} -``` - diff --git a/olddocs/js/lessons/minesweeper/quiz.md b/olddocs/js/lessons/minesweeper/quiz.md deleted file mode 100644 index e8dc0476..00000000 --- a/olddocs/js/lessons/minesweeper/quiz.md +++ /dev/null @@ -1,34 +0,0 @@ -# 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'. - -
- -## 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 ( , )` - -![](/static/mb/lessons/blink-1.png) - -
- -## 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 ( , )` - -![](/static/mb/lessons/blink-0.png) - -
- -## 4. How do you check if a dot is one away from given x and y coordinates? - -
- -
- diff --git a/olddocs/js/lessons/number-psych/quiz-answers.md b/olddocs/js/lessons/number-psych/quiz-answers.md deleted file mode 100644 index eb676a55..00000000 --- a/olddocs/js/lessons/number-psych/quiz-answers.md +++ /dev/null @@ -1,207 +0,0 @@ -# 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'. - -
- -``` -let options = ([]) -``` - -## 2. Add the options '1', '3', and '5' into the local variable 'options'. - -
- -``` -options.push(1) -options.push(3) -options.push(5) -``` - -## 3. Create a collection of scores and add four values of '0' into the collection. - -
- -``` -let scores = ([]) -``` - -## 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. - -
- -``` -scores = ([]) -for (let i2 = 0; i2 < 4; i2++) { - scores.push(0) -} -``` - -## 5.Write the code that transfers the three options. - -
- -``` -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.) - -
- -``` -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.) - -
- -``` -let choices = ([]) -let hasCommon = ([]) -``` - -## 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.) - -
- -``` -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.) - -
- -``` -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 @boardname@. - -
- -``` -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.) - -
- -``` -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. - -
- -``` -input.onButtonPressed(Button.B, () => { - if (gameMode == 2) { - gameMode = 1 - basic.plotImage(` -. . . . . -. . . . . -. # # # . -. . . . . -. . . . . -`) - } -}) -``` - -## 13. Create a while loop that first reads which controller the console @boardname@ 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). - -
- -``` -while (true) { - let playerRequest = micro_bitTransfer.readByte() - basic.plotImage(` -. . . . . -. . . . . -. # # # . -. . . . . -. . . . . -`) - if (playerRequest == 100 + playerNumber) { - } -} -``` - -## 14. Write the code that displays an "X" on the @boardname@ if 'result' is 1. Otherwise, display a "check mark". - -
- -``` -if (result == 1) { - basic.plotImage(` -# . . . # -. # . # . -. . # . . -. # . # . -# . . . # -`) -} else { - basic.plotImage(` -. . . . . -. . . . # -. . . # . -# . # . . -. # . . . -`) -} -``` - diff --git a/olddocs/js/lessons/number-psych/quiz.md b/olddocs/js/lessons/number-psych/quiz.md deleted file mode 100644 index 4bf034be..00000000 --- a/olddocs/js/lessons/number-psych/quiz.md +++ /dev/null @@ -1,116 +0,0 @@ -# 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'. - -
- -## 2. Add the options '1', '3', and '5' into the local variable 'options'. - -
- -
- -## 3. Create a collection of scores and add four values of '0' into the collection. - -
- -
- -## 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. - -
- -
- -
- -## 5.Write the code that transfers the three options. - -
- -
- -## 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.) - -
- -
- -
- -## 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.) - -
- -
- -## 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.) - -
- -
- -
- -
- -
- -
- -## 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.) - -
- -
- -
- -**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 @boardname@. - -
- -
- -## 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.) - -
- -
- -
- -## 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. - -
- -
- -## 13. Create a while loop that first reads which controller the console @boardname@ 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). - -
- -
- -
- -## 14. Write the code that displays an "X" on the @boardname@ if 'result' is 1. Otherwise, display a "check mark". - -
- -
- diff --git a/olddocs/js/lessons/on-fall/challenges.md b/olddocs/js/lessons/on-fall/challenges.md deleted file mode 100644 index ea67fb72..00000000 --- a/olddocs/js/lessons/on-fall/challenges.md +++ /dev/null @@ -1,69 +0,0 @@ -# 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 @boardname@ is falling. Your goal is to write a program that detects when the @boardname@ 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 @boardname@ alternates between the exclamation point and "X" images when the @boardname@ 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) - diff --git a/olddocs/js/lessons/on-logo-up-and-down/challenges.md b/olddocs/js/lessons/on-logo-up-and-down/challenges.md deleted file mode 100644 index f7c0f60b..00000000 --- a/olddocs/js/lessons/on-logo-up-and-down/challenges.md +++ /dev/null @@ -1,67 +0,0 @@ -# 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) // *** -}) -``` - diff --git a/olddocs/js/lessons/on-shake/challenges.md b/olddocs/js/lessons/on-shake/challenges.md deleted file mode 100644 index 3a31b227..00000000 --- a/olddocs/js/lessons/on-shake/challenges.md +++ /dev/null @@ -1,81 +0,0 @@ -# flipping bird challenges - -These challenges will allow you to create and display a flipping image of a bird when the @boardname@ is shaken. #docs - -### Challenge 0 - -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! - diff --git a/olddocs/js/lessons/pong.md b/olddocs/js/lessons/pong.md deleted file mode 100644 index 1ac3df35..00000000 --- a/olddocs/js/lessons/pong.md +++ /dev/null @@ -1,133 +0,0 @@ -# pong lesson - -code your own game of Pong on the @boardname@. #. - -## 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...](/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 @boardname@'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. - diff --git a/olddocs/js/lessons/pong/activity.md b/olddocs/js/lessons/pong/activity.md deleted file mode 100644 index 2f459fc6..00000000 --- a/olddocs/js/lessons/pong/activity.md +++ /dev/null @@ -1,63 +0,0 @@ -# pong activity - -Building a game of pong with sprites. - -### ~avatar avatar - -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) - } -}) -``` - diff --git a/olddocs/js/lessons/pong/quiz-answers.md b/olddocs/js/lessons/pong/quiz-answers.md deleted file mode 100644 index 6fc1fa51..00000000 --- a/olddocs/js/lessons/pong/quiz-answers.md +++ /dev/null @@ -1,87 +0,0 @@ -# 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. - -
- -``` -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. - -
- -``` -ballXVelocity = 1 -ballYVelocity = 1 -``` - -## 3. Write the code that plots the initial position of the paddle and the ball. - -
- -``` -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.) - -
- -``` -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.) - -
- -``` -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".) - -
- -``` -if (ballY == 4 || ballY == 0) { - ballYVelocity = (-1) * ballYVelocity -} -``` - -## 7. Write the code to move the ball. (Hint: look at the function "move ball".) - -
- -``` -led.unplot(ballX, ballY) -ballX = ballX + ballXVelocity -ballY = ballY + ballYVelocity -``` - diff --git a/olddocs/js/lessons/pong/quiz.md b/olddocs/js/lessons/pong/quiz.md deleted file mode 100644 index e049ac85..00000000 --- a/olddocs/js/lessons/pong/quiz.md +++ /dev/null @@ -1,40 +0,0 @@ -# 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. - -
- -## 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. - -
- -## 3. Write the code that plots the initial position of the paddle and the ball. - -
- -## 4. Write the code that moves the paddle up when Button A is pressed. (Don't worry about setting 'game running' to true.) - -
- -## 5. Write the code that moves the paddle up when Button B is pressed. (Don't worry about setting 'game running' to true.) - -
- -## 6. Write the code to update the y-velocity. (Hint: look at the function "update y velocity".) - -
- -## 7. Write the code to move the ball. (Hint: look at the function "move ball".) - -
- diff --git a/olddocs/js/lessons/rectangle-explosion/challenges.md b/olddocs/js/lessons/rectangle-explosion/challenges.md deleted file mode 100644 index d5f73b1d..00000000 --- a/olddocs/js/lessons/rectangle-explosion/challenges.md +++ /dev/null @@ -1,77 +0,0 @@ -# snowflake fall challenges - -These challenges will allow you to make an exploding rectangle. #docs - -**Challenge 0** - -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** - -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** - -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()`. - diff --git a/olddocs/js/lessons/return/challenges.md b/olddocs/js/lessons/return/challenges.md deleted file mode 100644 index efcfe8eb..00000000 --- a/olddocs/js/lessons/return/challenges.md +++ /dev/null @@ -1,46 +0,0 @@ -# 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. - diff --git a/olddocs/js/lessons/rock-paper-scissors-book-version/challenges.md b/olddocs/js/lessons/rock-paper-scissors-book-version/challenges.md deleted file mode 100644 index 209bc049..00000000 --- a/olddocs/js/lessons/rock-paper-scissors-book-version/challenges.md +++ /dev/null @@ -1,235 +0,0 @@ -# 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 @boardname@ using global variables. Create a global variable to keep track of the wins against the @boardname@. 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 @boardname@. 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 @boardname@. 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 @boardname@. - -## Challenge 2 - -### Step 21 - -You have managed to keep score of the number of wins you have against the @boardname@. 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 @boardname@ 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 @boardname@. - -``` -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 @boardname@! 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 @boardname@ can! - -Congratulations! You have successfully created a fully functional game of rock, paper, scissors against the @boardname@. Challenge your friends to see who can get a better score against the @boardname@. - diff --git a/olddocs/js/lessons/rock-paper-scissors-teacher-guide/challenges.md b/olddocs/js/lessons/rock-paper-scissors-teacher-guide/challenges.md deleted file mode 100644 index 1b23ef56..00000000 --- a/olddocs/js/lessons/rock-paper-scissors-teacher-guide/challenges.md +++ /dev/null @@ -1,235 +0,0 @@ -# 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 @boardname@ using global variables. Create a global variable to keep track of the wins against the @boardname@. 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 @boardname@. 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 @boardname@. 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 @boardname@. - -## Challenge 2 - -### Step 21 - -You have managed to keep score of the number of wins you have against the @boardname@. 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 @boardname@ 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 @boardname@. - -``` -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 @boardname@! 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 @boardname@ can! - -Congratulations! You have successfully created a fully functional game of rock, paper, scissors against the @boardname@. Challenge your friends to see who can get a better score against the @boardname@. - diff --git a/olddocs/js/lessons/runaway-pacman.md b/olddocs/js/lessons/runaway-pacman.md deleted file mode 100644 index 68884af7..00000000 --- a/olddocs/js/lessons/runaway-pacman.md +++ /dev/null @@ -1,7 +0,0 @@ -# runaway pacman lessons - -make a game to test hand-eye coordination. - -Make a game to test hand-eye coordination - -* [tutorial](/lessons/runaway-pacman/tutorial) diff --git a/olddocs/js/lessons/runaway-pacman/quiz-answers.md b/olddocs/js/lessons/runaway-pacman/quiz-answers.md deleted file mode 100644 index 4c004f22..00000000 --- a/olddocs/js/lessons/runaway-pacman/quiz-answers.md +++ /dev/null @@ -1,117 +0,0 @@ -# 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. - -
- -``` -initializeState() -``` - -## 2. Write the the method name created that will draw the player and the monster(s) - -
- -``` -redraw() -``` - -## 3. Write the code that keeps track of how long a player has been playing. (Don't include any if statements.) - -
- -``` -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. - -
- -``` -if ( ! playing) { - levelTime = 0 - playing = true -} -``` - -## 5. Write 'If statement' that will determine if the player has been playing for more than 5 seconds. - -
- -``` -if (levelTime >= 5000) { -} -``` - -## 6. Suspend the game if we are advancing to the next level. (Hint: this requires setting a variable to true.) - -
- -``` -gameSuspended = true -``` - -## 7. Write the code to add a monster. (Hint: look in the function "add monster".) - -
- -``` -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. - -
- -``` -levelTime = 0 -``` - -## 9. Write the code that makes the player go either North or East when button 'A' is pressed. - -
- -``` -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. - -
- -``` -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 -}) -``` - diff --git a/olddocs/js/lessons/runaway-pacman/quiz.md b/olddocs/js/lessons/runaway-pacman/quiz.md deleted file mode 100644 index 4914634d..00000000 --- a/olddocs/js/lessons/runaway-pacman/quiz.md +++ /dev/null @@ -1,60 +0,0 @@ -# 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. - -
- -## 2. Write the the method name created that will draw the player and the monster(s) - -
- -## 3. Write the code that keeps track of how long a player has been playing. (Don't include any if statements.) - -
- -## 4. Write the code that will reset the time and continue playing if we have been eaten. - -
- -## 5. Write 'If statement' that will determine if the player has been playing for more than 5 seconds. - -
- -## 6. Suspend the game if we are advancing to the next level. (Hint: this requires setting a variable to true.) - -
- -## 7. Write the code to add a monster. (Hint: look in the function "add monster".) - -
- -## 8. Write the code that will restart the time to 0 after you begin the next level. - -
- -## 9. Write the code that makes the player go either North or East when button 'A' is pressed. - -
- -
- -
- -## 10. Write the code that makes the player go either South or West when button 'B' is pressed. - -
- -
- -
- diff --git a/olddocs/js/lessons/running-time/challenges.md b/olddocs/js/lessons/running-time/challenges.md deleted file mode 100644 index 62fb8280..00000000 --- a/olddocs/js/lessons/running-time/challenges.md +++ /dev/null @@ -1,30 +0,0 @@ -# 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 @boardname@ 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. diff --git a/olddocs/js/lessons/screen-up-and-down/challenges.md b/olddocs/js/lessons/screen-up-and-down/challenges.md deleted file mode 100644 index 06ac19bf..00000000 --- a/olddocs/js/lessons/screen-up-and-down/challenges.md +++ /dev/null @@ -1,64 +0,0 @@ -# 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 @boardname@ 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 @boardname@ 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) // *** -}) -``` - diff --git a/olddocs/js/lessons/screen-wipe/activity.md b/olddocs/js/lessons/screen-wipe/activity.md deleted file mode 100644 index de3a7a12..00000000 --- a/olddocs/js/lessons/screen-wipe/activity.md +++ /dev/null @@ -1,45 +0,0 @@ -# screen wipe activity - -Clear the screen by pressing buttons on the @boardname@. - -### ~avatar avatar - -This activity will teach how to clear the screen by pressing button ``A`` on the @boardname@. - -### ~ - -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 @boardname@ to see how this works! - -### ~avatar boothing - -Excellent, you're ready to continue with the [challenges](/lessons/screen-wipe/challenges)! - -### ~ - diff --git a/olddocs/js/lessons/screen-wipe/challenges.md b/olddocs/js/lessons/screen-wipe/challenges.md deleted file mode 100644 index 1e7ba2c2..00000000 --- a/olddocs/js/lessons/screen-wipe/challenges.md +++ /dev/null @@ -1,71 +0,0 @@ -# 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** - -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! diff --git a/olddocs/js/lessons/screen-wipe/quiz-answers.md b/olddocs/js/lessons/screen-wipe/quiz-answers.md deleted file mode 100644 index 6c6eb45e..00000000 --- a/olddocs/js/lessons/screen-wipe/quiz-answers.md +++ /dev/null @@ -1,45 +0,0 @@ -# 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 @boardname@? - -This function turns off all the LED lights on the LED screen. - -## 2. Write the line of code that creates and displays this animation. - -![](/static/mb/lessons/screen-wipe-0.png) - -
- -``` -basic.showAnimation(` -# # # # . # # # # # . . . . . . . . . . -# # # # # # # # # # . . . . . . . . . . -. . . . . # # # # # # # # # # . . . . . -. . . . . # # # # # # # # # # # # # # # -. . . . . . . . . . . . . . . # # # # # -`, 400) -``` - -## 3. Write the condition that will detect when the @boardname@ is shaken. - -
- -``` -input.onGesture(Gesture.Shake, () => { -}) -``` - -## 4. Write the code that will clear an animation from the screen after shaking the @boardname@. - -
- -``` -input.onGesture(Gesture.Shake, () => { - basic.clearScreen() -}) -``` - diff --git a/olddocs/js/lessons/screen-wipe/quiz.md b/olddocs/js/lessons/screen-wipe/quiz.md deleted file mode 100644 index 7924842c..00000000 --- a/olddocs/js/lessons/screen-wipe/quiz.md +++ /dev/null @@ -1,32 +0,0 @@ -# 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 @boardname@? - -
- -## 2. We can show all of these images in one line of code. What method can we use to do this? - -![](/static/mb/lessons/screen-wipe-0.png) - -
- -## 3. How can the @boardname@ detect when it is shaken? - -
- -
- -## 4. Write the code that will clear an animation from the screen after shaking the @boardname@. - -
- diff --git a/olddocs/js/lessons/set-brightness/challenges.md b/olddocs/js/lessons/set-brightness/challenges.md deleted file mode 100644 index ac8af701..00000000 --- a/olddocs/js/lessons/set-brightness/challenges.md +++ /dev/null @@ -1,50 +0,0 @@ -# set brightness challenges - -These challenges will allow you to change the brightness of the @boardname@. docs - -**Challenge 0** - -[This tutorial](/lessons/set-brightness/tutorial) will show you how to set the brightness on the @boardname@. - -``` -led.setBrightness(255) -led.plotAll() -input.onButtonPressed(Button.A, () => { - led.setBrightness(64) -}) -``` - -**Challenge 1** - -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. diff --git a/olddocs/js/lessons/show-number/challenges.md b/olddocs/js/lessons/show-number/challenges.md deleted file mode 100644 index ca608ada..00000000 --- a/olddocs/js/lessons/show-number/challenges.md +++ /dev/null @@ -1,39 +0,0 @@ -# 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! - diff --git a/olddocs/js/lessons/show-string/challenges.md b/olddocs/js/lessons/show-string/challenges.md deleted file mode 100644 index 3ebb8c80..00000000 --- a/olddocs/js/lessons/show-string/challenges.md +++ /dev/null @@ -1,38 +0,0 @@ -# show string challenges - -My script. #docs - -**Challenge 0** - -Welcome! This [guided tutorial](/pxjkww) introduces the basic show string method on the @boardname@. - -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! - diff --git a/olddocs/js/lessons/the-hat-game.md b/olddocs/js/lessons/the-hat-game.md deleted file mode 100644 index 2f307eaa..00000000 --- a/olddocs/js/lessons/the-hat-game.md +++ /dev/null @@ -1,71 +0,0 @@ -# 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 - diff --git a/olddocs/js/lessons/the-hat-game/challenges.md b/olddocs/js/lessons/the-hat-game/challenges.md deleted file mode 100644 index 44dd1b7d..00000000 --- a/olddocs/js/lessons/the-hat-game/challenges.md +++ /dev/null @@ -1,174 +0,0 @@ -# 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! - diff --git a/olddocs/js/lessons/the-hat-game/quiz-answers.md b/olddocs/js/lessons/the-hat-game/quiz-answers.md deleted file mode 100644 index a9582a3d..00000000 --- a/olddocs/js/lessons/the-hat-game/quiz-answers.md +++ /dev/null @@ -1,87 +0,0 @@ -# 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? - -
- -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). - -
- -``` -for (let i = 0; i < 3; i++) { - led.plot(i * 2, 2) -} -``` - -## 3. How can you increase the difficulty of the game? - -
- -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. - -
- -
- -``` -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. - -
- -``` -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. - -
- -``` -swapHats(math.mod(not + 1, 3), math.mod(not + 2, 3), 50) -``` - -
- diff --git a/olddocs/js/lessons/the-hat-game/quiz.md b/olddocs/js/lessons/the-hat-game/quiz.md deleted file mode 100644 index 7b8a4ac1..00000000 --- a/olddocs/js/lessons/the-hat-game/quiz.md +++ /dev/null @@ -1,59 +0,0 @@ -# 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? - -
- -## 2. Write a for loop that plots the points (0, 2), (2, 2), and (4, 2). - -
- -## 3. How can you increase the difficulty of the game? - -
- -## 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. - -
- -
- -
- -
- -
- -## 5. Write the line of code that shows the swapping animation of two hats swapping if hat 1 = 0 and hat 2 = 2. - -
- -## 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. - -
- -
- diff --git a/olddocs/js/lessons/timing-game.md b/olddocs/js/lessons/timing-game.md deleted file mode 100644 index aa6a41a0..00000000 --- a/olddocs/js/lessons/timing-game.md +++ /dev/null @@ -1,7 +0,0 @@ -# timing game - -make a game to test hand-eye coordination. - -Make a game to test hand-eye coordination - -* [tutorial](/lessons/timing-game/tutorial) diff --git a/olddocs/js/lessons/transformer/quiz.md b/olddocs/js/lessons/transformer/quiz.md deleted file mode 100644 index 438146a5..00000000 --- a/olddocs/js/lessons/transformer/quiz.md +++ /dev/null @@ -1,44 +0,0 @@ -# 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. - -
- -## 3. Consider the following directions - -Write the line of code to use the condition 'on button pressed ("A")' - -
- -## 4. Consider the following directions - -Write the code that creates a function. - -
- -## 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`. - -
- -## 6. Consider the following picture - -Write the code to show number 20 on the @boardname@. Please add the variable called `doubled` Refer to the finished code on the tutorial. - -
- diff --git a/olddocs/js/lessons/transformers.md b/olddocs/js/lessons/transformers.md deleted file mode 100644 index 7e82c8ab..00000000 --- a/olddocs/js/lessons/transformers.md +++ /dev/null @@ -1,123 +0,0 @@ -# transformers lesson - -use functions to return values. - -## 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. - diff --git a/olddocs/js/lessons/transformers/challenges.md b/olddocs/js/lessons/transformers/challenges.md deleted file mode 100644 index 7aa97d3d..00000000 --- a/olddocs/js/lessons/transformers/challenges.md +++ /dev/null @@ -1,52 +0,0 @@ -# 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 - -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. - diff --git a/olddocs/js/lessons/transformers/quiz-answers.md b/olddocs/js/lessons/transformers/quiz-answers.md deleted file mode 100644 index f45cd455..00000000 --- a/olddocs/js/lessons/transformers/quiz-answers.md +++ /dev/null @@ -1,65 +0,0 @@ -# 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. - -
- -``` -let x = 5 -``` - -## 3. Write the line of code to create a condition for 'on button pressed ("A")' - -
- -``` -input.onButtonPressed(Button.A, () => { -}) -``` - -## 4. Write the steps to create a function. - -
- -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. - -
- -``` -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`. - -
- -``` -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. - -
- -``` -let doubleTwice = double(doubled) -``` - diff --git a/olddocs/js/lessons/transformers/quiz.md b/olddocs/js/lessons/transformers/quiz.md deleted file mode 100644 index dd4f111e..00000000 --- a/olddocs/js/lessons/transformers/quiz.md +++ /dev/null @@ -1,40 +0,0 @@ -# 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'? - -
- -## 2. Write the line of code to create a number variable called **x** that is equal to 5. - -
- -## 3. Write the line of code to create a condition for 'on button pressed ("A")' - -
- -## 4. Write the steps to create a function. - -
- -## 5. Create a function called **double** that will double whatever input parameter is passed into it. - -
- -## 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. - -
- -## 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. - -
- diff --git a/olddocs/js/lessons/typing-game/challenges.md b/olddocs/js/lessons/typing-game/challenges.md deleted file mode 100644 index 2ac981b5..00000000 --- a/olddocs/js/lessons/typing-game/challenges.md +++ /dev/null @@ -1,80 +0,0 @@ -# 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 @boardname@! - diff --git a/olddocs/js/lessons/while-counting/challenges.md b/olddocs/js/lessons/while-counting/challenges.md deleted file mode 100644 index 95a5eb17..00000000 --- a/olddocs/js/lessons/while-counting/challenges.md +++ /dev/null @@ -1,61 +0,0 @@ -# digi yoyo challenges - -These challenges will teach you how to create a counter 10 to 1. #docs - -**Challenge 0** - -[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** - -Now, we need `count` to decrease by one after the @boardname@ has displayed the value of `count`. - -We can do this by adding this line: - -``` -count = count - 1 -``` - diff --git a/olddocs/js/lessons/yes-no/challenges.md b/olddocs/js/lessons/yes-no/challenges.md deleted file mode 100644 index 2fdf5c17..00000000 --- a/olddocs/js/lessons/yes-no/challenges.md +++ /dev/null @@ -1,45 +0,0 @@ -# yes no challenges - -My script. #docs - -**Challenge 0** - -This [guided tutorial](/lessons/yes-no/challenges) will show you how to display text on the @boardname@! - -``` -basic.showString("ASK ME A QUESTION", 150) -``` - -**Challenge 1** - -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** - -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`. - diff --git a/olddocs/js/libraries.md b/olddocs/js/libraries.md deleted file mode 100644 index 8f0be3e0..00000000 --- a/olddocs/js/libraries.md +++ /dev/null @@ -1,64 +0,0 @@ -# Create and Use Libraries - -Libraries are scripts with functions that you can use in other scripts. - -### @parent javascript/language - -Libraries are scripts with functions that you can use in other scripts. For example, `game` is a library of game-related functions that you can use in your scripts. - -Benefits of using libraries: - -* **reuse code** between scripts -* **collaborate** with other people on a project by combining scripts into a library - -### Add a library - -To add a library to a script: - -1. Open a script in the [Touch Develop editor](/js/editor) and then click `script` (in the upper-right corner). - -2. Click `+` **add new**. - -3. Click `library`. - -4. Choose the library you want to use or search for a library (such as `game`). - -Once you've added a library to your script, you can use any of the library's non-private [functions](/js/function). Here's how: - -* on the [Code Keyboard](/js/editor) click the button with the library's name (for example, `@boardname@` and `@boardname@ game` are library buttons). The functions in the library have a button on the Code Keyboard. - -### Create a library - -Creating and publishing a script as a library is easy. Here's how: - -1. Open a script in the [Touch Develop editor](/js/editor), and then click `script`. - -2. Click the script name to open the script properties. - -3. Mark the `this script is a library` check box. - -4. Click `script`. - -5. Click `publish`. - -Once a script is marked as a _library_ and published, it's immediately available to other people. - -### Visibility - -The following library items are not accessible by other scripts: - -* data (global variables) -* functions marked as `private` - -If you want to access global library variables from other scripts, you need to create [functions](/js/function) that pass values in and out of the library script. - -### Library and function documentation - -Be sure to document the purpose of your functions and libraries. Add a [comment](/js/comment) at the beginning of a library to describe the purpose of the library. - -Use [comments](/js/comment) at the beginning of your [functions](/js/function) to describe the function's purpose. Comment text shows in the help area of the Code Keyboard when you insert the function. - -### See also - -[functions](/js/function), [Touch Develop Documentation](/js/contents) - diff --git a/olddocs/js/markdown.md b/olddocs/js/markdown.md deleted file mode 100644 index d7059666..00000000 --- a/olddocs/js/markdown.md +++ /dev/null @@ -1,175 +0,0 @@ -# Markdown Syntax - -Syntax to create formatted text in Touch Develop. - -### @parent td/comment - - -Markdown is a popular syntax used by developers to describe and annotate documents. Touch Develop supports a large subset of the markdown syntax, and adds a few new features. Markdown syntax applies to [comments](/js/comment) added using the [Touch Develop editor](/js/editor). - -## Basic markdown syntax - -### Headings - -Use #, ##, or ### at the beginning of a line to specify a heading: - -* ``use # for heading 1`` -* ``use ## for heading 2`` -* ``use ### for heading 3`` - -### Bulleted lists - -Use a * for a bullet: - -``* this is a bullet`` - -### Numbered lists - -Type a number, a period, and a space before each item in a numbered list. Like this: - -> `1. first item` - -> `2. second item` - -> `3. third item` - -The numbers in a numbered list appear as 1. in the Touch Develop editor, however, the numbers will update when the script is previewed or published. - -### Character formatting - -Use a single `*` for italic and `**` for bold: - -``*italic*`` => *italic* - -``**bold**`` => **bold** - -### Links - -* to add a link, type the URL: ``http://touchdevelop.com`` => http://touchdevelop.com -* to specify link text (instead of the URL), put the link text in [ ] brackets and the link in ( ) - -For example: - -``[TouchDevelop website](http://touchdevelop.com)`` => [TouchDevelop website](http://touchdevelop.com) - -### Columns - -To format text into columns, insert ``### ~column `` at the start of each column and ``### ~`` at the end of the column. - -## Touch Develop syntax - -The markdown syntax in this section is non-standard and specific to Touch Develop. - -### Inline code - -Use this syntax: ```basic => show number``` - -To show code like this: `basic-> show number` - -(``->`` is replaced with `->`) - -### HTML entities - -You can use HTML entities like ``&amp;``, ``&lt;``, or ``&#123;``. You can also use ``&`` verbatim if it cannot be confused with HTML entity. - -### Pictures - -You can include pictures in a script by adding an art resource to your script. All pictures must first be uploaded to the Touch Develop cloud before they can be used in a script. Here's how: - -1. Click `script`, **+ add new**, and then click **picture resource**. - -2. You can upload a new picture or search existing pictures. - -3. Give it a name, let's say you call it ``alien``. - -2. In your script, use ``(picture ...)`` with the picture name (in this case, alien) and an optional caption: -WARN: missing picture: ... -WARN: unknown picture: ... - -* ``![](/static/mb/image-0.png)`` - -![](/static/mb/image-0.png) - -By default, pictures are 12x12. You can specify a different size as in `![](/static/mb/image-0.png)`, up to 30x20. - -![](/static/mb/image-0.png) - -To insert a picture inline with text ![](/static/mb/image-0.png), use: `(picture ...)` without any size information. For example: ``![](/static/mb/image-0.png)`` -WARN: missing picture: ... -WARN: unknown picture: ... - -You can skip adding an art resource, and instead use the publication ID of a picture directly. - -### Declarations - -Any named declaration from a script can be rendered in a script using `{decl:name}`. For example, you can render global variables, functions, etc... -WARN: no such decl: name - -* ` -``` -var v: number = 0 -``` - -` where `v` is a global variable in the script: - -``` -var v: number = 0 -``` - -### Code snippets - -Any code that is not a comment is treated as a snippet. - -You can use ``{highlight}`` comment to start highlighting statements in the snippet. Use ``{/highlight}`` to stop. The comment needs to have ``{highlight}`` or ``{/highlight}`` and nothing else. -MACRO: highlightMACRO: /highlightMACRO: highlightMACRO: /highlight - -If you want to render some comments inside the snippets as comments (and not regular text), then surround the snippet with ``{code}`` ... ``{/code}``, for example: -MACRO: codeMACRO: /code - -``` -let theAnswer = 42 // *** -// and now show the answer: -basic.showNumber(theAnswer, 150) -``` - -Note that comments inside block structures are always rendered as regular comments, not text. For example: - -``` -if (false) { - // This code is never executed. -} -``` - -### Boxes and frames - -You can use `### ~ ` and `### ~` (each on separate comment line) to enclose a block of text in a coloured box. For example: - -### ~hint - -This is how `### ~hint ` looks like. Some helpful information goes here. - -### ~ - -The following box types are supported: - -* `hint`, `exercise`, `example` - self-explanatory -* `nointernet` - block with heading "no internet?" for giving instructions for offline operations -* `screen` - does not show in print -* `print` - does not show when not printing -* `portrait` - shows (with no frame or heading) when device is held in portrait orientation; in print it shows with heading "device in portrait" and a frame -* `landscape` - likewise - -### Special tutorial features - -You'll use markdown syntax when creating Touch Develop tutorials. See [create a tutorial](/js/create-tutorials) for more info. - -### ~hide - -### Embedding videos - -* any video: ``{video::}`` where ```` is a screenshot of the video, and ```` is the video url that plays -MACRO: video -If you want to include documents, slides, and videos from other sites, just use regular `http://...` link. - -### ~ - diff --git a/olddocs/js/math.md b/olddocs/js/math.md deleted file mode 100644 index c43f9cfc..00000000 --- a/olddocs/js/math.md +++ /dev/null @@ -1,101 +0,0 @@ -# Math Library - -Functions in the math library. - -### @parent javascript/language - -The math library includes math related functions that you can use with [Numbers](/types/number). - -* In the [TouchDevelop editor](/js/editor), click `math` to access the functions described below -* In the [Block editor](/blocks/editor), click **maths** on the left to see the available blocks - -The functions available in Touch Develop are: - -### abs - -math `->` abs (x : [Number](/types/number)) *returns* [Number](/types/number) - -returns the absolute value of input parameter `x` - -``` -basic.showNumber(math.abs(-7), 150) -``` - -### clamp - -math `->` clamp (min : [Number](/types/number), max : [Number](/types/number), value : [Number](/types/number)) *returns* [Number](/types/number) - -limits a number to a range (between a min and max number); returns `min` if `value` is < `min`; returns `max` if `value` is > `max`; otherwise, returns `value`. - -``` -basic.showNumber(td.clamp(5, 9, 12), 150) -``` - -### max - -math `->` max (x : [Number](/types/number), y : [Number](/types/number)) *returns* [Number](/types/number) - -returns the larger of two input numbers (`x` and `y`) - -``` -basic.showNumber(Math.max(9, 7), 150) -``` - -### min - -math `->` min (x : [Number](/types/number), y : [Number](/types/number)) *returns* [Number](/types/number) - -returns the smaller of two input numbers (`x` and `y`) - -``` -basic.showNumber(Math.min(9, 7), 150) -``` - -### mod - -math `->` mod (x : [Number](/types/number), y : [Number](/types/number)) *returns* [Number](/types/number) - -returns the integer modulus/remainder resulting from the division of the number `x` by the number `y` - -``` -basic.showNumber(math.mod(9, 7), 150) -``` - -### pow - -math `->` pow (base : [Number](/types/number), exp : [Number](/types/number)) *returns* [Number](/types/number) - -returns the value of the number `base` raised to the power `exp` - -``` -basic.showNumber(math.pow(3, 3), 150) -``` - -### random - -math `->` random (limit : [Number](/types/number)) *returns* [Number](/types/number) - -returns a random [Number](/types/number) between 0 and the parameter *limit* - 1 - -``` -basic.showNumber(Math.random(10), 150) -``` - -### sign - -math `->` sign (x : [Number](/types/number)) *returns* [Number](/types/number) - -returns the sign of input parameter `x` - -``` -basic.showNumber(math.sign(-7), 150) -``` - -### Lessons - -[flipping bird](/lessons/flipping-bird), [catch the egg game](/lessons/catch-the-egg-game) - -### See also - -[Bits library](/js/bits), [TouchDevelop documentation](/js/contents), [Number](/types/number) - diff --git a/olddocs/js/micro-bit-api.md b/olddocs/js/micro-bit-api.md deleted file mode 100644 index e4cec462..00000000 --- a/olddocs/js/micro-bit-api.md +++ /dev/null @@ -1,69 +0,0 @@ -# @boardname@ - -The @boardname@ device api. #microbit - -Initialize the library. - -{shim:} -MACRO: shim - -``` -if (board == null) { - compassHeadingValue = (null) - startTime = new Date() - board = media.createPortraitBoard(612, 498 + 100) - wall.setBackground(colors.transparent()) - let picture = microbitSchema.clone() - let padding = 27 - let left = 205 - let top = 156 - picture.fillRect(left - padding, top, 205 + padding + 4, 200 + padding + 4, 0, colors.black()) - picture.fillRect(274, 74, 63, 16, 0, colors.black()) - bkg = board.createPicture(picture) - bkg.width() = board.width() - bkg.left() = 0 - bkg.top() = 0 - createButtons() - finger = board.createEllipse(20, 20) - finger.setOpacity(0) - ledOnColor = "#ff4f4f".toColor() - ledOffColor = colors.transparent() - boardColor = colors.fromRgb(0.85, 0.95, 0.85) - backLeds = board.createSpriteSet() - leds = board.createSpriteSet() - let backLedColor = "#202020".toColor() - let ledOpacity = 127 / 255 - let ledW = 10 - let ledOffset = 48 - let ledH = 20 - for (let i = 0; i < 5; i++) { - let ledTop = i * ledOffset + top - for (let j = 0; j < 5; j++) { - let ledLeft = j * ledOffset + left - let backLed = board.createRectangle(ledW, ledH) - backLed.setColor(backLedColor) - let led = board.createRectangle(ledW + 8, ledH + 8) - backLed.left() = ledLeft - backLed.top() = ledTop - led.x() = backLed.x() - led.y() = backLed.y() - led.setOpacity(ledOpacity) - led.setColor(ledOffColor) - led.setShadow(10, colors.red(), 0, 0) - ledIndexAnim(backLed, j, i) - backLeds.add(backLed) - leds.add(led) - } - } - initEyes() - initAxis() - initPins() - updateAxis() - backgroundAnimation() - board.onEveryFrame(() => { - updateBoard() - }) - board.postToWall() -} -``` - diff --git a/olddocs/js/number.md b/olddocs/js/number.md deleted file mode 100644 index 2acb3205..00000000 --- a/olddocs/js/number.md +++ /dev/null @@ -1,84 +0,0 @@ -# Number - -An integer number. - -### @parent javascript/language - -A *Number* is an integer such as `42` or `-42`. More precisely, a *Number* is a signed 32-bit integer (two's complement). - -### Declare a number variable - -Use the [var statement](/reference/variables/var) and the [assignment operator](/reference/variables/assign) `:=` to declare a *local* number variable. Like this: - -``` -let number1 = 2 -let number2 = 2 -``` - -To declare a *global* number variable, see [global variables](/js/data). - -### Arithmetic operators - -The following arithmetic operators work on numbers and return a [Number](/types/number): - -* addition: `1 + 3` -* subtraction: `1 - 3 ` -* multiplication: `3 * 2` -* integer division: `7 / 3` -* modulo is available through the [math library](/js/math) - -### Relational operators - -The following relational operators work on numbers and return a [Boolean](/types/boolean): - -* equality: `(3 + 1) = 4` -* inequality: `3 != 4` -* less or equal than: `3 <= 4` -* less than: `3 < 4` -* greater or equal than : `4 >= 3` -* greater than: `4 > 3` - -### Show number - -The [show number](/reference/basic/show-number) function displays a number on the [LED screen](/device/screen). For example, this code displays the number 42: - -``` -basic.showNumber(42, 100) -``` - -### Functions that return a number - -Some functions return a number, which you can store in a variable. For example the following code gets the display brightness (using the [brightness function](/reference/led/brightness)) and stores the value in a variable named `brightness`: - -``` -let brightness = led.brightness() -``` - -### Math functions - -The [math library](/js/math) includes math related functions. In the [Touch Develop editor](/js/editor), click `math` on the Code Keyboard to see the math functions. For example, the `mod` function returns the modulus (division of one number by another number): - -``` -number1 = math.mod(4, 3) -``` - -### Convert a number to a string - -The `to string` function converts a Number into a [String](/types/string). The following code converts `number1` to a string and stores the string in the `str` variable: - -``` -let str = number1.toString() -``` - -### Bit-level manipulation - -The [bits library](/js/bits) includes functions for bit-level manipulation of integers. In the [Touch Develop editor](/js/editor), click `bits` on the Code Keyboard to see these functions. - -### Lessons - -[counter](/lessons/counter), [love meter](/lessons/love-meter), [flipping bird](/lessons/flipping-bird), [catch the egg game](/lessons/catch-the-egg-game) - -### See also - -[math library](/js/math), [var](/reference/variables/var), [bits library](/js/bits), [Boolean](/types/boolean), [show number](/reference/basic/show-number) - diff --git a/olddocs/js/object-disclaimer.md b/olddocs/js/object-disclaimer.md deleted file mode 100644 index 7fa13223..00000000 --- a/olddocs/js/object-disclaimer.md +++ /dev/null @@ -1,25 +0,0 @@ -# Objects disclaimer - -Touch Develop docs for the @boardname@. - -### Memory management on the micro-bit - -New user-defined object types are allocated on the heap and are ref-counted. Our ref-counting algorithm does *not* have a cycle collector. (See Wikipedia.) - -### Practical consequences - -This means that the following script will result in an out-of-memory error. - -![](/static/mb/object-disclaimer-0.png) - -``` -while (true) { - let l = new List() - l.next = l -} -``` - -### How to avoid this? - -Don't do it. It's bad. - diff --git a/olddocs/js/object-types.md b/olddocs/js/object-types.md deleted file mode 100644 index d63ed65b..00000000 --- a/olddocs/js/object-types.md +++ /dev/null @@ -1,57 +0,0 @@ -# Custom object types - -Touch Develop docs for the @boardname@. - -### What is an object? - -An object allows you to bundle several related pieces of data. For instance, if you have a player on the screen, there are two pieces of data that make up the object: its `x` position, and its `y` position. Therefore, we will define a player to be an *object* with two *fields*: the `x` field and the `y` field. By grouping related variables together in a single object, you reduce confusion in your script and eliminate some errors. - -### What is an object type? - -In order to use objects, we must first define an object type. More concretely, in order to create a new player, we must define what a player *is*. In our case, the type of players is the type of objects with two fields `x` and `y` of type `Number`. - -Creating an object type is done in the following manner. Hit "add new", then hit "object type". - -![](/static/mb/object-types-0.png)(picture foobar2) -WARN: unknown picture: foobar2 - -You can change the name of the type by clicking on it (i.e. replace `Thing` with `Player`). You can also add two fields of type number. Once this is done, here's what you should see. - -![](/static/mb/object-types-1.png) - -We have now defined what a player is (it has an `x` field and a `y` field). `Player` is a type, just like `Number` and `String`. However, we have not created any player yet. - -### Creating objects and using them - -To create a new *variable* of a given type, you can call the `create` operation on `Player`. - -``` -let p = new Player() -``` - -Just like `var x := 3` creates a new variable (`x`) of type `Number`, the line above creates a new variable (`p`) of type `Player`. We say that `p` is an *instance* of `Player`. - -If you want to *modify* (mutate) `p`, here's how you do it. - -``` -p.x = 5 -``` - -You can read the *fields* of `p` as follows. - -``` -basic.showString("My player is at x = ", 150) -basic.showNumber(p.x, 150) -``` - -That is, the generic syntax for accessing a field `x` of an object `p` is `p → x`. - -If there are multiple players in your game, you may want to create a collection of them. - -``` -let c = ([]) -c.push(new Player()) -``` - -A good example of using objects is in the game pac-man runaway. Search for it, read it and clone it! - diff --git a/olddocs/js/operators.md b/olddocs/js/operators.md deleted file mode 100644 index e466b51c..00000000 --- a/olddocs/js/operators.md +++ /dev/null @@ -1,9 +0,0 @@ -# Operators - -Built-in operators. - -### @parent javascript/language - - -### to be removed: has been combined into [statements and operators](/js/statements) - diff --git a/olddocs/js/orientation.md b/olddocs/js/orientation.md deleted file mode 100644 index 24d3f796..00000000 --- a/olddocs/js/orientation.md +++ /dev/null @@ -1,46 +0,0 @@ -# @boardname@ orientation - -A #microbit library that exposes accelerometer events. - -A simple library that exposes events to detect - -* detect that the screen is facing up and the board is horizontal - -``` -onScreenUp(() => { - micro_bit.showString("screen up", 100) -}) -``` - -* detect that the screen is facing down and the board is horizontal - -``` -onScreenDown(() => { - micro_bit.showString("screen down", 100) -}) -``` - -* detect when the logo is up and the board is vertical - -``` -onLogoUp(() => { - micro_bit.showString("logo up", 100) -}) -``` - -* detect when the logo is down and the board is vertical - -``` -onLogoDown(() => { - micro_bit.showString("r", 100) -}) -``` - -* detect that the device is shaken - -``` -onShake(() => { - micro_bit.showString("shake", 100) -}) -``` - diff --git a/olddocs/js/publishing.md b/olddocs/js/publishing.md deleted file mode 100644 index faf7851d..00000000 --- a/olddocs/js/publishing.md +++ /dev/null @@ -1,52 +0,0 @@ -# Publish a Script - -How to publish scripts. - -### @parent javascript/contents - - -Scripts that you create are periodically saved in the cloud, but only published scripts can be seen by other people. Once you publish a script, other people can run your script, post comments on it, tweak and re-publish it, or rate your script with a heart. - -### How to publish a script - -To publish a script from the TouchDevelop Editor: - -* when you're editing a script, click `script` and then click `publish` - -To publish a script from `My Scripts`: - -* go to **My Scripts* -* click a script on the left and then click `Publish` on the right - -**Publish options:** - -**Share with everyone**: click `publish` to publish your script so that anyone can find it using search or by browsing scripts. - -**Share with people you choose**: click `publish as hidden` to publish your script in a way that it is not discoverable by search (users will need to know your script's id to access it). - -When you publish a script, a url with a unique script id is created so that you can share your script with other people. To share a *publish as hidden* script, copy the url and give it to select people. There is also a `share` button in [script options](/js/editor). - -You can add a short publication note if you'd like. This note appears with the publishing history (on the script overview page). - -### Hidden scripts - -A hidden script is - -* not indexed by the search (so are never visible in search results) -* hidden from various lists, unless the person viewing the list is the user who created the script -* accessible to anyone who knows the hidden script's id -* accessible when it is the base of a public script - -The lists include: - -* list of scripts by the user -* list of derived scripts - -### Published scripts are public! - -**Do not store passwords or other confidential information** in your script code. Everyone will be able to see your script on the Internet forever once it is published. - -### Updates - -If you are working on a script, you might want to publish multiple updates of the same script. As long as you do not change the script name (and you are the author of the previous version), the published version will automatically be considered as the latest version of this script. - diff --git a/olddocs/js/quick-start.md b/olddocs/js/quick-start.md deleted file mode 100644 index 34c279cb..00000000 --- a/olddocs/js/quick-start.md +++ /dev/null @@ -1,34 +0,0 @@ -# The Quick Start Guide for Teachers - -The Quick Start Guide for Teachers #docs - -### ~hint - -**Spotty internet? No problem!** (1) When online, go to https://www.microbit.co.uk/app/ and bookmark this URL; (2) use the bookmark to reload the web app, even without the internet. - -### ~ - -The Quick Start Guide for Teachers is available in [PDF](https://microbit0.blob.core.windows.net/pub/tovulwsd/Quick-Start-Guide-for-Teachers.pdf). - -### Resources - -The currently available on-line resources from the Quick Start Guide are the - -* [scroll text tutorial](/js/tutorials/scroll-text) -* [flashing heart tutorial](/js/tutorials/flashing-heart) -* [button light tutorial](/js/tutorials/button-light) -* [digital key chain tutorial](/js/tutorials/digital-key-chain) -* [rock paper scissors tutorial](/lessons/rock-paper-scissors/tutorial) and [rock paper scissors challenges](/lessons/rock-paper-scissors/challenges) -* [digital pet tutorial](/lessons/digital-pet/tutorial) and [digital pet challenges](/lessons/digital-pet/challenges) -* [catch the egg game tutorial](/lessons/catch-the-egg-game/tutorial) and [catch the egg game challenges](/lessons/catch-the-egg-game/challenges) - -### Errata - -* compilation to the @boardname@ now works [off line](/offline), based on a new compiler in the web browser. The text and picture below replaces the text and picture on page 10 of the Guide: - -### How does my program get onto the @boardname@? - -For your program to work on the @boardname@, first it has to be compiled. Compiling means to translate a program into a more efficient computer language. When you hit the compile button on the Microsoft Touch Develop Editor interface, your program is compiled into a hex file that contains the machine code in the instruction set used by the ARM processor that is on your @boardname@. Compiling to ARM machine code actually happens in the web browser, where the code from script is joined with the machine code of the @boardname@ runtime. - -![](/static/mb/quick-start-0.png) - diff --git a/olddocs/js/reactive.md b/olddocs/js/reactive.md deleted file mode 100644 index a92f01af..00000000 --- a/olddocs/js/reactive.md +++ /dev/null @@ -1,149 +0,0 @@ -# The @boardname@ - a reactive system - -The @boardname@ is a reactive system. #docs - -### Computing systems - -What sort of a *computing system* is the @boardname@? - -### ~hint - -There are different types of computing systems, to address different kinds of problems that arise in practice: *transaction processing systems* are used by banks to handle huge numbers of financial transactions by their customers; *distributed systems* make a set of networked computers appear as one big computer (like Google’s search engine); there are also *parallel systems*, such as graphic cards, which perform a huge number of primitive operations simultaneously, using a great number of small processing cores. - -### ~ - -The @boardname@ is a *reactive system* – it reacts continuously to external events, such as a person pressing the A button of the @boardname@ or shaking the device. The reaction to an event may be to perform a computation, update variables, and change the display. After the device reacts to an event, it is ready to react to the next one. If this sounds like a computer game, that’s because most computer games are reactive systems too! - -### Responsiveness - -We want reactive systems to be responsive, which means to react in a timely manner to events. For example, when you play a computer game, it’s frustrating if you press a button to make a character jump, but it doesn’t immediately jump. A delay in reacting, or lack of responsiveness , can be the difference between life and death, both in the real and virtual worlds. - -Let’s consider a simple example: you want to program your @boardname@ to accurately count the number of times the A button has been pressed and continuously display the current count on the 5x5 [LED screen](/device/screen). Because the LED screen is small, we can only display one digit of a number at a time on it. The [show number](/reference/basic/show-number) function will scroll the digits of a number across the screen so you can read it. - -Let’s say that the current count is 42 and the number 42 is scrolling across the LED screen. This means there is some code executing to perform the scroll. So, what should happen if you press the A button during the scroll? It would be a bad idea to ignore the button press, so some code should record the occurrence of the button press. But we just said there already is code running in order to scroll the number 42! If we wait until the code scrolling the 42 has finished to look for a button press, we will miss the button press. We want to avoid this sort of unresponsiveness. - -### Concurrency - -To be responsive, a reactive system needs to be able to do several things at the same time (concurrently), just like you can. But the @boardname@ only has one CPU for executing your program, which means it can only execute one program instruction at a time. On the other hand, it can execute millions of instructions in a single second. This points the way to a solution. - -Think about how a motion picture projector works - it projects only 24 frames per second, yet this is good enough to provide the illusion of fluid motion on the screen. The @boardname@ can execute millions of instructions per second, so it seems quite possible for the device to both to smoothly scroll the number 42 across the LED screen while looking for button presses and counting them. - -Let’s think about three sequences of instructions: - -* Sequence S1 contains the instructions (let’s say several hundred thousand or so) that scroll the number 42 across the LED screen; -* Sequence S2 contains a few instructions to check if button A is pressed; -* Sequence S3 contains a few instructions to increment a counter. - -In order to be responsive, we would like to *interrupt* the execution of sequence S1 *periodically* to execute the sequence S2, which will check if button A is pressed, which looks like: - -![](/static/mb/device/reactive-0.png) - -The result is that it takes sequence S1 a little longer to complete, due to the interruptions to execute sequence S2, but we are checking often enough to detect a press of button A . When S2 detects a press of button A, then the sequence S3 can be executed before S1 resumes: - -![](/static/mb/device/reactive-1.png) - -As we’ll soon see, there are other choices for how the sequences can be ordered to achieve the desired result. - -### The @boardname@ scheduler and queuing up subprograms - -The @boardname@’s *scheduler* provides the capability to concurrently execute different code sequences, relieving us of a lot of low-level programming. In fact, scheduling is so useful that it is a part of every *operating system*! - -The first job of the scheduler is to allow multiple *subprograms* to be queued up for later execution . For our purposes, a subprogram is just a statement or sequence of statements in the context of a larger program. Consider the Touch Develop program below for counting button presses. - -``` -export function countButtonPresses() { - let count = 0 - input.onButtonPressed(Button.A, () => { - count = count + 1 - }) - basic.forever(() => { - basic.showNumber(count, 150) - }) -} -``` - -The program above contains three statements that execute in order from top to bottom. The first statement - -``` -let count1 = 0 -``` - -initializesthe variable `count`. The second statement - -``` -input.onButtonPressed(Button.A, () => { - count1 = count1 + 1 -}) -``` - -informs the scheduler that on each and every event of the A button being pressed, a subprogram (called the event handler) should be queued for execution. The event handler is demarcated by the do/end keywords; it increments the variable `count` by one. The second statement - -``` -basic.forever(() => { - basic.showNumber(count1, 150) -}) -``` - -queues a `forever` loop for later execution by the scheduler; the body of this loop (between the do/end keywords) displays the current value of variable `count` on the LED screen. - -The function ends after the execution of these three statements, but this is not the end of program execution! That’s because the function queued the `forever` loop for execution by the scheduler. - -The second job of the scheduler is to periodically interrupt execution to read (poll) the various inputs to the @boardname@ (the buttons, pins, etc.) and fire off events (such as “button A pressed”). Recall that the firing of an event causes the event handler subprogram associated with that event to be queued for later execution. The scheduler uses a timer built into the @boardname@ hardware to interrupt execution every 6 milliseconds and poll the inputs, which is more than fast enough to catch the quickest press of a button. - -### Cooperative passing of control - -How does the forever loop get to start execution? Furthermore, once the forever loop is running, how does any other subprogram (like the event handler that increments the count) ever get a chance to execute? - -The answer is “cooperation” and “passing”. Think of a football team doing a drill – there is one ball and each footballer gets to dribble the ball for a certain number of touches, after which they pass to another footballer. A footballer who never passes prevents all other footballers from dribbling. A cooperative footballer always passes to some other footballer after taking a few touches. - -If you hadn’t guessed already, a footballer represents subprogram and dribbling the ball corresponds to that subprogram executing. Only one subprogram gets to execute at a time, as there is only one ball (processor). Footballer Alice passing the ball to footballer Bob corresponds to stopping execution of Alice’s subprogram (and remembering where it stopped) and starting/resuming execution of Bob’s subprogram. - -We will call this “passing control of execution” rather than “passing the ball”. However, in the world of the @boardname@, the concurrently executing subprograms are not aware of each other, so they don’t actually pass control directly to one another. Rather they pass control of execution back to the scheduler and the scheduler determines the subprogram to pass control to next. The programmer inserts a call to the `pause` function to indicate a point in the subprogram where control of execution passes to the scheduler. Also, when a subprogram ends execution, control passes to the scheduler. - -Let’s take a look at the implementation of the `forever` statement to see an example of cooperative scheduling: - -![](/static/mb/device/reactive-2.png) - -The `forever` loop actually is a function that takes a subprogram (an *Action* in Touch Develop) as a parameter. The function uses the `control -> in background` function of the @boardname@ runtime to queue a `while true` loop for execution by the scheduler. The while loop has two statements. The first statement runs the subprogram represented by the `body` parameter. The second statement passes control to the scheduler (requesting to “sleep” for 20 milliseconds). - -Though the `while true` loop will repeatedly execute the body subprogram, between each execution of the body it will permit the scheduler to execute other subprograms. If the while loop did not contain the call to `pause`, then once control passed into the while loop, it would never pass back to the scheduler and no other subprogram would be able to execute (unless the body subprogram contained a call to `pause` itself). - -### Round-robin scheduling - -Now, we come to the third and final job of the scheduler, which is to determine which subprogram to pass control to next. The scheduler uses two queues to perform this task, the sleep queue and the run queue. The sleep queue contains the subprograms that have called the pause function and still have time left to sleep. The run queue contains all the non-sleeping subprograms, such as the event handlers queued by the firing of an event. - -The scheduler moves the subprogram that has just paused into the sleep queue and then removes the subprogram at the head of the run queue and resumes its execution. Once a subprogram’s sleep period is over, the scheduler moves it from the sleep queue to the back of the run queue. - -The property of such round-robin scheduling is that under the assumption that every subprogram periodically enters the sleep queue, then every subprogram will periodically get a chance to execute. - -### Putting it all together - -Let’s go back to the `count button presses` function and revisit its execution based on what we have learned about the @boardname@ scheduler. As detailed before, the function executes three steps to: (1) initialize the variable `count` to zero; (2) set up the event handler for each press of button A; (3) queue the forever loop to the run queue. - -The function then ends execution and control passes back to the scheduler. Let’s assume the user has not pressed any buttons . The scheduler finds the `forever` loop in the run queue and passes control to it. The loop first calls `basic -> show number(0,150)`. In the diagram below, we use “Show 0” to refer to the execution of this function: - -![](/static/mb/device/reactive-3.png) - -While "Show 0" (the blue sequence) is running, periodic interrupts by the scheduler (every 6 milliseconds) poll for button presses and queue an event handler for each press of button A. Let’s say that one button press takes place during this time, as shown above. This will cause an event handler (labelled “inc”) to be queued for later execution by the scheduler. Once the "Show 0" has completed, the loop then calls `basic -> pause(20)` to put the forever loop to sleep for 20 milliseconds and give the scheduler an opportunity to run any newly queued event handler. Control passes to the “inc” event handler which will increment the variable `count` from 0 to 1 and then complete, returning control to the scheduler. At some point, the `forever` loop moves from the sleep queue to the run queue; the `forever` loop then will resume and call `basic -> show number(1,150)`. - -### Final thoughts - -Through this example, we have seen that the @boardname@ scheduler enables you to create a program that is composed of concurrent subprograms. In essence, the programmer needs to only think about the concurrent subprograms cooperatively passing control back to the scheduler, making sure no subprogram hogs control (or “dribbles the ball without passing”) for too long. While a subprogram runs, the scheduler polls the buttons and other IO peripherals at a high frequency in order to fire off events and queue event handlers for later execution, but this is invisible to the programmer. - -As a result, you can easily add a new capability to the @boardname@ by just adding a new subprogram. For example, if you want to add a reset feature to the counter program, all you need to do is add a new event handler for a press of button B that sets the global variable "count" to zero, as shown below: - -``` -export function countButtonPressesWithReset() { - let count = 0 - input.onButtonPressed(Button.A, () => { - count = count + 1 - }) - basic.forever(() => { - basic.showNumber(count, 150) - }) - input.onButtonPressed(Button.B, () => { - count = 0 - }) -} -``` - diff --git a/olddocs/js/return.md b/olddocs/js/return.md deleted file mode 100644 index a0bf5740..00000000 --- a/olddocs/js/return.md +++ /dev/null @@ -1,49 +0,0 @@ -# Return - -Exit a function. - -### @parent javascript/statement - - -The return statement exits a [function](/js/function) and returns a value to the code that called the function. - -### Touch Develop syntax - -return *expression* - -### Square function - -``` -/** - * // return the value x * x - * @param x TODO - */ -export function square(x: number) : number { - let result: number - return x * x - return result -} -``` - -### The type of *expression* - -The type of *expression* should match the declared return type of the function; in the above example, the return type is Number and we see that the return expression `x * x` is a Number since the input parameter `x` is a Number. - -### Storing the returned value - -The following code calls the `square` function with the number 42 and stores the output parameter in the `result` variable: - -``` -let result1 = square(42) -``` - -`result` is the default variable name for the function output, as specified in the function - -### Lessons - -[transformers](/lessons/transformers) - -### See also - -[function](/js/function), [calling functions](/js/call), [function parameters](/js/functionparameters) - diff --git a/olddocs/js/scriptid.md b/olddocs/js/scriptid.md deleted file mode 100644 index 2b8a5201..00000000 --- a/olddocs/js/scriptid.md +++ /dev/null @@ -1,31 +0,0 @@ -# script id - -What is the script id? #docs - -### @parent javascript/contents - - -the *script id* is a unique identifier that is given to each [published](/js/publishing) script. This way you can share your scripts with other people. - -### where can I find the script id? - -when your looking at your list of scripts (**My Scripts** area), the *script id* is displayed under the author name (it begins with a forward slash: /). - -TODO Diagram - -the script id in the example above is `/tuxi`. - -### search by script id - -you can type the script id directly into the search in the hub to find it. - -### sharing your scripts - -when you [publish a script](/js/publishing), you can copy the url (which includes the script id) and send it to people. - -if you forget to copy the url when you publish, there's also a `share` button in [script options](/js/editor). - -### see also - -[publish a script](/js/publishing) - diff --git a/olddocs/js/senses.md b/olddocs/js/senses.md deleted file mode 100644 index b716ef95..00000000 --- a/olddocs/js/senses.md +++ /dev/null @@ -1,46 +0,0 @@ -# @boardname@ senses - -A #microbit library that exposes orientation and movement events. - -A library that exposes orientation and movement events. - -* detect that the screen is facing up and the board is horizontal - -``` -onScreenUp(() => { - micro_bit.showString("screen up", 100) -}) -``` - -* detect that the screen is facing down and the board is horizontal - -``` -onScreenDown(() => { - micro_bit.showString("screen down", 100) -}) -``` - -* detect when the logo is up and the board is vertical - -``` -onLogoUp(() => { - micro_bit.showString("logo up", 100) -}) -``` - -* detect when the logo is down and the board is vertical - -``` -onLogoDown(() => { - micro_bit.showString("r", 100) -}) -``` - -* detect that the device is shaken - -``` -onShake(() => { - micro_bit.showString("shake", 100) -}) -``` - diff --git a/olddocs/js/serial-library.md b/olddocs/js/serial-library.md deleted file mode 100644 index 9b2789e0..00000000 --- a/olddocs/js/serial-library.md +++ /dev/null @@ -1,128 +0,0 @@ -# Serial Library - -The serial library #docs - -The **serial library** supports [serial communication](https://en.wikipedia.org/wiki/Serial_port) between the @boardname@ and another computer. Basically, this allows you to send data from the @boardname@ to your own computer. This is very useful for debugging purposes: you can add `write line` statements in your code and see them display on your computer as the program executes. - -The code below shows a simple script that sends a line when the @boardname@ starts and another line each time the button ``A`` is pressed. - -``` -serial.writeLine("started...") -input.onButtonPressed(Button.A, () => { - serial.writeLine("A pressed") -}) -``` - -## How to read the @boardname@'s serial output from your computer - -Unfortunately, using the serial library requires quite a bit of a setup. - -### Windows - -You must install a device driver (for the computer to recognize the serial interface of the @boardname@); then, you must also install a terminal emulator (which is going to connect to the @boardname@ and read its output). Here's how to do it: - -* Follow instructions at https://developer.mbed.org/handbook/Windows-serial-configuration in order to install the device driver -* Install a terminal emulator; we recommend [Tera Term](https://ttssh2.osdn.jp/index.html.en). At the time of this writing, the latest version is 4.88 and can be downloaded [from here](http://en.osdn.jp/frs/redir.php?m=jaist&f=%2Fttssh2%2F63767%2Fteraterm-4.88.exe). Follow the instructions from the installer. - -Once both the driver and the terminal emulator are installed, plug in the @boardname@ and wait until the device is fully setup. Then, open TeraTerm. - -* Hit `File` > `New Connection` -* Check "Serial"; in the dropdown menu, pick the COM port that says "mbed Serial Port". Hit `Ok`. -* In the menus, hit `Setup` > `Serial Port` and set the baud rate to `115200`. - -You should be good. Feel free to hit `Setup` > `Save Setup` in the menus to erase the default configuration file with a new one so that you don't have to type in the settings again. - -Please note that Windows will assign you a different COM port if you plug in another @boardname@. If you're juggling between @boardname@s, you'll have to change the COM port every time. - -### Alternative Windows setup with Putty - -If you prefer another terminal emulator (such as [PuTTY](http://www.putty.org/)), here are some instructions. - -* Open Windows's [Device Manager](https://windows.microsoft.com/en-us/windows/open-device-manager); expand the section called "Ports (COM & LPT)"; write down the com number for "mbed Serial Port" (e.g. COM14) -* Open PuTTY; on the main screen, use the following settings: Serial / COM14 / 115200. Replace COM14 with the COM port number you wrote down previously. Feel free to type in a name and hit "Save" to remember this configuration. - -![](/static/mb/serial-library-0.png) - -* (optional): in the "Terminal" section, check "implicit cr in every lf" - -![](/static/mb/serial-library-1.png) - -### Linux - -(Untested). - -* Plug in the @boardname@ -* Open a terminal -* `dmesg | tail` will show you which `/dev/` node the @boardname@ was assigned (e.g. `/dev/ttyUSB0`) -* Then, do: `screen /dev/ttyUSB0 115200` (install the `screen` program if you don't have it). To exit, run `Ctrl-A` `Ctrl-D`. - -Alternative programs include minicom, etc. - -### Mac OS - -* Plug in the @boardname@ -* Open a terminal -* `ls /dev/cu.*` will return to you a list of serial devices; one of them will look like `/dev/cu.usbmodem1422` (the exact number depends on your computer) -* `screen /dev/cu.usbmodem1422 115200` will open up the @boardname@'s serial output. To exit, hit `Ctrl-A` `Ctrl-D`. - -## Using the serial library in your programs - -If the ``serial`` button is not available, you will need first to add the ``@boardname@ serial`` library to your script: - -* tap on `add new` -* tap on `library` -* select `@boardname@ serial` - -### Writing data - -This is basically what you will use the serial library for: debugging purposes. - -* write a number - -``` -serial.writeNumber(42) -``` - -* write a string - -``` -serial.writeString("hello") -``` - -* write a line of text - -``` -serial.writeLine("this is a line") -``` - -Theoretically, you can dump more sophisticated data and then read it back in the event that two @boardname@s should be connected to each other over serial. We have not tested this scenario yet as we have yet to expose functionality that allows re-routing the serial ports to the edge connector. - -* write an image - -``` -let img = images.createImage(` -. . . . . -. # . # . -. . . . . -. . . . . -# # # # # -`) -serial.writeImage(img) -``` - -* write the current screen LED status - -``` -serial.writeScreen() -``` - -### Reading data - -This is useful if you have something connected at the other end. As explained above, this is not yet a scenario. - -* reads a line of text - -``` -let msg = serial.readString() -``` - diff --git a/olddocs/js/showcase.md b/olddocs/js/showcase.md deleted file mode 100644 index 18a26319..00000000 --- a/olddocs/js/showcase.md +++ /dev/null @@ -1,16 +0,0 @@ -# Showcase Scripts - -#docs - -## Get Started with These Hex Files! - -If you have a @boardname@ and would like to explore a few scripts, we've created the following hex files for you to copy to your @boardname@ - -### Flashing Heart - -This script introduces you to the LED display: - -* {hex:xzlzgl:hex file} -MACRO: hex* [Block Editor script](/jxislh) -* [Touch Develop script](/xzlzgl) - diff --git a/olddocs/js/simulator.md b/olddocs/js/simulator.md deleted file mode 100644 index 995e063c..00000000 --- a/olddocs/js/simulator.md +++ /dev/null @@ -1,44 +0,0 @@ -# Run Code in your Browser - -Run scripts in a web browser. - -While you're writing and testing your scripts, you'll mostly be running scripts in your browser by clicking the `run` button. Both the [Microsoft Block editor](/blocks/editor) and the [Touch Develop editor](/js/editor) have a `run` button above the coding area. - -*Note*: in the Touch Develop editor, the button actually is named `run main`, reflecting the fact that execution of a Touch Develop script always beings in the `main` function - -When you click `run main` in the Touch Develop editor, your code executes and the results are simulated on-screen, using an image of the @boardname@ device, like this: - - -In the picture above, [plot image](/reference/led/plot-image) create a heart image that appears on the @boardname@ simulator. - -The @boardname@ simulator let's you... - -* write and test code, even if you don't have a @boardname@ device -* test your code throughly before downloading and running your script on the @boardname@ - -### What does the simulator support? - -The @boardname@ simulator supports the Touch Develop [functions](/js/contents) and Microsoft [blocks](/blocks/contents), including those related to the LED screen, input buttons, the compass, accelerometer, and the digital I/O pins. - -* **LED screen**: the [LED screen](/device/screen) that appears on-screen shows you what you'll see on the @boardname@ device -* **input buttons**: when running code with [button is pressed](/reference/input/button-is-pressed) or [on button pressed](/reference/input/on-button-pressed) functions, click the on-screen A or B button -* **compass**: when running code that includes [compass heading](/reference/input/compass-heading), click and drag the on-screen compass needle to change the heading -* **accelerometer**: move your mouse over the on-screen @boardname@ device to simulate [acceleration](/reference/input/acceleration). The x and y axis values are shown on-screen. -* **digital pins**: you can click the on-screen digital pins (0 , 1, or 2) to turn them on or off (see [digital write pin](/reference/pins/digital-write-pin) and [digital read pin](/reference/pins/digital-read-pin) for more info). - -**Can't see the red LEDs on the simulator?** - -If you click on the white THEME button in the top right corner of the simulator, it will switch to an accessible version of the simulator, where the LEDs are displayed in blue on a white background. - -### All done? - -Once you're done writing and testing your code on the simulator, compile and run your script on your @boardname@ device. To find out how to do this, see [run scripts on the @boardname@](/device/usb). - -### Simulator vs @boardname@ - -Running your scripts in a web browser is a *simulation* of how your code will run on the @boardname@ device. When you run your script on your @boardname@ device, the results may differ slightly. For example, the timing may be subtly different when your script runs on the @boardname@ device (you may need to adjust your [pause](/reference/basic/pause) functions). For this reason, be sure to test your scripts on the @boardname@ device. - -### See also - -[run scripts on the @boardname@](/device/usb), [Microsoft Block editor](/blocks/editor), [Touch Develop editor](/js/editor) - diff --git a/olddocs/js/statements.md b/olddocs/js/statements.md deleted file mode 100644 index cad30e4a..00000000 --- a/olddocs/js/statements.md +++ /dev/null @@ -1,41 +0,0 @@ -# statements, operators, and libaries - -Statements, operators, and libraries. - -### @parent javascript/language - - -TouchDevelop functions include statements and operators. - -### Statements - -TouchDevelop statements include: - -* [break](/js/break), to exit a loop before it has completed, usually used in conjunction with an [if](/reference/logic/if) statement -* [if](/reference/logic/if) conditional statement -* [for](/reference/loops/for) and [while](/js/while) loops -* [function](/js/function) -* [return](/js/return) -* [var](/reference/variables/var) (local variable declaration) - -### Operators - -TouchDevelop operators include: - -* [assignment operator](/reference/variables/assign) `:=` (to update variables) -* arithmetic operators (`+`, `-`, `*`, `/`, mod) operate on [Numbers](/types/number) -* comparison operators (such as `>`, `=`) operate on [Numbers](/types/number) -* boolean operators (`not`, `or`, `and`) operate on [Booleans](/types/boolean) -* concat operator combines [Strings](/types/string) - -### Libraries - -Libraries provide additional functions: - -* the [@boardname@ library](/js/contents) -* the [math](/js/math) and [bits](/js/bits) libraries - -### see also - -[TouchDevelop Documentation](/js/contents), [comments](/js/comment) - diff --git a/olddocs/js/string-functions.md b/olddocs/js/string-functions.md deleted file mode 100644 index 6691aeca..00000000 --- a/olddocs/js/string-functions.md +++ /dev/null @@ -1,178 +0,0 @@ -# String Functions - -string-related functions. - -### @parent javascript/language - -The following string related functions are available in Touch Develop for the @boardname@: - -* **equals** - find out if two strings are the same -* **at** - get a character within a string -* **concat** - combine two strings -* **count** - get the number of characters in a string -* **substring** - get a portion of a string -* **to character code** - converts a character into a character code -* **to number** - converts a string into a number - -Select a string variable in the [Touch Develop editor](/js/editor) to see the following string functions: - -``` -/* placeholder */ -``` - -### ~hide - -``` -let str = "hi" -``` - -### ~ - -### equals - -find out if two strings are the same - -#### Syntax - -[String](/types/string) `->` **equals** (other : [String](/types/string)) *returns* [Boolean](/types/boolean) - -#### Parameters - -* other - [String](/types/string); a string - -#### Example - -the following code does something if `str` = "Hi": - -``` -if (str == "Hi") { - // add code to do something here -} -``` - -### at - -get a character within a string, using the specified index - -#### Syntax - -[String](/types/string) `->` **at** (index: [Number](/types/number)) *returns* [String](/types/string) - -#### Parameters - -* index- [Number](/types/number); the character number within a string (0 returns the first character) - -#### Example - -The following code gets the first character from the `str` string and stores it in the `first char` variable: - -``` -let firstChar = str[0] -``` - -### The `||` operator - -To combine two strings you can use the string concatenation operation `||` as shown below: - -``` -let s = "abc" + "def" -let evaluatesToTrue = s == "abcdef" -``` - -NOTE: position the cursor outside of the string quotes, right after the string, for the || operator to appear in the keyboard. - -### concat - -combine two strings; like the concat operator (`||`) - -#### Syntax - -[String](/types/string) `->` **concat** (other : [String](/types/string)) *returns* [String](/types/string) - -#### Parameters - -* other- [String](/types/string); a string - -#### Example - -The following code combines two strings and displays the string on screen: - -``` -str = "Hi " -str = str.concat("there") -basic.showString(str, 100) -``` - -### count - -get the number of characters in a string - -#### Syntax - -[String](/types/string) `->` **count** *returns* [Number](/types/number) - -#### Example - -The following example gets the length of the `str` variable and stores it in the `x` variable: - -``` -let x = str.length -``` - -### Substring - -get a portion of a string, using a starting point and length - -#### Syntax - -[String](/types/string) `->` **substring** (start : [Number](/types/number), length : [Number](/types/number)) *returns* [String](/types/string) - -#### Parameters - -* start - [Number](/types/number); the starting character number (0 is the first character number in a string) -* length - [Number](/types/number); the string length - -#### Example - -The following code gets characters 6, 7, and 8 from the `str` string: - -``` -let asubstring = str.substr(5, 3) -``` - -### to character code - -converts the first character of a string into a character code number (unicode) - -#### Syntax - -[String](/types/string) `->` **to character code** *returns* [Number](/types/number) - -#### Example - -The following code converts the first character of `str` into a character code and stores the code in `x`: - -``` -x = str.toCharacterCode() -``` - -### to number - -converts a string into a number - -#### Syntax - -[String](/types/string) `->` **to number** *returns* [Number](/types/number) - -#### Example - -The following code converts `str` into a number and stores it in `x`: - -``` -x = parseFloat(str) -``` - -### See also - -[string](/types/string), [number](/types/number), [show string](/reference/basic/show-string) - diff --git a/olddocs/js/string.md b/olddocs/js/string.md deleted file mode 100644 index f13bd4a6..00000000 --- a/olddocs/js/string.md +++ /dev/null @@ -1,60 +0,0 @@ -# String - -a piece of text. - -### @parent javascript/language - -A *String* is a sequence of characters. For the @boardname@, ASCII character codes 32 to 126 are supported; letters, digits, punctuation marks, and a few symbols. All other character codes appear as a ? on the [LED screen](/device/screen). - -### Declare a string - -Use the [var statement](/reference/variables/var) and the [assignment operator](/reference/variables/assign) `:=` to declare a new *local* string variable. Like this: - -``` -let str = "this is a string" -``` - -To declare a string using the [Touch Develop editor](/js/editor): - -1. Click `var` (on the Code Keyboard). - -2. Type a name for your new string variable. - -2. Click on the right side of the `:=` operator. - -3. Type `"` (or click `"abc"`) and then type a string like `hello`. - -4. Click the check mark. - -Your code should look something like this: - -``` -let salutation = "Hello" -``` - -### The function `show string` - -Use [show string](/reference/basic/show-string) to display a string on the [LED screen](/device/screen). If the string is multiple characters, the string scrolls right to left. The following example displays `Hello world!` on the @boardname@ screen: - -``` -basic.showString("Hello world!", 100) -``` - -The first parameter of `show string` specifies the string, and the second parameter specifies the number of milliseconds between scrolling by one LED column - the larger the value, the slower the scroll will be. - -### More string functions - -Want to compare or concatenate strings? Check out the [string functions](/types/string-functions). - -### Global string variables - -Unlike [local variables](/reference/variables/var), global variables are accessible across functions and in nested code blocks. To find out how to declare a global string variable, see [global variables](/js/data). - -### Lessons - -[letter up](/lessons/letter-up) - -### See also - -[local variables](/reference/variables/var), [global variables](/js/data), [string functions](/types/string-functions), [Number](/types/number), [show string](/reference/basic/show-string) - diff --git a/olddocs/js/types.md b/olddocs/js/types.md deleted file mode 100644 index 43dde520..00000000 --- a/olddocs/js/types.md +++ /dev/null @@ -1,19 +0,0 @@ -# types - -Touch Develop types. - -### @parent language - - -A *type* refers to a class of data and the operations permitted on that data. The following types are supported by Touch Develop for the @boardname@: - -* **[String](/types/string)**: a sequence of characters -* **[Number](/types/number)**: an integer number (32-bit signed) -* **[Boolean](/types/boolean)**: true or false -* **[Image](/reference/image/image)**: a collection of [@boardname@ LED states](/device/screen) (on/off) -* *more types coming!!!* - -### see also - -[local variables](/reference/variables/var), [global variables](/js/data), [assignment operator](/reference/variables/assign) - diff --git a/olddocs/js/var.md b/olddocs/js/var.md deleted file mode 100644 index b2cd46c7..00000000 --- a/olddocs/js/var.md +++ /dev/null @@ -1,108 +0,0 @@ -# Local Variables - -How to define and use local variables. - -### @parent language - - -A variable is a place where you can store and retrieve data. Variables have a name, a [type](/js/types), and value: - -* *name* is how you'll refer to the variable -* *type* refers to the kind of data a variable can store -* *value* refers to what's stored in the variable - -### `var` and `let` statement - -The ``var`` keyword declares a global variables that is defined within the entire scope of the function. -The ``let`` keyword defined a block-scoped variable, similarly to other languages like Java, C# or C. - -For example, this code stores the number `2` in the `num1` variable: - -* number variable -```blocks -let num1 = 2 -``` - -* string variable -```blocks -let name = "Mike" -``` - -* boolean variable - -```blocks -let bool = true -``` - -* image variable -```blocks -let img = images.createImage(` -. . # . . -. # # # . -# # # # # -. # # # . -. . # . . -`) -``` - -See [Image](/reference/image/image) for info on creating and using image variables. -### Using variables - -Once you've defined a variable, just use the variable's name whenever you need what's stored in the variable. For example, the following code shows the value stored in `counter` on the LED screen: - -``` -let counter = 5; -basic.showNumber(counter, 100) -``` - -To change the contents of a variable use the assignment operator `:=`. The following code sets `counter` to 1 and then increments `counter` by 10: - -``` -let counter = 0; -counter = 1 -counter = counter + 10 -``` - -### Why use variables? - -Variables help simplify your code. For example, instead of turning on LEDs one by one like this: - -``` -led.plot(0, 0) -led.plot(1, 1) -led.plot(2, 2) -led.plot(3, 3) -led.plot(4, 4) -``` - -You can use a variable (`i`) and a [for loop](/reference/loops/for) to plot the same series of points (`i` is incremented by 1, each time the loop repeats): - -``` -for (let i = 0; i < 5; i++) { - led.plot(i, i) -} -``` - -### Local vs global variables - -Local variables exist only within the function or block of code where they're defined. Local variables don't exist outside of where they're defined. For example: - -``` -if (led.brightness() > 127) { - let y = 1 - // `y` variable exists here -} else { - // `y` variable does not exist here -} -``` - -Use **global variables** when you need to access a variable in nested code blocks or across multiple functions. - -### Lessons - -[guess the number](/lessons/guess-the-number), [digi yoyo](/lessons/digi-yoyo), [rock paper scissors](/lessons/rock-paper-scissors), [love meter](/lessons/love-meter) - -### See also - -[types](/types), [assignment operator](/reference/variables/assign) - diff --git a/olddocs/js/while.md b/olddocs/js/while.md deleted file mode 100644 index 0c8750ed..00000000 --- a/olddocs/js/while.md +++ /dev/null @@ -1,73 +0,0 @@ -# While - -Repeat code in a loop while a condition is true. - -### @parent javascript/language - - -Repeat code while a [Boolean](/types/boolean) `condition` is true. - -### ~hide - -``` -let condition = false -``` - -### ~ - -### Block Editor - - -### Touch Develop - -``` -while (condition) { - // This code runs if `condition` is `true` -} -``` - -The while loop has a *condition* that evaluates to a [Boolean](/types/boolean) value. After the `do` keyword, add the code that you want to run while the `condition` is `true`. The while loop concludes with `end while`. - -The condition is tested before any code runs. Which means that if the condition is false, the code inside the loop doesn't execute. Use the [break statement](/js/break) to exit a while loop before it's complete. - -### Example: diagonal line - -The following example uses a while loop to make a diagonal line on the LED screen (points `0, 0`, `1, 1`, `2, 2`, `3, 3`, `4, 4`). - -// index is set to 4 - -``` -let index = 4 -while (index >= 0) { - led.plot(index, index) - // // subtract 1 from `index` each time through loop - index = index - 1 -} -``` - -### Example: count until A button pressed - -The following example shows numbers on the screen(0, 1, 2, 3...), until the "A" button is pressed. - -``` -let x = 0 -while (true) { - basic.showNumber(x, 100) - let pressed = input.buttonIsPressed("A") - if (pressed) { - break - } else { - x = x + 1 - } - basic.pause(1000) -} -``` - -### Lessons - -[rotation animation](/lessons/rotation-animation), [digi yoyo](/lessons/digi-yoyo) - -### See also - -[on button pressed](/reference/input/on-button-pressed), [for](/reference/loops/for), [if](/reference/logic/if), [break](/js/break), [forever](/reference/basic/forever), [in background](/reference/control/in-background) -