I would usually ask a friend to help me who is good with javascript, but he’s unavailable and I’m pressed for time. It’s for my intro to programming class, and I got most of it..I think..let me just give you the prompt.
“Alberta Einstein teaches a business class at Podunk University. To evaluate the students in this class, she has given three tests. It is now the end of the semester and Alberta would like you to design a program, that inputs each student’s test scores and outputs the average score for each student and the overall class average.”
Ok, so I got it to input and output each individual student’s name and average, but I have no clue how to make it take the class average. Every attempt I have made for the past 2 hours have only taken the average of the last calculated student’s average and divided it by the total number of students entered in the class.
I was hoping you guys could take a quick look at my code and tell me what I’m missing to do the class average. I’m sure it’s something simple that just sliped my mind, but like I said, I have to turn this assignment in within 11 hours of now. (It’s 1:30 here.)
Now for my current code:
[CODE]
<script type =”text/javascript”>
//Lab 5-B
//Name
//11.03.05
//Class Average Program
//This program will create a class average based
//on 3 tests entered per student in the class.
//create the input function
function Input()
{
var counter = 0
var average = 0
var students = parseInt(prompt(“How many students are in the class?”, “”))
//create loop
while (counter++ < students)
{
var studentname = String(prompt(“Enter Student ” + counter + “‘s name.”,””))
var test1 = parseFloat(prompt(“Enter ” + studentname + “‘s first test score.”,””))
var test2 = parseFloat(prompt(“Enter ” + studentname + “‘s second test score.”,””))
var test3 = parseFloat(prompt(“Enter ” + studentname + “‘s third test score.”,””))
average = (test1 + test2 + test3) / 3
document.write(studentname + “‘s average score is ” + average + “.<br>”)
}
}
function Output()
{
classaverage = average / students
document.write(“The class average is: ” + classaverage + “.”)
}
var classaverage
Input()
Output()
</script>
Thanks in advance! ?