# How To Find / Calculate Average Number

Feb 1, 2010

I need to find the average number in javascript. It is the only bit of javascript that I have to do in the course but it carries a high mark of which I cannot afford to lose. Any way the question is : "Write code to calculate the average height and write it out in the browser window"

<SCRIPT LANGUAGE = "JavaScript">
//Experimental results of Table 1 stored in arrays.
var Height = [15,16,17,18,19];
var Number = [2,1,6,4,2];

//Part (ii).
//Write code to declare and initialise new array to represent the third row of the table.
var avg = new Array(5)
var avg = ["60","80","187","180","114"] ;
avg[0] = "60";
avg[1] = "80";
avg[2] = "187";
avg[3] = "180";
avg[4] = "114";
//Part (iv).
//Write code to calculate the average height and write it out in the browser window.
avg = 0;
for (var count = 1; count <= 5; count = count + 1)
Array.average = function(){
var avg = 0;
for(var a = 0; a < this.length; a++){
avg += this[a];
} return avg / this.length;
};

document.write('average height is ' +avg + '<br>');
</BODY></HTML>

## Code For Window.confirm() Function - Find The Number Of Days - Calculate And Display The Total Cost?

Dec 6, 2010

I am having some difficulty in constructing a window.confirm() function that works with my code.So if the form data is valid, I need to use a window.confirm() dialog box to show the user's total cost based on the rental rate of equipment chosen and the reservation period. The user must accept the cost by pressing the confirm button, and if user cancels do not submit data.I have written this code but cannot figure out how to find the number of days from the 2 date fields and use that to calculate and display the total cost.

//confirm submit and display rental cost
var equip = document.forms[0].equipment.value
var pDate = document.forms[0].pickupDate.value[code].....

## Calculate Average From Dynamic Input?

Jul 12, 2010

i am trying to create a interface to average down variable amount of input and show them on screen as they type....this is what i came up with.....and the input box fields....these are dynamically created...

<input type="text" name="datup[0][4]" size="3" onchange="calc()" >
<input type="text" name="datup[1][4]" size="3" onchange="calc()" >
<input type="text" name="datup[2][4]" size="3" onchange="calc()" >

[code]....

## How To Calculate Average (Mean) Of Session Variables

Aug 2, 2009

My knowledge of programming is very limited. I would like to calculate the average of session variables in Interpreted Java. However, some of session variables may not always be available. The first thing I do is remove the non numerical portion of the session variables:

String [] variables = {"A",'B','C','D','E'};
i = 0;
Iterate through each variable in the array above
while (i < variables.length){
Get the variables to be fixed
value = session.getVariable(variables[i]);
Log the UNFIXED values
session.log("UNFIXED: " + variables[i] + " = " + value);
if(value != null){
Remove non-numerical elements
value = value.replaceAll("\\D", "");
Set variables with new values
dataRecord.put(variables[i], value);
session.setVariable(variables[i], value);
Log the FIXED values
session.log("FIXED " + variables[i] + " = " + session.getVariable(variables[i]));
} i++;
}

Then I make sure the session variables can be treated as numbers:
A = Integer.parseInt(session.getVariable("A")).intValue();
B = Integer.parseInt(session.getVariable("B")).intValue();
C = Integer.parseInt(session.getVariable("C")).intValue();
D = Integer.parseInt(session.getVariable("D")).intValue();
E = Integer.parseInt(session.getVariable("E")).intValue();
Are they still alive?
session.log("A**" + A + "**");
session.log("B**" + B + "**");
session.log("C**" + C + "**");
session.log("D**" + D + "**");
session.log("E**" + E + "**");

I would like to calculate the average of A and B and save it as session variable AB, calculate the average of C and D and save it as session variable CD, and then the average of AB, CD, and E. Here's the weird part; AB, CD, and or E will not always be available. For example, AB will not be available so I need to calculate the average of CD and E or E will not be available so I need to calculate the average of AB and CD. As I said, my knowledge of programming is very limited so if you could provide code snippet with explanation of each step and where to plug in my session variables.

