View Full Version : can som1 please explain what this script does

05-10-2009, 12:14 PM
hi could someone explain what this script will do? and how it works thanks

<title>Function Example</title>
<script LANGUAGE="JavaScript" type="text/javascript">
function Average(a,b,c,d) {
result= (a+b+c+d)/4;
return result;
<p>the following is the result of the function call. </p>
<script LANGUAGE="JavaScript" type="text/javascript">
score= Average(3,4,5,6);
document.write("The average is: " + score);

Philip M
05-10-2009, 12:24 PM
Is it not entirely obvious?

It calculates the average (meaning the arithmetic mean) of four numbers which are passed to the function as variables a,b,c and d. Here the four numbers are 3,4,5 and 6 and the mean is 18/4 = 4.5.

Note that <script LANGUAGE="JavaScript"> is deprecated and obsolete. Use <script type = "text/javascript"> instead.

Please do not post any more homework assignmements in this forum. It is against the rules.

Quizmaster: If something in dispute is divided equally, it is referred to as splitting the ... what?
Contestant: Atom.

05-10-2009, 08:17 PM
but this isnt a homework assignment. You could say that everyone who posts here is doing that aswell

05-10-2009, 08:47 PM
Well could you then, just for laughs, explain, in which real life application you stumbled upon this snippet, why it is so important to you to understand what it does, and, lacking any coding experience, how you got yourself into that situation in the first place.

05-10-2009, 09:19 PM
but this isnt a homework assignment. You could say that everyone who posts here is doing that aswell

No, just the users that post questions like "explain this entire script to me". Others are posting code they've worked on that they can't quite get right.

05-10-2009, 11:15 PM
well sorry i didnt kno it was such a problem to explain what something does. It doesnt have to be homework. I only wanted to understand it

05-10-2009, 11:22 PM
Great, here you go: http://www.w3schools.com/jS/js_intro.asp

If you still have trouble understanding a particular line in that script after reading through the basic chapters, ask and you will be helped.