I really need help

i have hard time with this problem. Ive been stuck on it for 3 days and i cant seem to figure out how to start at all… it seems like i get all the other things and this one has to be the hardest one to understand.

Hi there. It will be easier to help if you can post your code and a link to the challenge, rather than a screenshot. Also explaining exactly what’s causing you problems can be helpful too!

If you are really stuck, click on Get Help and then Ask For Help to allow you to create a forum post which includes all of the above.

i posted the whole problem because im so lost to where i even start. On top of that im confused im even supposed to be doing.

Please follow the instructions above, to create a forum post which includes a link to the challenge and your code so far, so that we can help more easily.

what do you mean instructions above? i thought this where you come for help?

These instructions, to create a more useful Ask for Help post.

i did press it but the link isnt working for some reason

Ok, you’ve seen the other thread, but I can understand that Javascript can get confusing at first with a lot of new concepts to get your head around.

I’ll try to explain what this challenge is about.

function updateRecords(records, id, prop, value) {
  return records;
}

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

The starter code for this challenge is a function which, as it stands, just returns whatever value is supplied to the first function parameter when the function is called.

When writing a function, you can create whatever function parameters you like, with whatever names you choose for them. The important thing is what you do with them inside your function. It’s helpful to give your function parameters names which makes sense however.

So you could have a function which adds two numbers together:

function sumTwoNumbers(firstNumber, secondNumber) {
  return firstNumber + secondNumber;
}

sumTwoNumbers(10, 20); // returns 30

You could call those function parameters anything you like (orange and blue, a and b, giraffe and elephant), as long as the logic uses those parameter names inside the function.

So the function for this challenge provides you with usefully-named parameters for you to use inside your function. When the function is called, you will take the user-supplied values to represent the following:

records - an object representing the record collection (in this case recordCollection)
id - the unique 4-digit id representing each object within the collection
prop - any one of the property fields within each record (e.g. albumTitle, artist, tracks)
value - a new value for the supplied prop to be updated

If the user supplies bad values to a function, the function will just not work properly and will either return bad values, throw an error or crash depending on context. If you call the function with a set of ANY valid values however, the function will behave as expected and return a successfully updated recordCollection object.

So, your function will take the recordCollection object, update it and then return it. You do not need to modify the return statement.
What you do need to do is go through each of the following rules in turn and write simple logic for each which will perform the necessary action to update the recordCollection object:

  • If prop isn’t tracks and value isn’t an empty string, update or set that album’s prop to value.
  • If prop is tracks but the album doesn’t have a tracks property, create an empty array and add value to it.
  • If prop is tracks and value isn’t an empty string, add value to the end of the album’s existing tracks array.
  • If value is an empty string, delete the given prop property from the album.

For each rule, you need to write a simple conditional (if) statement which fulfils the specified conditions and then update the corresponding part of the object accordingly.

For instance, if the user wanted to update the albumTitle for Bon Jovi’s ‘Slippery When Wet’ to ‘Greatest Hits’, they would call the function like this:

updateRecords(recordCollection, 2548, 'albumTitle', 'Greatest Hits');

You could access the relevant object property and assign it a new value:

records[id][prop] = value;

This will work because the actual values for the above (e.g. ‘Greatest Hits’) were supplied by the user when the function was called.

I’m not the best teacher but I tried to explain this as clearly as possible… I hope that all makes sense and helps you get your head around how it all works!

Apologies, I had bracket notation until I edited the post and changed it inexplicably to dot notation, forgetting id and prop were variables, not object properties. I’ve changed it back now.

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