These are chat archives for FreeCodeCamp/HelpJavaScript

15th
Jan 2019
Jason Luboff
@JLuboff
Jan 15 00:34
Stupid Firefox doesn't support break-before
Brad
@bradtaniguchi
Jan 15 00:40
@JLuboff First time I've heard Firefox not supporting something, whereas others do
even IE supports it XD
Jason Luboff
@JLuboff
Jan 15 00:43
Ya...I don't really get why
No wonder I couldn't get it to work before :(
Brad
@bradtaniguchi
Jan 15 00:46
This is why CSS is the evil
Jason Luboff
@JLuboff
Jan 15 00:46
Yes...I hate it
Jose Pagan
@josepagan
Jan 15 01:21
I am trying to get my head around Promises, is not a good analogy to consider the Promise a sort of “switch” with three states, but we dont use it we set it up
Brad
@bradtaniguchi
Jan 15 01:27
@josepagan Idk if that's the best appraoch, since a "switch" is already a thing (switch-case statements). I think promises are best thought of as a straight solution, I never thought about comparing it to another idea. Async code is hard to understand :/
and they are a straight solution to the alternative, which is callback-hell
You can think of promises (then, catch) as "callbacks", but with different syntax were you chain them, rather than nest them. (that's the whole point of promises, they don't add "new" features, just cleaner syntax)
Riadh
@KWFE
Jan 15 03:18
HI
Brad
@bradtaniguchi
Jan 15 05:15
hello
Jose Pagan
@josepagan
Jan 15 10:48
I guys a couple of months ago I remember a site with “video” tutorials , but the video was not a video but an actual editor with its interpreter and all
I wonder what was that site
Francois Beyers
@Blusoup
Jan 15 10:54

Hi, what would be the best way to write the following in JavaScript?

var buttons = [".btn-success"];
    $("body").on("mousedown touchstart", buttons.join(), function (el) {
        //console.log("button clicked");
    })

Thank you

tundeiness
@tundeiness
Jan 15 12:02
@Blusoup you don't want to use bootstrap to achieve this?
codingfreak2018
@codingfreak2018
Jan 15 13:20
Hello guys
I do have a problem. My console log says that "Update" i not defined. I understand the error, but i don't know where in my code, that something is types wrong
const canvas = document.getElementById('tetris');

const context = canvas.getContext('2d');

context.fillStyle = '#000';
context.fillRect(0, 0, canvas.width, canvas.height);
context.scale(20, 20);

const matrix = [

    [0, 0, 0],
    [1, 1, 1],
    [0, 1, 0],

];
// My functions goes here
function draw() {
    drawMatrix(player.matrix, player.pos);

}

function drawMatrix(matrix, offset) {
    matrix.forEach((row, y) => {
        row.forEach((value, x) => {

            if (value !== 0) {
                context.fillStyle = 'red';
                context.fillRect(
                    x + offset.x,
                    y + offset.y,
                    1, 1);
            }
        });

    });
    let lastime = 0;


    function update(time = 0) {
        const deltaTime = time - lastTime;
        lasTime = time;
        draw();
        requestAnimationFrame(update);
    }

    const player = {
        pos: { x: 5, y: 5 },
        matrix: matrix,
    }


}


update();
Kaz Baig
@kbaig
Jan 15 13:22
@codingfreak2018 update is defined within drawMatrix but you are calling it outside drawMatrix
codingfreak2018
@codingfreak2018
Jan 15 13:24
@kbaig i can't see that it is defined inside drawMatrix?
Blauelf
@Blauelf
Jan 15 13:33
It's in the same scope as player and lastime. BTW, lastime is not same as lasTime. Case-sensitive.
Atsushi Toda
@broadsinatlanta
Jan 15 15:09
Hi everyone,
Can someone shed some light on why FCC doesn't seem to accept my solution for Smallest Common Multiple
link to code - It doesn't seem to be able to accept my sort in the problem although working on other environments
Thanks for help in advance - you guys have always been helpful!
Tom
@moT01
Jan 15 15:30
@broadsinatlanta there's a time limit
Atsushi Toda
@broadsinatlanta
Jan 15 15:31
@moT01 I wouldn't think the sorting function adds too much onto it though - where do you think the bottleneck is?
Tom
@moT01
Jan 15 15:36
not sure
19930210
@19930210
Jan 15 15:41
image.png
Hello, everyone. How can I get the property values in the JSON array? Can I be guided to solve the problem?
Christopher McCormack
@cmccormack
Jan 15 15:43
@19930210 first you target the index you want (integer value, if your array has 4 items the indexes would be 0-3), so you need some way to iterate
then when you have the index you can access the object at that index (i.e., contacts[1] is an object with a property firstName with a value Harry)
Blauelf
@Blauelf
Jan 15 15:45
@broadsinatlanta I'd change return (x * y) / GCD(x, y); to return x / GCD(x, y) * y; for numerical reasons (x is always divisible by GCD(x, y), so this division will produce an integer again, avoiding rounding errors for slightly larger numbers). But really, does not look like it should cause timeout issues.
Christopher McCormack
@cmccormack
Jan 15 15:47
@19930210 hint: a for loop is excellent for iterating a known number of times
19930210
@19930210
Jan 15 15:49
@cmccormack
This is a great tip! I didn't expect to use "for" to execute this program, thank you I will try to see again!
Atsushi Toda
@broadsinatlanta
Jan 15 15:50
@Blauelf Yup makes sense!
And I agree to the latter point - is it worth reporting as a bug of sorts?
Blauelf
@Blauelf
Jan 15 15:54
Good question. I have avoided the site ever since the relaunch, as my experience was mostly random (worse to debug, some tests broken, other fixed by reload, parts of the page not responding or crashing if "stripe" payment provider could not be reached, in a completely payment unrelated page)
Christopher McCormack
@cmccormack
Jan 15 15:55
@19930210 you can never assume you know how long the actual test array might be so it's always better to just get the length of the array and iterate over the length
Francois Beyers
@Blusoup
Jan 15 16:03
is there a way to combine mousedown and touchstart in a plain Javascript event function?
Christopher McCormack
@cmccormack
Jan 15 16:04
You can attach multiple events to an element using addEventListener
Kaz Baig
@kbaig
Jan 15 16:04
You could create a function that adds the same listener to both events
Francois Beyers
@Blusoup
Jan 15 16:04
@kbaig how would I do that?
@kbaig sorry to ask, its the end of the day and I can't think straight
Kaz Baig
@kbaig
Jan 15 16:06
const func = () => {};

