Basic JavaScript - Record Collection

Tell us what’s happening:
Describe your issue in detail here.
Hello family,
I tried so hart to understand this question but I field. And checked similar topics from community and copy the answers to give me some idea but its not working out.
can help me.

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 is not tracks and value is not "", leave alone 
  if (prop !== "tracks" && value !== "") {
    records[id][prop] = value; 
  // if not above, if prop is "tracks" and 
  } else if (prop === "tracks" && records[id].hasOwnProperty("tracks") === false) {
    records[id][prop] = [value];
  } else if (prop === "tracks" && value !== "") {
    // if value is empty string, delete the prop from object
  } else if (value === "") {
    delete records[id][prop];   
    return records;

  console.log(records, 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:

“Your function must always return the entire records object.”

This means the return records statement must execute no matter what happens inside the function. Right now it is only executing if the last else if statement is triggered.

1 Like

Hi, thank you so your time quick response.
You said, “it is only executing if the last else if statement is triggered” but how can i do so.?

else if (value === "") {
    delete records[id][prop];   
    return records;

The only return statement in the function is inside that block of code. So you will only return records when value equals an empty string. But you want to return records no matter what you do in the function. So you need to move the return statement somewhere where it will always be executed.

1 Like

YES YES YES! it has worked.
Thank you so much :clap: :clap: :clap: :clap:

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