These are chat archives for FreeCodeCamp/Help

18th
Feb 2015
Joshua
@Randomorph
Feb 18 2015 00:29
hey maybe I'm missing something, but Smallest Common Multiple bonfire seems quite difficult to implement for a range
Cristián Berríos
@crisberrios
Feb 18 2015 00:30
can you link the bonfire?
lcm and gcd are easy to do with two numbers, but with multiple I think I'm just missing some way to algorithm them
In math we usually did Prime factorization for lcm of multiple numbers, but that's not necessarily easy to implement in code
Cristián Berríos
@crisberrios
Feb 18 2015 00:37
prime factorization seems a good option
Joshua
@Randomorph
Feb 18 2015 00:38
yeah thinking that's what I'll have to do
code-wise some are simpler than prime factorization
but speed-wise I'll have to look into it
you could just do 1x2x3.... number
Nathan
@terakilobyte
Feb 18 2015 00:40
calculating the lcm is only a step further than finding the gcf
Joshua
@Randomorph
Feb 18 2015 00:42
yes, for two numbers tera
The issue arises with a range of unspecified size
because finding the gcd of 3 numbers is just gcd(a, gcd(b,c))
but finding it with four is gcd(a, gcd(b, gcd(c,d)))
and so on
Cristián Berríos
@crisberrios
Feb 18 2015 00:44
you can catch the array and do gcd(arr.shift(),gcd(arr))
Joshua
@Randomorph
Feb 18 2015 00:44
yeah I tried that, but then I wasn't getting the right numbers :/
Nathan
@terakilobyte
Feb 18 2015 00:45
consider the range 1-10, there are only 4 numbers to figure out the gcd and lcm
well, 5 actually
Joshua
@Randomorph
Feb 18 2015 00:45
actually it would be 22235*7
uhh
2x2x2x3x5x7 *
Nathan
@terakilobyte
Feb 18 2015 00:46
10 handles 10 and 5, 9 takes cares of 9 and 3, 8 takes care of 8, 4, and 2, 7 is prime, 6 has to handle itself
1 can safely be ignored
Joshua
@Randomorph
Feb 18 2015 00:47
2x2x2x3x3x5x7 * to double correct myself
Nathan
@terakilobyte
Feb 18 2015 00:58
10 & 9 gcd is 1, 9 / 1 * 10 = 90, 90 & 8 gcd is 2 8 / 2 * 90 = 360, 360 & 7, 7 is prime so 7 * 360 = 2520, 2520 / 6 is a whole number so no more needs to be done, so lcm([1,10]) is 2520 on my notepad from the plane
which agrees with the prime factorization method it appears
Christopher Hutchinson
@cshutchinson
Feb 18 2015 01:11
how do you get the bower.json files pulled into the package.json for your / my app as dependencies for my application? can anyone advise?
it seems npm install would leave a new user a little short without all the bower dependencies
Ryan Malm
@Rybar
Feb 18 2015 01:13
bower install.
Quincy Larson
@QuincyLarson
Feb 18 2015 01:14
I think you need to run a second command like bower install
Christopher Hutchinson
@cshutchinson
Feb 18 2015 01:16
do I need to do that from inside each of the bower_component directories? I assume so since they each have a bower.json file …. thank you both
Nathan
@terakilobyte
Feb 18 2015 01:18
you can add a bower command to grunt and/or gulp
Christopher Hutchinson
@cshutchinson
Feb 18 2015 01:19
ty hope you are well @terakilobyte
Nathan
@terakilobyte
Feb 18 2015 01:19
and no, if I remember correctly you should have a bower.json
bower install will look for that file and recursively do its magic just like npm install does on package.json
Christopher Hutchinson
@cshutchinson
Feb 18 2015 01:19
cool ty
are you on the way back to base I assume…? did you have to leave the wife?
Nathan
@terakilobyte
Feb 18 2015 01:20
doing well, on my way to korea, 4 hours out from narita
yep
Christopher Hutchinson
@cshutchinson
Feb 18 2015 01:21
my best wishes out to both of you
Nathan
@terakilobyte
Feb 18 2015 01:21
she checked in yesterday for a week of chemo, first round of consolidation
appreciate it :)
Christopher Hutchinson
@cshutchinson
Feb 18 2015 01:21
i know you are sick leaving her
will keep you both in our thoughts here
never even met you and I feel like a friend moved away :)
Suzanne Atkinson
@AdventureBear
Feb 18 2015 01:26
me too @cshutchinson !
Nathan
@terakilobyte
Feb 18 2015 01:28
aww, c'mon guys I'm still going to be around
I'll just have different office hours
besides I'm back to the states for good (maybe!) in July
Cristián Berríos
@crisberrios
Feb 18 2015 01:29
I admire your dedication @terakilobyte, keep it up!
Nathan
@terakilobyte
Feb 18 2015 01:29
and South Korea is a pretty awesome place
Cristián Berríos
@crisberrios
Feb 18 2015 01:30
we almost went to S.Korea instead of Mexico. My wife had a job offer and we even made the papers at the embassy, but the university backed on the offer about 3 weeks before we left.
Nathan
@terakilobyte
Feb 18 2015 01:31
the coming and going my wife and I have gotten used to after deployments, mission assignments to odd locations around the world, and election seasons when I'm forever gone and living out of a suitcase in hotel after hotel
Cristián Berríos
@crisberrios
Feb 18 2015 01:31
very unproffessional and made us very disappointed
Nathan
@terakilobyte
Feb 18 2015 01:31
wow, what university?
you could have complained to the south korean govt most likely, they love the idea of ppl coming to south korea for work and school from what I've seen
Cristián Berríos
@crisberrios
Feb 18 2015 01:33
let me see If I can find the name
it's an episode we don't like to remember too much
Nathan
@terakilobyte
Feb 18 2015 01:34
I can imagine
Cristián Berríos
@crisberrios
Feb 18 2015 01:34
anyways, it's a pretty harsh style of life @terakilobyte, but it has to have some perks
Nathan
@terakilobyte
Feb 18 2015 01:34
so, I lost 30 pounds in the month I was home
and the south korean diet will definitely not add it back
Cristián Berríos
@crisberrios
Feb 18 2015 01:35
Hankuk University of Foreign Studies
that one
Nathan
@terakilobyte
Feb 18 2015 01:35
I didn't have 30 pounds to lose either :/ maybe 15 max
hmm, I'll look into them when I get back back
Suzanne Atkinson
@AdventureBear
Feb 18 2015 01:36
where did you lose them?
David Charles
@davidcharles212
Feb 18 2015 01:37
Hey guys, I'm having a syntax issue with the CSS robot in Dash - will somebody please shed some light?
Cristián Berríos
@crisberrios
Feb 18 2015 01:37
sure :D (deja vu)
David Charles
@davidcharles212
Feb 18 2015 01:37
Lol
I'm doing the eyes - I just used a radial gradient. I now need to insert code for moz & webkit
Cristián Berríos
@crisberrios
Feb 18 2015 01:39
ok
for vendor prefixes you have to repeat the lines
one for each vendor
and also keep the original one at the top, since vendor ones are "fallbacks" for when the browser doesn't use the standard CSS3 attribute
David Charles
@davidcharles212
Feb 18 2015 01:40

I've tried:

background-moz: radial-gradient etc etc
background: moz-radial-gradient etc etc

but neither works. What is the correct format?

