These are chat archives for FreeCodeCamp/HelpJavaScript

10th
Aug 2018
Brad
@bradtaniguchi
Aug 10 2018 00:00
I'll be checking it out after I integrate some new security improvement's, then onto logging, that integration, then I'm going to push for some CI pipeline to test out all those integrations. Should work out well
let sampleWord = "astronaut";
let pwRegex = /(?=\w{5,})(?=\d{2,})/; // Change this line
let result = pwRegex.test(sampleWord);
Why its is not passing?
Blauelf
@Blauelf
Aug 10 2018 05:21
@ThePrakashKumar The two look-aheads would start at the same place, meaning your digits may not be placed at the end (unless there are at least 5 of them). Maybe you could add a .* in front of the \d.
Yashwardhan Pauranik
@yashwp
Aug 10 2018 05:59
I want to know how can I achieve to generate this automatic preview of the link I have just pasted in compose post block of FB in Angular. Or what it is called. Is there some library for angular which do this same functionality?
Dan Couper
@DanCouper
Aug 10 2018 07:27
Basically, there's an even listener on the text box that looks at what a user is typing. When someone types a link, there's an AJAX request made for the page HTML, and it parses the title, description, and the first image. In the case of Facebook, a website owner can actually put the information needed in special tags in the head section of the page html, and FB looks for that first. It's pretty easy to do (although making it performant is harder), there should be a standalone plugin, plus most text editing plugins have that functionality, again normally via plugin
Mohammed Boudad
@matrixersp
Aug 10 2018 09:23
Hey guys,
What's the purpose of having a function within another function here?
const increment = (function() {
  "use strict";
  return function increment(number, value = 1) {
    return number + value;
  };
})();
console.log(increment(5, 2)); // returns 7
console.log(increment(5)); // returns NaN
Blauelf
@Blauelf
Aug 10 2018 09:40

@matrixersp That's an IIFE (immediately invoked function expression, pronounced like "iffy"). Usually, you would do that to create a scope for variables shared between calls, but not with the surroundings. Like

var addUp = (function() {
    var sum = 0; // not visible from the outside
    return function addUp(increment) {
        sum += increment; // can access the variable
        return sum;
    };
}());
console.log(addUp(23)); // 23
console.log(addUp(19)); // 42

Block-scoped variables with let and const have greatly reduced the need for those IIFEs. I'm not sure what the one in your example is for.

Long Nguyen
@longnt80
Aug 10 2018 09:44
anyone know what this is: +function?
+function ($) {
  'use strict';
  var version = $.fn.jquery.split(' ')[0].split('.')
  if ((version[0] < 2 && version[1] < 9) || (version[0] == 1 && version[1] == 9 && version[2] < 1) || (version[0] > 3)) {
    throw new Error('Bootstrap\'s JavaScript requires jQuery version 1.9.1 or higher, but lower than version 4')
  }
}(jQuery);
Blauelf
@Blauelf
Aug 10 2018 09:47
@longnt80 That's unary +, turning the thing to the right into a number. It's used to enforce interpreting the word function as the start of a function expression, not a function declaration. ! is another operator often used for that purpose. The "correct" way would be to surround the expression in parentheses, but that's one extra character.
Long Nguyen
@longnt80
Aug 10 2018 09:48
oh I see, thanks @Blauelf
Blauelf
@Blauelf
Aug 10 2018 10:23
Maybe there's something special about placing "use strict"; outside of the function.
Bilal Rao
@bilal-rao
Aug 10 2018 10:40
Hello! can anyone tell me how can i integrate react-boilerplate code with my theme
ATom M
@ATom-M
Aug 10 2018 10:45
Basic Algorithm Scripting: Reverse a String
Does this lesson have a bug?
Because my solution doesn't work, and neither does one i found online
ATom M
@ATom-M
Aug 10 2018 10:53
Got it, false alarm!
Rogério Dalot
@Dalot
Aug 10 2018 11:01
Hey guys, how could I calculate how much a positioned absolute div element will take up on the screen?
in terms of height
Mohammed Boudad
@matrixersp
Aug 10 2018 13:15
@Blauelf I found out that you can't use 'use strict'; in the inner function when using default arguments, which is defined in ES6
Blauelf
@Blauelf
Aug 10 2018 13:29
Makes sense after all. Default arguments might contain code that has to be within the "use strict"; environment.
Mohammed Boudad
@matrixersp
Aug 10 2018 13:36
Exactly
Jason Luboff
@JLuboff
Aug 10 2018 15:05
Morning
Christopher McCormack
@cmccormack
Aug 10 2018 15:26
@JLuboff :wave:
Jason Luboff
@JLuboff
Aug 10 2018 15:34
@cmccormack What up homie
Christopher McCormack
@cmccormack
Aug 10 2018 15:34
hoping to make a lot of progress on my project at work today! depending on other teammates though so probably won't :(
you?
Jason Luboff
@JLuboff
Aug 10 2018 15:36
Haven't done a lot so far today lol Hoping to get done or close to done with adding the ability for multiple file uploads per action item today. Already have the backend handling of it done, just need to reconfigure the front end
Christopher McCormack
@cmccormack
Aug 10 2018 15:37
that's cool, can you make it so they can drop multiple files directly on the page?
I know that sounds like a pain to implement but I really like that feature
Jason Luboff
@JLuboff
Aug 10 2018 15:41
Maybe for a future implementation...for now it's just going to be file input fields with an Add Additional button. Then they'll be able to replace files as well (i.e they have a file uploaded already and instead of adding another they can choose a replacement file)
Christopher McCormack
@cmccormack
Aug 10 2018 15:44
Nice man I've never dealt with file uploads seems like a bit of a pain
Jason Luboff
@JLuboff
Aug 10 2018 15:46
It's actually not too bad with multer
You just give each input the same name, and then tell multer its multiple files so it gets it as an array.
But, its sort of a pain with SQL lol.
I have to man handle my returned query
(Due to having multiple rows of the same action but with a different file)
Christopher McCormack
@cmccormack
Aug 10 2018 15:49
What does SQL do with files exactly?
Jason Luboff
@JLuboff
Aug 10 2018 15:49
Well, in my case, I'm just storing the UNC path
You can store files directly in the database, but it's not really recomended unless it's < 1MB files
Christopher McCormack
@cmccormack
Aug 10 2018 15:53
Yeah figured you weren't storing the whole file :)
Jason Luboff
@JLuboff
Aug 10 2018 15:55
Ya don't know the sizes so figured network storage was the best scenario
Ozarion
@Ozarion
Aug 10 2018 16:58
Hey. How does one access fields inside mongoose document object?
Serenity
@qmikew1
Aug 10 2018 16:59

