0% found this document useful (0 votes)
21 views4 pages

Arrays Code Analysis

Uploaded by

kittu.sahoo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views4 pages

Arrays Code Analysis

Uploaded by

kittu.sahoo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Arrays Code Analysis

Part I: Review the Program

let grades = [82 89, 95, 90, 91 97;


let gpa;

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);

console.log("**** The GPA Calculator ****");


console.log();
console.log("Your grades are: ");
console.log(grades);
console.log();
console.log("Your GPA is: " + gpa);

Unless Otherwise Noted All Content © 2023 Florida Virtual School. FlexPoint Education Cloud™ is a trademark of Florida Virtual School
Corrected Version

let grades = [82, 89, 95, 90, 91, 97];


let gpa;

function calculateGPA(gradesEarned) {
let totalGrades = 0;
let numGrades = gradesEarned.length;
let avg;

for (let grade of gradesEarned) {


totalGrades = totalGrades + grade;
}
avg = Math.round(totalGrades / numGrades);
return avg;
}

gpa = calculateGPA(grades);

console.log("**** The GPA Calculator ****");


console.log();
console.log("Your grades are: ");
console.log(grades);
console.log();
console.log("Your GPA is: " + gpa);

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.

Describe how the array is used to manage complexity in this program.


Explain why the code could not be written without an array or how it would
need to be written differently if an array was not used.

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

Submit the following to your instructor:


A document with your written responses

Unless Otherwise Noted All Content © 2023 Florida Virtual School. FlexPoint Education Cloud™ is a trademark of Florida Virtual School

You might also like