0

How do I call a function within a function? I am working on a project and have a variable defined within add() that I wish to use in add2(), but I cannot define it outside of add() as it will be used many times with different values

Javascript:

function Question1() {
  var CurrentQuestionPoints = 100;
  function AddPoint(){
    Team1Points = Team1Points + CurrentQuestionPoints;
    document.getElementById("Team1Points").innerHTML = Team1Points;
  }
}

HTML:

<a href="javascript:AddPoint()" id="AddPoints">+  </a><a href="javascript:SubtractPoints()" id="SubtractPoints">-</a>
Pointy
  • 405,095
  • 59
  • 585
  • 614
  • 1
    You can only call that "AddPoint" function from *within* the "Question1" function (as currently written). – Pointy Jan 31 '14 at 23:38
  • 1
    possible duplicate of [Calling a function that's defined inside a function](http://stackoverflow.com/questions/6784079/calling-a-function-thats-defined-inside-a-function) – Charlie Jan 31 '14 at 23:40
  • You could make them all separate functions and just pass the currentquestionpoints string with the addpoint function call. Like AddPoint(100) – SyntaxLAMP Jan 31 '14 at 23:50

0 Answers0