Skip to content

Commit 3fa81c6

Browse files
committed
Put pseudo-JSON literals at the start of code snippets
1 parent df185ed commit 3fa81c6

29 files changed

+439
-954
lines changed

00_intro.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ In the
166166
beginning, at the birth of computing, there were no programming
167167
languages. Programs looked something like this:
168168

169-
```null
169+
```{lang: null}
170170
00110001 00000000 00000000
171171
00110001 00000001 00000001
172172
00110011 00000001 00000010
@@ -202,7 +202,7 @@ something in terms of job satisfaction.
202202
Each line of the previous program contains a
203203
single instruction. It could be written in English like this:
204204

205-
```text/plain
205+
```{lang: "text/plain"}
206206
1. Store the number 0 in memory location 0.
207207
2. Store the number 1 in memory location 1.
208208
3. Store the value of memory location 1 in memory location 2.
@@ -222,7 +222,7 @@ more readable than the soup of bits, it is still rather unpleasant. It
222222
might help to use names instead of numbers for the instructions and
223223
memory locations.
224224

225-
```text/plain
225+
```{lang: "text/plain"}
226226
Set “total” to 0.
227227
Set “count” to 1.
228228
[loop]
@@ -291,9 +291,7 @@ operations `range` and `sum` available, which respectively create a
291291
((collection)) of numbers within a range and compute the sum of a
292292
collection of numbers:
293293

294-
{{startCode}}
295-
296-
```
294+
```{startCode: true}
297295
console.log(sum(range(1, 10)));
298296
// → 55
299297
```

01_values.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ have only 2, and the weight of each increases by a factor of 2 from
3737
right to left. Here are the bits that make up the number 13, with the
3838
weights of the digits shown below them:
3939

40-
```null
40+
```{lang: null}
4141
0 0 0 0 1 1 0 1
4242
128 64 32 16 8 4 2 1
4343
```
@@ -287,7 +287,7 @@ backslash means a ((tab character)). Take the following string:
287287

288288
The actual text contained is this:
289289

290-
```null
290+
```{lang: null}
291291
This is the first line
292292
And this is the second
293293
```

02_program_structure.md

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ officially not allowed to be used as variable names, though some
198198
JavaScript environments do allow them. The full list of keywords and
199199
reserved words is rather long.
200200

201-
```text/plain
201+
```{lang: "text/plain"}
202202
break case catch class const continue debugger
203203
default delete do else enum export extends false
204204
finally for function if implements import in
@@ -749,17 +749,13 @@ Especially
749749
when looping, a program often needs to “update” a variable to hold a
750750
value based on that variable's previous value.
751751

752-
{{test no}}
753-
754-
```
752+
```{test: no}
755753
counter = counter + 1;
756754
```
757755

758756
JavaScript provides a shortcut for this:
759757

760-
{{test no}}
761-
762-
```
758+
```{test: no}
763759
counter += 1;
764760
```
765761

@@ -784,9 +780,7 @@ For `counter += 1` and `counter -=
784780

785781
It is common for code to look like this:
786782

787-
{{test no}}
788-
789-
```
783+
```{test: no}
790784
if (variable == "value1") action1();
791785
else if (variable == "value2") action2();
792786
else if (variable == "value3") action3();
@@ -841,7 +835,7 @@ words to clearly describe what the variable represents. These are
841835
pretty much your choices for writing a variable name with several
842836
words in it:
843837

844-
```null
838+
```{lang: null}
845839
fuzzylittleturtle
846840
fuzzy_little_turtle
847841
FuzzyLittleTurtle
@@ -886,9 +880,7 @@ JavaScript has two ways of writing comments. To write a single-line
886880
comment, you can use two slash characters (`//`) and then the comment
887881
text after it.
888882

889-
{{test no}}
890-
891-
```
883+
```{test: no}
892884
var accountBalance = calculateBalance(account);
893885
// It's a green hollow where a river sings
894886
accountBalance.adjust();
@@ -964,7 +956,7 @@ headache.
964956
Write a ((loop)) that makes seven calls to
965957
`console.log` to output the following triangle:
966958

967-
```null
959+
```{lang: null}
968960
#
969961
##
970962
###
@@ -1069,7 +1061,7 @@ should form a chess board.
10691061

10701062
Passing this string to `console.log` should show something like this:
10711063

1072-
```null
1064+
```{lang: null}
10731065
# # # #
10741066
# # # #
10751067
# # # #

03_functions.md

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,7 @@ function value in a new place, pass it as an argument to a function,
275275
and so on. Similarly, a variable that holds a function is still just a
276276
regular variable and can be assigned a new value, like so:
277277

278-
{{test no}}
279-
280-
```
278+
```{test: no}
281279
var launchMissiles = function(value) {
282280
missileSystem.launch("now");
283281
};
@@ -380,7 +378,7 @@ line 4. The line after that calls `console.log` again.
380378

381379
We could show the flow of control schematically like this:
382380

383-
```null
381+
```{lang: null}
384382
top
385383
greet
386384
console.log
@@ -414,9 +412,7 @@ back-and-forth between two functions. Rather, it _would_ be infinite,
414412
if the computer had an infinite stack. As it is, we will run out of
415413
space, or “blow the stack”.
416414

417-
{{test no}}
418-
419-
```
415+
```{test: no}
420416
function chicken() {
421417
return egg();
422418
}
@@ -465,9 +461,7 @@ can be called either with two arguments or with a single argument, in
465461
which case the exponent is assumed to be two, and the function behaves
466462
like `square`.
467463

468-
{{test wrap}}
469-
470-
```
464+
```{test: wrap}
471465
function power(base, exponent) {
472466
if (exponent == undefined)
473467
exponent = 2;
@@ -589,9 +583,7 @@ _recursive_. Recursion allows some functions to be written in a
589583
different style. Take, for example, this alternative implementation of
590584
`power`:
591585

592-
{{test wrap}}
593-
594-
```
586+
```{test: wrap}
595587
function power(base, exponent) {
596588
if (exponent == 0)
597589
return 1;
@@ -730,7 +722,7 @@ To better understand how this function produces the
730722
effect we're looking for, let's look at all the calls to `find` that
731723
are made when searching for a solution for the number 13.
732724

733-
```null
725+
```{lang: null}
734726
find(1, "1")
735727
find(6, "(1 + 5)")
736728
find(11, "((1 + 5) + 5)")
@@ -794,7 +786,7 @@ the numbers of cows and chickens on a farm, with the words `Cows` and
794786
`Chickens` after them, and zeros padded before both numbers so that
795787
they are always three digits long.
796788

797-
```null
789+
```{lang: null}
798790
007 Cows
799791
011 Chickens
800792
```
@@ -993,9 +985,7 @@ takes two arguments and returns their minimum.
993985

994986
{{if interactive
995987

996-
{{test no}}
997-
998-
```
988+
```{test: no}
999989
// Your code here.
1000990
1001991
console.log(min(0, 10));
@@ -1047,9 +1037,7 @@ Why? Can you think of a way to fix this?
10471037

10481038
{{if interactive
10491039

1050-
{{test no}}
1051-
1052-
```
1040+
```{test: no}
10531041
// Your code here.
10541042
10551043
console.log(isEven(50));
@@ -1108,9 +1096,7 @@ Rewrite `countBs` to make use of this new function.
11081096

11091097
{{if interactive
11101098

1111-
{{test no}}
1112-
1113-
```
1099+
```{test: no}
11141100
// Your code here.
11151101
11161102
console.log(countBs("BBC"));

0 commit comments

Comments
 (0)