Record collection: object or collection?

Tell us what’s happening:

in this questions, are ‘collection’ and ‘object’ interchangeable? if not, when must you use one over the other?

Your code so far


// Setup
var collection = {
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(object, id, prop, value) { if (prop != 'tracks' && value != '')
{ object[id][prop] = value;}
else if (prop == 'tracks' && collection[id][])
return object;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36.

Challenge: Record Collection

Link to the challenge:

else if (prop == 'tracks' && collection[id][prop] != 'tracks') {
  var value = []
  object[id][prop].push(value)
}

Also, does anyone know why my code is not creating a new value in my code?

function updateRecords(object, id, prop, value) { if (prop != 'tracks' && value != '')
{ object[id][prop] = value;}
else if (prop == 'tracks' && collection[id][prop] != 'tracks') {
  var value = []
  object[id][prop].push(value)
} else if (prop === 'tracks' && value != '')
{object[id][prop].push(value)}
  else {delete object[id][prop]}

  return object;
}

Here is my updated code if someone can help me see where I’m going wrong. The syntax for this problem has been giving me a lot of trouble

you are still using ‘collection’ instead of object in some part of your code!

they are not interchangeable - object is the function parameter, if you use that one the functiob is reusable

collection is a specific object, if use that the function can work only for the object you have in the editor, and will not change for example the objects that are passed in by the tests


I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

How to add this? @ilenia

how to add what?
do you mean the backticks? you can use the preformatte text like shown in the gif, o type directly the backticks

the message with gif showing how to format text

are you asking how to add images to the forum messages?

you can paste an image in the forum, or if you have already a link, write ![image name](image link)

i just want to add that quoted text in the above message.

I don’t understand what you want to add

Adding this part of your message🙂

I do not understand, have you not done that right now?

yeah never-mind I don’t need it much anyway

do you mean edit someone else post? that is something that only a mod can do

or the line between the two paragraphs? you do that with --- on an empty line

no adding that instruction message which tells how to format the code part

you type it (or paste it) inside the message, you can take the text you quoted before and paste it anywhere, and you have the instructions written in the message you are writing at the moment

I have the text saved, but I just paste it in a post everytime I need to write that

1 Like