Skip to content

Commit c97b238

Browse files
committed
Add exercise sandbox and solution files
1 parent e4efeec commit c97b238

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1704
-40
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/tex/*
2-
/html/*.html
2+
/html/[01]*.html
3+
/html/js/exercise_data.js
34
/code/chapter/*
45
/node_modules
56
.tern-port

04_data.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,8 +1359,7 @@ console.log(deepEqual(obj, obj));
13591359
// → true
13601360
console.log(deepEqual(obj, {here: 1, object: 2}));
13611361
// → false
1362-
console.log(
1363-
deepEqual(obj, {here: {is: "an"}, object: 2}));
1362+
console.log(deepEqual(obj, {here: {is: "an"}, object: 2}));
13641363
// → true
13651364
----
13661365
endif::html_target[]

05_higher_order.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ ifdef::html_target[]
872872
----
873873
var arrays = [[1, 2, 3], [4, 5], [6]];
874874
// Your code here.
875-
// → [1, 2, 3, 4, 5, 6];
875+
// → [1, 2, 3, 4, 5, 6]
876876
----
877877
endif::html_target[]
878878

06_object.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ console.log(new Vector(1, 2).plus(new Vector(2, 3)));
10391039
// → Vector{x: 3, y: 5}
10401040
console.log(new Vector(1, 2).minus(new Vector(2, 3)));
10411041
// → Vector{x: -1, y: -1}
1042-
console.log(new Vector(3, 4).norm);
1042+
console.log(new Vector(3, 4).length);
10431043
// → 5
10441044
----
10451045
endif::html_target[]

07_elife.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,8 @@ local population booms or busts are less likely to wipe out a species
11261126
entirely, and there is space for the relatively large prey
11271127
population needed to sustain a small predator population.
11281128

1129+
ifdef::html_target[]
1130+
11291131
// test: no
11301132

11311133
[source,javascript]
@@ -1159,6 +1161,8 @@ animateWorld(new LifelikeWorld(
11591161
));
11601162
----
11611163

1164+
endif::html_target[]
1165+
11621166
!!solution!!
11631167

11641168
Many of the same tricks that worked for in the previous exercise also

08_error.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -792,9 +792,13 @@ withBoxUnlocked(function() {
792792
box.content.push("gold piece");
793793
});
794794

795-
withBoxUnlocked(function() {
796-
throw new Error("Pirates on the horizon! Abort!");
797-
});
795+
try {
796+
withBoxUnlocked(function() {
797+
throw new Error("Pirates on the horizon! Abort!");
798+
});
799+
} catch (e) {
800+
console.log("Error raised:", e);
801+
}
798802
console.log(box.locked);
799803
// → true
800804
----

09_regexp.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ endif::html_target[]
12141214
First, do not forget the backslash in front of the dot.
12151215

12161216
Matching the optional sign in front of the number, as well as in front
1217-
of the exponent, can be done with `[+\-]?` or `(+|-|)` (plus, minus,
1217+
of the exponent, can be done with `[+\-]?` or `(\+|-|)` (plus, minus,
12181218
or nothing).
12191219

12201220
The more complicated part of the exercise is the problem of

13_dom.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -946,7 +946,7 @@ the function.
946946

947947
!!solution!!
948948

949-
== Elements by tag name ==
949+
=== Elements by tag name ===
950950

951951
The `getElementsByTagName` method returns all child elements with a
952952
given tag name. Implement your own version of it, as a regular
@@ -1004,7 +1004,7 @@ own children.
10041004

10051005
!!solution!!
10061006

1007-
== The cat's hat ==
1007+
=== The cat's hat ===
10081008

10091009
Extend the spinning cat animation we defined earlier to have both the
10101010
cat and his hat (`<img src="img/hat.png">`) spin around, at opposite
@@ -1024,7 +1024,7 @@ ifdef::html_target[]
10241024
// test: no
10251025

10261026
[source,text/html]
1027-
-----
1027+
----
10281028
<img src="img/cat.png" id="cat" style="position: absolute">
10291029
<img src="img/hat.png" id="hat" style="position: absolute">
10301030

14_event.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ Only one piece of JavaScript program can run at a time. Thus, event
831831
handlers and other scheduled scripts have to wait until other scripts
832832
finish, before they get their turn.
833833

834-
== Excercises ==
834+
== Exercises ==
835835

836836
=== Censored keyboard ===
837837

17_http.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,8 @@ function fail() {
867867
all([soon(1), fail(), soon(3)]).then(function(array) {
868868
console.log("We should not get here");
869869
}, function(error) {
870-
console.log("Failed with:", error);
870+
if (error.message != "boom")
871+
console.log("Unexpected failure:", error);
871872
});
872873
----
873874

0 commit comments

Comments
 (0)