These are chat archives for FreeCodeCamp/HelpJavaScript

25th
Apr 2018
Brittany Rutherford
@brittanyrutherford
Apr 25 2018 00:02
oh, my stupid mistake
it's not handlebars, it's my handlebars helper
i am using array.find .. but IE's so perfect it was showing it's something related to handlebars itself
weird that babel polyfill didn't work with it :/
anthonygallina1
@anthonygallina1
Apr 25 2018 00:15
:sun_with_face:
IE's kinda opinionated
i built a whole site 2 years ago. Flex I think. loved it!
But forgot to browser test.
And IE chewed on it bad.
jess
@jessmear
Apr 25 2018 06:23
Anyone around who is familiar with uglify-js?
Daniel Simeonov
@dbsimeonov
Apr 25 2018 07:15
guys is there any reason why I can not do eventlistener on nodeList ?
Markus Kiili
@Masd925
Apr 25 2018 07:16
@dbsimeonov It is an array-like object with dom nodes as elements.
Daniel Simeonov
@dbsimeonov
Apr 25 2018 07:17
So I should be able to do it ?
It gives me ... not a function(and when I change the element its working)
Markus Kiili
@Masd925
Apr 25 2018 07:18
@dbsimeonov You need to iterate or access the nodeList and put event listener on a node .
Daniel Simeonov
@dbsimeonov
Apr 25 2018 07:19
so I need to put my event listener inside a forLoop for example?
Markus Kiili
@Masd925
Apr 25 2018 07:19
@dbsimeonov Yes.
Daniel Simeonov
@dbsimeonov
Apr 25 2018 07:19
Thanks!
Markus Kiili
@Masd925
Apr 25 2018 07:20
@dbsimeonov Nodelist's have a built-in forEach method for such use.
Daniel Simeonov
@dbsimeonov
Apr 25 2018 07:20
Yes thats what I just started googleing :D
Markus Kiili
@Masd925
Apr 25 2018 07:21
@dbsimeonov Some methods return a HTMLCollection instead, and it doesn't have built-in forEach.
But all array-like objects are special so you can make array methods work on them too.
Daniel Simeonov
@dbsimeonov
Apr 25 2018 07:22
let removeClasses = () => {

        numbers.forEach(function(el){
            el.addEventListener('click', function(){
                console.log('this');
            });
        });
    }
    removeClasses();
