Challenge Record Collection has an issue.
User Agent is: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
.
Please describe how to reproduce this issue, and include links to screenshots if possible.
Instructions in description text:
For the given id in collection:
If prop does not contain the key "tracks", then update or set the value for that incomplete prop.
If prop does not contain the key "tracks" before you update it, create an empty array before pushing a track to it.
If prop does contain the key "tracks" and its value is non-blank, then push the value onto the end of its existing tracks array.
If value is blank, delete that prop.
Its just a sugesstion because your instructions (specially 3rd line) are confusing a lot of people .
So I think you should change it .
Your third line should be something like If the concerned object does not contain the key "tracks" ,then update it by creating an empty array before pushing a track to it.
because you only want to update when prop contains the value key but the concerned object doesn't have the tracks property.
I agree, I have some real concerns about the verbiage used in the checkpoint:
Record Collection - https://www.freecodecamp.com/challenges/record-collection
// Each album is identified by a unique id number (its key)
// and has several properties. Not all albums have complete information.
console.log(Object.keys(collection));
console.log(Object.keys(collection["2548"]));
console.log(Object.keys(collection["2468"]));
console.log(Object.keys(collection["1245"]));
console.log(Object.keys(collection["5439"]));
// Write a function which takes an id, a property (prop), and a value.
// - Great done.
function updateRecords(id, prop, value) {
// For the given id in collection:
for (id in collection) {
// If prop does not contain the key "tracks",
// then update or set the value for that incomplete prop.
//? Are we talking about the parameter 'prop' that is passed
//? into the function? Or are we talking about the Object[id] keys?
// If prop does not contain the key "tracks"
// before you update it,
// create an empty array before pushing a track to it.
//? Same question.
// If prop does contain the key "tracks"
// and its value is non-blank,
// then push the value onto the end of its existing tracks array.
//: Based on those instuctions, I would write something like this. (Which isn't correct.)
if (prop === Object.keys(collection[id][prop]) && collection[id][prop] === "") {
collection[id][prop].push(value);
}
// If value is blank,
// delete that prop.
if (value === "") {
delete collection[id][prop];
}
}
// Always return the entire collection object.
return collection;
}
I mean if you look this over the verbiage doesn't make sense. It may just be semantics but, for someone learning JavaScript. I'm really confused by the new instructions.
The old instructions made more sense: https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/Challenge-Record-Collection
// Write a function which takes:
// an id, a property (prop), and a value.
function updateRecords(id, prop, value) {
// If value is non-blank (value !== "")
// and prop is not "tracks"
// then update or set the value for the prop.
// Your code here
// If the prop is "tracks" and value is non-blank,
// push the value onto the end of the tracks array.
// Your code here
// If value is blank,
// delete that prop.
// Your code here
// Always return the entire collection object.
return collection;
}
If you look on my profile: https://www.freecodecamp.com/revisualize
You can see two different ways that I solved "Record Collection" before the verbiage in the instructions was changed.
// Only change code below this line
function updateRecords(id, prop, value) {
// If value is non-blank (value !== "") and
// prop is not "tracks"
// then update or set the value for the prop.
if (value !== "" && prop !== "tracks") {
collection[id][prop] = value;
}
// If the prop is "tracks" and value is non-blank,
// push the value onto the end of the tracks array.
else if (prop === "tracks" && value !== "") {
if (!collection[id].hasOwnProperty(prop)) {
collection[id][prop] = [];
}
collection[id][prop].push(value);
}
// If value is blank,
// delete that prop.
else if (value === "") {
delete collection[id][prop];
}
// Always return the entire collection object.
return collection;
}
// Alter values below to test your code
updateRecords(1245, "tracks", "Addicted to Love");
/*
The fucntion could also be written like this:
function updateRecords(id, prop, value) {
if (value !== '') {
if (prop === 'tracks') {
if (!collection[id].hasOwnProperty(prop)) {
collection[id][prop] = [];
}
collection[id][prop].push(value);
} else {
collection[id][prop] = value;
}
} else {
delete collection[id][prop];
}
return collection;
}
*/
I think this could work better than the current instructions
For the given id in collection:
If prop isn't "tracks" and value isn't blank, update or set the value for that record property.
If prop is "tracks", value isn't blank and the record hasn't that property, before you try updating it, set said property using an empty array and then push the new track to it.
If prop is "tracks", value isn't blank and the record already has that property, push the value onto the end of its existing tracks array.
If value is blank, delete that record property.
There is an ongoing discussion related to this in #9291, however that thread has divulged into a completely different topic, hence I am not marking this as duplicate.
This makes more sense to fix this challenge.
@erictleung Can you please guide on the proper text, as you are most aware on the ongoing issue?
Thanks all for the feedback. I like @Chrono79's suggestion but here's a few tweaks to it:
For the given
id
incollection
:If
prop
isn't"tracks"
andvalue
isn't blank, update or set the value for that record property.If
prop
is"tracks"
but theid
doesn't have a"tracks"
property, create an empty array before adding the newvalue
.If
prop
is"tracks"
andvalue
isn't blank, push thevalue
onto the end of its existingtracks
array.If
value
is blank, delete thatprop
.Always return the entire collection object.
@raisedadead Thanks for not closing this issue in favour of the other one .I actually saw that one before posting (didn't read completely) but didn't wanted to comment there (cause of obvious reasons).
@erictleung Seems good to me .
@erictleung, nice :smiley:
To First Timer:
Checkout the comment from @erictleung https://github.com/FreeCodeCamp/FreeCodeCamp/issues/9380#issuecomment-228628386 with details on what to change. You will need to change these lines. Please, check our Guidelines for Contributing and if you need any assistance reach out to the Contributors Chat room.
Note: You can only submit a pull request for this issue if you are new and haven't submitted one before. Hence the issue label
first-timers-only
:stuck_out_tongue_winking_eye:
https://github.com/FreeCodeCamp/FreeCodeCamp/issues/9380#issuecomment-228628386 is an improvement but still not clear enough for a newbie.
While parsing ambiguous requirements is a valuable skill, this challenge is still very early and should be just about coding.
The function updates the pre-existing object representing a musical records collection, but there is confusion between function parameters and object's properties. It may make sense to also rename "prop" to "property" to disambiguate.
The description contains special cases but does not mention the main objective clearly, which is to update each album's object even when given incomplete data.
There is an overload between using the term "record" to refer to a data structure record and using it to refer to a musical record. I propose to resolve that ambiguity by using "album" in place of "record", which is what the original instructions implied. This could be helpful to international students who may be less exposed to the pop-culture use of "record" to refer to music. The incorrect use of "its" in describing special cases contributes to creating ambiguity.
You start with a JSON object representing (a small part of) your record _musical album_ collection. Each album has several properties and a unique id number as its key. Not all albums have complete information.
Write a function which takes an _album's_ id _like "2548"_, a property _like "artist" or "tracks"_ (prop), and a value _like "Addicted to Love" to modify the data in this collection._
_Your function must always_ return the entire collection object.
_There are several rules for handling incomplete data:_
For the given id in collection: //this incorrectly strongly implies a "for" or "for in" loop and needs to be deleted.
We really should solidify something and get this verbiage changed pretty quickly. The Gitter Chat is seeing a LOT more assistance requests for this challenge.
@wiseleo thanks for the feedback. I like your changes and rationale for each change. The instructions should be changed to:
You are given a JSON object representing a part of your musical album collection. Each album has several properties and a unique id number as its key. Not all albums have complete information.
Write a function which takes an album's
id
(like2548
), a propertyprop
(like"artist"
or"tracks"
), and avalue
(like"Addicted to Love"
) to modify the data in this collection.If
prop
isn't"tracks"
andvalue
isn't blank, update or set the value for that record album's property.Your function must always return the entire collection object.
There are several rules for handling incomplete data:
If
prop
is"tracks"
but the album doesn't have a"tracks"
property, create an empty array before adding the new value to the album's corresponding property.If
prop
is"tracks"
andvalue
isn't blank, push thevalue
onto the end of the album's existingtracks
array.If
value
is blank, delete that property from the album.
Please first read the contributing guidelines before taking care of this issue. And feel free to visit the Contributors Help chat room if you have any questions about helping. We're there to help.
These last instructions seem clear enough to me, could anyone do a submit asap?
Can I make these changes? Looking to make my first contribution.
@SMaxOwok sure :wink:
yeh this solution perfectly works
// 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) {
if(prop !== "tracks" && value !== ""){
collection[id][prop] = value;
}
//if prop is track and album doesn't have track
else if( prop === "tracks" && !collection[id].hasOwnProperty("tracks")){
collection[id]["tracks"] = [value];
}
else if(prop === "tracks" && value !== ""){
collection[id][prop].push(value);
}
else if( value === ""){
delete collection[id][prop];
}
return collection;
}
// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
Most helpful comment
I agree, I have some real concerns about the verbiage used in the checkpoint:
Record Collection - https://www.freecodecamp.com/challenges/record-collection
I mean if you look this over the verbiage doesn't make sense. It may just be semantics but, for someone learning JavaScript. I'm really confused by the new instructions.
The old instructions made more sense: https://github.com/FreeCodeCamp/FreeCodeCamp/wiki/Challenge-Record-Collection
If you look on my profile: https://www.freecodecamp.com/revisualize
You can see two different ways that I solved "Record Collection" before the verbiage in the instructions was changed.