0

So I'm having some problems with my code here. and I'm not sure whats wrong. Im following a textbook on how to do it and this is basically the same format that they have for a random number function. Any feedback is appreciated.

<html>
    <head>
        <title> Grades </title>
        <script type="text/javscript">


            function Grader() 
            {
                var am1=parseFloat(document.getElementById('homework').value*0.25);
                var am2=parseFloat(document.getElementById('labs').value*0.20);
                var am3=parseFloat(document.getElementById('midterm').value*0.25);
                var am4=parseFloat(document.getElementById('final').value*0.30);
                var hw=homework*am1;
                var lbs=labs*am2;
                var mt=midterm*am3;
                var fe=finals*am4;
                var total = am1+am2+am3+am4;

                document.getElementById('outputDiv').innerHTML='Your final grade is ' + total;
            }
        </script>
    </head>

    <body>
    <p>
      <h2>Grades</h2>
      <h3>Enter your grade for each section</h3>
      <TABLE BORDER=3 CELLSPACING=3 CELLPADDING=3>

      <tr>
      <td>Type</td>
      <td>Weight</td>
      <td>Grade</td>
      <tr>

      <tr>
      <td>Homework</td>
      <td>25%</td>
      <td><input type="text" id="homework" size=2 value=""></td>
      </tr>

      <tr>
      <td>Labs</td>
      <td>20%</td>
      <td><input type="text" id="labs" size=2 value=""></td>
      </tr>

      <tr>
      <td>Midterm</td>
      <td>25%</td>
      <td><input type="text" id="midterm" size=2 value=""></td>
      </tr>

      <tr>
      <td>Final Exam</td>
      <td>30%</td>
      <td><input type="text" id="finals" size=2 value=""></td>
      </table>

      <br><br>
    </p>
        <input type="button" value="Calculate Grade" 
            onclick="Grader();">

        <hr>
        <div id="outputDiv"></div>

    </body>
</html>
2
Contributors
1
Reply
9
Views
5 Years
Discussion Span
Last Post by dcdruck
0

You have a typo in your script tag: text/javscript should be text/javascript. (Missing the second 'a' in 'javascript'.)

You also have a typo in your function Grader() ('finals' vs 'final'). The line that gets the value of the Final Exam reads:

var am4=parseFloat(document.getElementById('final').value*0.30);

but it should be:

var am4=parseFloat(document.getElementById('finals').value*0.30);

Fix those two issues and it should work.

Edited by dcdruck: Correction

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.