Select to view content in your preferred language

Arcade expression error

349
8
Jump to solution
3 weeks ago
KimberlyMoran
New Contributor

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
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

The error is caused by a missing "+" after the first double quotes in line 10 (and line 12 and 14).

View solution in original post

0 Kudos
8 Replies
KenBuja
MVP Esteemed Contributor

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.

0 Kudos
jcarlson
MVP Esteemed Contributor

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.

- Josh Carlson
Kendall County GIS
0 Kudos
KenBuja
MVP Esteemed Contributor

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 "

0 Kudos
jcarlson
MVP Esteemed Contributor

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!

- Josh Carlson
Kendall County GIS
0 Kudos
KimberlyMoran
New Contributor

How would I change the following? Currently I have O'conner Cres, I need to make the C capitalized. 

0 Kudos
KenBuja
MVP Esteemed Contributor

The error is caused by a missing "+" after the first double quotes in line 10 (and line 12 and 14).

0 Kudos
KimberlyMoran
New Contributor

Thank you. It worked. 

0 Kudos
KenBuja
MVP Esteemed Contributor

Don't forget to click "Accept as Solution" button on the post(s) that answered your question.

0 Kudos