Hi Guys would anybody kindly review what I have. I have been struggling with the exercise

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

  **Your code so far**

// Setup
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'
}
};

// Only change code below this line
function updateRecords (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 !== "") {
  records[id][prop].push(value);
}
 else if (value === "") {
  delete records[id][prop];
}

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

  **Your browser information:**

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

Challenge: Record Collection

Link to the challenge:

You forgot to put a } after delete records[id][prop]; }
Then add a “return”…

1 Like

Thou now that I reviewed and corrected, I still do not meet some of the tasks.
Such as: After updateRecords(recordCollection, 1245, "tracks", "Addicted to Love") , tracks should have the string Addicted to Love as the last element.

After updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me") , tracks should have the string Take a Chance on Me as the last element.

After updateRecords(recordCollection, 2468, "tracks", "Free") , tracks should have the string 1999 as the first element.
After updateRecords(recordCollection, 2548, "tracks", "") , tracks should not be set.
Any thoughts (I am reading other sources or checking where can I add or need fixing)…

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.

1 Like

What about the check for "" here?

(really, you can make you code tidier by re-ordering your if clauses)

Also, where is your return statement?

Hi thanks for the feedback.
So to start with it took me a while to get the instructions, anyhow I read the hints and became somewhat clearer.
Thou see my code (it still comes wrong, meaning the tasks previously described are the ones I am missing):

code:

function updateRecords(records, id, prop, value) {

 if (prop !== "tracks" && value !== "") {

   records[id][prop] = value;

   }

   else if (prop === "tracks" && record[id].hasOwnProperty("tracks") === false) {

records[id][prop] = [value];

   }

   else if (prop == "tracks" && value !== "" ) {

records[id][prop].push(value);

   }

else if (value === "") {

delete records[id][prop];

}

 

  return records;

}

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

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like

Formatted for easier reading:

function updateRecords(records, id, prop, value) {
  if (prop !== "tracks" && value !== "") {
    records[id][prop] = value;
  } else if (prop === "tracks" && record[id].hasOwnProperty("tracks") === false) {
    records[id][prop] = [value];
   // You probably meant to use === here!
 } else if (prop == "tracks" && value !== "" ) {
    records[id][prop].push(value);
 } else if (value === "") {
    delete records[id][prop];
  }

  return records;
}

Try running the first failing test case:

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

What do you see?

// Only change code below this line
function updateRecords(records, id, prop, value) {
  if (prop !== "tracks" && value !== "") {
    records[id][prop] = value;
  } else if (prop === "tracks" && record[id].hasOwnProperty("tracks") === false) {
    records[id][prop] = [value];
   // You probably meant to use === here!
 } else if (prop === "tracks" && value !== "" ) {
    records[id][prop].push(value);
 } else if (value === "") {
    delete records[id][prop];
  }
  
  return records;
}

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

To be honest I am not sure what else I am missing. 3 Tasks are completed out of the 7.
If I insert console.log(… an error will be displayed.
Thanks for the feedback still

Did you try adding this line at the bottom of the editor?

yes, although I might have deleted the update. So I will keep trying if anything changed.

When you add that line, you get a really big clue as to the bug - the error message tells you where to look

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