Still Searching For My Eureka Moment With JS Callbacks :(

So I’ve got this piece of code:

function convUSDToBTC (USDAmt, USDPricePerBTC)
{
  return USDAmt / USDPricePerBTC;
}

function convBTCToUSD (BTCAmt, USDPricePerBTC)
{
  return BTCAmt * USDPricePerBTC;
}

function convUSDToETH (USDAmt, USDPricePerETH)
{
  return USDAmt / USDPricePerETH;
}

function convETHToUSD (ETHAmt, USDPricePerETH)
{
  return ETHAmt * USDCostPerGBYTE;
}

And I can’t for the life of me figure out how to integrate callbacks into it. The functions seem pretty repetitive and every time I create a new one there’s this nagging sensation in my head that callbacks might actually be useful there.

Is there a way to use callbacks with that? Do you have any real world example of callbacks that can help me finally get it?

Thanks.

I don’t think that callbacks are the answer here.

From what I can see, using one function to express what you use several functions for, seems to be the next step.

function fromUSD(USD, conversionRate) {
    return USD / conversionRate;
}
function toUSD(amt, conversionRate) {
    return amt * conversionRate;
}
3 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.