dcsimg
www.webdeveloper.com
Results 1 to 15 of 15

Thread: Please Help!!!!

  1. #1
    Join Date
    May 2010
    Posts
    10

    Angry Please Help!!!!

    I was told to do this in a class. This code doesn't work like the teacher says it should. The problem is that it is suppose to add the text boxes together and total it in a final total text box. please help!



    Sorry for the amount of code.


    [html]
    [head]
    [title]
    Javascript Grade Calculator
    </title>

    <script Language="javascript">
    <!--This Javascript was created by Matthew Horner-->

    function do_addition()

    {

    var lab1,lab2,test1,test2, final, cp;
    lab1=document.form1.Lab1Score.value;
    lab2=document.form1.Lab2Score.value;
    test1=document.form1.Test1Score.value;
    test2=document.form1.Test2Score.value;
    final=document.form1.FinalScore.value;
    cp=document.form1.Classparticipationscore.value;



    alert("The Value of Lab 1 is "+lab1+" so I got to the function")
    alert("The Value of Lab 2 is "+lab2+" so I got to the function")
    alert("The Value of Test 1 is "+test1+" so I got to the function")
    alert("The Value of Test 2 is "+test2+" so I got to the function")
    alert("The Value of Final is "+final+" so I got to the function")
    alert("The Value of Class Participation is "+cp+" so I got to the function")
    alert("The Value of Total Score is "+total+" so I got to the function")


    result=parseFloat(lab1)+parseFloat(lab2)+parseFloat(test1)+parseFloa(test2)+parseFloat(final)+parseF loat(cp);
    document.form1.Total.value=result;

    if (result >=405 && result<=450) {alert("Total Points of "+result+" gives you an A")}
    if (result >=360 && result<=404) {alert("Total Points of "+result+" gives you an B")}
    if (result >=292 && result<=359) {alert("Total Points of "+result+" gives you an C")}
    if (result >=247 && result<=291) {alert("Total Points of "+result+" gives you an D")}
    if (result >=0 && result<=246) {alert("Total Points of "+result+" gives you an F")}
    }

    </script>
    </head>

    <body>

    <form name="form1">

    Lab #1 (30 points):
    <input type="text" name="Lab1Score" size="5"><br>

    Lab #2 (70 points):
    <input type="text" name="Lab2Score" size="5"><br>

    Test #1 (100 points):
    <input type="text" name="Test1Score" size="5"><br>

    Test #2 (100 points):
    <input type="text" name="Test2Score" size="5"><br>

    Final (100 points):
    <input type="text" name="FinalScore" size="5"><br>

    Class Participation (50 points):
    <input type="text" name="Classparticipationscore" size="5"><br>


    <input type="button" value="Calculate your score" name="add" onClick="do_addition()"><br>
    <p> Total Points (450)
    <input type="text" name="Total" size ="6"><br>
    <input type="reset" value=Reset><br>
    </form>

    </body>
    </html>

  2. #2
    Join Date
    Mar 2010
    Posts
    2,803
    even after I fix the syntax error in line 34, both the IE and FF browsers tell you exactly what the logical error is and in what line number it is in.

    are you not using 1 of these 2 browsers?

    btw - first fix the brackets in html, head and title

  3. #3
    Join Date
    May 2010
    Posts
    10

    errors

    I put it in dreamweaver and it showed those errors. I could not figure out what they where.

  4. #4
    Join Date
    Mar 2010
    Posts
    2,803
    post errors you got in DW.

  5. #5
    Join Date
    May 2010
    Posts
    10
    syntax error on line 15 and line 34

  6. #6
    Join Date
    Mar 2010
    Posts
    2,803
    ok, but I'm not sure what you want.

    Do you want:

    1) someone guide you through some basic debugging 101 to fix the problems

    or

    2) someone to sit down, correct the code for you and post the correct error free code for you to take to class.

    If it's 1) then go to line 34 and the syntax error is very obvious. If you can't find it, then post just line 34 as you see it to ensure we are both looking at the same line number.

  7. #7
    Join Date
    May 2010
    Posts
    10
    I just want someone to show me the basics of debugging. I am new to javascript.

    This is my line 34

    result=parseFloat(lab1)+parseFloat(lab2)+parseFloat(test1)+parseFloat(test2)+parseFloat(cp)+parseFlo at(final);

  8. #8
    Join Date
    May 2010
    Posts
    10
    Do you see a syntax error on line 15?

  9. #9
    Join Date
    Mar 2010
    Posts
    2,803
    no offence - but you will be hard pressed to convince me you can't see anything wrong in that line 34. (btw - that line is as I se it as well)

    If you genuinely can't see the syntax error, then to be honest I suspect you didn't write the code but most probably copied and pasted it from somewhere because the error sticks out like the proverbial sore thumb.

  10. #10
    Join Date
    May 2010
    Posts
    10
    I see the errors on line 34 but on my computer they are right. It must have copy and pasted weird.

  11. #11
    Join Date
    May 2010
    Posts
    10
    This is the correct code that I have already on my computer.
    result=parseFloat(lab1)+parseFloat(lab2)+parseFloat(test1)+parseFloat(test2)+parseFloat(cp)+parseFlo at(final);

  12. #12
    Join Date
    May 2010
    Posts
    10
    That last float keeps doing that weird space thing. I did write every word of it by hand and I am about to go crazy

  13. #13
    Join Date
    Mar 2010
    Posts
    2,803
    nup sorry - I'm not convinced you are being totally truthful here because you said DW sees it as an error since you said it generates a syntax error at line 34 and so the copy and paste is ok.

    hopefully someone else will come along to help you

    good luck.

  14. #14
    Join Date
    May 2010
    Posts
    10
    Thanks for the help. I don't understand what is wrong and I did exactly what my teacher wanted me and my class to do. I copied it word for word and I guess I just don't see it. Hopefully someone can help. Thanks for your time.

  15. #15
    Join Date
    May 2010
    Posts
    10
    I figured it out by myself with firebug in mozilla. Thanks for all the help

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