Cristián Berríos
@crisberrios
Feb 18 2015 01:40
-moz-
both of those are wrong
(mdn.io/search string)
David Charles
@davidcharles212
Feb 18 2015 01:42
ahh, just added a dash before it -- thanks
Cristián Berríos
@crisberrios
Feb 18 2015 01:42
np
David Charles
@davidcharles212
Feb 18 2015 01:42
back to the challenge, I appreciate your fast help. Have a good night!
Nathan
@terakilobyte
Feb 18 2015 01:46
@AdventureBear a lot of muscle density and my fat reserves are pretty much blasted. I can make out my ribs pretty easily
Suzanne Atkinson
@AdventureBear
Feb 18 2015 01:51
not eating or training? stress? you an have some of my fat reserves! =)
take care of yourself.
Nathan
@terakilobyte
Feb 18 2015 01:52
lol, thanks. Yeah I was probably eating a max of 5-800 calories a day
not super interested in food while watching the results of chemo
Suzanne Atkinson
@AdventureBear
Feb 18 2015 01:52
too much pair programming.
do you need a hat too?
Nathan
@terakilobyte
Feb 18 2015 01:54
lol
wearing my harley cap atm, all good
Suzanne Atkinson
@AdventureBear
Feb 18 2015 01:55
I have more pink!
Nathan
@terakilobyte
Feb 18 2015 01:56
then I'd have to buy new shoes, or at least a belt to color coordinate
Suzanne Atkinson
@AdventureBear
Feb 18 2015 01:57
hmm...well I could go get another roll of camo colored yarn ,then it might match what you have
Ashley Drake
@aldraco
Feb 18 2015 02:02
all right, finally worked it out - thanks @QuincyLarson. The twitter app settings need a callback URL, specifically the IP address version (i.e. can't write localhost:port). The app also needs to be given the authority to log in (duh).
Vince
@Vince33
Feb 18 2015 02:18
Any reason why the twitch feed is so spotty?
Suzanne Atkinson
@AdventureBear
Feb 18 2015 02:20
Hey @terakilobyte what airline are you flying to Norita? is it a military charter or a commercial flight? A lot of the calls I take are to/from Norita usually on Delta or Air Canada
Nathan
@terakilobyte
Feb 18 2015 02:21
could be his internet connection, or choppy settings in obs with compression rate
can't watch it from the plane so just guessing
United Airlines to Narita
Suzanne Atkinson
@AdventureBear
Feb 18 2015 02:23
if there is a medical emergency on the plane, tell the flight attendants to ask for me specifically! I'll turn the plane back around to NJ. :)
Nathan
@terakilobyte
Feb 18 2015 02:23
1621 miles to tokyo
Suzanne Atkinson
@AdventureBear
Feb 18 2015 02:23
woohoo!
Nathan
@terakilobyte
Feb 18 2015 02:23
hopefully godzilla has spared the airport
lol not sure they have the fuel for that
Suzanne Atkinson
@AdventureBear
Feb 18 2015 02:25
glide path...
Nathan
@terakilobyte
Feb 18 2015 02:25
lol this poor japanese girl next to me keeps falling asleep and slowly falling over onto my shoulder. Then she wakes up if I move a little and seems very embarrassed. it's been a recurring theme for the past 3 hours
it's like watching a puppy fall asleep
Suzanne Atkinson
@AdventureBear
Feb 18 2015 02:26
haha
poor thing. long flight
Nathan
@terakilobyte
Feb 18 2015 02:29
yep
have a 3 hour layover in narita
think I'll get some sushi
alright hopping out of chat, back to switching between reading about testing and functional programming
take care!
Cristián Berríos
@crisberrios
Feb 18 2015 02:31
I miss Japan :(
Christopher Hutchinson
@cshutchinson
Feb 18 2015 02:34
when you come back, thank you it worked Nathan
Screen Shot 2015-02-17 at 9.33.17 PM.png
@terakilobyte
Suzanne Atkinson
@AdventureBear
Feb 18 2015 05:53
@dannyfritz here is my solution for where-art-thou. I can't figure out how to get the hardcoded .last out of there...I'm not using the source object passed in. I can use object.keys to get "last" out of source, but then can't use that variable to generalize the algorithm. In any case, this code works, but would like to figure out how to use source as passed in .
function where(collection, source) {
  var arr = [];
  var matchKey = Object.keys(source); 

  // What's in a name?
  for (var item in collection) {

     if (collection[item].last === source.last) {
    arr.push(collection[item]);
   }
  }
  return arr;
}

where([{ first: 'Romeo', last: 'Montague' }, { first: 'Mercutio', last: null }, { first: 'Tybalt', last: 'Capulet' }], { last: 'Capulet' });
MychaelZ
@MychaelZ
Feb 18 2015 05:55
may i ask what this code is suppose to ddo?
Suzanne Atkinson
@AdventureBear
Feb 18 2015 05:56
Make a function that looks through a list (first argument) and returns an array of all objects that have equivalent property values (second argument).
MychaelZ
@MychaelZ
Feb 18 2015 05:57
so the answer for this collection should be tybalt right?
Suzanne Atkinson
@AdventureBear
Feb 18 2015 05:57
yes
so it is passed 2 arrays. the first one is the collection of first & last names
the 2nd has only one name that should act as a filter
it loops through each name pair in the collection, and if it is a match, pushes it to a new array, which is returned.
MychaelZ
@MychaelZ
Feb 18 2015 05:58
and you want to be able to use this for more than just the last property?
Suzanne Atkinson
@AdventureBear
Feb 18 2015 05:58
right
i hardcoded "last"
but it might be some other key pair passed in.
so if I return matchKey from this code I get "last", but If I use collection[item].matchKey I get either an undefined or an empty array.
Darryl Dixon - Piece Digital
@piecedigital
Feb 18 2015 06:02
For source you really don't need it to be an object. it can just be a string since that's what they're both supposed to match. Just my $0.02
MychaelZ
@MychaelZ
Feb 18 2015 06:02
yea this problem can not be solved ur going to have to hard code it
Suzanne Atkinson
@AdventureBear
Feb 18 2015 06:03
@piecedigital can I take the key and make it a string? and then can that string be used when accessing the collection objects?
MychaelZ
@MychaelZ
Feb 18 2015 06:03
function where(collection, source) {
  var arr = [];
  var matchKey = Object.keys(source); 

  // What's in a name?
  for (var item in collection) {

     if (collection[item][matchKey] === source[matchKey]) {
    arr.push(collection[item]);
   }
  }
  return arr;
}
try this ^^^
btw your use of the Object.keys to extract the prop name was pretty creative
i would have been stuck on trying to find a way to do that
probably use a for loop
Suzanne Atkinson
@AdventureBear
Feb 18 2015 06:05
lol...that worked! I tried to add you as a pair and it didn't take your name. @dannyfritz gave me that clue last night before I wen tto bed, so it was not original, but he didin't tell me how , just that he used it.
between the two of you I like the solution.
MychaelZ
@MychaelZ
Feb 18 2015 06:06
i never seen it used that way i will be using that
but do you see why it works?
this code from the other?
Suzanne Atkinson
@AdventureBear
Feb 18 2015 06:07
yes, of course...I think. S ource only has one key, so object.keys returns the value name. I just see the syntax you provided uses [keyvariable] instead of .keyvariable
which makes sense if you already know the answer. :)
MychaelZ
@MychaelZ
Feb 18 2015 06:08
but the last code you were using .last and instead we could just use the matchKey to compare on both the object in the collection and the source
Suzanne Atkinson
@AdventureBear
Feb 18 2015 06:08
yes, I like that.
but even before I was unable to get matchKey to be useful for anything except returning it as an object.
that's the sort of thing that before finding FCC I would ahve struggeld with for days and given up.
this place is great.
Cristián Berríos
@crisberrios
Feb 18 2015 06:09
when solving problems that deal with arrays, try to envision a solution which uses .map, .filter or .reduce
MychaelZ
@MychaelZ
Feb 18 2015 06:10
yeah matchKey is holding a property name so you can use it to look up properties
@crisberrios how come?
Suzanne Atkinson
@AdventureBear
Feb 18 2015 06:10
@crisberrios I have not used any of them successfully. So much to learn.
time for bed, thanks guys, will sleep on these ideas and be better tomorrow.
MychaelZ
@MychaelZ
Feb 18 2015 06:10
goodnight
Cristián Berríos
@crisberrios
Feb 18 2015 06:11
for...in, according to most authors, should be avoided
MychaelZ
@MychaelZ
Feb 18 2015 06:11
interesting
Suzanne Atkinson
@AdventureBear
Feb 18 2015 06:11
you said that last night, but why? It makes so much intuitive sense now that I have learned it!
and is faster than for (i=0, i<array.length, i++) ... so I've ready
read
Cristián Berríos
@crisberrios
Feb 18 2015 06:12
for example, in that last exercise
in this case is an array
so it should iterate only over the items
Suzanne Atkinson
@AdventureBear
Feb 18 2015 06:14
yes
but?
Cristián Berríos
@crisberrios
Feb 18 2015 06:14
but if, instead of using for...in, Object.keys and .filter was used
input could be also be in the format of an object
MychaelZ
@MychaelZ
Feb 18 2015 06:15
function where(collection, source) {
  var arr = [];
  var matchKey = Object.keys(source); 

    collection.forEach(function (item) {
       if (item[matchKey] === source[matchKey]) {
           arr.push(item);
      }
    });

  return arr;
}
Cristián Berríos
@crisberrios
Feb 18 2015 06:15
and make it a generic collection matcher
Suzanne Atkinson
@AdventureBear
Feb 18 2015 06:15
that makes sense. I tried to use filter
but couldn't sort it out
filter makes sense too, I need to see more examples
collection.filter(function () {
     if (collection[matchKey] === source[matchKey]) {
         arr.push(item);
    }
});
?????
Cristián Berríos
@crisberrios
Feb 18 2015 06:17
in this case return(item) would be used
as filter returns an array
Suzanne Atkinson
@AdventureBear
Feb 18 2015 06:18
instead of push?
MychaelZ
@MychaelZ
Feb 18 2015 06:18
yeah use return
Suzanne Atkinson
@AdventureBear
Feb 18 2015 06:18
how do you get all this to stick?
Cristián Berríos
@crisberrios
Feb 18 2015 06:18
var result = collection.filter(function(item) { valid});
MychaelZ
@MychaelZ
Feb 18 2015 06:19
function where(collection, source) {
  var arr = [];
  var matchKey = Object.keys(source); 

  var  ans = collection.filter(function (item) {
       if (item[matchKey] === source[matchKey]) {
           return true;
      }
    });

  return ans;
}
Cristián Berríos
@crisberrios
Feb 18 2015 06:19
^
so, if the function returns true, the passed item is pushed into the destination array
if you need to further modify the entry, you can chain a .map(...) after .filter()...
Suzanne Atkinson
@AdventureBear
Feb 18 2015 06:20
thanks, it makes sense seeing it, but the syntax is not intutivce to me. Nice see it working though
the function(item) seems like a twisted way to access collection, where for ... in, is semantic. At least right now that's how it feels. So I'll practice looking for those ways more.
MychaelZ
@MychaelZ
Feb 18 2015 06:21
yeah play around with the array methods whenever you get a chance
Suzanne Atkinson
@AdventureBear
Feb 18 2015 06:21
the bonfires are good, the help is better
Alex Olteanu
@alexandruolteanu
Feb 18 2015 09:10
Hi guys, my 'truncate a string' solution doesn't seem to pass and I can't figure out why exactly.
function truncate(str, num) {
    if (str.length > num)
        return str.slice(0, num - 3) + '...';
    else
        return "";
}

truncate('A-tisket a-tasket A green and yellow basket', 11);
Halp pls.
MychaelZ
@MychaelZ
Feb 18 2015 11:41
works for me
you should use {} for good practice though the code after the if and else statements should be in blocks {}
Alex Olteanu
@alexandruolteanu
Feb 18 2015 12:10
@MychaelZ it passes just the last test for me, not the first two. I can't figure out why. I think the curly braces aren't the problem.
MychaelZ
@MychaelZ
Feb 18 2015 12:11
post the tests
Alex Olteanu
@alexandruolteanu
Feb 18 2015 12:14
assert.strictEqual(truncate('A-tisket a-tasket A green and yellow basket', 'A-tisket a-tasket A green and yellow basket'.length + 2), 'A-tisket a-tasket A green and yellow basket', 'should not truncate if string is < length');AssertionError:should not truncate if string is < length: expected '' to equal 'A-tisket a-tasket A green and yellow basket'
assert(truncate('A-tisket a-tasket A green and yellow basket', 'A-tisket a-tasket A green and yellow basket'.length) === 'A-tisket a-tasket A green and yellow basket', 'should not truncate if string is = length');AssertionError:should not truncate if string is = length
These two are the ones I'm not passing
expect(truncate('A-tisket a-tasket A green and yellow basket', 11)).to.eqls('A-tisket...');
The last one seems ok
Lol nvm
Instead of return "" I only had to do return str. Silly me.
Serhii Borovskyi
@serhiicss
Feb 18 2015 14:08
F1 please!
Anyone here?
Maxim Orlov
@Maximization
Feb 18 2015 14:09
'sup
Serhii Borovskyi
@serhiicss
Feb 18 2015 14:09
I am doing the codecademy FizzBuzz game
Can you take alook at my code and point me in the right direction please?
Maxim Orlov
@Maximization
Feb 18 2015 14:09
ahh, the famous FizzBuzz
sure
Serhii Borovskyi
@serhiicss
Feb 18 2015 14:10
var foo = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];

