Basic JavaScript - Record Collection

Tell us what’s happening:
Who can help me to solve this question?

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(records[id][prop] == ""){
    delete records[id];
  }
  if(records[id] != "tracks" && records[id][prop] != ""){
    return records[id][prop] = records[id];
  }
  if(records[id] == "tracks" && records[id][prop] != ""){
    records[id].tracks=[""];
    return records[id][prop].tracks;
  }
  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/112.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Record Collection

Link to the challenge:

With what exactly do you have problem? What do you thing is the issue, what have you tried so far?

[quote=“Michael_84, post:1, topic:605789”]

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

this is what I have tried but it is not work?
function updateRecords(records, id, prop, value) {
if(records[id][prop] == “”){
delete records[id];
}
if(records[id] != “tracks” && records[id][prop] != “”){
return records[id][prop] = records[id];
}
if(records[id] == “tracks” && records[id][prop] != “”){
records[id].tracks=[“”];
return records[id][prop].tracks;
}
return records;
}

Could you explain what issue you are having?

according to what i was writing does not work? i want you to help me? if cause by my mistake you can handle it for the sake of improving the knowledge.

You seem to have misunderstood what the function should be checking and you are not using the value parameter.

if (records[id][prop] == "") {
  delete records[id];
}

records[id][prop] is never an empty string and records[id] is the nested object and not a property on the nested object.

Example:

delete users[userId][userName]

If value is an empty string, delete the given prop property from the album.


if (records[id] != "tracks" && records[id][prop] != "") {
  return records[id][prop] = records[id];
}

records[id] is never the string “tracks”.

You are assigning the records[id] to one of its properties which is not part of any of the requirements.


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

What is it you believe this code is doing?


I might suggest you go back a few challenges and make sure you understand objects and how to work with them.

When you come back to this challenge read the requirements carefully and make sure you understand the data you are working with.

How the object(s) are structured and what the function parameters are. Look at the tests in the bottom left to see the different values the function is supplied with.

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