@JLuboff When you say that you have to man handle your query are you talking about denormalizing one-to-many with what amounts to a pivot (approach/terminology varies by vendor)?
i.e.,

lisa someUNCpath1
lisa someUNCpath2
lisa someUNCpath3

becomes
lisa, someUNCpath1, someUNCpath2, someUNCpath3?
(not blindy advocating because performance is always an issue - but as general concept)

Jason Luboff
@JLuboff
Aug 10 2018 16:59
@Ozarion You access it like you would an object
@qmikew1 Ya sort of. If I always had the same number of files, than a pivot could work but it varies and I don't want to get into Dynamic SQL. But essentially I create a similar structure but with an array of filenames/filelinks,
Ozarion
@Ozarion
Aug 10 2018 17:03
@JLuboff like if I have an object that has following properties. How to I push one more item to favoriteFoods?
{name : "anyname", age : 0, favoriteFoods : ["Ice cream", "eggs", "potato"]}
Jason Luboff
@JLuboff
Aug 10 2018 17:03
@Ozarion There's a push operator :)
Ozarion
@Ozarion
Aug 10 2018 17:06
I see... @JLuboff Can you what is wrong with this. My favoriteFoods array, when retrieved, is undefined.

var findEditThenSave = function(personId, done) {
  var foodToAdd = 'hamburger';

  const foundPerson = Person.findById(personId, (err, doc) => {
    if (err) { return done(err); }
    return doc;
  });

  foundPerson.favoriteFoods.push(foodToAdd);
  foundPerson.save((err, doc) => {
    if (err) { return done(err); }
    return done(null, doc);
  });
};
Serenity
@qmikew1
Aug 10 2018 17:08
might be a more elegant solution with the result set with like reduce or something - interesting dillema
Jason Luboff
@JLuboff
Aug 10 2018 17:08

@qmikew1 So basically I have something like this from my query

