These are chat archives for FreeCodeCamp/HelpJavaScript

15th
Mar 2018
Tiago Correia
@tiagocorreiaalmeida
Mar 15 2018 00:03
@AdelMahjoub im out of the computer bur will do it for sure tomorrow and let you know, thanks for.your time
CamperBot
@camperbot
Mar 15 2018 00:03
tiagocorreiaalmeida sends brownie points to @adelmahjoub :sparkles: :thumbsup: :sparkles:
:cookie: 676 | @adelmahjoub |http://www.freecodecamp.org/adelmahjoub
Adel
@AdelMahjoub
Mar 15 2018 00:06
@tiagocorreiaalmeida sem problemas :+1:
Tiago Correia
@tiagocorreiaalmeida
Mar 15 2018 00:11
Seems you know portuguese ahah
TheLC
@huatianjun123
Mar 15 2018 00:16
How to separate words into arrays?
string.split("") does it works?
Dardan Demiri
@dardandmr
Mar 15 2018 00:17
yes
you can make split like this:
var string = "The text here";

string.split(" "); // < With a space inside
that returns
an array with three words inside
TheLC
@huatianjun123
Mar 15 2018 00:19
But if you split a word into an array of letters
There is no space between them.
Dardan Demiri
@dardandmr
Mar 15 2018 00:19
That's okey because you don't want the space
when you want to make an string again you do it like this
["The","text","here",].join("
 ");
["The","text","here",].join(" "); // < Again with space to create the lost spaces
TheLC
@huatianjun123
Mar 15 2018 00:23
got it thanks
Dardan Demiri
@dardandmr
Mar 15 2018 00:23
var string = "The text here";

var array = string.split(" ");  // Returns ["The","text","here"]

var againString = array.join(" "); // and Again it returns The text here
TheLC
@huatianjun123
Mar 15 2018 00:24
apple ------apple.split('')------> ['a','p','p','l','e'] Is this correct?
Dardan Demiri
@dardandmr
Mar 15 2018 00:26
var string = "apple";

var array = string.split(""); // And yes you get ['a','p','p','l','e']

and when you say thank you to someone
It's good to click on the helpers name to know to whom you are being thankful like this

Thank you @huatianjun123

CamperBot
@camperbot
Mar 15 2018 00:27
dardandmr sends brownie points to @huatianjun123 :sparkles: :thumbsup: :sparkles:
api offline
Dardan Demiri
@dardandmr
Mar 15 2018 00:28
:)
TheLC
@huatianjun123
Mar 15 2018 00:28
@dardandmr Thank you very much.
CamperBot
@camperbot
Mar 15 2018 00:28
huatianjun123 sends brownie points to @dardandmr :sparkles: :thumbsup: :sparkles:
:cookie: 289 | @dardandmr |http://www.freecodecamp.org/dardandmr
Dardan Demiri
@dardandmr
Mar 15 2018 00:28
You are welcome ;)
Zunaid Aslam
@ZunaidAslam
Mar 15 2018 01:13

So I am doing the wikipedia viewer and to test things out. I used the following code and it worked. I mean the link generated was working. Ajax request worked and the values were put inside the Html ID. But when I tried taking the value using Search result, it's not working. I will post the codes.

It worked:

$(document).ready(function(){
 var searchWord = "God"
 var wikiApi = "https://en.wikipedia.org/w/api.php? action=opensearch&format=json&search=" + searchWord+ "&callback=?";
  console.log(wikiApi);
   $.ajax({
    type: "GET",
    url: wikiApi,  
    dataType: "json",    
    success: function (data) {

     console.log(data[3][0]);

      $('#test').text(data[1][0]);

      $('#test-two').text(data[2][0]);

      $('#3').text(data[3][0]);
    },
    error: function (data) {

    alert ("Error");
    },

  })

})
It didn't:
$(document).ready(function(){

  $("#searchButton").click(function(){

  var searchTerms = $("#mySearch").val(); 
    // var searchWord = "Apple"
  var wikiApi = "https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=" + searchTerms+ "&callback=?";

  console.log(wikiApi);

  $.ajax({
    type: "GET",
    url: wikiApi,

    dataType: "json",

    success: function (data) {

     console.log(data[3][0]);

      $('#test').text(data[1][0]);

      $('#test-two').text(data[2][0]);

      $('#3').text(data[3][0]);
    },
    error: function (data) {

    alert ("Error");
    },

  })

  })

})
Fabien SHAN
@X140hu4
Mar 15 2018 01:45
@Zunaid-Aslam Can you put a codepen or jsfiddle?
Ken Haduch
@khaduch
Mar 15 2018 02:36
@Zunaid-Aslam - are you using a <form> element in your HTML to collect your search term? Because if you are, when you click the submit button on a search, the default action is to submit the page and effectively reload it, so you lose what you were trying to do. If that is the case (and I'm just guessing here) you can try adding e.preventDefault() to your click function handler, which will prevent the default form action and keep all of your activity within one page. If you can post your URL it would be easier to see the entire picture.
Conor Murphy
@cmurphy580
Mar 15 2018 07:01

can any one help me figure out how to transition the height on the div? Here is the code i'm using, and I am changing the height from 30vh to 100vh:

wrap.style.transition = 'width 0.3s cubic-bezier(0.4, 0.0, 0.2, 1) 1s, height 0.3s cubic-bezier(0.4, 0.0, 0.2, 1) 1s';

i've seen on stackoverflow this problem is pretty common, but none of the solutions are what i'm looking for. I'm trying to use some along the lines of what ihave going above.

Koohyar Movassagh
@Koohyar-m
Mar 15 2018 11:00
I haven't analyzed your code. But if you increment something, you should have some kind of upper bound, not just a not-equal. In case you missed the equal, you wouldn't be able to stop otherwise.
@Blauelf I undrestand now, thanks for explaining :)
CamperBot
@camperbot
Mar 15 2018 11:00
sorry connectcodes, you can't send brownie points to yourself! :sparkles: :sparkles:
Keegan
@Keggatron
Mar 15 2018 13:35
can somebody tell me why this function is returning undefined please:
const pizzaOrder = pizzaSpecs.forEach( (pizza, i) => {
        return (
          <div>  
            {pizzaSpecs[i].size}
            {pizzaSpecs[i].toppings.join[", "]}
          </div>  
        )
    })
