Calling a function from another function

I hava for loop in which i call count_change function which in turn call add function to increment counter.Basically i want to call function add from another function count_change ,but when i do so i get an error
Uncaught TypeError: add is not a function
at noun_change (stat3.js:40)
at missing_stat (stat3.js:8)

var add = (function () {
  var counter = 0;

  return function () {
    return counter += 1;
  }
})();

function count_change(){
  var count_noun= add();
}

} 

what am i doing wrong

The main thing at the moment seems to be, formatting your code really badly for use on the forum.

You should get rid of all those unnecessary asterisks to start, then put three backticks ( ``` ) on the line before your code, then another three backticks on the line after, OR highlight all the code section and click on the </> icon on the toolbar above the text editor box.

1 Like

Hi @abidakhtar, this snippet alone would work as expected (disregarding the excess curly brace)… however there’s no noun_change() function and no missing_stat() function as per the stack trace. So I suppose we need to see more code. ;-) Most probably the issue has to do with the scope in which add() is declared, though.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.