Markus Kiili
@Masd925
Apr 25 2018 07:23
@dbsimeonov Are you trying to log "this" or this?
Daniel Simeonov
@dbsimeonov
Apr 25 2018 07:23
@Masd925 I noticed that but still didn't work
I think I should have another event listener to trigger this one ?
Markus Kiili
@Masd925
Apr 25 2018 07:24
@dbsimeonov How are you creating numbers?
Daniel Simeonov
@dbsimeonov
Apr 25 2018 07:24
let numbers = document.querySelectorAll('.active-number');
Markus Kiili
@Masd925
Apr 25 2018 07:26
@dbsimeonov Are you running the script at the end of body or inside document ready or onload handler, so that the dom is ready before you run the script?
Daniel Simeonov
@dbsimeonov
Apr 25 2018 07:27
actually is onload.. I'm thinking that I can assign the main function to the html buttons?
Blauelf
@Blauelf
Apr 25 2018 11:52
Does removeClasses run? Does the inner function run (and for how many elements)? Is any of the callbacks triggered? You could log different lines from all of the three, and watch the console.
Jason Luboff
@JLuboff
Apr 25 2018 15:17
:wave:
Ken Haduch
@khaduch
Apr 25 2018 15:38
@JLuboff :wavy_dash: :wave: :wavy_dash:
Jason Luboff
@JLuboff
Apr 25 2018 15:38
@khaduch Good morning
Brad
@bradtaniguchi
Apr 25 2018 17:52
my morning starts now, muhaha
Jason Luboff
@JLuboff
Apr 25 2018 17:55
@bradtaniguchi ...it's like almost 11 AM
Brad
@bradtaniguchi
Apr 25 2018 17:55
Yes :sunglasses:
But then, I'll be here almost till 8:00pm :/
Jason Luboff
@JLuboff
Apr 25 2018 17:56
@bradtaniguchi What kind of work hours are those?
Brad
@bradtaniguchi
Apr 25 2018 17:57
Ones were you beat traffic XD
Jason Luboff
@JLuboff
Apr 25 2018 17:57
Move closer to work :P
Brad
@bradtaniguchi
Apr 25 2018 17:57
thats big $$$
Jason Luboff
@JLuboff
Apr 25 2018 17:58
Move jobs :P
Brad
@bradtaniguchi
Apr 25 2018 18:00
I mean i COULD work from home, but meh, haha
Jason Luboff
@JLuboff
Apr 25 2018 18:00
Luckily I'm only 10-15 minutes from work
And don't live in a big city (i.e LA)
I've done the commute for jobs though (35-60+ minute) they suck
Brad
@bradtaniguchi
Apr 25 2018 18:01
Yea I used to have to drive THROUGH LA at 8am, so my commute sucked
Jason Luboff
@JLuboff
Apr 25 2018 18:02
Ah... so you're out in that area
Brad
@bradtaniguchi
Apr 25 2018 18:02
I remember being able to take sidestreets to school :/ like 15 min drive so nice
Jason Luboff
@JLuboff
Apr 25 2018 18:04
I used to work in Woodland Hills... that commute wasn't terrible but if there was an accident it sucked. But luckily, I was coming from the north, so I didn't have to really go into LA..just the valley and I was pretty much at the enterance of the valley
Brad
@bradtaniguchi
Apr 25 2018 18:12
Oh yea, so your on the other side there. I come from the south, so its the 110 or side streets, no real options there
Jason Luboff
@JLuboff
Apr 25 2018 18:17
Ya, 101 for me
Brad
@bradtaniguchi
Apr 25 2018 18:18
lucky luck haha
Jason Luboff
@JLuboff
Apr 25 2018 18:19
:P
I guess I could take the 118 as well depending on where I'm going
Brad
@bradtaniguchi
Apr 25 2018 18:20
You got the options haha, I have the free way, or the street next to the freeway haha
Jason Luboff
@JLuboff
Apr 25 2018 18:23
Shitty... haha
Kaz Baig
@kbaig
Apr 25 2018 18:26
@JLuboff I have a 5 minute walk to work and I couldn't be happier about it
Well except for when it's cold - then I almost wish I lived far enough to get in a car
Jason Luboff
@JLuboff
Apr 25 2018 18:26
@kbaig That sounds really nice actually
Kaz Baig
@kbaig
Apr 25 2018 18:29
It just stopped being below 50F last week
Got snow the week before that :D
Jason Luboff
@JLuboff
Apr 25 2018 18:30
I'd still do it
Brad
@bradtaniguchi
Apr 25 2018 18:31
Damn, I wish I could do that. Actually get some exercise in my life :/
Jason Luboff
@JLuboff
Apr 25 2018 18:33
I get up at 6 am to take my dog for a mile walk (maybe quarter of it jogging)... than 3 days a week go to the gym during lunch...sometimes family walk in the evening... you just gotta do it!
Brad
@bradtaniguchi
Apr 25 2018 18:38
ayaya
Kaz Baig
@kbaig
Apr 25 2018 18:38
I just sit in front of my pride and joy desktop instead :smile:
Jason Luboff
@JLuboff
Apr 25 2018 18:41
I guess thats exercising your... hands?
Ugh...nothing like opening a brand new computer and it saying "Why did my PC restart?" :angry:
Brad
@bradtaniguchi
Apr 25 2018 18:43
always lock, then close. Never just close, funky stuff happens when you do that haha
Kaz Baig
@kbaig
Apr 25 2018 18:44
Just build one instead!
Unless it's a work laptop haha
Jason Luboff
@JLuboff
Apr 25 2018 18:45
It's not my personal laptop, it's a new laptop I have to setup
So it came from the factory this way
Brad
@bradtaniguchi
Apr 25 2018 19:19
Gosh I hate it when people name stuff super vague input-cardis the class for a specific icon on the bottom left of a card... and it has nothing todo with input wtf?
Jason Luboff
@JLuboff
Apr 25 2018 19:48
Lol
I try and be descriptive with my naming...buit..sometimes...I fail
Tiago Correia
@tiagocorreiaalmeida
Apr 25 2018 19:52
hello everyone
Jason Luboff
@JLuboff
Apr 25 2018 19:53
Yo
Tiago Correia
@tiagocorreiaalmeida
Apr 25 2018 19:53
@JLuboff so I think finally I found a package taht I would make love to
Jason Luboff
@JLuboff
Apr 25 2018 19:53
:joy:
Tiago Correia
@tiagocorreiaalmeida
Apr 25 2018 19:53
tell me something while using sql you have callbacks on node right?
Jason Luboff
@JLuboff
Apr 25 2018 19:53
I'm using promises, but ya essentially
Tiago Correia
@tiagocorreiaalmeida
Apr 25 2018 19:54
uh then you are lucky I was using mysql package and its based on callbacks
while watching a course that @forkerino pointed me I got introduced to a package that turns callbacks into promises, "promisify"
Jason Luboff
@JLuboff
Apr 25 2018 19:54
I've heard of it, but never looked into it
Tiago Correia
@tiagocorreiaalmeida
Apr 25 2018 19:55
also there's two funny packages that you should add to your wallet
is-odd and is-even :D
Jason Luboff
@JLuboff
Apr 25 2018 19:55
Just FYI.. the package I'm using is mssql https://www.npmjs.com/package/mssql but I think it only works with Microsoft SQL. But you can do either callbacks, promises, or async/await
Holy shit.. 3 million downloads for the week for is-odd??? That suchs a simple function that you can make yourself lol
Tiago Correia
@tiagocorreiaalmeida
Apr 25 2018 19:57
now imagine
people can't even place a !
behind one of the packages
so lets have both
:D
Jason Luboff
@JLuboff
Apr 25 2018 19:57
:joy:
Kaz Baig
@kbaig
Apr 25 2018 20:00
@JLuboff pretty sure the following are the same char counts too
import { isOdd } from 'is-odd';

