I'm learning Javascript. This is a problem I'm stuck on:
"Using a for loop, calculate the percentage of students' test scores stored in the testScore array. The test has a total of 100. Store the percentages in another array and display it to the console."
This was my solution (I know there's "better" alternative methods of solving this, but since I'm just learning, I'd rather understand first what I'm doing wrong here.):
const testScore = [10, 40, 30, 25];
const percentages = [];
const gradePercentage = (scores) => {
percentages[scores] = (scores / 100) * 100;
return percentages;
};
for (let i = 0; i < testScore.length; i++) {
gradePercentage(testScore[i]);
}
console.log(percentages);
I got the calculations right, but when trying to store it in another array, I get "empty" slots. Why?
This is what the console displayed: