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...inloop inlistOverdueDevices()rather than afor...ofloop with an array - calling a regular
forloop iterating overdevice[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 ![]()
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