Stephen James
@sjames1958gm
Mar 15 2018 13:38
@Keggatron forEach always returns undefined, the return from the callback is not used
Claudio Restifo
@Marmiz
Mar 15 2018 13:38

Guys a suggestion, how would you handle in your function the case of missing keys in object that causes error?

Imagine I have a situation where I expect a value to be like this:

const data = { a: [ 0,1 ] }

So that I access it with data.a[0]

However there's the case where sometimes a is not present so the methods that will read the 0 value will fail with a "cannot read property 0 of undefined".

Someone has a suggestion on how to handle this occurrence that does not involve checking for each property manually? (there are quite a few).
Was thinking of writing a function to do that, but I'm open to any suggestion

Keegan
@Keggatron
Mar 15 2018 13:39
@sjames1958gm so what's the best solution to this problem?
Stephen James
@sjames1958gm
Mar 15 2018 13:39
@Keggatron Use map if you want to convert array to JSX

@Marmiz Write a helper function

function getProp(obj, prop, index) { 
  return obj[prop] ? obj[prop][index] : undefined;
}

Or, check out lodash it has all sorts of functions for these kinds of things.

Claudio Restifo
@Marmiz
Mar 15 2018 13:43
@sjames1958gm was going for a helper function, but was keen on hearing other people opinion. Data norm is a pain
Keegan
@Keggatron
Mar 15 2018 13:45
@sjames1958gm thank you. I've been messing with that problem for ages. Although I have definitely tried map and it wasn't working.
CamperBot
@camperbot
Mar 15 2018 13:45
keggatron sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 9099 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Keegan
@Keggatron
Mar 15 2018 13:46
I may have had different code in there before which is why it wasn't working though
Stephen James
@sjames1958gm
Mar 15 2018 13:50
@Keggatron I am often forgetting to return from inside the map callback
Keegan
@Keggatron
Mar 15 2018 13:52
thanks again
Stephen James
@sjames1958gm
Mar 15 2018 14:05
@Keggatron :+1:
Tiago Correia
@tiagocorreiaalmeida
Mar 15 2018 14:26
@AdelMahjoub fails one of the hidden tests :\
Zunaid Aslam
@ZunaidAslam
Mar 15 2018 14:58
@khaduch Thanks Bro! Yes I was using Form and it seems to be working.
CamperBot
@camperbot
Mar 15 2018 14:58
zunaid-aslam sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3798 | @khaduch |http://www.freecodecamp.org/khaduch
Zunaid Aslam
@ZunaidAslam
Mar 15 2018 15:00

I have a question, it's more related to html/css I believe.
I am working on Wiki Viewer and I want search option to be like in the center and when someone search it should go up and list the results.

How do I make it happen? I mean how to make the search field to go at top.
Do I use CSS for this? Or like Reduce the margin of the search bar inside JS file after a click event?

Jason Luboff
@JLuboff
Mar 15 2018 15:07
@Zunaid-Aslam Combine JS and CSS to do so. Use JS to modify the CSS
Zunaid Aslam
@ZunaidAslam
Mar 15 2018 15:08
That what i was think, basically after the search happens, I reduce the margin so it goes up. Something like that...
Fabien SHAN
@X140hu4
Mar 15 2018 15:08
@Zunaid-Aslam @JLuboff Or have the CSS and use the JS to add/delete the class from the elements.
Adel
@AdelMahjoub
Mar 15 2018 15:09
@tiagocorreiaalmeida this one pass all the tests, the matching words are unique, but doesn't mean that the last one of them is actually the last matching word, fixed that
/**
 * 
 * @param {Array<Array<string>>} conversations 
 * @param {Array<string>} currentConversation 
 * @returns {Array<string>}
 */
