Gradebook
Learning Competencies
- Define local variables in JavaScript
- Define functions in JavaScript
- Create, add properties to, delete properties from, and access values in object literals
Time Box
Activity | Time |
---|---|
Kata | 4 hours |
Reflect | 10 minutes |
Summary
In this challenge, you will be taking your knowledge of JavaScript to the next level! Assume there is a teacher with a list of students and a list of their respective test scores. The teacher is providing you with this data which looks like ...
const students = ["Joseph", "Susan", "Wiremu", "Elizabeth"];const scores = [[80, 70, 70, 100],[85, 80, 90, 90],[75, 70, 80, 75],[100, 90, 95, 85],];
You will take this data and transform it into a gradebook. The gradebook will be a JavaScript object.
Get Coding!
Follow the steps below to make the tests pass and complete the challenge. The order of the steps corresponds to the order of the tests. After completing each step, run the code to check it has passed the test.
In the past, you had the option of using dot notation or bracket notation. Some properties need the bracket notation to be referenced correctly in this challenge. Find out why in this medium article on dot vs. bracket notation.
Create your gradebook
Create a variable gradebook
and assign it the value of an empty object.
Add students to the gradebook
Add each student (from the students
array) as a property to the gradebook
object. The key should equal the student’s name and the value should equal a new object.
testScores
Add a new property with a key of testScores
to each student property in gradebook
. The value of this property should be equal to the student’s scores in the scores
array.
addScore
Create an addScore
function that has two parameters: name
, and score
.
addScore
should add the score
which is passed to it to the given student’s testScores
array.
For example:
addScore("Susan", 80); // would push the score 80 into the value of gradebook.Susan.testScores
Create the average function
Create an average
function that returns the average of a given array of numbers.
getAverage
Create a getAverage
function that takes a name
parameter and returns the average of that student’s testScores
. You can call the average
function within this function.