The Replacements Explainer

Aim of the puzzle: Use Apps Script to make multiple edits to the text of a document from Docs.

Walk through of the solution: In this puzzle, you’ll use a for…of loop with .replaceText() to make multiple changes to a document from Docs.

The edits array contains 3 arrays, with each array containing 2 strings. The 1st string is the text to replace, and the 2nd string is new text to put in its place.

To complete the puzzle, add doc.replaceText() inside the code block {} of the for…of loop. Then, set the 1st argument of .replaceText() to edit[0]. Finally, set the 2nd argument of .replaceText() to edit[1].

Sample code solution:

let doc = DocumentApp.openById('226uAXY0YRUj-HMW5LQZ2YeeJgyDqmJTpnzRkGmFLch0');
let edits = [
  ['Xi', 'Sidhe'],
  ['seashells', 'diamonds'],
  ['by the seashore', 'on the soles of her shoes']
];

for (let edit of edits) {
  doc.replaceText(edit[0], edit[1]);
}

JavaScript concepts: Variables, Strings, For…of Loops, Nested Arrays, Array Indexing

Apps Script concepts: DocumentApp, openById(), .replaceText()