This is bug in Test ? (After updateRecords(2548, "tracks", ""), tracks should not be set)?

Hi guys, i have been write some code for the challenge

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/record-collection

This is the code

// Setup
var collection = {
  2548: {
    album: "Slippery When Wet",
    artist: "Bon Jovi",
    tracks: [
      "Let It Rock",
      "You Give Love a Bad Name"
    ]
  },
  2468: {
    album: "1999",
    artist: "Prince",
    tracks: [
      "1999",
      "Little Red Corvette"
    ]
  },
  1245: {
    artist: "Robert Palmer",
    tracks: [ ]
  },
  5439: {
    album: "ABBA Gold"
  }
};

// Only change code below this line
function updateRecords(id, prop, value) {
  
  var myCol = collection[id];

  if(prop == "tracks") {
    if(myCol.hasOwnProperty(prop)) {
      if(value != "") {
        myCol[prop].push(value);
      }else {
        console.log(id);
        console.log(value == "");
        console.log("Prop '" + prop + "' has been deleted");
        console.log("But why the test is wrong ??");
        delete myCol[prop];
      }
    }else {
      myCol[prop] = [];
      myCol[prop].push(value);
    }
  }else {
    if(value != "") {
      myCol[prop] = value;
    }else {
      delete myCol[prop];
    }
  }
  // collection = myCol;

  return collection;
}


console.log(updateRecords(2548, "tracks", ""));

but just the test updateRecords(2548, “tracks”, “”) always error
i have done delete prop tracks but why is not pas ?

this is the image

Definitely something weird is happening. If you remove function call from the bottom, or change it to any other test case everything will pass.

Only if updateRecords(2548, "tracks", "") is at the bottom of your code, relevant test is not passing.

1 Like

Yess i think this is weird too…

Maybe this is bug in the Unit Test ?
I have submit this issue in github

if the object doesn’t have a tracks property but value is an empty string your function add this to the object: tracks: [""]

maybe you need to rethink a bit your checks. You have some repeated code you could condense. like, you have many times if (value != "") {...} else { delete ... }

1 Like

incorrect answer to the question!

you may want to see for more recent topics, also this challenge has changed since this topic was last active