3

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

4
  • 1
    Lolz wow! so many answers all saying the same thing! how will you choose? Commented Sep 4, 2012 at 22:26
  • Lols dunno... I up voted the first 4 that I got... Commented Sep 4, 2012 at 22:26
  • I was actually going to close the post right when I found it in a google search.. But figured i would leave it open for someone else who makes the same fail mistake I did... Commented Sep 4, 2012 at 22:27
  • it's those minute syntactical details that exist in one language but not another (PHP) !! Commented Feb 15, 2013 at 23:54

4 Answers 4

5

You want to use

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

instead of the single-word "elseif"

Sign up to request clarification or add additional context in comments.

Comments

3

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

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

Comments

2

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

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.