These are chat archives for FreeCodeCamp/HelpJavaScript

1st
Nov 2018
Pagnito
@Pagnito
Nov 01 2018 01:31
white or black?
Screen Shot 2018-10-31 at 9.31.18 PM.png
Screen Shot 2018-10-31 at 9.31.11 PM.png
ehutchllew
@ehutchllew
Nov 01 2018 02:02
neither lol
but if it has to be one, i guess the white one.
Pagnito
@Pagnito
Nov 01 2018 02:28
u think its bad?
@ehutchllew
Nitin
@thenm
Nov 01 2018 10:36
Hi all . I want array element to be pushed only unique value .
Aditya
@ezioda004
Nov 01 2018 10:46
@thenm Sounds like you need a Set object.
Nitin
@thenm
Nov 01 2018 10:54
var result = [{
      reason: 'abc',
      reasonid: 1
    }, {
      reason: 'cac',
      reasonid: 2
    }, {
      reason: 'aac',
      reasonid: 1
    }]

should be like

[{
      reasonid: 1
       reasons: ['abc', 'aac']
},
{
      reason:[ 'cac'],
      reasonid: 2
}]

@ezioda004

Aditya
@ezioda004
Nov 01 2018 10:57
@thenm So before pushing check if reasonid exists? If it does then push the value into the reasons array.
You'd need to use a loop.
Nitin
@thenm
Nov 01 2018 11:13
How do I push it when the result array is empty for the first time?
@ezioda004
Kudzu
@czhower
Nov 01 2018 15:09
if array is empty the length will be 0 if you need to know that. otherwise just push to it
Jason Luboff
@JLuboff
Nov 01 2018 15:10
Morning :wave:
Tom
@moT01
Nov 01 2018 15:21
hello
Christopher McCormack
@cmccormack
Nov 01 2018 15:23
heya
Jason Luboff
@JLuboff
Nov 01 2018 15:25
Whats up guys
Christopher McCormack
@cmccormack
Nov 01 2018 15:26
just a whole lot of nothing
Tom
@moT01
Nov 01 2018 15:27
you guys know if there are any dangers with plugging usb devices with mismatching voltages
Christopher McCormack
@cmccormack
Nov 01 2018 15:28
depends on the device
Tom
@moT01
Nov 01 2018 15:28
i have two little speakers that plug into usb for power, says 3.7v 500mA on each
i think most usb is 5v
Christopher McCormack
@cmccormack
Nov 01 2018 15:28
usually for small voltage differences it will just mean slower charge
Tom
@moT01
Nov 01 2018 15:29
so not really dangerous
Jason Luboff
@JLuboff
Nov 01 2018 15:29
Usually its the amp's the is the bigger concern
Tom
@moT01
Nov 01 2018 15:31
the amp's the the the speaker the draws, right?
i suppose I need to make sure it's not overdrawing
Jason Luboff
@JLuboff
Nov 01 2018 15:33
Ya and what the power source provides..and actually usually if amp's are higher its not a huge deal but I'm speaking from a laptop charger standpoint. For example, an Apple Macbook used a 65W where as a Macbook Pro used 90W, but you could use the 90W on the Macbook no problem. (My wattages might be off there)
Tom
@moT01
Nov 01 2018 15:35
so basically I just need to make sure I have 1000+mA from my power
Jason Luboff
@JLuboff
Nov 01 2018 15:43
...maybe..
Tom
@moT01
Nov 01 2018 15:44
maybe
thats not very reassuring
Jason Luboff
@JLuboff
Nov 01 2018 15:46
I'm no electrical engineer... lol
Tom
@moT01
Nov 01 2018 15:48
that sounds right to me
but im not sure either
Jason Luboff
@JLuboff
Nov 01 2018 15:49
Just plug em in!
Tom
@moT01
Nov 01 2018 15:49
well, I did - there's no immediate problem
but they might be going in my arcade, and possibly left on for a long time or something and constantly plugged in
Jason Luboff
@JLuboff
Nov 01 2018 16:00
It'll probably be fine..but..don't quote me
Tom
@moT01
Nov 01 2018 16:20
that's what I'll tell the insurance
jason said it would be good
Jason Luboff
@JLuboff
Nov 01 2018 16:23
:anguished:
Jason Luboff
@JLuboff
Nov 01 2018 16:28
Aaaahhh...getting lost in my code
Jason Luboff
@JLuboff
Nov 01 2018 16:53
Now I'm just unhappy with my data structure..but.. it works.. but.. it requires a lot of loops to get through :(
Brad
@bradtaniguchi
Nov 01 2018 17:26
@JLuboff You still going about your data-structure problems haha?
Jason Luboff
@JLuboff
Nov 01 2018 17:26
@bradtaniguchi YA :(
Brad
@bradtaniguchi
Nov 01 2018 17:27
how many loops we talking about
Jason Luboff
@JLuboff
Nov 01 2018 17:27

@bradtaniguchi This is what I have... I need to group each step together with different hazards and controls

[
  {
    "stepNumber": 1,
    "stepDescription": "qwerewrweq",
    "hazardAndControls": [
      {
        "hazardID": "8",
        "hazardName": "Chemical Hazard (Corrisive)",
        "controlIDs": [
          "28",
          "27"
        ],
        "controlNames": [
          "Wear appropriate respiratory protection identified on SDS sheet",
          "Read and follow information given on chemicals SDS sheet"
        ]
      },
      {
        "hazardID": "9",
        "hazardName": "Chemical Hazard (Flammable)",
        "controlIDs": [
          "33",
          "31"
        ],
        "controlNames": [
          "Keep the flammable liquid containers closed when not in use",
          "Identify closest first aid and wash stations"
        ]
      },
      {
        "hazardID": "11",
        "hazardName": "Cuts",
        "controlIDs": [
          "31",
          "40"
        ],
        "controlNames": [
          "Identify closest first aid and wash stations",
          "Never leave an exposed blade unattended"
        ]
      }
    ]
  },
  {
    "stepNumber": 2,
    "stepDescription": "werwer",
    "hazardAndControls": [
      {
        "hazardID": "11",
        "hazardName": "Cuts",
        "controlIDs": [
          "39",
          "40"
        ],
        "controlNames": [
          "Use the proper tool for the job at hand",
          "Never leave an exposed blade unattended"
        ]
      }
    ]
  }
]

So.. 3... :(

Brad
@bradtaniguchi
Nov 01 2018 17:29
3? that's nothing haha, but it looks fine to me for the most part
Jason Luboff
@JLuboff
Nov 01 2018 17:30
@bradtaniguchi Anything you would do differently?
And I just hate nesting loops.. but..I guess it'll be quick enough lol
Brad
@bradtaniguchi
Nov 01 2018 17:30
The only thing that stands out are the controlIds and controlNames, are they related? I think nested loops are a necessary evil, no matter what were talking about and array of items, that has an array of items
Jason Luboff
@JLuboff
Nov 01 2018 17:31
Yes, ControlID is the database ID of the corresponding ControlName
I guess therotically I could make that an object instead, but I'm using them in different places
Brad
@bradtaniguchi
Nov 01 2018 17:32
Yea I would have combined them to be just "controls" and make them an array of objects with id and name, but its a very minor gipe
Jason Luboff
@JLuboff
Nov 01 2018 17:33
What would be your reasoning? Organization? I'm curious as you have a CS background
Brad
@bradtaniguchi
Nov 01 2018 17:34
In general or for the nested controls?
Jason Luboff
@JLuboff
Nov 01 2018 17:34
nested controls
Brad
@bradtaniguchi
Nov 01 2018 17:37
Well thinking about it from a (relational) database standpoint, I assume the controls would be it's own table. From an OOP standpoint they would be a single object to relate to the table, and from a UI standpoint Id pass around the entire control object instead of separate properties. Maybe tomorrow you might have controlDescription, and having separate arrays of attributes of a single object is harder to deal with than 1 object with multiple attributes.
Jason Luboff
@JLuboff
Nov 01 2018 17:39

Thanks :) Interesting thing is.. this is how I send my hazards/controls to my frontend

[
{
    "Hazard": [
      {
        "11": "Cuts"
      }
    ],
    "Controls": [
      {
        "41": "Cut away from the body"
      },
      {
        "31": "Identify closest first aid and wash stations"
      },
      {
        "42": "Identity cut hazards and avoid"
      },
      {
        "5": "Keep the work area clear"
      },
      {
        "43": "Keep tools in good working order, clean, and blades sharp"
      },
      {
        "40": "Never leave an exposed blade unattended"
      },
      {
        "39": "Use the proper tool for the job at hand"
      },
      {
        "38": "Wear cut resistant gloves"
      }
    ]
  }
]

But then I'm manipulating it differently on the front end.. but I definitely get your point of keeping everything related

So perhaps having it be {controlID : id, controlName: name} here would be better too instead of using the id as my key
alpox
@alpox
Nov 01 2018 17:41
@JLuboff Hey man, sry, was out at the time you wrote :)
Jason Luboff
@JLuboff
Nov 01 2018 17:41
@alpox No worries, was going to get your opinion on my data structure :) (the first one, not the second)
alpox
@alpox
Nov 01 2018 17:42
@JLuboff Uh what is a hazard and what is a control? (:
I handle datastructures like the first one atm and its going quite well
Jason Luboff
@JLuboff
Nov 01 2018 17:44
@alpox A hazard is a potential problem, and the control is what steps that will be taken to ensure the hazard does not cause a problem
alpox
@alpox
Nov 01 2018 17:44
Ah I see
Brad
@bradtaniguchi
Nov 01 2018 17:44
@JLuboff Oh yea you could use a map with the id being the key, would make lookups uber fast
Jason Luboff
@JLuboff
Nov 01 2018 17:44
There can be multiple hazards per step of the job, and multiple controls per hazard
alpox
@alpox
Nov 01 2018 17:45
@bradtaniguchi Right on. I did that several times
Brad
@bradtaniguchi
Nov 01 2018 17:45
As I said yesterday hashmap is the best :P
Jason Luboff
@JLuboff
Nov 01 2018 17:46
@bradtaniguchi Ya.. doing that on the backend, can't remember if I'm doing that on the frontend lol
@alpox So you would agree with @bradtaniguchi that its a decent structure than?
Brad
@bradtaniguchi
Nov 01 2018 17:47
Once you get the data on the front-end you can do whatever you want, the backend could be optimized to send the Controls array as an object, instead of an array of objects. Obviously duplicate ids would create collisions idk if that could happen tho
save on bits over the wire :D
alpox
@alpox
Nov 01 2018 17:47
@JLuboff Using hashmaps for the hazards would improve this as @bradtaniguchi said, else it looks fine to me
Jason Luboff
@JLuboff
Nov 01 2018 17:48
@bradtaniguchi Eh...not terribly concerned about over the wire... its all internal to our network
@alpox Awesome, thanks
You both have made me feel more confident :)
I don't know enough about hashmaps...so I'll stick with this lol
Brad
@bradtaniguchi
Nov 01 2018 17:49
Haha yea, what you have isn't bad at all. You should be fine if you did nothing haha. (just watch out on the nested control attributes hehe)
Jason Luboff
@JLuboff
Nov 01 2018 17:50
:smile:
alpox
@alpox
Nov 01 2018 17:51
@JLuboff What confuses me a bit is that in the datastructure you showed you have two hazards with the same id 11 in two steps with the same names but different controls. How is that possible? :D
I'd have said you could normalize a bit more else with putting only hazard ids into the steps to avoid duplication
Jason Luboff
@JLuboff
Nov 01 2018 17:53
@alpox So what I'm building is whats known as a JSA (Job Safety Analysis). An individual will put in however many steps there are to their job. Afterwards, they select all hazards (and controls) that can be an issue for that step. You can have the same hazard (and controls) for multiple steps
alpox
@alpox
Nov 01 2018 17:54
I see. But that hazard should be the same one then (with the same controls) right
So the datastructure above is a bit off :D
Jason Luboff
@JLuboff
Nov 01 2018 17:54
No, not necessarily, there can be different controls
To be a little clearer, the user selects a hazard, at which point they are presented with all potential controls for that hazard
depending on the step, it could be a different set of controls
alpox
@alpox
Nov 01 2018 17:55
Hmm alright I see
Jason Luboff
@JLuboff
Nov 01 2018 17:55
I do get where you're going with it though
alpox
@alpox
Nov 01 2018 17:55
Seems fine then :D
Jason Luboff
@JLuboff
Nov 01 2018 17:55
More often than not, ya I'd think the controls would be the same but I never fill these out or look at them lol
alpox
@alpox
Nov 01 2018 17:56
I'd just maybe have taken a bit a different structure then
Jason Luboff
@JLuboff
Nov 01 2018 17:58
Fair enough :)
alpox
@alpox
Nov 01 2018 17:58
{
        "hazardID": "9"
        "controlIDs": [
          "33",
          "31"
        ]
}

