Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with this piece of code

Status
Not open for further replies.

spinzer21

Technical User
Mar 1, 2010
1
GB
with this one I need is to find the difference between the numbers in first array (numberArray ) and to create new array and store in it. after running this code I get nothing in the browser.

var numberArray = [16,14,4,5]

function calculateDifferences()
{
var secondArray = new Array(numberArray.length);
for (var c = 0; c < numberArray.length - 1 ; c = c + 1)
{
secondArray[c] = difference(numberArray[c],numberArray[c+1]);
}
{
secondArray[numberArray.length - 1] = difference(numberArray[0],numberArray[numberArray.length - 1]);
}
{
return secondArray;
}
}

document.write(secondArray + '<BR>');


 
Are you actually calling your function somewhere that you have not shown us?

something like:

document.write(calculateDifferences() + "<BR>");

With what you showed us, you should be getting an error, that secondArray is not defined because its only defined inside your function. so document.write has no access to it.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top