These are chat archives for FreeCodeCamp/HelpJavaScript

18th
Apr 2018
Diego Mayer
@Chrono79
Apr 18 2018 00:37
@JLuboff I'm no expert in that (and many other things) but what @bradtaniguchi said pretty much nailed it.
Eunice Park
@eunicode
Apr 18 2018 02:01

I'm having trouble understanding a for loop example in YDKJS, and for loops in general
https://github.com/getify/You-Dont-Know-JS/blob/master/scope%20%26%20closures/ch5.md#loops--closure

for (var i=1; i<=5; i++) { 
        setTimeout( function timer(){ 
                console.log( i ); 
        }, i*1000 ); 
}

if you run this code, you get "6" printed out 5 times, at one-second intervals.
Apparently i is 6. If i is 6, then shouldn't we get "6" printed 5 times all at the same time (after six seconds) not in one-second intervals?

Also, Kyle Simpson says, "The terminating condition of the loop is when i is not <=5. The first time that's the case is when i is 6. So, the output is reflecting the final value of the i after the loop terminates. This actually seems obvious on second glance. The timeout function callbacks are all running well after the completion of the loop. In fact, as timers go, even if it was setTimeout(.., 0) on each iteration, all those function callbacks would still run strictly after the completion of the loop, and thus print 6 each time."

So if I understand this correctly,
i gets incremented until it becomes 6.
i is <= 5 for 5 iterations, so we will run the setTimeout function 5 times.
So basically the code block/statement doesn't run until the code in the parentheses is finished?
I always thought the process was: if the condition is true, run the code block, then increment i. then rinse and repeat. I guess not? The loop and the statement are separate things. The loop only refers to the stuff inside parentheses, and it's only until the loop is finished that the statement is run?

Claudio Restifo
@Marmiz
Apr 18 2018 02:08

@eunipa the point to consider is that JS doesn't wait for you. So what happens is that the first time the loop gets evaluated the interpreter see the setTimeoutfunction and call it on the stack.
It won't wait for it to finish since nothing instruct it to do so, so it keeps doing its loops (and adding setIntervals on the call stack.

What happen is that by the time the first timeout is over, the interpreter has already looped over all the for possibilities, thus when setTimeout resolve the i value is already at its last iteration.

Make sense?

In general tho, it's not a good idea to execute functions inside a for loop :)
Eunice Park
@eunicode
Apr 18 2018 02:12
@Marmiz Thank you very much, as always, for your kind and informative answers. I'm sorry to ask more questions, but Kyle Simpson says that even if the timeout function was setTimeout(.., 0), the functions would only run after the completion of the loop. I'm still confused why.
CamperBot
@camperbot
Apr 18 2018 02:12
eunipa sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1210 | @marmiz |http://www.freecodecamp.org/marmiz
Aditya
@ezioda004
Apr 18 2018 02:13
@eunipa As @Marmiz said, the with every loop setTimeout() is placed on call stack, since its an async function. The callback inside the setTimeout is placed on queue and that queue is not checked by Event Loop until all main call stack is resolved meaning JS is done finishing the synchronous actions.
Eunice Park
@eunicode
Apr 18 2018 02:15
@ezioda004 Thank you very much. Oh boy, looks like there's a whole bunch of things I need to look up like queue and Event Loop. So does that have something to do with why setTimeout is able to run at one-second intervals, while the callback function prints 6?
CamperBot
@camperbot
Apr 18 2018 02:15
eunipa sends brownie points to @ezioda004 :sparkles: :thumbsup: :sparkles:
:cookie: 540 | @ezioda004 |http://www.freecodecamp.org/ezioda004
Aditya
@ezioda004
Apr 18 2018 02:17
@eunipa Yep the function is placed on stack as the loop goes on, its the Callback function that executes after the stack is cleared.
Look at this image to visualize. http://altitudelabs.com/blog/content/images/2014/Jul/1-s7d9UjolRGGjqFtfK0wZ8w.png
Thats also the exact reason why setTimeout(.., 0) will run afterwards the for loop is over. The callback function is placed in queue and its not called until all the stack is cleared.
Claudio Restifo
@Marmiz
Apr 18 2018 02:19
@eunipa, as @ezioda004 has perfectly ( :clap: ) described, intervals actions in JS are teated differently. Even if the timer is sets to 0, the interpreters puts them on hold and resolve them as soon as it has the chance to do.
that may be now, or after a short delay while doing more synchronous stuff
Eunice Park
@eunicode
Apr 18 2018 02:20
@ezioda004 @Marmiz I don't know what I would do without you guys. Grateful as always for the sharing of your knowledge. I'll continue to mull over everything you guys told me.
Aditya
@ezioda004
Apr 18 2018 02:21
Actually this image may help you better visualize it.
http://vucuong12.github.io/css/images/eventloop.png
Just ignore the right side API block and focus on event loop and stack
Claudio Restifo
@Marmiz
Apr 18 2018 02:21
@eunipa this is a great website/tool that helps you visualise what the machine is doing while running code:
http://pythontutor.com/
Eunice Park
@eunicode
Apr 18 2018 02:23
Oh man, thank you guys so much for the detailed information. I'll have a lot to study tonight :)
Aditya
@ezioda004
Apr 18 2018 02:24
Its really an interesting topic, helps you put a bit memory management into perspective. Goodluck! :thumbsup:
Göran Kempe
@Gorankempe
Apr 18 2018 07:06
Hey guys, I'm trying to use an API and I don't really understand this whole authorization thing.
How do I send my API key with my call so that I can access it? If I just open the URL I'm calling I get an error, but when I use my API key through their API Explorer it shows me the result I want. In their docs they specify a authorization header, but I dont know where to use it.
@AdelMahjoub sadly no
Göran Kempe
@Gorankempe
Apr 18 2018 07:31
@tiagocorreiaalmeida Oh thank you so much! Any idea how to do this with fetch instead?
CamperBot
@camperbot
Apr 18 2018 07:31
gorankempe sends brownie points to @tiagocorreiaalmeida :sparkles: :thumbsup: :sparkles:
:cookie: 518 | @tiagocorreiaalmeida |http://www.freecodecamp.org/tiagocorreiaalmeida
Pieter Stokkink
@forkerino
Apr 18 2018 07:56
@Gorankempe Second argument to fetch is an options object, where you can specify headers. https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
Henry Guo
@finalfinalwinner
Apr 18 2018 08:37
#204 I need help....
function isLess(a, b) { return a === b;
}
not right
Markus Kiili
@Masd925
Apr 18 2018 08:38
@finalfinalwinner Function name implies that you need to test with < or >.
Henry Guo
@finalfinalwinner
Apr 18 2018 08:40
function isLess(a, b) {
// 请修改这部分代码
return a === b;
}
isLess(10, 15);
how to return false
#204
Markus Kiili
@Masd925
Apr 18 2018 08:41
@finalfinalwinner Don't use ===.
Henry Guo
@finalfinalwinner
Apr 18 2018 08:42

你可能会回想起Comparison with the Equality Operator ,所有的比较操作符返回的都是一个boolean值,要么是 true 要么是false 。

使用 if/else语句来做比较然后返回true或false已经成为大家的共识:

function isEqual(a,b) {
if (a === b) {
return true;
} else {
return false;
}
}
因为=== 总是返回 true 或 false,所以我们可以直接返回比较的结果:

function isEqual(a,b) {
return a === b;
}
任务
移除isLess函数的if/else语句但不影响函数的功能。

功能。

false

isLess(10,15) 应该返回 true
isLess(15,10) 应该返回 false
不要使用 if 或 else 表达式

有没有中国人
。。。
Blauelf
@Blauelf
Apr 18 2018 08:45
@finalfinalwinner If you don't understand English, maybe FreeCodeCamp/chinese can help.
Henry Guo
@finalfinalwinner
Apr 18 2018 08:45
@Blauelf Thank you
CamperBot
@camperbot
Apr 18 2018 08:45
finalfinalwinner sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4691 | @blauelf |http://www.freecodecamp.org/blauelf
Blauelf
@Blauelf
Apr 18 2018 08:47
Interesting. For me, English was a necessity to access the Internet. Not so for Chinese, it seems.
Henry Guo
@finalfinalwinner
Apr 18 2018 08:50
yes i agree with what you said .
Josh Queen
@josh-queen
Apr 18 2018 11:58
function tickets(peopleInLine){
  var counter = 0;
  for (var i = 0; i > peopleInLine.length-1; i++) {
    counter += peopleInLine[i];
  }
  return counter;
}

