Record Collection lesson (JavaScript) broken?

I got through this lesson and could not figure out why it is not correct. Finding that my solution was word-for-word what is shown in solution 1 in the help section, I eventually pasted it in entirely, and it still would not pass the work…

My code:

// Setup
const 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'
  }
};

// Only change code below this line
function updateRecords(records, id, prop, value) {
  if (prop !== "tracks" && value !== "") {
    records[id][prop] = value;
  } else if (prop === "tracks" && value !== "" && records[id].hasOwnProperty["tracks"] === false) {
    records[id][prop] = [value];
  } else if (prop === "tracks" && value != "") {
    records[id][prop].push(value);
  } else if (value == "") {
    delete records[id][prop];
  }

  return records;
}

updateRecords(recordCollection, 5439, 'artist', 'ABBA');

This is “solution 1” from the help area:

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

Additionally - I am having trouble understanding why I am supposed to use records instead of recordCollection for the object name… (admittedly didn’t get that until I looked up the solution)…

One more thing - the “Start a help topic” that pops up doesn’t work either…

Thanks

Recycle your browser and/or close and open a new fCC tab to fix the button issue.

They told you to use records.
The instructions said it:

You start with an updateRecords function that takes an object literal, records ,

And they also gave you the function skeleton so it should have been clear from the description and looking at the startup code that they want you to use the function which takes the four parameters mentioned (that include records).

1st: there is a very important difference in your code and the solution code.

That difference will become apparent when you figure out why your code fails one testcase.

To figure that out, just replace the last line that calls updateRecords with the failing testcase (and wrap it in a console.log statement).

Then look at the console. A syntax error is shown.

If you need another hint: check hasOwnProperty brackets. Which brackets does it and all other js functions use? (2nd hint: it doesn’t use square ones)

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.