These are chat archives for FreeCodeCamp/Help

7th
Feb 2015
Ammar Ali Shah
@AmmarAliShah
Feb 07 2015 04:19
var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: "bob.jones@example.com"
};

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: "mary.johnson@example.com"
};

var contacts = [bob, mary];

function printPerson(person) {
    console.log(person.firstName + " " + person.lastName);
}

function list() {
    var contactsLength = contacts.length;
    for (var i = 0; i < contactsLength; i++) {
        printPerson(contacts[i]);
    }
}

/*Create a search function
then call it passing "Jones"*/
var search = function(lastName){
    var contactsLength = contacts.length;
        for (var i = 0; i < contactsLength; i++) {
        if(lastName === contacts.lastName){
            printPerson(contacts[i]);
        }
    }
};
search("Jones");
The problem is somewhere in the search function
Cristián Berríos
@crisberrios
Feb 07 2015 04:20
let's see
Nathan
@terakilobyte
Feb 07 2015 04:20
what is the error?
start with that first
Cristián Berríos
@crisberrios
Feb 07 2015 04:21
@AmmarAliShah
if(lastName === contacts[i].lastName)
Ammar Ali Shah
@AmmarAliShah
Feb 07 2015 04:21
It looks like your search function didn't log "Bob Jones" to the console. Did you remember to call search after you defined it?
Error ^
Nathan
@terakilobyte
Feb 07 2015 04:21
ah
so no error message that’s helpful
what is contacts?
Suzanne Atkinson
@AdventureBear
Feb 07 2015 04:22
contacts.lastName should be contacts[i].lastname perhaps?
Darryl Dixon - Piece Digital
@piecedigital
Feb 07 2015 04:22
What did it log to the console.
Nathan
@terakilobyte
Feb 07 2015 04:22
as in, console.tellMe(typeof contacts)
Cristián Berríos
@crisberrios
Feb 07 2015 04:22
^
Darryl Dixon - Piece Digital
@piecedigital
Feb 07 2015 04:22
I think @crisberrios has it, possibly.
Ammar Ali Shah
@AmmarAliShah
Feb 07 2015 04:22
@crisberrios that was it
thanks
Suzanne Atkinson
@AdventureBear
Feb 07 2015 04:23
if(lastName === contacts[i].lastName){
Ammar Ali Shah
@AmmarAliShah
Feb 07 2015 04:23
thnak you all for the help
Suzanne Atkinson
@AdventureBear
Feb 07 2015 04:35
my first bug smash!
lol
Ammar Ali Shah
@AmmarAliShah
Feb 07 2015 04:37
@AdventureBear congratulations
Ammar Ali Shah
@AmmarAliShah
Feb 07 2015 04:45
var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: "bob.jones@example.com"
};

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: "mary.johnson@example.com"
};

var contacts = [bob, mary, add];

function printPerson(person) {
    console.log(person.firstName + " " + person.lastName);
}

function list() {
    var contactsLength = contacts.length;
    for (var i = 0; i < contactsLength; i++) {
        printPerson(contacts[i]);
    }
}

/*Create a search function
then call it passing "Jones"*/
var search = function(lastName){
    var contactsLength = contacts.length;
        for (var i = 0; i < contactsLength; i++) {
        if(lastName === contacts[i].lastName){
            printPerson(contacts[i]);
        }
    }
};
search("Jones");

var add = function(firstName, lastName. email, phoneNumber){
    this.firstName = firstName
    this.lastName = lastName
    this.phoneNumber = phoneNumber
    this.email = email
};
add("Ammar", "Shah", "syedammarali24@gmail.com", "9233189")
problem in the last part?

Error:

there was a problem with your syntax.

Cristián Berríos
@crisberrios
Feb 07 2015 04:45
lastName. email
and of course, semicolons at the end of each statement
Ammar Ali Shah
@AmmarAliShah
Feb 07 2015 04:46

new error:

Did you create a function called add?

Cristián Berríos
@crisberrios
Feb 07 2015 04:48
also add seems like a constructor, by itself is not doing anything
since it's not returning an object
and also it's not a method
Ammar Ali Shah
@AmmarAliShah
Feb 07 2015 04:49