for (i=0; i<foo.length; i++) {
    if foo %3 {
        document.write('Fizz');
    } else if {
        foo %5 {
            document.write('Buzz');
        }
    } else if {
        foo %3 && foo %5 {
            document.write('FizzBuzz');
        }
        else {
            document.write(foo);
        }
    }
}
If you just could tell me in general, not giving out the anwswer :)
Nathan
@terakilobyte
Feb 18 2015 14:11
what is foo?
Serhii Borovskyi
@serhiicss
Feb 18 2015 14:11
jut a var
Maxim Orlov
@Maximization
Feb 18 2015 14:11
why aren't your conditionals within a pair of ()?
Serhii Borovskyi
@serhiicss
Feb 18 2015 14:11
an array
Nathan
@terakilobyte
Feb 18 2015 14:11
for?
Serhii Borovskyi
@serhiicss
Feb 18 2015 14:11
for the numbers from1 to 20
Nathan
@terakilobyte
Feb 18 2015 14:11
yes I can see var foo = [itypedtoomuch]
lol
Serhii Borovskyi
@serhiicss
Feb 18 2015 14:12
lol
Maxim Orlov
@Maximization
Feb 18 2015 14:12
foo is an array, how do you access a value within an array?
Serhii Borovskyi
@serhiicss
Feb 18 2015 14:12
I found it strange
Nathan
@terakilobyte
Feb 18 2015 14:12
for (var i = 0; i < 20; i++)
for 0-19
1 to 20 would be for (var i = 1; i <=20; i++)
Ammar Ali Shah
@AmmarAliShah
Feb 18 2015 14:12
@serhiicss one more thing
The && condition needs to be on the top
or else it won't work
my experience
Serhii Borovskyi
@serhiicss
Feb 18 2015 14:13
ok let me try :)
var foo = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];

for (i=0; i<=20; i++) {
    if (foo % 3 && foo % 5) {
        document.write('FizzBuzz');
    } else if {
        ()foo % 3) {
            document.write('Fizz');
        }
    } else if {
        (foo %5) {
            document.write('Buzz');
        }
        else {
            document.write(foo);
        }
    }
}
I get unexpected token error
Ammar Ali Shah
@AmmarAliShah
Feb 18 2015 14:17
@serhiicss console.log
not document.write
This message was deleted
can you provide me with the link for the challenge?
Nathan
@terakilobyte
Feb 18 2015 14:19
foo in this case won't do anything
foo[i] might
Serhii Borovskyi
@serhiicss
Feb 18 2015 14:19
ah
Nathan
@terakilobyte
Feb 18 2015 14:19
but at that point I'd say get rid of foo
Serhii Borovskyi
@serhiicss
Feb 18 2015 14:20
I was thinking about how to come up with numbers from 1 to 20 without typing them, but I dunno
Nathan
@terakilobyte
Feb 18 2015 14:20
also no need to check for the fizzbuzz condition first. In fact, you could just check Fizz, then immediately check for Buzz, no else if
Ammar Ali Shah
@AmmarAliShah
Feb 18 2015 14:20
for (i = 1; i < 21; i++ ){
    if(i % 3 === 0 && i % 5 === 0){
        console.log("FizzBuzz");
    }
    else if(i % 5 === 0){
        console.log("Buzz");
    }
    else if(i % 3 === 0){
        console.log("Fizz");
    }
    else{
        console.log(i);
    }
};
@serhiicss How i wrote it ^
Nathan
@terakilobyte
Feb 18 2015 14:21
for (var i = 1; i <= 20; i++) {
  console.log(i);
}
would give you 1 through 20 printed tot he console
and again, don't check for the fizzbuzz condition first
it's pointless
Serhii Borovskyi
@serhiicss
Feb 18 2015 14:22
But there must be 4 conditions
Nathan
@terakilobyte
Feb 18 2015 14:22
no there musn't
take 15
if (15 % 3 === 0) // => true, would output fizz
Serhii Borovskyi
@serhiicss
Feb 18 2015 14:23
yes and it wont check further down
Nathan
@terakilobyte
Feb 18 2015 14:23
if (15 % 5 === 0) // => true, would output buzz
sure it will
Serhii Borovskyi
@serhiicss
Feb 18 2015 14:24
ah
i see
Nathan
@terakilobyte
Feb 18 2015 14:24
just do if checks, not else if
once you've solved it I'll show you my method
we'll see how close we are!
Serhii Borovskyi
@serhiicss
Feb 18 2015 15:12
@terakilobyte I think I know what you mean, but I don't know how to reproduce it. I must check if first two conditions return true to print FizzBuzz.
sort of if within if
Maxim Orlov
@Maximization
Feb 18 2015 15:14
@serhiicss tip, use a variable to store your result ;)
then you only have to do 2 if checks, not nested
Evan Davis
@davisec52
Feb 18 2015 15:31