alert(tickets([25, 25, 50]));
I was expecting counter to return 50
But it returns 0
Any ideas?
Marianissimus
@Marianissimus
Apr 18 2018 11:59
oh, but of course;
ijhar
@ijhar8
Apr 18 2018 12:00
@Kohota107 look at your condition
0>2 ===false
Marianissimus
@Marianissimus
Apr 18 2018 12:01
the loop doesn't even begin, that's it
ijhar
@ijhar8
Apr 18 2018 12:01
i < peopleInLine.length-1 use it
Marianissimus
@Marianissimus
Apr 18 2018 12:01
<
Josh Queen
@josh-queen
Apr 18 2018 12:02
My god I'm an idiot... -_-
Thanks guys! haha
Ronique Ricketts
@RoniqueRicketts
Apr 18 2018 12:22
good morning
Dhaval Vira
@dhavalveera
Apr 18 2018 12:22
Good Evening
Stephen James
@sjames1958gm
Apr 18 2018 12:23
@RoniqueRicketts :wave:
Ronique Ricketts
@RoniqueRicketts
Apr 18 2018 12:23
@sjames1958gm whats up bruv, if I have a .env.local file how do I get the variables from it in my code?
@dhavalveera sounds like your on the other side of the world. :)
Dhaval Vira
@dhavalveera
Apr 18 2018 12:24
Yes
India
Stephen James
@sjames1958gm
Apr 18 2018 12:24
@RoniqueRicketts I use dotenv package
Ronique Ricketts
@RoniqueRicketts
Apr 18 2018 12:26
@sjames1958gm i use it too, but if I want to get the variable from a .env.local that I made how do I get the a variable like HOST from it in my code? Normally I would do a process.env.HOST
Stephen James
@sjames1958gm
Apr 18 2018 12:29
require('dotenv').config({path: './local.env'})
Does this work to load them into process.env
Ronique Ricketts
@RoniqueRicketts
Apr 18 2018 12:34
@sjames1958gm should this local.env be the name of my environment variable?
Donnie
@Donnie-D
Apr 18 2018 12:35
quick little question...i want to do something when the checkbox is checked. is the following syntax alright?
function a(){
  if (document.getElementsByTagName('input')[0].checked){
    alert('yes');
  }
}
a();
Stephen James
@sjames1958gm
Apr 18 2018 12:39
@RoniqueRicketts That is the path name of the file containing the variables.
Why not just name it .env?
Ronique Ricketts
@RoniqueRicketts
Apr 18 2018 12:39
@sjames1958gm because when i add .env in my .gitignore file it is still uploading to my github. :(
Stephen James
@sjames1958gm
Apr 18 2018 12:41
You need to remove .env from tracking, if you have already added .env to your repo gitignore doesn't help
git rm .env
git commit -am "remove .env"
git push origin
Then if you copy local.env to .env it should not push to github
Donnie
@Donnie-D
Apr 18 2018 12:44
@sjames1958gm :ambulance: lol a little help?
quick little question...i want to do something when the checkbox is checked. is the following syntax alright?
function a(){
  if (document.getElementsByTagName('input')[0].checked){
    alert('yes');
  }
}
a();
Stephen James
@sjames1958gm
Apr 18 2018 12:48
@Donnie-D If you only have the one 'input' and it is a checkbox then this is ok.
More flexible to use querySelector and pass a selector into the function
function a(selector) {
  if (document.querySelector(selector).checked) {
    alert('yes')
  }
}
a('input')
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 12:49
require('dotenv').config(); and when uou need to use some varisble call it like this process.env.variablename @RoniqueRicketts
Ronique Ricketts
@RoniqueRicketts
Apr 18 2018 12:50
@tiagocorreiaalmeida Ya I do that but for some reason last night it wasn't starting my server since my port number was in the .env file
Donnie
@Donnie-D
Apr 18 2018 12:51
@sjames1958gm but despite of you and I approving that above code why wouldn't it respond here? :disappointed: ?
:laughing: I know i must've fudged up somewhere else
Ronique Ricketts
@RoniqueRicketts
Apr 18 2018 12:54
@sjames1958gm its still there. even after using
git rm .env
git commit -am "remove .env"
git push origin
Stephen James
@sjames1958gm
Apr 18 2018 12:54
@RoniqueRicketts Try deleting from github and then git pull from local
nandoBel
@nandoBel
Apr 18 2018 12:57
Hi there
Ronique Ricketts
@RoniqueRicketts
Apr 18 2018 12:57
@sjames1958gm done
nandoBel
@nandoBel
Apr 18 2018 12:57

function Betal(){

var dobbeltrom = document.getElementById("dobbeltrom").value;
var enkeltrom = document.getElementById("enkeltrom").value;
var valgt = document.getElementById("hotellValg").value;
var rom = dobbeltrom + enkeltrom;
var pris = 0;

if(valgt == "Aurora") { pris += 590}
if (valgt == "Downtown") { pris += 660}
if(valgt == "CityHall") { pris += 450}
if (valgt == "Wilmont") {pris += 660}
if (valgt == "ChelseaInn") {pris +=450}


var pass = 0;
if (document.getElementById("ja").checked) {pass = 700;}
else {pass = 0}

var sum = (pris*rom) + pass;

document.getElementById('utskrift').innerHTML = sum;

kostnad.innerHTML = `Kostnaden din blir på: ${sum}`;

}

Ronique Ricketts
@RoniqueRicketts
Apr 18 2018 12:57
it disappeared from my local setup too
nandoBel
@nandoBel
Apr 18 2018 12:57
Hod do I make it so this automatically updates price in a div based on what is chosen
Stephen James
@sjames1958gm
Apr 18 2018 12:57
@Donnie-D You have to attach a handler to
function a(){
  if (document.querySelector('input').checked){
    alert('yes');
  }
}
document.querySelector('input').onchange = a
@RoniqueRicketts Now if you recreate it will be .gitignored
Ronique Ricketts
@RoniqueRicketts
Apr 18 2018 12:58
so in my gitignore file there is .env in the file.
Stephen James
@sjames1958gm
Apr 18 2018 12:59
@nandoBel You need to add an event handler to the input that changes to call this function
@RoniqueRicketts Yes, now when you do
git status
it should not show you the .env file at all
nandoBel
@nandoBel
Apr 18 2018 12:59
Oh lord, thats more than I can handle right now :)
Could you pretty please show me how?
Stephen James
@sjames1958gm
Apr 18 2018 13:01
@RoniqueRicketts
If you have files in the .gitignore
then git status will not show them as untracked
and git add . will not add them as tracked
nandoBel
@nandoBel
Apr 18 2018 13:01
Oh, the onclick on that button already works
Stephen James
@sjames1958gm
Apr 18 2018 13:02
@nandoBel Something like this
document.getElementById("dobbeltrom").onchange = Betal
do this outside the function and when this element changes it will call the function
do this for each element that would affect the price
Ronique Ricketts
@RoniqueRicketts
Apr 18 2018 13:02
@sjames1958gm I just pushed and its not there. Thanks much man your deserve brownies. Your too @tiagocorreiaalmeida
CamperBot
@camperbot
Apr 18 2018 13:02
roniquericketts sends brownie points to @sjames1958gm and @tiagocorreiaalmeida :sparkles: :thumbsup: :sparkles:
:cookie: 519 | @tiagocorreiaalmeida |http://www.freecodecamp.org/tiagocorreiaalmeida
:star2: 9209 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
nandoBel
@nandoBel
Apr 18 2018 13:02
@sjames1958gm Thanks!
Stephen James
@sjames1958gm
Apr 18 2018 13:02
@RoniqueRicketts :+1:
Donnie
@Donnie-D
Apr 18 2018 13:03

