I am new to creating expressions in arcade. I don't know what I am missing. I am trying to create an expression for labeling roads. I keep getting "invalid expression error on line 10 semicolon or new line expected." I do have the "Remove extra spaces" and "Remove extra line breaks" checked too. Any advice or suggestions on how to fix this. I would appreciate it.
var words= split(upper([$feature.featurename])," ")
var upperWords=["N","NW","W","SW","S","SE","E","NE","US"]
var lowerWords=["1ST","2ND","3RD","4TH","5TH","6TH","7TH","8TH","9TH","0TH","1TH","2TH","3TH"]
var label= ""
for (var word in words)
{
var isUpper= indexof(upperWords, words[word]) >-1
var isLower= indexof(lowerWords, words[word]) >-1
if (isUpper)
label + "" words[word]+""
else if (isLower)
label + "" lower(word[words]) + " "
else
label + "" proper(words[word]) + " "
}
return label
Solved! Go to Solution.
The error is caused by a missing "+" after the first double quotes in line 10 (and line 12 and 14).
When posting code, don't use an image. Use the "Insert/Edit code sample" button. This makes it easier for us to read and copy it to check syntax.
You need curly braces around your if/elseif/else blocks:
if (isUpper) {
...
} else if (isLower) {
...
} else {
...
}
return label
You'll probably want to use label += to actually change the value of the variable, too.
You don't need curly braces for one line if/else statements (although they are good for avoiding confusion). This expression works properly
var words = ['n', '1st', 'ave']
var upperWords = ['N','W']
var lowerWords = ['1st', '2nd']
var label = ''
for (var word in words)
{
var isUpper = IndexOf(upperWords, words[word]) > -1
var isLower = IndexOf(lowerWords, words[word]) > -1
if (isUpper)
label += words[word] + ' '
else if (isLower)
label += lower(words[word]) + ' '
else
label += proper(words[word]) + ' '
}
return label
returning "N 1st Ave "
Well, I learned something new today! Had no idea that one-liners could go without braces. But one-liners can usually be replaced with Decode or When anyway.
I'm sure there's a JS-based reason this is the case, but I just don't like arbitrarily changing my formatting like that. Like, given the choice between an option that always works and an option that sometimes works, I'm gonna go with the former. Still neat, though!
How would I change the following? Currently I have O'conner Cres, I need to make the C capitalized.
The error is caused by a missing "+" after the first double quotes in line 10 (and line 12 and 14).
Thank you. It worked.
Don't forget to click "Accept as Solution" button on the post(s) that answered your question.