Am I even on the right track? Record collection

I have been trying the record collection challenge for a while now and even it seems to have given up on me. It refuses to give me any errors for guidance and I don’t see any red squiggly marks to say I typed something wrong. I feel like I have no idea what I’m doing. Am I on the right track at all?? Any advice would be appreciated!

// Setup
var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    },
    "5439": {
      "album": "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {
  let record = collection[id];
  if(prop != "tracks" && "value" != "")
    record[prop] = value;
    break
  }
  if (prop == "tracks" && value != ""){
    if (record["tracks"] === false){
    record[prop].push("tracks");
    record[prop] = value;
    break
  }
  if(value = ""){
    delete record[prop];
    }else{
    collection[id].push(value);
    break  
  
  return collection;
}
  }

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");

You have a few errors in your code which will prevent it from running. Copy it into jsfiddle and it will show you some:
https://jsfiddle.net/

Start adding some console.log in your code to see what is going on with the values.

1 Like

Here are a few pointers in comment inline:

// Only change code below this line
var collectionCopy = JSON.parse(JSON.stringify(collection));

function updateRecords(id, prop, value) {
  let record = collection[id];  
  if(prop != "tracks" && "value" != "")  // use value not "values - value is the variable
// "value" is just a string
    record[prop] = value;
    break // break is best used to stop a loop
// here its best to either return the collect or change these 2 if statements to an if , else statement
  }
  if (prop == "tracks" && value != ""){
    if (record["tracks"] === false){
    record[prop].push("tracks"); // here you are trying to add a string of "tracks" to the array, not the actual value
    record[prop] = value; // here you are trying to set the tracks property to the value, in this case this is a string. the tracks value should be an array
    break  // change to else if
  }
  if(value = ""){ . // this should be == or === not =.     = is for setting values not comparing value
    delete record[prop];
    }else{
    collection[id].push(value); // collection[id] is an object not an array so this will not work
    break  
  
  return collection;
}
  }

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");

I know there’s a lot of comments there but keep at it. Try go through each if statement and use console.log to see what is happening.

check out:

1 Like

hey @mmookow as a relatively new coder I both understand your frustration and admire your persistence. Here’s a few tips that have helped me:

  1. I usually find it easier to work out these challenges in some kind of online ‘sandbox’ environment and use a lot of console.logs to see where my code is hitting a snag. A lot of people like jsfiddle.net, I like jsbin.com because it’s uncluttered and there’s a dedicated console window.
    Ex: I pasted your code into jsbin, did a console.log on the function call and got an ‘illegal break statement’ error.

  1. FCC challenges can (usually) be solved with the stuff we learned in the previous challenges. Go back and review them if you need to.

  2. Step away from the computer and take a break. I’ve often found that a potential solution to a problem I’m working on pops into my head when I’m not staring at the screen.

  3. If you’ve spent a lot time working on a problem you’ve put a lot of effort into it. But these are really just a few lines of code in the end. Sometimes it helps me to re-think my approach by just deleting my work and starting over.

2 Likes

I am up to this now and finally getting errors to work off! Thank y’all very much for your feedback! Comments + some follow up Googling feel like they have cleared up a lot!

// Setup
var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    },
    "5439": {
      "album": "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {
  var record = collection.id;
  if(prop != "tracks" && value !== ""){
    record.prop = value;
    return collection;
  }else if(prop === "tracks" && value !== ""){
    if(record.tracks === false){
    record.push(tracks=[]);
    record.tracks = value;
    return collection;
  }else if(value === ""){
    delete record.prop;
    return collection;
  }else{
    record.push(value);
    return collection;
    }
  }
  }

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");