....
// Hazards
{
   "9": { "id": "9", "name": "..." }
}
...
// Controls
{
  "33": { "id": "33", "name": "..." },
  "31": { "id": "31", "name": "..." }
}
I guess more like this
Putting properties from the hazard and the controls on the same level looks like a mashup to me
Jason Luboff
@JLuboff
Nov 01 2018 18:00
My thought process was that it keeps the specific controls contained with the related hazard
Brad
@bradtaniguchi
Nov 01 2018 18:01
Controls only relate to 1 hazard right?
Jason Luboff
@JLuboff
Nov 01 2018 18:01
No, the same controls can relate to multiple hazards
Brad
@bradtaniguchi
Nov 01 2018 18:07
Oh.... >.>
So do
you duplicate the controls to each hazard if they are shared?
Jason Luboff
@JLuboff
Nov 01 2018 18:09
Ya.. its all based off my table structure from the database. Each control has a one-to-many relationship
Brad
@bradtaniguchi
Nov 01 2018 18:31
Ah I see, I guess it depends on how much processing you want todo later, say you take aplox approach, you'd have to spend time looking up controls and what not
Jason Luboff
@JLuboff
Nov 01 2018 18:34
Ya, I'm trying to structure it as best as I can to conform to my needs once I send the data to the backend as well
Brad
@bradtaniguchi
Nov 01 2018 18:43
yes
Jason Luboff
@JLuboff
Nov 01 2018 18:55
indeed
Brad
@bradtaniguchi
Nov 01 2018 18:57
hehe I'm in node_modules code debugging hehe
Jason Luboff
@JLuboff
Nov 01 2018 18:58
That...that does not sound fun...
Thats like...a deathtrap
Brad
@bradtaniguchi
Nov 01 2018 19:00
It's my node_modules code of a shared lib. So it's not that bad, but yea... not the best. Debugger to the rescue!
Dany Din
@danydin
Nov 01 2018 20:29
is there any active chat groups on the internet
Jason Luboff
@JLuboff
Nov 01 2018 20:30
Er.. active in what regard?
Dany Din
@danydin
Nov 01 2018 20:34
find like minded programmers i guess :p
Jason Luboff
@JLuboff
Nov 01 2018 20:34
Well... this chat is used.. the FCC help channel can be more active at times
alpox
@alpox
Nov 01 2018 20:34
@bradtaniguchi I almost broke my head on some css... my css managed to put my window.resize in an endless loop :/
Brad
@bradtaniguchi
Nov 01 2018 20:35
@alpox I hate CSS with a passion
Jason Luboff
@JLuboff
Nov 01 2018 20:35
@alpox Ewww... CSS... I mean...I'd love to be better at it...but...I'm not
I'm a loser and just use frameworks hah
alpox
@alpox
Nov 01 2018 20:35
@bradtaniguchi Me too... and yet I have to do too much with it... I'm on a project with 100000 animations and whatever stuff
My loop was the perfect fuckup before:
resize finds an element too big -> sets component state -> component state triggers update -> element gets bigger again -> resize handler is called because of update hook -> component state triggers update back to previous state as the element changed to bigger again.....
Ending in an oscillating element height, component state and resize handler
¯\_(ツ)_/¯
Brad
@bradtaniguchi
Nov 01 2018 20:38
Sounds fun :D
alpox
@alpox
Nov 01 2018 20:39
Yea very. Took me a moment to find the loop :D
Brad
@bradtaniguchi
Nov 01 2018 20:43
I have enough fun dealing with angular loops, dependency issues, I don't want to think about CSS loops :(
alpox
@alpox
Nov 01 2018 20:44
Ug thats no fun either
Lia-Sue-Kim
@Lia-Sue-Kim
Nov 01 2018 20:48
What do \you recommend for freelancing jobs
Sites like freelancer , upwork or fiver don't really work. I mean at least for me. People won't even reply there
Brad
@bradtaniguchi
Nov 01 2018 20:48
I was about to recommend those
Lia-Sue-Kim
@Lia-Sue-Kim
Nov 01 2018 20:49
There are some indian sites which is really hard to use their sites
Brad
@bradtaniguchi
Nov 01 2018 21:02
don't you go find jobs you want to do most of the time on freelancer?
enestatli
@enestatli
Nov 01 2018 21:10
from random import randint

