Jennifer Anthony
Jennifer Anthony

Reputation: 2277

After each times click an increasing number?

I want after each times click value 2011 an increasing number, how is it?

Example:

$('button').click(function() {
    var num = '2011';
    var out = num ++1;
    alert(num); // i want this output: 2012
});

Upvotes: 1

Views: 746

Answers (3)

MeLight
MeLight

Reputation: 5555

var num = '2011';
$('button').click(function() {
    num++;
    alert(num); // i want this output: 2012
});

Upvotes: 3

user142019
user142019

Reputation:

Try this:

var num = '2011';
$('button').click(function() {
    var out = num++;
    alert(num);
});
  • var num must be outside of the function, otherwise it will be 2011 again every time the function is run.
  • num++1 should be num++.

Upvotes: 2

aquinas
aquinas

Reputation: 23786

var num = 2011;
$('button').click(function() {
    num++;
    alert(num); // i want this output: 2012
});

Upvotes: 4

Related Questions