@Donnie-D You have to attach a handler to

function a(){
  if (document.querySelector('input').checked){
    alert('yes');
  }
}
document.querySelector('input').onchange = a    //could you write this line in vanilla JS please? I like vanilla flavour when its sunny

@sjames1958gm

Ronique Ricketts
@RoniqueRicketts
Apr 18 2018 13:03
@sjames1958gm one day I will be that good at debugging.
Stephen James
@sjames1958gm
Apr 18 2018 13:03
@RoniqueRicketts Since you added the file to .gitignore after it was already being tracked that had no affect
@Donnie-D That is all "vanilla" js
Donnie
@Donnie-D
Apr 18 2018 13:04
numpty me then :stuck_out_tongue_winking_eye:
Fabien SHAN
@X140hu4
Apr 18 2018 13:04
damn i want a vanilla ice cream now
ijhar
@ijhar8
Apr 18 2018 13:04
@RoniqueRicketts help me to add array in table https://jsfiddle.net/ijhar8/a9xczrbx/52/
Donnie
@Donnie-D
Apr 18 2018 13:05
@X140hu4 :wink:
Ronique Ricketts
@RoniqueRicketts
Apr 18 2018 13:05
@sjames1958gm oh zeen!! Well I am glad thats fixed. I decided that I will take a look at the whole form submitting unexpected feature i was getting yesterday.
nandoBel
@nandoBel
Apr 18 2018 13:05
Didn't work @sjames1958gm :(
Stephen James
@sjames1958gm
Apr 18 2018 13:05
@nandoBel Do you have this online somewhere (codepen / jsbin)?
@RoniqueRicketts :+1:
Donnie
@Donnie-D
Apr 18 2018 13:08
son of a :gun: it worked @sjames1958gm
:clap:
Stephen James
@sjames1958gm
Apr 18 2018 13:08
@Donnie-D :bow:
Ronique Ricketts
@RoniqueRicketts
Apr 18 2018 13:08
@Donnie-D don't underestimate the Stephen, he is a real nerd (in a cool way)
nandoBel
@nandoBel
Apr 18 2018 13:09
@sjames1958gm Sent you a PM
Stephen James
@sjames1958gm
Apr 18 2018 13:14
@nandoBel :+1:
Ronique Ricketts
@RoniqueRicketts
Apr 18 2018 13:15
off to work will check in once I reach work.
Donnie
@Donnie-D
Apr 18 2018 13:20
@sjames1958gm sorry to be thick but why cant i use document.getElementsByTagName('input')[0].onchange=a(); instead of document.querySelector('input').onchange = a;? You have the right to remain silent :police_car: if the question was too foolish.
Stephen James
@sjames1958gm
Apr 18 2018 13:21
@Donnie-D You could - I just like querySelector better as it returns just one value so the [0] is not needed
Donnie
@Donnie-D
Apr 18 2018 13:22
rightiho!
Stephen James
@sjames1958gm
Apr 18 2018 13:28
@Donnie-D query selector lets you do use css selectors like .class and #id as well
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 14:14
@RoniqueRicketts will try to look into the project now
May Kittens Devour Your Soul
@diomed
Apr 18 2018 14:42
pls help
particles won't display, even tho I added
why?
May Kittens Devour Your Soul
@diomed
Apr 18 2018 14:50
why hast thou forsaken me? :worried:
Nate Mallison
@NJM8
Apr 18 2018 14:59
@diomed looking at the particles example from the docs everything is in quotes
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 14:59
got it working @RoniqueRicketts there's a few changes to be made
Koohyar Movassagh
@Koohyar-m
Apr 18 2018 14:59
:wave:
Ken Haduch
@khaduch
Apr 18 2018 15:00
@diomed - I changed the color of the particles to #f00 and I see them at the bottom of the page, so they might have been showing up as white against a whie background?
@diomed - it appears that the canvas is at the bottom of the page...
May Kittens Devour Your Soul
@diomed
Apr 18 2018 15:02
oh , how did it get there?
@NJM8 that's not a real pen. u didnt save, I guess
Nate Mallison
@NJM8
Apr 18 2018 15:04
oops, that should've been the demo, I changed all your params to be in quotes and still not working
Ken Haduch
@khaduch
Apr 18 2018 15:04
@diomed - I see in one place you have a "uk-cover" just as an attribute - I added a class="uk-cover", and I see that it shows up as a class. Not sure how that was supposed to work, but I wondered if it might be a class, and it does seem to be?
Koohyar Movassagh
@Koohyar-m
Apr 18 2018 15:09
This is cool
Jason Luboff
@JLuboff
Apr 18 2018 15:10
Morning :wave:
May Kittens Devour Your Soul
@diomed
Apr 18 2018 15:11
@khaduch ugh. wherever I place that stupid div, it's never behind, it's always above or below :|
Christopher McCormack
@cmccormack
Apr 18 2018 15:18
@JLuboff morning!
Ken Haduch
@khaduch
Apr 18 2018 15:18
@JLuboff - howdy!
Jason Luboff
@JLuboff
Apr 18 2018 15:19
@cmccormack @khaduch How's it going?
Christopher McCormack
@cmccormack
Apr 18 2018 15:19
Good man waiting on people to get to work so I can start pestering them with questions
How you doing?
Ken Haduch
@khaduch
Apr 18 2018 15:24
@diomed - is the particles code supposed to find the canvas? Because you have two canvases, one appears to be behind the top image, but it doesn't have the particle-related classes attached to it? The one that shows up at the bottom does have some classes that do not appear to be in your HTML panel, I'm wondering if they are attached by the JS? The devtools is showing this for the bottom canvas:
<canvas class="particles-js-canvas-el" width="1200" height="600" style="width: 100%; height: 100%;"></canvas>
May Kittens Devour Your Soul
@diomed
Apr 18 2018 15:25
they're attached by js, yes
u can see js in JS window or pen
is it a problem if there are 2 canvases?
Jason Luboff
@JLuboff
Apr 18 2018 15:28
@cmccormack Doing alright. Putting out fires :joy:
Christopher McCormack
@cmccormack
Apr 18 2018 15:28
Did you light them? :D
Jason Luboff
@JLuboff
Apr 18 2018 15:30
@cmccormack Luckily not me (this time!) We had to get a new license for Autocad installed so my coworker took care of it this morning, but it broke another network license for a different software so we had to figure out why (service wasn't running D'oh)
Christopher McCormack
@cmccormack
Apr 18 2018 15:30
that's odd
Jason Luboff
@JLuboff
Apr 18 2018 15:30
Well both licenses get handled in one way or another through the same license manager
May Kittens Devour Your Soul
@diomed
Apr 18 2018 15:33
I wonder why this canvas refuses to be shown on 2 places @ the same time
Christopher McCormack
@cmccormack
Apr 18 2018 15:48
@diomed share?
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 15:56
@JLuboff save me

/*Please add ; after each select statement*/
CREATE PROCEDURE soccerPlayers()
BEGIN
    SELECT GROUP_CONCAT(CONCAT(first_name," ",surname," ",'#',player_number) ORDER BY player_number SEPARATOR '; ') FROM soccer_team;