Good morning! I'm trying to work through Eloquent JS and running into some snags.

The sample below is a code excerpt from chapter 5. Below, I've given a sample of the array of objects
that the code works with.

what I don't understand is why the function displays results in console.log but does not return result with "return."



var ANCESTRY_FILE = "[\n  " + [
  '{"name": "Carolus Haverbeke", "sex": "m", "born": 1832, "died": 1905, "father": "Carel Haverbeke", "mother": "Maria van Brussel"}',
  '{"name": "Emma de Milliano", "sex": "f", "born": 1876, "died": 1956, "father": "Petrus de Milliano", "mother": "Sophia van Damme"}',
  '{"name": "Maria de Rycke", "sex": "f", "born": 1683, "died": 1724, "father": "Frederik de Rycke", "mother": "Laurentia van Vlaenderen"}'].join(",\n  ") + "\n]";

var ancestry = JSON.parse(ANCESTRY_FILE);

function getInfo(array) {
var byName = {};
ancestry.forEach(function(person) {
  byName[person.name] = person;
  //console.log(person);    //<== displays results
  //return person;          //<== does not return results
});
}
getInfo(ancestry);
Cristián Berríos
@crisberrios
Feb 18 2015 15:32
because return only returns the value to the caller
Serhii Borovskyi
@serhiicss
Feb 18 2015 15:33
@Maximization This is the best I can come up with :(
var foo = ((i % 3 === 0) && (i % 5 === 0));
for (i = 1; i <= 20; i++ ){
    if (i % 3 === 0){
        console.log("Fizz");
    }
    if (i % 5 === 0){
        console.log("Buzz");
    }
     if (foo === true) {
      console.log('FizzBuzz');
    }
    else{
        console.log(i);
    }
};
Cristián Berríos
@crisberrios
Feb 18 2015 15:33
console.log is explicitly outputting a value to the console
Evan Davis
@davisec52
Feb 18 2015 15:34
@crisberrios Hi.
Cristián Berríos
@crisberrios
Feb 18 2015 15:34
if you use console.log(getInfo(ancestry)); using return
then it would also show, since you are explicitly logging the return value from calling getInfo
and on the other way, if you keep that last line but comment the return line on the function
Maxim Orlov
@Maximization
Feb 18 2015 15:35
@serhiicss you don't need the explicit foo var to make this work, you might as well put the code directly into the if-condition
Cristián Berríos
@crisberrios
Feb 18 2015 15:35
it won't show anything since the function won't be returning anything
Evan Davis
@davisec52
Feb 18 2015 15:35
Ok, so I would have to call getInfo from within the function?
Maxim Orlov
@Maximization
Feb 18 2015 15:35
does it work now?
Serhii Borovskyi
@serhiicss
Feb 18 2015 15:35
@Maximization No...
Cristián Berríos
@crisberrios
Feb 18 2015 15:36
@davisec52 no, the function itself is ok
Maxim Orlov
@Maximization
Feb 18 2015 15:36
@serhiicss btw, to make your code work like it is now you have to put the FizzBuzz if statement at the top
Evan Davis
@davisec52
Feb 18 2015 15:36
@crisberrios How would I get it to return without using console.log?
Maxim Orlov
@Maximization
Feb 18 2015 15:37
because as soon as the code values true either for Fizz or Buzz it will execute that and won't continue to FizzBuzz
Serhii Borovskyi
@serhiicss
Feb 18 2015 15:37
@Maximization Yes, I did come up with simple solution with 3 if conditions
Cristián Berríos
@crisberrios
Feb 18 2015 15:37
@davisec52 using return
but in that function
return is inside a forEach loop
Serhii Borovskyi
@serhiicss
Feb 18 2015 15:37
But, @terakilobyte suggests there is another method
Evan Davis
@davisec52
Feb 18 2015 15:37
@crisberrios moment . . .
Cristián Berríos
@crisberrios
Feb 18 2015 15:38
so it will return while processing the 1st element
and it won't continue
Maxim Orlov
@Maximization
Feb 18 2015 15:38
@serhiicss ah alright so you managed to make it work, so now you're asking for a more elegant solution?
Serhii Borovskyi
@serhiicss
Feb 18 2015 15:38
@Maximization That is correct :)
Cristián Berríos
@crisberrios
Feb 18 2015 15:38
@serhiicss the problem is, you are doing the calculations twice
Maxim Orlov
@Maximization
Feb 18 2015 15:38
@serhiicss use a variable to store your result
Evan Davis
@davisec52
Feb 18 2015 15:39
@crisberrios

function getInfo(array) {
var byName = {};
ancestry.forEach(function(person) {
  byName[person.name] = person;

});
return getInfo(ancestry);
}
Maxim Orlov
@Maximization
Feb 18 2015 15:39
and append Fizz and/or Buzz to it
Cristián Berríos
@crisberrios
Feb 18 2015 15:39
@davisec52 no, you made it into a recursive function that will loop infinitely until the stack overflows
Serhii Borovskyi
@serhiicss
Feb 18 2015 15:40
isn't i already a result variable?
Evan Davis
@davisec52
Feb 18 2015 15:40
@crisberrios Right. I understand that this can't work, but I don't see how to use return from within the function to get a returned result.
Cristián Berríos
@crisberrios
Feb 18 2015 15:40
@davisec52 but you got the return line out of the loop, which is ok
the only thing missing is what you are returning
where are you storing the result?
in byName {} right?
Maxim Orlov
@Maximization
Feb 18 2015 15:41
@serhiicss i is your loop variable, what are your outputs? Fizz, Buzz, FizzBuzz or i, those are your results
Evan Davis
@davisec52
Feb 18 2015 15:41
@crisberrios Ok, but this does not work either.

function getInfo(array) {
var byName = {};
return ancestry.forEach(function(person) {
  byName[person.name] = person;

});
return person;
}
Maxim Orlov
@Maximization
Feb 18 2015 15:41
have an empty variable var result = ''; to store your result
Cristián Berríos
@crisberrios
Feb 18 2015 15:42
@davisec52 still returning the wrong value
Serhii Borovskyi
@serhiicss
Feb 18 2015 15:42
you mean something like Fizz+ Buzz = Fizzbuzz?
Maxim Orlov
@Maximization
Feb 18 2015 15:42
then as you check for Fizz and Buzz append those to the result variable
Cristián Berríos
@crisberrios
Feb 18 2015 15:42
you only need to return 1 value, be it an array, an object, etc.
Evan Davis
@davisec52
Feb 18 2015 15:42
@crisberrios I think I'v tried returning every variable possible
Maxim Orlov
@Maximization
Feb 18 2015 15:42
yeah give it a try
Cristián Berríos
@crisberrios
Feb 18 2015 15:43
function getInfo(array) {
var byName = {}; // << where you are storing the result
ancestry.forEach(function(person) {
  byName[person.name] = person; // Store in byName each person's name

});
return ______; // return the result, where did you store it?
}
Evan Davis
@davisec52
Feb 18 2015 15:48

@crisberios I've also tried this but no result.


function getInfo(array) {
var byName = {};
return ancestry.forEach(function(person) {
  byName[person.name] = person;

});
//return byName[person];
//return byName;
}

