These are chat archives for MontCode/GeneralChat

2nd
Jul 2016
Eric Phy
@SimplyPhy
Jul 02 2016 00:06
So now for an example:
function LateBloomer() {
  this.petalCount = Math.ceil(Math.random() * 12) + 1;
}

// Declare bloom after a delay of 1 second
LateBloomer.prototype.bloom = function() {
  window.setTimeout(this.declare.bind(this), 1000); // does the first this select the window object, and the second (this) select the flower variable?
};

LateBloomer.prototype.declare = function() {
  console.log('I am a beautiful flower with ' +
    this.petalCount + ' petals!');
};

var flower = new LateBloomer();
flower.bloom();  
// after 1 second, triggers the 'declare' method
There's a question nested in a comment that spans right inside that code clock; should be pretty simple but I'm curious what you guys think
also: I know friday night means something for some people so sry :D
Lily Romano
@Lilyheart
Jul 02 2016 00:32
curry is something I know of, but nothing more than that.
Eric Phy
@SimplyPhy
Jul 02 2016 01:04
I found a redundancy in mozilla docs :D
SimplyPhy @SimplyPhy yay me
Eric Phy
@SimplyPhy
Jul 02 2016 01:09
just downloaded the gitter app for macOS :D
no more browser tab for me pshh
Lily Romano
@Lilyheart
Jul 02 2016 01:20
It's niiiiiiiice
Eric Phy
@SimplyPhy
Jul 02 2016 01:21
It is. Remarkably similar to the web app
Eric Phy
@SimplyPhy
Jul 02 2016 01:49
When you pass in an array as an argument into a callback function, will the values of its indexes all be put in as separate arguments?
Lily Romano
@Lilyheart
Jul 02 2016 01:54
It's really just a webpage wrapper with extra features using the API (notifications etc) and some extra spell check stuff. I like the notification icon.
Eric Phy
@SimplyPhy
Jul 02 2016 02:06
The answer to my question: No. It does happen when you pass an array into the second argument of the function.prototype.apply() method, though.
Interestingly enough, it appears that an array will be used as a single argument input, where it’s full content is converted to a string
fun facts galore
Eric Phy
@SimplyPhy
Jul 02 2016 02:27
omg.
Lily Romano
@Lilyheart
Jul 02 2016 02:27
?
Eric Phy
@SimplyPhy
Jul 02 2016 02:28
arguments is an object that you can pass into a nested function to get the parent/outer function’s arguments
:omg:
Lily Romano
@Lilyheart
Jul 02 2016 02:30
yup! very useful.
Eric Phy
@SimplyPhy
Jul 02 2016 02:30
function transitionTo () {
  var args = Array.prototype.slice.call (arguments, 1);
  console.log (args); // [“Today”, “20”]
}

