Why bracket annotation and not .dot annotation

Tell us what’s happening:
Describe your issue in detail here.

  **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) {
if(props !== "tracks" && value!== ""){
records.id.prop = value

if (prop !== 'tracks' && value !== "") {
  records[id][prop] = value;
} else if (prop === "tracks" && records[id].hasOwnProperty("tracks") === false) {
  records[id][prop] = [value];
} else if (prop === "tracks" && value !== "") {
} else if (value === "") {
  delete records[id][prop];
return records;

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

Hey gang could someone explain to me why we need to use the square brackets to access the properties. Why is it not records.id.props? Small thing but needs clarification.

  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.123 Safari/537.36

Challenge: Record Collection

Link to the challenge:

Hey There @CodeLooper
If you try to use dot notation with the variable props, the browser will search for a property in the object called "prop"

In bracket notation, you must use “” when mentioning a object property name.
Bracket notation also allows you to use variable like prop in this case
To use a variable to access an object property, you must not use “”
object[prop] //This searches for the value of variable prop

object.prop // This searches for the property "prop" in the object

Hope this helped
Happy Coding

Thanks you very much mate. I googled the question and came to a similar conclusion but you have just put it into perspective in a very clear and concise way. Aha Moment!

Your Welcome !!
I just try to follow the way fcc tries to motivate people

You can learn better by explaining things to others !

I am loving this website. I have done a full stack course from Udemy and this is challenging my knowledge in such a great way. I honestly flew through most of part one but every now and then the way a question is worded just gets me. I run into some new variants of things I have yet to come across such as this question. I have saved this for future reference, thank you again kind stranger.

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