pxt-calliope/docs/js/call.md

42 lines
1.2 KiB
Markdown
Raw Normal View History

2016-06-28 19:35:31 +02:00
# Call a function
The simplest way to get started in JavaScript with your micro:bit is to
call one of the micro:bit's built-in JavaScript functions. Just like Blocks
are organized into categories/drawers, the micro:bit functions are organized by
namespaces. The `basic` namespace contains a number of very helpful
functions:
```typescript
basic.showString("Hello!")
```
If you want to see all functions available in a namespace, simply type `basic`
followed by `.`; a list of all the functions will appear.
2016-06-30 19:10:15 +02:00
![](/static/mb/js/basicFuns.png)
2016-06-28 19:35:31 +02:00
Continue typing to select one of the functions, or click on one of the functions
to select. You also narrow down the set of functions by typing, as below:
![](/static/mb/js/basicIntell.png)
# Function parameters
You might have noticed that the call `showString` above takes one value,
the string to be scrolled on the LED screen. There is a second (optional)
2016-07-02 16:18:39 +02:00
parameter that controls the speed of the scroll. Try this:
2016-06-28 19:35:31 +02:00
```typescript
basic.showString("Hello!",50)
```
2016-07-02 16:18:39 +02:00
If you don't give a value for an optional parameter, where does its value
come from? TBD.
2016-06-28 19:35:31 +02:00
You might have noticed that the function list above shows all
the available parameters for each function.
2016-07-02 16:18:39 +02:00
### ~button /js/sequence
NEXT: Sequencing Commands
### ~