Challenge - Basic JavaScript: Record Collection

An empty array is a Truthy value.

console.log(Boolean([])); // true

1 Like

@lasjorg and @ILM Thank you so much for the help. This block makes so much more sense! and… what a great tool!

This is my own solution to that challenge. Took me about 20mins.

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

https://gist.github.com/PrechyDev/661c5b4192bcf6100d09f80c7818931f

2 Likes

Generally, posting complete solutions is discouraged, as it fosters copy-paste coding or doesn’t give someone looking for a hint the opt-out. The exception is, if your code is failing, then absolutely post it for review.

Please blur your code (wrap it in spoiler tags).

That said, your code looks good. :stuck_out_tongue_winking_eye:

… and i should have led with Welcome to the forums! Delighted you’re here. and thank you an advance, i can see you’re going to be a valued member of our community. :wink:

1 Like

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.
If you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

This is a pretty old thread, so I’m going to close it.