Click to See Complete Forum and Search --> : Average all the grades= grade so far


JavaDitz
12-16-2002, 09:36 PM
Hey guys Newbie Here
and a newbie to Java Script
the page
http://www.geocities.com/mistresssaturn15/Grades.htm

the code
http://www.geocities.com/mistresssaturn15/grade2.html

ok this is what I want it to do... I want it to get the grades by deviding what they got right out of what they got wrong... like say a 9/10 =90 (I know I would have to *100 in order to get a whole number)
then add these grades up and devide it by how many entries there are.
like if they entered 2 grades... then devide it by 2.
In order to get their current grade in that class.

lemme know if you have n e questions on what I want it to do.

I've asked my friends... they don't seem to know Java Script... I only know C++ and a lil True Basic I can really use the help I need this page done by tomorrow 1:00 pm

THANK YOU SO MUCH IN ADVANCE!

Java Ditz

JavaDitz
12-16-2002, 10:04 PM
it's not that... I have a code... it just doesn't work...

<SCRIPT LANGUAGE="JavaScript">
function a_div_b(form)
{
a=eval(form.a.value)
b=eval(form.b.value)
c=a/b
form.ans.value = c
}
function a1_div_b1(form)
{
a1=eval(form.a1.value)
b1=eval(form.b1.value)
c1=a1/b1
form.ans.value = c1
}
function a2_div_b2(form)
{
a2=eval(form.a2.value)
b2=eval(form.b2.value)
c2=a2/b2
form.ans.value = c2
}
function a3_div_b3(form)
{
a3=eval(form.a3.value)
b3=eval(form.b3.value)
c3=a3/b3
form.ans.value = c3
}
function fnlmrk(form)
{
ttl= c+c1+c2+c3
fnlmrk= ttl / 4
}
</SCRIPT>

JavaDitz
12-16-2002, 11:01 PM
Please I'm not a slacker... I've tried really hard...and I can't figure out why this thing won't work at all...please... I need your help ;_;

khalidali63
12-16-2002, 11:02 PM
Follow the pattern below.
I have only made changes to the first function

change the result showing text fields name to "result"
and by the way you need to put every attribute value in qoutes.cus at this point your code does not meet standards badly..

:-)

here is code

function a_div_b(form){
var a = 0;
var b = 0;
var result = 0;
a=eval(form.a.value)
b=eval(form.b.value)
result=a * b
//form.ans.value = c;//in the form there is no ans field
form.result.value = result;
}

JavaDitz
12-16-2002, 11:09 PM
thank you so much... i knew it was somethin somewhat simple as you can see I don't know much about this language he he :/

what is quote.cus?


Java Ditz

khalidali63
12-16-2002, 11:33 PM
my fault
qoutes = "" and cus = because

pardon the lingo

:-)

Khalid

JavaDitz
12-16-2002, 11:35 PM
lol THANK YOU so much...

I thought it was another code lol

Java Ditz

JavaDitz
12-17-2002, 12:42 AM
I'm sorry... I typed in the code... perhaps I didn't do something right? or did I maybe there's something wrong with the button :/
ok... so here's what I typed in...

<SCRIPT LANGUAGE="JavaScript">
function a_div_b(form){
var a = 0;
var b = 0;
var result = 0;
a=eval(form.a.value)
b=eval(form.b.value)
result=a * b
//form.ans.value = c;//in the form there is no ans field <br>
form.result.value = "result";
}

function a1_div_b1(form){
var a1 = 0;
var b1 = 0;
var result = 0;
a1=eval(form.a1.value)
b1=eval(form.b1.value)
result=a1 * b1
//form.ans.value = c;//in the form there is no ans field <br>
form.result.value = result;
}
function a2_div_b2(form){
var a2 = 0;
var b2 = 0;
var result = 0;
a2=eval(form.a2.value)
b2=eval(form.b2.value)
result=a2 * b2
//form.ans.value = c;//in the form there is no ans field <br>
form.result.value = "result";
}
function a3_div_b3(form){
var a3 = 0;
var b3 = 0;
var result = 0;
a3=eval(form.a3.value)
b3=eval(form.b3.value)
result=a3 * b3
//form.ans.value = c;//in the form there is no ans field <br>
form.result.value = "result";
}
form.ans.value = "c";
</SCRIPT>

