Rather than use an if else statement, I’m trying to use the ternary operator but have a syntax error somewhere in my statement.
Can someone tell me where I am going wrong?
Statement is:
my_alert(status ? ('Accepted', 'alert-success') : ('Declined', 'alert-info'))
- my_alert is a function which has 2 parameters.
- Status just evaluates to true or false.
- When I pass more than 1 parameter into the above expression, it doesn’t like the use of the comma.
In chrome and firefox when the function runs it displays ‘alert-success’ or ‘alert-info’. It misses out the first parameter.
I’ve looked on stackoverflow for the answer but by all means it’s telling me that what i’m doing is correct.
Any help would be great.
Alternatively, you could just wrap the function call in the ternary statement…
UPDATE:
Robin van Baalen makes a good suggestion…