on-internet
← Community

Why is my function returning a sparse array (javascript)?

Stack Overflow ·

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

Comments

Sign in or sign up to comment and upvote.

No comments yet.