JavaDitz
12-17-2002, 12:43 AM
and here's the code for the button

<FORM name="form">

<p>Please enter your first grade here
<input type=text size=4 value=0 name="a">
out of
<input type=text size=4 value=0 name="b">
Grade
<input type="button" value=" Submit " onClick="a_div_b(form)">
<input type "number" value=0 name="result" size=9>

</p>
<p>Please enter your second grade here
<input type=text size=4 value=0 name="a1">
out of
<input type=text size=4 value=0 name="b1">
Grade
<input type="button" value=" Submit " onClick="a1_div_b1(form)">
<input type "number" value=0 name="0" size=9>
</p>
<p>Please enter your third grade here
<input type=text size=4 value=0 name="a2">
out of
<input type=text size=4 value=0 name="b2">
Grade
<input type="button" value=" Submit " onClick="a2_div_b2(form)">
<input type "number" value=0 name="result" size=9>
</p>
<p>Please enter your fourth grade here
<input type=text size=4 value="0" name="a3">
out of
<input type=text size=4 value="0" name="b3">
Grade
<input type="button" value=" Submit " onClick="a3_div_b3(form)">
<input type "number" value="0" name="result" size=9>
</p>
<p align="center">Your Grade is now a
<input type="button" value=" Submit " onClick="c">
<input type "number" value=0 name="c" size=9>

</p>
</form>

JavaDitz
12-17-2002, 08:41 AM
THANK YOU SO MUCH
ok.. this may be a dumb question but I have to be sure

in the script do I change the name "result" also?

by the way it still doesn't work when I click submit

Java Ditz

<SCRIPT LANGUAGE="JavaScript">
function a_div_b(form){
var a = 0;
var b = 0;
var result = 0;
a=eval(form.a.value)
b=eval(form.b.value)
result=a * b
//form.ans.value = c;//in the form there is no ans field <br>
form.result.value = "resulta";
}

function a1_div_b1(form){
var a1 = 0;
var b1 = 0;
var result = 0;
a1=eval(form.a1.value)
b1=eval(form.b1.value)
result=a1 * b1
//form.ans.value = c;//in the form there is no ans field <br>
form.result.value = "resultb";
}
function a2_div_b2(form){
var a2 = 0;
var b2 = 0;
var result = 0;
a2=eval(form.a2.value)
b2=eval(form.b2.value)
result=a2 * b2
//form.ans.value = c;//in the form there is no ans field <br>
form.result.value = "resultc";
}
function a3_div_b3(form){
var a3 = 0;
var b3 = 0;
var result = 0;
a3=eval(form.a3.value)
b3=eval(form.b3.value)
result=a3 * b3
//form.ans.value = c;//in the form there is no ans field <br>
form.result.value = "resultd";
}
form.ans.value = "c";
</SCRIPT>

khalidali63
12-17-2002, 09:29 AM
Ok...here you go my friend..
I have fixed all the code as you desired.
Let me know if you still have any problems

Khalid

1.Here is what you should do.Create a new empty html page.
2.Copy everything below and paste in that empty page
3.Save it with whatever name.and then
4. Run it with either NS6+ or IE



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Grade Calculation</title>
<script type="text/javascript" language="JavaScript">
function a_div_b(form){
var a = 0;
var b = 0;
var result = 0;
a=eval(form.a.value)
b=eval(form.b.value)
c=a * b
//form.ans.value = c;//in the form there is no ans field
form.result.value = c;
}

function a1_div_b1(form){
a1=eval(form.a1.value)
b1=eval(form.b1.value)
c1=a1/b1
form.result1.value = c1//in the form there is no ans field
}

function a2_div_b2(form){
a2=eval(form.a2.value)
b2=eval(form.b2.value)
c2=a2/b2
form.result2.value = c2
}

function a3_div_b3(form){
a3=eval(form.a3.value)
b3=eval(form.b3.value)
c3=a3/b3
form.result3.value = c3
}

function fnlmrk(form){
ttl= c+c1+c2+c3;
form.finalResult.value = ttl / 4;
}
</script>


</head>
<body background="background1.jpg" text="#CCCCCC" link="#FF9900" background1.jpg="">
<table width="100%" height="76" border="0" cellpadding="4" cellspacing="0">
<tr>
<td width="13%" rowspan="2" bgcolor="#999933"><img src="flower.png" width="76" height="67"></td>
<td width="87%" height="31" bgcolor="#006633">
<h3 align="center"><font color="#FF9900" face="Arial, Helvetica, sans-serif">Want to give your grade a check
up?</font></h3>
</td>
</tr>