What would you do for this instruction:

Add this new contact object to the contacts array.

I think this is the problem
Cristián Berríos
@crisberrios
Feb 07 2015 04:50
well, you can do it in many ways, but for this example, first of all you have to return an object
like
 var add = function(a,b,c,d,e) {
return { a: this.a, b: this.b, c: this.c } });
and then contacts.push(add('a','b','c','d','e'));
Ammar Ali Shah
@AmmarAliShah
Feb 07 2015 04:53
What about this
contacts[contacts.length] = add
Cristián Berríos
@crisberrios
Feb 07 2015 04:54
it can work, but just use push, that's why it's there.
Ammar Ali Shah
@AmmarAliShah
Feb 07 2015 04:55
codecademy wants us to use this
Cristián Berríos
@crisberrios
Feb 07 2015 04:57
I see... well, it's better to follow instructions then, but always think on reusing code and abstracting functions :P
Ammar Ali Shah
@AmmarAliShah
Feb 07 2015 04:58
still doesn't work
var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: "bob.jones@example.com"
};

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: "mary.johnson@example.com"
};

var contacts = [bob, mary];

function printPerson(person) {
    console.log(person.firstName + " " + person.lastName);
}

function list() {
    var contactsLength = contacts.length;
    for (var i = 0; i < contactsLength; i++) {
        printPerson(contacts[i]);
    }
}

/*Create a search function
then call it passing "Jones"*/
var search = function(lastName){
    var contactsLength = contacts.length;
        for (var i = 0; i < contactsLength; i++) {
        if(lastName === contacts[i].lastName){
            printPerson(contacts[i]);
        }
    }
};
search("Jones");