transitionTo ("contact", "Today", "20");
that’s so cool!
Lily Romano
@Lilyheart
Jul 02 2016 02:30
it was used in a challenge or two i think. i’ll have to look.
Eric Phy
@SimplyPhy
Jul 02 2016 02:31
So arguments is an array-like object that exists in every function call
awesome
Lily Romano
@Lilyheart
Jul 02 2016 02:32
array like but isn’t an array. array things don;t work on it, you have to copy it to a real array for that
Eric Phy
@SimplyPhy
Jul 02 2016 02:32
that’s where .call() comes in :P
it borrows the array method slice, in my example above, and applies it to the arguments object
:D
now if only my emoji game could get with it xDD
Array.from(arguments) is probably better :p. lets you do array things like push shift pop etc
another good one you could use arguments on https://www.freecodecamp.com/challenges/sorted-union
Lily Romano
@Lilyheart
Jul 02 2016 02:39
i should have enjoyed this one, but didn’t. maybe it was a bad day https://www.freecodecamp.com/challenges/symmetric-difference
Eric Phy
@SimplyPhy
Jul 02 2016 02:41
ha I’m been studying for almost 11 hours today, and now you send me those :O
and let’s be real: :O isn’t an emoji??
cray cray
Lily Romano
@Lilyheart
Jul 02 2016 02:42
totes
why not use FCC when you need a break from clicking cats? You don’t need to do it all to get the certs.
Eric Phy
@SimplyPhy
Jul 02 2016 02:43
FCC?
oh the camp
Lily Romano
@Lilyheart
Jul 02 2016 02:43
free code camp
Eric Phy
@SimplyPhy
Jul 02 2016 02:43
hmm, I don’t know, I really doubt I have time
Lily Romano
@Lilyheart
Jul 02 2016 02:43
heh
Eric Phy
@SimplyPhy
Jul 02 2016 02:43
I don’t even have time for life
I’m also trying to do hackerrank’s 30 days of code, using javascript, c#, swift, and python 3
Lily Romano
@Lilyheart
Jul 02 2016 02:44
you’ll see more fcc posts here than any other website. just so you know, we aren’t tryin’ to pull you in.
Eric Phy
@SimplyPhy
Jul 02 2016 02:44
I prob would do it, and maybe I’ll get involved in some way, I just literally don’t know if there’s time
I just signed up <3
All they want me to do it commit to female coders :sigh:
Lily Romano
@Lilyheart
Jul 02 2016 02:47
wha
Eric Phy
@SimplyPhy
Jul 02 2016 02:49
nevermind, there was one without gender preference
w00t
so I’m investigating it now..
Lily Romano
@Lilyheart
Jul 02 2016 02:50
/confused
Eric Phy
@SimplyPhy
Jul 02 2016 02:51
if you go to your account > edit my settings > edit my pledge, a page comes up with 4-5 female exclusive coding organizations you can pledge $$s to, and 1-2 alts
Lily Romano
@Lilyheart
Jul 02 2016 02:52
respect the gender challenge.
Eric Phy
@SimplyPhy
Jul 02 2016 02:52
:)
Lily Romano
@Lilyheart
Jul 02 2016 02:52
it’s real and it sucks. hard.
but you don’t gotta pledge anything either :p
Eric Phy
@SimplyPhy
Jul 02 2016 02:53
i don’t have much knowledge of it, aside from the fact that significantly fewer women are employed as tech engineers than there are men
Lily Romano
@Lilyheart
Jul 02 2016 02:53
i don’t
Eric Phy
@SimplyPhy
Jul 02 2016 02:53
internationally i imagine it’s a much more dire problem
the front end cert is pretty extensive
anywho, I’m getting kicked off
night night!
Lily Romano
@Lilyheart
Jul 02 2016 02:55
the algorthm challenges can be a bear,
nini
Victor
@VictorHall
Jul 02 2016 11:54
hello all, I have question regarding ajax requests and objects
How come my page crashes when I try to access this json outside of the getJSON method
This message was deleted
           var location; 
       $.getJSON('http://ipinfo.io', function(data){
    // Only change code below this line.

    location = data.city    });
David Castner
@davidjcastner
Jul 02 2016 11:58
where are you trying to use location
Victor
@VictorHall
Jul 02 2016 11:58
@davidjcastner @Lilyheart @SimplyPhy
I want to make it global
but in another method
hold on ill post it
I want to access it in an event handler

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

var weather = new XMLHttpRequest();
weather.open("GET", "http://api.wunderground.com/api/93910d71a9cf0a66/conditions/q/CA/San_Francisco.json", false);
weather.send(null);

var r = JSON.parse(weather.response); 
var weather= "Current location: " + r.current_observation.display_location.full + "<br />"
+ "Current temperature" + r.current_observation.temperature_string + "<br />"  
+ "Current Wind Speed: " + r.current_observation.wind_string + "<br />";

/*var temp = "Current temperature" + r.current_observation.temperature_string + "<br />";
var wind = "Current Wind Speed: " + r.current_observation.wind_string + "<br />";*/

document.getElementById("info").innerHTML = weather;

});

instead of CA/San_Francisco I want to add the location in the api call
David Castner
@davidjcastner
Jul 02 2016 12:03
have you used $.ajax?
just have you used that before, not if you used it in your code
Victor
@VictorHall
Jul 02 2016 12:05
yes, my page still crashes
Victor
@VictorHall
Jul 02 2016 12:16
sorry @davidjcastner $.ajax does work. I must of had a misspelling in there when I tried it.
David Castner
@davidjcastner
Jul 02 2016 12:19

