# Build a Device Loan Ledger - Build a Device Loan Ledger

**URL:** <https://forum.freecodecamp.org/t/build-a-device-loan-ledger-build-a-device-loan-ledger/800189>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [September 14, 2026, 6:52pm UTC](https://forum.freecodecamp.org/t/build-a-device-loan-ledger-build-a-device-loan-ledger/800189 "2026-09-14T18:52:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mks616](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mks616/32/388810_2.png) [@mks616](https://forum.freecodecamp.org/u/mks616)\
**Post date:** [September 14, 2026, 6:52pm UTC](https://forum.freecodecamp.org/t/build-a-device-loan-ledger-build-a-device-loan-ledger/800189/1 "2026-09-14T18:52:09Z")

</div>

### Tell us what’s happening:

Hi Everyone,

For some reason my code fails checks 18-20 (listOverdueDevice) though I’m pretty sure it returns correct devices in correct order. Any hint on what I’m missing?

### Your code so far

```js
const equipmentLedger = {
  "1": { type: "PC", status: "CheckedOut", borrower: { name: "John Smith", email: "john@acme.org" }, dueDate: "1/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/1/2025" },
  "4": { type: "iPad", status: "CheckedIn", borrower: { name: "", email: "" }, dueDate: "" }
};

const checkinDevice = (ledger, assetTag) => {
	let confirmationString = `Asset ${assetTag} checked in`;
	let counter = 0;
	let updatedLedger = structuredClone(ledger);
	if (updatedLedger[assetTag]) 
		{
			updatedLedger[assetTag].borrower.email = "";	
			updatedLedger[assetTag].borrower.name = "";
			updatedLedger[assetTag].dueDate = "";
			updatedLedger[assetTag].status = "CheckedIn";
			counter = 1
		}
	if (counter === 0) {confirmationString = `Asset ${assetTag} not found`}
	return { ledger: updatedLedger, message: confirmationString}
}

const checkoutDevice = (ledger, assetTag, borrower) => {
	let confirmationString = `Asset ${assetTag} checked out to ${borrower.name}`;
	let counter = 0;
	let updatedLedger = structuredClone(ledger);
    if (updatedLedger[assetTag]) {
		if (updatedLedger[assetTag].status === "CheckedOut") {confirmationString = `Asset ${assetTag} already checked out`}
			else {
				updatedLedger[assetTag].borrower = borrower;
				updatedLedger[assetTag].status = "CheckedOut";
				counter = 1
			}
	}
	if (counter === 0) {confirmationString = `Asset ${assetTag} not found`}
	return { ledger: updatedLedger, message: confirmationString}
}

const listOverdueDevices = (ledger, today) => {
	let overdueDevices = [];
	let todayArr = today.split("/");
	if (todayArr[0].length === 1) {todayArr[0] = "0" + todayArr[0]}
  if (todayArr[1].length === 1) {todayArr[1] = "0" + todayArr[1]}
	let todayStr = todayArr[2] + todayArr[0] + todayArr[1];
  let updatedLedger = structuredClone(ledger);
  //console.log("Today is " + todayStr);
	for (let i = 1; i <= Object.keys(updatedLedger).length; i++) {
    //console.log(updatedLedger[i])
		if (updatedLedger[i].status === "CheckedOut") {
			let dateArr = updatedLedger[i].dueDate.split("/");
			if (dateArr[0].length === 1) {dateArr[0] = "0" + dateArr[0]}
      if (dateArr[1].length === 1) {dateArr[1] = "0" + dateArr[1]}
			let dateStr = dateArr[2] + dateArr[0] + dateArr[1];
      //console.log(dateStr);
			if (parseInt(dateStr) > parseInt(todayStr)) {
				updatedLedger[i].dateStr = dateStr;
				overdueDevices.push(updatedLedger[i])
			}
		}
	}
	overdueDevices.sort(function(a, b) {return parseInt(a.dateStr) - parseInt(b.dateStr)});
  for (let device of overdueDevices) {delete(device.dateStr)}
	return overdueDevices
}

const loadLedger = (str) => {return JSON.parse(str)}
const serializeLedger = (ledger) => {return JSON.stringify(ledger)}

console.log(listOverdueDevices(equipmentLedger, "9/11/2001"))

```

### Your browser information:

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

### Challenge Information:

Build a Device Loan Ledger - Build a Device Loan Ledger

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-v9/lab-device-loan-ledger/lab-device-loan-ledger)**
>
> Learn to Code for Free

GitHub Link: [freeCodeCamp/curriculum/challenges/english/blocks/lab-device-loan-ledger/69f0a37c3bf194a7c9c62492.md at main · freeCodeCamp/freeCodeCamp · GitHub](https://github.com/freeCodeCamp/freeCodeCamp/blob/main/curriculum/challenges/english/blocks/lab-device-loan-ledger/69f0a37c3bf194a7c9c62492.md)

---

<div class="post-metadata">

**Author:** ![sanity](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sanity/32/378897_2.png) [@sanity](https://forum.freecodecamp.org/u/sanity)\
**Post date:** [September 15, 2026, 4:30am UTC](https://forum.freecodecamp.org/t/build-a-device-loan-ledger-build-a-device-loan-ledger/800189/2 "2026-09-15T04:30:48Z")

</div>

To make sure the correct devices are returned, have you tried testing it with _today’s date_ that’s between due dates of two checked out items?

---

<div class="post-metadata">

**Author:** ![mks616](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mks616/32/388810_2.png) [@mks616](https://forum.freecodecamp.org/u/mks616)\
**Post date:** [September 15, 2026, 11:03am UTC](https://forum.freecodecamp.org/t/build-a-device-loan-ledger-build-a-device-loan-ledger/800189/3 "2026-09-15T11:03:07Z")

</div>

That was it, thank you!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [September 17, 2026, 11:03am UTC](https://forum.freecodecamp.org/t/build-a-device-loan-ledger-build-a-device-loan-ledger/800189/4 "2026-09-17T11:03:19Z")

</div>

Closed on September 17, 2026, 11:03am UTC

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
