0

I'm trying to set a variable that needs to concatenate certain pieces of string if certain conditions are met. I have tried:

var A; 
  if (B == "Waiting for access") {"Aria POS\n"}
  if (C == "Waiting for access") {"CBS\n"};

I have also tried:

var A =
   (B === "Waiting for access") ? "Aria POS\n" : "" +
   (C === "Waiting for access") ? "CBS\n" : "" ;

but this only returns the 1st string Aria POS without the 2nd string

1 Answer 1

1

The script need variable assignment. In ternary operator, it may help to enclose parentheses for multiple conditions. You could put on different line for readability.

As an example:

var A = ""; 
A += (B === "Waiting for access") ? "Aria POS\n" : "";
A += (C === "Waiting for access") ? "CBS\n" : "";
Sign up to request clarification or add additional context in comments.

2 Comments

It logs the strings but also ads undefined to it: ``` undefinedAria POS CBS ```
Because A is undefined at initialization. To fix that, simply initialize var A = "";.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.