These are chat archives for FreeCodeCamp/HelpJavaScript

29th
May 2018
asumirio
@asumirioo
May 29 2018 05:47
image.png
hi guys~ does anyone know how to solve this problem?
i've tried to install vue-cli and it always shows command not found
Pieter Stokkink
@forkerino
May 29 2018 07:17
@asumirioo did you install vue-cli globally?
Donnie
@Donnie-D
May 29 2018 12:33

We can self invoke a function expression but can we do this to a function declaration?

var example=(function () {
    //do something
})();

The above works

(function example() {
    //do something
})();

The above doesn't work. Is it because we can't do this or is there something wrong with my syntax etc. ?

Pieter Stokkink
@forkerino
May 29 2018 12:38
(function example(){
  console.log('huzaa!')
})()
logs huzaa! here
so there might be an error in your // do something, @Donnie-D
Donnie
@Donnie-D
May 29 2018 12:39
i better do something about that then :smile:
Pieter Stokkink
@forkerino
May 29 2018 12:40
:joy:
rumanbsl
@rumanbsl
May 29 2018 12:53
I am trying to chain function calls from all the props in an array. Is it possible in JS?
const opts = ['sort', 'map','filter'];
const arr = [1,2,3,4];
// then possibly looping then attach one after another
opts.forEach(opt => {
  arr[opt1](callback)[opt2](callback)[opt3](callback)
})
Blauelf
@Blauelf
May 29 2018 12:53
@Donnie-D If you put parentheses around like you did, it's no longer a function declaration but a named function expression.
@rumanbsl What do you mean by this? I mean, what should this thing do?
Donnie
@Donnie-D
May 29 2018 12:57
@Blauelf
(function example() { //do something })();
is this a function expression?
rumanbsl
@rumanbsl
May 29 2018 12:57

chaining function calls from a predefined sets
basically I want do something like

arr['sort']['map'] // and so on

i have dynamic props coming in, which values needs to be respected. if that make sense

Blauelf
@Blauelf
May 29 2018 12:58
@Donnie-D Yes, it is. A named function expression, those give nicer stack traces than anonymous function expressions.
Donnie
@Donnie-D
May 29 2018 13:01
you lost me at anonymous function expression @Blauelf
Pieter Stokkink
@forkerino
May 29 2018 13:01
@rumanbsl you can chain them, but you need to make sure that what is returned is the right form (sort, map, filter all return arrays, so that's ok, but don't accidentally throw a reduce in there which returns a number or string.
Blauelf
@Blauelf
May 29 2018 13:01
@rumanbsl Makes little sense to me, do you maybe have an example? And in JavaScript, one would more likely pass functions than method names.
Pieter Stokkink
@forkerino
May 29 2018 13:01
@rumanbsl and the callbacks have to be correct as well for the method
Donnie
@Donnie-D
May 29 2018 13:01
i know anonymous function. what is an anonymous function expression?
Blauelf
@Blauelf
May 29 2018 13:02
@Donnie-D (function(answer) { return answer === 42; }) is anonymous. (function check(answer) { return answer === 42; }) has a name. Both are function expressions.
Functions declared cannot be anonymous (for obvious reasons).
Donnie
@Donnie-D
May 29 2018 13:06
sorry i am missing something here. Am I right when I say function example(){} is a function declaration and var example= function(){}; is a function expression? @Blauelf
Blauelf
@Blauelf
May 29 2018 13:07
function example1(){}

is a function declaration.

(function example2(){})

is a function expression. The parentheses are needed only because I did not put anything in front that requires an expression.

Donnie
@Donnie-D
May 29 2018 13:10
in what case may I ask might we use (function example2(){}) please? @Blauelf
I was okay until you answered my question :smile: now I am more confused. But since you are clearly informing me of something I dont know already so please bear with me.
Blauelf
@Blauelf
May 29 2018 13:15
Wherever you might use (function(){}) but want nicer stack traces. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
Bjorn van de Peut
@bjorno43
May 29 2018 13:16
Heya all :wave:
@Blauelf Do you also work on backend languages?
Blauelf
@Blauelf
May 29 2018 13:18
Greetings to the other side of the border :)
Blauelf
@Blauelf
May 29 2018 13:30
@bjorno43 I'm not professionally coding at the moment. I have done Allaire/Macromedia ColdFusion, some Microsoft ASP (long before .net), CGI in Turbo Pascal (yeah, 16 bit times!), some Python, Java and JavaScript (but those not as backend). Most of this is outdated (like my Java knowledge mostly ends around J2SDK1.4).
Bjorn van de Peut
@bjorno43
May 29 2018 13:31
@Blauelf Ah cool. Still pretty impressive. Seems like you've been in it for quite some time, haha
Blauelf
@Blauelf
May 29 2018 13:32
I used to do more in my university times. Students have so much free time :)
Bjorn van de Peut
@bjorno43
May 29 2018 13:33
Uhuh, lol
Blauelf
@Blauelf
May 29 2018 13:37
And yes, also played too many games. Which is somewhat connected (like one might want to write a simulator or a helper script or an autoplayer for some of the games, but those are usually not that much backend)
In university, we used like Matlab and Mathematica, those are not exactly backend either.
Bjorn van de Peut
@bjorno43
May 29 2018 13:42
True. I've had my fair share of messing around with Game Trainers (ram injection, pointers etc) and Bots, haha
Donnie
@Donnie-D
May 29 2018 13:52
Wherever you might use (function(){}) but want nicer stack traces. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
I have read the above page but cant see ow its related to our discussion
@Blauelf
sorry I was unable to find why or where to use (function(){})
link from mdn you shared is about the function.name which is a read only property
Jyothi S
@Jyosiva
May 29 2018 13:56
Hi Could someone help me on this below error
Blauelf
@Blauelf
May 29 2018 13:56

A named function expression differs from the anonymous function expression only in the name property of the resulting function object, which is "anonymous" for an anonymous function. And this property is for example used when showing a stack trace.

So if you had something like

var answer = (function(){
    /* do complicated calculations */
    return 42;
}());

and it crashes, your function would print as "anonymous".

Jyothi S
@Jyosiva
May 29 2018 13:56
$ node app.js
server started !
removed all campgrounds
added campground
added campground
added campground
added campground
C:\Users\user\Downloads\Jyothi\yelpcampV3\node_modules\mongodb\lib\utils.js:132
      throw err;
      ^
in the code I have pushed the comments to a particular camp as below
 yelp.create(seed, function(err,camp){

                if(err)
                console.log(err);

                else
                console.log("added campground");

                comments.create({comment:"hi there", author:"John"},function(err,comment){

                    if(err)
                    console.log(err);

                    else
                    {
                        camp.comments.push(comment);
                        camp.save();

                    }

                });
Christopher McCormack
@cmccormack
May 29 2018 14:46
@Jyosiva issue appears to be with mongo - do you have error handlers in your db configuration?
Moisés Man
@moigithub
May 29 2018 14:51
soo if u have 4 conloe log with that msg "added cmpground"
why it breaks only after 4th? and not on previous calls
do u have any other places on ur code which log that msg? else it should break only on first call
Jason Luboff
@JLuboff
May 29 2018 15:15
:wave:
Christopher McCormack
@cmccormack
May 29 2018 15:17
@JLuboff hi! Have a good long weekend?
Blauelf
@Blauelf
May 29 2018 15:34
I always forget the Catholic holidays (but at the moment live in a catholic region, so Thursday is one).
Markus Kiili
@Masd925
May 29 2018 15:43
:wave:
Christopher McCormack
@cmccormack
May 29 2018 15:43
@Blauelf I don't know any of the catholic holidays :)
Except Easter I guess
Blauelf
@Blauelf
May 29 2018 15:45
I think Thursday's translates to "Corpus Christi".
Christopher McCormack
@cmccormack
May 29 2018 15:46
@Masd925 heya
Markus Kiili
@Masd925
May 29 2018 15:47
@cmccormack Hi. What's up?
Christopher McCormack
@cmccormack
May 29 2018 15:47
@Masd925 wishing we had the whole week off instead of just one day :)
Markus Kiili
@Masd925
May 29 2018 15:48
@cmccormack I just had two weeks off and now two hectic days at the new job.
Blauelf
@Blauelf
May 29 2018 15:48
And Christmas is somewhat universal Christian, too. Just celebrated at different days in different countries (depending among others on the calendar used)
Christopher McCormack
@cmccormack
May 29 2018 15:48
@Masd925 new job? Congrats!
@Blauelf it's considered secular in the US so everyone can enjoy
Markus Kiili
@Masd925
May 29 2018 15:49
@cmccormack At least 4 kinds of coffee there to be drunk all day. Need I say more?
Christopher McCormack
@cmccormack
May 29 2018 15:49
@Masd925 that's awesome! What kind of job is it?
Markus Kiili
@Masd925
May 29 2018 15:52
@cmccormack 2 months of training and then into some IT-projects. Aiming for full stack development eventually.
Christopher McCormack
@cmccormack
May 29 2018 15:53
Sounds fantastic!
Blauelf
@Blauelf
May 29 2018 15:53
@cmccormack Well, Christian holidays are general holidays here (and most holidays are Christian). But some are only in Catholic regions, others only in Protestant regions. And Christmas for us is December 25th/26th, while other countries celebrate for example December 6th (no longer official holiday) or January 6th (Three Kings Day). There are a few local holidays, too, so any region (or even city) has its own number.
Christopher McCormack
@cmccormack
May 29 2018 15:57
@Blauelf That's interesting. I like to look at it as just a winter celebration time, after a long year of working hard we all need that time to get together and enjoy something
Jason Luboff
@JLuboff
May 29 2018 16:24
@cmccormack Hey, ya pretty decent weekend. Yourself?
Christopher McCormack
@cmccormack
May 29 2018 16:27
@JLuboff good man came back from the conference and threw a surprise bday party for my sis-in-law, lots of fun
Jason Luboff
@JLuboff
May 29 2018 16:32
Nice
How was the conference?
Christopher McCormack
@cmccormack
May 29 2018 16:33
Was OK. I didn't get as much out of it as I had hoped. The parties were fun though :D
Jason Luboff
@JLuboff
May 29 2018 16:34
More of a networking thing then learning?
Christopher McCormack
@cmccormack
May 29 2018 16:35
I guess. I was a network guy at a security conference so most of the content wasn't catered toward me directly, and the stuff I did want to see wasn't as interesting as I hoped (new API and automation stuff)
Jason Luboff
@JLuboff
May 29 2018 16:36
Ah (when I said networking meant in the sense of meeting people not computer networking if that wasn't clear haha)
Christopher McCormack
@cmccormack
May 29 2018 16:36
But it is interesting to see the trends
@JLuboff haha yeah I know what you meant
Jason Luboff
@JLuboff
May 29 2018 16:37
Did you go to disneyland?
Christopher McCormack
@cmccormack
May 29 2018 16:39
No, walked all around it but didn't go in haha
A few colleagues did the Star Wars thing I guess
Jason Luboff
@JLuboff
May 29 2018 16:39
I forget that there's a decent amount of shopping around it
Christopher McCormack
@cmccormack
May 29 2018 16:40
yeah we went to the gardenwalk a few times, House of Blues, Mccormick and Shmicks, etc...
mostly stayed near the conference though as they provide food :)
Jason Luboff
@JLuboff
May 29 2018 16:40
Free food is nice
Christopher McCormack
@cmccormack
May 29 2018 16:45
very nice, my favorite part haha
Jason Luboff
@JLuboff
May 29 2018 16:45
Good food also?
Christopher McCormack
@cmccormack
May 29 2018 16:48
eh
Free always tastes a bit better though :)
Jason Luboff
@JLuboff
May 29 2018 16:48
haha
How's the nightlife app coming along?
Christopher McCormack
@cmccormack
May 29 2018 16:49
Good! I'm now working on the auth stuff, I think I have the twitter auth working
Jason Luboff
@JLuboff
May 29 2018 16:49
using passport.js or your own method?
Christopher McCormack
@cmccormack
May 29 2018 16:49
I've spent way too much time on refactoring and trying variations to make things more reusable though
passport-twitter
I don't like creating headers and all that junk haha
Jason Luboff
@JLuboff
May 29 2018 16:50
I feel ya
Christopher McCormack
@cmccormack
May 29 2018 16:52
I'm pretty happy with the tools though, I like these projects, the more I learn about express/passport/etc... the more I see how useful and reusable they can be
definitely a learning curve though
Jason Luboff
@JLuboff
May 29 2018 16:53
For sure, I learned a lot from each of those projects. I do need to go back and fix a lot of things I've learned since though
Christopher McCormack
@cmccormack
May 29 2018 16:57
Are you actually going to or just feel like you should? haha
Jason Luboff
@JLuboff
May 29 2018 16:58
....why you gotta call me out like that? haha
Christopher McCormack
@cmccormack
May 29 2018 16:59
haha
I rarely do either
once in a while I play with my recipe app because I actually use it occassionally but I want to do so much with it I should basically start over again
Jason Luboff
@JLuboff
May 29 2018 17:00
Recipe app is to demonstrate knowledge of react?
Christopher McCormack
@cmccormack
May 29 2018 17:00
FCC says React but I think you could use any framework
If/When you do build it, I highly recommend adding the ability to export/import json
maybe even use a db!
Jason Luboff
@JLuboff
May 29 2018 17:02
That would be a good way to handle it
Christopher McCormack
@cmccormack
May 29 2018 17:05
it's a fun project, really good way to get to know React
Jason Luboff
@JLuboff
May 29 2018 17:10
Eventually I'll get there :smile:
Christopher McCormack
@cmccormack
May 29 2018 17:10
I believe you... :D
@JLuboff you should soon though, isn't it the last piece for FCC?
Jason Luboff
@JLuboff
May 29 2018 17:12
In its current form, yes
@cmccormack You have the front end and data viz certs?
Christopher McCormack
@cmccormack
May 29 2018 17:16
yeah
Jason Luboff
@JLuboff
May 29 2018 17:18
So who will get their third cert first...you or I? dun dun dun!
Christopher McCormack
@cmccormack
May 29 2018 17:18
The race is on!
did you do the D3 projects?
Jason Luboff
@JLuboff
May 29 2018 17:19
Nope, haven't done any of the data viz stuff
Christopher McCormack
@cmccormack
May 29 2018 17:19
The d3 projects are probably worth digging into
You may get a lot out of it, like if you need to display charts or something for your work project
Christopher McCormack
@cmccormack
May 29 2018 17:25
I'm starting to understand why glitch.com has the word glitch in it...
Jason Luboff
@JLuboff
May 29 2018 17:26
I've briefly looked at D3 and it does look aweosme (and powerful). For charts in the past I've used chart.js but it is limited
Haha, what glitched?
Christopher McCormack
@cmccormack
May 29 2018 17:27
@JLuboff yeah charts.js and Victory are good if you just need something simple and quick. Their React components make it even simpler, which is great.
@JLuboff it seems I have to delete projects and create again when something goes wrong in the build process, and I don't see any way to stop the build temporarily
Shubham soni
@shubhamsoni2617
May 29 2018 17:28

I am learning Jquery, can anyone please help in doing the following:

<script>
$(document).ready(function() {
$("#getMessage").on("click", function(){
// Only change code below this line.
$(".message").html("Here is the message");
// Only change code above this line.
});
});
</script>

<div class="container-fluid">
<div class = "row text-center">
<h2>Cat Photo Finder</h2>
</div>
<div class = "row text-center">
<div class = "col-xs-12 well message">
The message will go here
</div>
</div>
<div class = "row text-center">
<div class = "col-xs-12">
<button id = "getMessage" class = "btn btn-primary">
Get Message
</button>
</div>
</div>
</div>


I want to replace "Here is the message" with

<h2>Numbers</h2>

<ul>

<li>1</li>
<li>2</li>

and on further clicking "Get message" with

<h2>Alphabet</h2>

<ul>

<li>A</li>

<li>B</li>
and so on...

Nate Mallison
@NJM8
May 29 2018 17:29
@JLuboff @cmccormack You guys have any experience with JSON web tokens?
Christopher McCormack
@cmccormack
May 29 2018 17:30
@NJM8 just theoretical, was going to use them but skipped
@shubhamsoni2617 are you using an FCC exercise as your template?
@shubhamsoni2617 You can add HTML as a string in your $(.message).html(...) call I believe. What I recommend is if you have lots of HTML you want to append to the DOM, either create the html in your html file and set the display to none, then target that html and display it when needed, or use Javascript to create your elements with the document.createElement method
Shubham soni
@shubhamsoni2617
May 29 2018 17:34
@cmccormack Actually, I have already done that exercise. I am doing Intermediate front end project.
I am doing something else, just to make it look simpler, I pasted that code.
Christopher McCormack
@cmccormack
May 29 2018 17:34
@shubhamsoni2617 if you share the link to the exercise that will help us. Also when posting code please surround code with three backticks (should be on ~ key, next to 1 on keyboard) on their own line, like this:
```
Code
```
Jason Luboff
@JLuboff
May 29 2018 17:35
@cmccormack Oh weird. I never had that issue. It does get sort of goofy when their's build issues but usually I just pull the fresh repo and it rebuilds
@NJM8 I've looked at JWT before but ended up not using them
Shubham soni
@shubhamsoni2617
May 29 2018 17:37
Christopher McCormack
@cmccormack
May 29 2018 17:38
@shubhamsoni2617 why do you want to add lists? that doesn't appear to be part of the exercise
Shubham soni
@shubhamsoni2617
May 29 2018 17:39
@cmccormack Currently I am doing: Intermediate Front End Development Projects
Build a Random Quote Machine Incomplete 
Christopher McCormack
@cmccormack
May 29 2018 17:41
@shubhamsoni2617 ok.
Shubham soni
@shubhamsoni2617
May 29 2018 17:42
@cmccormack Instead of quote, I want to make some weekly list sort of thing. For eg.
exercise for monday, tuesday....
Christopher McCormack
@cmccormack
May 29 2018 17:43
@shubhamsoni2617 :point_up: May 29, 2018 10:30 AM
Shubham soni
@shubhamsoni2617
May 29 2018 17:46
@cmccormack Alright! Thanks a ton. I didn't saw that at the first glance.
CamperBot
@camperbot
May 29 2018 17:46
shubhamsoni2617 sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1463 | @cmccormack |http://www.freecodecamp.org/cmccormack
Shubham soni
@shubhamsoni2617
May 29 2018 17:48
@cmccormack Could you please share some useful links so that I can have more detail on that?
Shubham soni
@shubhamsoni2617
May 29 2018 17:58
Thanks again. I really appreciate your help.
Christopher McCormack
@cmccormack
May 29 2018 18:02
For creating a template using HTML, there are a few ways to do it, but you may also use https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template @shubhamsoni2617
Will Foster
@Will5592
May 29 2018 18:05

hi guys, I'm absolutely stumped about something, anyone able to shed some light?

Basically, I've created a second event listener in my JS so that my lightbox will close (not actually put the closing functionality in yet) when I click the body.

The eventlistener is working, but I'm getting a 'null' when I console log my .lightbox class

const container = document.querySelector(".container");
const lightbox = document.querySelector(".lightbox");

//add event listener to main element with .container class
container.addEventListener("click", function(e) {
  console.log(e.target.dataset.attribute);

  // store data attribute of event target in var
  const dataAttr = e.target.dataset.attribute;

  //if event target's data attribute is toggle
  if (dataAttr === "toggle") {
    //if lightbox doesn't exist, create one
    if (!lightbox) {
      const newLightbox = document.createElement("div");

      newLightbox.className = "lightbox";
      newLightbox.id = "lightboxID";
      newLightbox.innerHTML =
        ' <div class="img-holder"><img src="img/portrait.jpeg" alt=""></div>';

      document.body.appendChild(newLightbox);

      console.log("lightbox created");
    }
  }
});

document.body.addEventListener("click", function() {
  console.log(document.body);
  console.log(lightbox);

  if (lightbox) {
    console.log(lightbox);
    //   lightbox.style.display = "none";
  }
});
Christopher McCormack
@cmccormack
May 29 2018 18:17
@Will5592 is your JS executing after the HTML has loaded?
Will Foster
@Will5592
May 29 2018 18:24
@cmccormack No I don't think so, but possibly. I put my script tag as the absolute last thing in the body, but the element that gets created does get appended after the script (I didn't think that would matter)
    <script type="text/javascript" src="javascript/main.js"></script>

