View Full Version : Why does this script return two commas?

01-02-2004, 11:25 PM
This script is supposed to convert two numeric variables to strings, store the characters of those strings into arrays and show an alert with the array values, but the alert only contains commas, so nothing was stored into the arrays, and I don't understand why. Any help is much appreaciated.

The variables sum1 and sum2 contain a numeric value (yes, I've tested that), and the variables numarray1 and numarray2 are empty arrays before this code.

//convert numeric sums to strings
sum1str = sum1 + "";
sum2str = sum2 + "";

//stores digits of sums in arrays
for(i = 0 ; i < sum1str.length ; i++)
numarray1[i] = sum1str.charAt[i];

for(i = 0 ; i < sum2str.length ; i++)
numarray2[i] = sum2str.charAt[i];

alert(numarray1 + " " + numarray2);

01-02-2004, 11:49 PM
1)make sure you have declared your arrays and there lengths.
2)use a different variable other than i for the second loop, use k or any other letter
3)change your square brackets in the part
numarray[i] = sumstr.charAt[i];

to round brackets so it becomes:

numarray(i) = sumstr.charAt(i);

and that should fix it.


01-03-2004, 02:02 PM
Thanks. All that wasn't neccessary, I just changed the brackets for charAt.