Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-26-2013, 02:19 AM   PM User | #1
GypsyParrot
New to the CF scene

 
Join Date: Jan 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
GypsyParrot is an unknown quantity at this point
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?
GypsyParrot is offline   Reply With Quote
Old 01-26-2013, 02:29 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,237
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:21 AM.


Advertisement
Log in to turn off these ads.