</body>

</html>
Element gets appended just before closing body tag]
Christopher McCormack
@cmccormack
May 29 2018 18:25
@Will5592 if an element gets created in JS, you'll either want to use the variable assignment when you first created your element within your handlers, or perform a new query for the selector and use that instead

@Will5592

the element that gets created does get appended after the script

Where is that in your code?

Will Foster
@Will5592
May 29 2018 18:32
@cmccormack I did try that, just console logging a new query selector, but it still returned null
Christopher McCormack
@cmccormack
May 29 2018 18:33
@Will5592 if you can duplicate your code into something like codepen it would be easier to help
Will Foster
@Will5592
May 29 2018 18:34
@cmccormack sure, give me a min to copy it in
@mcm
@cmccormack https://codepen.io/Will5592/pen/WyNzRm There is the pen, only issue is the images aren't included as they are not linked images, they're in a folder
Christopher McCormack
@cmccormack
May 29 2018 18:41
@Will5592 why not just build your lightbox in your html?
@Will5592 you can set display to none in your css then change it to display: block or whatever you want via JS
then it will be there already when you build your handlers
Gulsvi
@gulsvi
May 29 2018 18:43
Does JS have a simple way to do event delegation like in jQuery?
Will Foster
@Will5592
May 29 2018 18:43
@cmccormack Yeah that's probably what I'll have to do
Gulsvi
@gulsvi
May 29 2018 18:44
if not, a simple way to fix this problem @Will5592 is to redefine your lightbox variable at the top of your document.body event listener:
document.body.addEventListener("click", function() {
  lightbox = document.querySelector(".lightbox");
Will Foster
@Will5592
May 29 2018 18:44
@cmccormack I was just keen to understand why it didn't work so I knew for next time
Gulsvi
@gulsvi
May 29 2018 18:44
switch from const to let at the top when you initially define the variable
Christopher McCormack
@cmccormack
May 29 2018 18:44
he doesn't have a .lightbox element to reference
@Will5592 it didn't work because you never had the .lightbox element when you assigned your variable in JS. Your container click handler appears to build a new lightbox but you never assigned that value to your global
Will Foster
@Will5592
May 29 2018 18:50
@cmccormack @gulsvi Redeclaring in the second event listener did work thanks! I don't quite understand why it didn't work though , because the Const Lightbox variable is global
Christopher McCormack
@cmccormack
May 29 2018 18:51
Can you save your pen with the updates?
Will Foster
@Will5592
May 29 2018 18:51
So in my second event listener, surely when I console.log(lightbox), it would recall that selector?
Gulsvi
@gulsvi
May 29 2018 18:52
@Will5592 It's a common problem about how events bubble up. All of us hit it at some time or another. Glad that fix helped.
Bjorn van de Peut
@bjorno43
May 29 2018 18:52
@Will5592 It didn't work because you're not wrapping it inside a document.addEventListener("DOMContentLoaded", function(event) { event handler. You're selecting elements before the DOM is loaded. At least, that's what it looks like
Will Foster
@Will5592
May 29 2018 18:54
@cmccormack Saved my updates for you
Christopher McCormack
@cmccormack
May 29 2018 18:54
@bjorno43 that's not the issue, he never had that element, he only creates it when clicking the container, and never assigns the new element to the global var
Will Foster
@Will5592
May 29 2018 18:54
@bjorno43 That, in theory, shouldn't matter as I am creating the content I'm selecting with JS
Bjorn van de Peut
@bjorno43
May 29 2018 18:55
Are you sure? Cuz I see this at the top on that pen:
const container = document.querySelector(".container");
let lightbox = document.querySelector(".lightbox");
Christopher McCormack
@cmccormack
May 29 2018 18:56
@bjorno43 .lightbox isn't in his html
@Will5592 you saved the pen? still doesn't work
@Will5592 I dont' think your dataAttr is accurate
Bjorn van de Peut
@bjorno43
May 29 2018 18:58
Ah yes, I see. It's just a bit confusing
Will Foster
@Will5592
May 29 2018 18:59
@cmccormack It does work in VS code though, I just copied and pasted it into codepen
Christopher McCormack
@cmccormack
May 29 2018 19:01
not sure how that's possible if what is in your pen is what you're using but I'm glad it's working for you :)
Will Foster
@Will5592
May 29 2018 19:02
So I dunno why it doesn't really work in there, but thanks all for your help @cmccormack @gulsvi
Christopher McCormack
@cmccormack
May 29 2018 19:03
@Will5592 you may want to look up event.target vs event.currentTarget as well if you find any issues with your clicks not working 100% of the time
Bjorn van de Peut
@bjorno43
May 29 2018 19:08
@Will5592 I think VS code is doing some weird magic there. Because when you first create the selector variable, it isn't there yet. Then you're creating the element and add it to the DOM. But JS works from top to bottom. It's not like let lightbox = document.querySelector(".lightbox"); is executed again when called. It's simply still null. Only after you re-assign the variable, it'll work. You might as well just put let lightbox; at the top instead.
Donnie
@Donnie-D
May 29 2018 19:30
Just playing... wondering whether its the syntax of my function call at the end which is wrong or is it wrong altogether :smile:
function example(){
  var a= 1;

  function checking (){
    a+=1;
    console.log('you called this function');
  }
  return a;
}

example().checking();
anyone ? lol
oops missed some code above. sorry yall :smile:
basically my emphasis is on the last line of the code. How can we call a function which is inside another function?
Brad
@bradtaniguchi
May 29 2018 19:34
@Donnie-D theres a few ways to "call a function in a function" but it really depends on how you want to call it.
Donnie
@Donnie-D
May 29 2018 19:34
lol how about the way I did above. How bad is that ?
is the syntax wrong or right to begin with?
example().checking();
can we call a function which is inside another function like this?
Christopher McCormack
@cmccormack
May 29 2018 19:39
@Donnie-D in example you're just returning a Number, not an object with properties
Donnie
@Donnie-D
May 29 2018 19:42
Yes sorry the inside of the code is not the main point of my question here. I was basically curious whether I can call a function which is inside another function like the way I did? If not then whats the closest match?
Christopher McCormack
@cmccormack
May 29 2018 19:42
@Donnie-D
function example(){
  this.a= 1;

  this.checking = function(){
    this.a+=1;
    console.log('you called this function');
  }

}

new example().checking() // you called this function
Donnie
@Donnie-D
May 29 2018 19:42
That example I just made to get my point across :smile:
Christopher McCormack
@cmccormack
May 29 2018 19:42
@Donnie-D the inside of your code is what matters
Donnie
@Donnie-D
May 29 2018 19:44

of course it does lol. How about

function example(){
  var a= 1;

  function checking (){
   //do something
  }
  return a;
}

example().checking();

for now to keep this simple. Lol I didnt mean for anyone to catch my other problems. I have plenty of them. Just trying to sort them one at a time

Bjorn van de Peut
@bjorno43
May 29 2018 19:45
@Donnie-D You can't call a function inside a function like that, simply because it doesn't exist. The inner function is only created when the outer function is called. And it's destroyed when the outer function exits. So if you try to call an inner function directly from outside, it doesn't exist as the outer function never created it
Christopher McCormack
@cmccormack
May 29 2018 19:46
@Donnie-D
Using closure https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures
function example(){
  let a = 1;

  return function(){
    a+=1;
    console.log('you called this function');
  }
}

example()() // you called this function
Gulsvi
@gulsvi
May 29 2018 19:47
Or create a class @Donnie-D :
class Example {
  constructor(val = 1) {
    this.a = val;
  }

  checking() {
    this.a += 1;
    console.log("You updated a to equal: " + this.a);
  }
}

const example = new Example(4).checking() // You update a to equal: 5
Donnie
@Donnie-D
May 29 2018 19:51
@bjorno43 thats a concise and clear explanation :bow: @gulsvi hey boss (lol) @cmccormack :+1:
Gulsvi
@gulsvi
May 29 2018 19:52
And a simpler one :)
class Example {
  checking(val = 1) {
    this.a = 1 + val;
    return "You updated a to equal: " + this.a;
  }
}

console.log(new Example().checking());  // You update a to equal: 2
console.log(new Example().checking(4));  // You update a to equal: 5
console.log(new Example().checking(8));  // You update a to equal: 9
Hey boss lol
Ankur sharma
@ankur1163
May 29 2018 20:06
I have little different question
I have finished all 3 certificates
I want to create complex app. I was coding in my macbook air
and now i am thinking to code on monitors
so, my question is should i buy 2 monitors , 4k monitor or 1 ultrawide monitor?
Christopher McCormack
@cmccormack
May 29 2018 20:13
@ankur1163 that is entirely up to you. I like 2 monitors because there are hotkeys to mount windows on half the screen so you can create 4 discrete segments pretty easily
Bjorn van de Peut
@bjorno43
May 29 2018 20:13
@ankur1163 Whichever suits you best. I personally prefer working with 2+ monitors. Simply because you use your computer for other stuff than coding as well. And an ultrawide monitor might be uncomfortable for other work. But again, it's a personal preference
Jason Luboff
@JLuboff
May 29 2018 20:19
I have 3 monitors setup... two horitzontal...1 vertical. Depending on the editor/ide I'll change if its vert or horiz
Bjorn van de Peut
@bjorno43
May 29 2018 20:21
I've got 2 27" monitors and my 45" tv hooked up to my system. TV is just for watching movies I've downloaded, lol
Jason Luboff
@JLuboff
May 29 2018 20:25
All 3 are 24"...and its just my work computer. At home I used to have 2 off-sized but one died. So only one 20" tv which doesn't display text very sharply. Oh well. Never use it anyhow
Bjorn van de Peut
@bjorno43
May 29 2018 20:37
24" with 3 monitors is more than enough. With 27" I've already noticed it's the max for me. Any bigger and it become uncomfortable
Jason Luboff
@JLuboff
May 29 2018 20:43
Oh ya it's good. Not sure how I'd feel about higher res monitors of the same size..
Christopher McCormack
@cmccormack
May 29 2018 21:11
I bought one of these guys as a side monitor not too long ago and I love it - super crisp and great colors, kind of makes my super fancy gaming monitor look worse next to it
Jason Luboff
@JLuboff
May 29 2018 21:25
If I used my computer at home more I'd be willing to get something like t hat
Christopher McCormack
@cmccormack
May 29 2018 21:26
@JLuboff good for you. I try to avoid using it at night as well. I use them during the day though as my main PC is right next to my work laptop
Jason Luboff
@JLuboff
May 29 2018 21:27
I'm guilty of using my phone at night though.. :smile:
Christopher McCormack
@cmccormack
May 29 2018 21:29
ugh they should burn you at the stake
Jason Luboff
@JLuboff
May 29 2018 21:31
hah
Brad
@bradtaniguchi
May 29 2018 21:39
I just got a bunch of ram to upgrade my PC at home, I realized it was time when I was running into ram issues for just for work projects haha
Jason Luboff
@JLuboff
May 29 2018 21:40
@bradtaniguchi Whats with your work? They make you do work from home on your own computer? And give you junky hardware from what you've said before hah
Brad
@bradtaniguchi
May 29 2018 21:42
wow my grammar bad it is (hehe) but yea I worked from home last week and started running out of ram when working on my stuff. I could request another computer, but I don't have space for it. Plus my computer is still "alright", but 8gb of ram isn't enough nowadays
Jason Luboff
@JLuboff
May 29 2018 21:43
Get a laptop with a docking station
Brad
@bradtaniguchi
May 29 2018 21:44
I had bad experiences with those, and my company definantly wont pay for one of those to work from home, they'd just throw another desktop workstation at me
Its fine tho, more ram = more tabs open :P for personal stuff
Jason Luboff
@JLuboff
May 29 2018 21:44
"personal stuff" ;)
Christopher McCormack
@cmccormack
May 29 2018 21:45
hah
@JLuboff you ever have an issue where glitch doesn't import a specific directory from github?
Brad
@bradtaniguchi
May 29 2018 21:48
I just gotta see if the new ram works with the old ram, then 24gb ram here i come MUHAHA, If not 16gb is fine :P
Jason Luboff
@JLuboff
May 29 2018 21:49
@cmccormack No, but I haven't imported anything with a ton of directorys. You don't have an ignore file right?
@bradtaniguchi If its the same type of RAM (PC4, PC5, etc) and the motherboard supports it, then I don't see why not
I mean...ya sometimes mismatched causes issues but usually is alright
Christopher McCormack
@cmccormack
May 29 2018 21:51
@JLuboff my ignore file would mean it's not on github but it is, my src/images dir doesn't get pulled for some reason
Jason Luboff
@JLuboff
May 29 2018 21:52
well ignore on glitch side (I don't know how that would affect a pull)
Hmm.. the whole directory is ignore or just the files within?
Christopher McCormack
@cmccormack
May 29 2018 21:53
there is no ignore
I don't ignore anything in my src dir other than log files/etc...
it's strange
I don't believe glitch would have it's own internal ignore would it?
hmm using the console the dir is copied I guess, just doesn't show up in the tree
Jason Luboff
@JLuboff
May 29 2018 21:55
I wonder if it has to do with how Glitch hosts images (you have that specific folder you can drag images into)
Christopher McCormack
@cmccormack
May 29 2018 21:59
No clue
but this is a node app, it shouldn't require me to upload anything
Jason Luboff
@JLuboff
May 29 2018 22:02
There's a reason I use to switch between Glitch and Heroku haha. If I got deployment issues in one, I usually was fine to deploy in the other
Christopher McCormack
@cmccormack
May 29 2018 22:02
yeah I may pop over there, I'm kind of sick of Glitch always having some bug every time I use it
Jason Luboff
@JLuboff
May 29 2018 22:04
Definitely pro's and con's to each. I like Glitch's built in editor (I can quickly test something instead of needing to change it in my local editor push to github, pull in glitch, etc) but heroku's auto listening for repo changes is wonderful
Christopher McCormack
@cmccormack
May 29 2018 22:09
How do I actually set that up? I created a new app, set my deployment method to github, and setup automatic deploys from master. Not sure what to do next haha
isnt' there an interface that gives you the filesystem and an editor as well?
Ah I guess you have to push once to your repo first
@JLuboff thanks for being my rubber ducky :)
Jason Luboff
@JLuboff
May 29 2018 22:14
:+1:
Quincy turned off camperbot :(
Richard
@rylew0925
May 29 2018 22:15
What is the purpose of the form element in "Create a Form Element?"
Jason Luboff
@JLuboff
May 29 2018 22:15
@rylew0925 Can you give more context?
Richard
@rylew0925
May 29 2018 22:16
In the "Create a Form Element" lesson, what do the <form>content</form> do?
Jason Luboff
@JLuboff
May 29 2018 22:17
@rylew0925 Ok, the Form element allows you to send form data (i.e input fields, check buttons, etc) to your backend to process it as needed
mozilla docs are great for explaining this stuff
Jason Luboff
@JLuboff
May 29 2018 22:18
A login form is a fairly normal example
Richard
@rylew0925
May 29 2018 22:19
So basically, it's submitting the contents of the text box to the URL that is within the forms?
Jason Luboff
@JLuboff
May 29 2018 22:21
Yes
Richard
@rylew0925
May 29 2018 22:22
@JLuboff Thanks!
Brad
@bradtaniguchi
May 29 2018 22:22
Whats the difference between PC4/PC5 RAM :0
@JLuboff
Jason Luboff
@JLuboff
May 29 2018 22:23
@bradtaniguchi Clock speed
Brad
@bradtaniguchi
May 29 2018 22:23
HOT DAMN, I just went into a UBER CLASS file, taking 1.5k lines :_(
@JLuboff Damn I knew I forgot to look into something :/
Jason Luboff
@JLuboff
May 29 2018 22:27
Uh oh... you didn't just order RAM all willy nilly did you?
Brad
@bradtaniguchi
May 29 2018 22:28
whats the difference between PC4/5 and the frequency speed? I didn't see any talk of PC4/5 when I was doing a little research
Ok I did a little more research, might have to ship the ram back if its the wrong one :/
Jason Luboff
@JLuboff
May 29 2018 22:33
:D
Your computer may not even use either one depends on the processor/motherboard
If I remember correctly.. there are different speeds within the same type too. PC4 will have varying speeds (again dependson your processor/motherboard) but you can have a mix of slower and faster but it will run at the slower speed (i.e not ideal). Also, PC4 vs PC5 would have a different slot layout
Brad
@bradtaniguchi
May 29 2018 22:39
I thought the DDRx was what determines the slot layout? I read thru the entire amazon page and didnt' see anything about PC specification for the ram so I'm not sure if it doesn't apply, or if Im just missing something
Jason Luboff
@JLuboff
May 29 2018 22:42
I think DDRx corresponds to PCx while DDRy corresponds to PCy (again.,.. IIRC)
Brad
@bradtaniguchi
May 29 2018 22:44
Oh, I picked the same DDRx (DDR3) and MHz as my current RAM, so if the PCx corresponds to the DDRx number I should be fine then right?
Jason Luboff
@JLuboff
May 29 2018 22:44
Ya you sohuld be fine
just make sure the pin layout is the same
which is should be
Brad
@bradtaniguchi
May 29 2018 22:47
Ok I should be good then, damn you scared me XD, its been like 7-8 years since I built the CP with a friend so I forgot most of the specs and what not
Jason Luboff
@JLuboff
May 29 2018 22:48
I used to know the specs of my PC...but can't really remember besides knowing I have an i7 3.4 gHZ Sandy bridge... gigabyte motherboard... 16gb ram (not sure which)... cooler master heatsink..
Brad
@bradtaniguchi
May 29 2018 22:51
Yea I had to get speccy to get most of the info
I was good tho, I have the boxes for all the parts still, but I was too lazy to look at them at the time of my purchase haha
Jason Luboff
@JLuboff
May 29 2018 22:54
Oh and I have several hard drives... two in a RAID 0 config
Brad
@bradtaniguchi
May 29 2018 22:55
That's the one that seperates the data so its like twice the lookup speed, but twice the risk right?
Jason Luboff
@JLuboff
May 29 2018 22:56
Yes, Striping without Redundancy. So stripes data across both drives which results in faster speeds, but if one (or more) drives fail, all data is lost
Christopher McCormack
@cmccormack
May 29 2018 22:56
@JLuboff so it wasn't Glitch, it was me
apparently saving a jpg as a .ico may work locally but totally borks on both glitch and heroku :D
so my favicon kept breaking the entire chain
Jason Luboff
@JLuboff
May 29 2018 22:57
RAID 5 is better config if looking to use striping as its Striping with parity (i.e redundancy). IT will write data across all drives in blocks and have parity info of each drive on the others so if one drive fails, you can pop in a new one and it will write the data to it
@cmccormack Ah ha!
Good find
Brad
@bradtaniguchi
May 29 2018 22:59
Yea I remember the guy that helped me build my computer was all into that sorta stuff, but I was too cheap to buy more than 1 driving, knowing in the future I could purchase bigger HDs and possible SSDs. (They were out but expensive at the time).
Christopher McCormack
@cmccormack
May 29 2018 23:00
I had a raid 5 array forever until I got rid of it and just started using SSDs
hard drives get too hot
Jason Luboff
@JLuboff
May 29 2018 23:00
My drives were used drives I got for free :( but...they're still running... I always though about going to SSD...but by the time I was ready to..I really don't use the computer enough to have justified it
Brad
@bradtaniguchi
May 29 2018 23:00
I didn't see the purpose of doing RAID 0 with SSD's tho, and didn't care about RAID 5 redudancy tho
Jason Luboff
@JLuboff
May 29 2018 23:00
RAID 0 with SSD's would probably be limited by your SATA connection
Brad
@bradtaniguchi
May 29 2018 23:01
Right now I think i have like 3 HDs, 1 500 GB starter, used for media, 1 225 HD SSD for booting up like 2 games that require fasterload, 1 TB as the main for everything else
I want to move to a 1 TB SSD, but I could care less about HD speed for the most part
Christopher McCormack
@cmccormack
May 29 2018 23:02
yeah don't really need raid 0 for SSDs
Jason Luboff
@JLuboff
May 29 2018 23:02
You care once you realize the speed difference
Christopher McCormack
@cmccormack
May 29 2018 23:03
There are hybrid drives that have a small SSD cache and a large spinning media
Brad
@bradtaniguchi
May 29 2018 23:03
Yea my friend had that setup with 2 SSDs seem like uber overkill, yea his CP booted up in like 5 seconds, but he had like 500GB HD space for his C drive
I heard the hybrid drives aren't worth it tho?
Jason Luboff
@JLuboff
May 29 2018 23:03
@cmccormack Those things are awful ( or at least the original Seagate ones were)
Christopher McCormack
@cmccormack
May 29 2018 23:03
spinning drives are better now for just backup purposes imo
I used them for a few HTPCs I made, they were good for that
small boxes with a single drive, but faster boot times
Jason Luboff
@JLuboff
May 29 2018 23:05
I think Apple's solution was a cope out for iMacs. The fusion drive. Such a fucking stupid thing. They used two drives, one smaller SSD and a larger HD. The SSD stored the file system along with frequently used compnents (apps, files, etc). Did it on the fly but I don't think the speed difference was really all that much