Build a Device Loan Ledger - Help!

Tell us what’s happening:

I have been trying with this lab for about 5 or 6 hours total now over a few days. My rubber ducks have long since tired of my chuntering. Many w3schools/developer.mozilla.org pages, fCC forums, fCC curriculum lessons, etc have been opened. Several eureka moments have been had only to bear no fruit. At this point I struggle to remember what I have and haven’t tried doing. listOverdueDevices() has been a particular headache! As to what tests pass, it seems to randomly shuffle every time I make any sort of change! Is there something huge I’m missing here?

A small list of things I think I maybe tried(?)

  • calling a for...in loop in listOverdueDevices() rather than a for...of loop with an array
  • calling a regular for loop iterating over device[i]
  • endless combinations of dot notation and bracket notation for accessing properties
  • assigning every small step of the way to variables
  • properly destructuring objects
  • logging every line of code in the function to check for a stray undefined
  • praying

My code so far

const equipmentLedger = {
  "1": { 
    type: "PC", 
    status: "CheckedOut", 
    borrower: { 
      name: "John Smith", 
      email: "john@acme.org" 
      }, 
    dueDate: "11/30/2025" },
  "2": { 
    type: "Laptop", 
    status: "CheckedIn", 
    borrower: { 
      name: "", 
      email: "" 
      }, 
    dueDate: "11/15/2025" },
  "3": { 
    type: "Laptop", 
    status: "CheckedOut", 
    borrower: { 
      name: "Jane Doe", 
      email: "jane@acme.org" 
      }, 
    dueDate: "10/31/2025" },
  "4": { 
    type: "iPad", 
    status: "CheckedIn", 
    borrower: { 
      name: "", 
      email: "" 
      }, 
    dueDate: "11/03/2025" }
};

function serializeLedger(ledger){
  return JSON.stringify(ledger);
};
function loadLedger(json){
  return JSON.parse(json);
};

function checkoutDevice(ledger, assetTag, borrower){
  const clonedLedger = loadLedger(serializeLedger(ledger));
  if (assetTag in clonedLedger){
    clonedLedger.assetTag.borrower.name = borrower.name;
    clonedLedger.assetTag.borrower.email = borrower.email;
    clonedLedger.assetTag.status = "CheckedOut";
    const output = {
      "ledger": clonedLedger,
      "message": `${assetTag} checked out by ${borrower.name}`
    };
    return output;
  } else {
    const message = `${assetTag} not found.`
    return clonedLedger + message;
  };
};

function checkinDevice(ledger, assetTag){
  const clonedLedger = loadLedger(serializeLedger(ledger));
  if (assetTag in clonedLedger){
    delete clonedLedger.assetTag.borrower.name;
    delete clonedLedger.assetTag.borower.email;
    clonedLedger.assetTag.dueDate = "";
    clonedLedger.assetTag.status = "CheckedIn";
    const output = {
      ledger: clonedLedger,
      message: `${assetTag} checked in.`
    };
    return output;
  } else {
    const message = `${assetTag} not found.`
    return clonedLedger + message;
  };
};

// I was very proud of this one!
function transformDateString(mdy){
  const date = mdy.split("/");
  for (const chunk of date){
    if (chunk.length == 1){
      date.splice(date.indexOf(chunk), 1, `0${chunk}`)
    };
  };
  return Number(`${date[2]}${date[0]}${date[1]}`);
};

function listOverdueDevices(ledger, today){
  const overdueDevices = [];
  const transformedToday = transformDateString(today);
  for (const device of Object.values(ledger)){
    const transformedDateString = transformDateString(device.dueDate);
    if (transformedToday > transformedDateString && Object.values(ledger)[1] == "CheckedOut"){
      overdueDevices.push(device);
   };
  };
  return overdueDevices;
};

Thank you in advance! I always appreciate the patience of the mods on this forum :heart:

Browser information:

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:157.0) Gecko/20100101 Firefox/157.0 (Zen Browser - I can’t imagine it makes much difference from Firefox given it’s effectively a fork with tighter privacy and a shinier frontend but just in case!)

Challenge Information:

Build a Device Loan Ledger

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-device-loan-ledger/69f0a37c3bf194a7c9c62492.md at main · freeCodeCamp/freeCodeCamp · GitHub

Start with the status check in listOverdueDevices. Inside your loop, try logging device and Object.values(ledger)[1] side by side. Does [1] select a property of the current device, or the second device in the ledger? Are you comparing a status string with "CheckedOut", or a whole object?

Your loop already gives you the current device, and you access its dueDate property earlier in the loop. How could you use the same approach to check its status?

There is a related property-access issue in checkoutDevice and checkinDevice: clonedLedger.assetTag looks for a property literally named assetTag. Which notation lets you use the value stored in the assetTag parameter as the key?