END
for some reason I cna't force the space on the separator
Jason Luboff
@JLuboff
Apr 18 2018 16:02
@tiagocorreiaalmeida Won't let me go into the link you sent
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 16:02
hum open codefights
arcade mode, databases
Jason Luboff
@JLuboff
Apr 18 2018 16:03
Also.. which version of SQL is it using? It looks like GROUP_CONCAT is a MySQL method, not a standard SQL method
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 16:03
mysql itself
Jason Luboff
@JLuboff
Apr 18 2018 16:04
Ok, I went to arcade mode database...then?
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 16:05
GROUP Dishes BY Type
4 group on the databases
you can buy the group by 300coins
and each exercise unthil the soccerpalyers for mroe 300coins :D
once you are avaible to open it let me know
Jason Luboff
@JLuboff
Apr 18 2018 16:07
@tiagocorreiaalmeida You're output does have spaces?
It looks like the expected is double space. Or at least I can'
t see why there'
s extra spacing
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 16:08
after the separator; is expect one space
for some reason its not working
Jason Luboff
@JLuboff
Apr 18 2018 16:08
@tiagocorreiaalmeida Put a space in front of first_name? Also... you need to name your column players
Ken Haduch
@khaduch
Apr 18 2018 16:10
@diomed - well, if I comment out all of the JS, I definitely find two canvases they are both behind your images. (Using devtools and looking for the canvas elements.) It seems that only one gets properties or classes added to it, and then it moves from behind the div with the "Media Right" information...
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 16:10
@JLuboff that wont work
cause the last name will ahve the space aswell
:\
wait what
seems that the only issue missing was atually the column name?
but the output had no spaces what a strange thing sorry for waste your time @JLuboff :\
Jason Luboff
@JLuboff
Apr 18 2018 16:12
@tiagocorreiaalmeida ;) gotta name your column homie!
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 16:13
yeah done allready, atually liking this part of codeifghts didnt knew of group concat tbh
Nate Mallison
@NJM8
Apr 18 2018 16:13
backend challenges are a bit more challenging when you can't uhhh...... learn from the example code 😉
Jason Luboff
@JLuboff
Apr 18 2018 16:13
@tiagocorreiaalmeida Can you change from mysql to mssql do you know?
@NJM8 No need to look at the example code ;)
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 16:14
doesnt seems so @JLuboff :\
Nate Mallison
@NJM8
Apr 18 2018 16:15
I think the only one I really 'cheated' on was the wikipedia viewer to get the api call. wikimedia may as well not have any docs for all they are worth
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 16:16
you can atually look at the "example" code but avoid it tough
Jason Luboff
@JLuboff
Apr 18 2018 16:17
@tiagocorreiaalmeida Thats kind of lame. I mean..I try and use standard SQL, but it'd be nice to be able to do T-SQL
Passed the first DB arcade whoo
(It was super easy though)
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 16:18
ahah yeah, keep going on it probablyt will get more challenging after a while xd
Jason Luboff
@JLuboff
Apr 18 2018 16:19
And done with the second one lol
I keep forgetting the ; apparently MySQL is strict about that
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 16:20
ahahha yeah, im on the last one of the 4
Jason Luboff
@JLuboff
Apr 18 2018 16:22
Ya the first box of challenges so far is super easy. Like stupid easy
@tiagocorreiaalmeida So I've been learning more intermediate/advanced stuff, really cool feature in SQL Server 2016 is temporal tables. You can essentially have SQL server keep a history table, so everytime a delete/insert/update is performed, it'll write the old data to the history table automatically and then you can query the current or history table. (I know this can be setup manually, but now its much more automated which is cool)
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 16:26
like a trigger?
Jason Luboff
@JLuboff
Apr 18 2018 16:27
Doesn't require a trigger. Just setup two hidden columns that contain time, and as those actions take place it'll automatically handle everything
Most likely is a hidden trigger in there though
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 16:29
everyday I feel like I know less :D either way always good to hear about new stuff
Jason Luboff
@JLuboff
Apr 18 2018 16:29
haha, I know the feeling
Christopher McCormack
@cmccormack
Apr 18 2018 16:33
@diomed did you want something like this?
May Kittens Devour Your Soul
@diomed
Apr 18 2018 16:34
@cmccormack sweet. why does it make first one so long?
Christopher McCormack
@cmccormack
Apr 18 2018 16:40
dunno probably in the settings
I just cut out the settings object and moved to its own variable then created two instances, added an id that was missing to the first
cool effect I may have to use it
Ken Haduch
@khaduch
Apr 18 2018 16:42
@diomed - I'm doing a little bit of stepping through the particleJS code, and it appears to be creating a new canvas and appending it to the stuff that's already there. I take it that you want it to operate with the canvas elements that you are creating? It doesn't look like it's working that way, at least I can't see how it would at this point? There doesn't seem to be a ton of documentation on it.
May Kittens Devour Your Soul
@diomed
Apr 18 2018 16:45
@khaduch i'm confused on how can it be background of a card, but not background of a webpage
Ken Haduch
@khaduch
Apr 18 2018 16:47
@diomed - it looks like it's appending the canvas that it creates to the elements that you pass in as the function parameters. If you look at @cmccormack s code, you will see that he made changes where he called the new particlesJS twice. Maybe if you put the id on the body element?
May Kittens Devour Your Soul
@diomed
Apr 18 2018 16:49
uh oh how to add id to body in codepen
since it's already body
Ken Haduch
@khaduch
Apr 18 2018 16:50
@diomed - I'm thinking that maybe with some JS before you call the particleJS function? I'm trying it... just a little rusty with my JS... :)
Jason Luboff
@JLuboff
Apr 18 2018 16:56
@tiagocorreiaalmeida I'm really annoyed that codefights uses mysql and doesn't let you choose a different sql dialect lol
Ken Haduch
@khaduch
Apr 18 2018 16:56
@diomed - it didn't quite work because it appended the canvas to the elements in the body, so it still shows up at the bottom, after all of the other elements.
Markus Kiili
@Masd925
Apr 18 2018 16:57
@JLuboff Just learn it :imp:
Jason Luboff
@JLuboff
Apr 18 2018 16:58
@Masd925 :angry:
I don't wanna!
Markus Kiili
@Masd925
Apr 18 2018 17:01
@JLuboff You are not putting back your Mongo cloak, ever.
Jason Luboff
@JLuboff
Apr 18 2018 17:03
@Masd925 I'm said I haven't done anything with mongo for at least a month now :(
Everything is so much easier in Mongo!
Markus Kiili
@Masd925
Apr 18 2018 17:05
@JLuboff Chaos is always the easiest way.
Ken Haduch
@khaduch
Apr 18 2018 17:09
@diomed - I'm watching this netNinja video about using the canvas as a background element. I found another video that I started watching about using particleJS as a background, but it was moving slowly and hard to understand, so I opted for the netNinja...
May Kittens Devour Your Soul
@diomed
Apr 18 2018 17:17
@khaduch one guy figured it out, thanks tho
CamperBot
@camperbot
Apr 18 2018 17:17
diomed sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
api offline
May Kittens Devour Your Soul
@diomed
Apr 18 2018 17:17
It was about adding css
if you want, I can show you
Christopher McCormack
@cmccormack
Apr 18 2018 17:21
Please share @diomed
May Kittens Devour Your Soul
@diomed
Apr 18 2018 17:22
sure. here you go: pen
Christopher McCormack
@cmccormack
Apr 18 2018 17:25
hmm wasn't really a css issue more using a wrapper but looks pretty good. sort of strange behavior when you hover over a card (or maybe the lack of hover is what looks strange) but easily remedied
May Kittens Devour Your Soul
@diomed
Apr 18 2018 17:29
yeah, my cards are freaking transparent. lol
Christopher McCormack
@cmccormack
Apr 18 2018 17:29
haha
May Kittens Devour Your Soul
@diomed
Apr 18 2018 17:29
gotta fix that
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 17:39
@JLuboff yeah atually doesnt makes sense since they offer alot of languages on tje coding challenges
Ken Haduch
@khaduch
Apr 18 2018 17:46
@diomed - looking good!
Jason Luboff
@JLuboff
Apr 18 2018 17:49
@tiagocorreiaalmeida Eh.. I'm guessing they have to have a SQL backend for the tests, and instead of paying money they just use MySQL for free
I seek your honest criticism, tell me if it is trash, and not worth people's time
Christopher McCormack
@cmccormack
Apr 18 2018 18:40
@relentless-coder I think it probably needs more content
Ayush Bahuguna
@relentless-coder
Apr 18 2018 18:41
Okay, so whatever you read wasn't informative, the few minutes that you put into reading weren't worth it?
@cmccormack
Christopher McCormack
@cmccormack
Apr 18 2018 18:44
@relentless-coder I think it's a nice quick overview, and I wouldn't stop you from sharing it, you should share it, but personally if I were to read it I would like a bit more, maybe even something as simple as mapping the concepts to a bit of configuration
Ayush Bahuguna
@relentless-coder
Apr 18 2018 18:46
Great, thank you for the input, I'll extend upon that in my next post as I mentioned in the last line @cmccormack
CamperBot
@camperbot
Apr 18 2018 18:46
relentless-coder sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1414 | @cmccormack |http://www.freecodecamp.org/cmccormack
Nate Mallison
@NJM8
Apr 18 2018 18:51
Anyone have ideas on why I can access .env variables in my app.js but not in my router?
Ayush Bahuguna
@relentless-coder
Apr 18 2018 18:53
@NJM8 elaborate please :)
Nate Mallison
@NJM8
Apr 18 2018 18:53
using dotenv to expose environment variables
if (app.get('env') === 'development') {
  require('dotenv').load();
  console.log(process.env.API_KEY);
  console.log(process.env.CSE_ID);
}
that is in app.js, and it will log the variables
Ayush Bahuguna
@relentless-coder
Apr 18 2018 18:54
and what about the router?
Nate Mallison
@NJM8
Apr 18 2018 18:54
but if I put those console logs in router.js I get undefined
Christopher McCormack
@cmccormack
Apr 18 2018 18:54
you have to pass it along
Nate Mallison
@NJM8
Apr 18 2018 18:54
I know the router and the app.js are hooked up correctly
Christopher McCormack
@cmccormack
Apr 18 2018 18:55
code?
Christopher McCormack
@cmccormack
Apr 18 2018 18:59
not sure what you're trying to do - is the user browsing to /env?
Nate Mallison
@NJM8
Apr 18 2018 18:59
I just did the same with my URL shortener and it worked just fine, although I did experience some weirdness at the start
using .env to store the variables for the search client, line 5 in imageRouter.js
using dotenv
Christopher McCormack
@cmccormack
Apr 18 2018 19:02
ok, never saw this syntax before with a get (app.get('env') === 'development')
Ayush Bahuguna
@relentless-coder
Apr 18 2018 19:02
@NJM8 is it because you import your router first and then load your environment variables?
can you try and load your environment variables first and then import router?
Donnie
@Donnie-D
Apr 18 2018 19:04
Yyelp! :scream: whats wrong with my if condition that my conversion from fahrenheit to celcius isn't taking place in the code below fellas
https://codepen.io/Donnie-D/pen/YaydRM
Nate Mallison
@NJM8
Apr 18 2018 19:04
@relentless-coder I don't think so but I'll try it
Christopher McCormack
@cmccormack
Apr 18 2018 19:05
@NJM8 maybe just put this in any file you need to load env variables:
require('dotenv').config({path: path.resolve(__dirname, '.env')})

