• in
InterCourses
CoursesBlogs
0
← Introduction to JavaScript
○What is JavaScript?○Your First JavaScript Code○Data Types○Type Checking○Inspect Values in the Console○Inspect the Queue Report○Trace a Faulty Calculation○Repair the Score Calculation✦Module Quiz
○Declaring Variables○let and const in Practice○Operators○Type Conversion○Group and Convert Expense Inputs○Calculate the Event Expense Total○Track a Changing Points Tally○Adjust a Ticket Price✦Module Quiz
○Conditionals○Demo: Combined Conditions Before FizzBuzz○Challenge: FizzBuzz Announcer○Switch Statement○Demo: Switch a Venue Sign○Challenge: Power Loadout○For Loops○While Loop○Break and Continue○Demo: Stop a Ticket Scan○Challenge: Number Guess Referee○Demo: Rainfall Routing Walkthrough○Exercise: Score Batch Report✦Module Quiz
○Defining Functions○Arrow Functions○Scope○Closures○Project - Calculator○Function Expressions○Demo: Ticket Pricing Walkthrough○Exercise: Shipping Labels with Defaults○Demo: Seat Ledger Closure Walkthrough○Exercise: Private Budget Ledger✦Module Quiz
○Arrays○Demo: Student Scoreboard○Challenge: Student Course Scoreboard○Array Mutation Methods○Array Slice and Concat○Array Iteration Methods○Multidimensional Arrays○Destructuring○Array Reverse and Sort○Array Fill○Array Find and Includes○Array Flat and FlatMap○Array Reduce, Some, and Every○Demo: Charging Rack Restock Report○Exercise: Pantry Restock Plan✦Module Quiz
○Object Key-Value Pairs○Student Course Record○Object Methods and Destructuring○Map and Set Collections○Playlist Lookup○Number and BigInt Boundaries○Ticket Ledger○JSON○Math and Date○Date Basics○Demo: Supply Bin Audit○Exercise: Volunteer Shift Audit○Demo: Workshop Attendance Feed●Exercise: Parcel Scan Feed✦Module Quiz
○String Methods○Template Literals○Regular Expressions○Demo: Build a Reminder with Template Literals○Exercise: Format Pantry Pickup Messages○Demo: Validate a Time Slot with Regex○Exercise: Validate Storage Shelf Labels✦Module Quiz
○Higher-Order Functions○Callbacks○map, filter, and reduce○Demo: Student Register with map○Challenge: Student Register○Recursion○Project - Data Transform Pipeline○Demo: Handle an Error-First Callback○Exercise: Report Seat Reservation Results○Demo: Summarize Completed Bike Rides○Exercise: Summarize Delivered Parcels✦Module Quiz
○Demo: A notebook object○OOP Introduction○Demo: Independent workshop passes○Classes○Demo: An inherited notice○Inheritance○Demo: A private seat counter○Encapsulation○Demo: Equipment desk checkout○Project: Library Checkout✦Module Quiz
○Demo: Callback Timing○Exercise: Asynchronous JavaScript○Demo: Promise Rehearsal○Exercise: Promises and Async Await○Demo: Offline API Coordination○Exercise: Async API Simulation○Demo: Partial Results Bulletin○Project: Resilient Awards Feed○Demo: Retry a Local Delivery○Project: Reliable Score Delivery✦Module Quiz

Exercise: Parcel Scan Feed

The workshop demo parsed JSON, counted visits by topic, and tracked unique email addresses. Now process a shipping desk's parcel scans. Multiple scans of one parcel count as multiple scans but only one unique tracking ID. Work in script.js; no network or page markup is needed.

For example, a library check-in feed '[{"shelf":"A","card":"C1"},{"shelf":"A","card":"C1"}]' would produce a Map with A → 2 visits and a Set containing one card. Your task instead uses zone and tracking fields from parcel scans.

Worked example

A small visitor feed shows JSON parsing, counting by key, and tracking unique IDs:

javascript
const visits = JSON.parse('[{"room":"East","badge":"B1"},{"room":"East","badge":"B1"}]');
const byRoom = new Map();
const badges = new Set();
for (const visit of visits) {
  byRoom.set(visit.room, (byRoom.get(visit.room) ?? 0) + 1);
  badges.add(visit.badge);
}
console.log(byRoom.get("East"), badges.size); // 2 1

Your Task

  1. Write parseScans(jsonText) to parse JSON scan records into an array.
  2. Write countByZone(scans) to return a Map counting every scan by zone.
  3. Write uniqueIds(scans) to return a Set of tracking IDs.
  4. Write summarizeScans(jsonText) to use those helpers and return { byZone, uniqueTracking }.
  5. Make summarizeScans("[]") return an empty Map and Set.
  6. Log North: 2 | South: 2 | unique: 3 from summarizeScans(scanFeed) on its own Console line.

Objects and built-ins complete

You can now turn structured input into useful lookups and summaries. Take the section quiz, then work precisely with text.

Hint 1
1 / 2
HINT 1

Parse jsonText once; then iterate each scan in the resulting array.

HINT 2

Use (byZone.get(scan.zone) ?? 0) + 1 to increment counts.

Take the Quiz →
Loading editor…
Press Run to execute your code.
READY
intercourses
javascript