Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Array Question

  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    23
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Array Question

    I am attempting to do some basic array work.

    Here I am accepting an array, and a value of a variable to perform multiplication against my array, then write the product back into the array.

    However this never seems to resolve, I never get an alert box with my result.

    Can someone tell me where I have gone astray?



    function applyfunction(array, value){
    var arr1 = [];
    for (var i = 0; i < array.length; ++i) {
    var elm = array[i];
    elm = elm * value;
    arr1[i] = elm;
    }
    return arr1;
    }
    var arr1 = [1,2,3];
    var ans = applyfunction(arr1,5);
    alert(ans);

    I appreciate any help, I've been fiddling with this for a week and just want to get some output!

    Mary

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,077
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Question More information about problem please ...

    I'm not sure what the problem is.
    This works fine for me in FF and MSIE.
    Code:
    <html>
    <head>
    <title>Array Multiplier</title>
    <script type="text/javascript">
    function applyfunction(array, value){
      var arr1 = [];
      for (var i = 0; i < array.length; ++i) {
        var elm = array[i];
        elm = elm * value;
        arr1[i] = elm;
      }
      return arr1;
    }
    var arr1 = [1,2,3,4,5,6,7,8,9,10];
    var ans = applyfunction(arr1,5);
    alert(ans);
    </script>
    </head>
    <body>
    
    </body>
    </html>

  • #3
    New Coder
    Join Date
    Feb 2009
    Posts
    23
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Operator error. I appreciate your help. I think I may be losing my mind!

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,077
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Thumbs up

    Quote Originally Posted by Mary U View Post
    Operator error. I appreciate your help. I think I may be losing my mind!
    I have not lost my mind yet, but it does seem to wander away once in a while!

    Glad I could help.
    Good Luck!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •