Build a Record Collection

Hi all,

updateRecords is not registering as a function. I have scanned it myself, compared to other students’ arrow function syntax who were passing the same tests I am failing, ran it through a validator and had it analyzed by AI, all of which claimed it was, in fact, a function. I have also refreshed the page.

let recordCollection = {
  2548: {
    albumTitle: 'Slippery When Wet',
    artist: 'Bon Jovi',
    tracks: ['Let It Rock', 'You Give Love a Bad Name']
  },
  2468: {
    albumTitle: '1999',
    artist: 'Prince',
    tracks: ['1999', 'Little Red Corvette']
  },
  1245: {
    artist: 'Robert Palmer',
    tracks: []
  },
  5439: {
    albumTitle: 'ABBA Gold' 
  }
};

const updateRecords = (records, id, prop, value) => {

if (value === "") {
  
  delete records[id][prop];
  return records;
}

else if (prop !== "tracks" && value !== "") {
  
  records[id][prop] = value; 
  return records;
}

else if (prop === "tracks" && value !== "" && !records[id].hasOwnProperty("tracks")) 
{

  records[id][prop] = [];
  records[id][prop].push(value);
  return records;

}

else if (prop === "tracks" && value !== "") {
  
  let update = records[id][prop];
  update.push(value);
  return records;
}
}



That says nothing about the correctness of your code.

Applying some syntax formatting, I don’t see an obvious issue. What is the link to this step/lab/workshop/project?

const updateRecords = (records, id, prop, value) => {
  if (value === "") {
    delete records[id][prop];
    return records;
  } else if (prop !== "tracks" && value !== "") {
    records[id][prop] = value; 
    return records;
  } else if (prop === "tracks" && value !== "" && !records[id].hasOwnProperty("tracks")) {
    records[id][prop] = [];
    records[id][prop].push(value);
    return records;
  } else if (prop === "tracks" && value !== "") {
    let update = records[id][prop];
    update.push(value);
    return records;
  }
}

(Note - you can significantly simplify your if conditions)

I’m not sure exactly what “not registering as a function” means?

1 Like

Your solution works from my end. Please try one of the following steps to move forward.

Click on the “Restart Step” button and force a refresh of your page with CTRL + F5 then try to paste the code in again.

or - Try the step in incognito or private mode.

or - Disable any/all extensions that interface with the freeCodeCamp website (such as Dark Mode, Ad Blockers, or Spellcheckers), and set your browser zoom level to 100%. Both of these factors can cause tests to fail erroneously.

or - Ensure your browser is up-to-date or try a different browser.

I hope one of these will work for you.

1 Like

Hi Jeremy, thanks for replying so quickly. By ‘had it analyzed by AI’ I merely meant I showed the code to AI and asked if it was a function and it agreed it was. The link is Build a Record Collection: Build a Record Collection | freeCodeCamp.org

Yes, and that says nothing about the correctness of your code. LLMs do not actually have the capacity to reason or check your code.

1 Like

If I use exactly this solution and change nothing else, this code passes for me too.

1 Like

Additionally, by ‘not registering as a function’, I mean the console returns the entire object syntax and reads the following TypeError:

TypeError: recordCollection is not a function

I’d try in private mode or try a different browser. Seems like the problem may be your browser.

1 Like

good to know! Thanks guys for your help.

do you have other lines in the editor other than those you shared here? maybe try to share those two, we could figure out where it’s coming from

1 Like

You were right. I deleted a bunch of console.log()s I had been using for testing. Incomplete syntax on one of them. Didn’t think they were relevant.