const { API_KEY, CSE_ID, ... } = process.env
Nate Mallison
@NJM8
Apr 18 2018 19:06
@cmccormack That checks your environment, if you are in production express will set that variable accordingly, with that statement obviously then dotenv will not be used, on heroku the env vars will be populated from your config vars
But you know most of that
Christopher McCormack
@cmccormack
Apr 18 2018 19:06
@NJM8 yes, it's the comparison of a string to a middleware function I'm not familiar with
Nate Mallison
@NJM8
Apr 18 2018 19:07
I looked up how express sets that var before but I forget how it works, mostly magic
Ayush Bahuguna
@relentless-coder
Apr 18 2018 19:09
@NJM8 i think you are supposed to load dotenv before referencing to any of the environment variables. You have imported your imageRouter before you load env variables, kindly look into it and let me know.
the reason it works in the app.js is because you have placed console.logs after you have loaded the dotenv
for a simple test, console.log the env variables before loading the dotenv
Nate Mallison
@NJM8
Apr 18 2018 19:11
same as imageSearch
huh
Ayush Bahuguna
@relentless-coder
Apr 18 2018 19:12
@NJM8 that's because you are making use of the environment variables inside the router callbacks
Nate Mallison
@NJM8
Apr 18 2018 19:13
you are right! But now tell me why I have been doing it after..... ohhhh
Ayush Bahuguna
@relentless-coder
Apr 18 2018 19:13
whereas in the imageSearch you have console.log right when the module is loaded :)
Nate Mallison
@NJM8
Apr 18 2018 19:13
so outside of the callbacks it doesn't have access to the .env vars because it isn't exposed to the middleware
Ayush Bahuguna
@relentless-coder
Apr 18 2018 19:14
@NJM8 no that's not correct reason
Nate Mallison
@NJM8
Apr 18 2018 19:14
so why does it work in the urlShortener?
Ayush Bahuguna
@relentless-coder
Apr 18 2018 19:15
javascript executes the lines in a sequential manner, so when you import the imageRouter it starts executing it's lines, and it executes the console.logs, but the environment variables don't exist yet, since the require('dotenv').load() isn't executed yet.
Nate Mallison
@NJM8
Apr 18 2018 19:16
oh right, ok, so it's not the middleware it's just general availability, because the callbacks don't run until a later time
thanks @relentless-coder
CamperBot
@camperbot
Apr 18 2018 19:16
njm8 sends brownie points to @relentless-coder :sparkles: :thumbsup: :sparkles:
:cookie: 394 | @relentless-coder |http://www.freecodecamp.org/relentless-coder
Nate Mallison
@NJM8
Apr 18 2018 19:17
I think I've only ever used .env vars inside of the routes
Ayush Bahuguna
@relentless-coder
Apr 18 2018 19:17
in case of the urlShortner, router is event based. When you import the urlShortner router, javascript again executes each line, and sets up the routes, but the callbacks aren't being executed yet. and it moves on to the require('dotenv').load(). later when you make the api request, the relevant router executes the callback and the env variables are already present
@NJM8 as a safety net preload the dotenv
or you can simple make use of a bash scrip that loads the environment variables and also runs the app.
Christopher McCormack
@cmccormack
Apr 18 2018 19:18
question - why check for dev or prod? Isn't that why we use the .env file, so you can have a different version in each environment?'
Ayush Bahuguna
@relentless-coder
Apr 18 2018 19:19
@cmccormack i think it's because it's because dotenv uses the .env file and it's not a good practice to commit your .env file. In case of production, you simply use a process manager, and mention the env variables in it's config file
Nate Mallison
@NJM8
Apr 18 2018 19:20
Well I only know what I've been taught about it, but Heroku populates the .env vars from it's config vars. So in this way I can have my local version running, not commit .env file to github for everyone to have my keys, and then in production not bother with loading them with dotenv
Christopher McCormack
@cmccormack
Apr 18 2018 19:20
@relentless-coder I understand you don't push your .env file, but didn't think about the process manager, that's good info, thanks
CamperBot
@camperbot
Apr 18 2018 19:20
cmccormack sends brownie points to @relentless-coder :sparkles: :thumbsup: :sparkles:
:cookie: 395 | @relentless-coder |http://www.freecodecamp.org/relentless-coder
Nate Mallison
@NJM8
Apr 18 2018 19:20
although I don't know if it would actually cause an issue just to always load the .env vars with dotenv
Christopher McCormack
@cmccormack
Apr 18 2018 19:21
probably not.
why would Heroku need to populate that file? is the config vars something you configure to tell it to populate?
I haven't used Heroku in a long time so don't remember
Ayush Bahuguna
@relentless-coder
Apr 18 2018 19:22
Heroku is too much, mouse clicks and drag and drop. Makes me feel like less of a developer. ;D
jk
Christopher McCormack
@cmccormack
Apr 18 2018 19:22
:)
I just use glitch to host my node apps, easy peasy
pull it in from github and add my .env file, done
Ayush Bahuguna
@relentless-coder
Apr 18 2018 19:23
AWS all the way. I have spent hours writing scripts to automate stuff, now I can't turn back
Nate Mallison
@NJM8
Apr 18 2018 19:23
Heroku puts config vars in process.env
Christopher McCormack
@cmccormack
Apr 18 2018 19:24
@NJM8 but what is config vars in this context
Nate Mallison
@NJM8
Apr 18 2018 19:24
so in either environment process.env.SECRET_KEY will have the same
Christopher McCormack
@cmccormack
Apr 18 2018 19:24
just a form you put strings into?
Nate Mallison
@NJM8
Apr 18 2018 19:24
oh, config vars is where you put whatever you want exposed to process.env
yes
Christopher McCormack
@cmccormack
Apr 18 2018 19:24
ah ok
so exactly the same concept
as just adding the .env manually
Nate Mallison
@NJM8
Apr 18 2018 19:24
a form on your Heroku page for your app or you can do it in the terminal
Christopher McCormack
@cmccormack
Apr 18 2018 19:25
then yeah I don't see why you would need to test for dev vs prod
Nate Mallison
@NJM8
Apr 18 2018 19:25
heroku config:set GITHUB_USERNAME=joesmith
Christopher McCormack
@cmccormack
Apr 18 2018 19:25
except for @relentless-coder case where you aren't using those variables in a .env file perhaps
Nate Mallison
@NJM8
Apr 18 2018 19:25
yeah I was looking back at my express courses, I have no idea where I got that line from
Christopher McCormack
@cmccormack
Apr 18 2018 19:25
@NJM8 it's interesting it works, just tested it
$ node tester.js
development
...
$ NODE_ENV=production node tester.js
production
HAh it was right there, I just didn't scroll up to see it https://expressjs.com/en/api.html#app.get
I was looking at the one with the callback
@NJM8 glad you shared your issue, I learned a few new things! and that is why the chat room should persist!!
Nate Mallison
@NJM8
Apr 18 2018 19:29
motdotla/dotenv#126
Christopher McCormack
@cmccormack
Apr 18 2018 19:30
is heroku actually providing a production flag?
Nate Mallison
@NJM8
Apr 18 2018 19:30
I guess maybe that was it, looks like dotenv should fail silently so I'm not sure why I thought I needed that
maybe just over-optimizing
Ingram Jones
@Iggy1906
Apr 18 2018 19:30

