Tested my code in Chrome console and it worked, but it can't pass the test - why?

I finally came up with code that worked in Chrome console and it worked, but it can’t pass the test - I’d like to understand why that is.

Your code so far

function updateRecords(id, prop, value) {

  if (value !="") {

    function updateRecords(id, prop, value) {
  if (value !="") {

    if (collection[id].hasOwnProperty(prop)) {
  } else if (collection[id][prop] == "") {
    delete collection[id][prop];
  } else {
    collection[id][prop] = value;
updateRecords(5439, "artist", "ABBA");

Challenge: Record Collection

Link to the challenge:

are the first two lines of code repeated also in your editor?

why do you say that it works in the console but not in the freecodecamp editor? what result do you get in the console?

1 Like

I just finished this one last night.
you delete function wont actually delete the item “I don’t think” check out the delete function in the javascript documentation.

link goes here if the forum will let me put one some day

I don’t think you want to be recalling the update records function this isn’t a recursive solution. additionally your brackets are not in order and you have open functions.

1 Like

@ ieahleen No–this is my first time posting. The box pre-filled with text and I removed most of them. My code starts with function

@ ieahleen I tested the code in Chrome’s console. I called the various updates (copied and pasted from the instructions) and got all the correct results. For example, the instructions say

After updateRecords(5439, "artist", "ABBA") , artist should be "ABBA"

Using my code, when I called updateRecords(5439, "artist", "ABBA") , I verified by console.log(collection[5439]["artist"] and I got "ABBA"