var add = function(firstName, lastName, email, phoneNumber){
    this.firstName = firstName;
    this.lastName = lastName;
    this.phoneNumber = phoneNumber;
    this.email = email;
    contacts[contacts.length] = add
};
add("Ammar", "Shah", "syedammarali24@gmail.com", "9233189")
Cristián Berríos
@crisberrios
Feb 07 2015 04:59
no
var add = function(firstName,lastName,email,phoneNumber){
    var person = {
        firstName: firstName,
        lastName: lastName,
        email: email,
        phoneNumber: phoneNumber
    };
    contacts[contacts.length] = person;
}
that's what's being shown in codeacademy
1st you create the person object
then add it to the array
when calling add by its name, "this" refers to the globalobject, so you aren't asigning the values to the "add" variable but to the global scope.
Ammar Ali Shah
@AmmarAliShah
Feb 07 2015 05:02
ah
codecademy doesn't explain much
Cristián Berríos
@crisberrios
Feb 07 2015 05:03
if you want to read something to have a better understanding while doing the challenges
read "JavaScript for cats" and then Eloquent JavaScript up to chapter 6-ish
don't worry if you don't get everything, but it will help you a lot with the challenges
Ammar Ali Shah
@AmmarAliShah
Feb 07 2015 05:07
@crisberrios I have them both saved but for reading before I start with the MEAN stuff. I plan on ending all of this JavaScript stuff and then taking a break before starting with all the MEAN stuff
during the break i will read books to get a better understanding of JavaScript
Nathan
@terakilobyte
Feb 07 2015 06:11
the mean stack is all javascript
and unless you understand closure, scope, hoisting, and module patterns you’ll hate the stack
Suzanne Atkinson
@AdventureBear
Feb 07 2015 06:21
@terakilobyte Hmmm...I have a long way to go! not sure I understand any of those. ;)
Nathan
@terakilobyte
Feb 07 2015 06:22
you probably do
wel, you had asked about closure last night
Suzanne Atkinson
@AdventureBear
Feb 07 2015 06:22
right I'm not sure if I could explain any of those.
Nathan
@terakilobyte
Feb 07 2015 06:23
when you saw me doing something like this pattern….
something.someMethod(function(elem) {
…
});
that’s a small anonymous closure
Suzanne Atkinson
@AdventureBear
Feb 07 2015 06:24
closure meaning...? Self contained function?
and anonymous meaning that it has no name, just function (elem)?
Nathan
@terakilobyte
Feb 07 2015 06:26
no
well it can be those
but think of this
imagine I have two modules
remember that callback last night?
that callback was closure
Suzanne Atkinson
@AdventureBear
Feb 07 2015 06:27
yes
Nathan
@terakilobyte
Feb 07 2015 06:27
it executed in the function call to find the files
Suzanne Atkinson
@AdventureBear
Feb 07 2015 06:27
right
Cristián Berríos
@crisberrios
Feb 07 2015 06:27
the concept of closure is that functions have access to the context in which the function was created, which opens all sorts of possibilities
Nathan
@terakilobyte
Feb 07 2015 06:27
had you made references to variables and other functions that were in the main module
it could have accessed them
even though that other file knew nothing about them
that’s closure
Suzanne Atkinson
@AdventureBear
Feb 07 2015 06:28
hmmm
Nathan
@terakilobyte
Feb 07 2015 06:28
it’s a teleportation device for the function
Suzanne Atkinson
@AdventureBear
Feb 07 2015 06:28
right!
i like that
Cristián Berríos
@crisberrios
Feb 07 2015 06:29
var myObject = function () {
var value = 0;
return {
increment: function (inc) {
value += typeof inc === 'number' ? inc : 1;
},
getValue: function () {
return value;
}
};
}();
this is from JS: The Good Parts
look at value = 0
Suzanne Atkinson
@AdventureBear
Feb 07 2015 06:30
ok
Cristián Berríos
@crisberrios
Feb 07 2015 06:30
when you call myObject, it will return an object with 2 methods
increment and getValue
Suzanne Atkinson
@AdventureBear
Feb 07 2015 06:30
right nathan showed me that last night
Cristián Berríos
@crisberrios
Feb 07 2015 06:30
but that object was created in a context in which a variable "value" existed
Suzanne Atkinson
@AdventureBear
Feb 07 2015 06:31
OK
Cristián Berríos
@crisberrios
Feb 07 2015 06:31
and even if that variable doesn't "exist" anymore
methods can still access it
Nathan
@terakilobyte
Feb 07 2015 06:31
^
Cristián Berríos
@crisberrios
Feb 07 2015 06:31
because the object is "enclosed" in a context containing it
that is one example of a closure
Suzanne Atkinson
@AdventureBear
Feb 07 2015 06:32
I think I'm getting it. I'll just need more examples, but now I have a better idea
Cristián Berríos
@crisberrios
Feb 07 2015 06:33
well, I'm off for today
goodnight!
Nathan
@terakilobyte
Feb 07 2015 06:33
g’night
Suzanne Atkinson
@AdventureBear
Feb 07 2015 06:34
Hey Nathon, nodeschool #s 7 & 8 http clients...
I got 7 working just fine
in #8 it says to to an http request and .get ALL the data, not just the first data event.
When I do an http.get to freecode camp for example, using my code from #7, i get the entire page. is that one data event?
what would multiple data events mean?
Nathan
@terakilobyte
Feb 07 2015 06:37
umm it’s been a month since I did those
I’d have to look
Suzanne Atkinson
@AdventureBear
Feb 07 2015 06:38
that's OK, I just thought you'd have a quick answer.
No hurry
i'm lokoing for brain - easy stuff to do tonight. super tired.
I swam & ice skated today both, plus last nights' shift had me up till 6:50 am
Nathan
@terakilobyte
Feb 07 2015 06:40
it probably means there will be multiple requests
or hte server will respond back in a timed sequence with multiple items
Suzanne Atkinson
@AdventureBear
Feb 07 2015 06:43
makes sense
I think one of the best things I've learend so far from learn you node is...
ready for it?
bogan ipsum!
Nathan
@terakilobyte
Feb 07 2015 07:13
lol
Suzanne Atkinson
@AdventureBear
Feb 07 2015 07:23
@terakilobyte challenge 8 was easy, I just had to listen for an 'end' response, and until then collect the data. After the end, printed the length and the string.
Crazy that I'm getting it...3 days ago this would have seemd impossible
Nathan
@terakilobyte
Feb 07 2015 07:39
:)
through repitition we find mastery
Seitama
@Seitama
Feb 07 2015 10:37
hello i need help for c programming, where can i find some help pls?
Sudeepto
@Sudeepto
Feb 07 2015 11:24
Hello Friends . Have someone completed the FCC Customise Bootstrap Challenge number 16 ?? Codepen.io is not loading the webpage.
Ammar Ali Shah
@AmmarAliShah
Feb 07 2015 13:33
var james = {
    job: "programmer",
    married: false
};

