title: How to calculate a variable in Google spreadsheet script, then return in confirmation email
body: <p>I'm a little new at this so thanks in advance for any help! I've gotten a confirmation email working based on a submission trigger/event for a Google Form to a spreadsheet. However, I want to be able to have the script grab two fields from the user's submission and then calculate a field to be included in the confirmation email. Once I added in the code to calculate the field (cost1), the confirmation email stopped sending. I checked the execution transcript and it ran much more quickly and said it executed successfully, but no email sent... Is there something wrong with my code or am I asking for the script to do too much?</p>
  
  <p>The script:</p>
  
  <pre><code>function EmailFormConfirmation() {
  
  
    var sheetName = "Form Responses"; 
    var columnNumber = 3;
    var subject = "Summer School Registration Confirmation";
    var gn = 2;
    var sfn = 4;
    var sln = 5; 
    var s1 = 13;
    var s2 = 14;
  
  
    var ss = SpreadsheetApp.getActiveSpreadsheet(); 
    var dataSheet = ss.getSheetByName(sheetName);
    var numRows = dataSheet.getLastRow();
    var email = dataSheet.getRange(numRows,columnNumber).getValue();
    var guardianName = dataSheet.getRange(numRows,gn).getValue();
    var studentFirst = dataSheet.getRange(numRows,sfn).getValue();
    var studentLast = dataSheet.getRange(numRows,sln).getValue();
    var session1 = dataSheet.getRange(numRows,s1).getValue();
    var session2 = dataSheet.getRange(numRows,s2).getValue();
    var emailPattern = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+$/; //email reg expression
    var validEmailAddress = emailPattern.test(email); 
    var cost1 = 0
      if(session1 === "Driver's Education Classroom &amp; Behind the Wheel")
      {
        var cost1 = cost1+400
      }
      else
      {
        var cost1 = cost1+180
      }
  
      if(session2 &gt; 0)
      {
        var cost1 = cost1+180
        return(cost1)
      }
      else
      {
        return(cost1)
      };
    var body = "Dear" + " " + guardianName + "," +
    "\n\nThank you for submitting summer school registration for" + " " + studentFirst + " " + studentLast + "." +
    "\n\nYou have selected the following for Session 1:" + " " + session1 +
    "\n\nYou have selected the following for Session 2:" + " " + session2 +
    "\n\nIf any changes need to be made, please contact the office." +
    "\n\nYour total fees due for summer school are:" + " " + "$" + cost1 +  
    "\n\n\nSummer School Registrar";
  
    if (validEmailAddress) {
  
        MailApp.sendEmail(email, subject,body); 
      }
  
    }  
  </code></pre>