Can anyone help me out with this? I don't know why this function is not firing. When the user wins, the buttons on the pad are suppose to fire lighting the pads to let the user know that they one. It's not doing that. I don't know why.

function showTime(){
var colorWheel = [0, 1, 3, 2];
var i = 0;
var n = 0;
var myInterval = setInterval(function(){
if(n>3){
n = 0;
}
color = $("#"+colorWheel[n]).attr("class").split(" ")[1];
setTimeout (function(){
$("#"+colorWheel[n-1]).removeClass(color+"-active");
}, 75);
i++;
n++;
if(i == 4*6){
clearInterval(myInterval);
}
}, 115);

}

Christopher McCormack
@cmccormack
Apr 18 2018 19:31
@Iggy1906 please wrap your code with ``` on their own line to properly format. You can modify previous posts
```
code
```
Nate Mallison
@NJM8
Apr 18 2018 19:32
@cmccormack I believe that they do but I forget and can't find it fast
Christopher McCormack
@cmccormack
Apr 18 2018 19:33
no worries
Nate Mallison
@NJM8
Apr 18 2018 19:33
looks like it would be better to set it in package.json
Christopher McCormack
@cmccormack
Apr 18 2018 19:33
yeah
glitch uses npm start by default so I use that for my 'prod' build
Nate Mallison
@NJM8
Apr 18 2018 19:33
or if it really fails silently just always, load that. I'll try that and see what happens when I push to Heroku
I've not really made anything where i need to mess with the package.json actions
Ingram Jones
@Iggy1906
Apr 18 2018 19:35
@cmccormack Umm, I'm not following you. You mean when I post code in here?
Christopher McCormack
@cmccormack
Apr 18 2018 19:35
@Iggy1906 yes
Ingram Jones
@Iggy1906
Apr 18 2018 19:36

'''function showTime(){
var colorWheel = [0, 1, 3, 2];
var i = 0;
var n = 0;
var myInterval = setInterval(function(){
if(n>3){
n = 0;
}
color = $("#"+colorWheel[n]).attr("class").split(" ")[1];
setTimeout (function(){
$("#"+colorWheel[n-1]).removeClass(color+"-active");
}, 75);
i++;
n++;
if(i == 4*6){
clearInterval(myInterval);
}
}, 115);

}'''

CamperBot
@camperbot
Apr 18 2018 19:36
:bulb: to format code use backticks! ``` more info
Ingram Jones
@Iggy1906
Apr 18 2018 19:36

\\function showTime(){
var colorWheel = [0, 1, 3, 2];
var i = 0;
var n = 0;
var myInterval = setInterval(function(){
if(n>3){
n = 0;
}
color = $("#"+colorWheel[n]).attr("class").split(" ")[1];
setTimeout (function(){
$("#"+colorWheel[n-1]).removeClass(color+"-active");
}, 75);
i++;
n++;
if(i == 4*6){
clearInterval(myInterval);
}
}, 115);

}\\

Nate Mallison
@NJM8
Apr 18 2018 19:36
@Iggy1906 backticks not single quotes
top left of keyboard on the tilde button
Christopher McCormack
@cmccormack
Apr 18 2018 19:37
and you can edit your previous posts
just hit up arrow to edit most recent
Ingram Jones
@Iggy1906
Apr 18 2018 19:37

```function showTime(){
var colorWheel = [0, 1, 3, 2];
var i = 0;
var n = 0;
var myInterval = setInterval(function(){
if(n>3){
n = 0;
}
color = $("#"+colorWheel[n]).attr("class").split(" ")[1];
setTimeout (function(){
$("#"+colorWheel[n-1]).removeClass(color+"-active");
}, 75);
i++;
n++;
if(i == 4*6){
clearInterval(myInterval);
}
}, 115);

}```

