Copy link to clipboard
Copied
I am trying to create a calculation sheet that only shows the result of the calculation if there is a number put in the cells above it. The values in the cells can vary from a negative numbers to positive including zero. I am trying to use this expression but it keeps throwing "SyntaxError: syntax error 26: at line 27"
____________________________________________________
var B8 = this.getField("B8").value;
var B9 = this.getField("B9").value;
var C5 = this.getField("C5").value;
var C6 = this.getField("C6").value;
var C7 = this.getField("C7").value;
var C8 = this.getField("C8").value;
var GOAL = C7+(B9-(C8-B8))+C5-C6+25;
if( C5 != "" ) {
event.value = GOAL;
}
or ( C6 != "" )
{
event.value = GOAL;
}
or ( C7 != "" )
{
event.value = GOAL;
}
or ( C8 != "" )
{
event.value = GOAL;
}
else {
event.value = " ";
}
2 Correct answers
Replace the "or" with "else if".
The basic Boolean logical operator for "Or" is " || ". And also, when you are using a comparison operator with a logical statement to determine a difference in values (or between variables) you should employ "!==" ( not equal value or not equal type with the double equal comparison operator).
Last, in your last line, you're declaring the null statement for the event value with " " (a spcae in between the quotes); the quotes should be together "". Otherwise, you're declaring a statement bas
...Copy link to clipboard
Copied
Replace the "or" with "else if".
Copy link to clipboard
Copied
The basic Boolean logical operator for "Or" is " || ". And also, when you are using a comparison operator with a logical statement to determine a difference in values (or between variables) you should employ "!==" ( not equal value or not equal type with the double equal comparison operator).
Last, in your last line, you're declaring the null statement for the event value with " " (a spcae in between the quotes); the quotes should be together "". Otherwise, you're declaring a statement based on a value that corresponds to a single space character string inside of the quotes.
Is there a specific reason why yo needed to declare the event value like this?
I would deploy your script like this:
var B8 = this.getField("B8").value;
var B9 = this.getField("B9").value;
var C5 = this.getField("C5").value;
var C6 = this.getField("C6").value;
var C7 = this.getField("C7").value;
var C8 = this.getField("C8").value;
var GOAL = C7+(B9-(C8-B8))+C5-C6+25;
event.value = "";
if ( ( C5 !== "" ) || ( C6 !== "" ) || ( C7 !== "" ) || ( C8 !== "" ) ) {event.value = GOAL;}

