Is there a way in arcade to take a value and determine if it is an odd or even number? I have an if statement within a for loop and want the function to perform differently when my var i is even versus when it is odd. This is for the purpose of colouring table rows differently as I am building an HTML string from my arcade script.
Solved! Go to Solution.
Hey @CameronLacelle
This script here should help, this uses the % operator to check the remainder of the number divided by 2, if zero, then it is even, else it is odd.
var number = 7
var isEven = (number % 2 == 0)
if (isEven) {
return "Even"
} else {
return "Odd"
}
You'd replace the return with your function and you'll be set!
https://developers.arcgis.com/arcade/guide/operators/
Cody
Divide by 2 and check for a remainder. If the remainder is 0 its and even number. Use the Modulus (%) operator in Arcade to get the remainder.
Bernie.
Hey @CameronLacelle
This script here should help, this uses the % operator to check the remainder of the number divided by 2, if zero, then it is even, else it is odd.
var number = 7
var isEven = (number % 2 == 0)
if (isEven) {
return "Even"
} else {
return "Odd"
}
You'd replace the return with your function and you'll be set!
https://developers.arcgis.com/arcade/guide/operators/
Cody
Thank you
Divide by 2 and check for a remainder. If the remainder is 0 its and even number. Use the Modulus (%) operator in Arcade to get the remainder.
Bernie.