Skip to main content
Participant
May 25, 2018
Question

If/else Statement Calculation

  • May 25, 2018
  • 1 reply
  • 282 views

I have been working on this for hours now and keep having an issue.  I am semi-new to JavaScript but Google has been less than helpful in helping me figure out this JS.

Basically I created a function in Excel a couple years ago and now need to convert this to calculate it in a pdf.

This is my Excel calculation: =IF(B4<500,1,IF(B4=500,1,IF(B4=1000,2,IF(B4>1000,(B4*0.2%),2))))

So far in Adobe I have gotten this and I have no clue if I'm semi-correct or heading in the right direction or what:

var amount = this.getField("amount").value

var z = this.getField("amount") * 0.002;

if (amount <= 500) {event.value = "1.00"}

else if (amount > 500 & <= 1000) {event.value = "2.00"}

else {event.value = z}

I keep getting this error "SyntaxError: invalid XML name 4; at line 5"

Can anyone help me with this? I've been Google-ing for hours and asked my brother, but he hasn't programmed in 10 years.

This topic has been closed for replies.

1 reply

Joel Geraci
Community Expert
Community Expert
May 25, 2018

Fix line 5... the "and" logic operator is "&&"

else if (amount > 500 && <= 1000) {event.value = "2.00"}