Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error near "elseif" Javascript

I have recently started having a need to start learning Java Script. My application is MVC 3, VB.NET. In one of my views I have the following snippet of javascript that simply looks at the clientName from a SignalR message and decides on the correct color to display that message based on if the string contains a certain string. The code snippet is as follow:

   chat.addMessage = function (myClientName, message) {
        if (myClientName.indexOf("System") != -1) {
        $('#messages').append('<br><b style="color:red">'+ myClientName + message + '</b>');
        }

        elseif (myClientName.indexOf("devloper") != -1) {
        $('#messages').append('<br><b style="color:Blue">'+ myClientName + message + '</b>');
        }
        else
        {
        $('#messages').append('<br>' + myClientName + ' : ' + message);
                    }

        if (autoScroll) {
            $('#messages').animate({ scrollTop: $('#messages').prop('scrollHeight') })
        }
    };

The problem is the elseIf line is not liking the french brace on the end... its saying I need a ";" I guess I could do away with the elseIf and just use an if but seems lame way to work around the issue...

like image 879
Skindeep2366 Avatar asked Aug 07 '26 21:08

Skindeep2366


1 Answers

You want to use

} else if ( /*... */ ) { 

instead of the single-word "elseif"

like image 93
Ben Zotto Avatar answered Aug 10 '26 09:08

Ben Zotto



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!