These are chat archives for FreeCodeCamp/HelpJavaScript

9th
Nov 2018
Jason Luboff
@JLuboff
Nov 09 2018 00:00
20 minutes away, so no immediate danger but I can see all the smoke
Jason Luboff
@JLuboff
Nov 09 2018 00:31
Uggghhh I hate you IE
I think I'm just not going to support it. Fuck it. I hate it.
Brad
@bradtaniguchi
Nov 09 2018 00:36
Good choice
Jason Luboff
@JLuboff
Nov 09 2018 00:37
Ya... I think I'll just detect IE...and just display a message to open in a different browser
That...or I make it an Electron app and it wont even matter! but then it needs to be installedo n each computer that requires it :(
Brad
@bradtaniguchi
Nov 09 2018 00:39
just say IE is a security risk and force people to use another browser hehe
Jason Luboff
@JLuboff
Nov 09 2018 00:41
Well either way the project requestor is asking for me to use a modal for a certain section..which doesn't render correctly in IE (I'm using Bulma CSS). So...thats all the more reason hehe
Albert Cardona II
@daddycardona
Nov 09 2018 03:14
@sjames1958gm I feel you I only have one job nothing to do with coding lol and I am like why act like im going to do something I lost interest in. I realized that i have no idea what I want to do with the code I am learning and honestly struggle with almost everything besides simple code lol so I went with electronics instead lmao but I am wanting to learn c# with unity and probably make a simple 2 d game to help me understand programming better and hopefully figure out more stuff with javascript if I decide to get back into it :)
alpox
@alpox
Nov 09 2018 07:32
@JLuboff I am just waiting for the day that IE gets kicked fully. That awful thing should cease to exist
Victor Popescu
@VicPopescu
Nov 09 2018 07:35
@alpox I don't agree. How will you download chrome if IE cease to exist???
alpox
@alpox
Nov 09 2018 07:35
@VicPopescu Edge as default browser
Victor Popescu
@VicPopescu
Nov 09 2018 07:36
@alpox so EDGE should be the new chrome gate
alpox
@alpox
Nov 09 2018 07:36
Yep :D
Edge luckily has much less troubles than IE
Victor Popescu
@VicPopescu
Nov 09 2018 07:37
IE won't cease to exist ever, even versions under IE 9, sadly, because it's very popular in some companies....
maybe 20 years from now
alpox
@alpox
Nov 09 2018 07:37
Maybe yes, but we can just stop to support it fully and they will be forced to move :D
Victor Popescu
@VicPopescu
Nov 09 2018 07:37
if there are few people still using it, there will be clients asking for supporting it...
Wasiu Idowu
@Hoxtygen
Nov 09 2018 09:09
Hi guys
Dhaval Vira
@dhavalveera
Nov 09 2018 09:10
hi
Wasiu Idowu
@Hoxtygen
Nov 09 2018 09:11
I've got two codes that does the same thing, one with setTimeout() and the second without, would like to know the benefits of having setTimeout()
// with setTimeout()
 function createPost(post) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      posts.push(post);
      const error = false;
      if (!error) {
        resolve();
      } else {
        reject(new Error('Something went completely wrong'));
      }
    }, 2000);
  });
}