<tr>
<td height="44" background="background1.jpg">
<table width="100%" height="28" border="0" cellpadding="2" cellspacing="1" bgcolor="#006600">
<tr bgcolor="#669900">
<td width="20%" height="23" align="center" bgcolor="#669933">
<a href="index.htm"><font color="#FF9933" face="Arial, Helvetica, sans-serif">Home</font></a></td>
<td width="20%" align="center" bgcolor="#669933">
<div align="center"><a href="EVPP110001.htm">
<font color="#FF9933">Class</font></a></div>
</td>
<td width="20%" align="center" bgcolor="#669933">
<a href="mailto:klargen@gmu.edu?subject=I%20have%20a%20question">
<font color="#FF9933">klargen@gmu.edu</font></a></td>
<td width="20%" align="center" bgcolor="#669933">
<a href="biolinks.htm"><font color="#FF9933">Links</font></a></td>
</tr>
</table>
</td>
</tr>
</table>

<form name="formx">
<p>Please enter your first grade here <input type="text" size="4"
value="12" name="a"> out of <input type="text" size="4" value="12"
name="b"> Grade <input type="button" value=" Submit " onclick=
"a_div_b(this.form)"> <input type="text" value="0" name="result"
size="9"></p>

<p>Please enter your second grade here <input type="text" size="4"
value="12" name="a1"> out of <input type="text" size="4" value="12"
name="b1"> Grade <input type="button" value=" Submit " onclick=
"a1_div_b1(this.form)"> <input type="" value="0" name="result1" size=
"9"></p>

<p>Please enter your third grade here <input type="text" size="4"
value="12" name="a2"> out of <input type="text" size="4" value="12"
name="b2"> Grade <input type="button" value=" Submit " onclick=
"a2_div_b2(this.form)"> <input type="" value="0" name="result2" size=
"9"></p>

<p>Please enter your fourth grade here <input type="text" size="4"
value="12" name="a3"> out of <input type="text" size="4" value="12"
name="b3"> Grade <input type="button" value=" Submit " onclick=
"a3_div_b3(this.form)"> <input type="" value="0" name="result3" size=
"9"></p>

<p align="center">Your Grade is now a <input type="button" value=
" Submit " onclick="fnlmrk(this.form)"> <input type="" value="0"
name="finalResult" size="9"></p>
</form>

</body>
</html>

JavaDitz
12-17-2002, 09:36 AM
THANK YOU SOOOO MUCH!!! :D
All the buttons work except for one
the bottom button which averages all of the grades
"your final grade is" still does not work
when you enter just grades
and average them...
like if the user enters 3 grades it should devide by 3

khalidali63
12-17-2002, 09:45 AM
yes..but that is not your previous code does,It lacks this functionality.for this you have to code it so it dynamically finds out that how many grades are entered and then calculate accordingly..

khalidali63
12-17-2002, 09:45 AM
do u think it will always be four or less items or it can be more then four as well?

JavaDitz
12-17-2002, 09:47 AM
it will be 4 or less items...
btw... when I set the 12 to 0 it doesn't seem to work right :/

khalidali63
12-17-2002, 09:49 AM
lol..I know..its your code..
Let me re-write your logic..

Khalid

JavaDitz
12-17-2002, 09:51 AM
also if it's not a big deal could it go back a teth like instead of .72 -> 720
.72 - 72

THANK YOU SOO MUCH for your help... if you want I'll be more than happy to give you credit :)

khalidali63
12-17-2002, 10:40 AM
There you go JavaDitz

copy all of the code from below into an empty new html page save it and run it.

The last question you asked about the precision...
well how about you looked into javascript Math object .If you come across problems...e-mail me

Khalid


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<title>Grade Calculation</title>
<script type="text/javascript" language="JavaScript">
/*
Author Khalid Ali
Description a simple calculation routine, written for JavaDitz
Date December 17, 2002

***********Instructions***************
1. Create an new empty HTML page
2. Coppy all of this files code in that.
calculate and have fun
*/
function a_div_b(form,elementIndex){
var a = 0;
var b = 0;
var elementA = eval('form.'+('a'+elementIndex));
var elementB = eval('form.'+('b'+elementIndex));
var result = 0;
a=eval(elementA.value);
b=eval(elementB.value);
c=a * b
var resultElement = eval('form.result'+elementIndex);
resultElement.value = c;
}

