title: Google Scripts writing to Sheets
body: <p>I have the script below to pull out information about google classrooms.
  I seem to be bashing my head against a brick wall - how can I write the course.data into the google sheet I am creating?
  Many thanks</p>
  
  <pre><code>/**
   * Lists 100000 course names and ids.
   */
  function listCourses() {
    var rows = 100000
    var columns = 5
    var date = Utilities.formatDate(new Date(), "GMT+1", "dd/MM/yyyy")
    var spreadsheet = "ScriptClassroomCodes "+date
  
    var oldfiles = DriveApp.getFilesByName(spreadsheet);
    while (oldfiles.hasNext()) {
      var oldfile = oldfiles.next();
      oldfile.setTrashed(true);
  }
    var optionalArgs = {
      pageSize: rows
    };
    SpreadsheetApp.create(spreadsheet, rows, columns)
    var currentfile = DriveApp.getFilesByName(spreadsheet);
    while (currentfile.hasNext()) {
      var file = currentfile.next();
      var sheetid = file.getId();
  }
  
  var sheet = SpreadsheetApp.openById(sheetid)
  
    var response = Classroom.Courses.list(optionalArgs);
    var courses = response.courses;
    if (courses &amp;&amp; courses.length &gt; 0) {
      for (i = 0; i &lt; courses.length; i++) {
        var course = courses[i];
        Logger.log(course.name, course.alternateLink, course.enrollmentCode, course.courseState);
      }
    } else {
      Logger.log('No courses found.');
    }
  }
  </code></pre>