board = []

for x in range(5):
  board.append(["O"] * 5)

def print_board(board):
  for row in board:
    print " ".join(row)

print_board(board)

def random_row(board):
  return randint(0, len(board) - 1)

def random_col(board):
  return randint(0, len(board[0]) - 1)

ship_row = random_row(board)
ship_col = random_col(board)
print ship_row
print ship_col

# Everything from here on should go in your for loop!
# Be sure to indent four spaces!
for turn in range(4):
  print "Turn", turn + 1
  guess_row = int(raw_input("Guess Row: "))
  guess_col = int(raw_input("Guess Col: "))


if guess_row == ship_row and guess_col == ship_col:
  print "Congratulations! You sunk my battleship!"
else:
  if (guess_row < 0 or guess_row > 4) or (guess_col < 0 or guess_col > 4):
    print "Oops, that's not even in the ocean."
  elif(board[guess_row][guess_col] == "X"):
    print "You guessed that one already."
  else:
    print "You missed my battleship!"
    board[guess_row][guess_col] = "X"
  print_board(board)
after every guess, how can I finis the game if guess is correct
or wrong print the board again
Dany Din
@danydin
Nov 01 2018 21:15
make all the options except for the correct one which just use else: break instead
@enestatli
then make another if else statement, if the number==guess else print your current else from the above example
enestatli
@enestatli
Nov 01 2018 21:17
if not True: print board else: print "you win"
Dany Din
@danydin
Nov 01 2018 21:18
check if the var of the guess is equal to the right number
in the new if else outside the loop ^
if it's not print your current else, if it is print you win
enestatli
@enestatli
Nov 01 2018 21:19
okay @danydin I will try smt
thank you!
enestatli
@enestatli
Nov 01 2018 21:31
putting whole if elif else statements into the for loop iteration, solves my problem. nice
Brad
@bradtaniguchi
Nov 01 2018 21:53
damn, one of my classes exploded in complexity, its nearing 1k lines! 600 of those lines are 10 different methods, all supporting 1 api call
DMZ
@DMZ011
Nov 01 2018 21:55
is there a way to change text of buttons with css only?
Tom
@moT01
Nov 01 2018 22:02
there's a content property when using :before or :after @DMZ011
Amit Patel
@AmitP88
Nov 01 2018 22:09

