Build a Record Collection - Build a Record Collection

Tell us what’s happening:

hello everyone, test 2,5,6 and 8 fail to pass although the log are corrects. I need your’s help to completed this lab

Your code so far

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'
  }
};

const updateRecords = (records, id, prop, value) => {

  if(value === ""){
    console.log(delete records[id][prop]);

  } if ((prop !== "tracks")&& (value !== "")){
      console.log(records[id][prop] = value);

//If prop is tracks and value isn't an empty string, add value to the end of the album's existing tracks array.
}if (((prop === "tracks")&& (value !== "")) &&(records[id].hasOwnProperty("tracks") === true)){
 records[id][prop].push(value); 
  console.log(records[id][prop])
  
//If prop is tracks and value isn't an empty string, but the album doesn't have a tracks property, create an empty array and add value to it.
} else if (((prop === "tracks")&& (value !== "")) &&(records[id].hasOwnProperty("tracks") !== true)){
   records[id][prop]=[value] 
  console.log(records[id][prop] ); 
}
}

updateRecords(recordCollection, 1245, "tracks", "Addicted to Love")

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36

Challenge Information:

Build a Record Collection - Build a Record Collection

The first User Story:

Your function must always return the entire records object.

Does your function have a return statement?

okay, so i modified all the console.log inside the function to return statement, but test output the same result

Does your function return the entire records object?

You need to return what the Lab asks you to return. Don’t just change console log statements to return statements.

what i can do more than this?

return records[id][prop]

its the entire entire object i suppose

No, that is not the entire records object. The entire records object is records.

i will test that, but why certain if statement successful pass the test but some other not?

Some tests may pass for a variety of reasons but you need to ensure that you follow all of the required User Stories exactly, if you want to pass all of the tests. Your function only needs one return statement, detailed in the first User Story.

The overall principle of this exercise is for you to take an object as input, modify it, and then return the object.

1 Like

thank you for your advice and explain, this was exactly the correct solution.

1 Like