www.webdeveloper.com
Results 1 to 5 of 5

Thread: I need help with javascript code please

  1. #1
    Join Date
    Apr 2012
    Posts
    6

    I need help with javascript code please

    So I have no idea what I'm doing wrong, but Im guessing I entered in the formula to calculate the final grade wrong because when I press the calculate button nothing shows up. Im not sure how I'm supposed to enter the formula. Can someone please point me in the right direction? By the way its a grade calculator where you can enter whatever the values are for each category and then at the end it gives you the numerical grade and also the letter grade. Thanks in advance.

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <title>Lab</title>
    <meta charset="utf-8">

    <script>
    function calculateGrade ()
    {
    var test1 = document.getElementById("t1")
    var test2 = document.getElementById("t2")
    var finalexam = document.getElementById("t3")
    var labs = document.getElementById("t4")
    var projects = document.getElementById("t5")
    var quizzes = document.getElementById("t6")
    var grade= document.getElementById("fng")

    grade.value=parseFloat(0.15*test1.value)+parseFloat(0.15*test2.value)+parseFloat(0.20*finalexam.valu e)+parseFloat(0.30*labs.value)+
    parseFloat(0.05*projects.value)+parseFloat(0.15*quizzes.value)
    }

    function getLetterGrade(totalGrade)
    {
    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";
    else if (totalGrade < 60 && totalGrade > =50)
    letterGrade = "F";
    }


    </script>

    </head>
    <body>
    <form id="form1" name="form1">
    <table>
    <tr>
    <th colspan="2"> Score </th>
    </tr>
    <tr>
    <td> Test 1 </td>
    <td><input type="text" name="t1" id="t1" value= ""></td>

    </tr>
    <tr>
    <td> Test 2 </td>
    <td><input type="text" name="t2" id="t2" value= ""></td>
    </tr>
    <tr>
    <td> Final Exam </td>
    <td><input type="text" name="t3" id="t3" value=""></td>
    </tr>
    <tr>
    <td> Labs </td>
    <td><input type="text" name="t4" id="t4" value=""></td>
    </tr>
    <tr>
    <td> Projects </td>
    <td><input type="text" name="t5" id="t5" value=""></td>
    </tr>
    <tr>
    <td> Quizzes </td>
    <td><input type="text" name="t6" id="t6" value=""></td>
    </tr>
    <tr>
    <th colspan="2">
    <input type="button" name="b1" id="b1" value="Calculate Grade"
    onclick="calculateGrade()">
    </th>
    </tr>

    <tr>
    <td> Final numerical grade </td>
    <td><input type="text" name="fng" id="fng" style="border: none"></td>
    </tr>
    <tr>
    <td> Final letter grade </td>
    <td><input type="text" name="letterGrade" id="letterGrade" style="border: none"></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,633
    Code:
    [14.06.1996 6:00:48] JavaScript - file://localhost...htm
    Inline script compilation
    Syntax error at line 12 while loading: expected ')', got 'e'
    0.20*finalexam.valu e)+parseFloat(0.30*l
    --------------------^
    [01.01.1970 4:01:40] JavaScript - file://localhost...htm
    Inline script compilation
    Syntax error at line 26 while loading: expected expression, got '='
     60 && totalGrade > =50)
    --------------------^
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  3. #3
    Join Date
    Mar 2012
    Posts
    202
    Quote Originally Posted by Padonak View Post
    x = x + 1; my wife calls it "absurd"
    Aha, yes. That sig made my day

  4. #4
    Join Date
    Apr 2012
    Posts
    6
    Thank you I got it fixed so the calculator is working now except now the letter grade wont show. What website did you go to find those errors I made?

  5. #5
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,633
    that was Opera error console. press Ctrl+Shift+O in Opera browser to see it
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles