tags:

views:

49

answers:

2

I have a button which adds a paragraph each time it is clicked. In my code i have a function called addPara(count), and i have a counterstart variable. how can i pass this counterstart variable to me function?

+4  A: 

addPara(counterstart);

mathepic
thanks but not what i needed perhaps my question is too vague. The addPara() function should have (at least) one argument passed to it – the counterStart variable....
Sam
Yeah, I'm passing the `counterstart` variable to `addPara`.
mathepic
+2  A: 

If you mean that you're not sure how many arguments will be passed, you can reference any and all argument via the arguments collection inside the function.

function addPara() {
    console.log(arguments); // "arguments" is a collection of the arguments.
    if(arguments[0] === undefined) { 
         // do something and return if no arguments were given
        return false;
    }
      // otherwise loop through the arguments passed
    for( var i = 0, len = arguments.length; i < len; i++ ) {
       // do something with arguments[ i ];
    }
}
patrick dw
This question is so ambiguous that I question if its even worth answering. +1 for the effort.
mathepic