Skip to content

Conversation

chrisdavidmills
Copy link
Contributor

Description

As part of a larger project to make the challenges/reader exercises in MDN learn more consistent, this PR:

  • Replaces the old code editors with the live sample + MDN Playground flow.
  • Makes some general wording improvements.

Motivation

Additional details

Related issues and pull requests

@chrisdavidmills chrisdavidmills requested a review from a team as a code owner July 9, 2025 13:54
@chrisdavidmills chrisdavidmills requested review from bsmth and hamishwillee and removed request for a team July 9, 2025 13:54
@github-actions github-actions bot added Content:Learn Learning area docs size/l [PR only] 501-1000 LoC changed labels Jul 9, 2025
Copy link
Contributor

github-actions bot commented Jul 9, 2025

## Task 2
If you make a mistake, you can clear your work using the _Reset_ button in the MDN Playground. If you get really stuck, you can view the solution below the live output.

<!-- Code shared across examples -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy we can use this here 👍🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I love that we can do this. Unfortunately, the other articles didn't have so much scope for reuse.

Comment on lines 120 to 135
// Don't edit the code below here!

const section = document.querySelector("section");

const para1 = document.createElement("p");
para1.textContent = `Array: ${myArray}`;

const para2 = document.createElement("p");
para2.textContent = `The length of the array is ${arrayLength}.`;

const para3 = document.createElement("p");
para3.textContent = `The last item in the array is "${lastItem}".`;

section.appendChild(para1);
section.appendChild(para2);
section.appendChild(para3);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could make it a little more compact or even hidden?

Suggested change
// Don't edit the code below here!
const section = document.querySelector("section");
const para1 = document.createElement("p");
para1.textContent = `Array: ${myArray}`;
const para2 = document.createElement("p");
para2.textContent = `The length of the array is ${arrayLength}.`;
const para3 = document.createElement("p");
para3.textContent = `The last item in the array is "${lastItem}".`;
section.appendChild(para1);
section.appendChild(para2);
section.appendChild(para3);
```
```js hidden live-sample___arrays-2
// The following code checks if your edits work.
// Don't edit after this line!
const section = document.querySelector("section");
const para1 = document.createElement("p");
para1.textContent = `Array: ${myArray}`;
const para2 = document.createElement("p");
para2.textContent = `The length of the array is ${arrayLength}.`;
const para3 = document.createElement("p");
para3.textContent = `The last item in the array is "${lastItem}".`;
section.appendChild(para1);
section.appendChild(para2);
section.appendChild(para3);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @bsmth! After reading your comment, I experimented with hiding various sections of code to see what the experience was like. I ended up not going for a solution like this, for a couple of reasons:

  1. When the code is loaded up in MDN Playground, it gets rid of line breaks at the start and end of the blocks, even if you set them to -nolint in the MDN page. As a result, you get comments right next to one another in a way I didn't want, which annoyed me.
  2. When you jump over to the MDN Playground and are presented with code that you didn't know was there, it feels a bit jarring/surprising. I didn't feel like this would be a good experience, especially not for beginners.

To cut down on the size of these examples, I have done two things:

  1. Removed unnecessary blank lines, as you suggested.
  2. Truncated the shown "don't edit" code with ellipsis comments (// ...) inside the solution listings, keeping the other comments for context so the reader is less likely to get confused about where the solution should go.

Since this is a significant change, I'd like you to review this update to see if you think it works. Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super, thanks, Chris.

I ended up not going for a solution like this, for a couple of reasons:

Good, that all makes sense, tnx. Taking a look now

Copy link
Member

@bsmth bsmth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really glad we're refreshing these. General comment about format, and a question about hiding some of the logic checks in JS, but otherwise, looking great! Thank you 👏🏻

chrisdavidmills and others added 5 commits July 9, 2025 16:51
…lls/arrays/index.md

Co-authored-by: Brian Smith <brian@smith.berlin>
…lls/conditionals/index.md

Co-authored-by: Brian Smith <brian@smith.berlin>
…lls/conditionals/index.md

Co-authored-by: Brian Smith <brian@smith.berlin>
…lls/events/index.md

Co-authored-by: Brian Smith <brian@smith.berlin>
@chrisdavidmills chrisdavidmills requested a review from bsmth July 9, 2025 16:34
myArray.unshift("crocodiles");

// Don't edit the code below here!
// ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this looks good, tnx

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really tidy now, nice work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super, thanks @bsmth. I'll follow the same pattern in future PRs.

Copy link
Member

@bsmth bsmth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great, Chris! 👏🏻

@chrisdavidmills chrisdavidmills merged commit 6d76a8f into mdn:main Jul 10, 2025
8 checks passed
@chrisdavidmills chrisdavidmills deleted the js-active-learning-4 branch July 10, 2025 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:Learn Learning area docs size/l [PR only] 501-1000 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants