There's a two-part answer to what you're seeing:
First, every time you run the increment
function, you bind a new click event to the div
s with id
q1a
, q2a
, q3a
and q4a
. What this means is that if you have multiple click
events bound to one div, one click will run the event multiple times.
Next, these click events on q1a
, q2a
, etc. run AFTER the $('.option')
click event. Therefore, when you see the second alert at 0 points, the variable creative
is added to AFTER this alert is fired. You can see this by adding a console.log()
statement inside your q2a
click event like this:
$('#q2a').click(function(){
creative +=5;
online ++;
managerial ++;
console.log("q2a",creative);
});
Overall, you should either set up the click events inside of your increment
function at the beginning of the script OR identify which div was clicked and add values according to this - DON'T add so many click events.
Hopefully this is helpful - I can answer further questions if you have any!