```@crisberios I've also tried this but no result.

function getInfo(array) {
var byName = {};
return ancestry.forEach(function(person) {
byName[person.name] = person;

});
//return byName[person];
//return byName;
}

``` @crisberrios The chat setting have changed and I can't get back the normal screen. I've now got a scroll bar.

ignore last comment about the screen
Cristián Berríos
@crisberrios
Feb 18 2015 15:49
let's go to floobits
it's better if we see the code live
Evan Davis
@davisec52
Feb 18 2015 15:50
link?
I've also installed teamviewer if that would help.
simplyme5391
@simplyme5391
Feb 18 2015 15:52
I am struggling with the 'small business building website' module; can anyone help?
Cristián Berríos
@crisberrios
Feb 18 2015 15:53
edit workspace settings
so I can join
is set to private I think
Serhii Borovskyi
@serhiicss
Feb 18 2015 15:54
@Maximization Me give up... I have no idea
Evan Davis
@davisec52
Feb 18 2015 15:54
@crisberrios try it now.
simplyme5391
@simplyme5391
Feb 18 2015 15:55
@serhiicss Don't give up! Use the force...
Cristián Berríos
@crisberrios
Feb 18 2015 15:55
please wait, let me help @davisec52 1st :P
Serhii Borovskyi
@serhiicss
Feb 18 2015 15:55
If I had the force I would make the problem to find the solution by itself :)
@simplyme5391 What are you struggling with? Maybe I can help
simplyme5391
@simplyme5391
Feb 18 2015 15:59
@serhiicss LOL I actually figured it out. Thank you so much, though.
Maxim Orlov
@Maximization
Feb 18 2015 15:59
for (var i = 0; i < 20; i++) {
  var result = '';  
  if (i % 3 === 0) {
    ...
  }
  if (i % 5 === 0) {
    ...
  }
  // To-do console.log result, if result is empty console.log i
  ...
}
@serhiicss there's a head start
Suzanne Atkinson
@AdventureBear
Feb 18 2015 17:08
I'm trying to get freecodecamp working on my laptop and getting errors. I'd like to help contribute in whatever small way. If anyone could either pair or take a lookat some errors I'd appreciate it!
who else misses @terakilobyte !! ? even though digitally he's just as close, I imagine he'll have less time to hang out now.
Cristián Berríos
@crisberrios
Feb 18 2015 17:12
try to contact @QuincyLarson if @terakilobyte isn't available
I don't know much about the platform
Maxim Orlov
@Maximization
Feb 18 2015 17:31
@AdventureBear you don't have to get FCC working on your laptop per se in order to be able to contribute
Serhii Borovskyi
@serhiicss
Feb 18 2015 17:33
Sorry I was called back to work.
@Maximization Thanks, I will try it a bit later.
Suzanne Atkinson
@AdventureBear
Feb 18 2015 17:42
@Maximization how do I test code then?
anyway...it SHOULD work, but it's not. And I'd like to use the project to test my development environment
I'v elearned a lot in FCC so far, but stillf eel like I am missing a big big piece of how to do stuff I want to do.
eg build an database backed web app from scratch. So I have two different motivations
Maxim Orlov
@Maximization
Feb 18 2015 17:45
@AdventureBear ah, we're talking about bigger contributions here
maybe I could help, where are you stuck?
Suzanne Atkinson
@AdventureBear
Feb 18 2015 17:46
ha, yes, code fixes & stuff. I am such a newbie I want to catch easy stuff before the smart kids find it.
let me see
i tried following the instructions from git
i cloned the repo using the command line text on git readme.
then I tried to run npm install. Some stuff wroked then a bunch of errors were generated. Looking at the data, it looks like within that single command, the node seed command was run. (Git isntructions have it as a seprate step). the node seed command genrated a bunch of errors.
so I opened a new window, started mongod, then ran the seed command again, it seemed to do somethign?? Then I was unable to see the site when I opened a local browser window.
I know that's nt specific but that's what I got.
@terakilobyte helped me install mongo & some other stuff, so I think i have everything needed, but I'm not sure
i'm doing nodeschool so I know that I have node installed correction.
correctly.
that's why a quick pairing may help!
Maxim Orlov
@Maximization
Feb 18 2015 17:52
then I assume you have installed and configured a local mongod instance
have you setup an .env file?
Suzanne Atkinson
@AdventureBear
Feb 18 2015 17:52
as in within the directory itself?
Cristián Berríos
@crisberrios
Feb 18 2015 17:52
@AdventureBear I read on this error yesterday, you have to edit seed.js so it uses the local databae
*database
Suzanne Atkinson
@AdventureBear
Feb 18 2015 17:52
yes I set up the first 4 lines of the .env file b/c the instructions said i only needed those if I was using email login
Maxim Orlov
@Maximization
Feb 18 2015 17:52
no, I was referring to a running local MongoDB
Suzanne Atkinson
@AdventureBear
Feb 18 2015 17:53
um...I don't think so?
Maxim Orlov
@Maximization
Feb 18 2015 17:53
so if you go to the root of the project and run gulp what do you get
Suzanne Atkinson
@AdventureBear
Feb 18 2015 17:53
create the database then seed it as in two separate steps?
Cristián Berríos
@crisberrios
Feb 18 2015 17:53
@AdventureBear also, I can advise you to use nvm for installing node as it will save you from many permission-related problems in the future
Suzanne Atkinson
@AdventureBear
Feb 18 2015 17:53
node is already installed...Nathan did it for me
Maxim Orlov
@Maximization
Feb 18 2015 17:53
@AdventureBear installing mongodb is one step, seeding is another
Suzanne Atkinson
@AdventureBear
Feb 18 2015 17:54
Screen Shot 2015-02-18 at 12.53.50 PM.png
that's what I get
with gulp
Maxim Orlov
@Maximization
Feb 18 2015 17:56
do a npm install again
you said that gave you errors
Suzanne Atkinson
@AdventureBear
Feb 18 2015 17:57
Screen Shot 2015-02-18 at 12.57.16 PM.png
now those install errors are gone and I get some seed data
last night I opened the 2nd window and typed mongod, then ran npm install again and this is what I got. The screenshot is from just now though
Maxim Orlov
@Maximization
Feb 18 2015 18:00
judging by the bottom errors I guess that the data has been imported into mongod properly
and there' s no installation errors on npm
Suzanne Atkinson
@AdventureBear
Feb 18 2015 18:00
no not anymore. so after that I ran gulp, which you see in the above screen. Do you want to see my .env file?
Maxim Orlov
@Maximization
Feb 18 2015 18:02
can't hurt
Suzanne Atkinson
@AdventureBear
Feb 18 2015 18:04
Screen Shot 2015-02-18 at 1.03.01 PM.png
Maxim Orlov
@Maximization
Feb 18 2015 18:05
that looks good
I'm still assuming there's something with gulp
Suzanne Atkinson
@AdventureBear
Feb 18 2015 18:05
so what do you think the gulp error is?
Maxim Orlov
@Maximization
Feb 18 2015 18:05
try reinstalling your dependencies
rm -rf node_modules/
npm install
Suzanne Atkinson
@AdventureBear
Feb 18 2015 18:05
can you remind me
ok
good
Maxim Orlov
@Maximization
Feb 18 2015 18:06
first line removes them, second installs them
Cristián Berríos
@crisberrios
Feb 18 2015 18:06
watch for errors when doing npm install
Suzanne Atkinson
@AdventureBear
Feb 18 2015 18:06
same set of errors
Cristián Berríos
@crisberrios
Feb 18 2015 18:06
1 module failing and all the app will fail
Maxim Orlov
@Maximization
Feb 18 2015 18:06
show us the errors
Suzanne Atkinson
@AdventureBear
Feb 18 2015 18:06
npm install looks identical to the screen shot I just posted after doing the rm command
wait a sec there was a problem with the rm
Maxim Orlov
@Maximization
Feb 18 2015 18:07
but does it install stuff? in your ss above it didn't install anything
Suzanne Atkinson
@AdventureBear
Feb 18 2015 18:07
```
~/D/freecodecamp ❯❯❯ rm --rf node_modules/ ⏎
rm: illegal option -- -
usage: rm [-f | -i] [-dPRrvW] file ...
unlink file
Cristián Berríos
@crisberrios
Feb 18 2015 18:07
rm -rf
not --rf
Maxim Orlov
@Maximization
Feb 18 2015 18:07
my bad
Suzanne Atkinson
@AdventureBear
Feb 18 2015 18:07
ok!
Suzanne Atkinson
@AdventureBear
Feb 18 2015 18:19
sorry got a phone call
it's taking longer this time..that's probably good
ok stuff looks like it's isntalling
npm WARN deprecated node@0.0.0
big deal or not?
pages of stuff getting isntalled
Cristián Berríos
@crisberrios
Feb 18 2015 18:20
deprecated mostly means that sometime in the future it will stop working
but right now it works
Suzanne Atkinson
@AdventureBear
Feb 18 2015 18:21
OK, so looks like that went well
what command next, the seed?
Maxim Orlov
@Maximization
Feb 18 2015 18:24
gulp
Suzanne Atkinson
@AdventureBear
Feb 18 2015 18:25
looks like the same gulp errors.
module.js:338
    throw err;
          ^
Error: Cannot find module '/usr/local/lib/node_modules/gulp/node_modules/v8flags/cache/3.28.73.flags.json'
is it a path problem?
Maxim Orlov
@Maximization
Feb 18 2015 18:26
I think there's something wrong with your global gulp installation
npm uninstall -g gulp
npm install -g gulp
this will reinstall gulp,give that a try
Suzanne Atkinson
@AdventureBear
Feb 18 2015 18:26
could be.
we never checked it after, at least I don't think we did? installing now
with the -g flag, it doesn't matter what directory that command is run fro , it will be a global installation?
lots of good stuff showed up...
/usr/local/bin/gulp -> /usr/local/lib/node_modules/gulp/bin/gulp.js
gulp@3.8.11 /usr/local/lib/node_modules/gulp
├── v8flags@2.0.2
├── pretty-hrtime@0.2.2
├── interpret@0.3.10
├── deprecated@0.0.1
├── archy@1.0.0
├── tildify@1.0.0 (user-home@1.1.1)
├── minimist@1.1.0
├── chalk@0.5.1 (escape-string-regexp@1.0.2, ansi-styles@1.1.0, supports-color@0.2.0, has-ansi@0.1.0, strip-ansi@0.3.0)
├── semver@4.3.0
├── orchestrator@0.3.7 (stream-consume@0.1.0, sequencify@0.0.7, end-of-stream@0.1.5)
├── gulp-util@3.0.3 (array-differ@1.0.0, beeper@1.0.0, object-assign@2.0.0, array-uniq@1.0.2, replace-ext@0.0.1, lodash.reescape@3.0.1, lodash.reevaluate@3.0.1, lodash.reinterpolate@3.0.1, vinyl@0.4.6, lodash.template@3.2.0, through2@0.6.3, dateformat@1.0.11, multipipe@0.1.2)
├── liftoff@2.0.1 (extend@1.3.0, flagged-respawn@0.3.1, resolve@1.0.0, findup-sync@0.2.1)
└── vinyl-fs@0.3.13 (graceful-fs@3.0.5, strip-bom@1.0.0, defaults@1.0.0, vinyl@0.4.6, mkdirp@0.5.0, through2@0.6.3, glob-stream@3.1.18, glob-watcher@0.0.6)
hmm...something is happening
I ran gulp and it launched a browser window
at this address, but it just says waiting for local host
do I need to start node or something?
Maxim Orlov
@Maximization
Feb 18 2015 18:29
so after reinstalling gulp now the gulp command works?
Suzanne Atkinson
@AdventureBear
Feb 18 2015 18:30
I think so.
Maxim Orlov
@Maximization
Feb 18 2015 18:30
and it opened a browser window at that address? what so you see
Suzanne Atkinson
@AdventureBear
Feb 18 2015 18:30
i see a blank white screen
now terminal says the app crashed
Cristián Berríos
@crisberrios
Feb 18 2015 18:30
:S
Suzanne Atkinson
@AdventureBear
Feb 18 2015 18:30
oauth error...
Cristián Berríos
@crisberrios
Feb 18 2015 18:30
well, gulp opening the browser is a good signal
Suzanne Atkinson
@AdventureBear
Feb 18 2015 18:30
is that the .env file?
yes it's progress.
Cristián Berríos
@crisberrios
Feb 18 2015 18:30
yes
Maxim Orlov
@Maximization
Feb 18 2015 18:31
most likely
Cristián Berríos
@crisberrios
Feb 18 2015 18:31
you need to edit the env variables
and add your keys
Suzanne Atkinson
@AdventureBear
Feb 18 2015 18:31
heey my laptop battery is going to die, and we made good progress.
do I need to fill out every one of hte .env options? Get my own keys and stuff?
Cristián Berríos
@crisberrios
Feb 18 2015 18:32
I think that's right
Suzanne Atkinson
@AdventureBear
Feb 18 2015 18:32
so the problem was the gulp installation or the npm installation ? or we don't really know?
Cristián Berríos
@crisberrios
Feb 18 2015 18:32
you even need to create a twitter app to get the key
mandrill account
etc
@AdventureBear it seems that both :P
Suzanne Atkinson
@AdventureBear
Feb 18 2015 18:32
OK I'll work on it later. I think I have a twitter key. The readme file in git said I jsut needed mandrill but i'll just do the whole works and see how that goes.
Thak you both very much for your help
Maxim Orlov
@Maximization
Feb 18 2015 18:35
you're welcome
I think there's a workaround on not having to fill in all the keys
you'll just have to disable the relevant auth features
Vince
@Vince33
Feb 18 2015 19:57
''' var test = "testing markdown"; '''
well that didn't work
' ' ' var test = "testing markdown"; ' ' '
Joshua
@Randomorph
Feb 18 2015 19:59
@Vince33 use the ~ key's lower case ` <-- this
var codetest = true;
Vince
@Vince33
Feb 18 2015 20:00
var test = "testing markdown";
Joshua
@Randomorph
Feb 18 2015 20:00
use three for a code block, 1 just does inline code
`var codetest = true;'
vs
var codetest = true;
Vince
@Vince33
Feb 18 2015 20:01
var test = "testing markdown";
used three
hmmm
Joshua
@Randomorph
Feb 18 2015 20:01
Oh forgot to mention
put the three ` on a separate line, above and below the code
Vince
@Vince33
Feb 18 2015 20:01
ahhh
Joshua
@Randomorph
Feb 18 2015 20:03
press CTRL, SHIFT, M to see the markdown help list
Vince
@Vince33
Feb 18 2015 20:05
var test = "testing markdown";
there we go
@Randomorph
@Randomorph Thanks!
I was looking at that menu
just took me a bit
Joshua
@Randomorph
Feb 18 2015 20:07
Yeah no problem, glad I could help
Vince
@Vince33
Feb 18 2015 20:09
function truncate(str,num){
    if(str< num){
     var trunStr = str.substring(0,num-3);
     return trunStr.concat("...");
    }else {return str;}
}

truncate('A-tisket a-tasket A green and yellow basket', 11);
I got it to return the proper values in repl.it but not bonfire
I just want to know if its the code ?
Cristián Berríos
@crisberrios
Feb 18 2015 20:12
str < num
Danny Fritz
@dannyfritz
Feb 18 2015 20:12
yeah
Cristián Berríos
@crisberrios
Feb 18 2015 20:12
what are you trying to compare there?
Vince
@Vince33
Feb 18 2015 20:13
if the str is < than num
?
Cristián Berríos
@crisberrios
Feb 18 2015 20:13
"the str"
Danny Fritz
@dannyfritz
Feb 18 2015 20:13
what is the value of str?
Vince
@Vince33
Feb 18 2015 20:13
oh yeah
Oliver
@Dadsaster
Feb 18 2015 20:13
Is st a string?
Vince
@Vince33
Feb 18 2015 20:13
duh
Oliver
@Dadsaster
Feb 18 2015 20:13
sorry str?
Danny Fritz
@dannyfritz
Feb 18 2015 20:13
:)
Cristián Berríos
@crisberrios
Feb 18 2015 20:13
"the str" < 5 ?
Danny Fritz
@dannyfritz
Feb 18 2015 20:14
@crisberrios do you know if that does a type cast and does a lexical sort?
Vince
@Vince33
Feb 18 2015 20:14
that is so weird that in real.it it returns what I expect
Danny Fritz
@dannyfritz
Feb 18 2015 20:14
seems like having a string on the left would convert the right to "5" and then say if it is less than it alphabetidcally
Oliver
@Dadsaster
Feb 18 2015 20:14
a letter will always be greater than a number when compared with < etc
Vince
@Vince33
Feb 18 2015 20:14
repl.it
Cristián Berríos
@crisberrios
Feb 18 2015 20:14
I think it should cast the 1st char of the string into it's charcode
but I think it could also cast the number 5 to string and then compare charcodes, I'm not so sure
I never use type casting except for some cases of falsy values :P
Danny Fritz
@dannyfritz
Feb 18 2015 20:15
yeah, it coerces the right side to a string and compares with the alphabet: http://i.imgur.com/SblyXwK.png
Oliver
@Dadsaster
Feb 18 2015 20:16
if you want to convert "5" into 5 use parseInt - as in pasrseInt(str) < num
Cristián Berríos
@crisberrios
Feb 18 2015 20:16
@Vince33 in any case, if you would like to compare the length of a string against a number, the property is str.length
Vince
@Vince33
Feb 18 2015 20:17
@crisberrios yeah I saw that right away sorry for turning you guys into rubberducks
I knew when I typed duh
Cristián Berríos
@crisberrios
Feb 18 2015 20:18
it's always good to refresh the memory on some concepts
this channel serves me as quiz and anki :D
Vince
@Vince33
Feb 18 2015 20:18
love anki
@dannyfritz so no need to worry about type coercion I forgot to add a method that I added in my head but not in the editor
Danny Fritz
@dannyfritz
Feb 18 2015 20:20
yeah, type coercion is usually something to avoid in JS. So many edge cases and unexpected results. We were just chatting about what String < Number would do
Joshua
@Randomorph
Feb 18 2015 20:20

