You keep resetting the score to 0 every time because it's a local variable that you initialize over and over. If you want the score to accumulate, then you must declare score in a higher level scope so its value can continue from one event to the next and only initialize it once in that higher scope, not in each event.
See a modified version of your jsFiddle here: https://jsfiddle.net/jfriend00/qoju2z7g/
I moved the definition of:
var score = 0;
to a higher scope so the value survives from one event to the next.
In your code:
document.getElementById("box").onclick = function() {
clickedTime = Date.now();
reactionTime = (clickedTime - createdTime) / 1000;
document.getElementById("box").style.backgroundColor = getRandomColor();
document.getElementById("box").style.display = "none";
document.getElementById("time").innerHTML = reactionTime + " seconds!";
var score = 0;
if (reactionTime < 1) {
score += 10;
document.getElementById("score").innerHTML = score;
} else {
score += 5;
document.getElementById("score").innerHTML = score;
}
makeBox();
}
You can see that the variable score is a local variable. It is initialized to 0 every time the click handler is called and then you increment it and it's only local to each separate invocation of the click handler so it is recreated each time, initialized to 0 each time, incremented by 5 or 10 and then thrown away each time. So, no surprise, it only ever has a value of 5 or 10.
Moving the definition and initialization of that variable to a higher scope that persists from one client event to the next allows it to accumulate a value from one click to the next.