Skip to content
Aabha AI Academy
Skip to reading

JavaScript · Module 5

Answers and explanations · Model events with arrays and objects

Compare these references after your own attempt. You can read them at any time; they do not record a live model or vendor run.

A: it reads the first event object's id. An unsuccessful find returns undefined; accessing undefined.title throws a TypeError. Test whether a record was found before using it.

B:

const available = events.filter((event) => {
  return event.places > 0;
});

Without return, the callback returns undefined, so no record qualifies. Parentheses-only arrow expressions return implicitly, but braces-based bodies need return.

C:

function creativeTitles(events) {
  return events
    .filter((event) => event.category === "creative" && event.places > 0)
    .map((event) => event.title);
}

The first operation selects records; the second transforms each selected record to a title. Empty input gives []. A creative event with zero places is excluded. This code does not write into any record, though filtered arrays still refer to the same objects.

Return to the exercise

Return to this module