Basic JavaScript - Record Collection

Tell us what’s happening:
Unable to find out the mistake I’ve done in this code…

I am not able to pass the below test case

----“After updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me") , tracks should have the string Take a Chance on Me as the last and only element”----

Your code so far

// 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 !== "") {
  } else if (value === "") {
     delete records[id][prop];
  return records;

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Basic JavaScript - Record Collection

Link to the challenge:

1 Like

Your issue is here. What case from the instructions are you trying to handle here?


This is it

  • If prop is tracks but the album doesn’t have a tracks property, create an empty array and add value to it.
1 Like

And look very carefully here. Does your code create an empty array?


can you please tell me
How to create an empty array in that code?

1 Like

How have you created arrays on previous challenges?


like this
let array = ["xyz " , "abc " , 1 , 2 ]

1 Like

Yup. And here you should create an array that only holds value.


How to create it
in this step ----> records[id][prop] = value;

1 Like

You said here that you create arrays by

Maybe you should try something that looks like that?


Like this??
records[id][prop] = [value]

it worked!!


Thanks a lot!!

I’ve tried it earlier also!!
maybe somewhere it went wrong

Thanks you so so much for clearing my doubt :smiling_face_with_tear:


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