Record Collection solved but unsolved

Hello campers!
My silly problem here is that the function does all the things that is asked for, but still goes unsolved.

here’s my function:

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

here the test:
console.log(updateRecords(collection, 5439, "tracks", "Take a Chance on Me"))

here the test result:

{ '1245': { artist: 'Robert Palmer', tracks: [] },
  '2468': 
   { albumTitle: '1999',
     artist: 'Prince',
     tracks: [ '1999', 'Little Red Corvette' ] },
  '2548': 
   { albumTitle: 'Slippery When Wet',
     artist: 'Bon Jovi',
     tracks: [ 'Let It Rock', 'You Give Love a Bad Name' ] },
  '5439': { albumTitle: 'ABBA Gold', tracks: 'Take a Chance on Me' } }

but this is the given reult:
After updateRecords(collection, 5439, “tracks”, “Take a Chance on Me”), tracks should have Take a Chance on Me as the last element.

what I’m doing wrong?
since now, GRACIAS!!!

the tracks property should always have value of an array

1 Like

So the line above may new causing you issues.

  1. What do you think .hasOwnProperty(...) does? More specifically, what does it return?
  2. With that information, will that return value ever equal "tracks"?
  3. In the next if, you’re saying “if the property actually already exists…” - is this what the lesson calls for?

This is a case where i strongly suggest writing pseudocode. Write out, in your own words and in painful detail, what the program should do. Break it down to very small, discrete steps. Right now, your code seems to be trying to do too many things at once.

1 Like

Snowmonkey, muchas gracias for the time that you spended on it!
I do not know the answer, yet, but i will apply the things that you said and the pseudocode as well.

Once again, muchas gracias!!!

Hola, again.
Here’s my solution. I know it’s not the best way to do it, but works!
I wanna say again muchas gracias to Snowmonkey and ieahleen for they time and the will to help me.

Go coders unite!

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