//  Without setTimeout
/* function makePost(post) {
  return new Promise((resolve, reject) => {
    posts.push(post);
    const error = false;
    if (!error) {
      resolve();
    } else {
      reject(new Error('something went wrong'));
    }
  });
}
both function does the same and both works, just trying to know if setTimeout adds anything
Ghost
@ghost~5928d90bd73408ce4f629b9e
Nov 09 2018 09:25
Some questions @Hoxtygen
Why you need a setTimeout in a promise?
Do you really need to wrapped an array .push with a promise? is that database method ?? or just really pushing stuff in array
Wasiu Idowu
@Hoxtygen
Nov 09 2018 09:27
@2HexGFX_twitter just pushing stuff to an array.. This isn't some real world project , just practicing promise
Ghost
@ghost~5928d90bd73408ce4f629b9e
Nov 09 2018 09:33
I see, well the setTimeOut is actually just use to simulate an async call an example is when you make a request to your database to retrieve user posts
Jason Luboff
@JLuboff
Nov 09 2018 16:06
Morning :wave:
Christopher McCormack
@cmccormack
Nov 09 2018 16:14
@JLuboff yo gm
Jason Luboff
@JLuboff
Nov 09 2018 16:15
What up
Christopher McCormack
@cmccormack
Nov 09 2018 16:21
@JLuboff nm you?
Do you know an JS tools for creating sessions between backends?
Jason Luboff
@JLuboff
Nov 09 2018 16:22
Currently trying to look through some of your projects to figure out how to break out some of my components from a single file to seperate files...my single file is getting way too big and difficult to keep track of
Christopher McCormack
@cmccormack
Nov 09 2018 16:22
can pop it out, export it, and import where needed
Jason Luboff
@JLuboff
Nov 09 2018 16:22
Mmm...no. What exactly are you trying to establish?
Christopher McCormack
@cmccormack
Nov 09 2018 16:22
you can also use an index.js to import a bunch in one line if you want, I have done that in the past
@JLuboff I have a need to track session cookies from a remote server from my backend app, so a user can attempt to auth through my app, I send the creds to the remote server for authentication, and the remote server will send back a response including a session cookie in the header
I'd rather not write that session cookie logic if there's already something I can use that maintains the session between two backend apps
Lia-Sue-Kim
@Lia-Sue-Kim
Nov 09 2018 16:25
if someone says by budget for a restaurant wwebsite is 750 USD
does it mean that they can spend that amount of money for the site?
I can do it for 100 or 200
and she is asking me 'what is my budget'
Jason Luboff
@JLuboff
Nov 09 2018 16:29
@cmccormack Mmm...ya not sure on that one.
@cmccormack Also.. I notice you typically have your JSX files PascalCase, any reason?
Christopher McCormack
@cmccormack
Nov 09 2018 16:30
Linter
Jason Luboff
@JLuboff
Nov 09 2018 16:30
Ah. Cool
@cmccormack So should every component I break out be its own class?
Christopher McCormack
@cmccormack
Nov 09 2018 16:31
or function
up to you
if it needs state, class is preferred as the new hooks API is still in alpha
Jason Luboff
@JLuboff
Nov 09 2018 16:33
@cmccormack And you use views as your entry folder for all components? (at least in your nightlife app)
Christopher McCormack
@cmccormack
Nov 09 2018 16:34
@JLuboff yeah but I just made that up
I fool around each project to see what might work better
ignore that I put my context in views
I know it doesn't belong :)
that should go in a controllers folder probably
Jason Luboff
@JLuboff
Nov 09 2018 16:36
Ya.. thats okay I'm not getting that technical lol
think I'll just stick with components haha
Christopher McCormack
@cmccormack
Nov 09 2018 16:38
I mean, it makes sense... :)
Jason Luboff
@JLuboff
Nov 09 2018 16:38
@cmccormack Also.. I see that you import React in each JSX file...is that required? Like.. I can have lets say body-parser in my entry file for node (app.js/server.js) and then not have to reference it in my routes file but I'm able to use it
oh actually I lied on the body-parser one but I know theres modules I use without having to bring them in
Christopher McCormack
@cmccormack
Nov 09 2018 16:40
importing it the first time will attach it to the global object I believe, so every import should reference that same object, but I think you still need the import
I've not had great luck with how it's supposed to work though so I usually pass my object, like my express app
Jason Luboff
@JLuboff
Nov 09 2018 16:42
Got it
Joshua Arnett
@josha5
Nov 09 2018 16:58
@JLuboff Hey Jason have you used the formidable npm package before?
Jason Luboff
@JLuboff
Nov 09 2018 18:29
@josha5 I have not, sorry
Brad
@bradtaniguchi
Nov 09 2018 18:51
@JLuboff Yo I can see the fire from my house south of LA, looks bad haha
Jason Luboff
@JLuboff
Nov 09 2018 18:53
@bradtaniguchi Careful out there. We just have all the smoke here
@bradtaniguchi I read a while ago that all of Malibu is being evacuated...
Brad
@bradtaniguchi
Nov 09 2018 18:59
Oh damn yea
Jason Luboff
@JLuboff
Nov 09 2018 19:06
I'm not even sure how big it is...but it started in Newbury/Camarillo and has moved all the way to Malibu/Calabases (or however you spell that)
Brad
@bradtaniguchi
Nov 09 2018 19:10
I just read is spread super fast, an entire town is destroyed, got to 31 square miles in less than 12 hours
Jason Luboff
@JLuboff
Nov 09 2018 19:11
Thats crazy...
While I'm glad its not heading my way...I feel awful for the people going through this. I went through the Thomas fire and that was just awful
Smoke for weeks
Brad
@bradtaniguchi
Nov 09 2018 19:13
Yea I can imagine, the last fire I ended up passing thru just a day or so after they got it handled. Seems like this time we will be going around or thru the aftermath
Jason Luboff
@JLuboff
Nov 09 2018 19:15
You heading out of town?
Brad
@bradtaniguchi
Nov 09 2018 19:21
Yes this weekend
Jason Luboff
@JLuboff
Nov 09 2018 19:21
North or South? (or East or WEst)
Brad
@bradtaniguchi
Nov 09 2018 19:28
North-west, going to Solvang
Jason Luboff
@JLuboff
Nov 09 2018 19:29
Ah. Good ol' Solvang
You'll be passing by me on your way there...if you're taking the 101
Brad
@bradtaniguchi
Nov 09 2018 19:32
Yea Idk what the state of that freeway will look like tomorrow morning tho
Jason Luboff
@JLuboff
Nov 09 2018 19:32
Still closed do you know?
Brad
@bradtaniguchi
Nov 09 2018 19:48
I checked on google maps, buncha red alerts, not sure about full closure but sure looks like it
Brad
@bradtaniguchi
Nov 09 2018 19:54
rant time, I've found this POS code:
// get item from items, based upon UNIQUE code
const itemObj = items.filter((item) => item.code === code);
const item = itemObj[0];
Jason Luboff
@JLuboff
Nov 09 2018 20:15
is code an outside variable..?
alpox
@alpox
Nov 09 2018 20:32
@bradtaniguchi looks like const item = items.find(item => item.code === code);
alpox
@alpox
Nov 09 2018 20:37
But what about hashtables
Brad
@bradtaniguchi
Nov 09 2018 20:40
@alpox whatabout em (the original programmer doesn't know about find, of course they wont use a hashtable)
alpox
@alpox
Nov 09 2018 20:42
Hahah :D I guess you're right
Pagnito
@Pagnito
Nov 09 2018 21:00
hey im having some trouble with an async operation on api call, if anyone can help me.
Im trying to return a users gifsa number which is unpredictable, so I dont know how to resolve the promise
    app.get('/api/getMyGifs', (req, res)=>{
    let responseArr = [];
    fs.readdir(pathTo, (err,gifs)=>{
      let promise = new Promise((resolve, reject)=>{
        let myGifs = gifs.map((gif,ind)=>{
          fs.readFile(`${pathTo}/${gif}`,'utf-8', (err,data)=>{
            if (err) {
              throw err;
            } else {
              let gifObj = JSON.parse(data);
              if(gifObj.user){
                if(gifObj.user.fbId===req.user.fbId){
                  responseArr.push(gifObj)
                }
              }
            }
          })
        })
        //how to resolve this?///
      })
      promise.then(()=>{
        res.json(responseArr);
      })
    })
  })
atm im thinking of adding a field of "numberOfGifs" to user model schema, so everytime they upload a number is incremented and i can send that number everytime a request for gifs is made
alpox
@alpox
Nov 09 2018 21:05
@Pagnito This takes a whole lot of refactoring work to make it work nicely with promises. Please take a look at https://nodejs.org/dist/latest-v8.x/docs/api/util.html#util_util_promisify_original and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all
Those two utils can help you refactor this code
Pagnito
@Pagnito
Nov 09 2018 21:08
@alpox thnx
Simon Cordova
@gbsimon87
Nov 09 2018 22:52
Hello!
Lia-Sue-Kim
@Lia-Sue-Kim
Nov 09 2018 22:57
Hey
if you want to test or debug Javascript
is console the only place where you can do that?
I mean can you count on console as a debug tool
as it is web dev tool
Jason Luboff
@JLuboff
Nov 09 2018 23:09
@gbsimon87 Yo
Brad
@bradtaniguchi
Nov 09 2018 23:20
@Lia-Sue-Kim no, there are a lot of editors with debuggers that connect to wherever your running your code (like nodejs) that allow you to use debuggers (either in chrome or in the editor) You just need to look into what you want todo and its prolly supported
Lia-Sue-Kim
@Lia-Sue-Kim
Nov 09 2018 23:21
@bradtaniguchi okay thank you Brad
I also have a question about freelancing
If you hae time?
Brad
@bradtaniguchi
Nov 09 2018 23:22
I don't do freelancing(no time, no experience) so I'm not the best person to ask
Lia-Sue-Kim
@Lia-Sue-Kim
Nov 09 2018 23:22
we are already talking to the customer
and I just don't get few phrases
in English
so it is a site about restaurant
The customer is from USA
I didn't really know what to answer when she asked me about my budget
So i said whatever you offer i can create your website in 15 days
Brad
@bradtaniguchi
Nov 09 2018 23:25
You said whatever they give you, you will create it in 15 days? what if they give you 1$?
I think they are asking how much do you want to get paid no?
Lia-Sue-Kim
@Lia-Sue-Kim
Nov 09 2018 23:25
lol
no she said the estimated cost is okay for her to pay
Jason Luboff
@JLuboff
Nov 09 2018 23:29
What happens if you don't deliver in the 15 days?
Lia-Sue-Kim
@Lia-Sue-Kim
Nov 09 2018 23:29
yes but I just don't get few phrases
such as upront
upfront payment for design
I don't know if someone messing with me or something
Jason Luboff
@JLuboff
Nov 09 2018 23:30
upfront means they pay you prior to starting the work. Generally you'd want part of the payment before starting to ensure they are going to pay you. If you do all the work and give it to them before they pay...they may not pay
Lia-Sue-Kim
@Lia-Sue-Kim
Nov 09 2018 23:31
ohh I see
so you have right to ask that?
got it
But what kind of information should I give her
Jason Luboff
@JLuboff
Nov 09 2018 23:31
You do, yes. And since you aren't physically meeting the person, I would highly advise that
Lia-Sue-Kim
@Lia-Sue-Kim
Nov 09 2018 23:31
she asked for full name and address
Jason Luboff
@JLuboff
Nov 09 2018 23:31
Does she know that you are not in the US?
Lia-Sue-Kim
@Lia-Sue-Kim
Nov 09 2018 23:32
Also how payment
yes She know i'm in turkey
knows*
and she says it's okay
Jason Luboff
@JLuboff
Nov 09 2018 23:33
Than I'm not sure why she would want your address.. I would assume she would pay through some sort of online payment method like Paypal
Lia-Sue-Kim
@Lia-Sue-Kim
Nov 09 2018 23:38
not paypal but she said by chek or something
Jason Luboff
@JLuboff
Nov 09 2018 23:38
I would not do a check.
Lia-Sue-Kim
@Lia-Sue-Kim
Nov 09 2018 23:39
why
Jason Luboff
@JLuboff
Nov 09 2018 23:41
A multitude of reasons. This is the most likely way for you to not get your money. You need a secure method. A check being mailed to you from another country is just not a good idea
Lia-Sue-Kim
@Lia-Sue-Kim
Nov 09 2018 23:44
Okay thank you
Lia-Sue-Kim
@Lia-Sue-Kim
Nov 09 2018 23:57
@JLuboff She said that she wants me to update the site from time to time as I will buy her domain and host it with the hosting company i use myself
Jason Luboff
@JLuboff
Nov 09 2018 23:57
Ok.. where is the hosting company located?
Lia-Sue-Kim
@Lia-Sue-Kim
Nov 09 2018 23:58
It's partly in France and partly in Turkey
But daddygo is in the USA
I can use that if she sends me texts the logo and other pictures for the website
Jason Luboff
@JLuboff
Nov 09 2018 23:58
If this is a US based resturant, than the website should be hosted in the US..
Lia-Sue-Kim
@Lia-Sue-Kim
Nov 09 2018 23:59
Why?
Can't I do it from here and choose a company from the USA?
Jason Luboff
@JLuboff
Nov 09 2018 23:59
Becuase of latency.....