const isOdd = n => n % 2 === 1;
Jason Luboff
@JLuboff
Apr 25 2018 20:02

@kbaig You could even shorten that

const isOdd = n => n % 2 > 0;

Although..not as readable I guess

Kaz Baig
@kbaig
Apr 25 2018 20:07
same or less, let's say
to implement yourself
Jason Luboff
@JLuboff
Apr 25 2018 20:07
Yup
Brad
@bradtaniguchi
Apr 25 2018 20:16
Man those kinds of things piss me off. Like yo, what ARE you programing if you need to download this sorta stuff :/
also more packages == more security risks
Jason Luboff
@JLuboff
Apr 25 2018 20:16
I really don't get why so many people use it haha
Brad
@bradtaniguchi
Apr 25 2018 20:20
lazyness prolly
Gulsvi
@gulsvi
Apr 25 2018 20:48
Another big-o question :) again this week
Is 302^N considered O(2^N)?
or, would you actually use O(302^N)?
Tiago Correia
@tiagocorreiaalmeida
Apr 25 2018 20:50
@JLuboff https://www.npmjs.com/package/micromatch when you are really lazy
Gulsvi
@gulsvi
Apr 25 2018 20:50
I saw that something like N^8 would be considered O(N^8), but 12N would simply be O(N) instead of O(12N)... so a little confused on what magnitude to add if any
Tiago Correia
@tiagocorreiaalmeida
Apr 25 2018 20:51
400 dependencies
well that's something
Jason Luboff
@JLuboff
Apr 25 2018 20:52
@tiagocorreiaalmeida I'm too lazy (hah!) to read through the docs..but basically regex .test?
Tiago Correia
@tiagocorreiaalmeida
Apr 25 2018 20:52
yeah close to that I would say
Jason Luboff
@JLuboff
Apr 25 2018 20:53
but with more options I guess?
Tiago Correia
@tiagocorreiaalmeida
Apr 25 2018 20:53
in this case would be regex.match
what options tough?:D
Jason Luboff
@JLuboff
Apr 25 2018 20:55
I dunno. I didn't look that closely...but it looks like you can feed it arrays and such
Brad
@bradtaniguchi
Apr 25 2018 20:56
@gulsvi Off the top of my head I can't say for sure which is correct for 302^N
The main takeaway for such a thing is the growth for exponentials is basically useless for non-trivial amounts of data.
Tiago Correia
@tiagocorreiaalmeida
Apr 25 2018 20:57
@JLuboff
```
const values = ['foo', 'bar', 'baz'];
console.log(values.filter((ele)=> ele.match(/[(f*)|(*z)]/g)));
Jason Luboff
@JLuboff
Apr 25 2018 20:58
Ah.. ya you could use match that way :P
Brad
@bradtaniguchi
Apr 25 2018 20:58
Like if your sorting 100 records with an algorithm that runs in 2^N, were talking about like end of the universe level (just spitt balling) but regardless of if its 2 or 302, your basically screwed haha
Tiago Correia
@tiagocorreiaalmeida
Apr 25 2018 20:59
either way, @bradtaniguchi and @JLuboff codefights?
Brad
@bradtaniguchi
Apr 25 2018 20:59
@tiagocorreiaalmeida Nope sorry, too busy
Jason Luboff
@JLuboff
Apr 25 2018 20:59
mmm... I could try one 10 minute fight..but otherwise, ya pretty busy haha
Jason Luboff
@JLuboff
Apr 25 2018 21:02
Joined
Gulsvi
@gulsvi
Apr 25 2018 21:03
@bradtaniguchi Yeah, thanks, not sure if we are supposed to show *how* exponentially horrible the code is :)
Brad
@bradtaniguchi
Apr 25 2018 21:04
Yea I can't say for sure which answer is correct there tho, if you find out for sure let me know which would be the correct notiation :D (I feel likes its 302^N, since its more accurate but I could be wrong)
but yea regardless as long as you get the whatever^N in there haha
Michael Grienauer
@mgrienauer
Apr 25 2018 21:19
@khaduch hey ken, i took your suggestions and added them to my twitch streamer app, let me know what you think! https://mgrienauer.github.io/twitch_streamers/
Keggatron
@Keggatron
Apr 25 2018 22:54

@Keggatron
Hi guys, I'm having issues with a POST request from axios. I've set an action creator to call a POST reqeust which is supposd to send data to my backend API. However I'm unsure as to how I can retrieve the data. Using bodyparser and logging req.body is returning an undefined for me. I'm not sure what it is I'm not doing right but if someone could help me that would be great. Here is the code:

export const createOrder = (values) => async dispatch => {
  const request = await axios.post('/api/createorder', {
    addressOnOrder: values.addressOnOrder,
    nameOnOrder: values.nameOnOrder,
    orderType: values.order,
    paymentOption: values.paymentOption,
    orderPhoneNumber: values.phoneNumber,
    orderDetails: values.pizzas,
    orderPrice: values.orderPrice
  });

  console.log(values)

  // dispatch({ type: CREATE_ORDER, payload: request.data})
}

here's the api code:

app.post('/api/createorder', async (req, res) => {
    console.log('this is the order:',req.body)
    // const newOrder = await Order.create({
    //   nameOnOrder: req.body.nameOnOrder,
    //   addressOnOrder: req.body.addressOnOrder,
    //   orderType: req.body.order,
    //   orderPaymentType: req.body.paymentOption,
    //   orderPhoneNumber: req.body.phoneNumber,
    //   orderDetails: req.body.pizzas,
    //   orderPrice: req.body.orderPrice
    // });
    // await newOrder.save()
  });

the only way I seem to be able to see the data is by using an axios.get on the front end and using app.get on the backend then changing the console.log to req.query

Greg Duncan
@GregatGit
Apr 25 2018 23:32
@Keggatron after you POST shouldn't you be doing a GET with axios?