These are chat archives for FreeCodeCamp/Help

5th
Apr 2015
Chase
@hmmChase
Apr 05 2015 00:06
a css identifier is another word for a property value, correct?
Suzanne Atkinson
@AdventureBear
Apr 05 2015 00:51
Thanks @Crisberrios I'll try it
Suzanne Atkinson
@AdventureBear
Apr 05 2015 03:18
Why doesn't this pass the bonfire test? I am pretty sure it's doing what is requested http://repl.it/gsE/11
Tim Pinoy
@waeren
Apr 05 2015 03:20
you need to add a to the entities, e.g. &
Cristián Berríos
@crisberrios
Apr 05 2015 03:20
you are replacing with &lt instead of <
Suzanne Atkinson
@AdventureBear
Apr 05 2015 03:21
aha!
Thanks again @crisberrios !! that would have taken me forever to find, because it was so obvious! Is there a sexier way to do it like with the object I'd started with?
quiet in here tonight
Cristián Berríos
@crisberrios
Apr 05 2015 03:23
the sexiest way :P
you can check lodash source code to see how they do it
Suzanne Atkinson
@AdventureBear
Apr 05 2015 03:52
that's neat.
@waeren thanks for the good eye
Zach Klimczak
@zklimczak
Apr 05 2015 04:05
Need help. Bonfire challenge "Diff Two Arrays". I'm thoroughly convinced I have it correct, but I can't actually force an error. Anyone care to look over my code?
Danny Fritz
@dannyfritz
Apr 05 2015 04:06
force an error?
Zach Klimczak
@zklimczak
Apr 05 2015 04:07
Force an error = I intentionally make a mistake to understand how their "compiler" is attempting to read my code. By doing so, this should help me to see what they're expecting and I can backtrack where things are going wrong.
Nada?
Cristián Berríos
@crisberrios
Apr 05 2015 04:12
well
bonfires test are made so you can check what's wrong
instead of errors you can try writing logs to see what's happening
or using debugger; to create breakpoints and see what's happening in devtools
you can share your code with repl.it or jsbin so we can take a closer look
Zach Klimczak
@zklimczak
Apr 05 2015 04:15
Cristián Berríos
@crisberrios
Apr 05 2015 04:20
hmmm seems to return the correct answer
remove the 1st two lines
(sort lines)
Zach Klimczak
@zklimczak
Apr 05 2015 04:22
I did.. and it worked. Fault on FCC's part? Technically, my answer was correct.
Cristián Berríos
@crisberrios
Apr 05 2015 04:22
haven't checked for errors, but mutating the arguments is a bad idea
I think it might be because of that
Zach Klimczak
@zklimczak
Apr 05 2015 04:23
Meh. Ok. I'll keep your advice in mind. Thanks @crisberrios !
Cristián Berríos
@crisberrios
Apr 05 2015 04:27
:thumbsup:
Tim
@TimRizzo
Apr 05 2015 04:48
hey all, new bonfire new question. 'Drop it like it's hot ' takes an array and a function and asks to drop the first array element until one is found that returns true from the passed function. it's working for all the other tests, but when there's no solution in the array it empties and I get undefined when the checker is looking for an empty array (?) "AssertionError:expected undefined to deeply equal []" What'd I dooo?
function drop(arr, func) { 
  while (arr.length > 0) {    
    if (func(arr[0])) { return arr; }
    else { arr.shift(0,1); }   
  }  
}
console.log(drop([1, 2, 3,4], function(n) {return n >5; }));
Cristián Berríos
@crisberrios
Apr 05 2015 04:56
that's because after the while loop
you don't return anything
Tim
@TimRizzo
Apr 05 2015 05:00
hunh. you know, now that you mention it... :D
thanks @crisberrios !
Catalin Iosif
@ciosifweb
Apr 05 2015 10:57
hey guys, I'm currently doing the cash register bonfire, when I decrease the value of the remaining change I get floating point issues such as : 0.15 - 0.10 = 0.04999999
I thought about multiplying by a hundred to solve this
is there a better way?
Harshal
@McQuinTrix
Apr 05 2015 11:08
i just did +1 in the end to pennies .. i suppose you are facing similar error
@ciosifweb
Harshal
@McQuinTrix
Apr 05 2015 11:18
@waeren oh thats cool (:
i didn't know that we could round in floating numbers too
Kapil Dutta
@duttakapil
Apr 05 2015 11:19
Guys, can someone explain me what exactly a valid US number is? Because 6505552368 is not a valid number, but 1 456 789 4444 is?
Catalin Iosif
@ciosifweb
Apr 05 2015 11:21
I eventually used .toPrecision(2);
@duttakapil , the digits should range from 2 to 9
Suzanne Atkinson
@AdventureBear
Apr 05 2015 11:21
@duttakapil, i would call both valid numbers. it's a 10 digit number. i only use the 1 if I am inside of a hospital or office that has an internal calling system where you can punch in 4 numbers and get anotehr dept
Catalin Iosif
@ciosifweb
Apr 05 2015 11:22
only the country prefix can be lower than 1
Suzanne Atkinson
@AdventureBear
Apr 05 2015 11:22
there is a list of valid area codes available
not true about 1s, i have 1s in my last 4 digits
Catalin Iosif
@ciosifweb
Apr 05 2015 11:23
hmm, that's weird
Suzanne Atkinson
@AdventureBear
Apr 05 2015 11:23
the home number I grew up with had 0 and 1 in it as well.
@duttakapil are you working on a challenge?
Kapil Dutta
@duttakapil
Apr 05 2015 11:24
Yes
Catalin Iosif
@ciosifweb
Apr 05 2015 11:24
@AdventureBear you're right
from what I can see, the first digit in the first two groups has to be in 2-9 range
others can be from 0-9
Suzanne Atkinson
@AdventureBear
Apr 05 2015 11:25
learning new things every day!
Catalin Iosif
@ciosifweb
Apr 05 2015 11:25
so yeah, they both seem valid
Suzanne Atkinson
@AdventureBear
Apr 05 2015 11:25
although southwestern pennsynvanai area code is 412
come to think of it, each of the 3 groups of my current number has a 1 in it
Catalin Iosif
@ciosifweb
Apr 05 2015 11:26
it's ok
Suzanne Atkinson
@AdventureBear
Apr 05 2015 11:26
i had to think about it, lol. Now see if you can guess my phone nuber
Catalin Iosif
@ciosifweb
Apr 05 2015 11:26
as long as the first digit of the group isn't one
Suzanne Atkinson
@AdventureBear
Apr 05 2015 11:26
oh got it
Catalin Iosif
@ciosifweb
Apr 05 2015 11:26
darn
when I defined the regex I just used [2-9] instead of \d
and it passed the tests :))
Suzanne Atkinson
@AdventureBear
Apr 05 2015 11:27
well I guess your bonfire won't be calling me then. :)
Catalin Iosif
@ciosifweb
Apr 05 2015 11:28
yeah, you're kind of disconnected :))
maybe we should report this
this seems valid after more research
Kapil Dutta
@duttakapil
Apr 05 2015 11:31
I wrote a silly little code that seems to work for all the tests except the 6505552368 one.
I'm not even sure the code I wrote is legit.
Catalin Iosif
@ciosifweb
Apr 05 2015 11:34
I still think we got the gist of what the bonfire intended even so
Kapil Dutta
@duttakapil
Apr 05 2015 11:36
So if there is no country code, and the number is 10 digits long, the first digit has to be 5 or something? Because all the tests with a legit 10 digit number that should return true, are all 5's?
Catalin Iosif
@ciosifweb
Apr 05 2015 11:37
no, there actually is 650 area code
I passed the number to another regex I found on stackoverflow,
I used a pre-build validator online
and it seems legit
maybe we're missing something, or maybe the person that designed the bonfire thought the rules were different.
Kapil Dutta
@duttakapil
Apr 05 2015 11:41
So 6505552368 is supposed to return true?
Catalin Iosif
@ciosifweb
Apr 05 2015 11:41
from the rules that I found for us numbers it would seem so
but the assertion is set to false
I think you could ask Nathan in the main chat
and see what's up with this bonfire
Kapil Dutta
@duttakapil
Apr 05 2015 11:44
I have another issue now
My code is not legit, that I have figured out by now. But I improved the code a little to pass the Bonfire. My code now returns false for 6505552368, and yet in the tests it says that it returns true. I don't know what is going on.
Suzanne Atkinson
@AdventureBear
Apr 05 2015 11:45
did anyone call the number? lol.
@duttakapil, the "555" group is typically "information", or at least it used to be. It's the "fake" phone number used in tv shows all the time.
Kapil Dutta
@duttakapil
Apr 05 2015 11:46
Oh okay
Suzanne Atkinson
@AdventureBear
Apr 05 2015 11:46
like I could call 555-1212 when I was a kid and get the weather report on a recorded line
Catalin Iosif
@ciosifweb
Apr 05 2015 11:47
i used this:
function telephoneCheck(str) { // Good luck! var re = /^1* *\(*[2-9]{3}\)*[\s-]*[2-9]{3}[\s-]*[2-9]{4}$/g; if (str.match(re)) return true; else return false; }
but now I now it's not correct since I would be excluding valid numbers
:))
Suzanne Atkinson
@AdventureBear
Apr 05 2015 11:48
so there is a country code 1, an area code (next 3, often grouped with parentheses), then a 7 digit number in 2 groups, a group of 3, a hypen and a group of 4. The actual formatting with hyphens or dashes sometimes differs. ie 1 (412) 555-1212 vs 1-412-555-1212 vs 4125551212 those all look valid to me
I don't know about the bonfire though
your regex insists that it start with a 1, which is why the 650... number is returning false
or is the * an optional parameter? i havn't done this one yet just rying to help with the formatting. :)
Catalin Iosif
@ciosifweb
Apr 05 2015 11:50
* is optional
Suzanne Atkinson
@AdventureBear
Apr 05 2015 11:51
ok nm
Catalin Iosif
@ciosifweb
Apr 05 2015 11:51
it's still wrong, but it passes the test :))
Suzanne Atkinson
@AdventureBear
Apr 05 2015 11:51
haa
Kapil Dutta
@duttakapil
Apr 05 2015 11:52
I'm doing something silly like this :
function telephoneCheck(str) {
  // Good luck!
  var arr = str.match(/(\d)/g);
  if(arr.length == 10 || arr.length == 11){
    if(arr.length === 11){
      return str[0] === '1';
    }
    else{
      return str[0] === '5' || str[0] === '(';
    }
  }
  return false;
}
telephoneCheck("6505552368");
Suzanne Atkinson
@AdventureBear
Apr 05 2015 11:52
ok heres a Q. I'm actually at work right now with some legit downtime, and coding using the console on Windows 8. I used 'console.log' and got an error, 'console' is undefined.
Catalin Iosif
@ciosifweb
Apr 05 2015 11:53
this is after you remove spaces and dashes right?
coding in the console?
a repl environment?
Suzanne Atkinson
@AdventureBear
Apr 05 2015 11:53
no, internet explorer 8, hit f12
built in browser console
not windows 8, sorry
Catalin Iosif
@ciosifweb
Apr 05 2015 11:54
I am on win8 with internet explorer 11
it's working for me
tried using only log?
Kapil Dutta
@duttakapil
Apr 05 2015 11:55
@ciosifweb yes, in the arr I have all the digits. I use that to count the number of digits in the given string. It has to be either 10 or 11.
Suzanne Atkinson
@AdventureBear
Apr 05 2015 11:56
using only log I get "object expected". maybe something else is wrong. I'm trying a simple script from eloquent JS
Catalin Iosif
@ciosifweb
Apr 05 2015 11:56
try using jsbin with only the java window and the console turned up
IE8 might have some quirks
Suzanne Atkinson
@AdventureBear
Apr 05 2015 11:57
have you tried coding on the go with an ipad?
that's what I'm typing on in chat. working on holidays is nice at times
Kapil Dutta
@duttakapil
Apr 05 2015 11:58
The code returns false for the number 6505552368. But the Bonfire says it returns a true, and should return a false.
Suzanne Atkinson
@AdventureBear
Apr 05 2015 11:58
not abig deal, but thanks for looking at it.
Catalin Iosif
@ciosifweb
Apr 05 2015 11:59
@duttakapil that's because it's returning true at the first 5
once the function returns it stops execution
currently your function will return true for almost anything that has a single 5 in it
It will check if the given number is 10 or 11 digits long. If its 11, then it checks if the first digit is 1. But if its 10, it will check if the first digit is 5 or '('.
Catalin Iosif
@ciosifweb
Apr 05 2015 12:03
ok
hmm
weird
still, you should not return after checking a digit as it will take you out of the function immediatelly
Suzanne Atkinson
@AdventureBear
Apr 05 2015 12:04
why are you checking if the first digit is a 5?
Catalin Iosif
@ciosifweb
Apr 05 2015 12:05
@AdventureBear you're welcome, have a nice holiday :)
@duttakapil I would recommend using a regex that matches the whole string
instead of one digit at a time
Kapil Dutta
@duttakapil
Apr 05 2015 12:07
I'm checking if the first char is '5' or '(' if the number of digits in the given number is 10. That is because all the tests that should return true and are 10 digits long start with '5' or '('. I know this is not a legit solution.
Suzanne Atkinson
@AdventureBear
Apr 05 2015 12:09
haha. but the passed number starts wtih a 6 so your code is doing what you wrote (I think)
Kapil Dutta
@duttakapil
Apr 05 2015 12:09
@ciosifweb that is what I have been trying to do on the side. But RegEx can get so confusing some times. I was originally trying to select the valid US numbers and then compare them with their original strings and return a Boolean. But I couldn't figure out the right expression that would select only the valid numbers.
Catalin Iosif
@ciosifweb
Apr 05 2015 12:09
I found it now
when you call the function in your test
you call it as "650...."
but when the bonfire test system runs
it passes it as "(650....)"
Kapil Dutta
@duttakapil
Apr 05 2015 12:11
Oh
Catalin Iosif
@ciosifweb
Apr 05 2015 12:11
so it returns true because it starts with a (
Kapil Dutta
@duttakapil
Apr 05 2015 12:11
Wow nice catch @ciosifweb
Catalin Iosif
@ciosifweb
Apr 05 2015 12:11
you're welcome
yeah, regex is really confusing
I banged my head against the wall a lot when doing the regex challenge
Kapil Dutta
@duttakapil
Apr 05 2015 12:12
Lol, passed the Bonfire by changing the str[0] === '5' || str[0] === '('; to str[1] === '5';
Catalin Iosif
@ciosifweb
Apr 05 2015 12:13
:))
darn, that's bit cheating
but, nice one
Kapil Dutta
@duttakapil
Apr 05 2015 12:13
But it still is not a legit solution. Lol
Suzanne Atkinson
@AdventureBear
Apr 05 2015 12:13
back to the drawing board
Catalin Iosif
@ciosifweb
Apr 05 2015 12:14
still
Kapil Dutta
@duttakapil
Apr 05 2015 12:14
Haha I will come back to this later when I figure out the RegEx
Catalin Iosif
@ciosifweb
Apr 05 2015 12:14
this bonfire needs some brushing up
Kapil Dutta
@duttakapil
Apr 05 2015 12:14
Yup
Agreed
Catalin Iosif
@ciosifweb
Apr 05 2015 12:14
checking the 650 number
and the numbers should be more diverse so you can't pass it with a hack
:))
Kapil Dutta
@duttakapil
Apr 05 2015 12:15
Working on the RegEx for this one here : http://www.regexr.com/3aomn
@ciosifweb you can literally pass all the bonfires by just looking at the tests and writing code specific to that test. And Nathan and Quincy know about this. But this way the camper wouldn't learn anything, so it will be their loss.
Suzanne Atkinson
@AdventureBear
Apr 05 2015 12:21
well it is a self-study course. After 20 some years of formal schooling, i'm less interested in passing tests and more interested in true learning.
that's why I experiment a lot on these concepts I'm struggling with. Althoug you won' tfind me doing codepens with much regex...that's just painful, lol
Evgeny Klimenchenko
@Dzheky
Apr 05 2015 21:16
is there a difference between these two definitions?
function something(variable){};
var something = function(variable){};
Ben McMahon
@benmcmahon100
Apr 05 2015 21:17
This message was deleted
This message was deleted
also importantly the second commet on the best answer
By the way, the difference isn't only that they are parsed at different times. Essentially, your functionOne is merely a variable that has an anonymous function assigned to it, whereas functionTwo is actually a named function. Call .toString() on both to see the difference. This is significant in some cases where you want to get the name of a function programmatically. – Jason Bunting
Cristián Berríos
@crisberrios
Apr 05 2015 21:19
you can also do var som = function som(variable)
function expressions don't have to be anonymous
Evgeny Klimenchenko
@Dzheky
Apr 05 2015 21:21
So which one should I use more often than other?
Ben McMahon
@benmcmahon100
Apr 05 2015 21:22
function something(variable){}; would be the most common I'd think
Cristián Berríos
@crisberrios
Apr 05 2015 21:22
it all depends
Evgeny Klimenchenko
@Dzheky
Apr 05 2015 21:23
Depends on what?
Cristián Berríos
@crisberrios
Apr 05 2015 21:23
on the context
but you might want to name your expressions for better debugging
there's also the IIFE pattern, also very used
Evgeny Klimenchenko
@Dzheky
Apr 05 2015 21:24
so where would I use var something = function() {}; instead of first one?
Cristián Berríos
@crisberrios
Apr 05 2015 21:25
inside other functions would be a common scenario
Ben McMahon
@benmcmahon100
Apr 05 2015 21:26
@crisberrios is that to make up for the lack of classes+namespaces
in vanilla js
Cristián Berríos
@crisberrios
Apr 05 2015 21:26
hmm no, that would be objects
closures + objects = no need for classes
Ben McMahon
@benmcmahon100
Apr 05 2015 21:29
@crisberrios I get ya! :D
It is nice to have it so scope isn't always a thorn in your side! :p