[
  {
    "ActionTypeID": 1,
    "Action": "Action 1",
    "Name": "Jason Luboff",
    "Email": "potato@fries.com",
    "ReviewDate": "2018-08-09T00:00:00.000Z",
    "CompletionDate": null,
    "Comment": null,
    "FileLink": "\\\\networkLocation\\SQLKeyboardShortcuts.pdf",
    "CompleteCount": 0,
    "TotalActionItems": 9
  },
  {
    "ActionTypeID": 1,
    "Action": "Action 1",
    "Name": "Jason Luboff",
    "Email": "potato@fries.com",
    "ReviewDate": "2018-08-09T00:00:00.000Z",
    "CompletionDate": null,
    "Comment": null,
    "FileLink": "\\\\networkLocation\\YouDontKnowJS.pdf",
    "CompleteCount": 0,
    "TotalActionItems": 9
  }

And end up with

[ { Action: 'Action 1',
    Name: 'Jason Luboff',
    shortName: 'potato',
    Email: 'potato@fries.com',
    ReviewDate: '2018-08-09T00:00:00.000Z',
    CompletionDate: null,
    Comment: null,
    FileLinks: 
     [ '\\\\networkLocation\\SQLKeyboardShortcuts.pdf',
       '\\\\networkLocation\\YouDontKnowJS.pdf' ],
    FileNames: [ 'SQLKeyboardShortcuts.pdf', 'YouDontKnowJS.pdf' ],
    CompleteCount: 0,
    TotalActionItems: 9 } ]
Christopher McCormack
@cmccormack
Aug 10 2018 17:08
@Ozarion findById is asynchronous
Jason Luboff
@JLuboff
Aug 10 2018 17:09
@Ozarion Unfortunately I'm more of a vanilla mongo kind of guy. but luckily our homie @cmccormack is here!
Christopher McCormack
@cmccormack
Aug 10 2018 17:11
@Ozarion you can try using
var findEditThenSave = async function(personId, done) {
//...
      const foundPerson = await Person.findById(personId, (err, doc) => {
//...
}
Or just nest all the code in the callback for findById
I think async is much easier
Ozarion
@Ozarion
Aug 10 2018 17:14
@JLuboff @cmccormack Worked like a charm. Thank you brothers.
Christopher McCormack
@cmccormack
Aug 10 2018 17:15
@Ozarion :thumbsup: glad it did because I didn't test it and wasn't 100% :)
Brad
@bradtaniguchi
Aug 10 2018 17:15
working from home has its perks . But it also has its flaws, like lacking air conditioning :/
Jason Luboff
@JLuboff
Aug 10 2018 17:16
@bradtaniguchi You make the big bucks, get yourself a place with AC
Brad
@bradtaniguchi
Aug 10 2018 17:16
I'm too cheap for that, plus I need to hunt them down now, all sold out near me, or I buy it on amazon haha
Jason Luboff
@JLuboff
Aug 10 2018 17:17
Nah just move into a place with AC
Brad
@bradtaniguchi
Aug 10 2018 17:17
ug I gotta move in general
Ozarion
@Ozarion
Aug 10 2018 17:17
Work from your Car.
Christopher McCormack
@cmccormack
Aug 10 2018 17:17
Make sure if you do get one get a window unit, not one of the floor units
Brad
@bradtaniguchi
Aug 10 2018 17:17
my car unfortunantly does not have an internet connection
@cmccormack how come you say that?
Christopher McCormack
@cmccormack
Aug 10 2018 17:17
the floor units blow inside air out, which pulls outside air in through the cracks
You also have to empty the water on some of them which sucks in the middle of the night
window units recycle inside air only
split units are great too but much more expensive
Jason Luboff
@JLuboff
Aug 10 2018 17:19
Our server room has a floor unit, can confirm needs water emptied
Serenity
@qmikew1
Aug 10 2018 17:19
unless you're living west of CA it's kind of unusual to not have ac (with apt unit) - what's up with that?
Ozarion
@Ozarion
Aug 10 2018 17:20
You know at home, you can work right from the bathtub. And no AC beats that.
Christopher McCormack
@cmccormack
Aug 10 2018 17:20
west of CA is the ocean
Serenity
@qmikew1
Aug 10 2018 17:20
it is hawaii
Christopher McCormack
@cmccormack
Aug 10 2018 17:20
haha
Serenity
@qmikew1
Aug 10 2018 17:20
(which is in the middle of the ocean, yeah)
Jason Luboff
@JLuboff
Aug 10 2018 17:20
A lot of places in Hawaii don't have AC
Christopher McCormack
@cmccormack
Aug 10 2018 17:20
I was just in Maui, we had AC all over
Serenity
@qmikew1
Aug 10 2018 17:20
yep, that's true
Christopher McCormack
@cmccormack
Aug 10 2018 17:21
but the weather was good enough to not need it most of the time
Serenity
@qmikew1
Aug 10 2018 17:21
for locals though and stuff that isn't hotel or bnb - it's fairly normal not to have ac
Jason Luboff
@JLuboff
Aug 10 2018 17:21
When we stayed in Maui, our vrbo didn't have AC, but with the patio door open and the room window open, it had a nice breeze from the tradewinds
Brad
@bradtaniguchi
Aug 10 2018 17:21
not many people where i live have AC, I'm not in LA, and am pretty close to the beach (like 3-5 miles I think?). Its just been humid and hot latly :/
Jason Luboff
@JLuboff
Aug 10 2018 17:21
@bradtaniguchi I thought you were in LA
I'm near the beach, and have AC...but.. I pay a premium for my apartment lol
Serenity
@qmikew1
Aug 10 2018 17:22
ah, makes sense ...then - so, you're looking at upping your rent @bradtaniguchi
Brad
@bradtaniguchi
Aug 10 2018 17:23
I work in LA, but I live further south haha
Jason Luboff
@JLuboff
Aug 10 2018 17:23
Ah.. for some reason I thought you lived inland from LA
Brad
@bradtaniguchi
Aug 10 2018 17:23
Nope, wrong way haha
Serenity
@qmikew1
Aug 10 2018 17:24
wait you live by the beach?
Jason Luboff
@JLuboff
Aug 10 2018 17:24
I do, ya
Serenity
@qmikew1
Aug 10 2018 17:25
so, everybody here is like wealthy (except me) ?
feels bad lol
Jason Luboff
@JLuboff
Aug 10 2018 17:25
Lol I am far from wealthy
Christopher McCormack
@cmccormack
Aug 10 2018 17:25
Yeah we're all billionaires with too much time on our hands
Markus Kiili
@Masd925
Aug 10 2018 17:25
@JLuboff You don't have your first M$ yet?
Jason Luboff
@JLuboff
Aug 10 2018 17:26
@Masd925 eh?
Markus Kiili
@Masd925
Aug 10 2018 17:26
First million yet to come?
Jason Luboff
@JLuboff
Aug 10 2018 17:26
oh hahaha I wish
Brad
@bradtaniguchi
Aug 10 2018 17:27
I wouldn't say I live by the beach, just near the beach. I would still need to drive for like 10-15 mins to get there
Serenity
@qmikew1
Aug 10 2018 17:27
I guess messing with js is just as crazy as like wanting to go to mars for like a billionaire - seriously you peeps are an eccentric lot
Jason Luboff
@JLuboff
Aug 10 2018 17:31
@cmccormack lives in Arizona...I mean..how eccentric can he be? :P
Christopher McCormack
@cmccormack
Aug 10 2018 17:31
We Flagstaffians don't associate ourselves with Arizona in that way sir
Jason Luboff
@JLuboff
Aug 10 2018 17:32
:joy:
Simon Cordova
@gbsimon87
Aug 10 2018 17:35
What's up what's up!
Another day another 50 cents!
Jason Luboff
@JLuboff
Aug 10 2018 17:37
Does less than 1 pound translate into cents? (serious question..)
Christopher McCormack
@cmccormack
Aug 10 2018 17:47
I think they just shave the silver off the edges and sell that instead
but that may be from some historical fiction I read
Jason Luboff
@JLuboff
Aug 10 2018 17:47
:joy:
Simon Cordova
@gbsimon87
Aug 10 2018 17:49
Their cents are called pence
So 50 pence
Brad
@bradtaniguchi
Aug 10 2018 17:50
anyone have any advice on using winston? I have limited experience with logging libraries (i'm not a backend guy)
Jason Luboff
@JLuboff
Aug 10 2018 17:51
@gbsimon87 Ah!
Simon Cordova
@gbsimon87
Aug 10 2018 17:51
Don't think I've ever even heard of Winston
What's up J you good?
How's that app, been a week now no?
Jason Luboff
@JLuboff
Aug 10 2018 17:55
Yup, it's being actively used, and I'm actively making changes lol
but the live changes have been quick/easy ones
Probably 75% complete in getting multi-file upload going
Brad
@bradtaniguchi
Aug 10 2018 17:56
aw crap... my dev npm script no longer works, I broke it while setting up testing :cry:
Simon Cordova
@gbsimon87
Aug 10 2018 17:59
@JLuboff good stuff man
Man
I just started a course in JS testing, what do you guys recommend? Jest or Enzyme?
Brad
@bradtaniguchi
Aug 10 2018 18:00
I never used enzyme, what will you be testing? (front-end backend, some framework
Jason Luboff
@JLuboff
Aug 10 2018 18:03
@gbsimon87 Ya, thanks man. Been pretty exciting seeing it get used
Simon Cordova
@gbsimon87
Aug 10 2018 18:04
@bradtaniguchi I'll mainly be testing React components
Brad
@bradtaniguchi
Aug 10 2018 18:05
I hear good things about Jest, but yea idk enough to provide a good argument besides "I hear Jest used the most" haha
the one thing I do like about jest is it does everything. Compared to my experience with chai/mocha there's like 50 extensions I need to do what I would consider "basic". Got annoying. But then I came from a very "hand-holdy" experience with Angular
But not going to lie, a more opinionated approach to testing is probably better, easier to get started.
Simon Cordova
@gbsimon87
Aug 10 2018 18:12
ps @cmccormack the sticky div thing on React was simple, pure CSS
Did learn however you can't use sticky inside a flex/grid container, but found a work-around
https://stackoverflow.com/questions/44446671/my-position-sticky-element-isnt-sticky-when-using-flexbox
Christopher McCormack
@cmccormack
Aug 10 2018 18:14

@gbsimon87

Currently this is only supported in Safari and Edge

?
Simon Cordova
@gbsimon87
Aug 10 2018 18:15
@cmccormack It's not correct, I tested in on Opera, Firefox, and Chrome
All modern browsers support it
Christopher McCormack
@cmccormack
Aug 10 2018 18:15
is this for a top nav?
Simon Cordova
@gbsimon87
Aug 10 2018 18:16
I did it for a sidebar nav
Christopher McCormack
@cmccormack
Aug 10 2018 18:19
will it always be in the same place or does it depend on scroll?
Simon Cordova
@gbsimon87
Aug 10 2018 18:20
It will always be in the same spot and stick once the parent container has passed the viewport scrolling point
as 'sticky' property itself works
if that makes sense
Christopher McCormack
@cmccormack
Aug 10 2018 18:24
yup just trying to determine if flex was needed but sounds like it would be
Simon Cordova
@gbsimon87
Aug 10 2018 18:27
In my case probably because I wouldn't want to be messing with the whole Flex layout, however were that not the case I don't think it would be necessary no
any position apart from absolute I'd assume would handle it fine
Christopher McCormack
@cmccormack
Aug 10 2018 18:32
@gbsimon87 I wonder if it would be better to use JS if there might be compatability issues with sticky
you could use JS and fixed
Brad
@bradtaniguchi
Aug 10 2018 18:35
damn my spec files are being added to the bundle :/
Simon Cordova
@gbsimon87
Aug 10 2018 18:38
@cmccormack true, but they support nothing but modern browsers so I think it should suffice, but will certainly keep that in mind
hows your day going?
Christopher McCormack
@cmccormack
Aug 10 2018 18:38
Pretty good, solved an issue with a public DNS server not being reachable, so I call that a win for the day :)
Thanks for asking
Simon Cordova
@gbsimon87
Aug 10 2018 18:39
public DNS is waaay over my head lol
Christopher McCormack
@cmccormack
Aug 10 2018 18:40
DNS is one of the easiest and hardest concepts
Brad
@bradtaniguchi
Aug 10 2018 18:44
Ew, there's some kinds of OPS I dislike, and networking stuff is one of em
Christopher McCormack
@cmccormack
Aug 10 2018 18:47
I'm glad, it keeps my field niche and in demand :)
Brad
@bradtaniguchi
Aug 10 2018 18:51
that's true haha
Christopher McCormack
@cmccormack
Aug 10 2018 18:52
i've been doing it for almost 10 years now and still feel like a noob though
Simon Cordova
@gbsimon87
Aug 10 2018 18:53
Damn man, I wish I've been programming for 10 years
I got found out at work today
Christopher McCormack
@cmccormack
Aug 10 2018 18:53
@gbsimon87 found out...?
Simon Cordova
@gbsimon87
Aug 10 2018 18:53
They did a lot of research on me, good thing they're cool people cus I could have been let go quick
I told them initially I've been programming for close to 5 years, but it's really about to be 2.5
Christopher McCormack
@cmccormack
Aug 10 2018 18:54
I'm sure you programmed a VCR or a universal remote before right?
Simon Cordova
@gbsimon87
Aug 10 2018 18:54
They did a background search on me and saw I used to own a bar 3 years ago, asked me how I managed to do that and handled my programming on the side
I was just upfront before getting caught in a web of lies
Christopher McCormack
@cmccormack
Aug 10 2018 18:54
I work 50-60 hours a week and still manage to get a lot of programming in, kind of a weird assumption
JJ Megma
@megma_jj_twitter
Aug 10 2018 18:55
@cmccormack You don't work as a programmer?
Simon Cordova
@gbsimon87
Aug 10 2018 18:55
They were cool though, they understood that had I said 2.5 years nobody would give me a shot, and they said my work so far didn't reflect 2.5 years
Christopher McCormack
@cmccormack
Aug 10 2018 18:55
@megma_jj_twitter nope. I do a little programming at work, scripting, automation, but not full time
Fikry82
@Fikry82
Aug 10 2018 18:55
Christopher McCormack
@cmccormack
Aug 10 2018 18:55
@gbsimon87 is that a good thing or a bad thing? haha
Fikry82
@Fikry82
Aug 10 2018 18:56
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.id.hasOwnProperty[prop] && prop != "traks" && value != ""){
collection.id.prop = value;
  }else if(prop == "traks" && collection.id.hasOwnProperty["traks"] == false){
var traks = [];
traks.push(collection.id.traks[value]);

  }else if( prop == "traks" && value != ""){
delete collection.id.prop;
  }

  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
Simon Cordova
@gbsimon87
Aug 10 2018 18:56
@cmccormack owning and managing your own bar on the front and back end of it trust me you have no time for code
Christopher McCormack
@cmccormack
Aug 10 2018 18:56
@gbsimon87 maybe but how would they know that?
Fikry82
@Fikry82
Aug 10 2018 18:56
any help ??
Simon Cordova
@gbsimon87
Aug 10 2018 18:56
@Fikry82 if the codebase is that long please provide a Codepen or equivalent link instead
Christopher McCormack
@cmccormack
Aug 10 2018 18:56
@Fikry82 first thing I notice is tracks is misspelled
Simon Cordova
@gbsimon87
Aug 10 2018 18:57
@cmccormack I guess they wouldn't, but I didn't want to start an unnecessary web of lies you know
The job is listed in the shortages list and they're giving me the time of day so I need to show respect back
Christopher McCormack
@cmccormack
Aug 10 2018 18:57
understood, I wouldn't expect you to lie, wasn't even implying you should haha
just find it weird they're all up in your past now
Fikry82
@Fikry82
Aug 10 2018 18:58
function updateRecords(id, prop, value) {
  if(collection.id.hasOwnProperty[prop] && prop != "tracks" && value != ""){
collection.id.prop = value;
  }else if(prop == "tracks" && collection.id.hasOwnProperty["tracks"] == false){
var traks = [];
traks.push(collection.id.traks[value]);

  }else if( prop == "tracks" && value != ""){
delete collection.id.prop;
  }

  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
still not working
Christopher McCormack
@cmccormack
Aug 10 2018 18:59
@Fikry82 you should not use object dot notation when the property is a variable
collection.id.hasOwn... should be collection[id].hasOwn... for example
Simon Cordova
@gbsimon87
Aug 10 2018 19:00
@cmccormack they had done the research before but hadn't brought it up since it was unnecessary in a sense
I've been able to complete all tasks so far - working on a brand new codebase and the other two developers that created it are on holidays
Christopher McCormack
@cmccormack
Aug 10 2018 19:00
dot notation is used when you know the actual property name
Fikry82
@Fikry82
Aug 10 2018 19:00
okay thx
Simon Cordova
@gbsimon87
Aug 10 2018 19:00
So I've been lucky that it's worked out for me so far and my work has done the talking so that's good
Fikry82
@Fikry82
Aug 10 2018 19:00
i will fix it
Christopher McCormack
@cmccormack
Aug 10 2018 19:00
@gbsimon87 yup that's all that matters, get your work done
you'll only get better over time, and that's what they should want
Simon Cordova
@gbsimon87
Aug 10 2018 19:01
I got hit with a task today that the second I saw the requirement I thought oh man, here we go
But got it done in 1.5 hours, was given 4, so I hope that made me look good
Fikry82
@Fikry82
Aug 10 2018 19:04
function updateRecords(id, prop, value) {
  if(collection[id].hasOwnProperty[prop] && prop != "tracks" && value != ""){
collection.id.prop = value;
  }else if(prop == "tracks" && collection[id].hasOwnProperty["tracks"] == false){
var traks = [];
traks.push(collection[id].traks[value]);

  }else if( prop == "tracks" && value != ""){
delete collection[id][prop];
  }

  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
i just wanna know is it completely wrong idea ??
Christopher McCormack
@cmccormack
Aug 10 2018 19:09
@Fikry82 it's only wrong if it doesn't work
Fikry82
@Fikry82
Aug 10 2018 19:09
it doesn't work :)
Simon Cordova
@gbsimon87
Aug 10 2018 19:10
@Fikry82 first little tip I can give that will be a long lasting helper is clean the code up
indent everything properly, it'll be much easier to read and cope with it believe me
ask anybody here with experience they'll agree
Christopher McCormack
@cmccormack
Aug 10 2018 19:12
I've also found combining conditionals can make things confusing; instead, try nesting your conditionals first, and combine them later if you get it working, if you chose to
JJ Megma
@megma_jj_twitter
Aug 10 2018 19:17
@Fikry82 haven't seen bunch but i noticed hasOwnProperty[prop]
should be ()
not brackets
I guess that seems to work though
Thats JavaScript for ya...
smh
Christopher McCormack
@cmccormack
Aug 10 2018 19:19
it shouldn't work either
JJ Megma
@megma_jj_twitter
Aug 10 2018 19:20
That sort of stuff makes me hate JavaScript
Christopher McCormack
@cmccormack
Aug 10 2018 19:20
there's no issue
you can try to use brackets on a function but it's just not going to be effective
JJ Megma
@megma_jj_twitter
Aug 10 2018 19:21
it works though
hasOwnProperty[prop]
Christopher McCormack
@cmccormack
Aug 10 2018 19:21
sure functions are objects
but does it actually work work
JJ Megma
@megma_jj_twitter
Aug 10 2018 19:21
seems to, but I did not look into it that far I guess
I assume it is
lol
Fikry82
@Fikry82
Aug 10 2018 19:22
function updateRecords(id, prop, value) {
  if(collection[id].hasOwnProperty(prop) && prop != "tracks" && value != ""){
     collection.id.prop = value;
  }else if(prop == "tracks" && collection[id].hasOwnProperty("tracks") == false){
     var tracks = [];
        tracks.push(value);
        collection[id].tracks;

  }else if( prop == "tracks" && value != ""){
     delete collection[id][prop];
  }

  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
still not working :)
JJ Megma
@megma_jj_twitter
Aug 10 2018 19:22
@Fikry82 what tests are failing?
Christopher McCormack
@cmccormack
Aug 10 2018 19:22
> var obj = {a: 1}
> obj
{ a: 1 }
> obj.hasOwnProperty['a']
undefined
> obj.hasOwnProperty('a')
true
JJ Megma
@megma_jj_twitter
Aug 10 2018 19:23
@cmccormack ty :)
Christopher McCormack
@cmccormack
Aug 10 2018 19:23
but you're right in that it doesn't error, this does take an understanding of the language
JJ Megma
@megma_jj_twitter
Aug 10 2018 19:23
which is weird to me
But you are right, its an object
:[
Simon Cordova
@gbsimon87
Aug 10 2018 19:25
@megma_jj_twitter JS has bugs itself, more experienced devs know this and find ways around it, its worth noting it though
Fikry82
@Fikry82
Aug 10 2018 19:25
ummmm
Simon Cordova
@gbsimon87
Aug 10 2018 19:26
@Fikry82
Try this in the console
0.1+0.2
Christopher McCormack
@cmccormack
Aug 10 2018 19:27
a lot of those bugs people make fun of are similar in other languages, quirks that noone would necessarily use but everyone loves to circle jerk about
Fikry82
@Fikry82
Aug 10 2018 19:27
@gbsimon87 why ??
how that will help me ?
Aditya
@ezioda004
Aug 10 2018 19:29
@cmccormack Yep
JJ Megma
@megma_jj_twitter
Aug 10 2018 19:29
@Fikry82 if you look at the FCC console you will see the errors from the tests
Christopher McCormack
@cmccormack
Aug 10 2018 19:29
haha
JJ Megma
@megma_jj_twitter
Aug 10 2018 19:30
@Fikry82 When I run your code this is what the tests result
After updateRecords(5439, "artist", "ABBA"), artist should be "ABBA"
Cannot read property 'pop' of undefined
After updateRecords(2548, "artist", ""), artist should not be set
Cannot read property 'pop' of undefined
Cannot read property '0' of undefined
After updateRecords(2548, "tracks", ""), tracks should not be set
After updateRecords(1245, "album", "Riptide"), album should be "Riptide"
Now you can go through and fix some of those errors :)
Fikry82
@Fikry82
Aug 10 2018 19:31
pop ??
i will start over
thx
Christopher McCormack
@cmccormack
Aug 10 2018 19:44
@megma_jj_twitter did you copy exactly?

@Fikry82 didn't finish

collection.id.prop = value;

should again be using brackets

Fikry82
@Fikry82
Aug 10 2018 19:47
@cmccormack i rest my cod
i will try again
Christopher McCormack
@cmccormack
Aug 10 2018 19:48
@megma_jj_twitter ignore I see why you got that error
Jason Luboff
@JLuboff
Aug 10 2018 19:52
@gbsimon87 Caught in a web of lies, man oh man
Simon Cordova
@gbsimon87
Aug 10 2018 19:54
nah, I swam free haha
Jason Luboff
@JLuboff
Aug 10 2018 19:56
hah
Fikry82
@Fikry82
Aug 10 2018 20:06
function updateRecords(id, prop, value) {
  if(!collection[id][prop] && prop != "tracks"){
     collection[id][prop] = value;
  }
  if(prop = "tracks" && collection[id].hasOwnProperty("tracks") == false ){
     var Tracks =[]
     collection[id]["tracks"] = value;
}
   if(prop == "tracks" && value != ""){
     collection[id]["tracks"].push(value);
   }
   if(value = ""){
    delete collection[id][prop];
   }

  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
??
Jason Luboff
@JLuboff
Aug 10 2018 20:11
@Fikry82 You need a loop in there.
Fikry82
@Fikry82
Aug 10 2018 20:11
why ?
Moisés Man
@moigithub
Aug 10 2018 20:12
tracks should be an array
collection[id]["tracks"] = value; <--- value is not ... try [value]
hmm.. but second if will push twice if u do like that...
.. then do .....=[ ]
Fikry82
@Fikry82
Aug 10 2018 20:14
yea thx
but not all function works
do i need to loop ??
Jason Luboff
@JLuboff
Aug 10 2018 20:15
Yes, you need a loop
Thats the only way to check each element in the array
Fikry82
@Fikry82
Aug 10 2018 20:15
what arry ?
Moisés Man
@moigithub
Aug 10 2018 20:15
i forgot the details of that exercise... post a link to it
Jason Luboff
@JLuboff
Aug 10 2018 20:16
@Fikry82 collection is an array..
Sorry, its an object
Fikry82
@Fikry82
Aug 10 2018 20:16
okay then
what arry you mean ?
catalin560
@catalin560
Aug 10 2018 20:16
@Fikry82 there is a way to do it without a loop
Jason Luboff
@JLuboff
Aug 10 2018 20:17
It's been a while since I've done that challenge lol need to look closer here
catalin560
@catalin560
Aug 10 2018 20:17
1) check if prop is artist and you have value
Fikry82
@Fikry82
Aug 10 2018 20:17
it works but not with all cases
Moisés Man
@moigithub
Aug 10 2018 20:17
repost ur new code... and tell which test case dont pass
catalin560
@catalin560
Aug 10 2018 20:18
there are already too many people commenting :)
Jason Luboff
@JLuboff
Aug 10 2018 20:20
@catalin560 I'll stop commenting and let you join in ;) :joy:
Moisés Man
@moigithub
Aug 10 2018 20:20
not really...
it was messy before the forum was implemented, lot ppl asking and answering at same time
catalin560
@catalin560
Aug 10 2018 20:21
oh right fcc has a forum
@Fikry82 you can also look up your problem on https://forum.freecodecamp.org/
catalin560
@catalin560
Aug 10 2018 20:33
@Fikry82 this is how I've done it
1) check if prop is artist and you have value hint: check its length
if true then update the prop of current id with value
2) check if prop is tracks and you have value
2.a) check if check if collection of id doesn't have prop hint: use Object.hasOwnProperty()
then just add value to that prop
2.b) else push the value onto the end of the album's existing tracks array, hint: use Object.values()
3) finally if there is no value (check its length) then delete the property
Fikry82
@Fikry82
Aug 10 2018 20:47
why i need to check length ??
catalin560
@catalin560
Aug 10 2018 20:52
@Fikry82 you have 3 arguments right? id, prop and value... how do you know all of these are inputed? what if one is missing? how do you check that?
Fikry82
@Fikry82
Aug 10 2018 20:53
if(!collection[id][prop] && prop != "tracks"){
     collection[id][prop] = value;

  }
