...

View Full Version : Array Question



Mary U
03-20-2009, 03:13 AM
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

jmrker
03-20-2009, 03:57 AM
I'm not sure what the problem is.
This works fine for me in FF and MSIE.


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

Mary U
03-20-2009, 11:28 PM
Operator error. I appreciate your help. I think I may be losing my mind!

jmrker
03-21-2009, 12:06 AM
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! :D

Glad I could help.
Good Luck!
:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum