Not sure whats wrong with my code HELP PLEASE?!?!

Not sure whats wrong with my code HELP PLEASE?!?!

I cant figure out what I am doing wrong in my code can anyone help me out???

Grades

Class Average Calculator

Computing your grade for a class.

Homework
Labs
Midterm
Finals
Your Average

� 

View Answers

November 23, 2010 at 5:18 PM

Hi Friend,

Try the following code:

<html> 

<head> 
<title> Grades </title> 

<script type="text/javascript"> 
function computeGrade( )
{
    var hw, lab, midt, fin, avg;
    hw = parseFloat(document.grade.txthw.value);
    lab = parseFloat(document.grade.txtlab.value);
    midt = parseFloat(document.grade.txtmidt.value);
    fin = parseFloat(document.grade.txtfin.value);
    avg = hw*0.25 + lab*0.20 + midt*0.25 + fin*0.30 ;
    document.grade.txtAV.value = avg;

    var r = parseFloat(avg);
    if (r >= 90)
       document.grade.txtResult.value = " A ";
    else if (r <= 89 || r >= 80)
        document.grade.txtResult.value = " B ";
    else if (r <= 79 || r >=70)
        document.grade.txtResult.value = " C ";
    else if (r <= 69 || r >=60)
        document.grade.txtResult.value = " D ";
}
</script> 

</head> </p>

<body> </p>

<h2>Class Average Calculator</h1> </p>

Computing your grade for a class. </p>

<form name="grade"> 
<table> 
<tr> 
     <td>Homework</td> 
     <td><input type="text" name="txthw" size="10"
                value="" /></td> 
</tr> 
<tr> 
     <td>Labs</td> 
     <td><input type="text" name="txtlab" size="10"
                value="" /></td> 
</tr> 

<tr> 
     <td>Midterm</td> 
     <td><input type="text" name="txtmidt" size="10"
                value="" /></td> 
</tr> 


<tr> 
     <td>Finals</td> 
     <td><input type="text" name="txtfin" size="10"
                value="" /></td> 
</tr> 

<tr> 
     <td>Your Average</td> 
     <td><input type="text" name="txtAV" size="10"
                value="" /></td> 
</tr> 
</table> 

<input type="button" name="btnComputeGrade"  value="Compute Class Average"   onclick="computeGrade();" /> 

<input name="txtResult" size="36" type="text"> </p>

</form> 
</body> 
</html>

Thanks


November 23, 2010 at 5:24 PM

Thank you i eventually figured out i had the signs reversed :/









Related Tutorials/Questions & Answers:

Ads