okay I don't see anything wrong in your $.getJSON call so I'm assuming the error is where you use the variable location. Here is one possibility:

var location;
$.getJSON('http://ipinfo.io', function(data) {
    location = data.city;
});
// at this point location will be undefined because the request has not returned
// $.getJSON and $.ajax are asynchronous and the handler for location only belongs
// inside of the callback for $.getJSON or the successCallback for $.ajax
console.log(location);

I like to use $.ajax because it has all of the settings, and $.getJSON is really just shorthand for $.getJSON

jQuery.getJSON docs

This is a shorthand Ajax function, which is equivalent to:

$.ajax({
  dataType: "json",
  url: url,
  data: data,
  success: success
});

jQuery.ajax docs: http://api.jquery.com/jQuery.ajax/

$.ajax request explained

// you can read more about what settings ajax takes in the ajax docs
var dataToSend;

var successCallback = function(results) {
    // results is when we get back, this function isn't called until the
    // reponse has been returned
};

var errorCallback = function(error) {
    // error is when we get back, this function isn't called until the
    // reponse has been returned
};

$.ajax({
    // defaults to a  GET request
    // [optional] type: 'GET',
    // url is where we are making the request
    url: url,
    // data type is the type of data we expect back
    dataType: "json",
    // data is what we send to in the body of the request
    data: dataToSend,
    // success is a callback function triggered when the response is returned
    // and the response is successful
    success: successCallback,
    // error is a callback function triggered when the response is returned
    // and the response has failed
    error: errorCallback
});
Victor
@VictorHall
Jul 02 2016 12:30
This makes more sense when I was reading everything last night it did not
thanks @davidjcastner
Jonathan Herman
@lantech19446
Jul 02 2016 18:15
finally built something in JS that works, nothing very complicated but this is the furthest I've gotten so far :)
Eric Phy
@SimplyPhy
Jul 02 2016 18:36
:+1:
David Castner
@davidjcastner
Jul 02 2016 18:45
@lantech19446 woo! congrats, share??? :clap:
Eric Phy
@SimplyPhy
Jul 02 2016 18:59
addComputer("mac");
addYear("1997");
addScreenSize("jumbo”);
:P
Eric Phy
@SimplyPhy
Jul 02 2016 19:05
ha, I just spent some time trying to figure out why some code wouldn’t run
turns out I’m just way too advanced for these puny browsers #es6
Jonathan Herman
@lantech19446
Jul 02 2016 19:05
Need semicolons after each one i did the same thing
Eric Phy
@SimplyPhy
Jul 02 2016 19:38
learning programming is so much better once you’ve gotten to the point that you can digest documentation :santa:
Eric Phy
@SimplyPhy
Jul 02 2016 20:43
thought on whether or not encapsulating the entirety of a js file in an anonymous function has benefits?
maybe okay with a single js file for a site/app, but no good when using multiple js files that rely upon eachother?
Eric Phy
@SimplyPhy
Jul 02 2016 21:05
another question: can you call a function that’s nested inside an anonymous function from outside of that anonymous function? ... for example if it’s returned?
Lily Romano
@Lilyheart
Jul 02 2016 22:04
Sorry, I'm keeping an eye on chat but I'm mostly using the cell. Much house stuff. Pretty sure the kitchen needs gutting. Cabinets at least. /Sigh
Added to what already needs replaced
Eric Phy
@SimplyPhy
Jul 02 2016 22:05
ha no probz; i’m almost literally always here, and i can’t imagine anybody else adhering to that standard. The questions aren’t urgent at all; just curiosities that i feel this group can likely assist with at some point :D
Lily Romano
@Lilyheart
Jul 02 2016 22:11
I pretty much do two things. Code and work on this house. I'd rather just code.
Eric Phy
@SimplyPhy
Jul 02 2016 22:11
but alas..if the house fails, the code fails
:sigh: