From 3a867a7563e68470ceb3c0cea41eccd4ff88a65f Mon Sep 17 00:00:00 2001 From: jm1021 Date: Thu, 17 Sep 2026 23:21:20 -0700 Subject: [PATCH] Turn lesson code examples into runnable code-runner exercises MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wires the intro example and both popcorn hacks into the site's interactive Java code-runner (codemirror: true + CODE_RUNNER markers), and adds a new "Try It Yourself" exercise. Students can now edit and run each snippet in-browser instead of only reading static code blocks. Also fixes a cross-contamination bug where plain ``` fences inside answer-reveal cells desynced the runner metadata mapping for later cells — reveals now use

instead.

Co-Authored-By: Claude Sonnet 5 
---
 .../java/notebooks/2025-09-21-2.2.ipynb       | 106 +++++++++++++++---
 1 file changed, 88 insertions(+), 18 deletions(-)

diff --git a/_projects/lessons/java/notebooks/2025-09-21-2.2.ipynb b/_projects/lessons/java/notebooks/2025-09-21-2.2.ipynb
index 51741895ad..49a48aa5df 100644
--- a/_projects/lessons/java/notebooks/2025-09-21-2.2.ipynb
+++ b/_projects/lessons/java/notebooks/2025-09-21-2.2.ipynb
@@ -17,6 +17,7 @@
     "lesson_part: interactive\n",
     "lesson_type: lesson\n",
     "toc: true\n",
+    "codemirror: true\n",
     "title: Boolean Expressions\n",
     "menu: nav/csa_units/csaunit2.html\n",
     "permalink: /csa/unit_02/2_2\n",
@@ -38,7 +39,9 @@
     "| `<` | less than |\n",
     "| `>` | greater than |\n",
     "| `<=` | less than or equal to |\n",
-    "| `>=` | greater than or equal to |"
+    "| `>=` | greater than or equal to |\n",
+    "\n",
+    "Run it yourself below."
    ]
   },
   {
@@ -51,12 +54,18 @@
    },
    "outputs": [],
    "source": [
-    "int score = 85;\n",
+    "// CODE_RUNNER: Boolean Expressions - Try It\n",
+    "public class Main {\n",
+    "    public static void main(String[] args) {\n",
+    "        int score = 85;\n",
     "\n",
-    "System.out.println(score == 85);   // true\n",
-    "System.out.println(score != 100);  // true\n",
-    "System.out.println(score > 90);    // false\n",
-    "System.out.println(score <= 85);   // true"
+    "        System.out.println(score == 85);   // true\n",
+    "        System.out.println(score != 100);  // true\n",
+    "        System.out.println(score > 90);    // false\n",
+    "        System.out.println(score <= 85);   // true\n",
+    "    }\n",
+    "}\n",
+    "Main.main(null);"
    ]
   },
   {
@@ -112,10 +121,16 @@
    },
    "outputs": [],
    "source": [
-    "int temp = 72;\n",
-    "System.out.println(temp >= 70);\n",
-    "System.out.println(temp == 72.0);\n",
-    "System.out.println(temp < 32);"
+    "// CODE_RUNNER: Popcorn Hack 1 - Predict the Output\n",
+    "public class Main {\n",
+    "    public static void main(String[] args) {\n",
+    "        int temp = 72;\n",
+    "        System.out.println(temp >= 70);\n",
+    "        System.out.println(temp == 72.0);\n",
+    "        System.out.println(temp < 32);\n",
+    "    }\n",
+    "}\n",
+    "Main.main(null);"
    ]
   },
   {
@@ -123,7 +138,7 @@
    "metadata": {},
    "source": [
     "### Popcorn Hack 2\n",
-    "Find and fix the 2 errors in this Boolean expression."
+    "Find and fix the 2 errors in this Boolean expression, then run it until it works."
    ]
   },
   {
@@ -136,9 +151,66 @@
    },
    "outputs": [],
    "source": [
-    "int number = 4;\n",
-    "boolean isEven = number % 2 = 0;\n",
-    "System.out.println(isEven)"
+    "// CODE_RUNNER: Popcorn Hack 2 - Fix the Bug\n",
+    "public class Main {\n",
+    "    public static void main(String[] args) {\n",
+    "        int number = 4;\n",
+    "        boolean isEven = number % 2 = 0;\n",
+    "        System.out.println(isEven)\n",
+    "    }\n",
+    "}\n",
+    "Main.main(null);"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "
Show fixed code\n", + "
int number = 4;\n",
+    "boolean isEven = number % 2 == 0;\n",
+    "System.out.println(isEven);
\n", + "
" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Try It Yourself\n", + "Change `false` below to a Boolean expression using `age` and a relational operator, so `canJoinClub` is only `true` when `age` is 13 or older. Run it, then edit `age` to test 12, 13, and 100." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "vscode": { + "languageId": "java" + } + }, + "outputs": [], + "source": [ + "// CODE_RUNNER: Try It Yourself - Age Check\n", + "public class Main {\n", + " public static void main(String[] args) {\n", + " int age = 16;\n", + "\n", + " boolean canJoinClub = false; // TODO: use age and a relational operator\n", + "\n", + " System.out.println(canJoinClub);\n", + " }\n", + "}\n", + "Main.main(null);" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "
Show one possible answer\n", + "
boolean canJoinClub = age >= 13;
\n", + "
" ] }, { @@ -154,10 +226,8 @@ "
Show answerB \u2014 != is false when both sides are equal.
\n", "\n", "**2.**\n", - "```java\n", - "int x = 5, y = 10;\n", - "System.out.println(x <= y);\n", - "```\n", + "
int x = 5, y = 10;\n",
+    "System.out.println(x <= y);
\n", "What is printed?\n", "A) `5` B) `10` C) `true` D) `false`\n", "\n",