Christopher McCormack
@cmccormack
Apr 18 2018 19:37
on their own line
Nate Mallison
@NJM8
Apr 18 2018 19:37
almost got it
Christopher McCormack
@cmccormack
Apr 18 2018 19:37
Nate Mallison
@NJM8
Apr 18 2018 19:38
i think it took me about 15 times to get it right the first few times. lol
the annoying part is to add a return after you hit ``` you need to hit shift+return
Christopher McCormack
@cmccormack
Apr 18 2018 19:39
I feel like even after you get it @Iggy1906 we may still not have enough context either
Nate Mallison
@NJM8
Apr 18 2018 19:39
@cmccormack did you see my array comparisons page I made?
Christopher McCormack
@cmccormack
Apr 18 2018 19:39
the speed one?
Nate Mallison
@NJM8
Apr 18 2018 19:40
it was very interesting, in the end my flattenArray was much faster than lodash on my machine but lodash was much faster than mine on others
not really sure why
Christopher McCormack
@cmccormack
Apr 18 2018 19:41
make a new package that randomly picks yours or lodashes :)
Nate Mallison
@NJM8
Apr 18 2018 19:41
it may slow down your browser for a few minutes unless you have a newer computer
it takes my cpu like 6 minutes to do it, results are in console
Christopher McCormack
@cmccormack
Apr 18 2018 19:41
I have both a newer and older computer haha
built a beast in 2010 i7 top of the line everything
but replaced the graphics card only recently
still strong!
Nate Mallison
@NJM8
Apr 18 2018 19:42
well, only use the old one if you want it to crash
Christopher McCormack
@cmccormack
Apr 18 2018 19:42
no it's the same one
haha
Frankenpc
perhaps you shouldn't do the math immediatly when the page loads haha
Nate Mallison
@NJM8
Apr 18 2018 19:43
still rocking my 2010 MBP
core duo whipping along at the speed of an old Caddy
Christopher McCormack
@cmccormack
Apr 18 2018 19:43
I have a 2015 and am considering buying another to put in the freezer just in case - don't like the new ones
Ingram Jones
@Iggy1906
Apr 18 2018 19:43
function showTime(){
  var colorWheel = [0, 1, 3, 2];
   var i = 0;
   var n = 0;
   var myInterval = setInterval(function(){
     if(n>3){
       n = 0;
     }
     color = $("#"+colorWheel[n]).attr("class").split(" ")[1];
     setTimeout (function(){
       $("#"+colorWheel[n-1]).removeClass(color+"-active");
     }, 75);
     i++;
     n++;
     if(i == 4*6){
      clearInterval(myInterval);
     }
   }, 115);

 }
Nate Mallison
@NJM8
Apr 18 2018 19:44
got it! nice
Ingram Jones
@Iggy1906
Apr 18 2018 19:44
Here's the pen that I'm working with.
https://codepen.io/iggy1906/pen/GxaZVd?editors=1010
Nate Mallison
@NJM8
Apr 18 2018 19:44
yeah i had a plan to make a button to run the test and output the results on a page but skipped it
Christopher McCormack
@cmccormack
Apr 18 2018 19:44
@Iggy1906 that is a dangerous way to get your color
maybe look at the classList instead, or use a different attribute
Nate Mallison
@NJM8
Apr 18 2018 19:45
ohhhh, my website is run through cloudflare and they just exposed a way to use web workers.
I should try that out, this could actually be an interesting project
Christopher McCormack
@cmccormack
Apr 18 2018 19:45
@NJM8 maybe they can also get it to just work
Nate Mallison
@NJM8
Apr 18 2018 19:46
hopefully then it wouldn't slow the browser for so long
@Iggy1906 What do you want to do with that? make all the buttons highlight in a circle or something?
Christopher McCormack
@cmccormack
Apr 18 2018 19:48
you should make it a visualization! I can't see anything, btw
Nate Mallison
@NJM8
Apr 18 2018 19:48
@cmccormack open console the results are logged
no html
@Iggy1906 If that is the case I would look at simulating the button click, I've used that in a bunch of my apps, then you can just grab the 4 buttons and simulate a click every 115 ms looping through them
Christopher McCormack
@cmccormack
Apr 18 2018 19:49
lodash beat for deep, yours for shallow
Nate Mallison
@NJM8
Apr 18 2018 19:49
by how much?
roughly
Christopher McCormack
@cmccormack
Apr 18 2018 19:50
not too much but I reloaded
about 1.5ms
there may be an import time required but I don't know your source - did you copy lodash over?
Nate Mallison
@NJM8
Apr 18 2018 19:51
On my cpu i beat lodash 4X on deep and 2X on shallow, but forkerino tested on his cpu and lodash was 2X faster on both
I didn't but my deep runs first, lodash should be loaded by then
forkerino @forkerino exits lurk mode
Ingram Jones
@Iggy1906
Apr 18 2018 19:51
@NJM8 Yes. If you look at the pen that function is in there twice. The one that has been commented out. It's commented out because it works. The I posted here doesn't work and I'm trying to figure out why it doesn't work . I'm being very anal in that I need to know what the problem is with the function that doesn't work. To me it looks the same as the one that does work. I can't find the error in the code.
Pieter Stokkink
@forkerino
Apr 18 2018 19:52
@NJM8 It was 2x for the deep, but only 10% faster for the shallow
Ingram Jones
@Iggy1906
Apr 18 2018 19:52
@cmccormack What's dangerous and why?
Nate Mallison
@NJM8
Apr 18 2018 19:53
speak of the devil
Christopher McCormack
@cmccormack
Apr 18 2018 19:54
@Iggy1906 dangerous from a refactoring standpoint - you're basically breaking the second class out of your element directly, if you changed something you could break something somewhere else
probably not your current issue but not great
Nate Mallison
@NJM8
Apr 18 2018 19:54
@forkerino I was thinking of adding more comparisons with various frameworks and taking advantage of webworkers on cloudflare to do the work
Christopher McCormack
@cmccormack
Apr 18 2018 19:54
although it could be, put some log statmeents in and make sure variables are what you think they are
Pieter Stokkink
@forkerino
Apr 18 2018 19:56
@NJM8 sounds like fun!
Christopher McCormack
@cmccormack
Apr 18 2018 19:57
does it? :)
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 19:58
@forkerino round 2?:D
Pieter Stokkink
@forkerino
Apr 18 2018 20:00
sure
Kelechi Chinaka
@ke1echi
Apr 18 2018 20:02
:wave: guys
what project are you working on @tiagocorreiaalmeida
Christopher McCormack
@cmccormack
Apr 18 2018 20:03
@kelechy heya
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 20:03
a ticket system just to pratice a bit more of node + react, nothing too fancy :D
Kelechi Chinaka
@ke1echi
Apr 18 2018 20:06
:wave: @cmccormack
Christopher McCormack
@cmccormack
Apr 18 2018 20:08
@tiagocorreiaalmeida that's the kind of stuff you do there?
maybe I will partake
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 20:09
@cmccormack no, my job its mostly related to helpdesk, even tough I will change of job in the next weeks
part of the proejct or the codefight ?:D
Christopher McCormack
@cmccormack
Apr 18 2018 20:10
I assumed you were talking about codefight
haha
new job? nice!
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 20:10
yeah, nodejs developer, sounds good lets hope it goes well too :D
Kelechi Chinaka
@ke1echi
Apr 18 2018 20:11
congrats @tiagocorreiaalmeida
Christopher McCormack
@cmccormack
Apr 18 2018 20:11
awesome congratulations @tiagocorreiaalmeida !
Kelechi Chinaka
@ke1echi
Apr 18 2018 20:11
u finished backend section on fcc? @tiagocorreiaalmeida
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 20:12
thank you @kelechy and @cmccormack , yes I did some time ago
CamperBot
@camperbot
Apr 18 2018 20:12
tiagocorreiaalmeida sends brownie points to @kelechy and @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 329 | @kelechy |http://www.freecodecamp.org/kelechy
:star2: 1415 | @cmccormack |http://www.freecodecamp.org/cmccormack
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 20:12
@cmccormack come for the fight :D
Christopher McCormack
@cmccormack
Apr 18 2018 20:12
Maybe after work :)
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 20:15
let me know when you are home then if Im around we can do one or two :), how's work going?
Christopher McCormack
@cmccormack
Apr 18 2018 20:15
super busy right now, way behind on projects because of so many other projects
Christopher McCormack
@cmccormack
Apr 18 2018 20:21
But i'll let you know sounds fun
Pieter Stokkink
@forkerino
Apr 18 2018 20:21
@tiagocorreiaalmeida gg
close call
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 20:22
yeah @forkerino, always faster than me :D
wanna come on this one? probably my last one today, https://codefights.com/tournaments/DhZf639uGtgmLFqiC its public tough
Pieter Stokkink
@forkerino
Apr 18 2018 20:28
sure
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 20:29
@forkerino doesnt back from a fight :D
Pieter Stokkink
@forkerino
Apr 18 2018 20:29
last one for me too
Jason Luboff
@JLuboff
Apr 18 2018 20:29
:wave:
@tiagocorreiaalmeida Psh... @cmccormack is always home ;)
Christopher McCormack
@cmccormack
Apr 18 2018 20:31
haha
I'm in my work corner how about that
Jason Luboff
@JLuboff
Apr 18 2018 20:32
Fair enough
Gulsvi
@gulsvi
Apr 18 2018 20:34

Okay, back to the basics question...

for(var i = 0; i < 5; i++){
  console.log(i);
}

and

for(var i = 0; i < 5; ++i){
  console.log(i);
}
I haven't seen the second syntax before - ++i I thought would increment the variable before it's used the first time
Christopher McCormack
@cmccormack
Apr 18 2018 20:35
@gulsvi increment i first
Gulsvi
@gulsvi
Apr 18 2018 20:35
But both for loops do exactly the same thing
0, 1, 2, 3, 4
I was thinking the second one would do 1, 2, 3, 4
Christopher McCormack
@cmccormack
Apr 18 2018 20:36
nope i believe they do the same thing in that context as it's after the conditional
Jason Luboff
@JLuboff
Apr 18 2018 20:36
If I remember correctly.. the iterator iterates after the loop runs (if that wording makes sense)
Gulsvi
@gulsvi
Apr 18 2018 20:36
Yeah @JLuboff that's what I was trying to explain and taking forever to write out lol
Okay, thanks @cmccormack and @JLuboff - rubber ducky debugging help
CamperBot
@camperbot
Apr 18 2018 20:37
gulsvi sends brownie points to @cmccormack and @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2404 | @jluboff |http://www.freecodecamp.org/jluboff
:star2: 1416 | @cmccormack |http://www.freecodecamp.org/cmccormack
Ingram Jones
@Iggy1906
Apr 18 2018 20:38
Useless, ugh!
Pieter Stokkink
@forkerino
Apr 18 2018 20:40
@tiagocorreiaalmeida good game!
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 20:41
thanks, almost did the D one :\
Pieter Stokkink
@forkerino
Apr 18 2018 20:41
I was working on it
I probably should have a look at all challenges before going into any of them
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 20:41
yeah eheh
alpox
@alpox
Apr 18 2018 20:42
I rly read too slow for those challenges
Pieter Stokkink
@forkerino
Apr 18 2018 20:42
well, good night!
@alpox hahaha
yeah
Christopher McCormack
@cmccormack
Apr 18 2018 20:42
night man
forkerino @forkerino is off
Jason Luboff
@JLuboff
Apr 18 2018 20:42
Night
alpox
@alpox
Apr 18 2018 20:42
The challenge was gone after i read half of the text of the second challenge
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 20:42
see you tomorrow @forkerino
alpox
@alpox
Apr 18 2018 20:42
and for finishing the first challenge i needed like 5 sec after i read its text
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 20:43
@alpox the trick here is start from the last 3 :\
the first 2 are there to make a fix or complete the others its for you to write a entire solution
alpox
@alpox
Apr 18 2018 20:44
I saw
But still to make the fix i read too long :D
There is like a page of text which you cannot even read in time
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 20:46
yeah true tough
Jason Luboff
@JLuboff
Apr 18 2018 20:57
uuugggghhhh... i hate network licenses
Christopher McCormack
@cmccormack
Apr 18 2018 21:00
you always get the fun work
Jason Luboff
@JLuboff
Apr 18 2018 21:00
Its all fucked up :'(
Tiago Correia
@tiagocorreiaalmeida
Apr 18 2018 21:50
@JLuboff may I ask what have you been building using nodejs and sql? trying to get an idea my self to give a try on with using sql this time
Brittany Rutherford
@brittanyrutherford
Apr 18 2018 21:57
is anyone familiar with npm packages versioning?
anthonygallina1
@anthonygallina1
Apr 18 2018 22:02
@brittanyrutherford maybe try the back end chat room? https://gitter.im/FreeCodeCamp/HelpBackEnd
Brittany Rutherford
@brittanyrutherford
Apr 18 2018 22:12
@anthonygallina1 thanks!
CamperBot
@camperbot
Apr 18 2018 22:12
brittanyrutherford sends brownie points to @anthonygallina1 :sparkles: :thumbsup: :sparkles:
:star2: 5872 | @anthonygallina1 |http://www.freecodecamp.org/anthonygallina1
Gulsvi
@gulsvi
Apr 18 2018 22:30
I need a rubber ducky again. Why doesn't this remove all the ones?
const ARR = [0, 1, 1, 0, 1, 0, 1, 0];

function removeOnes(arr) {
  let i = 0;

  while (i < arr.length) {
    if (arr[i] === 1) arr.splice(i, 1);
    i++;
  }

  return arr;
}

console.log(removeOnes(ARR)); // [0, 1, 0, 0, 0]
Christopher McCormack
@cmccormack
Apr 18 2018 22:37
@gulsvi don't increment 1 if you're splicing!
never modify an array you're iterating over
you have a case where you removed the first 1, then that shifted the next 1 in its place, but you incremented past it
Gulsvi
@gulsvi
Apr 18 2018 22:38
Amazing how quickly I get stumped on these stupid things lol! Thanks @cmccormack splice/slice I need to remember the difference
CamperBot
@camperbot
Apr 18 2018 22:38
gulsvi sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1417 | @cmccormack |http://www.freecodecamp.org/cmccormack
Christopher McCormack
@cmccormack
Apr 18 2018 22:38
@gulsvi yeah but slice wouldn't work here
Gulsvi
@gulsvi
Apr 18 2018 22:38
I'm trying to sort a bit array with a while loop
Christopher McCormack
@cmccormack
Apr 18 2018 22:38
not in place anyhow
filter not good enough? haha
Gulsvi
@gulsvi
Apr 18 2018 22:40
lol, that's what I would normally use, but practicing projects - sort a bit array in place with a while loop :eyeroll: :)
Christopher McCormack
@cmccormack
Apr 18 2018 22:43
ohhh ok
Gulsvi
@gulsvi
Apr 18 2018 23:01
This seems to work, but not sure if there's a better way - seems O(n)? and the challenge says to try for O(1)...
function sortBitArray(arr) {
  let start = 0;
  let end = arr.length - 1;

  while (start < end) {
    if (arr[start] === 0) start++;
    if (arr[end] === 1) end--;
    if (start < end) [arr[start], arr[end]] = [arr[end], arr[start]];
  }
}
Christopher McCormack
@cmccormack
Apr 18 2018 23:03
using a while loop getting O(1)?
hmm I'd have to think about it
is it something like [0,1,0,1,1,1,0,0] becomes [1,1,1,1,0,0,0,0]?
Gulsvi
@gulsvi
Apr 18 2018 23:04
Yeah, unless the array length is guaranteed to be the same length every time, I don't get it
Yes, exactly
0 on the left, 1 on the right, but same idea
Christopher McCormack
@cmccormack
Apr 18 2018 23:05
ok
you could probably do it with recursion faster
probably not much faster
I dunno weird one, if it wasn't for a while loop requirement I would try and think of a mathematical way to do it
Jason Luboff
@JLuboff
Apr 18 2018 23:08
@tiagocorreiaalmeida I'll DM you when I get a chance
Christopher McCormack
@cmccormack
Apr 18 2018 23:08
you could have told him that in a DM!
Jason Luboff
@JLuboff
Apr 18 2018 23:09
@cmccormack I DM'd you
Gulsvi
@gulsvi
Apr 18 2018 23:09
I'll DM you that I'm gonna DM you again when I get a chance :)
Christopher McCormack
@cmccormack
Apr 18 2018 23:09
Hah
Jason Luboff
@JLuboff
Apr 18 2018 23:09
Network licenses are all fuckkked right now lol
Kicking people out of software haha
Christopher McCormack
@cmccormack
Apr 18 2018 23:10
always blaming the network
Jason Luboff
@JLuboff
Apr 18 2018 23:10
Network is solid
License manager is garbage
Christopher McCormack
@cmccormack
Apr 18 2018 23:10
those words are foreign to me
Jason Luboff
@JLuboff
Apr 18 2018 23:11
Which words? lol
Christopher McCormack
@cmccormack
Apr 18 2018 23:11
Network is solid
Noone ever says that to my team, always complaining
Jason Luboff
@JLuboff
Apr 18 2018 23:39
@cmccormack Lol... well... it's fairly solid.. in the office..the over all WAN may not be quite as solid
Christopher McCormack
@cmccormack
Apr 18 2018 23:44
WAN is hard, many times out of your control and often attacked for no good reason
Jason Luboff
@JLuboff
Apr 18 2018 23:45
Ya... and we've been changing circuits/ISP's so...that introduces a lot of headaches
Like the fact that our offshore facilities are all going through a VPN to our Texas location :worried:
(Temporary but its been in place for several months and will be for several more I believe)
anthonygallina1
@anthonygallina1
Apr 18 2018 23:50
i just saw a bear with laser beam eyes
Jason Luboff
@JLuboff
Apr 18 2018 23:50
@anthonygallina1 That sounds both awesome and scary
anthonygallina1
@anthonygallina1
Apr 18 2018 23:51
wanna see?
Jason Luboff
@JLuboff
Apr 18 2018 23:51
It's not a trick is it?
anthonygallina1
@anthonygallina1
Apr 18 2018 23:52
Nope I need to get vpn one of these days
Jason Luboff
@JLuboff
Apr 18 2018 23:52
Ah haha
anthonygallina1
@anthonygallina1
Apr 18 2018 23:52
:)