From 58802c81129a11a7735e2262068de4161f75f5a6 Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Tue, 30 Sep 2025 18:41:16 +0200 Subject: [PATCH] refactor: remove before after user code (#59204) --- .../56533eb9ac21ba0edf2244a8.md | 14 ----- .../56533eb9ac21ba0edf2244bd.md | 61 +++++-------------- .../56533eb9ac21ba0edf2244c6.md | 40 ------------ .../56533eb9ac21ba0edf2244cf.md | 48 +++++++-------- .../5ee127a03c3b35dd45426493.md | 19 ------ .../587d7db1367417b2b2512b87.md | 44 ++----------- .../587d7db6367417b2b2512b9a.md | 14 ++--- 7 files changed, 49 insertions(+), 191 deletions(-) diff --git a/curriculum/challenges/english/blocks/basic-javascript/56533eb9ac21ba0edf2244a8.md b/curriculum/challenges/english/blocks/basic-javascript/56533eb9ac21ba0edf2244a8.md index e36b66f16aa..4199419fecc 100644 --- a/curriculum/challenges/english/blocks/basic-javascript/56533eb9ac21ba0edf2244a8.md +++ b/curriculum/challenges/english/blocks/basic-javascript/56533eb9ac21ba0edf2244a8.md @@ -45,20 +45,6 @@ assert(typeof a === 'number' && a === 7); # --seed-- -## --before-user-code-- - -```js -if (typeof a != 'undefined') { - a = undefined; -} -``` - -## --after-user-code-- - -```js -(function(a){return "a = " + a;})(a); -``` - ## --seed-contents-- ```js diff --git a/curriculum/challenges/english/blocks/basic-javascript/56533eb9ac21ba0edf2244bd.md b/curriculum/challenges/english/blocks/basic-javascript/56533eb9ac21ba0edf2244bd.md index ea277a76202..d3045037836 100644 --- a/curriculum/challenges/english/blocks/basic-javascript/56533eb9ac21ba0edf2244bd.md +++ b/curriculum/challenges/english/blocks/basic-javascript/56533eb9ac21ba0edf2244bd.md @@ -24,6 +24,12 @@ Then we can call `testFun` like this: `testFun("Hello", "World");`. We have pass
  1. Create a function called functionWithArgs that accepts two arguments and outputs their sum to the dev console.
  2. Call the function with two numbers as arguments.
+# --before-each-- + +```js +var logOutput; +``` + # --hints-- `functionWithArgs` should be a function. @@ -35,22 +41,20 @@ assert(typeof functionWithArgs === 'function'); `functionWithArgs(1,2)` should output `3`. ```js -if (typeof functionWithArgs === 'function') { - capture(); - functionWithArgs(1, 2); - uncapture(); -} +console.log = function (message) { + logOutput = message +}; +functionWithArgs(1, 2); assert(logOutput == 3); ``` `functionWithArgs(7,9)` should output `16`. ```js -if (typeof functionWithArgs === 'function') { - capture(); - functionWithArgs(7, 9); - uncapture(); -} +console.log = function (message) { + logOutput = message +}; +functionWithArgs(7, 9); assert(logOutput == 16); ``` @@ -66,43 +70,6 @@ assert( # --seed-- -## --before-user-code-- - -```js -var logOutput = ""; -var originalConsole = console -function capture() { - var nativeLog = console.log; - console.log = function (message) { - if(message) logOutput = JSON.stringify(message).trim(); - if(nativeLog.apply) { - nativeLog.apply(originalConsole, arguments); - } else { - var nativeMsg = Array.prototype.slice.apply(arguments).join(' '); - nativeLog(nativeMsg); - } - }; -} - -function uncapture() { - console.log = originalConsole.log; -} - -capture(); -``` - -## --after-user-code-- - -```js -uncapture(); - -if (typeof functionWithArgs !== "function") { - (function() { return "functionWithArgs is not defined"; })(); -} else { - (function() { return logOutput || "console.log never called"; })(); -} -``` - ## --seed-contents-- ```js diff --git a/curriculum/challenges/english/blocks/basic-javascript/56533eb9ac21ba0edf2244c6.md b/curriculum/challenges/english/blocks/basic-javascript/56533eb9ac21ba0edf2244c6.md index 5c73b36636d..0f468b5eaa4 100644 --- a/curriculum/challenges/english/blocks/basic-javascript/56533eb9ac21ba0edf2244c6.md +++ b/curriculum/challenges/english/blocks/basic-javascript/56533eb9ac21ba0edf2244c6.md @@ -44,48 +44,8 @@ assert(nextInLine([2], 1) === 2); assert(nextInLine([5, 6, 7, 8, 9], 1) === 5); ``` -After `nextInLine(testArr, 10)`, `testArr[4]` should be `10` - -```js -nextInLine(testArr, 10); -assert(testArr[4] === 10); -``` - # --seed-- -## --before-user-code-- - -```js -var logOutput = []; -var originalConsole = console -function capture() { - var nativeLog = console.log; - console.log = function (message) { - logOutput.push(message); - if(nativeLog.apply) { - nativeLog.apply(originalConsole, arguments); - } else { - var nativeMsg = Array.prototype.slice.apply(arguments).join(' '); - nativeLog(nativeMsg); - } - }; -} - -function uncapture() { - console.log = originalConsole.log; -} - -capture(); -``` - -## --after-user-code-- - -```js -uncapture(); -testArr = [1,2,3,4,5]; -(function() { return logOutput.join("\n");})(); -``` - ## --seed-contents-- ```js diff --git a/curriculum/challenges/english/blocks/basic-javascript/56533eb9ac21ba0edf2244cf.md b/curriculum/challenges/english/blocks/basic-javascript/56533eb9ac21ba0edf2244cf.md index fd235501373..994ca9fe242 100644 --- a/curriculum/challenges/english/blocks/basic-javascript/56533eb9ac21ba0edf2244cf.md +++ b/curriculum/challenges/english/blocks/basic-javascript/56533eb9ac21ba0edf2244cf.md @@ -27,6 +27,30 @@ Complete the function using the rules below to modify the object passed to the f **Note:** A copy of the `recordCollection` object is used for the tests. You should not directly modify the `recordCollection` object. +# --before-each-- + +```js +const _recordCollection = { + 2548: { + albumTitle: 'Slippery When Wet', + artist: 'Bon Jovi', + tracks: ['Let It Rock', 'You Give Love a Bad Name'] + }, + 2468: { + albumTitle: '1999', + artist: 'Prince', + tracks: ['1999', 'Little Red Corvette'] + }, + 1245: { + artist: 'Robert Palmer', + tracks: [] + }, + 5439: { + albumTitle: 'ABBA Gold' + } +}; +``` + # --hints-- After `updateRecords(recordCollection, 5439, "artist", "ABBA")`, `artist` should be the string `ABBA` @@ -94,30 +118,6 @@ assert( # --seed-- -## --before-user-code-- - -```js -const _recordCollection = { - 2548: { - albumTitle: 'Slippery When Wet', - artist: 'Bon Jovi', - tracks: ['Let It Rock', 'You Give Love a Bad Name'] - }, - 2468: { - albumTitle: '1999', - artist: 'Prince', - tracks: ['1999', 'Little Red Corvette'] - }, - 1245: { - artist: 'Robert Palmer', - tracks: [] - }, - 5439: { - albumTitle: 'ABBA Gold' - } -}; -``` - ## --seed-contents-- ```js diff --git a/curriculum/challenges/english/blocks/basic-javascript/5ee127a03c3b35dd45426493.md b/curriculum/challenges/english/blocks/basic-javascript/5ee127a03c3b35dd45426493.md index 719abbd8846..7fe914eab25 100644 --- a/curriculum/challenges/english/blocks/basic-javascript/5ee127a03c3b35dd45426493.md +++ b/curriculum/challenges/english/blocks/basic-javascript/5ee127a03c3b35dd45426493.md @@ -45,25 +45,6 @@ assert(/b\s*=\s*a\s*/g.test(__helpers.removeJSComments(code))); # --seed-- -## --before-user-code-- - -```js -if (typeof a != 'undefined') { - a = undefined; -} -if (typeof b != 'undefined') { - b = undefined; -} -``` - -## --after-user-code-- - -```js -(function(a, b) { - return 'a = ' + a + ', b = ' + b; -})(a, b); -``` - ## --seed-contents-- ```js diff --git a/curriculum/challenges/english/blocks/object-oriented-programming/587d7db1367417b2b2512b87.md b/curriculum/challenges/english/blocks/object-oriented-programming/587d7db1367417b2b2512b87.md index 13db3f85a7c..45752265605 100644 --- a/curriculum/challenges/english/blocks/object-oriented-programming/587d7db1367417b2b2512b87.md +++ b/curriculum/challenges/english/blocks/object-oriented-programming/587d7db1367417b2b2512b87.md @@ -79,55 +79,23 @@ assert(beagle.constructor === Dog); `beagle.eat()` should log the string `nom nom nom` ```js -capture(); +const spy = __helpers.spyOn(console, 'log'); beagle.eat(); -uncapture(); -assert(logOutput == 'nom nom nom'); +assert.lengthOf(spy.calls,1); +assert(spy.calls[0][0] == 'nom nom nom'); ``` `beagle.bark()` should log the string `Woof!` ```js -capture(); +const spy = __helpers.spyOn(console, 'log'); beagle.bark(); -uncapture(); -assert(logOutput == 'Woof!'); +assert.lengthOf(spy.calls,1); +assert(spy.calls[0][0] == 'Woof!'); ``` # --seed-- -## --before-user-code-- - -```js -var logOutput = ""; -var originalConsole = console -function capture() { - var nativeLog = console.log; - console.log = function (message) { - logOutput = message; - if(nativeLog.apply) { - nativeLog.apply(originalConsole, arguments); - } else { - var nativeMsg = Array.prototype.slice.apply(arguments).join(' '); - nativeLog(nativeMsg); - } - }; -} - -function uncapture() { - console.log = originalConsole.log; -} - -capture(); -``` - -## --after-user-code-- - -```js -uncapture(); -(function() { return logOutput || "console.log never called"; })(); -``` - ## --seed-contents-- ```js diff --git a/curriculum/challenges/english/blocks/regular-expressions/587d7db6367417b2b2512b9a.md b/curriculum/challenges/english/blocks/regular-expressions/587d7db6367417b2b2512b9a.md index aaa4fdba5ac..ef285639e02 100644 --- a/curriculum/challenges/english/blocks/regular-expressions/587d7db6367417b2b2512b9a.md +++ b/curriculum/challenges/english/blocks/regular-expressions/587d7db6367417b2b2512b9a.md @@ -26,7 +26,7 @@ In order, the three `match` calls would return the values `["goooooooo"]`, `["g" # --instructions-- -For this challenge, `chewieQuote` has been initialized as the string `Aaaaaaaaaaaaaaaarrrgh!` behind the scenes. Create a regex `chewieRegex` that uses the `*` character to match an uppercase `A` character immediately followed by zero or more lowercase `a` characters in `chewieQuote`. Your regex does not need flags or character classes, and it should not match any of the other quotes. +Create a regex `chewieRegex` that uses the `*` character to match an uppercase `A` character immediately followed by zero or more lowercase `a` characters in `chewieQuote`. Your regex does not need flags or character classes, and it should not match any of the other quotes. # --hints-- @@ -72,15 +72,10 @@ assert( # --seed-- -## --before-user-code-- - -```js -const chewieQuote = "Aaaaaaaaaaaaaaaarrrgh!"; -``` - ## --seed-contents-- ```js +const chewieQuote = "Aaaaaaaaaaaaaaaarrrgh!"; // Only change code below this line let chewieRegex = /change/; // Change this line // Only change code above this line @@ -91,6 +86,7 @@ let result = chewieQuote.match(chewieRegex); # --solutions-- ```js - let chewieRegex = /Aa*/; - let result = chewieQuote.match(chewieRegex); +const chewieQuote = "Aaaaaaaaaaaaaaaarrrgh!"; +let chewieRegex = /Aa*/; +let result = chewieQuote.match(chewieRegex); ```