Skindeep2366
Skindeep2366

Reputation: 1559

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...

Upvotes: 3

Views: 715

Answers (4)

zerkms
zerkms

Reputation: 254926

There is no elseif in JavaScript. Instead you should use else if

Upvotes: 2

Ben Zotto
Ben Zotto

Reputation: 71008

You want to use

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

instead of the single-word "elseif"

Upvotes: 5

Deepak
Deepak

Reputation: 6802

It should not be elseif it should be else if So your code becomes

else if (myClientName.indexOf("devloper") != -1) { 

Upvotes: 3

Jo&#227;o Silva
Jo&#227;o Silva

Reputation: 91319

It's else if, separated with a space, not elseif.

Upvotes: 2

Related Questions