Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Feb 2012
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Student Grade help.

    i wold like to get this working. when a user enters 4 grades into the text boxes. it would give them the Avg Grade and also what Mark they got,

    and if they failed one out put the module they most Repeat and if they passed all out put a smiley face..

    This is what i have so far..
    Code:
    function compute() {
    
    var c = document.getElementById("c").value;
    
      var computer = document.getElementById("computer").value;
    
      var web = document.getElementById("web").value;
    
    var math = document.getElementById("math").value;
    
    
    
    
    
    
    
      document.getElementById("cost").value =
    
    totalCost = (c * 100 + computer * 100 + web * 100 + math * 100 ) /4;
    
    
    if(cost >=93)
     alert(" You got an A+")
    else 
    if((cost >=85)&(grade <93))
     alert(" You got an A")
    else
    if((cost >=78)&(grade <85))
     alert(" You got an B")
    else 
    if((cost >=60)&(grade <78))
     alert(" You got an C")
    else
    if((cost >=40)&(grade <60))
     alert(" You got an D")
    else
    if(cost <40)
     alert(" You Failed this Module")
    
    
    </script>
    </head>
    <body>
    
    <form  method="get" action="" onsubmit='return formValidator()' >
    <fieldset id="personalInfo">
    
                        <h3> Student Results </h3>
    
    
    
    <!-- A bordered table for item orders -->
    
    
    
          <table border = "border">
    
    
    
    <!-- First, the column headings -->
    
    
    
            <tr>
    
              <th> Module Name </th>
    
              <th> Pass Mark </th>
    
              <th> Final Mark </th>
    
            </tr>
    
    
    
    <!-- Now, the table data entries -->
    
    
    
            <tr>
    
              <th> C++ </th>
    
              <td> 40 % </td>
    
              <td> <input type = "text"  id = "c"  
    
                          size ="10" /> </td>
    
            </tr>
    
            <tr>
    
              <th> Computer Systems </th>
    
              <td> 40 % </td>
    
              <td> <input type = "text"  id = "computer"  
    
                    size = "10" /> </td>
    
            </tr>
    
            <tr>
    
              <th> Web Development </th>
    
              <td> 40 %  </td>
    
              <td> <input type = "text"  id = "web"  
    
                    size = "10" /></td>
    
            </tr>
             <tr>
    
              <th> Maths </th>
    
              <td> 40 %  </td>
    
              <td> <input type = "text"  id = "math"  
    
                          size ="10" /> </td>
    
            </tr>
    
          </table>
    
    
    
    <!-- Button for precomputation of the total cost -->
    
    
    
          <p>
    
            <input type = "button"  value = "Total Grade"
    
                   onclick = "compute();" />
    
            <input type = "text"  size = "5"  id = "cost"
    
                   onfocus = "this.blur();" />
    
          </p>
                  
                  
                  
        
    
    
    
    
              
    </fieldset>
                  </p>
      <input type='submit' value='Check Form' />
    
    </form>
    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    You have a total of 5 variables in your code (c, computer, web, math and totalCost). But you are comparing a variable "cost" to get the grade. I think you should replace "cost" with "totalCost" down there.

  • #3
    New Coder
    Join Date
    Feb 2012
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts
    The Total Cost is the Vaule of the Button that gives the GPA,

    was thinking of just making it simpler..
    how would i get a popup after i enter in the value that states you got an A or a F

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    var c = document.getElementById("c").value;

    Do not use the same name for an HTML element and a Javascript variable.

    It is obvious that you have copied this from somewhere with no attempt to make the variable names something sensible. What has "cost" to do with student grades?

    Name your textboxes Subject1, Subject2 etc. or better the actual subject names.

    Code:
    var grade = "Failed";
    if (totalmark >=40) {grade = "D"}
    if (totalmark >=60) {grade = "C"}
    if (totalmark >=78) {grade = "B"}
    if (totalmark >=85) {grade = "A"}
    if (totalmark >=93) {grade = "A+"}
    alert ("Your grade is " + grade);
    What if the user enters nonsense (or nothing at all) into the textboxes?

    I used to go to church religiously. - Interviewee BBC Radio 4
    Last edited by Philip M; 02-28-2012 at 03:29 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New Coder
    Join Date
    Feb 2012
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Yes i have copy a bit of the code,

    from Example labs that were given to us in web development

    if the user enters in nothing or nonsense i have some JS functions that will stop them

    I have no problem with that part but its getting the popup box up as they enter in a mark to give them an A or F

    i have change this around..
    so i not getting the GPA just want a alert box to pop up after they enter their Mark

    Code:
    
       Enter Semester: <br  />
                <input type='text' id='semester'  placeholder="Enter Seemster"/>
                  </p>
                  <p>
                   Module Results: <br  /> 
        <select id='course1'>
                    <option>Please Choose</option>
                    <option value="c">C++</option>
                    <option value="java">Java 1</option>
                    <option value="java2">Java 2</option>
                    <option value="hard">Computer HardWare</option>
                    <option value="data">DataBase System 1</option>
                    <option value="data2">DataBase System 2</option>
                    <option value="system">System Administration 1</option>
                  </select><br  />
                  <input type='text' id='module1'  placeholder="Enter Module Results"/>
                     </p>
    <p>
         <select id='course2'>
                    <option>Please Choose</option>
                    <option value="c">C++</option>
                    <option value="java">Java 1</option>
                    <option value="java2">Java 2</option>
                    <option value="hard">Computer HardWare</option>
                    <option value="data">DataBase System 1</option>
                    <option value="data2">DataBase System 2</option>
                    <option value="system">System Administration 1</option>
                  </select><br  />
                  <input type='text' id='module2'  placeholder="Enter Module Results"/>
                     </p>
    <p>
         <select id='course3'>
                    <option>Please Choose</option>
                    <option value="c">C++</option>
                    <option value="java">Java 1</option>
                    <option value="java2">Java 2</option>
                    <option value="hard">Computer HardWare</option>
                    <option value="data">DataBase System 1</option>
                    <option value="data2">DataBase System 2</option>
                    <option value="system">System Administration 1</option>
                  </select><br  />
                  <input type='text' id='module3'  placeholder="Enter Module Results"/>
                     </p>
    <p>
     <select id='course4'>
                    <option>Please Choose</option>
                    <option value="c">C++</option>
                    <option value="java">Java 1</option>
                    <option value="java2">Java 2</option>
                    <option value="hard">Computer HardWare</option>
                    <option value="data">DataBase System 1</option>
                    <option value="data2">DataBase System 2</option>
                    <option value="system">System Administration 1</option>
                  </select><br />
                  <input type='text' id='module4'  placeholder="Enter Module Results"/>
                  </p>
               
    </fieldset>
                  </p>
      <input type='submit' value='Check Form' />
    Last edited by jace_co_uk; 02-28-2012 at 04:23 PM.

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Code:
    <input type='text'  size = "3" maxlength = "3" id='module1'  onblur = "show(this)" placeholder="Enter Module Results"/>
    <input type='text'  size = "3" maxlength = "3" id='module2'  onblur = "show(this)" placeholder="Enter Module Results"/>
    <input type='text'  size = "3" maxlength = "3" id='module3'  onblur = "show(this)" placeholder="Enter Module Results"/>
    
    <script type = "text/javascript">
    
    function show(which) {
    var mark =  parseInt(which.value,10) || 0;    // trap non-numeric entries, make number integer
    if (mark >100)  {mark == 100}  // maximum 100
    which.value = mark;  // write it back to the field
    var mod = which.id;
    var grade = "Failed";
    if (mark >=40) {grade = "D"}
    if (mark >=60) {grade = "C"}
    if (mark >=78) {grade = "B"}
    if (mark >=85) {grade = "A"}
    if (mark >=93) {grade = "A+"}
    alert ("Your grade for " + mod + " is " + grade);
    }
    
    </script>
    Last edited by Philip M; 02-28-2012 at 05:52 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    jace_co_uk (02-28-2012)

  • #7
    New Coder
    Join Date
    Feb 2012
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks alot..

    i'll mess around with this one function.. and see what else i could add to it


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •