Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-20-2009, 03:13 AM   PM User | #1
Mary U
New Coder

 
Join Date: Feb 2009
Posts: 23
Thanks: 4
Thanked 0 Times in 0 Posts
Mary U is an unknown quantity at this point
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
Mary U is offline   Reply With Quote
Old 03-20-2009, 03:57 AM   PM User | #2
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,764
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
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>
jmrker is offline   Reply With Quote
Old 03-20-2009, 11:28 PM   PM User | #3
Mary U
New Coder

 
Join Date: Feb 2009
Posts: 23
Thanks: 4
Thanked 0 Times in 0 Posts
Mary U is an unknown quantity at this point
Operator error. I appreciate your help. I think I may be losing my mind!
Mary U is offline   Reply With Quote
Old 03-21-2009, 12:06 AM   PM User | #4
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,764
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
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!
jmrker is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:01 PM.


Advertisement
Log in to turn off these ads.