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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to get the calculation to show in disabled textbox

    For some reason I cannot seem to get output in my disabled textboxes that the program generates after user input. It makes it very had to know if i am even codeing anything correctly. Could someone please point out my mistake that prevent the program from spitting out anything in the box?

    I am not sure either if I have my conditional statements in the correct place because while my book tells me how to write the statements it says nothing about where those statements should go in the code.

    Thanks in advance!





    Make a web page that does the following:

    •The user enters 5 grades that they've made in a particular class. Grades entered have to be between 0 and 100
    •A JavaScript function will take the 5 grades, find the average, and display the following in an alert box when the user clicks a button
    •If they made an A (90-100): display Excellent! You made an A in the class! Your average grade is: ___

    •If they made a B (80-89): display Good Job! You made a B in the class! Your average grade is: ___

    •C (70-79): display Not Bad! You made a C in the class! Your average grade is: ___

    •D (65-69): display Do better next time, you made a D. Your average grade is: ___

    •F(0-64): display Oh no....you made an F. Sorry you didn't pass. Your average grade is: ___



    Here is the code:
    <code>

    <title>Grade Average Calculator</title>

    <script type='text/javascript'>
    function calculateAverage() //this is the code for the calculation function
    {var a = parseInt(document.getElementById('firstNumber').value);
    var b = parseInt(document.getElementById('secondNumber').value);
    var c = parseInt(document.getElementById('thirdNumber').value);
    var d = parseInt(document.getElementById('fouthNumber').value);
    var e = parseInt(document.getElementById('fifthNumber').value); //assigns variables to the five grades
    var sum =5*(a+b+c+d+e);
    if (sum <= 64){alert ("Oh no....you made an F. Sorry you didn't pass. Your average grade is:")
    }else if (sum <= 69){alert ("Do better next time, you made a D. Your average grade is:")
    }else if (sum <= 79){alert ("Not Bad! You made a C in the class! Your average grade is:")
    }else if (sum <= 89){alert ("Good Job! You made a B in the class! Your average grade is:")
    }else if(sum <= 100){alert ("Excellent! You made an A in the class! Your average grade is:")} //else if that decides which message to diplay

    document.getElementById('gradePlaceholder').value = sum;}</script>

    </head>

    <body>

    <p>Please enter your five grades and I will display a message with your average.
    <br />
    Grade one <input type='text' id='firstNumber' /> <br />
    Grade two <input type='text' id='secondNumber' /> <br />
    Grade three <input type='text' id='thirdNumber' /> <br />
    Grade four <input type='text' id='fourthNumber' /> <br />
    Grade five <input type='text' id='fifthNumber' /> <br />

    <input type='text' id='gradePlaceholder' disabled='disabled'/> <br />
    <input type="button" id="calcAverage" value="Compute Average" onclick='calculateAverage()'/>


    </p>
    </body>
    </html>


    <code>
    Last edited by GypsyParrot; 01-26-2013 at 02:23 AM. Reason: code tags not working?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Code tags here are [ code ] and [ /code ] (without spaces of course).

    And look here:
    Code:
    var d = parseInt(document.getElementById('fouthNumber').value);
    vs.
    Grade four <input type='text' id='fourthNumber' /> <br />
    I think you need to learn what the word "average" means. But that's another issue.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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