title: Uncaught ReferenceError: total cost is not defined
body: <p>I've looked over and over it, but I can't seem to find the problem. When I load the script in Google Chrome's JavaScript console, it returns the following error back to me
  <code>Uncaught referenceerror: total cost is not defined</code>. This happens by the <code>document.getElementById("answer").innerHTML</code> code.</p>
  
  <p>I've tried to split up the formula, give it another name, recombined the formula, but it still gives me the same error. </p>
  
  <pre><code>//waarde vasthouden
    function calcul(){
      var fund = parseFloat(document.getElementById("fund").value);
      var age1 = parseFloat(document.getElementById("age1").value);
      var age2 = parseFloat(document.getElementById("age2").value);
      var age3 = parseFloat(document.getElementById("age3").value);
      var age4 = parseFloat(document.getElementById("age4").value);
      var age5 = parseFloat(document.getElementById("age5").value);
      var age6 = parseFloat(document.getElementById("age6").value);
      var primcost = parseFloat(document.getElementById("primcost").value);
      var seccost = parseFloat(document.getElementById("seccost").value);
      var unicost = parseFloat(document.getElementById("unicost").value);
      var start = parseFloat(document.getElementById("start").value);
      var annrate = parseFloat(document.getElementById("annrate").value);
      //additional calculations
      //Duration primary school
      var primdur = (age2 - age1) + 1; 
      //Present Value Primary School before starting
      var pvprim = primcost * ((1 - (Math.pow((1 + (annrate / 100)), primdur))) / (annrate / 100));
      //Duration secondary school
      var secdur = (age4 - age3) + 1; 
      //Present Value secondary School before starting
      var pvsec = seccost * ((1 - (Math.pow((1 + (annrate / 100)), secdur))) / (annrate / 100));
      //Duration university
      var unidur = (age6 - age5) + 1; 
      //Present Value university before starting
      var pvuni = unicost * ((1 - (Math.pow((1 + (annrate / 100)), unidur))) / (annrate / 100));
      //Present value when starting primary school
      //var X1 = ((pvprim) / (Math.pow((1 + (annrate / 100)), (age1 - 1))));
      //Present value when starting secondary school
      //var X2 = ((pvsec) / (Math.pow((1 + (annrate / 100)), (age3 - 1))));
      //Present value when starting university
      //var X3 = ((pvuni) / (Math.pow((1 + (annrate / 100)), (age5 - 1))));
      //Annual deposits (PV formula)
      var totalcost = ((pvprim) / (Math.pow((1 + (annrate / 100)), (age1 - 1)))) + 
      ((pvsec) / (Math.pow((1 + (annrate / 100)), (age3 - 1)))) + 
      ((pvuni) / (Math.pow((1 + (annrate / 100)), (age5 - 1))));
      var othcalc = (1 / (annrate / 100)) - ((1 / ((annrate / 100)*(Math.pow((1 + (annrate / 100)), age5)))));
    }
  
  //binnen in script resterende decimal code, nadat alle variabelen zijn gedefinieerd
          var decs = +(document.getElementById('dec').value);
          calculated = true; //end of decimal code
  
  //Eindantwoord weergeven in decimalen
   document.getElementById("answer").innerHTML =(((totalcost) - fund) / othcalc).toFixed(decs);
  &lt;/script&gt;
  </code></pre>
  
  <p>Is this because my <code>var totalcost</code> is incorrect, or is this because of another mistake? The built in Google Sites HTML-box doesn't give me any errors, but the JSconsole does.</p>