Reputation: 1559
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
Reputation: 71008
You want to use
} else if ( /*... */ ) {
instead of the single-word "elseif"
Upvotes: 5
Reputation: 6802
It should not be elseif
it should be else if
So your code becomes
else if (myClientName.indexOf("devloper") != -1) {
Upvotes: 3