HI im a student and I programed this calculator for give a average for 3 grades yet I cant calculate/average my final grade, I wish for advance.Thanks P.S I could find a way to post my HTML and my java so i put photos,sorry. picture 1picture2
Asked
Active
Viewed 607 times
-6
-
2please read this if you're going to ask about homework https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions – Isaac Jun 01 '17 at 03:56
-
Provide HTML also – Karan Singh Jun 01 '17 at 03:56
-
Where's the question? What problems have you encountered? What have you tried? – Assafi Cohen-Arazi Jun 01 '17 at 03:58
-
1Provide HTML text not image – Karan Singh Jun 01 '17 at 03:59
-
4are you gonna submit your code as a photo to your professor? – Dalin Huang Jun 01 '17 at 04:00
-
SO Isn't a place to get people to do things for you, this is a place to ask for help/direction in a problem. Read what @Isaac posted and try again. – Baruch Jun 01 '17 at 04:01
-
The first three lines of your `calculator()` function have syntax errors. Also, the IDs you are referencing in your JS do not exist in the HTML shown in the picture. (A picture? Please don't do that. [Edit] your question and paste the HTML as text.) – nnnnnn Jun 01 '17 at 04:05
2 Answers
0
You got to match the id and get value document.getElementById('homework').value
<script type="text/javascript">
function calculator() {
var homework = parseFloat(document.getElementById('homework').value);
var labs = parseFloat(document.getElementById('labs').value);
var midterm = parseFloat(document.getElementById('midterm').value);
var finals = parseFloat(document.getElementById('finals').value);
var total = homework + labs + midterm + finals;
var display = document.getElementById('outputDiv');
display.innerHTML = 'Your Final Grade Is: ' + total;
}
</script>

Dalin Huang
- 11,212
- 5
- 32
- 49
-
Hi i would like to edit my question. Where can I edit my question? – Soichiro Okuyama Jun 01 '17 at 04:16
-
0
Read this link:
And edit your code to:
<script type="text/javascript">
function calculator()
{
var grade1 = parseFloat(document.getElementById('first').value);
var grade2 = parseFloat(document.getElementById('second').value);
var grade3 = parseFloat(document.getElementById('thrid').value);
var total = grade1 + grade2 + grade3;
document.getElementById('outputDiv').innerHTML='Your Final Grade Is: ' +total;
}
</script>

Ali Hesari
- 1,821
- 5
- 25
- 51