Not sure whats wrong with my code HELP PLEASE?!?!
2 Answer(s)      6 years and 3 months ago
Posted in : Java Beginners

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


Class Average Calculator

Computing your grade for a class.

Your Average


View Answers

November 23, 2010 at 5:18 PM

Hi Friend,

Try the following code:


<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 ";

</head> </p>

<body> </p>

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

Computing your grade for a class. </p>

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

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

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

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

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

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



November 23, 2010 at 5:24 PM

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

Related Tutorials/Questions & Answers: