<html>
<head>
<title>Grade Calculation</title>
<script type="text/javascript">
function Add()
{
  var a=parseInt(document.getElementById("fptxt").value);
  var b=parseInt(document.getElementById("sptxt").value);
  var c=parseInt(document.getElementById("fgtxt").value);
  var d=a+b+c;

  document.getElementById("sgtxt").value=d/3;
}
//grade equivalent
if(sgtxt >= 95&& sgtxt < 100)
{
document.write("etxt").value=excellent;
}
else if(sgtxt >= 90&& sgtxt < 95)
{
document.write("etxt").value=VeryGood;
}
else if(sgtxt >= 85&& sgtxt < 89)
{
document.write("etxt").value=Good;
}
else if(sgtxt >= 80&& sgtxt < 84)
{
document.write("etxt").value=Avaerage;
}
else if(sgtxt >= 75&& sgtxt < 79)
{
document.write("etxt").value=BelowAverage;
}
else if(sgtxt < 75)
{
document.write("etxt").value=Poor;
}
else if(sgtxt < 0||sgtxt > 100)
{
 msgbox.txt("Out of Range!");
}


function clear()
{
 txt1.value="";  
  txt2.value="";  
  txt3.clear();  
    txt4.clear();  
}


</script>
</head>


    <body>
    <h1>Student Grade Calculator</h1>
    <br/>
    JavaScript
    <hr width=500 align="left">
    First Prelim Grade
    <br/>
    <input type="text" id="fptxt">
    <br/>
    Second Prelim Grade
    <br/>
    <input type="text" id="sptxt">
    <br/>
    Final Term Grade
    <br/>
    <input type="text" id="fgtxt">
    <br/>

    <input type="button" id="btnCmpute" value="Compute" onclick="Add()">
    <input type="button" id="btnclr" value="Clear" onclick="clear()">
    <br/>
    Semestral Grade<br/>
    <input type="text" id="sgtxt" >
    <br/>
    Equivalent<br/>
    <input type="text" id="etxt" >
    <hr width=500 align="left">
    <h6>Copyright© 2013<br/>
    </h3>


    </body>
    </html>

..............................................
...............................................
hi all..
just need help in printing the EQUIVALENT of grades like excellent ,good etc. on equivalent box....
.i try this codes and no one is working printing the equivalent
document.write("etxt").value=Avaerage;
document.getElementById("etxt").value=BelowAverage;
document.write("average"etxt);
...................
the clear box still not working though.....

Dani AI

Generated

The original script has a few separate problems that prevent the equivalent from being shown: the grade logic sits outside the compute flow, numeric inputs are not validated, bare identifiers like excellent are used instead of strings, document.write is misused (it will replace the page if called after load), and the clear function refers to undefined variables. is correct in principle — the equivalent must be written into the element's .value as a quoted string — but the surrounding logic also needs fixing.

A compact, robust approach:

  • Convert inputs to numbers with Number() (or parseFloat()), check isNaN().
  • Compute the average, format it, then map the numeric average to a labeled equivalent with a dedicated function.
  • Avoid document.write. Set the .value of the target element.
  • Rename clear to something like resetFields and explicitly clear each known input (or use a form reset).

Example implementation (replace the old Add / clear handlers with these):

function computeGrade() {
  var a = Number(document.querySelector('#fptxt').value);
  var b = Number(document.querySelector('#sptxt').value);
  var c = Number(document.querySelector('#fgtxt').value);
  if (isNaN(a) || isNaN(b) || isNaN(c)) {
    alert('Enter numeric grades (0-100).');
    return;
  }
  var avg = (a + b + c) / 3;
  document.querySelector('#sgtxt').value = avg.toFixed(2);
  document.querySelector('#etxt').value = gradeLabel(avg);
}

function gradeLabel(score) {
  if (score < 0 || score > 100) return 'Out of range';
  if (score >= 95) return 'Excellent';
  if (score >= 90) return 'Very Good';
  if (score >= 85) return 'Good';
  if (score >= 80) return 'Average';
  if (score >= 75) return 'Below Average';
  return 'Poor';
}

function resetFields() {
  ['#fptxt','#sptxt','#fgtxt','#sgtxt','#etxt'].forEach(function(s){ document.querySelector(s).value = ''; });
}

Troubleshooting tips: verify each input id matches the HTML, use the browser console to inspect values and errors, and make sure the compute button calls computeGrade() (not an out-of-scope routine). This addresses the issues in 's code and builds on 's correct note about setting element .value to a string.

It should be like this:

document.getElementById("etxt").value = "BelowAverage";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.