These are chat archives for FreeCodeCamp/HelpJavaScript

29th
Jan 2018
Stephen James
@sjames1958gm
Jan 29 2018 00:20
@BinaryKing Are you wanting to sort the boss array?
HumaDeng
@HumaDeng
Jan 29 2018 01:32
I got it!
Jianyu Zhang
@Jatstar
Jan 29 2018 02:27
anyone?
``````
``````
function destroyer(arr) {
    var array = arguments[0];
    return array.filter(
        function callback(value) {
            for (var i = 1; i < arguments.length; i++) {
                var e = arguments[i];
                if (e == value) {
                    return false;
                }
            }
            return true;
        }
    );
}

 var result = destroyer([1, 2, 3, 1, 2, 3], 2, 3);
 console.log(result);
Stephen James
@sjames1958gm
Jan 29 2018 02:59
@Jatstar Each function has its own arguments, so the one in the callback function is not the same.
Jianyu Zhang
@Jatstar
Jan 29 2018 03:18
Thanks ,I retain arguments of the destroyer function, then ues them at callback ,it’s work.
@sjames1958gm thanks , and I am sorry to my poor English.
CamperBot
@camperbot
Jan 29 2018 03:18
jatstar sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8913 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
aRtoo
@artoodeeto
Jan 29 2018 05:05
hey bros i redo my simon game. i want to change the JS to a module pattern . im starting right not but i have this error.
heres the pen https://codepen.io/artoo/pen/xYKvKX
but  this example i made i dont have an error

let modPat = (function() {

    "use strict";
    // console.log(this);
    // let btn; //working get the DOM elem first then before adding a event
    let a = 2; //this is working
    let b = 3; //this is working

    return {
        init: function (){
            console.log(this);
            this.cacheDOM();
            this.bindEvents();
          },
          cacheDOM: function(){
           let btn = document.getElementById('btn'); //you can put let here too
         },
          bindEvents: function(){
            btn.addEventListener('click', this.displayLog);
          },
          displayLog: function(){
            console.log('yes you made it', a + b);
          }
    }

  }());

  modPat.init();
Conor Murphy
@cmurphy580
Jan 29 2018 07:07
@cmurphy580
I got this error when trying to deploy a react app.
Do i need to update my redux?
bundle.js:19 You are currently using minified code outside of NODE_ENV === 'production'. This means that you are running a slower development build of Redux. You can use loose-envify (https://github.com/zertosh/loose-envify) for browserify or DefinePlugin for webpack (http://stackoverflow.com/questions/30030031) to ensure you have the correct code for your production build.
Claudio Restifo
@Marmiz
Jan 29 2018 07:25
@cmurphy580 that looks like a warning more than an error
Ian
@toianw
Jan 29 2018 07:36
@artoodeeto The variables you're declaring with let in the cacheDOM method are scoped to that function. They are not available to the bindEvents method. The 2nd example only works because the btn element is available in the global scope through reference of its id. You could remove the cacheDOM method entirely and it would still work. Read this for more details:
https://www.tjvantoll.com/2012/07/19/dom-element-references-as-global-variables/
aRtoo
@artoodeeto
Jan 29 2018 07:39
@toianw omg bro please let me pm you
@toianw if its ok
@toianw on my simon game ive used ID too its not working either bro. this is confusing
Ian
@toianw
Jan 29 2018 07:43
@artoodeeto on your Simon game, the ids are different to the variable names.
aRtoo
@artoodeeto
Jan 29 2018 07:44
@toianw i tried using start because its an ID its still not working bro.
Ian
@toianw
Jan 29 2018 07:47
@artoodeeto I don't think it's a good idea to rely on using the global id references in your javascript code. You'd be better off storing these DOM element references on the object itself (or in the scope of the sgMod functon should work too)
aRtoo
@artoodeeto
Jan 29 2018 07:48
@toianw here bro i tried this. wait send you some parts
@toianw bro im gonna DM you
Ian
@toianw
Jan 29 2018 07:49
ok
Thompson jackson
@micheljorden94
Jan 29 2018 09:48
help
Thompson jackson
@micheljorden94
Jan 29 2018 09:57
function lookUp(firstName, prop){
// 请把你的代码写在这条注释以下
for(var i=0;i<apple.length;i++){
if(apple[i][firstName]){
if(apple[i][firstName]==firstName){
if(apple[i][firstName][prop]){
return apple[i][firstName][prop];
}
else{
return "No such property";
}
}
}
else{
return "No such contact";
}
}
error
Blauelf
@Blauelf
Jan 29 2018 11:00

@micheljorden94 First, there's freeCodeCamp/Chinese if that's your language.

Then, what is apple? Maybe you meant contacts? contacts is an array of objects, and you have to check the various contacts[i].firstName or contacts[i]["firstName"], not contacts[i][firstName], against function parameter firstName. And for existence of a property, check hasOwnProperty.

Also, only two ifs required.

And make sure to return "No such contact" after unsuccessfully checking all the contacts.

Diego Mayer
@Chrono79
Jan 29 2018 13:29

Then, what is apple?

@Blauelf undercover marketing campaign?

Blauelf
@Blauelf
Jan 29 2018 13:29
Product placement?
Markus Kiili
@Masd925
Jan 29 2018 13:30
@Blauelf He is talking about der apfel.
Blauelf
@Blauelf
Jan 29 2018 13:31
An apple a day keeps the windows away?
Tiago Correia
@tiagocorreiaalmeida
Jan 29 2018 14:10
has anyone runned into this error
Module not found: Can't resolve 'aws-sdk'
using create-react-app?
./node_modules/node-pre-gyp/lib/info.js
Module not found: Can't resolve 'aws-sdk' in 'C:\wishList\client\node_modules\node-pre-gyp\lib'
Ken Haduch
@khaduch
Jan 29 2018 15:00
@tiagocorreiaalmeida - I googled for that, and aws/aws-sdk-js#603 seems like there were a lot of issues with this, and some potential solutions? You might have already found that in your own searching...
Tiago Correia
@tiagocorreiaalmeida
Jan 29 2018 15:07
tried a few of them didnt changed anything that's why I came here :\
Razvan Jackson
@RazvanJackson
Jan 29 2018 15:07
Hey guys!
how can i handle big number in javascript and avoid smth like
'1.3115120134408189e+29'
Tiago Correia
@tiagocorreiaalmeida
Jan 29 2018 15:08
as a string you can also use a library that will do that for you
Markus Kiili
@Masd925
Jan 29 2018 15:08
@RazvanJackson Depends on what you mean by handling big number.
Razvan Jackson
@RazvanJackson
Jan 29 2018 15:10
@Masd925 to avoid getting a result as that
Markus Kiili
@Masd925
Jan 29 2018 15:13
@RazvanJackson Do you mean that you wan't to format the result without the scientific notation?
Razvan Jackson
@RazvanJackson
Jan 29 2018 15:18
yes
Markus Kiili
@Masd925
Jan 29 2018 15:18
@RazvanJackson I don't think that there is any easy way. Some big number library might do it.
Tiago Correia
@tiagocorreiaalmeida
Jan 29 2018 15:19
for strange it might seem you gonna use one of the first things you learned in math
one value on top on below sum the first with the one below
leave the rest
sum it on the next one
image.png
like this
Razvan Jackson
@RazvanJackson
Jan 29 2018 15:21
@tiagocorreiaalmeida thanks
CamperBot
@camperbot
Jan 29 2018 15:21
razvanjackson sends brownie points to @tiagocorreiaalmeida :sparkles: :thumbsup: :sparkles:
:cookie: 491 | @tiagocorreiaalmeida |http://www.freecodecamp.org/tiagocorreiaalmeida
Tiago Correia
@tiagocorreiaalmeida
Jan 29 2018 15:22
but if you working on some project I would recommend just going for a library
FlashHero
@FlashHero
Jan 29 2018 15:24
What's the difference between reactjs native router and browser router
Razvan Jackson
@RazvanJackson
Jan 29 2018 15:25
@FlashHero from what i now reacjss native router it's not going through server side
@FlashHero Like express routing is doing, hope i'm right
Tiago Correia
@tiagocorreiaalmeida
Jan 29 2018 15:38
native for what I know is used on mobile applications/desktop
Jason Luboff
@JLuboff
Jan 29 2018 16:07
:wave:
Tiago Correia
@tiagocorreiaalmeida
Jan 29 2018 16:08
hey @JLuboff
Jason Luboff
@JLuboff
Jan 29 2018 16:08
Whats up?
Markus Kiili
@Masd925
Jan 29 2018 16:12
Yo.
Jason Luboff
@JLuboff
Jan 29 2018 16:14
@Masd925 What up?
Markus Kiili
@Masd925
Jan 29 2018 16:15
I spent the weekend figuring out how to get local bus information with JS. Maybe I will do some app using it. How about you?
@JLuboff
Simon Cordova
@gbsimon87
Jan 29 2018 16:21
Hey all! :)
Markus Kiili
@Masd925
Jan 29 2018 16:22
Yo.
Tiago Correia
@tiagocorreiaalmeida
Jan 29 2018 16:24
nothing special what about you ?:D
hey @gbsimon87 are you some how related to cordova from narcos?:D
Jason Luboff
@JLuboff
Jan 29 2018 16:25
@Masd925 Spent the weekend doing some work and spending time with family. I'm guessing there's an API you're getting the bus info from?
Markus Kiili
@Masd925
Jan 29 2018 16:25
@JLuboff Yes. Ajax request with GraphQL in and json back mostly.
Jason Luboff
@JLuboff
Jan 29 2018 16:26
@tiagocorreiaalmeida Same ol' same ol
@Masd925 Got it. Sounds nifty
FlashHero
@FlashHero
Jan 29 2018 16:26
@RazvanJackson @tiagocorreiaalmeida thanks
jusgoose
@gusd773
Jan 29 2018 16:33
@Masd925 thank you I forgot to import it with codepen thank you
CamperBot
@camperbot
Jan 29 2018 16:33
gusd773 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4676 | @masd925 |http://www.freecodecamp.org/masd925
Simon Cordova
@gbsimon87
Jan 29 2018 16:36
@tiagocorreiaalmeida I might be, who knows really!
I was here on Friday chatting away, missed a lot of you guys
jusgoose
@gusd773
Jan 29 2018 19:18

can anybody tell me why my button is not aligned underneath my well?

<div class = "container-fluid">
<div style="text-align:center">
<h1> Random Quote Generator</h1>
</div>

<div style="text-align:center">
<div class = "col-xs-12 well quote">
<h2> Quote Goes Here </h2>
</div>
</div>
<div class = "text-align:center">
<div class = "col-xs-12">

<button id = "getQuote" class = "btn btn-primary">
Get Quote
</button>
</div>
</div>
</div>

Jason Luboff
@JLuboff
Jan 29 2018 19:21
Becuase you used class instead of style
but it looks like you're using Bootstrap..bootstrap has built in center classes text-center for centering text and center-block for elements
Wilfred
@WillzMu
Jan 29 2018 19:28

"Sum All Numbers in Range" under Intermediate Algorithm Scripting. I seem to get the right result but when I run only get one tick.
var total;
var amount;
var arr2=[];
var x;
var y;
function sumAll(arr) {

x= Math.max(arr[0],arr[1]);
y= Math.min(arr[0],arr[1]);
for(var i=y; i<x+1;i++){
arr2.push(i);
}

return arr2.reduce(getSum);
}
function getSum(total, amount){
return total + amount;
}

sumAll([10, 5]);

Jason Luboff
@JLuboff
Jan 29 2018 19:29
@WillzMu FCC generally does not like global variables
Wilfred
@WillzMu
Jan 29 2018 19:32
haha, I've tried with local variables and its worked!!! Thanks a lot. Is it bad programming practice to use global variables?
Jason Luboff
@JLuboff
Jan 29 2018 19:33
@WillzMu It all depends on how you're scoping things. With FCC, its how they run the tests that it doesn't like globals (I think it might not reset the values?)
Wilfred
@WillzMu
Jan 29 2018 19:34
Got it. thanks again! I will surely remember it.
jusgoose
@gusd773
Jan 29 2018 19:36
@JLuboff yessir thanks didn't know that
CamperBot
@camperbot
Jan 29 2018 19:36
gusd773 sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2312 | @jluboff |http://www.freecodecamp.org/jluboff
FlashHero
@FlashHero
Jan 29 2018 19:37
Why would I need to use component mounting in reactjs for example when I can call clear interval instead of calling mounting functions to clear interval. In what situations should I call these mounting and unmounting functions
Wilfred
@WillzMu
Jan 29 2018 19:41
@JLuboff thanks. Long time since I've been on the platform.
CamperBot
@camperbot
Jan 29 2018 19:41
willzmu sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2313 | @jluboff |http://www.freecodecamp.org/jluboff
Jason Luboff
@JLuboff
Jan 29 2018 19:41
:+1:
Stephen James
@sjames1958gm
Jan 29 2018 19:49
@FlashHero You don't call those functions, React calls your functions when mounting and unmounting your components.
You would call clearInterval when React is unmounting your component so you don't have random timers running
aRtoo
@artoodeeto
Jan 29 2018 20:34

help fam. i have a branch on a my project. then i push my change to my branch then instead merging it on master i merge the master to the branch. i tried reseting it but it wont. this is the link artoodeeto/Simon-Game-@e4dade5

and this is the hash i want to reset e4dade5621706894a03e5d

i tried doing the git reset --head e4dade5621706894a03e5d it didnt change my file locally