Please select a category and click GO
UK Residents: Get great deals on high quality designer bathroom fittings from plumbfit.com

Plumbfit: Basin mixers, showers, taps, towel radiators Plumbfit: Bathroom showers, taps, towel radiators Plumbfit: Bathroom taps, showers, taps, towel radiators Plumbfit: Concealed showers, taps, towel radiators Plumbfit: Exposed showers, taps, towel radiators Plumbfit: Towel rails, showers, taps, towel radiators

Go Back Community for Webmasters & Developers > Client-Side Technology Forums > JavaScript Forum
Reload this Page need help calculating an average
Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
JavaScript Forum Pop-up, rollover, and drop-down to open a window on an object-oriented buzz session. Cookies will be served. DOM Perignon is also available for a truly vintage JavaScript experience.

Time:
Scotland: Sat, 3:55 am
Rhode Island: Fri, 10:55 pm
Florida: Fri, 10:55 pm
New Mexico: Fri, 8:55 pm
California: Fri, 7:55 pm

Click here to visit Livelife365.com

Click here to visit nmdarts.com



Buy this Ad Space.

180px wide.

Please get in touch with KH@ if you are interested and make an offer.

Selanac Embroidery and Screen Printing

Embroidery
Screen Printing
Signs and Banners
Promotional Advertising

WEBSITE

Contact Paul Canales
TEl: USA 732-901-8417
CELL: USA 732-773-1339


Please click here for more information

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-04-2010, 08:29 PM
badgirlkelly badgirlkelly is offline
Citizen
 
Join Date: Feb 2010
Posts: 2
badgirlkelly is on a distinguished road, wearing high heels and a tiara
need help calculating an average

Hi

Can anyone help me try and sort this out please

the idea here is to find out the average height out of the three backs of numbers

height 15,16,17,18,19
number of 4,5,11,10,6
then i have to multiply them which gives me
60,80,187,180,114

here is the maths side of it

Total of height 60+80+187+180+114= 621
Total of number 4+5+11+10+6 = 36

621/36= 17.25

Average height is 17.25cm

what i am trying to do is get the script to give me the average height. been trying for a while now but all i get is
Quote:
< The average of the plants 60,80,187,180,114 is 0

anyone help this poor girl stop getting tormented by the script from hell and give me my life back

love
kelly
xxx


Code:
<<HEAD>
<TITLE>
averages
</TITLE>

<SCRIPT LANGUAGE = "JavaScript">
 

//Experimental results of Table 1 stored in arrays.
var height = [15,16,17,18,19];
var number = [4,5,11,10,6];

//Part (ii).
//Write code to declare and initialise new array to represent the third row of the table.
var myarray = new Array(5)
var myarray = ["60","80","187","180","114"] ;

//Part  (iv).
//Write code to calculate the average height and write it out in the browser window.
var values = [60, 80, 187, 180, 114];
var total = 0;

for ( var i = 0; i < values.length; ++i)
var averageDivisor = 0;

for (var i = 0; i < number.length; i++)
     averageDivisor += number[i];

var myarray = total / averageDivisor;


document.write("The average height " + values.join(",") + " is " + myarray);

</SCRIPT>

</HEAD>
<BODY>
</BODY>
</HTML>
Reply With Quote
  #2  
Old 02-05-2010, 07:21 PM
coothead's Avatar
coothead coothead is offline
Citizen
 
Join Date: Feb 2003
Location: Chertsey, a small town 25 miles south west of London, England.
Posts: 614
coothead is a jewel in the rough, just bad at golf coothead is a jewel in the rough, just bad at golf
Hi there badgirlkelly,

and a warm welcome to these forums.

Have a look at this example, hopefully, it may give you your life back
Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english"> 
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">

<title></title>

<style type="text/css">
form {
    width:270px;
    padding:20px;
    border:3px double #999;
    margin:auto;
 }
form h1 {
    margin-bottom:20px;
    font-size:16px;
    text-align:center;
 }
form div {
    height:25px;
    margin-bottom:8px;
    vertical-align:top;
 }
form select{
    display:none;
 }
</style>

<script type="text/javascript">

