(Understanding code structure)
in algebra, variables are used to represent a value that is initially unknown.
x = 1 + 2
var x = 1 + 2;
In this example, the variable “x” has been assigned the value of 3.
Variables can also hold text values by placing the text in “quotation marks.”
var x = "One";
Each field in your form can hold a value, and as such, that value can be assigned to a variable.
var x = $fieldkey_1$;
As usual, we place ‘$’ signs around our field key. Now that you have assigned “x” to the value of “fieldkey_1,” lets take it a bit further.
var x = $fieldkey_1$; var y = $fieldkey_2$; return y+b;
Let’s say in this example that “x” (fieldkey_1) has an entered value of “3,” and that y (fieldkey_2) has an entered value of “5.” This would mean that we would “return” the value of “8.”
We can also add strings together; however, there are a few things you should be aware of.
• If you are adding things together if there is at least one string, it will concatenate (combine side by side) as opposed to mathematically adding them.
• Strings can contain numbers too, and they are not just limited to text.
var x = "123"; var y = 123;
In this example, var “x” is a string, whilst var "y" is an integer (number).
If you were to add these two together, you would not get “246” you would instead get “123123.”
var x = "123"; var y = 123; return x+y; 123123