These are chat archives for FreeCodeCamp/HelpJavaScript

27th
Apr 2018
Brad
@bradtaniguchi
Apr 27 2018 00:52
Good busy (whish is why im uber late here) @anthonygallina1
1Mher1
@1Mher1
Apr 27 2018 08:12
please help me to add game over when car and tank collide this is my code https://codepen.io/1Mher1/pen/rvWepK
1Mher1
@1Mher1
Apr 27 2018 09:45
please help my why my backspace dont remove input word

I tried this $(document).keyup((e)=>{
var k = e.key

if(e.keyCode == 8){
console.log(e.keyCode)
var d =$("#inp").val()
$("#inp").remove(k+d)

}

})

Pieter Stokkink
@forkerino
Apr 27 2018 10:16
@1Mher1 .remove is for removing elements from the DOM, if you want to remove everything, you need to set the value to an empty string.
1Mher1
@1Mher1
Apr 27 2018 10:19
@forkerino I want to remove last letter only when i click backspace
Pieter Stokkink
@forkerino
Apr 27 2018 10:21
@1Mher1 ok, that should happen by default if you are using an <input> tag.
1Mher1
@1Mher1
Apr 27 2018 10:22
@forkerino yes correct
id="inp"
Pieter Stokkink
@forkerino
Apr 27 2018 10:23
so why would you need an eventhandler for that?
1Mher1
@1Mher1
Apr 27 2018 10:25
@forkerino I want to develop Word Rain game in jQuery According in game I should delete last letter when pressed backspace and when presed space they must delete all word in input
Pieter Stokkink
@forkerino
Apr 27 2018 10:34
ok, so maybe tell us what you expect to happen and what actually happens with the code that you have written.
1Mher1
@1Mher1
Apr 27 2018 10:36

$(document).keyup((e)=>{
var k = e.key

if(e.keyCode == 8){
    console.log(e.keyCode)
    var d =$("#inp").val()
    $("#inp").remove()
}

})

$(window).keypress((e)=>{
if (e.key === ' ' || e.key === 'Spacebar') {

e.preventDefault()
console.log('Space pressed')

}
})

for backspace and space Itried this but they don't worked what I want
namely when I pressed in console worked dont show errors but they dont worked wha I want
Pieter Stokkink
@forkerino
Apr 27 2018 10:53
you'd have to be a little more descriptive if you want people to be able to help you.
WHEN I press space THEN the word should be deleted
BUT now x happens.
'they dont worked wha I want' is not really helping me understand what actually happens when you do this.
or do you have a codepen where I can see this code in action?
Tiago Correia
@tiagocorreiaalmeida
Apr 27 2018 11:00
Hey @forkerino how are you?
Pieter Stokkink
@forkerino
Apr 27 2018 11:05
@tiagocorreiaalmeida not completely sober.
:joy:
Markus Kiili
@Masd925
Apr 27 2018 11:05
:beer:
Pieter Stokkink
@forkerino
Apr 27 2018 11:06
@Masd925 hello
Markus Kiili
@Masd925
Apr 27 2018 11:06
Evening.
Pieter Stokkink
@forkerino
Apr 27 2018 11:06
lol
It's a national holiday here, so I guess it is ok
@1Mher1 So.... I do see the keycode and 'space pressed' being logged to the console.
Pieter Stokkink
@forkerino
Apr 27 2018 11:12
not exactly sure why the input box doesn't do its normal job.
1Mher1
@1Mher1
Apr 27 2018 11:15
@forkerino this is chellange in this chellange I must develop Word Rain only backspace and space Dont worked
Pieter Stokkink
@forkerino
Apr 27 2018 11:16
ah, I see what is happening. Your cursor is not in the input field, so the standard backspace doesn't work.
threw me off base for a second
@1Mher1 basically you want to do something like this for backspace:
var content = $('#inp').val()
$('#inp').val(content.slice(0,-1))
and for space you want to clear it completely, right?
1Mher1
@1Mher1
Apr 27 2018 11:19

@forkerino $(document).keyup((e)=>{
var k = e.key

if(e.keyCode == 8){
    console.log(e.keyCode)
    var content = $('#inp').val()

$('#inp').val(content.slice(0,-1))
}

})

