0

I want to make simple clicking game, but I have a problem. Let's say I have this:

var clicks = 0;

function somefunction() {
  clicks++;
}
<button onclick="somefunction()">BUTTON 1</button>
<button onclick="anothfunction()">BUTTON 2</button>

and here comes the problem. I want to count clicks on BUTTON 1, but after clicking on BUTTON 2. It will count one click as two clicks. Thank you in advance. ;-)

0

1 Answer 1

2

Have the second button set a variable that's used by the first function.

var clicks = 0;
var increment = 1;

function somefunction() {
  clicks += increment;
  console.log(clicks);
}
function anothfunction() {
    increment = 2;
}
<button onclick="somefunction()">BUTTON 1</button>
<button onclick="anothfunction()">BUTTON 2</button>

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. It helped me a lot.
Ok, I did. Thanks again. :-)

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.