Skip to content

Commit adc4811

Browse files
committed
Add first no_runs
1 parent d2d6930 commit adc4811

File tree

10 files changed

+43
-37
lines changed

10 files changed

+43
-37
lines changed

ferris.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var ferrisTypes = [
55
},
66
{
77
attr: 'panics',
8-
title: 'This code panics!'
8+
title: 'This code will crash!'
99
},
1010
{
1111
attr: 'not_desired_behavior',

src/first_steps.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Its a tradition for this to be your first program in any language.
3131
We aren't quite at the point where I can explain what `void main()` means, but
3232
all you need to know for now is that it is what Java looks for to know where to start the program.
3333

34-
```java
34+
```java,no_run
3535
void main() {
3636
< WRITE YOUR CODE HERE >
3737
}
@@ -42,15 +42,15 @@ void main() {
4242
Unfortunately, for reasons that are impossible to explain with the context you have at this point,
4343
half of this probably reads as cryptic nonsense.
4444

45-
```java
45+
```java,no_run
4646
public class Main {
4747
public static void main(String[] args) {
4848
```
4949

5050
I don't _want_ it to stay cryptic nonsense, but until we get there all you truly need to know
5151
is that Java uses all of that to know where to start the program.
5252

53-
```java
53+
```java,no_run
5454
public class Main {
5555
public static void main(String[] args) {
5656
< WRITE YOUR CODE HERE >
@@ -62,7 +62,7 @@ public class Main {
6262

6363
So for all intents and purposes, this is the whole program.
6464

65-
```java
65+
```java,no_run
6666
System.out.println("Hello, World!");
6767
```
6868

@@ -72,7 +72,7 @@ This bit of magic here - `System.out.println` - is a "statement" that "prints" t
7272

7373
If you were to replace it with `System.out.print`, then the output would lack that new line. This makes the following program be functionally identical to the first.
7474

75-
```java
75+
```java,no_run
7676
System.out.print("Hello, ");
7777
System.out.print("World");
7878
System.out.println("!");

src/first_steps/challenges.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The rules for this are
1212

1313
Write a program that prints your name twice. So if your name is "Jasmine", the output of the program should be this.
1414

15-
```text
15+
```text,no_run
1616
Jasmine
1717
Jasmine
1818
```
@@ -63,7 +63,7 @@ How could you use that error to figure out where you might have forgotten to put
6363

6464
~IF toplevel_anonymous_class
6565

66-
```java
66+
```java,editable
6767
void main() {
6868
System.out.println("Apple");
6969
System.out.println("Banana");

src/first_steps/comments.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ words.
88

99
~IF toplevel_anonymous_class
1010

11-
```java, no_run
11+
```java
1212
void main() {
1313
// This prints hello world!
1414
System.out.println("Hello, World!");
@@ -17,7 +17,7 @@ void main() {
1717

1818
~ELSE
1919

20-
```java, no_run
20+
```java
2121
public class Main {
2222
public static void main(String[] args) {
2323
// This prints hello world!

src/first_steps/formatting.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ You may have noticed that after each `{` all the code that comes after it is "in
55
~IF toplevel_anonymous_class
66

77
```java
8-
public class Main {
9-
public static void main(String[] args) {
10-
System.out.println("Hello, World!");
11-
}
8+
void main() {
9+
System.out.println("Hello, World!");
1210
}
1311
```
1412

src/first_steps/semicolon.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The `;` at the end of each of those lines is a "semicolon".
44

5-
```java
5+
```java,no_run
66
~IF simple_io
77
print("Hello, "); // <-- this thing
88
// ^
@@ -16,7 +16,7 @@ It indicates that the statement has finished. A "statement" is a line of code th
1616
The reason we call it a statement and not just a "line of code" is that it can technically span multiple lines and be
1717
more complicated than these examples.
1818

19-
```java
19+
```java,no_run
2020
System.out.print(
2121
"Hello, "
2222
);
@@ -28,15 +28,15 @@ at the end of every statement. If you do not, Java will get confused and your co
2828

2929
If you happen to have an extra semi-colon or two that is technically okay. It just reads it as an "empty statement." It's pointless, but it is allowed.
3030

31-
```java
31+
```java,no_run
3232
System.out.print(
3333
"Hello, "
3434
);;
3535
```
3636

3737
Or even
3838

39-
```java
39+
```java,no_run
4040
System.out.print(
4141
"Hello, "
4242
);

src/getting_started.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ edit the following code.
1616

1717
~IF toplevel_anonymous_class
1818

19+
<!--
1920
<span id="ferris"></span>
2021
2122
| Ferris | Meaning |
@@ -27,7 +28,9 @@ edit the following code.
2728
In most situations, we’ll lead you to the correct version of any code that
2829
doesn’t compile.
2930
30-
```java,panics
31+
-->
32+
33+
```java
3134
void main() {
3235
System.out.println("Hello, World");
3336
}

src/return_values.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Return

src/variables.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class Main {
2626

2727
A variable declaration has three components - the "type", the "name", and the "initial value".
2828

29-
```java
29+
```java,no_run
3030
String boss = "Jaqueline";
3131
// type name initial value
3232
```
@@ -37,7 +37,7 @@ of `"Jaqueline"`. Its "type" is "String", which I'll explain in more detail a bi
3737
After you declare a variable and assign it a value, the "name" refers to the value on the right
3838
hand side and you can use that name instead of the value.
3939

40-
```java
40+
```java,no_run
4141
// Does the same thing as System.out.println("Jaqueline");
4242
String boss = "Jaqueline";
4343
System.out.println(boss);

theme/book.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
// Fix back button cache problem
4-
window.onunload = function () {};
4+
window.onunload = function () { };
55

66
// Global variable, shared between modules
77
function playground_text(playground, hidden = true) {
@@ -103,8 +103,7 @@ function playground_text(playground, hidden = true) {
103103
}
104104
}
105105

106-
async function run_java_code(code_block)
107-
{
106+
async function run_java_code(code_block) {
108107
var result_block = code_block.querySelector(".result");
109108
if (!result_block) {
110109
result_block = document.createElement("code");
@@ -135,17 +134,23 @@ function playground_text(playground, hidden = true) {
135134
})
136135
.then((response) => response.json())
137136
.then((response) => {
138-
if(response["success"] != true)
139-
{
137+
console.info(response);
138+
139+
if (response["success"] != true) {
140140
result_block.innerText = response["stderr"];
141+
if (response["stdout"]) {
142+
result_block.innerText = result_block.innerText + "\n----------\n" + response["stdout"];
143+
}
144+
}
145+
else {
146+
result_block.innerText = response["stdout"];
141147
}
142-
result_block.innerText = response["stdout"];
143148
result_block.classList.remove("result-no-output");
144149
})
145150
.catch(
146151
(error) =>
147-
(result_block.innerText =
148-
"Playground Communication: " + error.message),
152+
(result_block.innerText =
153+
"Playground Communication: " + error.message),
149154
);
150155
}
151156

@@ -242,11 +247,10 @@ function playground_text(playground, hidden = true) {
242247
pre_block.insertBefore(buttons, pre_block.firstChild);
243248
}
244249

245-
250+
246251

247252
let code_block = pre_block.querySelector("code");
248-
if (code_block.classList.contains("no_run") == false)
249-
{
253+
if (code_block.classList.contains("no_run") == false) {
250254
var runCodeButton = document.createElement("button");
251255
runCodeButton.className = "fa fa-play play-button";
252256
runCodeButton.hidden = true;
@@ -255,7 +259,7 @@ function playground_text(playground, hidden = true) {
255259

256260
buttons.insertBefore(runCodeButton, buttons.firstChild);
257261
runCodeButton.addEventListener("click", function (e) {
258-
run_java_code(pre_block);
262+
run_java_code(pre_block);
259263
});
260264
}
261265
var clipButton = document.createElement("button");
@@ -359,7 +363,7 @@ function playground_text(playground, hidden = true) {
359363
var theme;
360364
try {
361365
theme = localStorage.getItem("mdbook-theme");
362-
} catch (e) {}
366+
} catch (e) { }
363367
if (theme === null || theme === undefined) {
364368
return default_theme;
365369
} else {
@@ -405,7 +409,7 @@ function playground_text(playground, hidden = true) {
405409
if (store) {
406410
try {
407411
localStorage.setItem("mdbook-theme", theme);
408-
} catch (e) {}
412+
} catch (e) { }
409413
}
410414

411415
html.classList.remove(previousTheme);
@@ -517,7 +521,7 @@ function playground_text(playground, hidden = true) {
517521
sidebar.setAttribute("aria-hidden", false);
518522
try {
519523
localStorage.setItem("mdbook-sidebar", "visible");
520-
} catch (e) {}
524+
} catch (e) { }
521525
}
522526

523527
var sidebarAnchorToggles = document.querySelectorAll("#sidebar a.toggle");
@@ -540,7 +544,7 @@ function playground_text(playground, hidden = true) {
540544
sidebar.setAttribute("aria-hidden", true);
541545
try {
542546
localStorage.setItem("mdbook-sidebar", "hidden");
543-
} catch (e) {}
547+
} catch (e) { }
544548
}
545549

546550
// Toggle sidebar

0 commit comments

Comments
 (0)