Hi

I'm tackling down an extra credit assignment which I'm so confused on.
We are to design a basic JS Grade Calc where we input our scores and it gives us our grade.

For extra credit we have to snazz it up a bit.

So far this is what I want it to look like:
[IMG]http://img.photobucket.com/albums/v30/chibidemonkitty/gradecalc.jpg[/IMG]

I would like for it to add up all the CP scores and give the amount for that, then do the same for the lab scores, and then the tests/final exam.

In the box below the Calculate Grade, I would like it to give this kind of answer:

...adding up all your scores.
...calculating your grades.

Here are your scores thank you for waiting:

CP: <score>
Labs: <score>
Exams: <score>
Total Score: <score>
Your letter grade is: <grade>

Congratulations!~ CIS 101 is now over. :)


Any and all help creating the formula part of this would be great!

Recommended Answers

All 4 Replies

This is my script:

<center><h1><i> Grade Calculator </i></h1></center>
<!-- Start script -->
<script type="text/javascript">
function gradeCalc()

  // Output Variable
  var gradeOut;
  
  // Input Variables
  var gradeCP = document.gradeform.cp.value;
  var gradeCP2 = document.gradeform.cp2.value;
  var gradeCP3 = document.gradeform.cp3.value;
  var gradeCP4 = document.gradeform.cp4.value;
  var gradeCP5 = document.gradeform.cp5.value;
  var gradeCP6 = document.gradeform.cp6.value;
  var gradeCP7 = document.gradeform.cp7.value;
  var gradeLabs = document.gradeform.labs.value;
  var gradeLabs2 = document.gradeform.labs2.value;
  var gradeLabs3 = document.gradeform.labs3.value;
  var gradeLabs4 = document.gradeform.labs4.value;
  var gradeLabs5 = document.gradeform.labs5.value;
  var gradeLabs6 = document.gradeform.labs6.value;
  var gradeTests = document.gradeform.tests.value;
  var gradeTests2 = document.gradeform.tests2.value;
  var gradeFinal = document.gradeform.final.value;
  var gradeEC = document.gradeform.ec.value;
  
  // Inputed Variables to the output variable
  gradeOut = "...adding up your scores.\n\n";
  gradeOut = "...calculating your grades. \n\n";
  gradeOut = "Here are your scores, thank you for waiting: \n\n";
  gradeOut+= "CP: " "\n";
  gradeOut+= "Lab: " "\n";
  gradeOut+= "Exams: " "\n";
  gradeOut+= "Extra Credit: " "\n\n";
  gradeOut = "Congratulations!~ CIS 101 is now over :) \n\n";
  
  // Formula
  var totalGrade = (  );
  
  // Grade Variable
  gradeOut+= "Your grade is: " + totalGrade + "\n";
  
  // Grade letter to Output Variable
  if (totalGrade >= 90)
    gradeOut+= "Your letter grade is: A";
  else if (totalGrade < 90 && totalGrade >= 80)
    gradeOut+= "Your letter grade is: B";
  else if (totalGrade < 80 && totalGrade >= 70)
    gradeOut+= "Your letter grade is: C";
  else if (totalGrade < 70 && totalGrade >= 60)
    gradeOut+= "Your letter grade is: D";
  else if (totalGrade < 60)
    gradeOut+= "Your letter grade is: F";
	
	// Results in the text area
  document.gradeform.gradeout.value = gradeOut;
  
}
</script>
</head>
<body>

<!-- Start the form -->
<form name="gradeform"> 
       <!-- Input all the grades -->
<table width="100%" height="100%" cellpadding="3" cellspacing="5" border="1px">
<tr><td align="center" valign="top">
<h3> Class Participation </h3>
        CP 9/5:<br>
        <input type="text" name="CP1" size="10"><br><br>
        
        CP 10/3:<br>
        <input type="text" name="CP2" size="10"><br><br>
        
        CP 10/17:<br>
        <input type="text" name="CP3" size="10"><br><br>
        
        CP 10/31:<br>
        <input type="text" name="CP4" size="10"><br><br>
        
        CP 11/7:<br>
        <input type="text" name="CP5" size="10"><br><br>
        
        CP 11/21:<br>
        <input type="text" name="CP6" size="10"><br><br>
        
        CP 12/5:<br>
        <input type="text" name="CP7" size="10"><br><br></td>
        