function chatBot(conversations, currentConversation) {

    /** @type {Array<{index: number, count: number, words: Array<string>} */
    let matches = [];

    /** @type {Array<string>} */
    let conversationToKeep = [];

    /** @type {Array<string>} */    
    let matchingWords = [];

    /** @type {number} */
    let lastMatchingWordIndex = 0;

    /** @type {Array<string>} */
    let missingWords = [];

    conversations.forEach((conversation, index) => {
        const words = Array.from(new Set(conversation.filter(word => currentConversation.indexOf(word) >= 0))); /* Keep only unique matching values */
        if(words.length) {
            matches.push({index, count: words.length, words});
        }
    });

    /* No matching words, return current conversation as it is*/
    if(!matches.length) {
        return currentConversation;
    }

    /* Sort by Descending word count, Ascending index */
    matches.sort((a ,b) => {
        if(!(b.count - a.count)) {
            return a.index - b.index
        }
        return b.count - a.count;
    });

    conversationToKeep = conversations[matches[0].index];
    matchingWords = matches[0].words

    matchingWords.forEach(word => {
        let lastIndex = conversationToKeep.lastIndexOf(word);
        if(lastIndex > lastMatchingWordIndex) {
            lastMatchingWordIndex = conversationToKeep.lastIndexOf(word);
        }
    });

    missingWords = conversationToKeep.slice(lastMatchingWordIndex + 1);

    return currentConversation.map(word => word).concat(missingWords);
}
Jason Luboff
@JLuboff
Mar 15 2018 15:09
@X140hu4 Yup, that'd actually probably be the better way. Add/Remove class based on what you want to occur
Fabien SHAN
@X140hu4
Mar 15 2018 15:10
@JLuboff It feels very spaghetti when I manipulate too much css in JS haha
Jason Luboff
@JLuboff
Mar 15 2018 15:11
Ya I was just thinking that. While either way is viable, how much CSS manipulation do you really want to do with JS
Zunaid Aslam
@ZunaidAslam
Mar 15 2018 15:27
Yeah adding and removing class sounds like a better solution
NikolaNbgd
@NikolaNbgd
Mar 15 2018 15:36
Hello folks. I'm trying to create an animation on scroll, here is the code https://codepen.io/anon/pen/yvmRjJ?editors=1111, so my idea is to turn that damn circle on scroll and each section has own angle and color of that circle. That error has been torturing me for days. Any help? Advice? Many thanks!
Christopher McCormack
@cmccormack
Mar 15 2018 16:45
:wave:
@NikolaNbgd I don't think Circle is a built in - what type of Circle are you trying to use?
Blauelf
@Blauelf
Mar 15 2018 16:50
Circle is defined after use. Wrong order.
Christopher McCormack
@cmccormack
Mar 15 2018 16:50
Yeah just saw that
@NikolaNbgd you can't use the function declaration out of order like that, declare Circle at the top
NikolaNbgd
@NikolaNbgd
Mar 15 2018 16:51
@cmccormack I did it guys! Solved
Blauelf
@Blauelf
Mar 15 2018 16:51
Has nothing to do with ES6. IIFEs are not hoisted like function definitions.
Christopher McCormack
@cmccormack
Mar 15 2018 16:51
@NikolaNbgd oh great
@Blauelf hah already edited myself
Jason Luboff
@JLuboff
Mar 15 2018 17:40
@cmccormack :wave:
Keegan
@Keggatron
Mar 15 2018 17:40
Can anyone help me with getting the values out of a redux-form
I have this so far:
const FetchValues = connect(state => ({
    values: getFormValues('wizard')(state),
  }))(({ values }) => {
    const orderValues = values
    return orderValues
  });
