PencilCoder

Add Text!

Goals:

  • Learn about Strings, another of the seven Javascript data types
  • Add text output (letters and other symbols) to your Pencil Code programs using the label function.

Coding Snippets:

  • coding snippets
  • label is a sprite-specific function. It takes an argument of type String and prints it on screen at the sprite's current location.
  • Change the size of a label using an optional numeric second argument.

Math and Computer Concepts:

  • To create a String, enclose characters in matching sets of single or double quotes, e.g., 'a blue string' or "blue".
  • In the coding snippet above, myWords is a user-defined variable that references (i.e., points to) a string. Many build-in variables we have used all along actually point to strings. For example, the variable blue points to the string "blue".
  • Coding ExampleYou can join two strings using +, an operation referred to as concatenation. In the example to the right, the variable c references the string "PencilCode".
  • Labels appear on top of other graphics, including sprites. E.g.:

Activities:

Save each of the following in a folder called Text.