Record Collection: I do not know what is the reason why it does not work to solve the problem. It is Record Collection Problem

Record Collection: I do not know what is the reason why it does not work to solve the problem. It is Record Collection Problem
0
function updateRecords(id, prop, value) {
        if(prop !==tracks && prop!==""  ){
          return value;
}else if (prop=="tracks" && prop==0){
a=[];
prop.push(a);
        }else if(prop=="tracks" && "tracks"!=""){
tracks.push(value);

        }else if(value===""){
          delete prop;
        }

  return collection;
        
}

this are glaring logic and syntax errors
anything else, you will need to provide the challenge link.

you don’t have a variable called tracks anywhere

prop can’t have two different values at the same time. This will always be false

you have never defined the variable a

prop is a string. Strings don’t have a push method.

this is always true, you are comparing two string that are obviously different from each other.

you don’t have a variable tracks in your code, you can’t push to undefined

ask again if you need clarifications

1 Like

I do not understand the reason why my functions does not work. I write conditions from the last one to the first one


function updateRecords(id, prop, value) {
var a=["collection"]["id"]["prop"]["value"];
var b= ["collection"]["id"]["prop"]["tracks"];
var c=  ["collection"]["id"]["prop"]     ;
       if (a==""){
         delete prop;
       }else if(b!=="")
       tracks.push(value);
       
  return collection;
}

Can you send a link to the challenge? It looks like you’re trying to access the properties of an object? If the Object named collection? If so, you need to remove the brackets and the quotes from around collection. Also, if you’re trying to access the variables id, prop, and value you need to remove the quotes from them as well, otherwise you’re passing the literal strings "id", "prop", and "value".

2 Likes

ich bin ihnen dafĂĽr dankbar

1 Like

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/record-collection

santiagodeleondecar1

TaraBryn

9m

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/record-collection

if you get stuck trying to fix the various things, post your whole code, everything that’s in the editor, and explain what’s going wrong and we will dk our best to
help!

It does not still work :(. What suggestion can you give me, please?

// 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"
  }
};

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

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

first big issue - you are overwriting the function parameter value

you do not have a variable called tracks. Plus, the actual operator you want to use is != (you used = which is an assignment operator, followed by the NOT operator, !)

same issue as above about operator,'plus you have overwritten value so you can’t do that comparison anymore to check what’s the input value

value will never be 0

value is not an array anymore if you fix the first issue, but a string, strings to not have a push method

push always needs an argument to work

value will never be 0, so you never delete from the collection object

you need to delete the object property, how do you access the object property?

1 Like