Hey I'm having some trouble with this:

function Person(firstAndLast) {
  var tmp = firstAndLast.split(' ');
  var firstName = tmp[0];
  var lastName = tmp[1];

  this.getFullName = function() {
    return this.firstName + " " + this.lastName;
  };
}

var bob = new Person("Bob Ross");
bob.getFullName();

getFullName() is returning undefined undefined and I'm not sure why. the split should be working unless I'm missing something.

Danny Fritz
@dannyfritz
Feb 18 2015 20:23
@Randomorph this.firstName and this.lastName in getFullName are undefined
Joshua
@Randomorph
Feb 18 2015 20:23
I realize, but shouldn't they be set by the constructor?
Danny Fritz
@dannyfritz
Feb 18 2015 20:23
sorry to sound so obvious. lol
Oliver
@Dadsaster
Feb 18 2015 20:23
I looks like you have an extra space in your split(' ')
Danny Fritz
@dannyfritz
Feb 18 2015 20:23
you talking about the var firstName = tmp[0] part?
@Dadsaster his split is fine.
Joshua
@Randomorph
Feb 18 2015 20:23
yesx
Danny Fritz
@dannyfritz
Feb 18 2015 20:24
do you mean this.firstName = tmp[0]; then?
right now you are just storing it to a var
in your Person function's scope
or maybe you intended to do return firstName + " " + lastName; instead
Joshua
@Randomorph
Feb 18 2015 20:25
which should make it a private variable, unless I'm severely misreading things on multiple sites?
hmm that might be right
Danny Fritz
@dannyfritz
Feb 18 2015 20:25
yeah, that will make it private
keeping it as a scoped var will make it private
Joshua
@Randomorph
Feb 18 2015 20:25
nope still returning undefined undefined
Danny Fritz
@dannyfritz
Feb 18 2015 20:27
how did you change it?
Joshua
@Randomorph
Feb 18 2015 20:27
return firstName + " " + lastName; now instead of return this.firstName + " " + this.lastName;
Danny Fritz
@dannyfritz
Feb 18 2015 20:28
and you left it as var firstName = tmp[0]?
Joshua
@Randomorph
Feb 18 2015 20:28
yes
Danny Fritz
@dannyfritz
Feb 18 2015 20:29
@Randomorph how sure are you about that? http://jsbin.com/quvivedeqe/1/edit?js,console
Vince
@Vince33
Feb 18 2015 20:30
Thanks by the way guys!!
Joshua
@Randomorph
Feb 18 2015 20:31
weird it's working in jsbin (recopied my code)
Danny Fritz
@dannyfritz
Feb 18 2015 20:31
odd
Joshua
@Randomorph
Feb 18 2015 20:34
okay I think I got it working now, thanks. No idea what the heck was wrong with it :/
Nope nvm, won't run in the bonfire still
http://www.freecodecamp.com/bonfires/make-a-person
Won't run, keeps saying, undefined is not a function.
function Person(firstAndLast) {
  var tmp = firstAndLast.split(" ");
  var firstName = tmp[0];
  var lastName = tmp[1];
  this.setFirstName = function(first) {
    firstName = first;
  };
  this.setLastName = function(last) {
    lastName = last;
  };
  this.getFirstName = function() {
    return firstName;
  };
  this.getLastName = function() {
    return lastName;
  };
  this.getFullName = function() {
    return firstName + " " + lastName;
  };
}

var bob = new Person('Bob Ross');
bob.getFullName();
However, full thing and all methods works in jsbin
Danny Fritz
@dannyfritz
Feb 18 2015 20:37
looks righ to me
you getting this? No user tests were run.
Joshua
@Randomorph
Feb 18 2015 20:37
Yes
Yet in Jsbin I tested every method, and they all work as expected
it's a straight copy paste between the two
Danny Fritz
@dannyfritz
Feb 18 2015 20:38
i'm going to say it is a problem with the bonfire
Joshua
@Randomorph
Feb 18 2015 20:38
oh hold up I think I see it
Danny Fritz
@dannyfritz
Feb 18 2015 20:39
oh, you are missing setFullName
Joshua
@Randomorph
Feb 18 2015 20:39
the bonfire asks for setFullName, and tries to call getFullName in the default text. That through me off
Danny Fritz
@dannyfritz
Feb 18 2015 20:41
you pass?
Joshua
@Randomorph
Feb 18 2015 20:42
one error
it wants bob.getFullName() === "George Carlin"
New code:
function Person(firstAndLast) {
  var tmp = firstAndLast.split(" ");
  var firstName = tmp[0];
  var lastName = tmp[1];

  this.setFirstName = function(first) {
    firstName = first;
  };
  this.setLastName = function(last) {
    lastName = last;
  };
  this.setFullName = function(firstLast) {
    if(!firstLast) return;
    var tmp = firstAndLast.split(" ");
    firstName = tmp[0];
    lastName = tmp[1];
  };
  this.getFirstName = function() {
    return firstName;
  };
  this.getLastName = function() {
    return lastName;
  };
  this.getFullName = function() {
    return firstName + " " + lastName;
  };
}

