I successfully use php implode fucnction to display drink types. Please see below code.
<?php
echo 'Type:';
$types = array();
if ($a == 1) {$types[] = 'Pepsi';}
if ($b == 1) {$types[] = 'Mirinda';}
if ($c == 1) {$types[] = '7up';}
echo implode(', ', $types);
?>
Now I need to do that with jquery i.e. create array using if statements and then join them. Could you help me to modify the code below to get the expected result.
$( "#view" ).html(
'<div>+
'Type:'+
(a == 1?"Pepsi, " :"") +
(b == 1?"Mirinda, " :"") +
(c == 1?"7up, " :"")+
'</div>');
I tried in this way but it did not work:
$( "#view" ).html(
'<div>+
'Type:'+
(a == 1?types[] = 'Pepsi' :types[] = '') + //syntax error
(b == 1?types[] = 'Mirinda':types[] = '') + //syntax error
(c == 1?types[] = '7up' :types[] = '')+ //syntax error
types.join(',');
'</div>');