Skip to main content
Participating Frequently
June 1, 2018
Answered

Syntax error 5 at line 6, but nearly identical code is accepted earlier in the script.

I've made countless attempts to change parenthesis, quotes, etc. and updated the entire script to match, but continue to get the same error in the same place.  I need help from someone smarter than I am!  Any thoughts?

*Field1 has an export value of 1, 2, or 3.

*Field2 is a number

1  var v = this.getField("Field1").value;

2  var l = this.getField("Field2");

3  if ((v==1) && (l<21)) event.value = l;

4  else if ((v==1) && (l>20)) event.value = (Math.ceil(l/2))+10;

5  else if (v==2) && (l>0) && (l<5) event.value = (l-1);

6  else if (v==2) && (l>4) && (l<9) event.value = (l-2);

7  else if (v==2) && (l>8) && (l<13) event.value = (l-3);

8  else if (v==2) && (l>12) && (l<17) event.value = (l-4);

9  else if (v==2) && (l>16) && (l<21) event.value = (l-5);

10 else if (v==2) && (l>20) event.value = (Math.ceil(l/2))+5;

11 else if ((v==3) && (l<21)) event.value = Math.floor(l/2);

12 else if ((v==3) && (l>20)) event.value = (Math.ceil((l-20)/2))+10;

13 else event.value = "";

This topic is closed to new replies. Start a new post to keep the conversation going.
Bernd Alheit
Bernd AlheitCorrect answer
Community Expert
June 1, 2018

At lines 5 to 10 add (.       )

11 replies

Legend
June 1, 2018

Line 5 is not valid, the count is perhaps one off as it often is.

I found that page I linked to has a very poor specification as it says you must have

if ( condition ) { block }

but this is also acceptable

if ( condition ) statement

Anyway, the rule that you must have brackets around the condition (even if the condition includes sub-conditions with their own brackets) is a real one.

Translate
Participating Frequently
June 1, 2018

Thanks!

Translate
Legend
June 1, 2018

Look at the difference between this line

else if ((v==1) && (l>20)) event.value = ...

which follows the rules in the article I linked to and this line

else if (v==2) && (l>0) && (l<5) event.value = ...

which does not

Similar is not good enough, you have to follow the rules.

Translate
Participating Frequently
June 1, 2018

Lines 4 and 5 had been accepted:

4  else if ((v==1) && (l>20)) event.value = (Math.ceil(l/2))+10;

5  else if (v==2) && (l>0) && (l<5) event.value = (l-1);

6  else if (v==2) && (l>4) && (l<9) event.value = (l-2);

...but not line 6.  Either way, I appreciate your input!  Got it fixed.

Translate
try67
Community Expert
Community Expert
June 1, 2018

Again, the entire if-condition needs to be inside a set of parentheses.

Translate
Legend
June 1, 2018
Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
June 1, 2018

At lines 5 to 10 add (.       )

Translate
Participating Frequently
June 1, 2018

Around what?

Translate
Bernd Alheit
Community Expert
Community Expert
June 1, 2018

Same as at line 4.

Translate