Building online calculator, unsure how to structure coding logic in JavaScript? [closed]

As a personal project I am trying to code this calculator (https://www.omnicalculator.com/finance/cpc-cpm), however I need some help.

I am unsure how to approach the Javascript logic here? There are 6 fields, and a user can type data into any one of them and it will auto-populate the others when it has the necessary data.

I am not asking for a full coding help, just some hints as to how to approach the logic?

These are the basic formulae I assume the calculator uses:

  1. clicks = impressions * (CTR / 100)
  2. total cost = (impressions * (CTR / 100)) * CPC
  3. CPM = ((impressions * (CTR / 100)) * CPC) / impressions * 1000

But how do they ensure the reverse calculations are done in real-time? Any ideas?

Much appreciated,
Adam