Bitpath

Boss lesson · Unit 04

A gradebook

An array of objects turned into an average, a best student, groups and a sorted report

13 exercisesabout 3 min

What you practise

  • An array of objects: averages, the best student, grouping by grade, a sorted report

Try a question from this lesson

Pick one

A gradebook is an array of objects, one per student. Follow the path: which item, then which key? What does this print?

JavaScript
const students = [
  { name: "Ana", score: 82 },
  { name: "Bo", score: 67 },
  { name: "Cy", score: 91 },
];
console.log(students[1].name);

The idea

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Grouping

To sort things into groups, use an object: each key is a group, and each value is an array of its members.

The first time a group comes up, there is no array under its key yet. Asking for it gives undefined, which is falsy.

So check with !, create an empty array if needed, and then push.

JavaScript
const groups = {};
const grade = "B";
if (!groups[grade]) {
  groups[grade] = []; // first time
}
groups[grade].push("Ana");
console.log(groups.B.length); // 1

11 more exercises in the app

  • 4× type the answer
  • 1× order the lines
  • 3× multiple choice
  • 1× fill the blanks
  • 1× true or false
  • 1× match the pairs

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy