Arrays Code Analysis
Arrays Code Analysis
function calculateGPA(gradesEarned)
{
let totalGrades = 0;
let numGrades = gradesEarned-length;
let avg;
for(let e of gradesEarned)
{
totalGrades = totalGrades + element;
}
avg = Math.round(totalGrades / numGrades);
return;
}
gpa = calculateGPA(grades);
Unless Otherwise Noted All Content © 2023 Florida Virtual School. FlexPoint Education Cloud™ is a trademark of Florida Virtual School
Corrected Version
function calculateGPA(gradesEarned) {
let totalGrades = 0;
let numGrades = gradesEarned.length;
let avg;
gpa = calculateGPA(grades);
Unless Otherwise Noted All Content © 2023 Florida Virtual School. FlexPoint Education Cloud™ is a trademark of Florida Virtual School
Part II: Written Response
Using a word processing program of your choice, create a 1-2 sentence response
for each question below. Your answers to questions 2-4 will be based on the
corrected code for the program after you have fixed the errors.
Your responses should be in complete sentences using proper grammar, spelling,
and punctuation.
Describe the purpose and function of the program.
The program calculates the GPA by averaging the grades in the array. It
adds all grades together and divides by the number of grades.
Identify the name of the array and describe the data in the array, what it
represents in the program, and how it is used to fulfill the program’s
purpose.
The grades array stores the student's grades. It is used to calculate the total
and average GPA.
The array stores multiple grades in one place, making it easier to calculate
the GPA. Without the array, each grade would need to be written separately.
What errors were identified and what needs to be done to correct them?
The program had syntax errors with the array and wrong variable names.
These were fixed by correcting the array declaration and using the correct
variable names.
Unless Otherwise Noted All Content © 2023 Florida Virtual School. FlexPoint Education Cloud™ is a trademark of Florida Virtual School
Part III: What to Submit
Unless Otherwise Noted All Content © 2023 Florida Virtual School. FlexPoint Education Cloud™ is a trademark of Florida Virtual School