Texan78 Texan78 - 4 days ago 6
Javascript Question

Properly addressing "Uncaught SyntaxError: Unexpected token )" error

In my console I am getting the


Uncaught SyntaxError: Unexpected token )


I know why I am getting this error but, not sure how to resolve it as all of the methods I have tried have not been successful.

This is the snippet of code it is in.

var contentDetails = '<div id="iw-container">'+
'<div class="iw-title">' + ((value.streamStatus == 'true') ? ('<span class="online"><i class="material-icons" style="vertical-align:-3px; font-size:18px;">videocam</i></span> ') : ('<span class="offline"><i class="material-icons" style="vertical-align:-3px; font-size:18px;">videocam_off</i></span><strong> ' )) + value.DisplayName + ' - ' + value.ChaserLocation + '</strong><hr /></div>'+
'<div class="iw-content">'+
'<p>Location: ' + value.UserLocation + '<br />'+
'Heading: ' + value.UserHeading + '<br />'+
((value.streamStatus == 'true') ? ('Stream: <span class="online">Online</span><br />') : ('Stream: <span class="offline">Offline</span><br />'))+
((value.streamStatus == 'true') ? ('Viewers: ' + value.CurrentViewers + ))+
'</div>';


The specific line of interest where the error is come from is the second to last.

((value.streamStatus == 'true') ? ('Viewers: ' + value.CurrentViewers + ))+


Any assistance with how I can properly close this line?

Answer

You need to update from this:

((value.streamStatus == 'true') ? ('Viewers: ' + value.CurrentViewers + ))

To this:

((value.streamStatus == 'true') ? ('Viewers: ' + value.CurrentViewers) : '')

The 2 changes are adding the "false" option in the ternary expression and removing the extra "+"

Comments