hey guys, I'm working on my pomodoro timer and I need a little help. When the work timer runs out and the break timer starts, if I try to pause the timer, it starts counting down twice as fast. I've looked over my code but I can't figure out what I'm doing wrong. (the function is runAfterWork starting on line 115)

https://codepen.io/AmitP88/pen/KRyjLw

DMZ
@DMZ011
Nov 01 2018 22:15
ouch, chat was frozen due to proxy
Christopher McCormack
@cmccormack
Nov 01 2018 22:15
@AmitP88 means you probably aren't using clearInterval on your previous interval
DMZ
@DMZ011
Nov 01 2018 22:15
@moT01 does it change the actual "value" for the button?
Christopher McCormack
@cmccormack
Nov 01 2018 22:15
haven't looked at the code yet but that's usually what it is
Amit Patel
@AmitP88
Nov 01 2018 22:16
@cmccormack I called resetTimer() though which uses clearInterval()
I'll give it a shot though
Tom
@moT01
Nov 01 2018 22:17
it can set the text of either of those elements @DMZ011
so you couldn't just say button { content: 'new text'; } you would have to create your button in the before or after pseudo-elements and do the whole thing there
somehow
Amit Patel
@AmitP88
Nov 01 2018 22:19
@cmccormack oh you know what, I think it also has to do with the play button setting after the timer runs out. Thanks though, you gave me an idea :)
Tom
@moT01
Nov 01 2018 22:20
<div></div>