// set to the first property name of "james"
var aProperty = "job";

// print the value of the first property of "james" 
// using the variable "aProperty"
console.log(james["job"]);
console.log(aProperty);
Cristián Berríos
@crisberrios
Feb 07 2015 15:01
// print the value of the first property of "james" 
// using the variable "aProperty"
console.log(james[aProperty]);
Ammar Ali Shah
@AmmarAliShah
Feb 07 2015 15:02
@crisberrios solved this ages ago
thanks anyway
Cristián Berríos
@crisberrios
Feb 07 2015 15:04
np :)
Christopher Hutchinson
@cshutchinson
Feb 07 2015 18:48
@AdventureBear nodeschool is the REAL DEAL….learning so much
Suzanne Atkinson
@AdventureBear
Feb 07 2015 19:20
nodeschool is fun
var http = require("http");
var body = [];
var complete = 0;


http.get(process.argv[2],  function (response) {  
        response.setEncoding("utf8")

        response.on('data', function (data) {
            body[0] += data;
            })

        response.on('end', function(){
            complete ++;
            dataComplete(complete);
      })
});

http.get(process.argv[3],  function (response) {  
        response.setEncoding("utf8")

        response.on('data', function (data) {
            body[1] += data;
            })

        response.on('end', function(){
        complete ++;
        dataComplete(complete);
      })
});

http.get(process.argv[4],  function (response) {  
        response.setEncoding("utf8")

        response.on('data', function (data) {
            body[2] += data;
            })

        response.on('end', function(){
         complete ++;
         dataComplete(complete);
      })
});


function dataComplete(num){
    if (num===3){

        console.log(body[0]);
        console.log(body[1]);
        console.log(body[2]);

};
getting this error:
 /Users/suzanne/Developer/nodeschool/multiple-http.js:56
});
 ^
