0

Intellisense pretty much stops working as soon as I call function "meanValue"

I think I narrowed it down but I can't quite figure it out. Apparently there is something wrong with the function "meanValue" because after I call it within another function, all forms of intellisense stop working...Here is my code. Intellisense doesnt work for everything inside function test after I call the meanValue function...

I have no clue the meanValue function seems fine to me?? // EDIT: I've narrowed it down. Apparently any function where I have If(arr[0].length) type of syntax, it pretty much fails. One thing to note that is the functions run fine and debug fine but for some reason intellisense doesnt like this.

Anyone know what another way to check if something is defined or not? I want to check to see what kind of array I am looking at, if its a multidimensional array or not.

Thanks!!! //

<script language="javascript" type="text/javascript">

    function meanValue(arr) {
        var mean;
        var sum = 0;

        if (arr[0].length) {
            for (var j = 0; j < arr[0].length; j++) {
                sum += arr[0][j];
            }
            mean = (sum) / arr[0].length;

        }
        else {
            for (var i = 0; i < arr.length; i++) {
                sum += arr[i];
            }
            mean = (sum) / arr.length;


        }
        return mean;
    }

    function test(a, b) {
        var testing = 5;
        var oranges = meanValue(a);

     }
     var a = [1, 3, 4];
     var b = [4, 5, 6];

</script>
6
  • In addition to what @robert said, you are trying to treat a single dimension array as a multidimensional array. This will cause logic errors at least. Commented Aug 7, 2011 at 1:08
  • wait what?? The if statement sees whether or not arr[0].length is defined meaning that if it is not defined then it is not a multi-dimensional array and it goes to the else statement. Commented Aug 7, 2011 at 1:11
  • Ah I see what you did there. That makes sense. Commented Aug 7, 2011 at 1:17
  • I wish I could figure out the problem because it all looks good on my end but for some reason as soon as I call that function from test(), intellisense just gives up. Commented Aug 7, 2011 at 1:19
  • and what is this in? VS? Commented Aug 7, 2011 at 1:27

2 Answers 2

1

In test() you have a variable testing, that has nothing assigned to it after =. That could be one of the problems.

Who is calling test()?

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

2 Comments

I run your code and oranges is 2.6666. Also add var in front of a and b. Also you might want to return something from test(), true or orange.
Try to write something after "var testintoranges = meanValue(a);" and let me know if intellisense works?? Thnx i fixed the var infront of a and b. I know the code runs and everything is fine, but intellisense is pretty crucial to me because I am writing numerous other functions and if it decides to just stop working I need to figure out the reason??
0

I was able to reproduce the issue in my Netbeans.

The problem seems to stem from a mixing of two languages in one file for certain IDEs. (Is this a .php file with some Javascript in it?)

For some reason, the IDE intellisense engine is trying to parse the less-than (<) symbol in that chunk of code as if it were trying to validate XML, which Javascript isn't. So, of course, it's failing.

Try wrapping that code in [CDATA -- it should resolve the issue.

So the example above, modified, would be:

<script language="javascript" type="text/javascript">
//<![CDATA[ 
    function meanValue(arr) {
        var mean;
        var sum = 0;

        if (arr[0].length) {
            for (var j = 0 ; j < arr[0].length ; j++) 
            {
                sum += arr[0][j];
            }

            mean = (sum) / arr[0].length;
        }
        else 
        {
            for (var i = 0; i < arr.length; i++) {
                sum += arr[i];
            }
            mean = (sum) / arr.length;
        }
        return mean;
    }

    function test(a, b) {
        var testing = 5;
        var oranges = meanValue(a);
    }

    var a = [1, 3, 4];
    var b = [4, 5, 6];
//]]>
</script>

3 Comments

I edited the original post. Something is wrong with the meanValue function because intellisense does not work for any lines of code within test() after I say "var oranges = meanValue(a)"
Same thing. I notice the problem with intellisense is if the function i am using has somwhere the code "if (a[0].length) {}" it pretty much fails.
I accepted the answer, thanks man. I'm going to try it tomorrow and see if it works. Would be pretty awesome if it did. Thanks again, Cheers.

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.