I have vast experience with C, but I'm fairly new using JavaScript. I've been searching for an explanation, but it seems like I'm not phrasing my question right. I need to tell a function which GLOBAL variable it should change. Here's the code:
<!DOCTYPE html>
<html>
<head>
<script>
function test(blah)
{
if (!window.blah)
window.blah = 0;
window.blah++;
document.getElementById(blah).innerHTML = window.blah;
}
</script>
</head>
<body>
<div id="first">0</div>
<input type="button" onclick="test('first')" value="change">
<br>
<div id="second">0</div>
<input type="button" onclick="test('second')" value="change">
<br>
</body>
</html>
The purpose of the code is to have two separate counters - clicking the first button should increment window.first while clicking the second button should increment window.second. How do I phrase this?