Making regular review of tier 2 and 3 vocabulary easier with google apps script

In the coming academic year I want KS3 lessons in my department to include more of a deliberate attempt to get students to learn and remember tier 2 and 3 vocabulary from lessons. What I've noticed in GCSE and A-Level exam question answers is that very often students do know the answer but the language they've used is not quite accurate enough for the marks. My hope is that by improving the amount of tier 2 and 3 vocabulary that students remember and use at KS3 we'll eventually end up with students at KS4 and KS5 that are better able to write "like a computer scientist" in their exam answers.

One way I'll be trying to do this is by making vocabulary learning a part of regular review in lessons so I decided to make a tool for teachers in my department which makes including regular review of vocabulary very low effort. The tool allows the teacher to automatically generate a definition retrieval activity with a certain number of key terms from a particular topic. It generates a document for students to complete the task in and a document with answers. Here is a short video demonstration:

How it works: spreadsheet contents

Firstly I have a sheet with all of the key terms from each topic and their definitions. The program retrieves these when asked to create a worksheet.

There's then a separate small spreadsheet which functions as the user interface. 

The user can choose how many terms they want included in the activity and which topic they want the terms taken from. Clicking on Generate Worksheet runs the makeStarter function in my apps script code.

How it works - apps script code

Initially, set up some objects that'll be needed. Retrieve the topic and number of questions the user selected from the sheet and create the documents.
var spreadsheet = SpreadsheetApp.getActive();
var topic = spreadsheet.getSheetByName('Worksheet Generator').getRange("B2").getValue();
var questionNum = spreadsheet.getSheetByName('Worksheet Generator').getRange("B1").getValue();
var worksheet = DocumentApp.create(topic + " vocab starter");
var answers = DocumentApp.create(topic + " vocab starter answers");

Then retrieve all the key terms from the spreadsheet and remove all of the terms that aren't in the selected topic. 
var terms = filterByTopic(spreadsheet.getSheetByName('Terms').getRange("A1:C195").getValues());
This is achieved with the filter method
function filterByTopic(terms) {
  return terms.filter(isInTopic);
}
The condition to filter on is given by the isInTopic function. The term will remain in the array
if it is in the topic the user has chosen.
function isInTopic(term) {
  var spreadsheet = SpreadsheetApp.getActive();
  topic = spreadsheet.getSheetByName('Worksheet Generator').getRange("B2").getValue();
  return term[2] == topic;
}
Then choose some random terms from the topic and add them along with their definitions to the answers document
  var questions = [];
  for (var i = 0i<questionNumi++) {
    var randomTerm = terms[getRndInteger(0terms.length)]
    randomTerm.pop()
    questions.push(randomTerm);
  }
  answers.appendTable(questions);
Finally, strip out the answers and add the key terms to the worksheet.
  var questionsNoAnswers = [["Key Term""Your definition"]];
  for (var i = 0i < questions.lengthi++) {
    questionsNoAnswers.push([questions[i][0], ""])
  }
  worksheet.appendParagraph("Define the following key terms from the " + topic + " topic:");
  worksheet.appendTable(questionsNoAnswers);

Full code listing