Hi I am failing on tests 3,5,6 and think its because im not adding the value in question 4. If i try to add the value it does seem to make any difference think i missing something simple but not sure where to look next
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'
}
};
function updateRecords(records, id, prop, value) {
if (value === "") {
delete records[id][prop];
} else if (prop !== "tracks" && value !== "") {
records[id][prop] = value;
} else if (prop === "tracks" && value !== "" && records.hasOwnProperty(id, tracks) == false) {
records[id][tracks] = [];
} else if (prop === "tracks" && value != "") {
records[id][tracks].push(value);
} return records;
};
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0
Challenge Information:
Build a Record Collection - Build a Record Collection
a few things here
which object is the one you want to check if it has a specific property?
how many arguments can hasOwnProperty take?
do you have a tracks variable?
function updateRecords(records, id, prop, value) {
if (value == "") {
delete records[id][prop];
} else if (prop != records[id].tracks && value != "") {
records[id][prop] = value;
} else if (prop === records[id].tracks && value != "" && records[id].hasOwnProperty([tracks]) === false) {
records[id][tracks] = [].push(value);
} else if (prop === records[id].tracks && value != "") {
records[id][tracks].push(value);
} return records;
};
I have changed the code concerned with the earlier questions. if i use the tests to console log the function i get the correct answer but it is still failing .
so back here, you said you do not have a variable named tracks, right? but here you are using a variable named tracks, so it is that what you want to do?
also, do you want to check if the property name is an array? can the property name even be an array?
tracks variable again
but also this will not assign an array with value inside, because push returns a number
so records[id][tracks] will have a value of 1
see docs here Array.prototype.push() - JavaScript | MDN
I’m sorry I must be really stupid because I am just getting more confused i thought that what i was doing was asking for the array of tracks within each id object
please ask specific questions about what you have doubts on
first thing to fix is here, the two above have the same issue
prop is one of the parameters of the function, and gets passed the value of a string records[id].tracks is an array or is undefined
so this will always be false for == and will always be true for !=
so this is not how you check if prop is (or is not) tracks
you want to check if prop variable has the value of string "tracks", how do you check if a variable has a certain value?
here you have tracks variable, which we don’t have available, so you are going to get an error here of tracks is not defined
you want to check if the object has the proeprty tracks, string — remember how a string is different from a variable
also, string, not array, remember what make an array an array
here you have the same issue of tracks being a variable that was never defined. You can use bracket notation if you use a string properly, or you use the syntax you used in other places to reach the tracks property inside the object
then, push returns a number
can you write an array with an item inside without using any methods here?
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.