My brain hurts. I cant manage to get the function to update a different variable depending on what the parameter says the variable is. I have been looking at this for a while and I am not that good at JavaScript. Can anyone help me? Also not sure if i have forgotten anything.
<input type="number" value="0" id="input2"/>
<button id="plus2" onclick="runPlus('input2', total2, 3)">+</button>
<input type="number" value="0" id="input2"/>
<button id="plus2" onclick="runPlus('input2', total2, 3)">+</button>
<p>$<span id="total"></span></p>
<script>
const total = document.getElementById('total');
var total1 = 0;
var total2 = 0;
function getId(id) {
return document.getElementById(id);
};
function runPlus(inputNum, totalNum, worth) {
const currentValue = Number(getId(inputNum).value) || 0;
getId(inputNum).value = Math.round(currentValue) + 1;
totalNum = Number(getId(inputNum).value) * worth; //This line is not working
refresh();
};
function refresh() {
return total.textContent = total1 + total2;
};
</script>