Skip to content

Commit 8f4c73b

Browse files
Document using trailing commas
Signed-off-by: David A. Wheeler <[email protected]>
1 parent 37e62e8 commit 8f4c73b

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

docs/labs/create_checker.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@ The basic inputs are:
128128
The number of attempt fields (in the HTML), the number of `expected` values,
129129
and the number of `correct` values much match.
130130

131-
### JavaScript strings
131+
### JavaScript notation.
132132

133-
The lab data is expressed using JavaScript strings.
134-
There's more than one way to express a string in JavaScript, each
133+
The lab data is expressed using JavaScript, primarily as
134+
JavaScript strings.
135+
There's more than one way to express a string in JavaScript, and each
135136
has its advantages:
136137

137138
* "..." - double-quoted string. You don't need to do anything special to
@@ -148,6 +149,15 @@ has its advantages:
148149
These are often useful for patterns.
149150
Use ${BACKQUOTE} for &#96; and ${DOLLAR} for $.
150151

152+
JavaScript allows trailing commas, and we encourage using them.
153+
In other words,
154+
a list in JavaScript can have the form `[ 'a', 'b', 'c', ]`
155+
(note the trailing comma after `'c'`).
156+
Using trailing commas reduces the likelihood of
157+
a common error: forgetting to add a comma when you add an item to a list.
158+
Using trailing commas means that when you add a new item (`'d'`) at the end,
159+
you *already* have the comma ready for use.
160+
151161
### Expressing correct answer patterns
152162

153163
The patterns used for `correct` and `hints`
@@ -299,6 +309,8 @@ Here's an explanation of this pattern:
299309
This that one of the following patterns is allowed:
300310
`'id'` or `"id"` or <tt>&#96;id&#96</tt> (and nothing else).
301311
Again, the space after it means 0+ spaces are allowed.
312+
WARNING: If you use JavaScript raw strings or templates, you
313+
need to escape the backquote (&#96;) character.
302314

303315
5. The `\)` matches a literal close parenthesis,
304316
while `\.` matches a literal period.

0 commit comments

Comments
 (0)