thats how
lol
its wrong
catalin560
@catalin560
Aug 10 2018 20:54
ding ding..
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 (like 2548), a property prop (like "artist" or "tracks"), and a value (like "Addicted to Love") to modify the data in this collection. If prop isn't "tracks" and value isn't empty (""), 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" and value isn't empty (""), push the value onto the end of the album's existing tracks array. If value is empty (""), delete the given prop property from the album.
Fikry82
@Fikry82
Aug 10 2018 20:57
if(!collection[id].hasOwnProperty(prop) && prop != "tracks"){
     collection[id][prop] = value;
  }
is this wrong ?
Mohammed Boudad
@matrixersp
Aug 10 2018 21:02
@Fikry82 It seems right
Moisés Man
@moigithub
Aug 10 2018 21:03
remove first ! <-- means NOT
Fikry82
@Fikry82
Aug 10 2018 21:04
yes that what i want
if this prop not there i create one
how i can push value to array inside object ??
Moisés Man
@moigithub
Aug 10 2018 21:06
soo that piece of code saying....
if collection[id]. NOT . have a property (prop)
and props is not tracks
Fikry82
@Fikry82
Aug 10 2018 21:06
yes
Mohammed Boudad
@matrixersp
Aug 10 2018 21:06
use push() method
Fikry82
@Fikry82
Aug 10 2018 21:06
how ???
Mohammed Boudad
@matrixersp
Aug 10 2018 21:07
collection[id][prop].push(value);
It won't work if you don't have "tracks" in the collection object
Moisés Man
@moigithub
Aug 10 2018 21:07