function calculate(){ 

  document.forms[0].reset();

  s=[];
  op=[];
  hgt=[];
  num=[];
  totalHeight=[];
  totalNumber=[];

for(k=0;k<6;k++) {
   s[k]=document.createElement('select');
   for(c=0;c<21;c++) {
   op[c]=document.createElement('option');
   op[c].setAttribute('value',c);
   op[c].appendChild(document.createTextNode(c))
   s[k].appendChild(op[c]);
 }
  document.getElementById('d'+k).appendChild(s[k]);
 }
  cb=document.forms[0].getElementsByTagName('input');
  sel=document.forms[0].getElementsByTagName('select');

for(c=0;c<cb.length;c++){
if(cb[c].type=='checkbox') {
   hgt[c]=0;
   num[c]=0;
   totalHeight[c]=0;
   totalNumber[c]=0;
   cb[c].number=c;
   sel[c].number=c;

cb[c].onclick=function(){ 
if(this.checked==true){
   sel[this.number].style.display='inline';
   hgt[this.number]=parseFloat(this.value);
 }
else {
   sel[this.number].style.display='none';
   hgt[this.number]=0;
  }
 }

sel[c].onchange=function(){
    num[this.number]=parseFloat(this.value);
    totalHeight[this.number]=num[this.number]*hgt[this.number]
    totalNumber[this.number]=num[this.number];
   }
  }
 }

document.getElementById('calc').onclick=function() {
   th=0;
   tn=0;
for(c=0;c<totalHeight.length;c++) {
   th+=parseFloat(totalHeight[c]);
   tn+=parseFloat(totalNumber[c]);
 }
   av=th/tn;
if(isNaN(av)) {
   av=0;
 }
   document.getElementById('result').firstChild.nodeValue='The average height is '+av.toFixed(2)+'cms';
  }


document.getElementById('res').onclick=function() {
   document.getElementById('result').firstChild.nodeValue='';
for(c=0;c<sel.length;c++) {
if(sel[c].style.display=='inline') {
   sel[c].style.display='none';
   hgt[c]=0;
   num[c]=0;
   totalHeight[c]=0;
   totalNumber[c]=0;
    }
   }
  }
 }

if(window.addEventListener){
   window.addEventListener('load',calculate,false);
 }
else { 
if(window.attachEvent){
   window.attachEvent('onload',calculate);
  }
 }
</script>

</head>
<body>

<form action="#">
<h1>average height calculator</h1>
<div id="d0">
<label for="c0">15cms :</label><input id="c0" type="checkbox" value="15">
</div>

<div id="d1">
<label for="c1">16cms :</label><input id="c1" type="checkbox" value="16">
</div>

<div id="d2">
<label for="c2">17cms :</label><input id="c2" type="checkbox" value="17">
</div>

<div id="d3">
<label for="c3">18cms :</label><input id="c3" type="checkbox" value="18">
</div>

<div id="d4">
<label for="c4">19cms :</label><input id="c4" type="checkbox" value="19">
</div>

<div id="d5">
<label for="c5">20cms :</label><input id="c5" type="checkbox" value="20">
</div>

<div>
<input id="calc" type="button" value="calculate">
<input id="res" type="reset" value="clear">
</div>

<div id="result">&nbsp;</div>
</form>

</body>
</html>
coothead
Reply With Quote
  #3  
Old 02-05-2010, 08:14 PM
badgirlkelly badgirlkelly is offline
Citizen
 
Join Date: Feb 2010
Posts: 2
badgirlkelly is on a distinguished road, wearing high heels and a tiara
Hi

Thanks for the help
i have now got it working

thanks
kelly
Reply With Quote
  #4  
Old 02-05-2010, 08:17 PM
coothead's Avatar
coothead coothead is offline
Citizen
 
Join Date: Feb 2003
Location: Chertsey, a small town 25 miles south west of London, England.
Posts: 614
coothead is a jewel in the rough, just bad at golf coothead is a jewel in the rough, just bad at golf
No problem, you're very welcome.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
JavaScriptHow to workout average of numbers Smilin JavaScript Forum 3 06-07-2006 02:33 AM
JavaScriptSorting integers in ascending and descending order mdunn JavaScript Forum 31 06-01-2003 08:28 AM
Average Day in Web Development JMG General Development and Computers Forum 1 12-22-2000 10:00 AM


All times are GMT +1. The time now is 03:55 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright ©2002 - 2010, WebXpertz.com. All Rights Reserved.