Skip to main content
stfr
Participant
September 24, 2021
Answered

Unexpected token 'if'

  • September 24, 2021
  • 2 replies
  • 1163 views

Hi,

i do have a little Problem with my Expression:


b = effect("StartPlus")("Punkt")[1];


a = if (786,1<b){786,1}else{b};


[960,a];


every single time there is this error: "SyntaxError: Unexpected token 'if'"

Does someone knows why? Because i don't get it - but im a bit new to the expressions topic

 

 

This topic has been closed for replies.
Correct answer OussK

As i know you can't use "if" in a variable, also i'm not sure what you mean with ","? it is wrong and you want to use "." or you mean a array with 2 values?

anyway if it's "." your expression should looks like this 

b = effect("StartPlus")("Punkt")[0];
function funName() {if (786.1<b)
{
return 786.1
}
else
{ return b}};
a = funName();
[960,a];
 

2 replies

OussK
Community Expert
OussKCommunity ExpertCorrect answer
Community Expert
September 25, 2021

As i know you can't use "if" in a variable, also i'm not sure what you mean with ","? it is wrong and you want to use "." or you mean a array with 2 values?

anyway if it's "." your expression should looks like this 

b = effect("StartPlus")("Punkt")[0];
function funName() {if (786.1<b)
{
return 786.1
}
else
{ return b}};
a = funName();
[960,a];
 
Community Expert
September 24, 2021

786,1 is not an array so you can't compare it to b. The if statement would need to read if([786, 1] < some other array) to make any sense.

 

b is defined as the second value in an array generated by the "StartPlus/Punket" property. If you wanted to use b in the if statement then it would have to read if ( 786 < b) so you are comparing apples to apples. 

 

I'm not exactly sure what you are trying to do but the expression you wrote says "b equals a single value and if a value comprised of one number, a comma and another number is less than the single value of be, do something." Unfortunately, that doesn't make any sense.