The reason you get a dodgy output is because of 2 reasons:
You get the values once and only once, so updated values will be incorrect when you call the function.
You are concatenating strings together, rather than adding strings. E.g: '5' + '2' = '52'
You should get the values inside the function, because they may change, and you should convert the values to numbers before adding them. You should also use ID's - not classes - for specific elements:
const subtotal = document.getElementById("total")
subtotal.addEventListener('click', function() {
const price = +document.getElementById("price").value,
items = +document.getElementById("items").value,
a = price + items
console.log(a)
});
<input type="number" id="price" value=5>
<input type="number" id="items" value=2>
<button id="total">Add</button>
You can write this function better like so:
const subtotal = document.getElementById("total")
subtotal.addEventListener('click', () => console.log(['price', 'items']
.reduce((a, id) => a + +document.getElementById(id).value, 0)
))
<input type="number" id="price" value=5>
<input type="number" id="items" value=2>
<button id="total">Add</button>
With this approach, you can just add an ID to the list to add that element too.