Build a Record Collection - Build a Record Collection

Tell us what’s happening:

Hello! I need a help. Where is heere issue? The point four wrote me still issue. I do not why? Thaks for your answer.

Your code so far

const 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'
  }
};

// Funkcia na aktualizáciu záznamov
function updateRecords(records, id, prop, value) {
  // Ak sa hodnota prop rovná 'tracks' a nie je prázdna, pridať nový track
  if (prop === "tracks" && value !== "") {
    if (!records[id].tracks) {
      records[id].tracks = []; // Inicializácia poľa, ak neexistuje
    }
    records[id].tracks.push(value);
  } else if (prop === "artist" && value !== "") {
    // Ak je prop 'artist' a hodnota nie je prázdna, priradiť nového umelca
    records[id].artist = value;
  } else if (prop === "tracks" && value === "") {
    // Ak je prop 'tracks' a hodnota prázdna, odstrániť všetky tracky
    delete records[id].tracks; 
  }

  if (prop === "albumTitle" && value !== "") {
    records[id].albumTitle = value; // Priradenie hodnoty albumTitle
  }

  return records;
}

// Testovanie funkcie
updateRecords(recordCollection, 5439, "artist", "ABBA");
console.log(recordCollection[5439].artist); // "ABBA"

updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me");
console.log(recordCollection[5439].tracks); // ["Take a Chance on Me"]

updateRecords(recordCollection, 2548, "artist", "");
console.log(recordCollection[2548].artist[0]); // (nevykoná sa žiadna akcia)

updateRecords(recordCollection, 1245, "tracks", "Addicted to Love");
console.log(recordCollection[1245].tracks); // ["Addicted to Love"]

updateRecords(recordCollection, 2468, "tracks", "Free");
console.log(recordCollection[2468].tracks[0]); // "Free"

updateRecords(recordCollection, 2548, "tracks", "");
console.log(recordCollection[2548].tracks); // undefined (tracky sú odstranene)

updateRecords(recordCollection, 1245, "albumTitle", "Riptide");
console.log(recordCollection[1245].albumTitle); // "Riptide"

Your browser information:

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

Challenge Information:

Build a Record Collection - Build a Record Collection

Which is point 4?

You shouldn’t have special cases for each property, only tracks

This is point 4: 4. After updateRecords(recordCollection, 2548, "artist", ""), artist should not be set

which if statement would be run for that function call?

updateRecords(recordCollection, 2548, “artist”, “”);
console.log(recordCollection[2548].artist[0]);

that is not an if statement, I am asking you which of the if statements in the function is the one that works for this situation

Sorry !!!
else if (prop === “artist” && value !== “”) {

// Ak je prop 'artist' a hodnota nie je prázdna, priradiť nového umelca

records\[id\].artist = value;

are you sure? it does not look like the condition is going to be true

Note - you really, really only should have special logic for ‘tracks’ and all other properties should be handled the exact same way

I can not move. Please help. I do not know where is issue.

Note - you really, really only should have special logic for ‘tracks’ and all other properties should be handled the exact same way

That is the core of your problem

if you have not found the if statement that executes for the case, maybe it’s missing, don’t you think?