Not sure what I'm doing wrong here with "Record Collections" challenge

Tell us what’s happening:

I tested the same code by moving it all into an empty HTML page and looking at the results in chrome developer tools. I don’t think anything I typed here was wrong. The tests are disagreeing with me.

Can anyone see if anything is wrong with my code?

  **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(value.length === 0){
  delete records[id][prop];
  return records;
}

if(prop !== "tracks" && value.length > 0){
  records[id][prop] = value;
} else if(prop === "tracks"){

  album = records[id];

  if(album.hasOwnProperty(prop)){

    if(value.length > 0){
      album[prop].push(value);
    }

  } else {
    album[prop] = [value];
  }
}

return records;
}

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/91.0.4472.114 Safari/537.36

Challenge: Record Collection

Link to the challenge:

You are referencing a variable without declaring it. This creates a variable in the global scope. Creating a global variable this way considered to be a bad practice and if you have your JavaScript in strict mode it won’t allow you to use undeclared variables. freeCodeCamp code is executed in strict mode, so when you are using another environment to run your JavaScript, you always want 'use strict' at the top of the file.

Thank you! Didn’t realize that I forgot to declare it.

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