PDA

View Full Version : Javascript using arrays


ArmyWife0306
12-04-2008, 01:55 AM
I need help to make a javasvript program that will take an array as input and calculate the square root of its element. This is what I have, but I cant figure out any more. :confused: :confused:


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- Generated by AceHTM http://freeware.acehtml.com -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Using Arrays</title>
<script language="javascript">

<!-- hide script away from browsers
//define array and calculate sum of element squares
numArray = new Array (2, 5, 6, -3, 0, -7, 9, 4);
sumSquares = 0;
for (i=0; i<8; i++) {
sumSquares += numArray[i]*numArray[i];
}//for

//print results
document.write("The sum of the sqaures of these " + numArray.length + " numbers:<br />");
for (i=0; i<8; i++) {
document.write(numArray[i] + ", ");
}//for
document.write("is <h2>" + sumSquares + "</h2>");
-->

</script>
</head>
<body>
</body>
</html>