Getting a variable out of an expression element

Hi All,

I’ve got the below set up in an expression but for the life of me I’ve not been able to work out how to extract the two variables stampduty and stampdutyRate

Any ideas on how to output these variables to a text element? The console logging works perfectly so I know the script functions as it should, I just can’t show the results :frowning:

p.s. I don’t think the script is relevant but included just in case.

var price = X Input’s value > 0 ? X Input’s value : 0;

var stampduty = 0;
var intervals = {
  0: {
    'from': 0,
    'to': 125000,
    'rate': 0
  },
  1: {
    'from': 125000,
    'to': 250000,
    'rate': 2
  },
  2: {
    'from': 250000,
    'to': 925000,
    'rate': 5
  },
  3: {
    'from': 925000,
    'to': 1500000,
    'rate': 10
  },
  4: {
    'from': 1500000,
    'to': parseInt(price),
    'rate': 12
  }
};

for(var interval in intervals) {
  if(price > 1500000 || intervals[interval]['from'] == 0 || price > intervals[interval]['from']) {
    
    if(price < intervals[interval]['to']) {
      intervals[interval]['to'] = price;
    }
    
    intervals[interval]['due'] = ((intervals[interval]['to'] - intervals[interval]['from'])/100)*intervals[interval]['rate'];
    stampduty += intervals[interval]['due'];
    
  } else {
    delete intervals[interval];
  }
}

var stampdutyRate = (Math.round((stampduty/price)*10000))/100;

console.log(stampduty, stampdutyRate)

Add this as the last line: [stampdutyRate, stampduty];

And set the return type to a list of numbers as shown below:

Screenshot 2022-08-10 at 3.44.18 PM

This topic was automatically closed after 70 days. New replies are no longer allowed.