0

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?

3
  • 5
    So add them together.... Commented Sep 13, 2013 at 19:38
  • parseInt(0) etc are redundant; you gain nothing over just saying 0. parseInt is for when you have a string that you need to be a number instead, and want to make sure it's interpreted as an integer rather than a float. Commented Sep 13, 2013 at 19:49
  • What do you want to do with points_per_second? Commented Sep 13, 2013 at 19:53

2 Answers 2

3

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;
Sign up to request clarification or add additional context in comments.

Comments

2
total_points = total_points + points_per_click;

Is that what you are saying??

Sorry, can't comment, not enough rep...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.