These are chat archives for FreeCodeCamp/Help

9th
Mar 2019
b3twiise
@b3twiise
Mar 09 00:31
@ezioda004 that seems to be open to sql injection
Jason Luboff
@JLuboff
Mar 09 00:33
I heard SQL
idris
@idris12
Mar 09 03:36
hello so i this code am trying to get
11,5,12 but the for loop keeps crashing what am i doing wrong

function diagonalDifference(arr) {
for(var i=0; i<arr.length; i+4){
console.log(arr[i]);

}

}
diagonalDifference([11,2,4,4,5,6,10,8,12]);

Kyle Holm
@thekholm80
Mar 09 03:49
@idris12 i believe you need for(var i=0; i<arr.length; i+=4){ or for(var i=0; i<arr.length; i=i+4){ instead of just i+4. you're not actually changing the value of i each loop, so it's infinite
kinopotato
@kinopotato
Mar 09 04:30
Untitled.jpg
Hello people, was looking for some advice, I was thinking of making the chevron (>) into a link or maybe some kind of element where if I hover my mouse something appears and that will turn the blocks below into something else.
my question is, how do I let people know that that chevron is a link?
or interactable, without them having to mouse over it for an effect to trigger
nevermind, I'm going with an animation
kinopotato
@kinopotato
Mar 09 05:57

anyone got any idea why this code works in codepen

let a = document.querySelectorAll("#a");

a[0].classList.toggle("display--hidden");
a[1].classList.toggle("display--hidden");

but gets a type error cannot read property of undefined when run in chrome??

kinopotato
@kinopotato
Mar 09 06:23
it seems I can't select anything in vs code and I have no clue why
WTF! now it's working! I didn't do anything, and it's just working! wtaf!
screw this, I'm going to eat!
Niraj Nandish
@Nirajn2311
Mar 09 07:07
@kinopotato life works in a strange way when you're hungry
kinopotato
@kinopotato
Mar 09 07:55
a fox said it so I accept it as true
Niraj Nandish
@Nirajn2311
Mar 09 08:30
😂😂
yj
@atangyj
Mar 09 15:35
Hi, I am wondering how to define styles that can be applied to all components files in react instead of importing a shared style file to each component file.
kinopotato
@kinopotato
Mar 09 16:49
hello, is my syntax wrong? it's triggering the function for some reason even tho I don't click on anything
const switchFront = (id) => {
  let sectionArr = document.querySelectorAll(".section");
  debugger;
  sectionArr.forEach(function(elem, index){
    elem.classList.add("display--hidden")
  });

  if (id === "about"){
    document.querySelector("#about").classList.remove("display--hidden");
  }
  }

document.querySelector("#aboutBtn").addEventListener("click", switchFront("about"));
Kyle Holm
@thekholm80
Mar 09 16:56
@kinopotato document.querySelector("#aboutBtn").addEventListener("click", switchFront("about")); the switchFront("about") is adding the result of the function call, not the function itself
kinopotato
@kinopotato
Mar 09 16:56
what do you mean with "adding the result"?
Kyle Holm
@thekholm80
Mar 09 16:57
function myFunction() {
  // do stuff
}
const copy = myFunction;  // copy will be a copy of the function
const result = myFunction(); // result will be the result of calling the function
if you add the () after a function, it will call the function
kinopotato
@kinopotato
Mar 09 16:59
I thought it would wait for the click, hmm, how do I add a parameter to the function then if I can't use ()?
Kyle Holm
@thekholm80
Mar 09 16:59
so in your code, the switchFront("about") will call the function when it creates the event listener, and assign the result of the function call to the event handler
which will be undefined since your function doesn't return anything
kinopotato
@kinopotato
Mar 09 17:00
would I be able to add a parameter to addEventListener syntax since I can't use ()?
Aditya
@ezioda004
Mar 09 17:01

I thought it would wait for the click, hmm, how do I add a parameter to the function then if I can't use ()?

You dont, the function is being called from someother place and the argument is passed by the listener after the event occurs

Kyle Holm
@thekholm80
Mar 09 17:01
maybe wrap it in an anonymous function? () => switchFront("about")
then you're passing a function that will call your function with a param
kinopotato
@kinopotato
Mar 09 17:02
how do these syntax keep popping up xD I thought I already knew these things
Kyle Holm
@thekholm80
Mar 09 17:02
lol you'll get there
kinopotato
@kinopotato
Mar 09 17:02
alright lemme try it
Kyle Holm
@thekholm80
Mar 09 17:02
@ezioda004 :wave:
Aditya
@ezioda004
Mar 09 17:03
@thekholm80 :wavy_dash:
Long time, no see
kinopotato
@kinopotato
Mar 09 17:03
wow that worked
wow,
Kyle Holm
@thekholm80
Mar 09 17:03
i'm usually lurking somewhere, just super busy now
kinopotato
@kinopotato
Mar 09 17:03
an anonymous function that returns/calls another function, super sneaky
JS is super sneaky
Kyle Holm
@thekholm80
Mar 09 17:04
that's a pretty common pattern, i believe
when i was working with React i used it a ton
kinopotato
@kinopotato
Mar 09 17:05
hmm, I'll have to get used to this mindset. anyway thanks @thekholm80 and @ezioda004. I learned something new again :D
Kyle Holm
@thekholm80
Mar 09 17:05
np
Aditya
@ezioda004
Mar 09 17:06
@kinopotato I barely helped, double thanks to @thekholm80
@thekholm80 Do you code these days?
idris
@idris12
Mar 09 17:06
hi so theres a problem on hacker rank that am trying to solve but am getting stuck heres the link
Kyle Holm
@thekholm80
Mar 09 17:06
@ezioda004 no, sadly i don't. i'm trying to learn electronics, i don't have any brain cells left over for code
Aditya
@ezioda004
Mar 09 17:08
@thekholm80 Electronics? Sounds cool, hows that coming?
Kyle Holm
@thekholm80
Mar 09 17:08
there's so much math involved. i'm not that great at math
but it's super interesting
Aditya
@ezioda004
Mar 09 17:12
Somedays I love math, but most days I dont
Kyle Holm
@thekholm80
Mar 09 17:14
@ezioda004 are you all settled into your new job?
i guess it's not that new anymore
Aditya
@ezioda004
Mar 09 17:17
@thekholm80 Yeah I'd say so
Somedays are monotonic, work, sleep, repeat
Kyle Holm
@thekholm80
Mar 09 17:19
I will say this: one advantage electronics has over software dev is all the cool toys I get to use. Multi-Meters, Oscilloscopes, Function Generators, etc.
monotony ... yeah i can see that
Aditya
@ezioda004
Mar 09 17:22

Multi-Meters, Oscilloscopes, Function Generators, etc.

Woah, those sound big boy toys

May Kittens Devour Your Soul
@diomed
Mar 09 17:22
oscilloscope stagnating
psyperl
@psyperl
Mar 09 17:23
can function generators creates JS functions?
Aditya
@ezioda004
Mar 09 17:23
@thekholm80 Are you making a time machine?
Kyle Holm
@thekholm80
Mar 09 17:23
lol
i am, but it just wastes time
no time travel
Aditya
@ezioda004
Mar 09 17:25
I'll give you 5$ for one
idris
@idris12
Mar 09 17:27
what does this mean
var rows = input.trim().split(/\n/),
fajar12345
@fajar12345
Mar 09 17:27
does anyone here know how to pass by this Responsive Web Design Projects - Build a Survey Form, and how to send the result that I wrote in FCC: Tribute page?
Kyle Holm
@thekholm80
Mar 09 17:30
@idris12 trim() removes any spaces from the beginning and end of a string, and split() will return an array where each element is a portion of the string that has been separated by the /\n/, regex for new line? i think. i'd have to look it up
May Kittens Devour Your Soul
@diomed
Mar 09 17:31
@fajar12345 what?
why bypass?
Niraj Nandish
@Nirajn2311
Mar 09 18:14
@thekholm80 nice, for a second there i thought you were building the TARDIS
Kyle Holm
@thekholm80
Mar 09 18:18
@Nirajn2311 how cool would that be?
BuntyBru
@BuntyBru
Mar 09 18:37
can function generators creates JS functions?
haha
Niraj Nandish
@Nirajn2311
Mar 09 19:29
@thekholm80 so cool that i would be a rich marty mcfly
idris
@idris12
Mar 09 19:33
Hi so i was reading about a solution on about 2d arrays where we have to get their diagonals add them up and get absolute value
here are the values [[2, 3], [4, 0]]
Heres the solution
but i dont understand line 12 could someone explain
BuntyBru
@BuntyBru
Mar 09 19:42
@idris12
codepen is empty
i put it there now
Philip Durbin
@pdurbin
Mar 09 21:28
What's the problem?