Basic JavaScript: Record Collection - console.log not behaving as expected

Hi everyone,

please don’t tell me what I need to do to solve the challenge - I just need to understand why my console.log expression is failing - let me struggle with the challenge please

I’m working through the basic javascript challenges and I’m trying to debug my code for this challenge.

Any idea why my console.log expression is failing? I think it should be okay since I am accessing the part of the object I want to check — but obviously I’m doing something wrong.

// 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": [ 
        "Little Red Corvette" 
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    "5439": {
      "album": "ABBA Gold"
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {
  //case of deleting property because value=""
  if ("" == value) {
    delete collection[id][prop];
  //case of updating non-array JSON properties
  else if (prop != "tracks" && "" != value) {
  //case of updating/creating JSON properties values that should have array as type
  else if ("tracks"==prop) {
    if (collection.hasOwnProperty(prop)) {
    else {


  return collection;

// Alter values below to test your code
var returned_object=updateRecords(2468, "tracks", "FREE");
var test_output =returned_object[2468][tracks][0];

But, there is no printing to my console below. I’ve tested just


And it works fine.

Aren’t I accessing the returned object’s track values correctly? What am I missing?

Thank you!

I’d suggest checking your actual console (in Developer Options/F12). I’ve found that stuff I’ve tried to output only outputs there if my code has issues

The issue with the console.log printing was on this line:

var test_output =returned_object[2468][tracks][0];

It should read:

var test_output =returned_object[2468]["tracks"][0];

It was seeing tracks as an undefined variable.