GameSpark/Tutorials Open editor ↗
JavaScript · Lesson 3

Strings

A string is text — a name, a message, a label. You write it inside quotes: 'Spark' or 'Game Over'. Single or double quotes both work; just start and end with the same one.

1. Make and show text

let name = 'Spark';

function draw() {
  cls(1);
  print('Hello!', 8, 8, 10);
  print(name, 8, 20, 7);
}

2. Join strings with +

Between two strings, + glues them together — this is called concatenation. Build a bigger message from pieces:

let name = 'Spark';

function draw() {
  cls(1);
  print('Hi ' + name + '!', 8, 8, 10);
}
💡

Mind the spaces — they live inside the quotes. 'Hi ' + name keeps the space before the name; 'Hi' + name would print HiSpark.

3. Numbers become text automatically

When you + a string and a number, JavaScript turns the number into text so it can join. That is exactly why a score shows up when you glue it onto a label:

let score = 42;

function draw() {
  cls(1);
  print('Score: ' + score, 8, 8, 7);   // the number joins as text
}
⚠️

Watch out: because + joins whenever text is involved, '3' + 4 is the string '34', not 7. To add, keep both sides numbers; to show a number, joining it onto a label is exactly right.

You can also turn a number into text on purpose with String(n), but with print the automatic join usually does the job.

What you learned