These are chat archives for FreeCodeCamp/Help

16th
Jan 2015
Rob Colella
@robcolella
Jan 16 2015 03:13
Good evening!
Dominic Jones
@towwiow
Jan 16 2015 04:56
good evening @robcolella
Bin Ury
@teddy-error
Jan 16 2015 08:46
while (null !== (chunk = request.read() ) )
WHY are we putting assignments inside of conditionals!?!
is this a thing
it is a thing. this is weird.
okay so, if there are no more request chunks to read, request.read() will return null and then we can break right
Maxim Orlov
@Maximization
Jan 16 2015 10:33
@teddy-error you assign input data to chunk and check if it's not equal to null, if that is true you process chunk
if the condition is false you indeed break out of the loop
you can put as many assignment as you want where a condition is expected, as long as the final expression results into a true/false condition
Bin Ury
@teddy-error
Jan 16 2015 10:38
i've never seen that in a clever way before. Generally seeing an assignment in a conditional was a sign of an accidental use in place of a comparision ==.
So that was hardcoded in my brain
very cool though
it's kind of shorthand i think
do while (null !== chunk  )
 chunk = request.read()
Maxim Orlov
@Maximization
Jan 16 2015 10:49
well, if you'll have to do the assignment before the test then
because if you don't assign request.read() to chunk, chunk is going to be undefined and therefore false which is equal to null
Bin Ury
@teddy-error
Jan 16 2015 10:51
unless i am mistaken a do while skips the conditional and executes the body upon first loop
in either situation, we would need to instantiate the chunk variable outside the loop anyway
Maxim Orlov
@Maximization
Jan 16 2015 10:52
yeah
Ben Clist
@BenClist
Jan 16 2015 10:53
you put the while after the body in a do while loop ;)
Bin Ury
@teddy-error
Jan 16 2015 11:13
i am so dumb i cannot believe i forgot do whiles.
here before you, i commit coder seppuku
farewell
i mean sodoku
Christopher Nguyen
@crosscris
Jan 16 2015 13:28
Does anyone have trouble editing the jquery-exercises file on challenge 15?
Nathan
@terakilobyte
Jan 16 2015 13:33
link the challenge please
I've gotten to the chrome dev tools and placed the next exercise code below the '.next-button' code...but I believe what I'm saving isn't being applied
Nathan
@terakilobyte
Jan 16 2015 13:52
what are you typing in your console, and what exercise on that page?
Christopher Nguyen
@crosscris
Jan 16 2015 13:53
$('#next-exercise').attr('disabled', false); is going into the console.
Exercise 1
Nathan
@terakilobyte
Jan 16 2015 13:54
hmm
it works for me :/
Christopher Nguyen
@crosscris
Jan 16 2015 13:54
hmm....can I send you a screen shot?
Nathan
@terakilobyte
Jan 16 2015 13:54
I literally just pasted what you typed and hit enter
Christopher Nguyen
@crosscris
Jan 16 2015 13:55
hmm...
Christopher Nguyen
@crosscris
Jan 16 2015 13:56
O....the console, I was trying to edit the JS file....
Nathan
@terakilobyte
Jan 16 2015 13:56
lol
and bob's your uncle ;)
holler out if you run into any more issues!
Christopher Nguyen
@crosscris
Jan 16 2015 13:57
yeah, the obvious things are always the trickiest, thanks tera
Maxim Orlov
@Maximization
Jan 16 2015 14:11
@crosscris which is why this challenges immediately proceeds chrome's dev tools
Gregory Scheerlinck
@greg-js
Jan 16 2015 15:46
Hello, I was wondering if there's a better way than this to break out of a nested forEach/some/every loop? This seems unwieldy but I've been looking at this for like 45 minutes and I can't figure out a better/cleaner/prettier way to solve this with array methods but without the confusing return statements (I know it's easy to return in a regular for loop but I'm trying to get better with the array methods) -- the function returns 1 if there's an identical consecutive triple digit in num1 and double digit in num2 and 0 if there isn't
function TripleDouble(num1,num2) { 
  var triples = num1.toString().match(/(\d)\1{2}/g);
  var doubles = num2.toString().match(/(\d)\1/g);  
  var result = 0;
  if (!!triples && !!doubles) {
    triples.some(function(tri){
      doubles.some(function(dou){
        if ( tri[0] == dou[0] ) { 
          return ++result;
        };
      });
      return result;
    });
  }  
  return result;
}
just to clarify - the function works, but i'm just looking for a way to avoid the confusing return statements
  • without using a regular for loop
Dominic Desimini
@trisell
Jan 16 2015 15:57
I have a question. I'm trying to pull a json document from yahoo, and when I get the Json downloaded, I cannot get it out of the function that follows the JSON download call. I would like to dump a piece of that data into an array that is globally available so that I can chart the data.
xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        var today = [];
        today.push(JSON.parse(xmlhttp.responseText));
        test = today;

    }
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
Maxim Orlov
@Maximization
Jan 16 2015 23:25
can anyone spot what's wrong with this code, I get a connection error. I'm sure it must be something silly
var http = require('http');
var url = require('url');
var server = http.createServer();

http.get('/api/parsetime', function (res) {
    res.writeHead(200, { 'Content-Type': 'application/json' });
    var date = new Date(url.parse(req.url, true).query.iso);
    var time = {
        "hour": date.getHours(),
        "minute": date.getMinutes(),
        "second": date.getSeconds()
    };
    console.log(JSON.stringify(date));
});

http.get('/api/unixtime', function (res) {
    res.writeHead(200, { 'Content-Type': 'application/json' });
    var date = new Date(url.parse(req.url, true).query.iso);
    var time = {
        "unixtime": date.getMilliseconds()
    };
    console.log(JSON.stringify(date));
});

server.listen(process.argv[2]);
console.log('Server listening on port ' + process.argv[2]);
I'm doing nodeschool's node tutorial btw, this is the last lesson
Bin Ury
@teddy-error
Jan 16 2015 23:25
which connection error
Maxim Orlov
@Maximization
Jan 16 2015 23:26
events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: connect ECONNREFUSED
    at errnoException (net.js:905:11)
    at Object.afterConnect [as oncomplete] (net.js:896:19)
āœ— Error connecting to http://localhost:48849: connect ECONNREFUSED

Error: connect ECONNREFUSED
    at errnoException (net.js:905:11)
    at Object.afterConnect [as oncomplete] (net.js:896:19)
not very explanatory
Bin Ury
@teddy-error
Jan 16 2015 23:30
nodeschool/discussions#124
Maybe this would help?
there is an answer in full discussion
idk which problem you're on- I don't remember that one- but you can look for yours here
https://github.com/nodeschool/discussions/issues
Maxim Orlov
@Maximization
Jan 16 2015 23:32
ah nice, was looking at a different repo but this one is more active
I'll look around, cheers