Skip to content

Build a Campus Directory Normalizer - Step 47 - Step 50 #71783

In progress
notsoravii/freeCodeCamp
#2

Description

@Gazdean

Describe the Issue

Inconsistency when using equality and strict equality to increment counters in Build a Campus Directory Normalizer.

Step 47

Inside the loop, check if instructorValues[i].officeHours == null. If true, increment missingOfficeHours by 1.

Step 50

Inside the loop, check if programValues[i].room === null. If true, increment programsWithoutRooms by 1.

Affected Page

https://www.freecodecamp.org/learn/javascript-v9/workshop-campus-directory-normalizer/step-47

Your code

const rawData = {
  "Computer Science": {
    Dept_code: "CSE",
    programs: [
      {
        id: "CSE101",
        name: "Database Management System",
        room: "405",
        instructors: [
          { id: "INS001", name: "Alejandro", email: "[email protected]", officeHours: "Sun-Tue 10AM-12PM" },
          { id: "INS002", name: "Kenji", officeHours: null },
        ],
      },
      {
        id: "CSE102",
        name: "Data Structures",
        room: null,
        instructors: [
          { id: "INS003", name: "Fatima", email: "[email protected]", officeHours: "Mon-Wed 10AM-2PM" },
        ],
      },
      {
        id: "CSE103",
        name: "Operating Systems",
        room: "401",
        instructors: [
          { id: "INS005", name: "Wei", email: "[email protected]", officeHours: "Thu 1PM-3PM" },
        ],
      },
    ],
  },
  "Business Administration": {
    Dept_code: "BBA",
    programs: [
      {
        id: "BBA101",
        name: "Financial Accounting",
        room: "201",
        instructors: [{ id: "INS004", name: "Sofia", email: "[email protected]" }],
      },
      {
        id: "BBA102",
        name: "Marketing Management",
        room: "204",
        instructors: [
          { id: "INS006", name: "Robin", email: "[email protected]", officeHours: "Tue-Thu 9AM-11AM" },
        ],
      },
      {
        id: "BBA103",
        name: "Business Law",
        room: "203",
        instructors: [
          { id: "INS007", name: "Priya", email: "[email protected]", officeHours: "Mon 2PM-4PM" },
        ],
      },
    ],
  },
};


function normalizeDirectory(rawData) {
  const departmentsById = {};
  const programsById = {};
  const instructorsById = {};
  const instructorsByEmail = {};

  const departmentEntries = Object.entries(rawData);

  for (let i = 0; i < departmentEntries.length; i++) {

    const [departmentName, departmentData] = departmentEntries[i];

    const departmentId = departmentData.Dept_code || `dept-${i + 1}`;

    departmentsById[departmentId] = {
      id: departmentId,
      code: departmentData.Dept_code,
      name: departmentName,
      programIds: [],
    };

    for (let j = 0; j < departmentData.programs.length; j++) {
      const program = departmentData.programs[j];

      programsById[program.id] = {
        ...program,
        departmentId,
      };

      departmentsById[departmentId].programIds.push(program.id);
      for (let k = 0; k < program.instructors.length; k++) {
        const instructor = program.instructors[k];

        instructorsById[instructor.id] = {
          ...instructor,
          programId: program.id,
          departmentId,
        };

        if (instructor.email) {
          instructorsByEmail[instructor.email] = instructor.id;
        }
      }
    }
  }

  return {
    departmentsById,
    programsById,
    instructorsById,
    instructorsByEmail,
  };
}

const normalizedData = normalizeDirectory(rawData);


function getInstructorByEmail(email, normalizedData) {
  const instructorId = normalizedData.instructorsByEmail[email];

  if (!instructorId) {
    return "Instructor not found";
  }

  const instructor = normalizedData.instructorsById[instructorId];
  const department = normalizedData.departmentsById[instructor.departmentId];

  return {
    name: instructor.name ?? "Unknown Instructor",
    officeHours: instructor.officeHours ?? "Not Available",
    department: department.name ?? "Unknown Department",
  };
}


function listRoomsByBuilding(buildingCode, normalizedData) {

  const programValues = Object.values(normalizedData.programsById);
  const rooms = [];

  for (let i = 0; i < programValues.length; i++) {
    const program = programValues[i];
    const department = normalizedData.departmentsById[program.departmentId];

    if (department.code === buildingCode && program.room != null) {
      rooms.push(program.room);
    }
  }

  rooms.sort();
  return rooms;
}


function renderDirectorySummary(normalizedData) {
  const departments = Object.keys(normalizedData.departmentsById).length;
  const programs = Object.keys(normalizedData.programsById).length;
  const instructors = Object.keys(normalizedData.instructorsById).length;

  const instructorValues = Object.values(normalizedData.instructorsById);
  let missingOfficeHours = 0;

  for (let i = 0; i < instructorValues.length; i++) {
    
  }

}

Expected behavior

Step 50 should also use equailty instead of strict equality, so the single "if" condition checks for both a 'null' value and 'undefined' if the key value pair is missing
Maybe a brief explanation as to why equality is used over strict equality in Step 47s description

Screenshots

No response

System

  • Device: [e.g. iPhone 6, Laptop]
  • OS: [e.g. iOS 14, Windows 10, Ubuntu 20.04]
  • Browser: [e.g. Chrome, Safari]
  • Version: [e.g. 22]

Additional context

No response

Activity

  1. added theissue type on Nov 25, 2026
  2. added
    scope: curriculum
    status: waiting triage
    on Nov 25, 2026
  3. polyvexr commented on Nov 25, 2026

    @polyvexr

    Hi! Could a maintainer clarify whether the use of === null in Step 50 is intentional?

    Step 48 specifically describes programs whose room is explicitly null, which makes me think the strict equality check may be deliberate. However, Step 40 uses program.room != null, which also handles undefined.

    Should Step 50 count only explicitly null values, or should it also account for programs where the room property is missing (undefined)?

    I'd be interested in working on this issue if a change is needed. If maintainers agree that the behavior should be updated, could you please assign it to me? I'd be happy to implement the fix and submit a PR.

    Thanks!

  4. syedryaaan commented on Nov 25, 2026

    @syedryaaan

    Hi @Gazdean,

    I'd love to take ownership of this issue and contribute a fix.

    After reviewing the issue, I believe Step 50 should use == null instead of === null, matching the behavior in Step 47. This would ensure that both null and undefined values are handled correctly when checking for missing room properties.

    I'd like to:

    • Update the Step 50 condition for consistency with Step 47.
    • Review the relevant curriculum tests and ensure the expected behavior is covered.
    • Run the appropriate tests to verify the fix.
    • Submit a PR with the changes.

    Could you please assign this issue to me and allow me to work on it? I'll make sure to follow the repository's contributing guidelines and submit a clean, tested PR.

    Thank you!

  5. added
    js v9 cert
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    js v9 certscope: curriculumstatus: waiting triage

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions