Basic JavaScript - Record Collection

Tell us what’s happening:
Hello; I have many issues here…
1-. if we are recieving an Object like the obj given with the name recordCollection, wich is clear that is incomplete, first I have to assume that for example this id and their properties are the full content of any album object ( thinking as a recordCollection as a father)

like this

2548: {
albumTitle: ‘Slippery When Wet’,
artist: ‘Bon Jovi’,
tracks: [‘Let It Rock’, ‘You Give Love a Bad Name’]
},
the above extract is the full sub object
this sub object has id = 2548
And the properties are:
albumTitle: (string)
artist:(string)
tracks: ( an array)

id and 3 properties

So, under my point if view I have to verify if the object recordCollection contains as follow: first the id and so on;if the id it is NOT found, I have to add it( I guess, because this is updating function at least starting adding the id number)
second if the ID is found, then I have to check any properties like the ones mention before, because the instrction says that some times not all the properties are filled…

And the properties are:
albumTitle: (string)
artist:(string)
tracks: ( an array)

knowing that this 3 elements are the full properties I started checking the existance of this properties using
Object.hasOwnProperty(prop1);
Object.hasOwnProperty(prop2);
Object.hasOwnProperty(prop3);

respectively if one or more are not found I have to work on it, and create it, adding the element to the principal object as a propertie.
and finally show te record wich is already done

with
return records

the solution that I saw at least the number one ( does not have all this thinking and focus only in the array tracks so this asuume that he user always will put the right id, wich is not necessary

finally it looks i´m over thinking and I do not know if that is correct or I have to be more simple and not to do nothing about something I’m not been told

updateRecords(recordCollection, 5439, ‘artist’, ‘ABBA’);

Your code so far

// Setup
const recordCollection = {
  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(records, id, prop, value) {
  return records;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0

Challenge: Basic JavaScript - Record Collection

Link to the challenge:

It doesn’t look like you’ve made any changes to the original code. Please try your best to solve the lesson and if it doesn’t work then please paste your broken code in here so we can see what you did. If you truly need a question answered before you can even start then please ask a specific question that we can answer.

To display your code in here you need to wrap it in triple back ticks. On a line by itself type three back ticks. Then on the first line below the three back ticks paste in your code. Then below your code on a new line type three more back ticks. The back tick on my keyboard is in the upper left just above the Tab key and below the Esc key. You may also be able to use Ctrl+e to automatically give you the triple back ticks while you are typing in the this editor and the cursor is on a line by itself. Alternatively, with the cursor on a line by itself, you can use the </> button above the editor to add the triple back ticks.

here I´m still can not figure out how to keep going :frowning:

const recordCollection = {
  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(records, id, prop, value) {
//I have to assume that users input are correct in obj name and id
// but I think I have to check all the properties like:  albumTitle, artist and Track
//************************************** */
//If prop isn't tracks and value isn't an empty string, I put the value from the parameter in the input funnction wich is value)
if(prop !== "tracks" && value!== " "){
  records.[id].[props]=value;
//If prop isn't tracks but I have to create it because its not empty, and the propertie its created was not there before (checked with hasOwnproperty())
}else if(prop !== "tracks" && value!== " " && records[id].hasOwnProperty("tracks") ==false){
records.[id].[props]=value;
//If prop is "traks" we change the value for the new one ( wich is not an empty space)(push(value) add the value and create the array))
}else if(prop==="tracks" && value!== "") {
records.[id].[props].push(value)
//need to create a possible  "artist" 
}elseif(prop !== "tracks" && "AlbumTitle"!== " "){

}else{

}

  return records;
}

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

This needs a space.

You don’t want to use both dot and bracket notation here. It’s either one or the other. I would stick with brackets.

Also, are you sure its props? Look at the parameter names for the function:

function updateRecords(records, id, prop, value) {

There is a prop, but not a props.

A space is not considered to be an empty string since a space is a legitimate character that can be in a string. An empty string literally has nothing in it.

I’ve given you a lot to clean up. There are still more problems, but you need to fix the above first to give yourself a chance.

There are four bullets in the instructions that all start with if. You used the if/else if pattern for them, which is perfect. Make sure that each one is testing for exactly what each of the bullet points is asking. Some of them are correct, but some of them you are not.

And you don’t need the last else block. Having an else at the end is not required. Since there is no default action to take if none of the bullets points are matched then there is no reason to have an else at the end.

Also, I’m tempted to say that you should get rid of your comments. They are much longer than the actual code and I think they might be causing your code to look more confusing than it should be. If you really need them then of course leave them in. But the first thing I did when testing your code was to remove them because they were too distracting.

Give it another try and paste your updated code in here if you still need help.

ok here we go again…thx for the advice…@bbsmooth
:facepunch:

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