Record collection code doesn't check

Tell us what’s happening:
Hi all. I’ve been trying for a solution and I don’t find a logical error (maybe there is). Is it that or some special character I missed? I don’t expect a solution, just a hint at what I may be doing wrongly. Thanks.

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 === [id][prop] }
if (value === "tracks");
tracks[value]; {
 } if  
   (value === '') delete [id][prop],
return object;

updateRecords(collection, 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/85.0.4183.102 Safari/537.36.

Challenge: Record Collection

Link to the challenge:

if (prop != "tracks"); - extra semicolon and missing curly brace

if (value === "tracks"); - extra semicolon and missing curly brace

what is happening on this line and what do theses curly braces do?:

tracks[value]; {
 } if

(value === '') delete [id][prop], - extra comma

1 Like

what should this line do?

and this?

or this?

how do you access object properties? you will need to review that

also difference between assignment and comparison operator

1 Like

@jenovs and @ilenia I’m sorry for my bad syntax.
Thank you for taking the time to answer.
I read the solution but I wanted to try it with code of my own. Problem is there are things I should already know but I’m a slow learner.
I know that.
So forgive me for my bad code. I thought nobody would answer and you did.
The same happened to me with css flexbox but you should see my code now. Because someone cared enough to help me. Like you both are doing now.
I promise I will improve. And thank you again.

@ilenia I changed my code but I still don’t see what’s wrong with the delete [id] [prop] line. Here’s what I have now:

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

Thank you for your time.

really, please, review how to access object properties

[id][prop] is not doing what you think

1 Like

@ilenia I’m sorry. I’ll do that and not bother you no more.

bother again, but if you don’t get how to access an object property, you can’t solve this algorithm

do you have doubts with objects?

1 Like

I’m having too many structural doubts and before I keep on with this challenge I’m going to re-read the curriculum or at least certain points of it, like you said, objects especially. I just thought I was really close to solve this challenge but I’m clearly not. So thank you. I’ll keep on studying and may I go on coding and do something that makes sense. Thank you.

Hi, I think I understand better now. I did the reasoning and took some pieces of code from other places, but mostly I did on my own. I got problems with the .push property it seems. Can you help? Thank you,

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

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

The function accepts object as an argument, so why are you using collection inside your function and then return object at the end of the function.


@RandellDawson thank you, I’ll take care of that.
@RandellDawson still doesn’t check out.
I studied objects last night and I understand the challenges, then come here and feel at a loss.
@ilenia you said I could bother again I think the fail is in the push line. Not sure how to solve it yet.
I got better at the syntax though. At least is something.

You’ve changed the function signature, which isn’t helping:

function updateRecords(id, prop, value) {

Also, you have a few issues

Not quite right bracket notation here.

I think you have a logical problem here. You need both of these actions to occur in some cases, but they never will.

What is this?

I think you have got yourself into a bit of a logic mess, with some syntax issues as well.

I would grab a sheet of paper and ask yourself:

  1. What are the two things that this function must do?

Update or delete property values for entries

  1. What are the special cases?

When updating an entry, the tracks property is an array and may require initalization

From there, I’d (still using pencil and paper) write out your if statements. How does this pesudocode compare to your current code?

1 Like

@JeremyLT Jeremy, it’s the most understanding comment I have received.
Many times I’ve said to myself I shouldn’t go on with this if there are so many concepts I can’t handle.
But something tells me I should follow.
Thank you for your sympathetic (and useful) reply.

congratulations for your progress!

1 Like

:hugs: @ilenia thank you so much, it means a lot!

After spending 5 hours trying to fix this code, do it first on paper as @JeremyLT recommended I’ve finally come to this. I understood the “official” solution, it makes perfect sense, but I’m stubborn and wanted to do it myself because that’s the way you learn. Trying and failing. But I had a ton or errors and finally I only have one which makes me think it must be something very little that’s why I come to you for help. I think the logical errors are solved and hope not to be wrong here.

I posted the code in an image so you see the single error it generated. Then I copy it in code text.

record collection mi solución errada

// Only change code below this line
function updateRecords(object, id, prop, value) {
if (prop !== "tracks" && value !== "") {
  object[id][prop] = value;
if (prop === "tracks" && "tracks" === []) {
  object[id][prop] = [];
  [] = value;
if (prop === "tracks" && value !== "") { 
  (value === "") {
  delete object[id][prop];
  return object;
updateRecords(collection, 5439, 'artist', 'ABBA');

Thank you.

Your bug is the if statement on line 27, I think. tracks can’t be . I’d check if object[id][prop] exists (i.e. if it’s truthy).

Also, line 29 isn’t valid (but you don’t need it).

1 Like

@JeremyLT Thank you Jeremy, I passed the test! I had to set “tracks” as the array and give the value of undefined.
You surely must guess how good I feel now.

do not overwrite the value parameter…

1 Like