Home Answers Viewqa Java-Beginners Not sure whats wrong with my code HELP PLEASE?!?!

 
 


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

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 Pages:

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.