div::before {
  width...height...etc...
  content: 'button';
}

div:hover::before {
  content: 'new text';
}
something like that is all I can think of @DMZ011, and that syntax might not right - you would have to play with it
I think that might work anyway
@cmccormack looks like the bleeding may have stopped
Christopher McCormack
@cmccormack
Nov 01 2018 22:25
@moT01 sounds so ominous haha
Tom
@moT01
Nov 01 2018 22:26
just so many that are so low effort and time consuming to go through
Christopher McCormack
@cmccormack
Nov 01 2018 22:27
yeah I've been trying in my free time but there's only so much time in the day and so busy with work right now
Pagnito
@Pagnito
Nov 01 2018 22:37
hey anyone know of a way to anchor a fixed element so it doesnt flow out of page on max-width
Screen Shot 2018-11-01 at 6.36.14 PM.png
DMZ
@DMZ011
Nov 01 2018 22:38
@moT01 :S :S :S :S
jquery is acting weird
DMZ
@DMZ011
Nov 01 2018 23:02
anyone knows why: $("input[id$='diidIOSaveItem']") or $("input[id*='diidIOSaveItem']") doesn't work? Knowing that I have a generated html that contains 2 inputs with ids that end with diidIOSaveItem
seems like jquery attribute selectors don't work at all.. like: $("input[value='Save']") doesn't work as well
Pagnito
@Pagnito
Nov 01 2018 23:30
is there a way to load page with a if statment if(internet connection high) or low etc
Brad
@bradtaniguchi
Nov 01 2018 23:33
@Pagnito yes, but I think handling such a situation isn't easy. Like if you find out the user has a slower internet what are you going todo and how will it affect your app
Pagnito
@Pagnito
Nov 01 2018 23:33
im gonna turn off some animations and stuff like that
turn off scroll events
Brad
@bradtaniguchi
Nov 01 2018 23:36
Are animations affected by slow internet?
Pagnito
@Pagnito
Nov 01 2018 23:41
yea i think so, they look really bad and arent smooth
i might b wrong tho, maybe its because certain phones suck or somethin
DMZ
@DMZ011
Nov 01 2018 23:43
i know what's goin on with jquery
iframes ..
not sure why dialogs are displayed as iframes ..
but it works now after all
Brad
@bradtaniguchi
Nov 01 2018 23:45
@Pagnito If your animations are CSS, you could turn off the animations if the screen gets too small. I assume its probably because the phone doesn't have enough graphical power to render the animations properly.
Pagnito
@Pagnito
Nov 01 2018 23:55
@bradtaniguchi yea u right i think its the gpu