title: Can I add a formula to a google form response using Apps Script?
body: <p>Apologies as I am a beginner to coding. I am interested in using Google Apps Script to automate the analysis of a Google Form response.</p>
  
  <p>The <a href="https://docs.google.com/spreadsheets/d/1RgUaZQY_pdlWpC0NivVUO_yeJPzhPlgdV4ytHMvx9jk/edit?usp=sharing" rel="nofollow noreferrer">simple example</a> I have is for the spreadsheet of responses for a form asking people: </p>
  
  <p>1) how many players there were?<br>
  2) where they finished [1st, 2nd, etc,]  </p>
  
  <p>On submission of the form I want to run a script that calculates how may points they received and inserts this value in the next available column (column E in this example).</p>
  
  <p>I have tried writing my first Apps Script to automate this process, but without success.</p>
  
  <p>SAMPLE CODE:</p>
  
  <pre><code>function onFormSubmit(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Form Responses Master");
  var players = e.values[2];
  var place = e.values[3];
  var positionPoints = e.values[4];
  var positionPoints = (players - place + 1);
  
  return positionPoints;
  }
  </code></pre>
  
  <p>I know there are workarounds available by creating duplicate pages, but I was hoping someone might be able to advise me on how to code a solution in App Scripts, in the hope I might get a better understanding of the coding process.</p>