var bob = new Person('Bob Ross');
bob.getFullName();
Danny Fritz
@dannyfritz
Feb 18 2015 20:44
this is a copy paste error. :P
Joshua
@Randomorph
Feb 18 2015 20:44
?
Danny Fritz
@dannyfritz
Feb 18 2015 20:45
you have duplicated the first 3 lines of your function with the code in setFullName, but then failed to rename variables. what you should do instead, is call setFullName instad of duplicating it at the top of the constructor.
Joshua
@Randomorph
Feb 18 2015 20:46
okay, I'm unsure how to call a function, within a constructor in which the function is defined
Danny Fritz
@dannyfritz
Feb 18 2015 20:46
you see the error though?
Joshua
@Randomorph
Feb 18 2015 20:46
yes, should I still leave firstname and lastname declared at the top?
Danny Fritz
@dannyfritz
Feb 18 2015 20:46
yes, you need it for the closure
Joshua
@Randomorph
Feb 18 2015 20:47
Ahh okay, that's how you would call it, thanks
Danny Fritz
@dannyfritz
Feb 18 2015 20:47
what you had would work after fixing the bug of course
but duplicating code is never good because of errors like that. :P
something can seem to work sometimes, but it is actually 2 different code paths trying to achieve the same goal
Joshua
@Randomorph
Feb 18 2015 20:48
yeah, I didn't want to duplicate it, but wasn't sure how to properly call a function on object construction
Documentation on javascript classes/objects is pretty damn convoluted
Danny Fritz
@dannyfritz
Feb 18 2015 20:51
what classes?
Joshua
@Randomorph
Feb 18 2015 20:51
exactly. lol
Danny Fritz
@dannyfritz
Feb 18 2015 20:51
js doesn't have classes. :P so i would imagine the docs would be nonexistent
Joshua
@Randomorph
Feb 18 2015 20:51
This is the type of problem that is easy with classes though
Danny Fritz
@dannyfritz
Feb 18 2015 20:52
yeah, you build an object that contains classes you want
methods*-
Joshua
@Randomorph
Feb 18 2015 20:53
Yep, just a lot different than classes from a class-based language in set-up.
Danny Fritz
@dannyfritz
Feb 18 2015 20:53
indeedly
Nathan
@terakilobyte
Feb 18 2015 20:58
js doesn't need classes
js
has an object system way better than classes and inheritence
MychaelZ
@MychaelZ
Feb 18 2015 20:59
^ okay kyle simpson
Nathan
@terakilobyte
Feb 18 2015 20:59
and eric elliot
you know you agree @MychaelZ ;)
Danny Fritz
@dannyfritz
Feb 18 2015 20:59
haha
i agree
MychaelZ
@MychaelZ
Feb 18 2015 20:59
i do agree
Danny Fritz
@dannyfritz
Feb 18 2015 20:59
douglas crockfor says it too
MychaelZ
@MychaelZ
Feb 18 2015 21:00
yeah i heard crockpot say it too
Nathan
@terakilobyte
Feb 18 2015 21:00
yeah I couldn't remember how to spell his name
so was going to let it come up naturally
MychaelZ
@MychaelZ
Feb 18 2015 21:01
im not familiar with classes so i can't say that i 100% agree but from the limited knowledge i do have i like the object system
Danny Fritz
@dannyfritz
Feb 18 2015 21:01
classes are one of those things you learn and at first are the answer to everything you do, but then as you make stuff more complicated than 101 tutorials you quickly see the short comings
Nathan
@terakilobyte
Feb 18 2015 21:02
yeah
I read a really good article but can't find it anymore
called something like 'The terrible success of OOP'
Joshua
@Randomorph
Feb 18 2015 21:06
I like OOP, but I think people tend to over OOP.
Joshua
@Randomorph
Feb 18 2015 21:10
So I don't need help with this, I'm just hella proud of my regex:
function telephoneCheck(str) {
  if(str.search(/^1?(\s|\-)?\(?[1-9]{3}\)?(\s|\-)?[1-9]{3}(\s|\-)?[1-9]{4}$/) >=0) return true;
  else return false;
}

telephoneCheck("555-555-5555");
alternatively could do match !== null to same effect
Nathan
@terakilobyte
Feb 18 2015 21:11
no need for an else
especially when rocking an early return
the else is implied
Danny Fritz
@dannyfritz
Feb 18 2015 21:11
pretty sure the regex fails on 1-800-333-3333
Joshua
@Randomorph
Feb 18 2015 21:12
why?
Danny Fritz
@dannyfritz
Feb 18 2015 21:12
you don't allow any 0's
Joshua
@Randomorph
Feb 18 2015 21:12
oh whoops thanks
should I do 0-9 then?
Cristián Berríos
@crisberrios
Feb 18 2015 21:12
Darryl Dixon - Piece Digital
@piecedigital
Feb 18 2015 21:12
Yes.
Danny Fritz
@dannyfritz
Feb 18 2015 21:12
@Randomorph kind of. phone numbers are much more complex though. 0-000-000-0000 isn't valid either
Nathan
@terakilobyte
Feb 18 2015 21:13
also, please
if (reallyShort) {
  // format it as if it was really long
}
Joshua
@Randomorph
Feb 18 2015 21:13
what do you mean tera?
And yeah that's true Danny, but it wouldn't allow that one anyways. but it would allow 1-000-000-0000
Danny Fritz
@dannyfritz
Feb 18 2015 21:14
Joshua
@Randomorph
Feb 18 2015 21:15
regex blows my mind
Nathan
@terakilobyte
Feb 18 2015 21:16
I mean don't single line your if statements
if (condition) {
  do work;
}
vs.
Danny Fritz
@dannyfritz
Feb 18 2015 21:17
@terakilobyte @Randomorph http://eslint.org/docs/rules/curly.html
Nathan
@terakilobyte
Feb 18 2015 21:17
if (condition) do work;
Joshua
@Randomorph
Feb 18 2015 21:18
Isn't that a matter of style preference?
Danny Fritz
@dannyfritz
Feb 18 2015 21:18
yes it is
and @terakilobyte is requesting a different style. lol
Nathan
@terakilobyte
Feb 18 2015 21:19
it's easier to read
Joshua
@Randomorph
Feb 18 2015 21:19
okay just making sure
Nathan
@terakilobyte
Feb 18 2015 21:19
I've been ninja-editing the entire fcc codebase as I go along
getting rid of stuff like that
I've mostly squashed it all out
Joshua
@Randomorph
Feb 18 2015 21:19
lol, I find it good to multiline long one line instructions
Danny Fritz
@dannyfritz
Feb 18 2015 21:20
the whole reason style is argued over so much is because the time it takes for the reader to understand a bit of code is proportional to how frustrated they are reading it.
Joshua
@Randomorph
Feb 18 2015 21:20
but I don't personally mind the one line short instructions
Nathan
@terakilobyte
Feb 18 2015 21:21
@Randomorph well here's my argument
why would you multiline long instructions?
Danny Fritz
@dannyfritz
Feb 18 2015 21:22
my .eslintrc warns when lines are over 80 characters long. :P
Joshua
@Randomorph
Feb 18 2015 21:22
readability, eg when the line goes off the page if you left it one line
Nathan
@terakilobyte
Feb 18 2015 21:22
right, readability
so why make a distinction between long and short lines, and why obfuscate your blocks?
Danny Fritz
@dannyfritz
Feb 18 2015 21:23
whether or not it is obfuscating is up to the reader @terakilobyte
Joshua
@Randomorph
Feb 18 2015 21:23
I wouldn't say it obfuscates it, unless there is a large amount of inconsistency
eg switching back and forth between styles
Danny Fritz
@dannyfritz
Feb 18 2015 21:24
a computer would argue a minifier would make code easier to read.
Joshua
@Randomorph
Feb 18 2015 21:24
yep
Nathan
@terakilobyte
Feb 18 2015 21:24
that's why we minify after the human part is over
you aren't a computer
you don't have robot ears or robot eyes
;)
Danny Fritz
@dannyfritz
Feb 18 2015 21:24
i'm just saying. beauty and readability depends on the reader.
Joshua
@Randomorph
Feb 18 2015 21:25

realistically what I do, which might give tera an aneurysm is something like

if(condition)
   do work;

for long one line code blocks

Danny Fritz
@dannyfritz
Feb 18 2015 21:25
yeah, i can't get behind that. haha
so many times people add a second statement to it thining it is part of the if
Nathan
@terakilobyte
Feb 18 2015 21:25
I'd reject every single pr from you rando
sorry :(
Joshua
@Randomorph
Feb 18 2015 21:25
lol yeah I've seen many do that
Danny Fritz
@dannyfritz
Feb 18 2015 21:26
haha, i have an .eslintrc on my repos that enforce style. https://github.com/dannyfritz/hjsonify/blob/master/.eslintrc
Joshua
@Randomorph
Feb 18 2015 21:26
@terakilobyte I understand keeping code consistent amongst users, and wouldn't deviate from style in a group setting, but in a private setting, what works works
Danny Fritz
@dannyfritz
Feb 18 2015 21:26
and my build runs the linter so the person knows before submitting if it will be rejected for style reasons
Joshua
@Randomorph
Feb 18 2015 21:27
Anyways, I gotta leave, I'll talk to you good folks another time
Elliescode
@EllieAdam
Feb 18 2015 22:50
Hello!
anyone up for a bonfire challenge or two?
Chris Dziewa
@chrisdziewa
Feb 18 2015 23:15
@terakilobyte hey I was wondering if you could offer a more elegant solution for Where art thou. I passed it, but used nested for loops.