How to define a property that could refer to two object keys?

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

How do I get prop, which is not defined in the object, to either pick “artist” or “tracks” keys ?

Please take a look at my code below to see if that’s the problem. The function works fine when the entry is: updateRecords(recordCollection, 2468, "tracks", "Free")

  **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 (prop !== id.tracks && value !== "") {
  prop = value
} else if (prop === id.tracks && id.tracks == undefined) {
  return [id.value]
} else if (prop == tracks && id.value !== "") {
  id.tracks.push('value')
} else if (id.value === "") {
  delete id.prop  
}
return records;
}

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

console.log(updateRecords(recordCollection, 5439, "artist", "ABBA"))

  **Your browser information:**

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

Challenge: Record Collection

Link to the challenge:

Take a look at the lesson Accessing Object Properties With Variables.

1 Like

So id is the second property being passed into your function… Does 5439 have a tracks property? hint: its a primitive number value…

Thank you, I solved this after two days :frowning:

2 Likes

Congratulations on working through the problem! This is tough stuff to learn.

1 Like

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