<td align="center" valign="top">
<h3> Lab Grades </h3>

        Lab #1:<br>
        <input type="text" name="labs1" size="10"><br><br>
        
        Lab #2:<br>
        <input type="text" name="labs2" size="10"><br><br>
        
        Lab #3:<br>
        <input type="text" name="labs3" size="10"><br><br>
        
        Lab #4:<br>
        <input type="text" name="labs4" size="10"><br><br>
        
        Lab #5:<br>
        <input type="text" name="labs5" size="10"><br><br>
        
        Lab #6:<br>
        <input type="text" name="labs6" size="10"><br><br></td>
<td align="center" valign="top">
<h3> Test Grades </h3>

        Test #1:<br>
        <input type="text" name="Tests1" size="10"><br><br>
        
        Test #2:<br>
        <input type="text" name="Tests2" size="10"><br><br>
    
    <br> <h3> Final Exam Grade</h3>

        Final Exam:<br>
        <input type="text" name="final" size="10"><br><br>
        
    <br><h3> Extra Credit</h3>
         
         EC:<br>
         <input type="text" name="ec" size="10"><br><br>
</td></tr>
</table><br><br>
<center>
  <input type="button" value="Calculate Grade" onClick="gradeCalc()">
  <br>
  <br>
  
  <!-- Textarea used to return grades -->
  <textarea name="gradeout" rows="10" cols="25"></textarea>
  <br>
</p>
</center>
</form>

The problems I'm having are here:

// Inputed Variables to the output variable
  gradeOut = "...adding up your scores.\n\n";
  gradeOut = "...calculating your grades. \n\n";<br><br>
  gradeOut = "Here are your scores, thank you for waiting: \n\n";<br>,<br>
  gradeOut+= "CP: " "\n";
  gradeOut+= "Lab: " "\n";
  gradeOut+= "Exams: " "\n";
  gradeOut+= "Extra Credit: " "\n";
  gradeOut = "Congratulations!~ CIS 101 is now over :) \n\n";
  
  // Formula
  var totalGrade = (  );

The formula itself so it outputs the correct answer.
And of course, how to get it to add up all the cps and give me a number, and the same for the rest.

Your HTML document is not valid; it lacks a DOCTYPE. Also your question isn't very clear here. What kind of an help do you need since except for a few problems it pretty much looks OK. As for the formula, you would be the best person to come up with it. Here is a cleaner valid version of the same code. Just plug-in your formula calculation part and it should go well.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Grade Calc</title>
    <meta name="generator" content="Vim">
    <meta name="author" content="sos">
    <script type="text/javascript">
      function getLetterGrade(totalGrade) {
        var letterGrade = "F";
        if (totalGrade >= 90)
          letterGrade = "A";
        else if (totalGrade < 90 && totalGrade >= 80)
          letterGrade = "B";
        else if (totalGrade < 80 && totalGrade >= 70)
          letterGrade = "C";
        else if (totalGrade < 70 && totalGrade >= 60)
          letterGrade = "D";
        return(letterGrade);
      }

      function gradeCalc() {
        var gradeOut = "";

        var gradecp = document.gradeform.cp1.value;
        var gradecp2 = document.gradeform.cp2.value;
        var gradecp3 = document.gradeform.cp3.value;
        var gradecp4 = document.gradeform.cp4.value;
        var gradecp5 = document.gradeform.cp5.value;
        var gradecp6 = document.gradeform.cp6.value;
        var gradecp7 = document.gradeform.cp7.value;
        var gradeLabs = document.gradeform.labs1.value;
        var gradeLabs2 = document.gradeform.labs2.value;
        var gradeLabs3 = document.gradeform.labs3.value;
        var gradeLabs4 = document.gradeform.labs4.value;
        var gradeLabs5 = document.gradeform.labs5.value;
        var gradeLabs6 = document.gradeform.labs6.value;
        var gradetests = document.gradeform.tests1.value;
        var gradetests2 = document.gradeform.tests2.value;
        var gradeFinal = document.gradeform.final.value;
        var gradeEC = document.gradeform.ec.value;

        var totalGrade = 56 /* some formula */;

        var cp = 'some cp', lab = 'some-lab',
            exams = 'some-exams', credit = 'some-credit'

              gradeOut = "...adding up your scores.\n";
        gradeOut += "...calculating your grades.\n";
        gradeOut += "Here are your scores, thank you for waiting.\n";
        gradeOut += "cp: Some-cp\n";
        gradeOut += "Lab: Some-ca\n";
        gradeOut += "Exams: some-exam\n";
        gradeOut += "Extra Credit: some-credit\n";
        gradeOut += "Your grade is: " + totalGrade + "\n";
        gradeOut += "Your letter grade is: " + getLetterGrade(totalGrade) + "\n";
        gradeOut += "Congratulations!~ CIS 101 is now over :) \n\n";

        document.gradeform.gradeout.value = gradeOut;
      }
    </script>
  </head>
  <body>
    <form name="gradeform" action="#">
      <div>
      <table width="100%" cellpadding="3" cellspacing="5" border="1px">
        <tr><td align="center" valign="top">
            <h3> Class Participation </h3>
            cp 9/5:<br>
            <input type="text" name="cp1" size="10"><br><br>

            cp 10/3:<br>
            <input type="text" name="cp2" size="10"><br><br>

            cp 10/17:<br>
            <input type="text" name="cp3" size="10"><br><br>

            cp 10/31:<br>
            <input type="text" name="cp4" size="10"><br><br>

            cp 11/7:<br>
            <input type="text" name="cp5" size="10"><br><br>

            cp 11/21:<br>
            <input type="text" name="cp6" size="10"><br><br>

            cp 12/5:<br>
            <input type="text" name="cp7" size="10"><br><br></td>

          <td align="center" valign="top">
            <h3> Lab Grades </h3>

            Lab #1:<br>
            <input type="text" name="labs1" size="10"><br><br>

            Lab #2:<br>
            <input type="text" name="labs2" size="10"><br><br>

            Lab #3:<br>
            <input type="text" name="labs3" size="10"><br><br>

            Lab #4:<br>
            <input type="text" name="labs4" size="10"><br><br>

            Lab #5:<br>
            <input type="text" name="labs5" size="10"><br><br>

            Lab #6:<br>
            <input type="text" name="labs6" size="10"><br><br></td>
          <td align="center" valign="top">
            <h3> Test Grades </h3>

            Test #1:<br>
            <input type="text" name="tests1" size="10"><br><br>

            Test #2:<br>
            <input type="text" name="tests2" size="10"><br><br>

            <br> <h3> Final Exam Grade</h3>

            Final Exam:<br>
            <input type="text" name="final" size="10"><br><br>

            <br><h3> Extra Credit</h3>

            EC:<br>
            <input type="text" name="ec" size="10"><br><br>
        </td></tr>
      </table>
      <br>
        <input type="button" value="Calculate Grade" onclick="gradeCalc()">
        <br>
        <br>
        <textarea name="gradeout" rows="10" cols="80"></textarea>
        <br>
    </div>
    </form>
  </body>
