Displays a string and/or variable values to the app screen. The text can also be formatted as HTML.
write() can be used as a debugging tool to help you understand what your code is doing. By displaying a message containing either descriptive text that tells you what is happening or the value of particular variables, you can follow along as your code executes. The user of your app will see the write() messages, so it can also be used to write large blocks of HTML formatted text to the screen instead of using textLabel()
.
Found a bug in the documentation? Let us know at documentation@code.org
Collect, count and display messages from friends.
// Collect, count and display messages from friends. textLabel("myTextLabel", "Type a message and press press enter"); textInput("myTextInput", ""); var count = 1; onEvent("myTextInput", "change", function(event) { var myText = getText("myTextInput"); write("Message #" + count + ": " + myText); setText("myTextInput", ""); count = count + 1; });
Creates a simple ticker tape calculator.
// Creates a simple ticker tape calculator. var total = 0; textInput("value","0"); write("<br>"); button("plus","+"); button("minus","-"); button("clear","clear"); write(total); onEvent("plus","click", function(event) { total += parseFloat(getText("value")); write(total); }); onEvent("minus","click", function(event) { total -= parseFloat(getText("value")); write(total); }); onEvent("clear", "click", function(event) { total = 0; write(total); });
// Let's you know your code is running. write("It's Alive!");
write(text)
Name | Type | Required? | Description |
---|---|---|---|
text | string | The message string and/or variable values to display to the app screen. |
No return value. Displays to the app screen only.
Found a bug in the documentation? Let us know at documentation@code.org