Build a Device Loan Ledger - Build a Device Loan Ledger

Tell us what’s happening:

I’m curious how we’re meant to complete the listOverdueDevices function if we haven’t gotten to for loops yet in the curriculum. We could manually enumerate each assetTag but that isn’t repeatable for ledgers with different lengths. Is there some Array or Object method I’m missing that was previously discussed?

Your 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: "" },
  "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: "" }
};

// 1 
function checkoutDevice(ledger, assetTag, borrower) {
  // 10 return ledger unchanged when asset tag not found
  if (!(assetTag in ledger)) {
    return {
      ledger: ledger,
      message: `Asset tag ${assetTag} not found`
    }
  }
  // 11 return unchanged when already checked out
  if (ledger[assetTag].status === "CheckedOut") {
    return {
      ledger: ledger,
      message: `Asset ${assetTag} is already checked out by ${ledger[assetTag].borrower.name}.`
     }
  }
  // 6 clone ledger
  const clonedLedger = {...ledger};
  // 7 set borrower's name and email, status -> "CheckedOut"
  clonedLedger[assetTag].borrower = borrower;
  clonedLedger[assetTag].status = "CheckedOut";
  
  // 8 return confirmation message
  // 9 preserve unrelated devices/unchanged fields
  return {
    ledger: clonedLedger,
    message: `Asset ${assetTag} checked out by ${borrower.name}`
  }
};


// 2
function checkinDevice(ledger, assetTag) {
  if (!(assetTag in ledger)) {
    return {
      ledger: ledger,
      message: `Asset tag ${assetTag} not found`
    }
  }
  // 12 clone ledger
  const clonedLedger = {...ledger};

  // 13 clear borrower name/email, reset duedate, status -> CheckedIn
  clonedLedger[assetTag].borrower = {
    name: "", email: ""
  };
  clonedLedger[assetTag].dueDate = "";
  clonedLedger[assetTag].status = "CheckedIn";
  // 14 asset tag in confirmation message
  return {
    ledger: clonedLedger,
    message: `Asset ${assetTag} is checked in.`
  };

};



// 3 
function listOverdueDevices(ledger, today) {
  
};

// 4
function serializeLedger(ledger) {
  return JSON.stringify(ledger);
};

// 5 
function loadLedger(json) {
  return JSON.parse(json);
};



// TESTS

// console.log(checkoutDevice(equipmentLedger, "2", {name: "Kevin", email: "kevin@kevin.kevin"}).ledger);
console.log(checkinDevice(equipmentLedger, "3").ledger);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:155.0) Gecko/20100101 Firefox/155.0

Challenge Information:

Build a Device Loan Ledger - Build a Device Loan Ledger

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

Hi @kevdub

I see what you mean. This is a relatively new challenge, so I’m thinking that was overlooked when it was placed in the curriculum.

I’ll open an issue for this.

Happy coding