</html>

Umm pretty much the formula is what Im having trouble with...
and coming up with the proper part to give me the results. Our teacher gave us this:

http://students.depaul.edu/~lkoziol/it130/gradecalc.htm

Pretty much he wants us to make it like that with the added inputs.

and...lol I'm so confused with it

Now the part I don't understand from the calculator we are supposed to go off of is this:

// Add the inputed Grades to the output variable
  gradeOut = "Your Calculated Grades:\n\n";
  gradeOut+= "Homework Grade: " + gradeHomework + "\n";
  gradeOut+= "Lab Grade: " + gradeLabs + "\n";
  gradeOut+= "Midterm Grade: " + gradeMidterm + "\n";
  gradeOut+= "Final Grade: " + gradeFinal + "\n\n";

  // Calculate the course grade via the formula
  var totalGrade = ( (gradeHomework*.25) + (gradeLabs*.20) + (gradeMidterm*.25) + (gradeFinal*.30) );

  //Add the course grade to the variable
  gradeOut+= "Your course grade is: " + totalGrade + "\n";

  // Check for what grade letter and add to output variable (extra credit)
  if (totalGrade >= 90)
    gradeOut+= "Your letter grade is: A";
  else if (totalGrade < 90 && totalGrade >= 80)
    gradeOut+= "Your letter grade is: B";
  else if (totalGrade < 80 && totalGrade >= 70)
    gradeOut+= "Your letter grade is: C";
  else if (totalGrade < 70 && totalGrade >= 60)
    gradeOut+= "Your letter grade is: D";
  else if (totalGrade < 60)
    gradeOut+= "Your letter grade is: F";

In the part that says: "// Add the inputed Grades to the output variable" I need it to add up all my CPs and give me a total for that, as well as the labs, and the exams.

So in essence I need it to look like this:
CP: <all cp scores added up>
Labs: <all lab scores added up>
Exams: <all exam scores added up>
Total Score: <score>
Your letter grade is: <grade>

Which is different from that grade calc we have to work off of because it just outputs whatever you wrote in the box field.
Like so:
[IMG]http://img.photobucket.com/albums/v30/chibidemonkitty/example.jpg[/IMG]

Could someone please help me? I hope I explained myself well enough now...if not...I'll try explaining more.

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.