Christopher McCormack
@cmccormack
Mar 15 2018 17:41
@JLuboff how's it going?
Keegan
@Keggatron
Mar 15 2018 17:42
I can't call that from anywhere else though. I'm just looking for a way to set the form values to an object so that I can actually submit them
sorry I mean I can't call orderValues and when I log FetchValues I don't actually get what I want
Jason Luboff
@JLuboff
Mar 15 2018 17:44
@cmccormack Doing alright. Just got back to work from an allergist appointment for my son. Good news is, most likely isn't allergic to the dog. Bad news is, we still don't know what he is allergic to unless we do a prick test.. How about you?
Christopher McCormack
@cmccormack
Mar 15 2018 17:45
@JLuboff Good super busy with work, miss coding :( Probably dig back in hardcore in a couple weeks
Jason Luboff
@JLuboff
Mar 15 2018 17:46
@cmccormack Thats all I've been trying to do at work is code, finally got my queries moved out to seperate file(s) and continuing work on the actual page. Whats been keeping you busy at work, new equipment?
Christopher McCormack
@cmccormack
Mar 15 2018 17:46
Just deadlines, some big ones due by end of the month
Jason Luboff
@JLuboff
Mar 15 2018 17:47
Luckily I don't really get deadlines lol
I sometimes give myself deadlines but otherwise, things are fairly lax here
Christopher McCormack
@cmccormack
Mar 15 2018 17:48
@JLuboff That sounds so nice. Sometimes I wish I was an all-around guy at a smaller company so I could dig into more tech, and not have my changes affect hundreds of sites globally if I mess up
Thinking of starting my own consultancy company so I can set my own hours and work :)
Jason Luboff
@JLuboff
Mar 15 2018 17:50
That'd be nice
I've done some consultant work on the side, but just for home users not businesses
Christopher McCormack
@cmccormack
Mar 15 2018 17:54
What kind of work?
Jason Luboff
@JLuboff
Mar 15 2018 17:56
Just mainly setup new computers, TV's, phones, etc. Bit of training. That sort of thing. I guess technically I've done business work to, but while working under a company, never independently. Then it was setting up Apple servers, VPNs, etc
Christopher McCormack
@cmccormack
Mar 15 2018 17:58
I did something like that when I was in my teens but the guy never paid me. Was interesting but he was nuts
Jason Luboff
@JLuboff
Mar 15 2018 17:58
:joy:
I always get paid on site
Actually. I did do a business on site independently that I billed after the fact
But it was for one of my mom's best friends so no issue
Christopher McCormack
@cmccormack
Mar 15 2018 18:03
It makes me nervous thinking about doing work independently but I guess you just have to jump in
Jason Luboff
@JLuboff
Mar 15 2018 18:07
Oh I agree. As a full time gig, I wouldn't be up for it
I've dealt with some of those guys and a lot of them are very high strung
but then I also have a buddy who does really well
He has a few business clients that he has SLA's with
Christopher McCormack
@cmccormack
Mar 15 2018 18:10
I think that's where the money is
long term support with many clients
Jason Luboff
@JLuboff
Mar 15 2018 18:11
Absolutely. Stick in a higher charge for quicker response
Christopher McCormack
@cmccormack
Mar 15 2018 18:14
Easier than ever now too, Wifi everywhere and laptops have long charges, I could work from a bar :) (I had to do this once several years ago when we had an outage and I was on call)
Jason Luboff
@JLuboff
Mar 15 2018 18:15
He often works from the beach ;)
Christopher McCormack
@cmccormack
Mar 15 2018 18:23
Sounds wonderful. I'm trying to get my wife to get a remote job so we can both be digital nomads
Razvan Jackson
@RazvanJackson
Mar 15 2018 18:29
Someone who used passport.js?
Christopher McCormack
@cmccormack
Mar 15 2018 18:29
@RazvanJackson there's probably someone! What's your question?
Jason Luboff
@JLuboff
Mar 15 2018 18:31
@cmccormack That'd be cool
Razvan Jackson
@RazvanJackson
Mar 15 2018 18:32
How to use it with React routing if i have 2 servers one for frontend one for backend
Jason Luboff
@JLuboff
Mar 15 2018 18:32
@RazvanJackson Yes, I've used it for several projects (specifically, github, facebook, twitter and local strategies)
Oh psh... no clue for react
Christopher McCormack
@cmccormack
Mar 15 2018 18:33
@RazvanJackson what I did was create a PrivateRoute that basically does a backend call for any component that requires auth, validates the user session still exists and the user is authorized, then returns an object containing success/failure and any error message or whatever
Razvan Jackson
@RazvanJackson
Mar 15 2018 18:34
@cmccormack Thanks
CamperBot
@camperbot
Mar 15 2018 18:34
razvanjackson sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1378 | @cmccormack |http://www.freecodecamp.org/cmccormack
Christopher McCormack
@cmccormack
Mar 15 2018 18:35
@RazvanJackson PrivateRoute uses a function that does a fetch request against an api endpoint. You can see it here in my app if you want - it's not done yet but a lot of that functionality is working right now . https://github.com/cmccormack/voting-app
Jason Luboff
@JLuboff
Mar 15 2018 19:00
The space argument in JSON.stringify() is a life saver
Christopher McCormack
@cmccormack
Mar 15 2018 19:01
@JLuboff the ..., null, 2) or whatever?
Jason Luboff
@JLuboff
Mar 15 2018 19:01
Yup!
I had forgotten about it but knew there was a way to format console messages
Christopher McCormack
@cmccormack
Mar 15 2018 19:02
Yeah man it's my fav
Jason Luboff
@JLuboff
Mar 15 2018 19:02
My data went from one ugly block to a nice formattedl ist
Tiago Correia
@tiagocorreiaalmeida
Mar 15 2018 19:03
@AdelMahjoub check my msg on codefights mate
Jason Luboff
@JLuboff
Mar 15 2018 19:03
Now to create my template...
Christopher McCormack
@cmccormack
Mar 15 2018 19:03
@JLuboff have fun man
I'm out for an hour or so see ya
Jason Luboff
@JLuboff
Mar 15 2018 19:03
@cmccormack Thanks. Im finishing my lunch, then heading to the gym then be back
CamperBot
@camperbot
Mar 15 2018 19:03
jluboff sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1379 | @cmccormack |http://www.freecodecamp.org/cmccormack
Kaz Baig
@kbaig
Mar 15 2018 19:18
@JLuboff that JSON.stringify comment blew my mind. Just finished reading the docs
cody j Green
@codyjgreen
Mar 15 2018 19:36
how do i use mongoose to build a schema that has a string of say hops but that for each instance of it would have a value associated with it of the ammount of hops? so when i made a new recipe i could say Hops: galaxy Ammount: 4oz
Ronique Ricketts
@RoniqueRicketts
Mar 15 2018 19:43
Herllo
function Dog(name
) {
  this.name = name; 
}

Dog.prototype = {
  // Add your code below this line
  numLegs: 7,
  eat: ()=>{
    console.log("munch munch munch!");
  },
  describe: function() {
    console.log("My dog name is " + this.name);
  }

};
let ash = new Dog('ash');

