Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 17 09:32
    User @bjorno43 unbanned @linkin-park
  • Jun 20 21:19
    @bjorno43 banned @shenerd140
  • Apr 25 17:13
    @mstellaluna banned @cmal
  • Jan 08 22:05
    @mstellaluna banned @dertiuss323
  • Nov 07 2018 04:42
    User @texas2010 unbanned @ows-ali
  • Nov 02 2018 16:25
    @texas2010 banned @ows-ali
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 23:02
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:12
    User @bjorno43 unbanned @androuino
  • Sep 05 2018 07:38
    @bjorno43 banned @androuino
  • Aug 23 2018 16:57
    User @bjorno43 unbanned @rahuldkjain
  • Aug 23 2018 16:23
    @bjorno43 banned @rahuldkjain
  • Jul 29 2018 14:13
    User @bjorno43 unbanned @jkyereh
  • Jul 29 2018 01:00
    @bjorno43 banned @jkyereh
  • Jul 10 2018 22:09
    @bjorno43 banned @manafn
  • Jul 06 2018 15:20
    @texas2010 banned @imlegend19
  • Jul 03 2018 12:28
    @bjorno43 banned @vbvmatta
  • Jun 29 2018 13:54
    @bjorno43 banned @OGTechnoBoy
Tom
@moT01
know of a good place where there's some audio files i can use?
Ken Haduch
@khaduch
@johnnunns - ookay - so in your code, you have this: collection["1245"].tracks.hasOwnProperty(prop) - what is that going to tell you? Is it correct? (I would say that tracks might be there, it might not be there, and if it is there, it needs to be an array, as many of the records are initialized with an array.) But does an array have properties?
@moT01 - I've heard some really strange audio files being played on some of these timers! I don't know the best place to find them - google "free audio files" or something like that.
John Nunns
@johnnunns
Well in the problem, 1245 already has the tracks property, but no value @khaduch
i can see where the other one, 5439, would need to be asked if it has the property in the first place

// 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(collection[1245].tracks.hasOwnProperty(value)){
    return collection;
  }else {
    collection[1245].tracks.push("Addicted to Love");
  }
  if(collection[5439].hasOwnProperty(prop)) {
    return collection;
  }else if(collection[5439])
  }
Tom
@moT01
oh boy
Ken Haduch
@khaduch
@johnnunns - hmmm - it looks like they changed the data ffrom the last time I looked at it. I don't remember that they had one with an empty array. Okay...
John Nunns
@johnnunns
sorry I didn't just repost in the first place @khaduch
Tom
@moT01
@johnnunns hint: there shouldn't be any testing of the actual id numbers
just the variable id
that variable will hold the id that you need to test
John Nunns
@johnnunns
How will it know which ID to go to though?
Tom
@moT01
it just knows
John Nunns
@johnnunns
like if just wrote collection[id]... <- that would apply to multiple ones. So I may add the song to multiple ids
Tom
@moT01
the value of id, will be an ID number
no, that will only be a single id number, ...look at the tests, theres never two id's passed
Ken Haduch
@khaduch
@johnnunns - but regardless of whether it has one or not, you have to look at the general case - if you are going to just add a property to an object, that is simple to do with object.newProperty = "something"; for example. If you want to add something to an array, as with this problem, you have to use .push(), which you know. But again, in the general case, you have to make sure that there is an array there in order to push. So you cannot just do object.someOtherProperty.push("something"); if there isn't a someOtherProperty that doesn't contain an array. For the general case, you want to make sure that there is or isn't a property for the "tracks" case so you can properly create it if necessary, and .push() to it if it exists.
Tom
@moT01
@khaduch thanks for looking at my clock
CamperBot
@camperbot
mot01 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2180 | @khaduch |http://www.freecodecamp.com/khaduch
Ken Haduch
@khaduch
@johnnunns - this seems to be a concept that you aren't clear on - there will be multiple tests run. Each time, one ID value will be passed to indicate which record to work on. the function argument id will contain that value, and you can use it as collection[id], and your code has to be written to just handle the other cases - for example, if value === '' is one of the things that they mention - the specific record that you have the ID for is the one that will be tested. It will work!
@moT01 - you're welcome..
@johnnunns - and, by the way, this problem is a stepping stone from some of the simpler concepts that were presented in the earlier lessons and challenges. It does take things to a new level, and many people have trouble getting this! But once you get it, you'll be able to do greater things in JavaScript... :)
Tom
@moT01

@johnnunns when you call...
updateRecords(5439, "tracks", "");
those values get plugged into your variable...
updateRecords(id, prop, value);

so using collection[id], in this case, will give you access to the collection with the id of 5439
maybe you already got that part, trying to bring more clarity

John Nunns
@johnnunns
sorry had a kitchen crisis :). Ok let me read what you wrote 20 times and try and let it sink in haha @khaduch @moT01
ok, I think i see what you're saying, no need to write the actual specific id, because it will be found through testing. Let me see if I can apply it
Ken Haduch
@khaduch

@johnnunns - one example of one of these tests - the first one:

updateRecords(5439, "artist", "ABBA");

Your function will be called - the function arguments will be:

  • id = 5439
  • prop = "artist"
  • value = "ABBA"

The test says that after the function runs:

artist should be "ABBA"

So the testing code is going to read the collection object that is returned. Before your function runs, that record doesn't have an artist field. But you will add it, and since it is not a tracks property, no need to worry about array-type structures, you can just set that property using the variables and bracket notation - collection[id][prop] = value; That's a hint...
It is equivalent to having the code collection["5439"].artist = "ABBA"; but it is reusable because it is parameterized with the function arguments that will assume the values for the current function invocation.

John Nunns
@johnnunns
ok I hit the wall again. Tell me this. And I'm sorry I'm sure you've already answered but there's a disconnect somewhere for me. So if you have collection[id].hasOwnValue <-the else if statement will apply to multiple ids and then won't I be pushing the same song or artist to multiple ids? It seems if I don't specifically say the id number, I can't stop the push from going to multiple spots.
Zaurbek Zhakupov
@zzhakupov
Hello guys can I have some feedback on my conway's game of life project http://codepen.io/Zooll/pen/XNoRNY
John Nunns
@johnnunns
@khaduch
man coding is a humbling experience for my perceived intelligence :))
Andrew Thompson
@zovaaa
Where's the best place for some help with the wikipedia project? I can't for the life of me work out how to get the correct snippet for the results (i.e., search 't' and check the snippets) codepen: http://codepen.io/zovaaa/pen/eBMMxX
currently using this link: https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=${query.value}&format=json&origin=*
Tom
@moT01
@johnnunns think of whats there, ...if you put if (collection[id].hasOwnProperty('someproperty');
Ken Haduch
@khaduch
@johnnunns - it is .hasOwnProperty(), I think that's what you meant? And the point is that you want to be able to work on multiple records. The thing is, that the function is only called with one value at a time - so for each invocation of the function, you'll probably be using different values, but ONLY ONE AT A TIME! That's the beauty of it! You can, of course, have something that would take action on all of the records in the collection, say, if you wanted to add another field - but you'd have to be getting multiple pieces of data in an array or something - so calm yourself. :) It will work, I promise!
Tom
@moT01
youre asking if the collection with that id has that property
it will only be that one id, because that variable is a single id
@zovaaa is that how you put a variable in a string?
ive always used the " + variable + ".com" style
but maybe your way works
Andrew Thompson
@zovaaa
Yeah, if you use backticks you can make it so `${variable}.com`
= variable + '.com'
Tom
@moT01
yea, figured that
John Nunns
@johnnunns

```
function updateRecords(id, prop, value) {
if(collection[id].tracks.hasOwnProperty(value)){
return collection;
}else {
collection[id].tracks.push("Addicted to Love");
}
if(collection[id].hasOwnProperty(prop)) {
return collection;
}else {
collection[id].push("tracks","artists");
}

}

``` @khaduch @moT01

function updateRecords(id, prop, value) {
  if(collection[id].tracks.hasOwnProperty(value)){
    return collection;
  }else {
    collection[id].tracks.push("Addicted to Love");
  }
  if(collection[id].hasOwnProperty(prop)) {
    return collection;
  }else {
    collection[id].push("tracks","artists");
  }






}
Tom
@moT01
@zovaaa the url gives results
but not the results you want?
@johnnunns if collection['1245'].tracks.hasOwnProperty("artist")
John Nunns
@johnnunns
function updateRecords(id, prop, value) {
  if(collection[id].tracks.hasOwnProperty(value)){
    return collection;
  }else {
    collection[id].tracks.push(value);
  }
  if(collection[id].hasOwnProperty(prop)) {
    return collection;
  }else {
    collection[id].push("tracks","artists");
  }
replaced the specific song with 'value'
Tom
@moT01
how can tracks have the property of artist