Gradebook

The Big Idea

You will take two arrays of data — student names and their test scores — and transform them into a gradebook object. This challenge builds on everything you know about objects, arrays, and functions.

Your Roadmap

SectionTimeRequired?
The data5 min⚑ Required
Build the gradebook step by step4 hrs⚑ Required

The data

You are given a teacher's data:

const students = ['Joseph', 'Susan', 'Wiremu', 'Elizabeth']
const scores = [
[80, 70, 70, 100],
[85, 80, 90, 90],
[75, 70, 80, 75],
[100, 90, 95, 85],
]

Your goal is to transform this into a gradebook object.

Note: Some properties in this challenge need bracket notation to be referenced correctly. If you are unsure of the difference, read this article on dot vs bracket notation.


Build the gradebook step by step

Complete each step in order. Run the tests after each one before moving on.

Run the tests:

npm test 4-gradebook

Create your gradebook

Create a variable gradebook and assign it an empty object.

Add students to the gradebook

Add each student from the students array as a property of gradebook. The key should be the student's name and the value should be a new empty object.

testScores

Add a testScores property to each student in gradebook. The value should be that student's scores from the scores array.

addScore

Create an addScore function that takes name and score as parameters. It should push the score onto the named student's testScores array.

addScore('Susan', 80) // pushes 80 into gradebook.Susan.testScores

average

Create an average function that takes an array of numbers and returns their average.

getAverage

Create a getAverage function that takes a student's name and returns the average of their testScores. Use your average function inside it.