Pieter Stokkink
@forkerino
Apr 27 2018 11:19
$('#inp').val('')
1Mher1
@1Mher1
Apr 27 2018 11:19
correct this
Pieter Stokkink
@forkerino
Apr 27 2018 11:19
that last one was for the space
if I remember jQuery correctly, I haven't used it in over a year
1Mher1
@1Mher1
Apr 27 2018 11:20
@forkerino for backspace worked they remove all characters
Pieter Stokkink
@forkerino
Apr 27 2018 11:20
cool
1Mher1
@1Mher1
Apr 27 2018 11:21
@forkerino in my chellange backspace must remove last character only
Markus Kiili
@Masd925
Apr 27 2018 11:21
@forkerino What do you think is your optimal drunkenness level in order to help others here the best? Surely not zero.
Pieter Stokkink
@forkerino
Apr 27 2018 11:22
@Masd925 I reckon it varies
@1Mher1 when I copy my code into your pen, it removes only the last character
and the one for space also seems to work
Now you probably need to use some logic to compare the value to the names you have floating around there.
1Mher1
@1Mher1
Apr 27 2018 11:25
@forkerino https://codepen.io/1Mher1/pen/erBgLO all deleted
Pieter Stokkink
@forkerino
Apr 27 2018 11:26
what is all deleted? When I type something and hit backspace, it just deletes the last character
@Masd925 you'll get a kick out of this: https://en.wikipedia.org/wiki/Illegal_prime
Markus Kiili
@Masd925
Apr 27 2018 11:34
@forkerino I think that they should ban all the primes, because they can be used to crack encryption methods.
Pieter Stokkink
@forkerino
Apr 27 2018 11:36
:smile:
Markus Kiili
@Masd925
Apr 27 2018 11:36
They should also ban all the symbols and flags too, because some evil people use such things to identify themselves as a group.
Markus Kiili
@Masd925
Apr 27 2018 11:41
@forkerino ... and living under the sea level and eating bread every day.
Pieter Stokkink
@forkerino
Apr 27 2018 11:45
hahaha
yes
I agree to most of it
ban banning
Nate Mallison
@NJM8
Apr 27 2018 12:15
Can someone help me with an npm question, is it possible to update sub-dependencies?
I have a warning from github about a package being vulnerable, there is a new version available, but it's not a package I installed, its something one of the modules I'm using installed, npm update only seems to affect the packages I installed.
Pieter Stokkink
@forkerino
Apr 27 2018 12:26
I guess you could fork the repo and update the dependencies there, including that in your project, but if the package you use is popular, it will probably be updated soon (or you can make a PR for it!)
@NJM8
Nate Mallison
@NJM8
Apr 27 2018 12:28
thanks @forkerino . So there is no way for me to upgrade a package that bcrypt uses. That makes sense as I don't maintain bcrypt so being able to manually update it may break it
Pieter Stokkink
@forkerino
Apr 27 2018 12:44
Basically, yes
You could roll your own version, but if you're going to fix bcrypt, better colaborate on the open source project, so everyone can benefit.
Nate Mallison
@NJM8
Apr 27 2018 12:50
I see, I have another one, is there an easy way to track what sub-deps belong to my deps? I have an older issue from github on a security vulnerability with ms, it is used by expressworks in this case, but I'm not sure which packages installed by expressworks are using ms, I have trolled through my packagelock but it's very long and hard to read through. I don't want to submit an issue to expressworks without knowing which dep is the issue, although it appears a lot of their deps are out of date
it doesn't really matter it's not like I'm using it in a production setting, it's just expressworks, just curious about the process
Pieter Stokkink
@forkerino
Apr 27 2018 12:54
Not sure, there must be a way to visualize the dependency tree
pretty cool tool!
Pieter Stokkink
@forkerino
Apr 27 2018 13:02
I'm off! Have a great day everyone.
Nate Mallison
@NJM8
Apr 27 2018 13:08
whoa, that's cool
Muhammad Hasham
@MohammadHasham
Apr 27 2018 13:30
is it okay as a web developer to only know JS and no PHP or should i learn php as well?
vaibhav sharma
@vaibsharma
Apr 27 2018 13:31
Learn as much as you can but be really good at anyone of the framework be it on python, JS or php.
ROR and Go lang is also extensively used by most of the developers.
So answer to your question is 'NO', a very big 'NO'. You might get good at JS at one point but you might need to write programs on Go lang then for your client. So first thing if you ever want to be a good developer that never love one language. Keep building stuffs and learn them as much as you can and never limit yourself
Muhammad Hasham
@MohammadHasham
Apr 27 2018 13:38
@vaibsharma thanks
Jason Luboff
@JLuboff
Apr 27 2018 15:12
:wave:
Blauelf
@Blauelf
Apr 27 2018 15:19
@MohammadHasham For server-side programming, most people use PHP, Java, or C#, maybe even Ruby, Perl, Python, or JS, but it's pretty specific. Big companies often like Java or C#, because they have large codebases in those languages. If you're doing Wordpress plugins, you'll need PHP. Less webby, but machine learning often uses Python, the actual computation is done using C or Fortran code. Startups are open to new languages like Go lang, and there are also a bunch of languages that run on the JVM and might be compatible with existing Java code. So it pretty much depends on where you want to go. Don't do all at once, nobody needs all at once, but somebody really good at their particular used language.
Blauelf
@Blauelf
Apr 27 2018 15:27
I don't really agree with including C++ in https://medium.freecodecamp.org/best-programming-languages-to-learn-in-2018-ultimate-guide-bfc93e615b35, but that's subjective. I recently heard of somebody spending days to debug a C# programme because the bug was not in the debugged code, but some listener invisibly attached from outside, so it could be worse.
Christopher McCormack
@cmccormack
Apr 27 2018 15:33
@JLuboff :wave:
Jason Luboff
@JLuboff
Apr 27 2018 15:33
@cmccormack wHAT UP
Fucking caps lock
Christopher McCormack
@cmccormack
Apr 27 2018 15:33
@JLuboff ah thought you were excited to see me
Jason Luboff
@JLuboff
Apr 27 2018 15:34
Well.. that too
Christopher McCormack
@cmccormack
Apr 27 2018 15:34
haha
What's up man still breaking windows machines?
Jason Luboff
@JLuboff
Apr 27 2018 15:35
It's always possible :P
Just finishing up one right now actually. Decrapifier didn't work on the profile I needed it to..so having to run some powershell
Christopher McCormack
@cmccormack
Apr 27 2018 15:36
Is that the actual name of some software?
Jason Luboff
@JLuboff
Apr 27 2018 15:37
It's a powershell script someone made, ya lol
Christopher McCormack
@cmccormack
Apr 27 2018 15:40
that looks awesome
Blauelf
@Blauelf
Apr 27 2018 15:41
Does this remove Candy Crush Soda from the start menu?
Jason Luboff
@JLuboff
Apr 27 2018 15:43
It can, yes
Blauelf
@Blauelf
Apr 27 2018 15:43
I never understood how they managed to sell a windows version containing tons of ads.
Jason Luboff
@JLuboff
Apr 27 2018 15:44
It's pretty good..but I've found doesn't always work quite right..
I still need to go through all the code to understand exactly what each part does and than modify it for our use (like I'd like to clear the start menu, but have different apps than what he puts)
@Blauelf You would think at least hte Pro version wouldn't have it...but noppe...its plagued with crap
like...why would I need the XBox app at work (haha..thats a trick question..I definitely use it)
Blauelf
@Blauelf
Apr 27 2018 15:51
I intend using my Windows 7 notebook those two years until there are no more updates. It then will be about 6 years, which is the average age of my notebooks to retire. But then - I've got too much Windows software to switch to Linux. Games that probably won't like emulators and Wine ("Wine Is Not an Emulator").
Jason Luboff
@JLuboff
Apr 27 2018 15:53
Windows 10 isn't bad at all except for that IMO
Christopher McCormack
@cmccormack
Apr 27 2018 15:59
@Blauelf I may be on that same path myself.
I wouldn't even use Win10 if it wasn't for games
Blauelf
@Blauelf
Apr 27 2018 16:02

I know a few people using it, and there were a few things that were not so great. Like the database request that should run over night. It probably did, but the result got washed away when automatic update restarted the computer. Or the interface changing on some of the 6-month updates (guess this won't happen that often now). And the tons of software updates following that one, as many developers did not test for the new Windows release and it broke their software.

But it's the first Windows version coming with a usable browser :D

Christopher McCormack
@cmccormack
Apr 27 2018 16:05
usable to me depends on extensions these days
Jason Luboff
@JLuboff
Apr 27 2018 16:05
I have been using it in an office enviroment, so updates don't bother me. But with the latest build (1709) it did break scanning until I figured out why lol
Christopher McCormack
@cmccormack
Apr 27 2018 16:08
I think it's really shitty of them to have put you in a situation you have to do all this just to make your machines suitable for the workplace
Jason Luboff
@JLuboff
Apr 27 2018 16:09
Yes... I do agree there
@cmccormack What're you working on today?
Christopher McCormack
@cmccormack
Apr 27 2018 16:14
Just cleanup from the week, stuff I couldn't get to until quiet Friday
maybe finish my voting app today and move to the next one
Jason Luboff
@JLuboff
Apr 27 2018 16:15
Dope
Christopher McCormack
@cmccormack
Apr 27 2018 16:16
yeah man
really boring haha
Jason Luboff
@JLuboff
Apr 27 2018 16:17
Haha
Gulsvi
@gulsvi
Apr 27 2018 16:25

Curious.... is one lookup and one variable definition less costly than two lookups?
For example, this:

  for (let i = 0; i < string1.length; i++) {
    const letter = string1[i];
    hash[letter] = hash[letter] + 1 || 1;
  }

instead of:

  for (let i = 0; i < string1.length; i++) {
    hash[string1[i]] = hash[string1[i]] + 1 || 1;
  }

Which is "better"?

Christopher McCormack
@cmccormack
Apr 27 2018 16:26
@gulsvi the performance difference is almost nil for something like that
Gulsvi
@gulsvi
Apr 27 2018 16:27
I am being a little pedantic, I know, but "almost nil" is the answer I'm trying to get more clarification on.
is the first nil + 0.000000001 better? :)
Pieter Stokkink
@forkerino
Apr 27 2018 16:28
@gulsvi the question is whether definition is less costly than one lookup
I think it is more
but that's a guess
Gulsvi
@gulsvi
Apr 27 2018 16:28
I'm not sure how to find out - or, if it actually might come down to browser implementation
differ in chrome vs. firefox vs. safari
Pieter Stokkink
@forkerino
Apr 27 2018 16:29
well, you can create a test that does it a million times for arrays of length 100000.
see which is faster
Jason Luboff
@JLuboff
Apr 27 2018 16:29
@forkerino :wave:
Gulsvi
@gulsvi
Apr 27 2018 16:30
I wonder if jsperf is accurate enough to tell - i can't ever seem to get repeatable results
same with performance.now() on my local computer
Pieter Stokkink
@forkerino
Apr 27 2018 16:30
@JLuboff :wave:
Jason Luboff
@JLuboff
Apr 27 2018 16:30
I understand it's Queens day there.. is it proper to say "Happy Queens Day"? @forkerino
Christopher McCormack
@cmccormack
Apr 27 2018 16:30
hmm I think in the end it would probably be the same time since the interpreter would need to store the values temporarily anyhow
Pieter Stokkink
@forkerino
Apr 27 2018 16:31
@gulsvi if the sample size is big enough, the results should speak for themselves.
@JLuboff we have a King nowadays
but yeah
same shit different puppet
Gulsvi
@gulsvi
Apr 27 2018 16:31
alright, I'll dig deeper for now - thanks @forkerino and @cmccormack
Jason Luboff
@JLuboff
Apr 27 2018 16:32
@forkerino Ah, my mistake :D
Gulsvi
@gulsvi
Apr 27 2018 16:32
Koningsdag :)
Pieter Stokkink
@forkerino
Apr 27 2018 16:32
tbh I don't care much for royalty, it's just an excuse for a big party today.
Jason Luboff
@JLuboff
Apr 27 2018 16:34
Sounds like Cinco de mayo here... it's not even our holiday but people get stupid drunk anyways
Christopher McCormack
@cmccormack
Apr 27 2018 16:35
or every other holiday pretty much @JLuboff haha
Pieter Stokkink
@forkerino
Apr 27 2018 16:35
We have liberation day on 5th of May, but everyone is usually still hung over from King's Day.
Christopher McCormack
@cmccormack
Apr 27 2018 16:35
oh cinco is coming up soon! time to make some plans
Jason Luboff
@JLuboff
Apr 27 2018 16:37
Eh...at least 4th of July is our holiday @cmccormack
Christopher McCormack
@cmccormack
Apr 27 2018 16:38
good point. I've never been a huge fan of the 4th though, living in Phoenix it's like 120 degrees that day
That's about 49c @forkerino :grinning:
Jason Luboff
@JLuboff
Apr 27 2018 16:40
The fourth is fun usually there's street fairs and stuff here
Weather is decent for us.. 70-80*
Christopher McCormack
@cmccormack
Apr 27 2018 16:42
man that sounds great
maybe I'll try to schedule an annual trip to places with better weather for the fourth :) I have enough friends/family now spread across the states it shouldn't be too hard
maybe I'll visit @JLuboff first! :D
Jason Luboff
@JLuboff
Apr 27 2018 16:45
Come on over
Christopher McCormack
@cmccormack
Apr 27 2018 16:46
cool I'll bring the whole family :p
Jason Luboff
@JLuboff
Apr 27 2018 16:48
Bring a air matteress, you can sleep in the living room with my dog :D lol
Christopher McCormack
@cmccormack
Apr 27 2018 16:49
Great hosts!
Jason Luboff
@JLuboff
Apr 27 2018 16:50
He stays behind a gate during the night, so he won't bug you too much :P
Christopher McCormack
@cmccormack
Apr 27 2018 16:51
haha
Jason Luboff
@JLuboff
Apr 27 2018 16:52
Plus...you've probably seen pictures/videos of him, he's adorable! And kind of a dick but thats irrelevant
Christopher McCormack
@cmccormack
Apr 27 2018 16:54
That is an adorable dog
Jason Luboff
@JLuboff
Apr 27 2018 16:54
:dog2:
Christopher McCormack
@cmccormack
Apr 27 2018 16:57
Spitting image
Jason Luboff
@JLuboff
Apr 27 2018 17:02
I thought so
Mohammed Boudad
@matrixersp
Apr 27 2018 19:09

