Skip to content

Commit fbf985c

Browse files
committed
Add download link and more text to exercise page
1 parent 63f9571 commit fbf985c

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

html/exercises.html

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,23 @@
3232
<article style="max-width: 50em;">
3333
<h1>Exercises<div style="font-size: 70%">Eloquent JavaScript</div></h2>
3434

35+
<p>You can use this page to work on exercises when reading through a
36+
non-interactive version of Eloquent JavaScript, and to see solution
37+
code.</p>
38+
3539
<p>
3640
<select id="exercises"><option value="none">Select an exercise</option></select>
3741
<button id="run">run code</button>
38-
<button id="solution">see solution</button>
3942
</p>
4043

4144
<div class="editor-wrap">
4245
<textarea id="editor"></textarea>
4346
<div class="sandbox-output" id="output"></div>
4447
</div>
48+
49+
<p>If you've solved the exercise and want to compare your code with
50+
mine, or you <em>really</em> tried, but can't get your code to work,
51+
you can <button id="solution" style="color: #c22">look at the
52+
solution</button> (or <a id="download" href="javascript:alert('No exercise
53+
selected')">download it</a>).</p>
4554
</article>

html/js/exercises.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ addEventListener("load", function() {
3535
}
3636
}
3737

38+
var downloadLink = document.querySelector("#download");
3839
var currentExercise = null;
3940
function selectExercise(id) {
4041
var exercise = findExercise(id);
@@ -44,6 +45,8 @@ addEventListener("load", function() {
4445
editor.setValue(exercise.code);
4546
editor.setOption("mode", exercise.type == "js" ? "javascript" : "text/html");
4647
});
48+
downloadLink.href = exercise.file;
49+
downloadLink.download = "download";
4750
}
4851

4952
var outnode = document.querySelector(".sandbox-output");

0 commit comments

Comments
 (0)