const addListenerToMousedownAndTouchstart = () => {
  window.addEventListener('mousedown', func);
  window.addEventListener('touchstart', func);
}
Francois Beyers
@Blusoup
Jan 15 16:07
@kbaig awesome thank you! 🙏🏼
Jason Luboff
@JLuboff
Jan 15 16:09
Morning :wave:
Christopher McCormack
@cmccormack
Jan 15 16:09
@JLuboff heya
Kaz Baig
@kbaig
Jan 15 16:09
Howdy
Jason Luboff
@JLuboff
Jan 15 16:10
Whats going on guys?
Kaz Baig
@kbaig
Jan 15 16:10
Kingdom Hearts aka lack of productivity
Jason Luboff
@JLuboff
Jan 15 16:11
Good deal
Christopher McCormack
@cmccormack
Jan 15 16:11
@kbaig man I've been feeling that way a lot too. maybe SAD?
Riadh
@KWFE
Jan 15 16:12
Hi
Jason Luboff
@JLuboff
Jan 15 16:12
Yup... good ol' SAD
Kaz Baig
@kbaig
Jan 15 16:12
Definitely maybe. Haven't seen the sun in a while
Jason Luboff
@JLuboff
Jan 15 16:12
Hello
Kaz Baig
@kbaig
Jan 15 16:12
What up @KWFE
Jason Luboff
@JLuboff
Jan 15 16:12
I saw the sun yesterday
Kaz Baig
@kbaig
Jan 15 16:12
California -_- I'll get to see Cali sun next month hopefully
Christopher McCormack
@cmccormack
Jan 15 16:12
it's snowy AND rainy at the same time here right now, I didn't even know that was possible
Jason Luboff
@JLuboff
Jan 15 16:13
Eh... it was raining yesterday and is supposed to rain pretty good the next couple days including today
@kbaig Where in cali?
Kaz Baig
@kbaig
Jan 15 16:13
SF. It's our 'honeymoon'
Jason Luboff
@JLuboff
Jan 15 16:14
Good deal. How long you going for?
Christopher McCormack
@cmccormack
Jan 15 16:14
@kbaig i'm guessing the quotes mean it's much later than expected?
Kaz Baig
@kbaig
Jan 15 16:14
Yeah we got married in Aug haha
Christopher McCormack
@cmccormack
Jan 15 16:14
haha well congrats!
Kaz Baig
@kbaig
Jan 15 16:14
A week! And then a couple days in houston with family
Thanks!
Feb is turning out to be quite a month
Atsushi Toda
@broadsinatlanta
Jan 15 16:15
@Blauelf I see, thanks for the help!
Jason Luboff
@JLuboff
Jan 15 16:15
Wait... you're expecting sun in SF in Feb? I mean..I guess there could be sun...but it won't be warm
Kaz Baig
@kbaig
Jan 15 16:15
I'm just expecting it to be better than Chicago okay
Jason Luboff
@JLuboff
Jan 15 16:15
Fair enough
Christopher McCormack
@cmccormack
Jan 15 16:16
I feel like most places outside Siberia are nicer than Chicago in the winter
Kaz Baig
@kbaig
Jan 15 16:16
heh true
It's my first official one. Not a fan
Christopher McCormack
@cmccormack
Jan 15 16:18
oh thought you had been there longer
Kaz Baig
@kbaig
Jan 15 16:18
I was in champaign for a year but coming here every other weekend
Christopher McCormack
@cmccormack
Jan 15 16:20
with a name like that it must be fancy!
Kaz Baig
@kbaig
Jan 15 16:20
It's exceptionally unfancy
Christopher McCormack
@cmccormack
Jan 15 16:20
I've found most places that are named fancy aren't lol
Kaz Baig
@kbaig
Jan 15 16:20
Home of U of I and not much else
Roger Ebert actually
Christopher McCormack
@cmccormack
Jan 15 16:22
hey not bad!
@JLuboff what you up to today? you were quiet yesterday so I assume you are super busy
Kaz Baig
@kbaig
Jan 15 16:29
I should really get back to my personal site...but I'm feeling stuck on how to express my content
Riadh
@KWFE
Jan 15 16:32
hru guys?
Kaz Baig
@kbaig
Jan 15 16:36
good man how are you
Christopher McCormack
@cmccormack
Jan 15 16:36
@KWFE hi doing well, you?
@kbaig maybe check out dribbble?
Kaz Baig
@kbaig
Jan 15 16:37
No I mean written content
Riadh
@KWFE
Jan 15 16:40
doing well back to learn coding again
19930210
@19930210
Jan 15 16:40
@cmccormack I have untied the answer to that question, thank you for your guidance!
Christopher McCormack
@cmccormack
Jan 15 16:41
@19930210 very nice!
Riadh
@KWFE
Jan 15 17:04
hey any new courses to learn css and js
Christopher McCormack
@cmccormack
Jan 15 17:19
@KWFE FCC updated its cirriculum a few months ago, adding a bunch of new content, did you see that?
Jason Luboff
@JLuboff
Jan 15 17:24
@cmccormack Just got out of a meeting.. going to continue working on my E2E testing and finishing up some other stuff with that project...what about yourself?
Christopher McCormack
@cmccormack
Jan 15 17:27
Jumping all over the place, working on some site-to-site vpn stuff, then some coding hopefully
can't wait to pick your brain on testing later though :)
alpox
@alpox
Jan 15 17:30
Anyone experience with Docker / Docker Compose / Gitlab CI ?
Jason Luboff
@JLuboff
Jan 15 17:36
@cmccormack My testing knowledge is still limited...but @alpox and @bradtaniguchi are both good resources for extra help!
Jason Luboff
@JLuboff
Jan 15 17:49
@cmccormack E2E testing with testcafe is a lot of fun though
Christopher McCormack
@cmccormack
Jan 15 17:51
@JLuboff you should write a Medium article :)
Jason Luboff
@JLuboff
Jan 15 17:52
I started watching r/javascript....they hate medium lol
Kaz Baig
@kbaig
Jan 15 17:52
With a passion
Jason Luboff
@JLuboff
Jan 15 17:53
Haha ya they do
Aditya
@ezioda004
Jan 15 17:53
Oh yeah, write an article on bashing medium
On medium.com
Jason Luboff
@JLuboff
Jan 15 17:53
:joy:
Christopher McCormack
@cmccormack
Jan 15 17:53
why hate it?
Jason Luboff
@JLuboff
Jan 15 17:55
I think the paywall
And becoming too clickbait-y
Christopher McCormack
@cmccormack
Jan 15 17:56
I think it's worth paying for, beautiful interface, tons of content, and if you pay you can save articles to read for later offline ( good if you're somewhere with terrible signal like I am a few times a year )
Aditya
@ezioda004
Jan 15 17:56
Pff you can already save articles later to read, by not closing the tab
Christopher McCormack
@cmccormack
Jan 15 17:58
lol fair enough
Kaz Baig
@kbaig
Jan 15 17:58
The browser comes with an inbuilt shortcut for saving it for later
ctrl b
Christopher McCormack
@cmccormack
Jan 15 17:58
that's a bookmark
Kaz Baig
@kbaig
Jan 15 17:58
yeee
Christopher McCormack
@cmccormack
Jan 15 17:59
doesn't download data when you have no signal
Kaz Baig
@kbaig
Jan 15 17:59
oh is that what we're talking about
derp
Christopher McCormack
@cmccormack
Jan 15 17:59
it's even what I said :)
Kaz Baig
@kbaig
Jan 15 17:59
pff reading
Christopher McCormack
@cmccormack
Jan 15 17:59
haha
maybe you should pay me so you can read my comments offline :p
Jason Luboff
@JLuboff
Jan 15 17:59
Oh BURNNNNN
Christopher McCormack
@cmccormack
Jan 15 18:00
I dunno, I find it to be worth the $5 a month
Jason Luboff
@JLuboff
Jan 15 18:00
Not all of us have $5 to throw around all willy-nilly
Christopher McCormack
@cmccormack
Jan 15 18:00
even if just to support something I like
Go sell snow cones on the side of the road!
or lattes
kids should sell coffee, I bet they'd make a lot more than lemonade
Jason Luboff
@JLuboff
Jan 15 18:02
I'd rather a sour lemonade than a burnt coffee :)
alpox
@alpox
Jan 15 18:02
@JLuboff I started to dislike medium because too many people with too little knowledge write articles there which pulled the reliability and worth of the platform down a lot
Jason Luboff
@JLuboff
Jan 15 18:03
@alpox Thats fair. There have definitely been some low quality content that I've seen. Or just rehash of a tutorial that really doesn't offer anything different
Christopher McCormack
@cmccormack
Jan 15 18:03
I think my tongue only likes burnt coffee - I have one of those top rated drip coffee makers and I don't like the flavor nearly as much as my ancient Mr. Coffee
Low quality content on Medium is easy to identify though
Jason Luboff
@JLuboff
Jan 15 18:04
I have a Mr.Coffee K-cup brewer...works pretty well
Aditya
@ezioda004
Jan 15 18:04
fcc publish quality articles most of the time, worth subscribing ;)
Christopher McCormack
@cmccormack
Jan 15 18:04
low claps, simple title that's been done 1000 times, bad grammar in first paragraph, short length, etc..
yeah FCC articles and Hackernoon are some of my favorites on Medium
I imagine both are vetted
Jason Luboff
@JLuboff
Jan 15 18:08
I read a Hackernoon article the other day, was decent from what I remember
Christopher McCormack
@cmccormack
Jan 15 18:09
you're going to see a ton of low quality content for simple concepts like How JavaScript array methods work or whatever as that's low hanging fruit for new authors
alpox
@alpox
Jan 15 18:11
I was asked some time to write articles about javascript... I strongly believe that would just add to the 1 million mediocre javascript basics articles out there... so nope :D
Christopher McCormack
@cmccormack
Jan 15 18:12
There are a few reasons to write - You want to practice, you want to help with a niche concept that isn't well covered, you're getting paid in some way
Brad
@bradtaniguchi
Jan 15 18:13
5$=cup of coffee
Aditya
@ezioda004
Jan 15 18:13
Get :clap: paid :clap: in :clap: claps :clap:
alpox
@alpox
Jan 15 18:14