function fnlmrk(form){
var totalGrade = 0;
var divident = 0;
for(n=0;n<4;n++){
var element = eval('form.'+('result'+(n+1)))
if(element.value>0){
totalGrade += parseInt(element.value);
++divident;
}
}
form.finalResult.value = totalGrade / divident;
}
</script>


</head>
<body background="background1.jpg" text="#CCCCCC" link="#FF9900" background1.jpg="">
<table width="100%" height="76" border="0" cellpadding="4" cellspacing="0">
<tr>
<td width="13%" rowspan="2" bgcolor="#999933"><img src="flower.png" width="76" height="67"></td>
<td width="87%" height="31" bgcolor="#006633">
<h3 align="center"><font color="#FF9900" face="Arial, Helvetica, sans-serif">Want to give your grade a check
up?</font></h3>
</td>
</tr>

<tr>
<td height="44" background="background1.jpg">
<table width="100%" height="28" border="0" cellpadding="2" cellspacing="1" bgcolor="#006600">
<tr bgcolor="#669900">
<td width="20%" height="23" align="center" bgcolor="#669933">
<a href="index.htm"><font color="#FF9933" face="Arial, Helvetica, sans-serif">Home</font></a></td>
<td width="20%" align="center" bgcolor="#669933">
<div align="center"><a href="EVPP110001.htm">
<font color="#FF9933">Class</font></a></div>
</td>
<td width="20%" align="center" bgcolor="#669933">
<a href="mailto:klargen@gmu.edu?subject=I%20have%20a%20question">
<font color="#FF9933">klargen@gmu.edu</font></a></td>
<td width="20%" align="center" bgcolor="#669933">
<a href="biolinks.htm"><font color="#FF9933">Links</font></a></td>
</tr>
</table>
</td>
</tr>
</table>

<form name="formx">
<p>Please enter your first grade here <input type="text" size="4"
value="12" name="a1"> out of <input type="text" size="4" value="12"
name="b1"> Grade <input type="button" value=" Submit " onclick=
"a_div_b(this.form,1)"> <input type="text" value="0" name="result1"
size="9"></p>

<p>Please enter your second grade here <input type="text" size="4"
value="12" name="a2"> out of <input type="text" size="4" value="12"
name="b2"> Grade <input type="button" value=" Submit " onclick=
"a_div_b(this.form,2)"> <input type="" value="0" name="result2" size=
"9"></p>

<p>Please enter your third grade here <input type="text" size="4"
value="12" name="a3"> out of <input type="text" size="4" value="12"
name="b3"> Grade <input type="button" value=" Submit " onclick=
"a_div_b(this.form,3)"> <input type="" value="0" name="result3" size=
"9"></p>

<p>Please enter your fourth grade here <input type="text" size="4"
value="12" name="a4"> out of <input type="text" size="4" value="12"
name="b4"> Grade <input type="button" value=" Submit " onclick=
"a_div_b(this.form,4)"> <input type="" value="0" name="result4" size=
"9"></p>

<p align="center">Your Grade is now a <input type="button" value=
" Submit " onclick="fnlmrk(this.form)"> <input type="" value="0"
name="finalResult" size="9"></p>
</form>

</body>
</html>

JavaDitz
12-17-2002, 11:30 AM
The last question you asked about the precision... well how about you looked into javascript Math object

I figured it out ^^
THANK YOU SO MUCH!!! btw... do you want your name to be seen on the actual page? or is it in the code just fine?

function a_div_b(form,elementIndex){
var a = 0;
var b = 0;
var elementA = eval('form.'+('a'+elementIndex));
var elementB = eval('form.'+('b'+elementIndex));
var result = 0;
a=eval(elementA.value);
b=eval(elementB.value);
c= (a / b) * 100
var resultElement = eval('form.result'+elementIndex);
resultElement.value = c;
}

khalidali63
12-17-2002, 11:34 AM
I leave that completely upto you,
though a little boasting won't hurt..hehehe

Feel free to e-mail me for any further questions
Have fun

Khalid