I have two practically identical functions. The only difference between them are one has +
and one has -
. These are used about 20 times in each function, so I'd love to make this simpler with a var.
I'm still very new to JavaScript, so I don't know where to start, but something like:
if ( blah blah ){
var symbol = '-';
} else{
var symbol = '+';
}
var example = value1 [symbol] value2;
Thanks
Else You can use these conditions to perform different actions for different decisions. Use the if statement to specify a block of C++ code to be executed if a condition is true. Note that if is in lowercase letters.
Else C++ If ... Else You can use these conditions to perform different actions for different decisions. Use the if statement to specify a block of C++ code to be executed if a condition is true. Note that if is in lowercase letters.
AND – =IF (AND (Something is True, Something else is True), Value if True, Value if False) OR – =IF (OR (Something is True, Something else is True), Value if True, Value if False) Following are examples of some common nested IF (AND ()), IF (OR ()) and IF (NOT ()) statements.
The NOT function only takes one condition. Here are the formulas spelled out according to their logic: IF A2 (25) is greater than 0, AND B2 (75) is less than 100, then return TRUE, otherwise return FALSE. In this case both conditions are true, so TRUE is returned.
Use this:
var modifier = (blah blah) ? 1 : -1;
var example = value1 + (modifier * value2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With