@cmccormack

you're getting paid in some way

Valid

Christopher McCormack
@cmccormack
Jan 15 18:15
That can be directly or indirectly (exposure)
Brad
@bradtaniguchi
Jan 15 18:15
I think the pay wall can get around if you want to be evil (incognito browser :P), and having "a bunch of mediocre" content hasn't stopped me before. (Github repos, npm packages)
alpox
@alpox
Jan 15 18:17
@bradtaniguchi Do you have any gitlab-ci experience?
Brad
@bradtaniguchi
Jan 15 18:17
@alpox Only a tiny bit, I have more experience with CircleCi and travis, but then were talking about basic use-case stuff
alpox
@alpox
Jan 15 18:18
@bradtaniguchi Hmm too bad :D
Christopher McCormack
@cmccormack
Jan 15 18:18
@bradtaniguchi you have been voted off the island
alpox
@alpox
Jan 15 18:18
I'm trying to set up CD for a PHP app running through docker-compose
Brad
@bradtaniguchi
Jan 15 18:18
Aw man, time to go back to Angular island then :P
Christopher McCormack
@cmccormack
Jan 15 18:19
Watch out for the sharks
Jason Luboff
@JLuboff
Jan 15 18:29
@alpox PHP :(
Kudzu
@czhower
Jan 15 18:31
+1.. PHP for anything but basic scripting is a mess.
Markus Kiili
@Masd925
Jan 15 18:31
php...aargh
Brad
@bradtaniguchi
Jan 15 18:32
YES! I finally fixed the issues with my desktop computer, still have no idea how it got messed up, or exactly what was wrong but all is back to working >:D
Christopher McCormack
@cmccormack
Jan 15 18:33
@bradtaniguchi turn it off and back on again?
Brad
@bradtaniguchi
Jan 15 18:33
@cmccormack I re-installed a package. which uses the package that wasn't working and it worked so yes :D
Christopher McCormack
@cmccormack
Jan 15 18:34
@bradtaniguchi that's been like a week hasn't it?
Brad
@bradtaniguchi
Jan 15 18:34
@cmccormack Yea XD, I only tried to fix it on and off, been on my laptop, and it wasn't critical (just some QT apps were not working)
Kudzu
@czhower
Jan 15 18:36
If Windows, dont install 1809... nothing but troubles on the 2 machines I updated.
Jason Luboff
@JLuboff
Jan 15 18:37
Still on 1803 here
Kudzu
@czhower
Jan 15 18:38
stay there :)
Jason Luboff
@JLuboff
Jan 15 18:39
So far...all the new computers we have recieved still have 1803 luckily. Going to suck when they start coming with 1809 as I'll have to redo ADK on our imaging server ugh
alpox
@alpox
Jan 15 18:59
@JLuboff @Masd925 @bradtaniguchi Lets kill PHP! I hate it too! :D
Brad
@bradtaniguchi
Jan 15 18:59
I never said I hated PHP :(
alpox
@alpox
Jan 15 18:59
What a bad thing that my company locked in to Symfony on backend :(
Jason Luboff
@JLuboff
Jan 15 18:59
@bradtaniguchi But you should!
Brad
@bradtaniguchi
Jan 15 19:00
All yall trying to turn me to the dark side, the side that feels hate :P
alpox
@alpox
Jan 15 19:00
I dont really feel hate... just a stroong dislike :D
Brad
@bradtaniguchi
Jan 15 19:15
Lol I'm scrolling thru twitter and see an article on animal hibernation from NatGeo... and right below it is an article on using Hibernate for Java XD
Jason Luboff
@JLuboff
Jan 15 19:18
I'm looking at old VB code...
Brad
@bradtaniguchi
Jan 15 19:50
@JLuboff Are your eyes bleeding?
So we got a job for a client that uses windows stuff, oh boy
alpox
@alpox
Jan 15 20:06
My eyes were bleeding when I did some months ago...
I just got a new laptop and installed arch linux... byebye creep windows
Brad
@bradtaniguchi
Jan 15 20:08
@alpox :+1: for arch
Jason Luboff
@JLuboff
Jan 15 20:13
@bradtaniguchi Yes...yes they are.. I haven't finished... but..I forgot that stupid debugger won't work if theres any errors in compiling even if its an error that won't affect the app
So here I am trying to use breakpoints and they aren't working
Jason Luboff
@JLuboff
Jan 15 22:21
Sweet... finally found a useful need for a class constructor
Christopher McCormack
@cmccormack
Jan 15 22:24
Even with class properties or whatever they're called?
Brad
@bradtaniguchi
Jan 15 22:25

Dependency Injection

Jason Luboff
@JLuboff
Jan 15 22:25
nah... just a constructor lol Using it to create my form element selectors for different cases
Brad
@bradtaniguchi
Jan 15 22:25
oh :(
Jason Luboff
@JLuboff
Jan 15 22:26
Sorry bud
Riadh
@KWFE
Jan 15 22:59
@cmccormack would u check your pm
Brad
@bradtaniguchi
Jan 15 23:30
It's time... to bring the front-end code serverside :sunglasses: