Click to See Complete Forum and Search --> : Javascript program that uses a function


highspeed4eva
04-23-2007, 02:02 PM
:confused: I have a homework assignment and I am officialy stumped any help will be greatly appreciated. This is what the assignment asks:

Write a JavaScript program that uses a function which takes an array as input and calculates the square roots of its elements.

I have written the following code:

<?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>Chpter 20 hw20.4</title>
<script language="javascript">

function squares (numArray) {
len = numArray.length;
for (i=0; i<len; i++); {


document.write("The square root of these" + len + "numbers:<br /">
for(i=0; i<len; i++) {
document.write(numArray[i] + ",");
}

document.write ("are <h2>" + squares + "</h2>");
}

numArray = new Array (2, 4, 6, 8, 10);

squares(numArray);



</script>

</head>

<body>
</body>

</html>

Znupi
04-23-2007, 02:08 PM
As many would say, this is not the place to get your homework done. I'll give you a hint though, what you need is:

Math.sqrt(float n);

:)