Need variable A to declare variable B, but need variable B to declare variable A

Viewed 59

I am making a tool to make a new google doc and email it to my teacher for a certain subject, however my variable "Subjects" needs to include the document link, which means I need to create the document before I declare the variable Subjects, however in order to know what to name the doc, I need to access information stored in the variable Subjects. Any suggestions? My javascript is down below.

function doGet() {
  return HtmlService.createHtmlOutputFromFile('Index.html');
}

function customDoc(subject) {

  var formattedDate = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), 'M/d/yyyy');
  
  var subjects = {
      'math': {
     email: 'teacher@example.com',
      preSubject: 'math for '
    },
    'la': {
     email: 'teacher@example.com',
      preSubject: 'la for '
    },
    'science': {
     email: 'teacher@example.com',
      preSubject: 'science for '
    },
    'is': {
  email: 'teacher@example.com',
      preSubject: 'I&S for '
    },
    'spanish': {
      email: 'teacher@example.com',
      preSubject: 'Español para '
    
      message:  'Español para ' + formattedDate + 'This is supposed to be where the link to the google doc is, so this is where the paradox comes in. '
    }
  };

 
  console.log('Today: ' + formattedDate);
  console.log('Subject: ' + subject);
  console.log(subjects[subject]);
GmailApp.sendEmail(subjects.email, subjects.preSubject, subjects.message)
}
0 Answers
Related