## Unable To Execute Function Designed To Calculate The Average Of Numbers Inputted?

Oct 4, 2010

I've been messing with this code for about a couple of hours, and I did everything down to the wire..yet still I am unable to get it to work. When I input the numbers, and click off to the side nothing appears down at the final textarea of the form which is suppose to show the average.I've tried just about everything, sadly all I have to go by is other example codes, and the very intricate instructions which states I must pass the values to the calcAvg() to the second function of performCalc(), which I did, and then I assigned the var calcResult another value. From there I did the return..and after that I'm rather loss as to what to do next to get this code to work, any tips?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

[code]....

## Getting Average In 20 Input Number?

Sep 18, 2010

can i ask how to make this problem?input 20 number and print the average of the numbers..

## Find The Average Of The Values In An Array Of Numbers Passed As Argument To A Function?

Apr 20, 2009

How do i use a function to find the average of the values in an array of numbers passed as argument to a function.(using java script) thank you for your help...

## Calculate The Percentage Of A Number?

Apr 12, 2011

I want to calculate the percentage of a number, but I'm getting a really weird result. In the following code f is equal to 3 and x.length is equal to 8. The part that isn't working is emphasised in bold. Basically 3/8 * 100 should result in 37.5 but the result I am getting with the following code is 7934570.3125. How do you calculate this percentage in Javascript?

function displaymember()
{
var m = 1;

[code]...

## Calculate Number Of Nights?

Dec 8, 2009

I have a form that posts a Date In and a Date Out to another form. The variables are datein and dateout in format mm/dd/yyyy Trying to use this function to calculate number of nights :

Code:
<SCRIPT LANGUAGE=javascript>
<!--
function DateDifference()
{
date1= Date.parse(form.datein.value)

[Code]...

## Calculate The Number Of Days Between Two Dates?

Sep 28, 2010

I want to calculate the number of days between two dates.

Date is in the below format:
First Date : 2010-09-27 05:00:00
Second Date : 2010-10-1 08:00:00

## Calculate Number Of Weeks Between Two Selected Dates

Oct 25, 2010

I am new to Java scripts. But at my job, my boss asks me to come up with a calculator that calculates the number of weeks on our website. But I want two calenders where in the first one the user will select the start date and in the second one, the user will select the end date. And There will be one last button that says"calculate" and a text box to display the number of weeks.

## JQuery :: Calculate Number Of Inputs Where Name Starts With Name^ And Input Value Is>0?

Sep 8, 2010

I have many inputs with name totalsum1,totalsum2,totalsum3 etc. I need to calculate number of inputs where name starts with "totalsum" and value is >0. I need to send result to another input with id="#rowtotal".My code:

\$("#rowtotal").val((\$("input[name^=totalsum]").val>0).size()); It's not working. Best RegardsRafa‚ Koszyk

## JQuery :: Calculate Number Of Months Between Date Ranges?

Aug 3, 2010

For a project that would be too hard to explain, I am working with date ranges. There is a begin date and an end date. With those two variables, I need a function to calculate the number of months between both dates. To be more precise, I need a count of all unique month names in the dates (or month numbers if that is easier) where the range includes the beginning date, the end date, and all dates in between. So I am not looking for full months or an approximation. If only, say, one day of a given month is included in the date range, that adds a month. Also the range can span several years, january 2010 and january 2011 need to count for two different months.

## Program - User Must Enter Number Of Books And Price And Then Calculate The Total Cost Of Items

May 4, 2011

I have a program in which a user must enter number of books and price and then calculate the total cost of the items, i have tried and tried to get it working to no effect can anyone see where i have went wrong.

## Find The Largest Number?

Sep 23, 2010

I am working on my assignment: The assignment is: The process of finding the largest value (i.e., the maximum of a group of values) is used frequently computer applications. Write a Javascript program that input a series of 10 single digit numbers as characters, determines the largest of the number and output XHTML text that displays the largest number. Your program should use 3 variables as follows:

a.) COUNTER: A counter to count to 10 (i.e. to keep track of how many number have been input and to determine when all 10 number have been processed). b.) NUMBER: The current digit input to the program.