SyntaxError: Unexpected token )
all the parens and brackets match up ans the http.get is the same code used in the previous challenge.
@cshutchinson i used your code ideas for the last function
Christopher Hutchinson
@cshutchinson
Feb 07 2015 19:30
great! glad it worked out
have a great day of coding, I know I am :)
Suzanne Atkinson
@AdventureBear
Feb 07 2015 19:31
thanks
can you see anything wrong with my function above? it challenge 8
it is
Nathan
@terakilobyte
Feb 07 2015 19:31
taking a look
is it?
Suzanne Atkinson
@AdventureBear
Feb 07 2015 19:32
sorry 9
8 was just one of those get requests
without the incrementign variable
i can't figure out when JS wants or needs the ";" ... seems like it doesn't care sometiems
Nathan
@terakilobyte
Feb 07 2015 19:33
at the very end
you don’t appear to be closing your if statement properly
you’re missing a }
semicolons aren’t requried after function(){} bodies
they should be required after = function(){expressions}; though
and statements should end with semicolons;
the linter in my brain is going off :P
Suzanne Atkinson
@AdventureBear
Feb 07 2015 19:41
that was it! Good eye! I had a few different if statements in there so I wonder if a for (item in body) { console.log(item);} would have worked? let me see
that just prints out 1,2,3! but the original way worked.
Nathan
@terakilobyte
Feb 07 2015 19:42
try console.log(body[item])
Suzanne Atkinson
@AdventureBear
Feb 07 2015 19:42
yep that worked!
Nathan
@terakilobyte
Feb 07 2015 19:43
also, when in doubt, hint it out
Suzanne Atkinson
@AdventureBear
Feb 07 2015 19:44
oh, cool. I'm still using brackets...worthless POS, lol.
ok one more odd thing before this passes. My out put looks like this: "undefinedLets get some chrissie flamin flat out like a barbie. Gutful of clucky no worries"
there is an "undefined" being logged. Not sure if it's an element from the http.get that I'm captureing by accident? I don't see any extra console.log statements. I'll take another good look and see if i can figure it out, buti fyou have any hints, let me know
Nathan
@terakilobyte
Feb 07 2015 19:47
webstorm
webstorm, webstorm, webstorm
vim is also acceptable ;)
undefined relates to objects
you’re getting an undefined as your first object
do you need to += data?
or can you just assign body[0] = data?
what do you suppose is already in body[0]?
Suzanne Atkinson
@AdventureBear
Feb 07 2015 20:49
it should be empty???
var body = [];
I need a webstorm them for 45+ year old eyes. It's actually one reason I like brackets...easy to read! :)
theme
for webstorm "projects" is that anything different than opening a folder in brackets or sublime? Projects sound big & scarey
Suzanne Atkinson
@AdventureBear
Feb 07 2015 20:54
I did += because I think the data comes in streams until it sneds an "end". So If I just did =data it would only be the last stream? Not sure, let me try it.
This fixed it var body = ["","",""];
is there a shortcut for that? basically I think I defined body as an array of strings.
Deam
@deamme
Feb 07 2015 20:58
Hello
Suzanne Atkinson
@AdventureBear
Feb 07 2015 20:59
the official solution uses the bl library and is a little more streamlined than mine, refactored into one fucntion call. Kind of mind boggling, but I guess that's the beauty of asynchronous calls
Deam
@deamme
Feb 07 2015 20:59
What's the difference on between: http://nodejs.org/api/readline.html. and: fs.readFile and result = data.split(\n)
Suzanne Atkinson
@AdventureBear
Feb 07 2015 20:59
@deamme hello
readFile gets the result. the 2nd half is what you do with the result
you need to read it, use a call back function to get the 'result' then manipulate the result how you want
If I 'm understanding your question, but maybe not...readline is a separate function. Nevermind.
Deam
@deamme
Feb 07 2015 21:01
Should I use the readline api or?
Suzanne Atkinson
@AdventureBear
Feb 07 2015 21:01
what are you doing?
Deam
@deamme
Feb 07 2015 21:04
I'm reading a .txt file and I need to read it line by line. Proxy checker: https://gist.github.com/deamme/ebee457f7c98e5931dce
This doesn't check that well, it skips a lot of the proxies. I think it's because it's too fast
btw it's coffeescript..
Suzanne Atkinson
@AdventureBear
Feb 07 2015 21:06
are the instructions to read it line by line or print it line by line?
readfile will get the whole thing, then you are splitting it by new line? I'm not really all that experienced, not sure I can help !!
Deam
@deamme
Feb 07 2015 21:07
Thanks for the help anyways! Just tried to ask here because, noone would answer in the node irc chat >_>
Suzanne Atkinson
@AdventureBear
Feb 07 2015 21:07
lol
there are some smart people in here. What are you working on? is it from nodeschool?
Deam
@deamme
Feb 07 2015 21:09
It's just my own challenge :-)
Suzanne Atkinson
@AdventureBear
Feb 07 2015 21:10
nice
what are you working towards?
just learning? student? getting a new job?
Deam
@deamme
Feb 07 2015 21:11
Right now I'm just focused on learning the language. I need this to make a website for my school assignment, I got 3-4 months left :-)
What about you?
Suzanne Atkinson
@AdventureBear
Feb 07 2015 21:12
trying to get fluent in web dev stuff so I can write my own projects. Things on my mind I know I can make happen in a web application.
just like knowing how to do it and so I don't have to be frustrated that other subscription based tools i'm using won't match my needs
what level are you in school?
Deam
@deamme
Feb 07 2015 21:14
What do you mean by level? Like grade?
Suzanne Atkinson
@AdventureBear
Feb 07 2015 21:15
yes. high school, college?
Deam
@deamme
Feb 07 2015 21:17
High school :-) You?
Suzanne Atkinson
@AdventureBear
Feb 07 2015 21:17
I'm 46
:)
done a lot of school
lol
call me an adult learner
awesome that you are learning this in high school!
Deam
@deamme
Feb 07 2015 21:21
I see :D! It's self learning for me..