console.log(ash.describe());
console.log(ash.eat())
this is returning
"My dog name is ash"
undefined
"munch munch munch!"
undefined
Why am I getting 2 undefined?
```
Christopher McCormack
@cmccormack
Mar 15 2018 19:50
@RoniqueRicketts your logging your return as well on the last two lines, either return a string in your functions or don't log when you invoke them
Ronique Ricketts
@RoniqueRicketts
Mar 15 2018 19:52
ok ill try that. :)
@cmccormack thanks bruv
CamperBot
@camperbot
Mar 15 2018 19:52
roniquericketts sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1380 | @cmccormack |http://www.freecodecamp.org/cmccormack
Ronique Ricketts
@RoniqueRicketts
Mar 15 2018 19:56
@cmccormack so while in es6 how would I access this.name in this case
Christopher McCormack
@cmccormack
Mar 15 2018 19:57
@RoniqueRicketts in an es6 arrow function? You wouldn't
Ronique Ricketts
@RoniqueRicketts
Mar 15 2018 19:58
@cmccormack what would I use to access the name
Christopher McCormack
@cmccormack
Mar 15 2018 19:58
@RoniqueRicketts a regular function
or just call the property on the object itself
hmm I see you aren't using an ES6 function
I really need to read closer the first time :D
@RoniqueRicketts I believe you can add the function after the declaration and this should work
Ronique Ricketts
@RoniqueRicketts
Mar 15 2018 20:05
@cmccormack I changed to full ()=>{}
Tiago Correia
@tiagocorreiaalmeida
Mar 15 2018 20:07
@AdelMahjoub brownies hunter around?
and hey there @RoniqueRicketts haven't seen you in a while :)
Adel
@AdelMahjoub
Mar 15 2018 20:08
@tiagocorreiaalmeida how can I be a brownies hunter with merely ~670
Ronique Ricketts
@RoniqueRicketts
Mar 15 2018 20:09
@tiagocorreiaalmeida Yeah I have been lazy I was learnign FCC content with a group of Developers from Jamaica. Now we are at Basic Algorithms. Soon redo the Web apps and then backend
@tiagocorreiaalmeida hbu?
Tiago Correia
@tiagocorreiaalmeida
Mar 15 2018 20:10
ehehhe :D two months ago or something like that you gave me a few info about the roguelike dungeon game, back then I wasnt really interested in building it but I guess the motivation is here now, if you dont mind giving some of them again :\
nice @RoniqueRicketts , lately just lazy and addicted to codefights :D
and built something close to a blog using react on the client side finally
Christopher McCormack
@cmccormack
Mar 15 2018 20:11
@RoniqueRicketts how much is a hamburger in Jamaica?
Ronique Ricketts
@RoniqueRicketts
Mar 15 2018 20:11
@tiagocorreiaalmeida oh wanna fight soon
Tiago Correia
@tiagocorreiaalmeida
Mar 15 2018 20:12
@RoniqueRicketts how about now?since its all about having fun
Adel
@AdelMahjoub
Mar 15 2018 20:12
@tiagocorreiaalmeida there are some definitions of the genre but you are not restricted, I'll take alook at , should have some links around
Tiago Correia
@tiagocorreiaalmeida
Mar 15 2018 20:13
thanks @AdelMahjoub I think mainly I need to understand the game logic, there was also a library I think?
CamperBot
@camperbot
Mar 15 2018 20:13
:cookie: 677 | @adelmahjoub |http://www.freecodecamp.org/adelmahjoub
tiagocorreiaalmeida sends brownie points to @adelmahjoub :sparkles: :thumbsup: :sparkles:
Adel
@AdelMahjoub
Mar 15 2018 20:13
@tiagocorreiaalmeida have played any rogue-like games ?
Ronique Ricketts
@RoniqueRicketts
Mar 15 2018 20:14
@cmccormack it varies its about JS $650 - $750
Christopher McCormack
@cmccormack
Mar 15 2018 20:14
@RoniqueRicketts thanks - it's an honest question as well - https://www.economist.com/content/big-mac-index
CamperBot
@camperbot
Mar 15 2018 20:14
:cookie: 417 | @roniquericketts |http://www.freecodecamp.org/roniquericketts
cmccormack sends brownie points to @roniquericketts :sparkles: :thumbsup: :sparkles:
Christopher McCormack
@cmccormack
Mar 15 2018 20:15
Just curious if you can work remotely and get paid similar to someone in another country/state how much additional value you would get
Tiago Correia
@tiagocorreiaalmeida
Mar 15 2018 20:15
yours :D
Ronique Ricketts
@RoniqueRicketts
Mar 15 2018 20:16
@tiagocorreiaalmeida nice yuh building stuff
@cmccormack Please tell me you have a job to offer me.
@cmccormack its about USD $6.50
Christopher McCormack
@cmccormack
Mar 15 2018 20:19
@RoniqueRicketts I do not sorry haha I am in no position to hire someone unless you're also a competent network engineer
Ronique Ricketts
@RoniqueRicketts
Mar 15 2018 20:19
@cmccormack minimal
@cmccormack I know how to plug a network cable in a Modem :)
Tiago Correia
@tiagocorreiaalmeida
Mar 15 2018 20:20
well its a start @RoniqueRicketts :D
so are you into doing a 10min tournament on codefights now ?
Ronique Ricketts
@RoniqueRicketts
Mar 15 2018 20:21
@tiagocorreiaalmeida haha your all so awful
Tiago Correia
@tiagocorreiaalmeida
Mar 15 2018 20:21
I can maybe try to get @cmccormack to join us :D
Ronique Ricketts
@RoniqueRicketts
Mar 15 2018 20:21
@tiagocorreiaalmeida no, sah, I am not familiar with it I may have to look up and get some algorithm practice ;)
Tiago Correia
@tiagocorreiaalmeida
Mar 15 2018 20:21
doing a tournament its pratice :)
some of they are even simpler than the fcc ones depends really of the situation
Adel
@AdelMahjoub
Mar 15 2018 20:24
Start by collecting some info about the genre Rogue Basin a lot of info in this site. Then try to prototype some with ROT, Quick ROT tutorial, long rot tutorial old but useful. You can use some parts of rotjs with react or anything, son't have to use the renderer etc. pathfinding lib: easystar, opengameart for game assets.
@tiagocorreiaalmeida take your time and explore, and play some for some inspiration :smile:
Jason Luboff
@JLuboff
Mar 15 2018 20:25
@kbaig :+1: I had forgotten about it but I remember in one of my udemy courses they used it. I think when you're in mongo shell and use pretty() that it's doing the same thing
Tiago Correia
@tiagocorreiaalmeida
Mar 15 2018 20:25
thanks @AdelMahjoub once again :)
CamperBot
@camperbot
Mar 15 2018 20:25
tiagocorreiaalmeida sends brownie points to @adelmahjoub :sparkles: :thumbsup: :sparkles:
api offline
Ronique Ricketts
@RoniqueRicketts
Mar 15 2018 20:25
Btw I now have a team of devs that go through fcc live on FB and newly on youtube, every, Sunday, Tuesday and Thursday. If any of you want to join us and share some knowledge with us you always welcome. You may hear some Jamaican Dilect
Adel
@AdelMahjoub
Mar 15 2018 20:27
@tiagocorreiaalmeida the easiest solutions for game screens is to position multiple divs with identical dimensions on top of each others, and hide/show according to your game state
aRtoo
@artoodeeto
Mar 15 2018 20:29
hello. someone here?
Tiago Correia
@tiagocorreiaalmeida
Mar 15 2018 20:30
alot of people @artoodeeto eheh
aRtoo
@artoodeeto
Mar 15 2018 20:30
@tiagocorreiaalmeida hey bro can you help me?
Tiago Correia
@tiagocorreiaalmeida
Mar 15 2018 20:31
sure @artoodeeto
Ronique Ricketts
@RoniqueRicketts
Mar 15 2018 20:32
@tiagocorreiaalmeida @cmccormack @JLuboff you all could join in with us Jamaicans and do some FCC algorithms with us one evening if you like :)
Its our version of a mini online meetup
aRtoo
@artoodeeto
Mar 15 2018 20:33
i have an issue of getting location. so when i try to get the location and console log it. it will first say undefined and then i my console log inside the function of geolocation is being posted. i know that its because of asynchronous but how would you address this?
@tiagocorreiaalmeida
heres my code.
  let long;
    let lat;

    // function getCoords() {
        navigator.geolocation.getCurrentPosition(
            position => {
                long = position.coords.longitude
                lat = position.coords.latitude
                console.log(position)                
            },
            () => alert("CANT GET LOCATION")
        )
    // }getCoords()

    console.log('the coords', long, lat) //undefined
should i put a condition inside the first arrow function?
no because it will fire as soon as the geolocation is being retrive
@tiagocorreiaalmeida i just did this.
 // function getCoords() {
        navigator.geolocation.getCurrentPosition(
            position => {
               const long = position.coords.longitude
               const lat = position.coords.latitude
                hala()
                console.log(position)                
            },
            () => alert("CANT GET LOCATION")
        )
    // }getCoords()

    function hala(){
        console.log('the coords', long, lat) //undefined 
    }
Jason Luboff
@JLuboff
Mar 15 2018 20:37
You can call your function within geolocation (which it looks like you are)
aRtoo
@artoodeeto
Mar 15 2018 20:37
so i wrap my console.log inside the hala fn. then call it inside the first arrow function. if you find better way bro pm me thanks
Jason Luboff
@JLuboff
Mar 15 2018 20:39
You also need to pass in the variables, hala doesn't know what long/lat are
aRtoo
@artoodeeto
Mar 15 2018 20:39
@JLuboff yea. but im gonna use react for the first time i dont know if im gonna put the state inside the first arrow fn.
@JLuboff oh right. thanks sir
CamperBot
@camperbot
Mar 15 2018 20:40
artoodeeto sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2367 | @jluboff |http://www.freecodecamp.org/jluboff
aRtoo
@artoodeeto
Mar 15 2018 20:41
im just gonna do my react inside the hala function. what do you think?
Jason Luboff
@JLuboff
Mar 15 2018 20:42
Someone with react experience will have to answer that
aRtoo
@artoodeeto
Mar 15 2018 20:47
@JLuboff i got a solution i dont know if its the best but heres the code
  navigator.geolocation.getCurrentPosition(
            position => {
               const long = position.coords.longitude
               const lat = position.coords.latitude
// so  i just render my component here then pass the lat and long as props
               ReactDOM.render(<Weather long={long} lat={lat}/>, document.getElementById('root'))              
            },
            () => alert("CANT GET LOCATION")
        )


    // function hala(long ,lat){
    //     console.log('the coords', long, lat) //undefined 
    // }

    class Weather extends React.Component {
        constructor(props){
            super(props)
            this.state = {
                null: null
            }
        }
//on the return i just took the props in the component 
        render(){
            return(
                <div> {this.props.lat} {this.props.long} </div>
            )
        }
    }
Jason Luboff
@JLuboff
Mar 15 2018 20:49
Ok, I don't know react so I can't really tell if thats good or not lol
aRtoo
@artoodeeto
Mar 15 2018 20:50
@JLuboff ohh ok sir. sorry i was just starting react yesterday. thanks for the response too. :)
CamperBot
@camperbot
Mar 15 2018 20:50
artoodeeto sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
api offline
Christopher McCormack
@cmccormack
Mar 15 2018 20:51
@artoodeeto if you're trying to render your components within your callback, you're probably thinking about it wrong
Kaz Baig
@kbaig
Mar 15 2018 20:51
@artoodeeto Are you trying to use the coords on page load?
aRtoo
@artoodeeto
Mar 15 2018 20:52
@cmccormack hmm. is there another way sir?
@kbaig . so basically im redoing my weather challenge with React so when the user gets into the page it will automatically show their weather. so yes. any idea sir?
Christopher McCormack
@cmccormack
Mar 15 2018 20:53
@artoodeeto Only render your main app with ReactDOM. in your api call you can utilize a function passed down from a parent that is maintaining state, and when that function is invoked and state is updated in the parent, the parent should render the new information if you are relying on state for your renders
Kaz Baig
@kbaig
Mar 15 2018 20:54
set your coords to the state of the component in componentDidMount @artoodeeto
Christopher McCormack
@cmccormack
Mar 15 2018 20:54
@artoodeeto you can also do it within the same component like @kbaig said
aRtoo
@artoodeeto
Mar 15 2018 20:56
@cmccormack im not rendering my component with the callback sir. the ReactDOM.render is inside the first arrow fn. so basically the ReactDOM method still renders it.
@kbaig right. why didnt i think of that. ok sir im gonna try that life cycle. thanks
CamperBot
@camperbot
Mar 15 2018 20:57
artoodeeto sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 582 | @kbaig |http://www.freecodecamp.org/kbaig
Christopher McCormack
@cmccormack
Mar 15 2018 20:57
@artoodeeto that arrow function is a callback
aRtoo
@artoodeeto
Mar 15 2018 20:57
@cmccormack thank you too sir
CamperBot
@camperbot
Mar 15 2018 20:57
artoodeeto sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1381 | @cmccormack |http://www.freecodecamp.org/cmccormack
Christopher McCormack
@cmccormack
Mar 15 2018 20:58
@artoodeeto ReactDOM.render should be used only to mount your main component
aRtoo
@artoodeeto
Mar 15 2018 20:58
@cmccormack right. i thougt you were saying like this.
() => {
<Component />
}
Christopher McCormack
@cmccormack
Mar 15 2018 20:58
you can actually do more with ReactDOM.render but I'd recommend doing it the standard way for now
aRtoo
@artoodeeto
Mar 15 2018 20:59
@cmccormack ohhh. ok ok. thank thank you sir. so this is wrong. im gonna try what @kbaig said. :)
CamperBot
@camperbot
Mar 15 2018 20:59
artoodeeto sends brownie points to @cmccormack and @kbaig :sparkles: :thumbsup: :sparkles:
api offline
api offline
Christopher McCormack
@cmccormack
Mar 15 2018 21:00
@artoodeeto yup if doing it within the same component componentDidMount is where you're supposed to call APIs
Kaz Baig
@kbaig
Mar 15 2018 21:01
@artoodeeto wrote it up without checking but hopefully it gets the idea accross
class Weather extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            coords: null
        }
    }

    componentDidMount () {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(position => {
                this.setState({ coords: { ...position.coords } });
            });
        }
    }

    render () {
        return({ this.state.coords &&
            <div> {this.props.lat} {this.props.long} </div>
        });
    }
}
aRtoo
@artoodeeto
Mar 15 2018 21:04
@kbaig @cmccormack again sir thank you.
CamperBot
@camperbot
Mar 15 2018 21:04
artoodeeto sends brownie points to @kbaig and @cmccormack :sparkles: :thumbsup: :sparkles:
api offline
api offline
Kaz Baig
@kbaig
Mar 15 2018 21:05
@cmccormack see any issues with what I wrote? Didn't have time to run it
aRtoo
@artoodeeto
Mar 15 2018 21:08
@kbaig i was about to copy it sir. but i have one more question. can use the componentDidMount again? like what if im gonna fetch API again for the weather?
Jason Luboff
@JLuboff
Mar 15 2018 21:10
@kbaig You got that fancy computer and can't run a little code? Should be lickity-split quick!
Kaz Baig
@kbaig
Mar 15 2018 21:10
@JLuboff I'm at work on 2 core 3.0 GHz laptop :(
Jason Luboff
@JLuboff
Mar 15 2018 21:11
@kbaig Ouch. Thats all they give you?
Kaz Baig
@kbaig
Mar 15 2018 21:12
@JLuboff yeaaah no GPU either :'(
Markus Kiili
@Masd925
Mar 15 2018 21:12
Evening.
Jason Luboff
@JLuboff
Mar 15 2018 21:12
@kbaig Meh.. I have no GPU in my work computer, just on board. Works fine for what I need
@Masd925 Afternoon!
Kaz Baig
@kbaig
Mar 15 2018 21:12
@JLuboff Well if they want me to R&D our computational tech, it's somewhat inconvenient
Jason Luboff
@JLuboff
Mar 15 2018 21:13
@kbaig Tell them to get you a better computer than :P
Kaz Baig
@kbaig
Mar 15 2018 21:13
@artoodeeto Assuming you mean you want to implement a 'refresh data' type button, you'd just call this.setState in a different method in your class whenever your button is clicked or whatever the event is
@JLuboff I've only been here for ~7 months so probs need to the computer to fizzle before they give me something new
Jason Luboff
@JLuboff
Mar 15 2018 21:14
Was it a used computer when you got it?
Kaz Baig
@kbaig
Mar 15 2018 21:14
Not sure
I know they do that
Christopher McCormack
@cmccormack
Mar 15 2018 21:15
Ah sorry got pulled away
Jason Luboff
@JLuboff
Mar 15 2018 21:16
Did it look used? Or are the specs > than 2 years old?
Ronique Ricketts
@RoniqueRicketts
Mar 15 2018 21:16
@cmccormack yuh too lie
Jason Luboff
@JLuboff
Mar 15 2018 21:16
Or did you replace someone? A lot of times if we replace someone they get their old computer
Christopher McCormack
@cmccormack
Mar 15 2018 21:17
@kbaig yeah looks pretty good - will the object destructuring maintain all nested objects?
Kaz Baig
@kbaig
Mar 15 2018 21:17
@cmccormack I just assumed position.coords has two attr's in it
State would end up looking like
{
  coords: {
    latitude: '123',
    longitude: '123'
  }
}
That was the goal anyway
aRtoo
@artoodeeto
Mar 15 2018 21:21
@kbaig desctruring didnt work sir. it had to pull multiple data. so i just did the same. :)
Kaz Baig
@kbaig
Mar 15 2018 21:22
@artoodeeto oh right I forgot position is not actually an object. My b @cmccormack
a plain object anyways
Christopher McCormack
@cmccormack
Mar 15 2018 21:26
@kbaig I still appreciate you providing the code :)
Jason Luboff
@JLuboff
Mar 15 2018 21:30
Lame.. <a href="file:///\\servername..." doesn't work in FF or Chrome only in Edge.. erg
Jason Luboff
@JLuboff
Mar 15 2018 21:37
Looks like Express has res.download... may work for me
alpox
@alpox
Mar 15 2018 21:37
@JLuboff whats with the \\
Christopher McCormack
@cmccormack
Mar 15 2018 21:37
to download files? good to know
Jason Luboff
@JLuboff
Mar 15 2018 21:38
@cmccormack Ya, I need to read more but looks like it transfers the file as an attachment
@alpox Windows UNC path
AKA the path to the file on the local server
Christopher McCormack
@cmccormack
Mar 15 2018 21:38
why would that be in your href though?
alpox
@alpox
Mar 15 2018 21:39
@JLuboff Probably the reason why FF and Chrome don't work with that ;)
Jason Luboff
@JLuboff
Mar 15 2018 21:39
@alpox Thats exactly why. It's a damn intranet page, let me do what I want! But I get it
alpox
@alpox
Mar 15 2018 21:39
They are designed for cross-platform and don't know about \\ paths
So you can maybe just replace them with /
Jason Luboff
@JLuboff
Mar 15 2018 21:40
@cmccormack Individuals upload file on web page, others will want to view the file
alpox
@alpox
Mar 15 2018 21:40
@JLuboff Btw. there is also the download attribute - http://mdn.beonex.com/en/HTML/Element/a
Christopher McCormack
@cmccormack
Mar 15 2018 21:40
but that would be their own computer
if you want from server you have to specify a path on the server
Jason Luboff
@JLuboff
Mar 15 2018 21:40
@alpox The file path is automatically switching it to /. If I plug in the url that it ends up being into the url field of the browser, it accesses the file just fine
@cmccormack No, its pointing to the server path
Christopher McCormack
@cmccormack
Mar 15 2018 21:41
@JLuboff hmm I see but why not just use the server path
let the route determine if it should download
Jason Luboff
@JLuboff
Mar 15 2018 21:42
That doesn't work, acts like it can't find the file
Christopher McCormack
@cmccormack
Mar 15 2018 21:42
Do you have the route?
Jason Luboff
@JLuboff
Mar 15 2018 21:42
@alpox I'll look into that too, thanks
CamperBot
@camperbot
Mar 15 2018 21:42
jluboff sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1588 | @alpox |http://www.freecodecamp.org/alpox
Jason Luboff
@JLuboff
Mar 15 2018 21:43
@cmccormack Ya
Christopher McCormack
@cmccormack
Mar 15 2018 21:44
looks like res.download might be what you wanted ya
Jason Luboff
@JLuboff
Mar 15 2018 21:44
Thats what I'm thinking
Kaz Baig
@kbaig
Mar 15 2018 22:14
@cmccormack I try :)
Jason Luboff
@JLuboff
Mar 15 2018 23:14
@cmccormack @alpox Just FYI.. with my first test.. res.download() works like a champ :+1: