Reputation: 165
I am looking for some help. I'd like to be able to add 2 variables and then set one of the variables to a higher digit.
function gain_points() {
var total_points = parseInt(0)
var points_per_click = parseInt(1)
var points_per_second = parseInt(0)}
I'd like to be able to add total_points and points_per_click together, and then for that to increase total_points.
Is this possible?
Upvotes: 0
Views: 218
Reputation: 326
Having var total_points defined in the gain_points function it will be defined every time the function is called and assigned to the value of 0.
You may want to consider something like this:
var total_points = parseInt(0);
var points_per_click = parseInt(1);
var points_per_second = parseInt(0);
function gain_points() {
total_points = total_points + points_per_click;
}
This allows total_points to continue to increment every time that function is called.
You also don't need to use the parseInt(); The following would be just fine instead:
var total_points = 0;
var points_per_click = 1;
var points_per_second = 0;
Upvotes: 3
Reputation: 315
total_points = total_points + points_per_click;
Is that what you are saying??
Sorry, can't comment, not enough rep...
Upvotes: 2