c.) LARGEST: The largest number found so far.

Below is my code so far:

[Code]...

## Find And Replace A Number

Feb 12, 2011

When I find a record such as this in a textarea:

[Code]....

There will be from 1 to 4 Pts, if one is missing there will not be a next one. My problem is I replace the first occurrence of any number I find and for certain factors (2 in this case) it could change an already converted number and leave other fields in the record alone. I could split the line on commas to change the first number I find but can't be certain if there are no other commas elsewhere on the line.

## Find The VIN Number And Store It In A Variable?

Nov 8, 2009

FRom this page: [URL]I need to find the VIN number and store it in a variable, however there's no ID located in it, so getelementbyid doesn't work.

## Find Number Of Checked Boxes ?

Aug 7, 2009

How to find out the number of checked boxes length without looping thru the whole set of check boxes....

## Find Smallest Number In List Of Vars?

Nov 11, 2011

If i have 4 vars

var one = 29.1
var two = 5.4
var three = 12.4
var four = 15

how can compare all 4 and find the smallest? in this case the result would be two

## JQuery :: Find Li Number In An Ordered List?

Mar 25, 2010

Is there an efficient way (ie. not looping through all members and counting) to find out what number an li will get in an ordered list? For example: [code]...

Naturally #first and #second will be 1 and 2, respectively. Without looping though all children of ol and counting, can I determine the number for #first and #second?

## JQuery :: Find Row Number Clicked Of Item List?

Oct 22, 2009

I'm just a starter and I'm looking for a function I can't find.

What I want:

I want the row number of the row i clicked of the item list.

For instance I click on third row then I want that var i returns 2. code...

## Find Factors Of Number And Pick Two Closest To Middle?

Mar 10, 2011

Basically I want to factor a number and select the two closest numbers to the middle of the factors for example: 20 factors to 1, 2, 4, 5, 10, 20 I want it to return 4 and 5 If the number is has an odd number of factors (has to be a perfect square) I want it to select the middle number and say it twice for example:

64 factors to 1, 2, 4, 8, 16, 32, 64

I want it to return 8 and 8 Would I use an array or what? My code should probably look like:

[Code]....

## Find Cursor Position In A Textbox In Term Of Number?

Apr 29, 2003

After retrieving a record from the database and displaying one of its text field in an input-type textbox, I click on a word and it'll store or show the current position of cursor in a variable. I have no success with IE's caretPos.

## Finding The Highest Average?

Nov 5, 2011

need to find the highest average from all of the averages entered in this code, but i have to use an if statement only, no arrays.

// ** Work out average ** //
// ** Put average into a category and display everything ** //

[code]....

## Display Average Of Five Into Sixth Box?

Apr 7, 2011

I am attempting a simple average calculation with javascript. I would like to have 6 boxes, 5 for the user to input a number in each, and the 6th box to display the average of the five. I have set up 2 functions to take the input, calc the total, then calculate the average. It seems to be taking the input, but on the rare occasions I get anything in the results box, it is NaN.

Here is my code:
<!DOCTYPE html PUBLIC "-W3CDTD XHTML 1.0 TransitionalEN" "[URL]">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Calculate Average</title>
<script language="javascript" type="text/javascript">
/* <[CDATA[ */
Declare variables
var calcResult Result of numbers added together and deivided by 5.

function calcAvg() {
calcResult += document.numbers.box1.value;
calcResult += document.numbers.box2.value;
calcResult += document.numbers.box3.value;
calcResult += document.numbers.box4.value;
calcResult += document.numbers.box5.value;
return calcResult;
} function performCalc(calcResult) {
avgResult = calcResult / 5;
document.numbers.averageResult.value = avgResult;
} .....

## Calculating The Average/mean In An Array ?

Mar 30, 2011

Im trying to calculate the mean/average of numbers in an array.how can i get the length of an array to perform in a simple / maths problem whilst being flexiable to the length of the array?

function sum()
{
var i=0 [code].....