Multiply value by amount

So I have this code, where I what with a button increase amount and by increasing amount the weight changes with it.

The result of the code below, by clicking the button innerText changes to
for example

1piece = 8 g
2piece = 16 g
3piece = 48 g -> here is the problem - I want the number increase by the first value (38 = 24), but its doing (316)

How can I fix this? The weight is not a variable set on 8, but has for every element a different value, thats why its called in const. Element are from JSON file in an array map

let amount = document.getElementById('amount');
let weight = document.getElementById('weight');

function add(el, pt) {
    {
        amount = parseInt(document.getElementById(el).innerText);
        weight= parseInt(document.getElementById(pt).innerText);
        amount++
        
        let totalPt = weight * amount

        document.getElementById(el).innerText = amount;
        document.getElementById(pt).innerText = totalPt;
    }
}```

Hi!
I am not sure but could you tell me what happens wenn you remove amount++ and insert it at the end just after document.getElementById(pt).innerText = totalPt;?
Is there any change?
Thanks!

Nothing happens, the innerText doesn’t change, I’ve put it into console.log and it shows 8 everytime i click on the button

getElementById needs a string as argument

you have el and pt which seems to be two undefined variables

otherwise please share how the function is called

Hi!

I have tried to find a solution for your question and after while I have the following approach. I hope it works. You have to put it in HTML-Editor and check it.

<!doctype html>
<html>
  <head>
    <script>
      function add(){
        const weigth = 8;
        let amount = parseInt(document.getElementById("amount").value);
        let totalPt = weigth * amount;
        document.getElementById("result").value = totalPt;
      }
    </script>
  </head>

  <body>
    Enter amount : <input id = "amount">
    <button onclick = "add()">calculate</button>
    <input id="result">
  </body>
</html>

Try to improve it!

So I actually created a const for base and then I multiplied the amount with base, pretty easy solution, didn’t know why it didn’t occure to me.