album tracks artist are valid props.. .. by adding ! (not)
u already discarting all those

if collection[id]. NOT . have a property (prop)

catalin560
@catalin560
Aug 10 2018 21:11
@moigithub collection[id][prop] = [value]; will create that prop and add its value
oops
Fikry82
@Fikry82
Aug 10 2018 21:12
i did that
catalin560
@catalin560
Aug 10 2018 21:12
I spoiled an answer
Fikry82
@Fikry82
Aug 10 2018 21:12
but not all cases works
catalin560
@catalin560
Aug 10 2018 21:12
what about the rest?
Fikry82
@Fikry82
Aug 10 2018 21:12
function updateRecords(id, prop, value) {
  if(!collection[id].hasOwnProperty(prop) && prop != "tracks"){
     collection[id][prop] = value;
  }
  if(prop = "tracks" && collection[id].hasOwnProperty("tracks") == false ){
    var Tracks =[]
     collection[id][prop]=[value];
}
   if(prop == "tracks" && value != ""){
     collection[id]["tracks"].push(value);
   }
   if(value = ""){
    delete collection[id][prop];
   }

  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
Moisés Man
@moigithub
Aug 10 2018 21:14
yea i wrote that.. but next IF condition he wrote will push the value again @catalin560
:point_up: 10 de agosto de 2018 15:12
soo on that step.. you/he only need to create an empty array (unless use a else if instead of individual if )
also.. for comparison.. use === instead of = @Fikry82
single = is for assigment
Fikry82
@Fikry82
Aug 10 2018 21:22
zzzzz
i am lost :)
i think i will try again later
Moisés Man
@moigithub
Aug 10 2018 21:24
also.. instead of && (and) u could use nested IF's and else statement
then no need to duplicate prop ==="tracks" on each condition
Fikry82
@Fikry82
Aug 10 2018 21:48
function updateRecords(id, prop, value) {
  if(!collection[id].hasOwnProperty(prop) && prop != "tracks"){
     collection[id][prop] = value;
  }
  if(prop = "tracks" && collection[id].hasOwnProperty("tracks") == false ){
    var Tracks = [];
     collection[id][tracks] = value;
}
   if(prop == "tracks" && value != ""){
     var tracks = [];
     collection[id]["tracks"].push(value);
   }

  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
updateRecords(5439, "artist", "ABBA"); it works with this call
updateRecords(5439, "tracks", "Take a Chance on Me") not working with this
Christopher McCormack
@cmccormack
Aug 10 2018 21:51
@Fikry82 I think you may be leaning on us too heavily - have you added log statements to see what the values are at each step? Have you walked through the logic on paper to see if it matches what you expect?
If you can walk through your own code using the arguments passed to fill in variables along the way, you should be able to derive where your code is failing
Fikry82
@Fikry82
Aug 10 2018 21:52
dud i start the hole thing 3 dayz ago :)
but thx any way
bye
Christopher McCormack
@cmccormack
Aug 10 2018 21:53
see ya...
Jason Luboff
@JLuboff
Aug 10 2018 21:53
@cmccormack Way to be a jerk :P
Christopher McCormack
@cmccormack
Aug 10 2018 21:53
You can't learn by asking other people to help every time you make a change to your own code right?
Jason Luboff
@JLuboff
Aug 10 2018 21:54
True
Brad
@bradtaniguchi
Aug 10 2018 22:03
some people legit work that way, doing more work finding people to help them than debugging the problem :/
Pagnito
@Pagnito
Aug 10 2018 23:16
why do ppl write __dirname in path.resolve if it by default cancatenates current directory
newmoon
@newmoon
Aug 10 2018 23:39
@Pagnito __dirname is the path to the directory that contains the source file being executed. It is not always the "current directory"
I think if you console.log it in different environments, it may be clearer.
Pagnito
@Pagnito
Aug 10 2018 23:41
yea i did
so
if
i write
path.resolve( "build")
instead of path.resolve(__dirname, "build")
oh wait no
ok now i get it
newmoon
@newmoon
Aug 10 2018 23:42
You'd get an absolute vs relative path
Pagnito
@Pagnito
Aug 10 2018 23:43
thnx