Hey guys,
I'm trying to create a search route, when I use '?' in I get an error

router.get('?product=:name', offersController.offers_search_offer);

error:
SyntaxError: Invalid regular expression: /^?q=(?:([^\/]+?))\/?$/: Nothing to repeat

Brad
@bradtaniguchi
Apr 27 2018 19:11
@matrixersp This is with express I assume/
Mohammed Boudad
@matrixersp
Apr 27 2018 19:11
@bradtaniguchi yes
Brad
@bradtaniguchi
Apr 27 2018 19:13
Im no express user, but it sure seems like all the route definitions start with a /
otherwise, are you sure you need to provide the query param in the route?
Mohammed Boudad
@matrixersp
Apr 27 2018 19:14
@bradtaniguchi I already included that in app.js file
app.use('/offers', offerRoutes);
Brad
@bradtaniguchi
Apr 27 2018 19:15
so what if you just do?
router.get('', offersController...)
and in the offsers controller get the params you want
Daniel Simeonov
@dbsimeonov
Apr 27 2018 19:17
guys can you help me translate that, or if I'm right?
index = index < 0 ? totalItems - 1 : index >= totalItems ? 0 : index;
if(index < 0){
   index = totalItems - 1;
}else{
   if(index>= totalItems){
      index = 0;
   }else{
    index = index;
    }
}
Mohammed Boudad
@matrixersp
Apr 27 2018 19:18
@bradtaniguchi I think that would overlap with other routes
ehutchllew
@ehutchllew
Apr 27 2018 19:21
@dbsimeonov missing the last condition: where index = index.
Nate Mallison
@NJM8
Apr 27 2018 19:21
@matrixersp You don't need to include optional parameters in the route, it will show up in the req object
Daniel Simeonov
@dbsimeonov
Apr 27 2018 19:21
@ehutchllew like that, just edited it?
ehutchllew
@ehutchllew
Apr 27 2018 19:21
yep
could also use else if instead of nested if/else inside the else.
Daniel Simeonov
@dbsimeonov
Apr 27 2018 19:22
aaa right okay thanks!
Brad
@bradtaniguchi
Apr 27 2018 19:23
This is how I write complicated ternary statements.
index = index < 0 
  ? totalItems - 1 
  : index >= totalItems 
    ? 0 
    : index;
Its debatable if this helps or not, but helps for me at least.
Daniel Simeonov
@dbsimeonov
Apr 27 2018 19:24
right okay, thats more readable I guess
ehutchllew
@ehutchllew
Apr 27 2018 19:24
^ could do that, i generally stay away from nested ternary. They feel cool to write, but don't offer much in terms of clarity.
Nate Mallison
@NJM8
Apr 27 2018 19:25
@matrixersp it shows up in req.query, so req.query.product will contain the optional url parameter if it exists
so use your normal route to capture it and the use a if statement to do something else if that param exists
Muhammad Hasham
@MohammadHasham
Apr 27 2018 19:32
@Blauelf Thanks for the insight! that was an awesome answer
Mohammed Boudad
@matrixersp
Apr 27 2018 19:37
@NJM8 I guess I got it now, I'll try that, thank you
Mohammed Boudad
@matrixersp
Apr 27 2018 19:46
@NJM8 I get an empty object when I console log req.params even after I send
http://localhost:3000/offers?product=name
Christopher McCormack
@cmccormack
Apr 27 2018 19:53
@matrixersp did you validate you were logging from the correct route?
Mohammed Boudad
@matrixersp
Apr 27 2018 19:57

@cmccormack
I included the offers route in my app.js file

const offerRoutes = require('./api/routes/offers');
app.use('/offers', offerRoutes);

and this the route in offers.js file

router.get('', offersController.offers_get_all);
Christopher McCormack
@cmccormack
Apr 27 2018 20:01
ok, did you log it within your get?
Mohammed Boudad
@matrixersp
Apr 27 2018 20:04
I don't really get you sorry
I console logged req.params in offers.js (controller) and I got an empty object
exports.offers_get_all = (req, res, next) => {
    console.log(req.params);
    Offer.find()
    ...
Christopher McCormack
@cmccormack
Apr 27 2018 20:07
That's all I was asking :)
put a log statement in every route, make sure you're hitting them first
Nate Mallison
@NJM8
Apr 27 2018 20:08
@matrixersp req.query not req.params
Christopher McCormack
@cmccormack
Apr 27 2018 20:08
@NJM8 :thumbsup:
Jason Luboff
@JLuboff
Apr 27 2018 20:09
Yup.. params is if your route is /myRoute/:myParam
Jason Luboff
@JLuboff
Apr 27 2018 20:09
req.params would contain myParam
Mohammed Boudad
@matrixersp
Apr 27 2018 20:09
@NJM8 Thank you, you saved me lol
Nate Mallison
@NJM8
Apr 27 2018 20:12
lol, no worries, someone saved me, pass it on
Brad
@bradtaniguchi
Apr 27 2018 21:51
Man, when your given 1 task to make something more stable, and end up needing to impliment entirly new features XD
Jason Luboff
@JLuboff
Apr 27 2018 22:21
@bradtaniguchi Sounds like a good time
Brad
@bradtaniguchi
Apr 27 2018 22:34
meh
kyle-kauzlarich
@kyle-kauzlarich
Apr 27 2018 22:35
greetings
Brad
@bradtaniguchi
Apr 27 2018 22:36
hello
anthonygallina1
@anthonygallina1
Apr 27 2018 22:42
@bradtaniguchi Yup I have side tracts on my side tracts
Living with not yet resolved issues is a art.
IMO
kyle-kauzlarich
@kyle-kauzlarich
Apr 27 2018 22:45
hows it going?
anthonygallina1
@anthonygallina1
Apr 27 2018 22:45
Good how are you?
kyle-kauzlarich
@kyle-kauzlarich
Apr 27 2018 22:47
doing alright killing time
anthonygallina1
@anthonygallina1
Apr 27 2018 22:49
Iwas just doing some node And found the conversation above interesting.