...

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



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

<html>
<head>
<title>Function Example</title>
<script LANGUAGE="JavaScript" type="text/javascript">
function Average(a,b,c,d) {
result= (a+b+c+d)/4;
return result;
}
</script>
</head>
<body>
<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);
</script>
</body>
</html>

Philip M
05-10-2009, 11:24 AM
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.

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

venegal
05-10-2009, 07: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.

bdl
05-10-2009, 08: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.

deldel
05-10-2009, 10: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

venegal
05-10-2009, 10: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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum