Implementing Array And Then Calculating The Average?

Sep 16, 2011

She's wanting an array that will store points awarded and then calculate the average. It will also then show the distribution of the allocated grades (that I'm not having trouble with - just pulling the averages from the array data).

This is my code so far:

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

[Code]....

I've tried different ways, most ending in the 'average' variable being undefined or when the button is pressed and the function 'ReturnAverage' called it doesn't do anything. I'm using Eclipse as my IDE to work on this and check syntax.

View 2 Replies


ADVERTISEMENT

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].....

View 2 Replies View Related

Calculating Sum And Average Of Integers And Display Value

May 25, 2009

I'm a newbie to javascript and I made this script
<script>
var num = parseInt(prompt("Enter the number of integers to follow"));
var sum = 0;
for (i = 0; i < num; i++){
sum += parseInt(prompt("Enter a number"));
}

if (isNaN(num)) {
alert("Invalid");
} else {
if (sum < 0) {
document.writeln("The sum is 0 and the average is 0");
} else {
document.writeln("The sum is " + sum + " and the average is " + sum/num);
}
}
</script>

The scenario : Create in javascript that will read a series of integers at the terminal. The first integer is special, as it indicates how many more integers will follow. Your javascript is to calculate the sum and average of the integers, excluding the first integer, and display these values to the screen. If the total is not greater than 0 then display "The sum is 0 and the average is 0". Did I write the script correctly? am I missing anything that a dumb person might do? for example the person might type in letters instead of numbers.

View 3 Replies View Related

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...

View 1 Replies View Related

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..

View 5 Replies View Related

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 ** //
average= readingSum/totalReadings
// ** Put average into a category and display everything ** //

[code]....

View 15 Replies View Related

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]">
<html xmlns="[URL]"><head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Calculate Average</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<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;
} .....

View 6 Replies View Related

Print Average Of Numbers?

Sep 17, 2010

I do not know how to program this in html code?

this is the problem?

input 20 number and print the average of the number....?

View 1 Replies View Related

Average From Loops Without Arrays Nor Functions?

Oct 26, 2011

I've now got to form an average of snowfall inputs, taken from looped prompts, however I'm not allowed to use arrays or functions...Almost every example I see uses arrays, such as this one here:http://www.codingforums.com/showthread.php?t=4313Is it possible to not use arrays to form the average? Please describe how to do this in general terms, as was highlighted in that link ^^^ I want to learn, not copy, although one can be derived from the other...What I haveso far, assume all vars have been announced.

for (var d=1; d<=numofinputs; d=d+1)
{
input = prompt("Enter a data input" + d)
}

View 4 Replies View Related

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]....

View 1 Replies View Related

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.

View 1 Replies View Related

GPA Calculator - Using Select Input And Average It

Oct 7, 2011

My task was to build a simple GPA calculator using select input and Javascript to average it all together and return it to the user with his name. So I started with my form which looks like this

<tr><td>
<form name="GPA"
<p> Test 1</p>
</td><td>
<select id="v1">
<option value="4">A</option>
<option value="3">B</option>
<option value="2">C</option>
<option value="1">D</option>
<option value="0">F</option>
</select>
</td></tr><tr><td>

Now to the best of my knowledge that looks correct, I made sure to use integers as the values so I could average them using this function
<script type="text/javascript">
<!--
function Average(v1,v2,v3){
return Average (v1+v2+v3) / 3;
}
-->
</script>

View 6 Replies View Related

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"

<HEAD><TITLE> average</TITLE>
<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>');
</SCRIPT></HEAD><BODY>
</BODY></HTML>

View 10 Replies View Related

JQuery :: Add Special Symbol (average) To Textfield?

Jul 15, 2010

ich got a textarea and want to add a special symbol to it like average. would be awesome if there were a button next to the textfield where a dialog pops up. via click on the specific symbol it should be added at the promt in the textarea box. maybe something like that smiley input in this wysiwyg-editor. should be as easy for the user as possible.does anybody know a plugin for that problem? i googled a lot and didn't find anything suitabl

View 2 Replies View Related

Implementing JS Effect

Sep 5, 2006

What i want is this div to expand:

<div id="info"><a onclick="Effect.toggle('toggle','Blind')" href="javascript:void(0)">More Info</a>

and show the rest of the content, for example it will say "More Info" when the user clicks it will toogle down and reveal the rest of the content which for example sake can be "Heres more info".

View 2 Replies View Related

Implementing Opacity Script

Jul 12, 2007

I've just had a look at your fading opacity script. As I'm new to
programming and I'm amazed by the script could I ask for some hints
how to implement it in a site with a mouseover, mouseout events?

View 4 Replies View Related

Implementing Validation To Form?

Apr 11, 2011

[URL] however i want to impliment this into my form. if false I want it to return an alert saying postcode not valid and then stop the form submitting, else i want it to just allow the form to submit.

View 5 Replies View Related

Selecting The Highest Calculated Average Of Varioous Data Inputs?

Oct 28, 2011

I've written a program which will prompt for a number of cities, Prompt for the name of the city, then prompt for the number of snowfall readings of that city, and then prompt for each of these individual snowfall readings of that city. From this, it adds up each of the individual snowfall readings of that city, and will calculate an average by dividing this figure [the total snowfall] by the total number of readings for that city. This average is used to then classify the city as "not snowy", "mild", or "blizzard". I'm happy to PM my code to anyone willing to help out, as I realise this is a complex structure to visualise perhaps, but I can't post it publicly.

View 3 Replies View Related

Implementing A Lite Feed Reader

Jul 13, 2006

I would like to know if anyone has some javascript code that reads an
external, arbitrary, XML feed, and can display the 2 or 3 latest
submissions based on the XML src.

Is such a task even possible with just client-side javascript?

View 1 Replies View Related

JQuery :: Implementing Next To Last Selector For Project

Mar 18, 2010

I need to implement a next to last selector for our project. I came up with the following code:
jQuery.expr[':'].next_to_last = function(obj, index, m){
var $this = jQuery(obj);
return $this.find(m[3]).last().prev();
};
Is there any problem with this implementation?

View 13 Replies View Related

Implementing A Countdown Clock From Within A Php Page?

Jul 27, 2009

Im having trouble implementing a countdown clock from within a php page. I am using the countdown clock from dynamic drive. It works well if I have the javascript in the php page, but when I move it to an external js file clock.js it gives an 'invalid date'. Does it have something to do with the php tags inside the function ? below is the code.

callclock.php
<script src="clock.js" language="javascript" type="text/javascript">
</script>

[code]....

View 2 Replies View Related

Implementing A Variable's Value Inside A Function

Jan 9, 2008

I'm making a project which creates tabs with a class. I don't really know how to explain it better but this is how it works:

<a href="#" id="tbs_tabs">Create</a>
<script type="text/javascript">
var tbs = new Tabs('tbs_tabs');
tbs.theme = 'classic'
tbs.create_option('abc','#');
tbs.create_option('abz','#');
tbs.create_option('abf','#');
tbs.create();
</script>

It first creates the new class and tells it the id, then it creates as many options as you want and creates it.

My problem is with this line:
for(i=0;i<this.option_values.length;i++)
{
li = document.createElement("LI");
li.appendChild(document.createTextNode(this.option_values[i]));
addEvent(li,"click",function(){oThis.select_option(i); return false;};

ul.appendChild(li);
}

What I was trying to do here is add an event to the LI element that refers to the current tab class but doesn't use the CURRENT i value but the value that was when the event was first created.

For example.. If my i value is currently 2 and I add the function, then I want that when I call the function, the value will still be 2 and not the current i value. What happens now is when I call the function the value is something like 5 or 6.

View 2 Replies View Related

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]....

View 2 Replies View Related

Formula - Convert Estimated Average Glucose To HbA1c And Vice Versa

Apr 17, 2011

I need a Javascript that can process two math formulas to convert Estimated Average Glucose to HbA1c and vice versa. The formulas are as follows:

(28.7 x A1C) - 46.7 = eAG
(46.7 + eAG) / 28.7 = A1c

It could be a two function javascript or two separate javascripts, I am not that particular as long as it does what I need it to do. The way I would like to see it work is you type the number you have into a field, and press a button to convert it. If it was a two function javascript you would have to select the conversion type you want do first.

View 2 Replies View Related

Implementing Remember PAssWord In Client Side

Sep 27, 2006

I have a Login Page whrere all Functionalities such as validations are
Done in Client Side...

I have to Implement Remember My Mail Id and PAss Word Functionality
also in Client side..

When Remember PAssWord Check Box is Checked.....

The User and Mail Id Should be Remembered Duriing The Next Login...

How could i do this in Client Side.

View 6 Replies View Related

JQuery :: Implementing A Click And Hold Function?

Jun 19, 2010

I have a grid of items that when clicked lead to a new page. I would like to implement a function so that if a user clicks on an item and holds for at least 1000ms, a menu will be shown next to the item and they will not be taken to the next page.

However, all of my current attempts either lead to the menu not being shown, or it is shown and the user is redirected to the next page anyways.

Here's my current code:

jQuery(document).ready(function(){
var mousehold;
jQuery('.item').mousedown(function(){

[Code].....

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved