Javascript - Record Collection

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/record-collection

I don’t understand why my script doesn’t work?

if (prop == "tracks" && value != "")
collection [id][prop] = value;
else if (prop == "tracks" && value != "")
collection [id].tracks.value(push);```
else if (value = "")
delete collection [id][prop];
else if (prop !== "tracks" && value !== "")
collection [id][prop] = value;
return collection;
}

Is this the full solution you tried? You are missing the function declaration.

Also, your if condition is identical to your first else if condition. The first else if condition will never get evaluated, so its code block will never execute.

if you are trying to use the push method… I suggest you review previous lessons on the topic

Thanks, I am using a function but I forgot to paste it. I will revise my conditions

Hello guys Any help for this one? This is my function but something is wrong and i dont see it.

function updateRecords(id, prop, value) {

if(prop !== "tracks" && value !== "" ){

    collection[id][prop]=value;

}else if(collection[id].hasOwnProperty("tracks") && prop == "tracks"){

 collection[id].tracks=[];

}else if(prop == "tracks" && value !==""){

  collection[id][prop].push(value);

}else if(value == ""){

  delete collection[id][prop];

}

  return collection;

}

Thanks mate,

i really need help to understand whats is wrong. because if i want the solution i just look in the hints. i really thank you for the time.

In rule 2 and 3 I see that you used only if prop === tracks that passes is tracks different from prop? You are telling me to create an array but it will never enter that if if the only condition is that it be the same. and in the final part

it should not be? prop! == “tracks” && value! == “”

I feel like I’m not seeing something.

But the way thanks for the time. iam trying to figure out all your explanation

@miguel.hamouic

In the future, please create your own topic when you have specific questions about your own challenge code. Only respond to another thread when you want to provide help to the original poster of the other thread or have follow up questions concerning other replies given to the original poster.

The easiest way to create a topic for help with your own solution is to click the Ask for Help button located on each challenge. This will automatically import your code in a readable format and pull in the challenge url while still allowing you to ask any question about the challenge or your code.

Thank you.

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.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

@eklavyasharma

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.

Thank you for understanding.

let’s consider what’s going on with your code:
you are checking if the object has the property, and if it has, you are overwriting it with collection[id].tracks = [], instead if the object has already the property you should just add value at the end of the array

if instead the object doesn’t have the tracks property, the second condition is the one that execute: collection[id][prop].push(value)
at this point, collection[id].tracks is undefined, so you get an error because push() works only with already existing arrays and the function stops.

is now clear why you are not getting the desired result?

Thanks Both!. i see the solution now.

@ilenia No Problem! Thank you.

@ilenia Hi, I received a message from FCC that my post was flagged as inappropriate : the community feels it is offensive, abusive, or a violation of our community guidelines.

To inform you, I did not abuse anybody in the post (I never did in my entire life). Neither I was offensive, abusive or violected the community guidelines.

You did not like me posting a working solution and explaining it later thoroughly and I agreed to it. But telling me such things (that I was offensive) when I am clearly not. I do not like it. I kindly ask you please take it back.

This is FAQs of FCC which clearly says …

But I do not want to go into all this. I just want you take the comments back.

Thank you.

Thank you for your concern, it was a misuse on my part on the moderator tools.

We are trying to cut back on the number of readily available solutions, to avoiding spoilers to people that are just trying to get hints from the Read-Search-Ask method, so they aren’t bombarded with clear solutions.

We also ask that you don’t share solutions just for the sake of sharing them, only if you have questions about a specific solution. And do not share solutions to people that ask for help, and instead point out what they did wrong.

If you think it is really important for you to share your solutions you can use the formatting options to hide it from first glance.