Stuck on "Record Collection"

So I’ve been stuck on record collection for at least a week now. Went back through the javascript object lessons again. Looked at answers on the FCC forum. It’s still not clicking for me.

Is anyone able to help me out here? I took a few days off to see if it would help but I think it made me more confused, lmao. This is my third iteration of code, and I’m not passing any of thetests. Here’s what I have so far:

My code so far


// Setup
var collection = {
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(object, id, prop, value) {
if (prop !== 'tracks' && value !== ''){
  object[id][prop] = value;
} else if (prop == 'tracks'){
  if (object[id].hasOwnProperty('tracks') == false){
    object[id][prop] == [value];
  } else if (prop == 'tracks' && value !== ''){
    tracks.push(value);
  }
} else if (value == ''){
  delete object[id][prop];
}

return object;
}

updateRecords(collection, 5439, 'artist', 'ABBA');
console.log(artist);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.67 Safari/537.36.

Challenge: Record Collection

Link to the challenge:

what’s tracks in the second line of this snippet?

didn’t you get any error in the console?

and what’s artist here?

Should that be nested in the previous if statement? I thought tracks was a property.

Should this not push the variable value into the tracks array?

When I remove this part of the code I pass the following tests:

After updateRecords(collection, 5439, "artist", "ABBA") , artist should be ABBA

After updateRecords(collection, 2548, "artist", "") , artist should not be set

don’t you get any error in the console? like a TypeError or ReferenceError?

you could need to open the browser console before running the tests, or try to call the function with the arguments of the not passing tests

No, when I run the tests I get the following:

// running tests After

updateRecords(collection, 5439, "tracks", "Take a Chance on Me")

,

tracks

should have

Take a Chance on Me

as the last element. After

updateRecords(collection, 1245, "tracks", "Addicted to Love")

,

tracks

should have

Addicted to Love

as the last element. After

updateRecords(collection, 2468, "tracks", "Free")

,

tracks

should have

1999

as the first element. After

updateRecords(collection, 2548, "tracks", "")

,

tracks

should not be set // tests completed

copy this and put it below your code

ok, I wasn’t noticing a thing - I really suggest you format your code, you have some issues with the graph parenthesis

after that, the issues I was trying to point above will surface

I am now getting “ReferenceError: tracks is not defined” with “updateRecords(collection, 1245, “tracks”, “Addicted to Love”)”.

it says also exactly where - do you understand why?

Ok, update: I’m now passing every test except “After updateRecords(collection, 5439, "tracks", "Take a Chance on Me") , tracks should have Take a Chance on Me as the last element.” with the following code:

function updateRecords(object, id, prop, value) {
if (prop === 'tracks' && object[id][prop] === false){
  object[id][prop] = [value];
} else if (prop != 'tracks' && value != ''){
  object[id][prop] = value;
} else if (value ===''){
  delete object[id][prop];
} else if(prop === 'tracks'){
  object[id][prop].push(value);
} 

  return object;
}

I am getting “TypeError: Cannot read property ‘push’ of undefined” and I’m not sure what I did wrong. Does this tell me that object[id][prop] is not an array in this instance?

Are you handling the case where the tracks property is empty?

Isn’t that handled with:

if (prop === 'tracks' && object[id][prop] === false){
  object[id][prop] = [value]

Is it? That checks if the left hand side is defined and strictly equal to false?

Sorry, you’re right. But yes, this case:

updateRecords(collection, 2548, "tracks", ""), tracks should not be set

passes. Or am I misunderstanding & you’re asking something else?

That test checks that you can un-set the tracks. But once you have un-set it, there is no array to push onto, which is why you are getting that error about undefined not having the push method.

You’ve got the right idea with the first if clause, the === false just isn’t doing what you need/expect it to.

Major facepalm! Changed false to undefined & it’s working.

Unfortunately I’m still not sure I fully understand the challenge, since I did a considerable amount of guessing. Appreciate your help though!

‘A considerable amount of guessing’ until it works is a fair part of my strategy. Planning is key to coding, but fiddling around until you get something that works is super important.

Feel free to ask if there are parts we can clarify.

1 Like

can someone help me with this ?
:neutral_face:import * as uppercaseString and lowercaseString from ‘./string_functions.js’;
// add code above this line

uppercaseString(“hello”);
lowercaseString(“WORLD!”);