Please don't know what am doing, I need help understanding this

Tell us what’s happening:
please i’ve been going through the basic javascript tutorial and am on topic Record Collection and i was given a task to code:


You are given an object literal representing a part of your musical album collection. Each album has a unique id number as its key and several other properties. Not all albums have complete information.

You start with an updateRecords function that takes an object literal, records , containing the musical album collection, an id , a prop (like artist or tracks ), and a value . Complete the function using the rules below to modify the object passed to the function.

  • Your function must always return the entire record collection 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.

Note: A copy of the recordCollection object is used for the tests.


and below is the code i was given to alter . Please i need assistance. thanks

  **Your code so far**

// Setup
var 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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36

Challenge: Record Collection

Link to the challenge:


This is a screenshot of one of the attempts i’ve made. please am new to coding that’s why its bad:

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.

1 Like

It looks like now you’ve copied the instructions to the challenge into your post.

What part of the instructions are confusing? What have you tried so far?

thanks for your response. I’ve updated my question as Guided.

I’ve tried to analyze the question but to no avail.

this is a screen shot of one of my bad attempts:

Screenshots are almost impossible to debug. Please provide your actual code.

One big problem I’m seeing is that you are incorrectly using dot notation. You cannot use dot notation with a variable holding the name of the property you want.

1 Like
// Setup

var 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) {

  if (prop == records.id.track && value != ""){

    records.id.prop = value;

  }

  if(prop == tracks && id.albumTitle.includes(tracks)==false){

    var empty =[""];

    empty.push(value);

    records.id.push(empty);

  }

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

    records.id.tracks.push(value);

  }

  return records;

}

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

I see bad syntax, so it’s not easy to say how’s your logic

first, you need to review how to access object properties with variables

prop is a variable containing a string, you need to compare it to a string

same as above

includes is an array method, id.albumTitle is not an array

that’s not an empty array

records.id is not an array so you can’t use push to it

2 Likes

yeah omg you’re right, thanks. I’ll re-evaluate it and get back to you if am still messing it up. Thanks again.

//thanks guys i got extra assistance, so the code below works for anyone with similar problem. Setup:

Mod Edit: SOLUTION REDACTED

It is great that you solved the challenge, but 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.

1 Like

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