These are chat archives for FreeCodeCamp/HelpJavaScript

25th
Jul 2017
dyon3334
@dyon3334
Jul 25 2017 00:09
javascript:when to use a object over a array?
kumquatfelafel
@kumquatfelafel
Jul 25 2017 00:09
array is an object.
Long Nguyen
@longnt80
Jul 25 2017 00:10
@kumquatfelafel I think we know what he meant
Stephen James
@sjames1958gm
Jul 25 2017 00:14
@dyon3334 arrays are generally used when you have a number of homogenous values.
Objects, are used to store different values, where the values for a logical group
kumquatfelafel
@kumquatfelafel
Jul 25 2017 00:18
basically, array is a special type of object that provides a bunch of functions for iterating through and manipulating data that are generally of the same type and where you may want some kind of ordering. Objects are good for .... nvm
Long Nguyen
@longnt80
Jul 25 2017 00:19
I'm out of breath in the middle of that sentence
dyon3334
@dyon3334
Jul 25 2017 00:20
@longnt80 @sjames1958gm thanks a lot !!
kumquatfelafel
@kumquatfelafel
Jul 25 2017 00:20
@longnt80 I meant to have response immediately after, but out of steam lol
dyon3334
@dyon3334
Jul 25 2017 00:20
@kumquatfelafel thanks !
CamperBot
@camperbot
Jul 25 2017 00:20
dyon3334 sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 534 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Long Nguyen
@longnt80
Jul 25 2017 00:20
@kumquatfelafel lol
dyon3334
@dyon3334
Jul 25 2017 00:20
@sjames1958gm thanks !
CamperBot
@camperbot
Jul 25 2017 00:20
dyon3334 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8149 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Conor Murphy
@cmurphy580
Jul 25 2017 00:21
Can anyone tell me why require is not working in codepen? here is the script tag i have in the header <script data-main="scripts/main" src="scripts/require.js"></script>
and here is where i'm using it in js
const saveButton = document.querySelector('a'); 
  saveButton.addEventListener('click', () => {
    let FileSaver = require('file-saver');
    let blob = new Blob([text], {type: "text/plain;charset=utf-8"});
    FileSaver.saveAs(blob, "text_file.txt");
  });
Long Nguyen
@longnt80
Jul 25 2017 00:21
@cmurphy580 it's from your computer, codepen cannot access it
Conor Murphy
@cmurphy580
Jul 25 2017 00:22
@longnt80 not if i put a script tag in the header
>
?
dyon3334
@dyon3334
Jul 25 2017 00:22
queryselector vs normal selectors (getElementById,getElementByTagName)
Stephen James
@sjames1958gm
Jul 25 2017 00:22
@cmurphy580 Yes, you should probably load that from a CDN.
Long Nguyen
@longnt80
Jul 25 2017 00:23
@cmurphy580 no, scritpt tag only declare that this is a script
Stephen James
@sjames1958gm
Jul 25 2017 00:23
@cmurphy580 There is no scripts directory accessible from codepen.
Conor Murphy
@cmurphy580
Jul 25 2017 00:23
@sjames1958gm what about font awesome
Stephen James
@sjames1958gm
Jul 25 2017 00:23
@cmurphy580 same.
Long Nguyen
@longnt80
Jul 25 2017 00:23
fontawesome has a CDN
Conor Murphy
@cmurphy580
Jul 25 2017 00:24
@longnt80 whats a CDN
kumquatfelafel
@kumquatfelafel
Jul 25 2017 00:25

http://www.webopedia.com/TERM/C/CDN.html

Comes from google search, haven't had chance to read very thoroughly yet, but seems reasonable.

dyon3334
@dyon3334
Jul 25 2017 00:25
nobody? queryselector vs normal selectors (getElementById,getElementByTagName)
Long Nguyen
@longnt80
Jul 25 2017 00:26
@cmurphy580 basically, CDN is just a place to store file so user can access it on the internet
you need to put your js file to a server so that codepen can access it
@cmurphy580 easiest way is to copy your js to codepen directly
Conor Murphy
@cmurphy580
Jul 25 2017 00:27
@longnt80 so get it working on an html file first then put into codepen later
Long Nguyen
@longnt80
Jul 25 2017 00:27
yes
kumquatfelafel
@kumquatfelafel
Jul 25 2017 00:28

think... going to go to sleep.

amazingly enough.

night
Long Nguyen
@longnt80
Jul 25 2017 00:28
@kumquatfelafel later
Conor Murphy
@cmurphy580
Jul 25 2017 00:28
@longnt80 @sjames1958gm alright sweet thanks
CamperBot
@camperbot
Jul 25 2017 00:28
cmurphy580 sends brownie points to @longnt80 and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:cookie: 456 | @longnt80 |http://www.freecodecamp.com/longnt80
:star2: 8150 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
dyon3334
@dyon3334
Jul 25 2017 00:41
javascript:queryselector vs normal selectors (getElementById,getElementByTagName)
Long Nguyen
@longnt80
Jul 25 2017 00:45
@dyon3334 I think they return different results
one is a NodeList, one is not a NodeList
also, one is live list, and the other is not
Kevin Anderson
@LemonStain
Jul 25 2017 00:49
within FCC, how do I stop the infinite loop I created? (it freezes the window everytime i load the challenge)
John
@AnonymousLords
Jul 25 2017 00:50
Makea limit on it?
On how many times it can loop maybe?
Kevin Anderson
@LemonStain
Jul 25 2017 00:51
I mean, I can't get in to change it
before it runs
eeflores
@eeflores
Jul 25 2017 00:51
delete cookies for FCC
Kevin Anderson
@LemonStain
Jul 25 2017 00:51
so it freezes the browser tab
thanks
John
@AnonymousLords
Jul 25 2017 00:51
lol
dont do that again
lol
Guys what is the "private variable"

var Car = function() {
  var speed = 10;

  this.accelerate = function(change) {
    speed += change;
  };

  this.decelerate = function() {
    speed -= 5;
  };

  this.getSpeed = function() {
    return speed;
  };
};
is it so speed can only be changed by the outside factors
Like acceleration, deceleration
Stephen James
@sjames1958gm
Jul 25 2017 00:52
@AnonymousLords It is a variable local to a constructor function, that is only accessible to the functions also defined inside the constructor function.
The functions are public so they can be accessed and they access the private variable
@AnonymousLords Yes it is speed
@AnonymousLords The functions defined with this are properties on the object.
John
@AnonymousLords
Jul 25 2017 00:53
okay
How would i set accl and decel?
Stephen James
@sjames1958gm
Jul 25 2017 00:54
@AnonymousLords you don't set those you call those functions to change speed
John
@AnonymousLords
Jul 25 2017 00:54
Okay
so acceleration = #;
Stephen James
@sjames1958gm
Jul 25 2017 00:55
@AnonymousLords No. assuming var car = new Car();
You would call car.accelerate(10); to change speed by 10
John
@AnonymousLords
Jul 25 2017 00:55
Oh thanks
Stephen James
@sjames1958gm
Jul 25 2017 00:56
bitte
John
@AnonymousLords
Jul 25 2017 00:56
thanks @sjames1958gm
CamperBot
@camperbot
Jul 25 2017 00:56
anonymouslords sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8151 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
John
@AnonymousLords
Jul 25 2017 00:56
Wow you have a lot of cookies @sjames1958gm
Do you have a programming job :D?
Stephen James
@sjames1958gm
Jul 25 2017 00:57
Yeah, I hang out here a lot.
I do have a programming job.
John
@AnonymousLords
Jul 25 2017 00:57
What do you program?
Stephen James
@sjames1958gm
Jul 25 2017 00:58
Mostly "backend" type stuff. But lately I have been working with Alexa skills to launch android apps in the cloud.
So, a combination of js, c++ and java
John
@AnonymousLords
Jul 25 2017 00:58
Also when i set my variable in my constructor function, does it have to be the max it can be?
Stephen James
@sjames1958gm
Jul 25 2017 00:59
Well for this challenge the tests always call set before get so it doesn't really matter.
In a real situation, the functionality would dictate the initial value
John
@AnonymousLords
Jul 25 2017 01:00
@sjames1958gm You should make a app or something. Have things that you can buy like in game currency.
Becoem rich
@sjames1958gm So in the case i listed above, would i make speed "10" the max speed of teh car?
Stephen James
@sjames1958gm
Jul 25 2017 01:00
Yeah. It is coming up with that "app or something" that I have trouble with
John
@AnonymousLords
Jul 25 2017 01:01
What is your hobbies?
Stephen James
@sjames1958gm
Jul 25 2017 01:01
I like premier league soccer, learning about new technologies.
John
@AnonymousLords
Jul 25 2017 01:02
Make a game about soccer or something
Like having to shoot a ball over obstacles or inbetween obstacles to a goal
like a 2d game
Stephen James
@sjames1958gm
Jul 25 2017 01:02
@AnonymousLords IN a real application the accelerate function would be limited by the max speed of the car.
John
@AnonymousLords
Jul 25 2017 01:02
@sjames1958gm Okay
Dan Couper
@DanCouper
Jul 25 2017 01:04
@dyon3334 someEl.querySelector and document.getElementById will do the same thing, only ...ById has to be used on the document, and with name of an ID only.getElementByTagName isn't a thing. getElementsByTagName and getElementsByClassName return live list
As was stated, compare to querySelectorAll
Dan Couper
@DanCouper
Jul 25 2017 01:10
It can make a difference if you're dynamically creating stuff - querySelectorAll sometimes won't work. Otherwise querySelector and querySelectorAll are a bit easier as they're consistent, easier to remember and write, and interface is a lot like jQuery selector function $()
dyon3334
@dyon3334
Jul 25 2017 01:46
When and why to use the strict statement?
nhanly91
@nhanly91
Jul 25 2017 01:54
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line

  for(var e in source) {
    collection.forEach(function(element){
      if(source.e == element.e)  arr.push(element)
    })
  }

  // Only change code above this line
  return arr
}

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" })

Hi every one, I'm stuck in Wherefore art thou challenge. I don't know why the result still return

[ { first: 'Romeo', last: 'Montague' },
  { first: 'Mercutio', last: null },
  { first: 'Tybalt', last: 'Capulet' } ]

please help

dyon3334
@dyon3334
Jul 25 2017 01:58
What are the differences between null and undefined?
Kei Nart
@codenart
Jul 25 2017 02:02
@dyon3334
null - is an assignment value, an object, a representation of no value
so u can do this
var x = null;
undefined - is Not an assignment value, it's a type, a state of a variable, a representation of non-used yet.
so u can'T do this
x = undefined;
var x;   // undefined ,new variable, not used yet
dyon3334
@dyon3334
Jul 25 2017 02:06
@codenart thanks !!
CamperBot
@camperbot
Jul 25 2017 02:06
dyon3334 sends brownie points to @codenart :sparkles: :thumbsup: :sparkles:
:cookie: 366 | @codenart |http://www.freecodecamp.com/codenart
Kei Nart
@codenart
Jul 25 2017 02:07
@dyon3334 Nothin' at all. Happy coding.
dyon3334
@dyon3334
Jul 25 2017 02:08
@codenart can you tell me How would you compare two objects in JavaScript?
Joel Korcsmaros
@lossness
Jul 25 2017 02:19
so how looked down apon is it to go through the algorithm challenges by googling how to code all the different steps required
Ken Haduch
@khaduch
Jul 25 2017 02:55
@lossness - well, "search" is part of the methodology that they suggest. So you can go and find different code example and documents and tutorials on how to do things with more detail than the brief overviews that are given in the lessons. The hope is (and mostly for your own sanity) that you would start to assimilate the information as you got more exposure and be able to do more and more of it with less "research" - starting to remember the techniques and methods. You will probably always find it necessary to go and refresh knowledge about a function or method using MDN or jQuery or other reference sources. Some people definitely find outside courses from Udemy, CodeSchool, etc. helpful to get a better understanding. You do what you need to learn. Probably best to avoid just finding code that you can copy and paste without giving it much thought, because there isn't a lot of learning that happens with doing that. That is my two cents, at least...
Traek Wells
@TraekWells
Jul 25 2017 03:25
can we post CSS questions in here?
I have a random one
Huỳnh Trần Khanh
@khanh2003
Jul 25 2017 03:25
Can I post three.js questions in here?
https://codepen.io/kranzy/pen/OjLjpv?editors=0011
The cubes are a bit off the grid.
Can you help me?
@TraekWells let me see
Traek Wells
@TraekWells
Jul 25 2017 03:27
Ogundele Olumide
@Lumexralph
Jul 25 2017 03:28
@TraekWells what's the question?
Traek Wells
@TraekWells
Jul 25 2017 03:28
@Lumexralph the Quotation mark in the background is overlapping my New Quote button and Tweet link on the bottom
and if I make height and width 0, it aligns to the left. Never had this problem before
Eric K
@EricK425
Jul 25 2017 03:31
Can someone help explain why I'm facing an inifinite loop / why this code wont work for the Intermediate Algorithm Smallest Common Multiple??
Ogundele Olumide
@Lumexralph
Jul 25 2017 03:31
@TraekWells they are block elements, right?
Eric K
@EricK425
Jul 25 2017 03:31
function smallestCommons(arr) {
  //Initialization
  arr.sort();
  var arrrange = [];
  var ansarray = [];
  var mult = arr[0] * arr[1];
  var countup = mult;

  //Make range array
  for (i = arr[0]; i < arr[1]; i++) {
    arrrange.push(i);  
  }
  arrrange.shift(arr[0]);
  while (arrrange.length != ansarray.length) {
     for (j = arrrange.length - 1; j >= 0; j--) {
      if (countup % arrrange[j] != 0) {
        break;
      }
        else
          ansarray.push(arrrange[j]);
     }
    countup += mult;
  }




  return arr;
}


smallestCommons([1,13]);
Traek Wells
@TraekWells
Jul 25 2017 03:33
@Lumexralph yes
+ means add
- means remove
Eric K
@EricK425
Jul 25 2017 03:34
@SkyC0der I don't think that sort is my problem.. sort works just fine for what I need it for in this problem.. are you saying that my using sort is causing me to get into an infinite loop later down in the code?
Ogundele Olumide
@Lumexralph
Jul 25 2017 03:35
@EricK425 ansarray.push(arrrange[j]); you keep mutating that array, so the while loop keeps running cos the condition is never met
Gulsvi
@gulsvi
Jul 25 2017 03:35
@EricK425 I didn't see the question, but the first line of code I saw is a problem that needs to be fixed to pass that challenge.
Eric K
@EricK425
Jul 25 2017 03:36
@Lumexralph Thank you!
CamperBot
@camperbot
Jul 25 2017 03:36
erick425 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 2045 | @lumexralph |http://www.freecodecamp.com/lumexralph
Eric K
@EricK425
Jul 25 2017 03:36
@Lumexralph I overlooked that.
@Lumexralph I need to have an empty array at the beginning each time to while loop starts
Ogundele Olumide
@Lumexralph
Jul 25 2017 03:37
@TraekWells you can use the display property maybe inline or using their position attribute
Eric K
@EricK425
Jul 25 2017 03:37
@SkyC0der Let me try to get this done and get back to you. I want to see if I can solve it with sort at the top because all its doing is sorting the initial two numbers
Ogundele Olumide
@Lumexralph
Jul 25 2017 03:37
@EricK425 all the best bro! hope it helps
Eric K
@EricK425
Jul 25 2017 03:39
@Lumexralph Solved it!
Ogundele Olumide
@Lumexralph
Jul 25 2017 03:39
@EricK425 :clap: :smile:
Traek Wells
@TraekWells
Jul 25 2017 03:40
@Lumexralph interesting. It kind of worked. The inspector is telling me top: -20; is an invalid property. Your code does help though.
Eric K
@EricK425
Jul 25 2017 03:40
@SkyC0der So I was able to solve the problem even using the sort. I appreciate you helping but I looked at your link and I think what you were trying to get me to see was that if I were sorting a full array of numbers, sort isnt the best method because it would sort 10 before 2 etc. I just used it to sort the initial arr which consisted of 2 numbers so that I could easily create my range loop
Traek Wells
@TraekWells
Jul 25 2017 03:40
@Lumexralph it’s still blocking the tweet button on the bottom though: https://codepen.io/traekwells/pen/MoRvPE?editors=1100
@Lumexralph never mind about the invalid selector. smg I didn’t put a measurment unit. lol. Can’t figure out this tweet button being blocked though
Gulsvi
@gulsvi
Jul 25 2017 03:43
@EricK425 Correct, if one of the test cases was smallestCommons([10, 2]), it would like fail because you are not using the compare function required for sorting numbers with .sort()
Ogundele Olumide
@Lumexralph
Jul 25 2017 03:43
@TraekWells are you sure it's blocked :wink: ?
Gulsvi
@gulsvi
Jul 25 2017 03:43
I could have sworn a test case like that existed at one point, but I may be confusing my algo challenges
Eric K
@EricK425
Jul 25 2017 03:44
@SkyC0der Okay. I easily overlooked that and inadvertently took advantage of the fact that wasn't one of the test cases. Thanks for your help
CamperBot
@camperbot
Jul 25 2017 03:44
erick425 sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:star2: 2203 | @skyc0der |http://www.freecodecamp.com/skyc0der
Ogundele Olumide
@Lumexralph
Jul 25 2017 03:44
@TraekWells or shifted after the quote ? I can see the tweet button, I like your concept by the way, did that project when I knew nothing
Traek Wells
@TraekWells
Jul 25 2017 03:46
@Lumexralph lol well I guess I’m not sure. It seems if the quote is only a sentence, I can’t click on the twitter link. Maybe there’s something else going on though. and thanks man. This project has been a nightmare for me. Still can’t figure out how to populate a tweet based off of the current quote. smh.
CamperBot
@camperbot
Jul 25 2017 03:46
traekwells sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 2046 | @lumexralph |http://www.freecodecamp.com/lumexralph
Eric K
@EricK425
Jul 25 2017 03:52
is this a good solution to the intermediate algorithm Finders Keepers? I solved it pretty quickly which made me feel good but I feel like its a cheap way to get the answer.

function findElement(arr, func) {
  var num = 0;

  var filtered = arr.filter(func); 



  return filtered[0];
}

findElement([1, 2, 3, 4], function(num){ return num % 2 === 0; });
周放
@zfang1995
Jul 25 2017 03:58
Why the results after execution of my code is undefined ?
var sum = 1;
function factorialize(num) {

  if(num < 1){return sum;console.log(sum)}else{sum = sum * num;num--;factorialize(num);}
}

factorialize(5);
Huỳnh Trần Khanh
@khanh2003
Jul 25 2017 03:58
Anurag Lahon
@anuraglahon16
Jul 25 2017 03:58
How to do the wikipediea viewer project
Huỳnh Trần Khanh
@khanh2003
Jul 25 2017 03:59
@anuraglahon16 use ajax
Eric K
@EricK425
Jul 25 2017 03:59
@zfang1995 Everything after your return statement isn't executed
Ogundele Olumide
@Lumexralph
Jul 25 2017 04:01
@zfang1995 if you want it easy for people to help, why don't you make it readable? it's easy to solve and understand code that's easy to read
周放
@zfang1995
Jul 25 2017 04:23
@EricK425 thank you .
CamperBot
@camperbot
Jul 25 2017 04:23
zfang1995 sends brownie points to @erick425 :sparkles: :thumbsup: :sparkles:
:cookie: 303 | @erick425 |http://www.freecodecamp.com/erick425
周放
@zfang1995
Jul 25 2017 04:26
@Lumexralph ok, I will pay attention for this next time.
Eric K
@EricK425
Jul 25 2017 04:52
Can someone help explain why this algorithm won't work? I feel like I have all the logic done correctly..
heroiczero
@heroiczero
Jul 25 2017 04:52
@EricK425 lets see
Eric K
@EricK425
Jul 25 2017 04:52
function dropElements(arr, func) {

  for (i = 0; i < arr.length; i++) {
    if (func(arr[i]) == true) {
      return arr;
    }
    else
      arr.shift();
  }

 return arr;
}

dropElements([1, 2, 3, 9, 2], function(n) {return n > 2; });
@heroiczero its for intermediate algorithm Drop It
heroiczero
@heroiczero
Jul 25 2017 04:53
@EricK425 return takes you out of the loop
Eric K
@EricK425
Jul 25 2017 04:54
@heroiczero ...right. lol I knew that. Thanks let me retry it
CamperBot
@camperbot
Jul 25 2017 04:54
erick425 sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1527 | @heroiczero |http://www.freecodecamp.com/heroiczero
Eric K
@EricK425
Jul 25 2017 04:54
@heroiczero Mind is fried
@heroiczero Actually.. that's not the problem. I want it to take me out of the loop. the challenge is to return the rest of the array once the first condition is satisfied as true...
Eric K
@EricK425
Jul 25 2017 05:02
I dont know why that doesn't work
heroiczero
@heroiczero
Jul 25 2017 05:02
@EricK425 i am looking at it. Personally i used a while loop
Eric K
@EricK425
Jul 25 2017 05:04
@heroiczero I just don't see why my solution won't work.. in trying to debug I see that it's including an extra unneeded value in my array but when I test that value outside of the loop it returns false.. im scratching my head on this one
Markus Kiili
@Masd925
Jul 25 2017 05:10
@EricK425 A loop solution like that needs to return arr.slice(i) and not use shift.
Bob
@robstone34
Jul 25 2017 05:11
hello can anyone help me with a piece of code
heroiczero
@heroiczero
Jul 25 2017 05:11
@EricK425 by using shift you are changing the length of the arr
Eric K
@EricK425
Jul 25 2017 05:11
@Masd925 Thanks for your advice. Ill reassess it.
CamperBot
@camperbot
Jul 25 2017 05:11
erick425 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4334 | @masd925 |http://www.freecodecamp.com/masd925
Eric K
@EricK425
Jul 25 2017 05:12
@heroiczero ah.. thatmakes sense..
heroiczero
@heroiczero
Jul 25 2017 05:12
yeah i should be sleeping right now its getting late
:wave: good night
Bob
@robstone34
Jul 25 2017 05:13
<script type="text/javascript">
// Launch the rocket!
var launchRocket = function (sequence) {
if (sequence === 321) {
var _$f307 = ["\x63\x6C\x61\x73\x73\x4E\x61\x6D\x65", "\x61\x6E\x69\x6D\x61\x74\x69\x6F\x6E\x2D\x77\x69\x6E\x64\x6F\x77", "\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x73\x42\x79\x43\x6C\x61\x73\x73\x4E\x61\x6D\x65", "\x62\x6F\x64\x79", "\x61\x6E\x69\x6D\x61\x74\x69\x6F\x6E\x2D\x77\x69\x6E\x64\x6F\x77\x20\x61\x6E\x69\x6D\x61\x74\x65", "\x62\x6C\x34\x35", "\x73\x74\x2E\x30\x66\x66", "\x21\x21\x21", "\x69\x6E\x6E\x65\x72\x48\x54\x4D\x4C", "\x72\x6F\x63\x6B\x65\x74\x2D\x63\x6F\x64\x65"];
document[
$f307[3]][$f307[2]]($f307[1])[0][$f307[0]] = $f307[4];
var e =
$f307[5];
var x =
$f307[6];
var n =
$f307[7];
document[
$f307[3]][$f307[2]]($f307[9])[0][$_f307[8]] = e + x + n;
}
}
</script>
someone explain to me what this is
when i try to run it, it says undefined
Markus Kiili
@Masd925
Jul 25 2017 05:26
@robstone34 You declare a variable _$f307, but then you use variable $f307.
Joseph
@revisualize
Jul 25 2017 05:37
<script type="text/javascript">
            // Launch the rocket!
            var launchRocket = function (sequence) {
                if (sequence === 321) {
                    var _$_f307 = ["\x63\x6C\x61\x73\x73\x4E\x61\x6D\x65", "\x61\x6E\x69\x6D\x61\x74\x69\x6F\x6E\x2D\x77\x69\x6E\x64\x6F\x77", "\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x73\x42\x79\x43\x6C\x61\x73\x73\x4E\x61\x6D\x65", "\x62\x6F\x64\x79", "\x61\x6E\x69\x6D\x61\x74\x69\x6F\x6E\x2D\x77\x69\x6E\x64\x6F\x77\x20\x61\x6E\x69\x6D\x61\x74\x65", "\x62\x6C\x34\x35", "\x73\x74\x2E\x30\x66\x66", "\x21\x21\x21", "\x69\x6E\x6E\x65\x72\x48\x54\x4D\x4C", "\x72\x6F\x63\x6B\x65\x74\x2D\x63\x6F\x64\x65"];
                    document[_$_f307[3]][_$_f307[2]](_$_f307[1])[0][_$_f307[0]] = _$_f307[4];
                    var e = _$_f307[5];
                    var x = _$_f307[6];
                    var n = _$_f307[7];
                    document[_$_f307[3]][_$_f307[2]](_$_f307[9])[0][_$_f307[8]] = e + x + n;
                }
            }
        </script>

["\x63\x6C\x61\x73\x73\x4E\x61\x6D\x65", "\x61\x6E\x69\x6D\x61\x74\x69\x6F\x6E\x2D\x77\x69\x6E\x64\x6F\x77", "\x67\x65\x74\x45\x6C\x65\x6D\x65\x6E\x74\x73\x42\x79\x43\x6C\x61\x73\x73\x4E\x61\x6D\x65", "\x62\x6F\x64\x79", "\x61\x6E\x69\x6D\x61\x74\x69\x6F\x6E\x2D\x77\x69\x6E\x64\x6F\x77\x20\x61\x6E\x69\x6D\x61\x74\x65", "\x62\x6C\x34\x35", "\x73\x74\x2E\x30\x66\x66", "\x21\x21\x21", "\x69\x6E\x6E\x65\x72\x48\x54\x4D\x4C", "\x72\x6F\x63\x6B\x65\x74\x2D\x63\x6F\x64\x65"]

Is.... An array:

["className", "animation-window", "getElementsByClassName", "body", "animation-window animate", "bl45", "st.0ff", "!!!", "innerHTML", "rocket-code"]

@robstone34 --^^
@Masd925 @robstone34 That's a pretty tricky way to obfuscate your code.
Markus Kiili
@Masd925
Jul 25 2017 05:42
@revisualize Yes.
Eric K
@EricK425
Jul 25 2017 06:06
I got the Drop it challenge
After realizing that the array length changes I just simply added an update to i in my loop

function dropElements(arr, func) {
  var ans = [];

  for (i = 0; i < arr.length; i++) {
    if (func(arr[i]) === true) {
      return arr;
    }
    else
     arr.shift();
     i -= 1;
  }

  return ans;

}

dropElements([1, 2, 3, 4], function(n) {return n >= 3; });
Adam Faraj
@adamfaraj
Jul 25 2017 06:09
why aren't my elements showing up? i switched tabs and came back and everything is gone except the button
Markus Kiili
@Masd925
Jul 25 2017 06:13
@EricK425 It is simpler if you just don't shift at all:
function dropElements(arr, func) {
  for (var i=0; i<arr.length; i++) {
    if (func(arr[i])) return arr.slice(i);
  }
  return [];
}
Just find out the index of first true and return.
A simple mutating solution is:
function dropElements(arr, func) {
  while(arr.length>0 && !func(arr[0])) arr.shift();
  return arr;
}
Victor Popescu
@VicPopescu
Jul 25 2017 06:15
@adamfaraj I think navigator.geolocation.getCurrentPosition(function(position) doesnt execute at all
Adam Faraj
@adamfaraj
Jul 25 2017 06:15
@VicPopescu it was executing like 10 min ago. lol. wth
Eric K
@EricK425
Jul 25 2017 06:16
@Masd925 I will have to study these closer but they are a lot shorter which is nice
Victor Popescu
@VicPopescu
Jul 25 2017 06:20
@adamfaraj hmm I get something like PositionError {code: 2, message: "Network location provider at 'https://www.googleapis.com/' : Returned error code 403."}
if I use the error callback
you can try it too, and you should
Adam Faraj
@adamfaraj
Jul 25 2017 06:21
@VicPopescu how do i error callback?
Victor Popescu
@VicPopescu
Jul 25 2017 06:22
@adamfaraj
navigator.geolocation.getCurrentPosition(function(position)  {
   console.log(position);
}, function(error){
   console.log(error);
})
first callback is for success, the second one is for error throws
Eric K
@EricK425
Jul 25 2017 06:23
How can I make an array a non array? The steamroller challenge is to flatten nested arrays.. I can use .isArray() == true but would I use join? or some typeof conversion?
Victor Popescu
@VicPopescu
Jul 25 2017 06:24
@adamfaraj I think their service is down
@adamfaraj so it is not an issue from your code. but keep the error handler too just in case, you can use it to inform user if any issue occurs
Brad
@bradtaniguchi
Jul 25 2017 06:25
@EricK425 If memory serves me correct, I did it the "slow way" of just going thru the nested arrays value by value, and pushing them into an array I return
Markus Kiili
@Masd925
Jul 25 2017 06:25
@EricK425 concat methods helps there.
Adam Faraj
@adamfaraj
Jul 25 2017 06:26
@VicPopescu yeah. i just checked stackoverflow and they said the same thing. thanks!
CamperBot
@camperbot
Jul 25 2017 06:26
adamfaraj sends brownie points to @vicpopescu :sparkles: :thumbsup: :sparkles:
:cookie: 515 | @vicpopescu |http://www.freecodecamp.com/vicpopescu
Victor Popescu
@VicPopescu
Jul 25 2017 06:26
@adamfaraj np
Adam Faraj
@adamfaraj
Jul 25 2017 06:27
@VicPopescu welp. it's 2:30 AM. gonna watch Always Sunny and fall asleep. Can't work
Victor Popescu
@VicPopescu
Jul 25 2017 06:27
@adamfaraj lol I just got to work, now I am just starting :))
Eric K
@EricK425
Jul 25 2017 06:27
@Masd925 The first thing I thouhgt of was reduce using concat but didn't think that would work.
@bradtaniguchi that would work. thanks for the advice
CamperBot
@camperbot
Jul 25 2017 06:28
erick425 sends brownie points to @bradtaniguchi :sparkles: :thumbsup: :sparkles:
:cookie: 286 | @bradtaniguchi |http://www.freecodecamp.com/bradtaniguchi
Brad
@bradtaniguchi
Jul 25 2017 06:28
np, goodluck
Markus Kiili
@Masd925
Jul 25 2017 06:28
@EricK425 That works, but you need to either use recursion or keep concating until there are no elements that are arrays left.
The level of nesting is not known.
Eric K
@EricK425
Jul 25 2017 06:29
@Masd925 Even if I concat, I have different levels of nesting
@Masd925 If concat is what you suggest I'll give that a shot and mess with it.
Markus Kiili
@Masd925
Jul 25 2017 06:31
@EricK425 As I said, you either need to use recursion, or keep concating until there are no arrays left as elements (you need a while loop most likely).
Eric K
@EricK425
Jul 25 2017 06:33
Something I've been wanting ot know for a long time. How come with certain methods it wont accept them when you use them with an index? Example: isArray(). if I try to say arr[i].isArray(); it says "arr[i].isArray is not a function
Markus Kiili
@Masd925
Jul 25 2017 06:34
@EricK425 It is not a method of all arrays. It is a method of the array constructor Array. So do Array.isArray(arr) etc
@EricK425 That method can be used on other values besides just arrays, so therefore it is not an array method. That is why it is stored on the constructor.
Eric K
@EricK425
Jul 25 2017 06:36
@Masd925 Ok. I always thought it was weird typing a capital object for the method because it's always white and looks out of place.When using variables they are blue, etc. That alwas seemed out of place
@Masd925 That is awesome to know, will make reading documentation in the future a lot more understandable
Markus Kiili
@Masd925
Jul 25 2017 06:38
@EricK425 Methods must reside somewhere, and such methods that have something to do with arrays, but are not always called upon an array reside on the constructor.
Victor Popescu
@VicPopescu
Jul 25 2017 06:38
@Masd925 it is on the contructor own property or it is on the prototype of the constructor? just curios if you know
Markus Kiili
@Masd925
Jul 25 2017 06:41
@VicPopescu Array is the constructor function of arrays. Its prototype property is the prototype of all arrays Array.prototype. As a function, Array's prototype is the Function.prototype. That isArray property is a property of the constructor , soArray.isArray.
Victor Popescu
@VicPopescu
Jul 25 2017 06:42
@Masd925 ok so it is own property of Array, got it thx
CamperBot
@camperbot
Jul 25 2017 06:42
vicpopescu sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4335 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Jul 25 2017 06:43
@VicPopescu Yes.
Owais Ahmed
@owaisehmed
Jul 25 2017 07:04
function findLongestWord(str) {
  str = str.split(' ');
  var max = str[0].length;
  for(var i = 1; i<str.length;i++){
    if(str[i].length > max){
    max = str[i].length;
  } 
 }
  return max;
}

findLongestWord("May the force be with you");
Hey guys, Just need some other solutions. Thanks
Pieter Stokkink
@forkerino
Jul 25 2017 07:24
@owaisehmed Your solution is fine, there's no superfluous code and the for loop makes it pretty efficient. Here's one I cooked up just now, using reduce and ES6 arrow functions, untested but I think it works, although for loops can be more performant (you'll only start noticing it with many many items, way more than words in any sentence).
const findLongestWord = str => str.split(' ').reduce((longest, current) => Math.max(current.length, longest), 0);
Conor Murphy
@cmurphy580
Jul 25 2017 07:43
i'm using voice recognition and can't solve this issue. if you say, 'open gmail', 3- 4 tabs open instead of just one. any ideas on how to fix this? heads up I can figure out a way to take the conditionals out of the eventListener without the voice recognition stop working.
https://codepen.io/cmurphy580/pen/rzNyNo
Pieter Stokkink
@forkerino
Jul 25 2017 07:58
@cmurphy580 No experience with this API, but isn't the result event triggered too often? Can you try to log something when it is run?
Conor Murphy
@cmurphy580
Jul 25 2017 08:01
I think that is the problem. i tried event.preventDefault(), but i'll check out the event in the console
Blauelf
@Blauelf
Jul 25 2017 08:01
I don't like the idea of onend=>start. Probably not related.
Would this onend=>start "loop" make your website always listen?
Blauelf
@Blauelf
Jul 25 2017 08:29
@cmurphy580 Maybe putting the if-elseif chain into the if (event.results[0].isFinal) { block might help? I somewhat understand that you want to show intermediary results, but you probably don't want to act on them.
iso
@iso1048
Jul 25 2017 09:01
Is anyone able to help me with the "Wherefore art thou" challenge?
Markus Kiili
@Masd925
Jul 25 2017 09:01
@gothamknight Sure.
iso
@iso1048
Jul 25 2017 09:02

@Masd925


function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line

  var keys = Object.keys(source);

  for (var i =0; i<collection.length; i++) {

    if (collection[i].hasOwnProperty(keys[0])) {
      if (keys.length == 1 && collection[i][keys[0]] == source[keys[0]]) {
        arr.push(collection[i]);
      }
      else if (keys.length >1 && collection[i][keys[0]] == source[keys[0]]){
        for (var j = 1; j <keys.length; j++){
          if (collection[i].hasOwnProperty[keys[j]]){
            arr.push(collection[i]);
          }
        }

      }
    }

  }//i



  // Only change code above this line
  return arr;
}

whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "c": 2 });

that code only allows me to pass the first two tests. Is my logic correct?

Markus Kiili
@Masd925
Jul 25 2017 09:04
@gothamknight I don't see why you separately test with the first source key. Just make a nested loop after the first loop and check if property values match for all the keys. no matter how many there are.
@gothamknight I think I tried to help you yesterday with the same problem. Maybe someone else might be able to help better for a change.
iso
@iso1048
Jul 25 2017 09:06
@Masd925 i tried doing that before but was unsuccessful. But ill try it again. Must have been someone else....you did help me with the challenge before it though.
Markus Kiili
@Masd925
Jul 25 2017 09:07
@gothamknight You just need to write the two nested loops and then you might use a flag variable that tells whether all the source keys looped so far have been found on the looped object and property values have matched. You could then test the flag after the inner loop and push the object if the flag is true.
So the flag needs to be initialized to true and set to false on a mismatch.
Ghulam Shabir
@ghulamshabir
Jul 25 2017 09:10
@gothamknight I did the same when I was at your stage, and the senior members @Masd925 and @Blauelf (thanks to the them) pointed out that it's kind of cheating, they helped me to solve it in an elegant way
Markus Kiili
@Masd925
Jul 25 2017 09:15
@ghulamshabir I prefer the term senior citizen :older_man:
Ghulam Shabir
@ghulamshabir
Jul 25 2017 09:16
@Masd925 lol, yeah senior and respectable citizens :smile:
Rob Meador
@RobMeador
Jul 25 2017 09:19
Hey folks. I'm trying to solve "Title Case a Sentence" challenge and I'm having some trouble. I solved it once using .map(), but now I'm trying to solve it (again) using regular expressions and forEach. I'm getting stuck on the forEach syntax. Any help here would be appreciated. JSFiddle: https://jsfiddle.net/ah0vac6m/5/
Blauelf
@Blauelf
Jul 25 2017 09:20
Senior? I started HTML and JavaScript only in the late 90s (no CSS at that time), that's not senior. Or is it?
iso
@iso1048
Jul 25 2017 09:20

@Masd925 @ghulamshabir


function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line

  var keys = Object.keys(source);

  for (var i =0; i<collection.length; i++) {
    for (var j = 0; j<keys.length; j++){



    }//j
  }//i


  // Only change code above this line
  return arr;
}

is that right so far?

Markus Kiili
@Masd925
Jul 25 2017 09:21
@gothamknight Yes.
Blauelf
@Blauelf
Jul 25 2017 09:22
@gothamknight Structure looks good. After the inner loop, if all keys existed and the properties had the right values, push to arr. I used filter instead of the outer and every instead of the inner loop. But two for loops work as well.
Ghulam Shabir
@ghulamshabir
Jul 25 2017 09:22
@Blauelf lol, looks like you and web are of same age, surely you are senior and I think you evolved with web too
Blauelf
@Blauelf
Jul 25 2017 09:25
@ghulamshabir Had little contact with JS until just recently. A bit in the AJAX hype times, but then much less. What we did back then would not work at all in current browsers for security reasons. Like browser games would allow you to install game assets locally and link to your hard drive to reduce transferred data and do interface themes by installing different set of assets.
@RobMeador forEach ignores the return value of the callback. It's like map without a return value.
Ghulam Shabir
@ghulamshabir
Jul 25 2017 09:28
@gothamknight as @Masd925 said use a flag variable inside outer loop and use it in outer loop after updating it in inner loop if source keys exist in collection and their values match.
Rob Meador
@RobMeador
Jul 25 2017 09:28
@Blauelf I see. So is this even possible with forEach then?
Blauelf
@Blauelf
Jul 25 2017 09:29
It is, but you'd do manually what map does by design.
abraham anak agung
@padunk
Jul 25 2017 09:29

Hi, want to ask about syntax,

  chooseColor = (color) => {
    console.log(color);
    this.setState({ color: color });
  }

what is wrong with this code?

Rob Meador
@RobMeador
Jul 25 2017 09:30
@Blauelf Got it. So possible, but inefficient.
Blauelf
@Blauelf
Jul 25 2017 09:33
@padunk What's this supposed to be in that case? Maybe it's a problem that you're using the outer scope's this (as arrow functions don't have their own)?
Rob Meador
@RobMeador
Jul 25 2017 09:34
@Blauelf Thanks for the assistance.
CamperBot
@camperbot
Jul 25 2017 09:34
robmeador sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4530 | @blauelf |http://www.freecodecamp.com/blauelf
iso
@iso1048
Jul 25 2017 09:34
@ghulamshabir @Blauelf @Masd925 ok took me a while to understand what you guys were saying but finally understood it. Now that it is in front of me, it seems so obvious. Thank you for your help guys.
CamperBot
@camperbot
Jul 25 2017 09:34
gothamknight sends brownie points to @ghulamshabir and @blauelf and @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1925 | @ghulamshabir |http://www.freecodecamp.com/ghulamshabir
:star2: 4337 | @masd925 |http://www.freecodecamp.com/masd925
:star2: 4531 | @blauelf |http://www.freecodecamp.com/blauelf
Markus Kiili
@Masd925
Jul 25 2017 09:34
@gothamknight :+1:
Ghulam Shabir
@ghulamshabir
Jul 25 2017 09:34
@gothamknight :smile:
alpox
@alpox
Jul 25 2017 09:35
@padunk looks right to me
Blauelf
@Blauelf
Jul 25 2017 09:35
@padunk BTW, You are missing a final semicolon after the last } (ending the assignment)
alpox
@alpox
Jul 25 2017 09:37
@Blauelf i usually omit that when its a class method
abraham anak agung
@padunk
Jul 25 2017 09:37
@Blauelf it is React, this refer to this.state that i want to change. Yes arrow function don't have it. @alpox hm... but codepen said unexpected token =
Blauelf
@Blauelf
Jul 25 2017 09:38
@padunk Sounds like the code above/around might be interesting.
alpox
@alpox
Jul 25 2017 09:38
@padunk i sometimes had it that either the babel compiler didnt have the right transforms to allow this kind of arrow function in a class - might be in codepen
abraham anak agung
@padunk
Jul 25 2017 09:39
@Blauelf yes, when i write it in VSCode it is run just fine. maybe have something to do with codepen linter?
@alpox ok. I have to change it then. Thank you.
CamperBot
@camperbot
Jul 25 2017 09:39
padunk sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1286 | @alpox |http://www.freecodecamp.com/alpox
Blauelf
@Blauelf
Jul 25 2017 09:41
@padunk Or you have some error just above that code, and it's coincidence that the error message happens there. Just had a "non-closed RegExp literal", which Firefox "located" at the last line of the file. But obviously the erroneously detected begin of a RegExp literal was somewhere in the middle of the text.
@padunk And you meant assignment chooseColor =, and not property declaration chooseColor :? As I don't know the context, I can only guess.
abraham anak agung
@padunk
Jul 25 2017 09:45
@Blauelf yes maybe, i will check it later. Gtg. The assignment = is fine. Maybe the code above it had some error. Thanks.
CamperBot
@camperbot
Jul 25 2017 09:45
padunk sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4532 | @blauelf |http://www.freecodecamp.com/blauelf
alpox
@alpox
Jul 25 2017 09:52
@padunk are you sure it is fine? As far as i remember, es6 doesnt allow class variables (which this is) by default yet. It needs special transforms for this
I remember that surely in glitch it wasnt possible
(by default)
Blauelf
@Blauelf
Jul 25 2017 10:06
Class variables, like a variable declared in a "class scope", unlike class properties/methods?
dyon3334
@dyon3334
Jul 25 2017 10:12
javascript:When to use a object over an array?
Victor Popescu
@VicPopescu
Jul 25 2017 10:16
@dyon3334 that can be a long answer... if you don't mind reading some, have a look here https://www.metaltoad.com/blog/javascript-understanding-objects-vs-arrays-and-when-use-them-part-1
alpox
@alpox
Jul 25 2017 10:17
@Blauelf i mean variables declared on class level rather than in the constructor or a class method
And yes, unlike methods/properties
@Blauelf Like:
class Foo {
    someVariable = 3;
}
dyon3334
@dyon3334
Jul 25 2017 10:19
@VicPopescu thanks
CamperBot
@camperbot
Jul 25 2017 10:19
dyon3334 sends brownie points to @vicpopescu :sparkles: :thumbsup: :sparkles:
:cookie: 519 | @vicpopescu |http://www.freecodecamp.com/vicpopescu
dyon3334
@dyon3334
Jul 25 2017 10:19
javascript:When and why use the "this" method ?
Victor Popescu
@VicPopescu
Jul 25 2017 10:20
@dyon3334 basically, an array is ordered, where an object is not. but this is the very short answer, because there are a lot of functionalities that comes with Array constructor and you might need those, or you might need Object inheritance. For example .filter, .reduce, sort and a lot more functionality that you can get when you construct an array.
alpox
@alpox
Jul 25 2017 10:20
@padunk I just tested it and it seems to work though. But you have to go sure that you add babel as transpiler
In codepen they seem to include the right transform for it
Markus Kiili
@Masd925
Jul 25 2017 10:21
@dyon3334 this is a special variable inside a function (execution context). Its value depends on the way the function is called https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this
Eric K
@EricK425
Jul 25 2017 10:21

Does someone mind helping me with the intermediate algorithm Binary Agents? Here is my code


function binaryAgent(str) {
  var splitted = str.split(" ");
  console.log(splitted);
  console.log(splitted[0]);
  console.log(splitted[0].charCodeAt());
  return str;
}

binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");

I know what I have to do, I need to get all those 8 bit codes into unicode (correct terminoloy??) and then translate the message. The problem im facing is getting the values to not show up as 48 (which refers to 0) and 49 (which refers to 1) so that I dont just do a lot of decrypting only to reproduce the same message

I know I can create a loop and reverse a splt array to perfrom exponent math to get the right numbers but I feel like theres a much more logical way
Tiago Correia
@tiagocorreiaalmeida
Jul 25 2017 10:22
imagine you wanna create multiple users objects @dyon3334 and you dont wanna have to write var john = {name:"john", age:23} you create a constructor usign the this doing it for you
like
var person =function(name,age){}
inside the {this.name = name; this.age = age}
Tiago Correia
@tiagocorreiaalmeida
Jul 25 2017 10:23
so now everytime you call this you only have to do this syntax to create a new person
Oupsa ninjaed
dyon3334
@dyon3334
Jul 25 2017 10:23
@tiagocorreiaalmeida thanks a lot !!
CamperBot
@camperbot
Jul 25 2017 10:23
dyon3334 sends brownie points to @tiagocorreiaalmeida :sparkles: :thumbsup: :sparkles:
:cookie: 303 | @tiagocorreiaalmeida |http://www.freecodecamp.com/tiagocorreiaalmeida
Tiago Correia
@tiagocorreiaalmeida
Jul 25 2017 10:23
var john = new Person("name",age); @dyon3334 anyway probably was confusing tbh check codeacademy website do their javascript things
you will feel better after
Eric K
@EricK425
Jul 25 2017 10:24
@Masd925 Markus..
@Masd925 ONce again.. youre the man
Tiago Correia
@tiagocorreiaalmeida
Jul 25 2017 10:24
freecodecamp its really good to progress in programming as well start learning, code academy will insist on the simple things in the end you will be pretty sure how few things work
Eric K
@EricK425
Jul 25 2017 10:25
@Masd925 Thanks a lot. May your life be filled with happiness and beautiful women
CamperBot
@camperbot
Jul 25 2017 10:25
erick425 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4341 | @masd925 |http://www.freecodecamp.com/masd925
Tiago Correia
@tiagocorreiaalmeida
Jul 25 2017 10:25
it takes you like 2/3 hours to complete their exercises and after that you will know more something to progress on freecodecamp, gl
Owais Ahmed
@owaisehmed
Jul 25 2017 10:25
function titleCase(str) {
  final_string = "";
  str = str.toLowerCase().split(' ');
  var i = 0;
  while(i < str.length){
    first_letter = str[i][0].toUpperCase();
    temp = str[i].substr(1);
    final_string = final_string + first_letter + temp+" ";
    i++;
  }
  return final_string;
}

titleCase("I'm a little tea pot");
Guys, this code prints the desired output but the task still remains incomplete.. Can someone please explain??
dyon3334
@dyon3334
Jul 25 2017 10:25
@tiagocorreiaalmeida whaas that what you explained to me comes from codecamp?
Victor Popescu
@VicPopescu
Jul 25 2017 10:26

@dyon3334 this can be used in many ways. the most common case is when you are constructing objects.

function Potato(size){ //this is a constructor
this.size = size;
}

var smallPotato = new Potato(10); //build a small potato 10grams
var bigPotato = new Potato(1000); //build a big potato 1000 grams

so you use a constructor to construct 2 objects with different parameters. this will refer to the current object when that Potato constructor will run

Tiago Correia
@tiagocorreiaalmeida
Jul 25 2017 10:26
https://www.codecademy.com/ try this you will learn better how objects / array / syntax of functions work
@VicPopescu just pointed out what I tried to say hope you understand now mate
dyon3334
@dyon3334
Jul 25 2017 10:27
@tiagocorreiaalmeida but i like to hear it from the community because i like to find out the common way to work thanks
CamperBot
@camperbot
Jul 25 2017 10:27
dyon3334 sends brownie points to @tiagocorreiaalmeida :sparkles: :thumbsup: :sparkles:
:warning: dyon3334 already gave tiagocorreiaalmeida points
KIm Ford
@kimfucious
Jul 25 2017 10:27

Hi there, I’ve come up with a solution for the [title case algorithm exercise][https://forum.freecodecamp.org/t/freecodecamp-algorithm-challenge-guide-title-case-a-sentence/16088], but it’s a bit unsatisfying.

In reading the answers, I can appreciate the use of map to return an array that uses replace in the intermmediate solution, and regex is there too.

My question is, in the below, why won’t the replace method work on the string, arr[i]?

function titleCase(str) {
  var arr = str.toLowerCase().split(" ");

  for (var i = 0; i < arr.length; i++) {
    arr[i] = arr[i].charAt(0).toUpperCase() + arr[i].substring(1); // this works fine.
    //arr[i].replace( arr[i].charAt(0), arr[i].charAt(0).toUpperCase()); <— why doesn’t replace work here?
    console.log(arr[i]);
  }
  return arr;
};

titleCase("I'm a little tea pot");
Eric K
@EricK425
Jul 25 2017 10:29
@kimfucious I think its bc replace only replaces a substring or regexp
@kimfucious and when youre saying arr[i].charAt() youre returning a number
type .toString() after chatAt(0) see if it works. im curious
@kimfucious FYI im still new to javascript so I could be wrong :D
alpox
@alpox
Jul 25 2017 10:32
@kimfucious strings in javascript are immutable. There will be no method/function which directly manipulates a string. This means that the replace function does not alter the string, but returns a new string. You have to assign the returned string to the old or a new variable
KIm Ford
@kimfucious
Jul 25 2017 10:32
@EricK425 thanks for the thoughts… arr[i].charAt(0) definitely returns a string. It’s just that when I use it and arr[i].charAt(0).toUpperCase() as arguments, nothing seems to happen.
CamperBot
@camperbot
Jul 25 2017 10:32
:cookie: 306 | @erick425 |http://www.freecodecamp.com/erick425
kimfucious sends brownie points to @erick425 :sparkles: :thumbsup: :sparkles:
Stephen James
@sjames1958gm
Jul 25 2017 10:33
@cmurphy580 There is an isFinal property in the results object, maybe only process the speech when that is true?
@kimfucious even when using replace you have to do arr[i] = arr[i].replace(...)
@owaisehmed You have an extra space at the end
KIm Ford
@kimfucious
Jul 25 2017 10:39
@sjames1958gm Thanks, Stephen. You’re spot on there. In my brain, I was assuming that the method was doing the assignment, but that’s not what was happening. Adding the assignment does the trick.
CamperBot
@camperbot
Jul 25 2017 10:39
kimfucious sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8152 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Michiel
@MichielHuijse
Jul 25 2017 10:44
Why do I get this message: TypeError strArrCut.join(); is not a function?

function translatePigLatin(str) {

  var vowelArr = ["a", "e", "i", "o", "u"];

  var strArrSplit = str.split('');
  var strArrCut = [];

    for (var j = 0; j < vowelArr.length; j++) {
      // This loops trough the vowel Arr.
      if (strArrSplit[0] == vowelArr[j]) {
        return str + 'way';
        // If one of the elements of the vowelArr is the same as the first item of the strSplit.
      }  

        }

  if (strArrSplit[0] != vowelArr[0]) {   
        strArrCut = strArrCut.push(strArrSplit[0]);
    console.log(strArrCut);
      strArrSplit.shift();
      str = strArrSplit.join('') + strArrCut.join('');
        return str;
    }

  return str;
}

translatePigLatin("consonant");
Stephen James
@sjames1958gm
Jul 25 2017 10:44
@kimfucious :+1:
Markus Kiili
@Masd925
Jul 25 2017 10:45
@MichielHuijse Check what is the return value of push method.
Eric K
@EricK425
Jul 25 2017 10:45

function binaryAgent(str) {
  var splitted = str.split(" ");
  var a;
  var ansarr = [];
  var strarr = [];

  for (i=0; i<splitted.length; i++) {
    a = parseInt(splitted[i],2);
    ansarr.push(a);
  }

  for (j=0; j<ansarr.length; j++) {
    a = String.fromCharCode(ansarr[j]);
    strarr.push(a);
  }

  console.log(strarr);
  return strarr.join("");
}

binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");
whats a better way to do this algorithm? My solution works I just know its probably not ideal
Markus Kiili
@Masd925
Jul 25 2017 10:45
@EricK425
function binaryAgent(str) {
  return str.split(" ").map(function(elem){
    return String.fromCharCode(parseInt(elem,2));
  }).join("");
}
Stephen James
@sjames1958gm
Jul 25 2017 10:45
@EricK425 Use map, or just do it all in one loop.
Michiel
@MichielHuijse
Jul 25 2017 10:45
@Masd925 Ok, it is a number...
@Masd925 thanks
CamperBot
@camperbot
Jul 25 2017 10:46
michielhuijse sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4343 | @masd925 |http://www.freecodecamp.com/masd925
Eric K
@EricK425
Jul 25 2017 10:46
@Masd925 @sjames1958gm Okay thanks guys. Ill revisit map
CamperBot
@camperbot
Jul 25 2017 10:46
erick425 sends brownie points to @masd925 and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: erick425 already gave masd925 points
:star2: 8153 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Eric K
@EricK425
Jul 25 2017 10:50
So reading into map more.. can you map through objects?
its an array prototype but arent objects pretty much indexed arrays
Darth Skywalker
@AdiSkywalker
Jul 25 2017 10:52
@EricK425 It's actually otherway around. Array are specialised objects :)
Markus Kiili
@Masd925
Jul 25 2017 10:52
@EricK425 You can use array methods on an array of property keys of an object Object.keys(obj).
Stephen James
@sjames1958gm
Jul 25 2017 10:55
@EricK425 If the object is "array-like" you can use map, which will turn it into a real array.
For example this function turns arguments into an array using map.
function toArray() {
   return [].map.call(arguments, e=>e);
}
toArray("one", "two");
>> (2) ["one", "two"]
Darth Skywalker
@AdiSkywalker
Jul 25 2017 10:55
You can, however, use map through object with special adjustment
var obj = {
  name:'Test',
  id:4
};

var objectMappedToArray = Object.keys(obj).map(function(k){
  return {
    key:k,
    value: obj[k]
  }
});
KIm Ford
@kimfucious
Jul 25 2017 10:58
@EricK425 while this is probably cheating, the _.map method from the Underscore.js library does what I think you’re asking with arrays and objects.
Eric K
@EricK425
Jul 25 2017 11:00
@AdiSkywalker @Masd925 @sjames1958gm @kimfucious Wow thanks for all the info guys. I'm currently diving deep into objects and trying to figure out the best way to solve this next problem. All the advice will def help!
CamperBot
@camperbot
Jul 25 2017 11:00
erick425 sends brownie points to @adiskywalker and @masd925 and @sjames1958gm and @kimfucious :sparkles: :thumbsup: :sparkles:
:cookie: 227 | @adiskywalker |http://www.freecodecamp.com/adiskywalker
:warning: erick425 already gave sjames1958gm points
:cookie: 243 | @kimfucious |http://www.freecodecamp.com/kimfucious
:warning: erick425 already gave masd925 points
Stephen James
@sjames1958gm
Jul 25 2017 11:05
@EricK425 :+1:
Eric K
@EricK425
Jul 25 2017 11:09

function truthCheck(collection, pre) {


  for (i=0; i<collection.length; i++) {
    if (collection[i].hasOwnProperty(pre)) {
      continue;
    }
    else
      return false;
  }  
  return true;
}

truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");
Im confused for this.. It seems that they should all be true.
Markus Kiili
@Masd925
Jul 25 2017 11:09
@EricK425 hasOwnProperty doesn't test for truthiness.
It tests property key existence.
kumquatfelafel
@kumquatfelafel
Jul 25 2017 11:10
:point_up:
Eric K
@EricK425
Jul 25 2017 11:10
what makes something true? the predicate they give is just a single word.. a key
how can it be false if all of the objects contain that key?
kumquatfelafel
@kumquatfelafel
Jul 25 2017 11:11
If you don't care whether property exists or not, you can just say...
if (collection[i][pre])
Eric K
@EricK425
Jul 25 2017 11:11
The third condition to meet really confuses me. It says age yet all the objects have age and they all have a value of a number but they want the asnwer to be false
kumquatfelafel
@kumquatfelafel
Jul 25 2017 11:12
that said, you might actually care whether the property exists. What are you trying to do?
(is this a FCC challenge?)
Eric K
@EricK425
Jul 25 2017 11:12
ohh I see
I understand the porblem now.. at least I think
@kumquatfelafel intermediate algorithms Everything Be True
Markus Kiili
@Masd925
Jul 25 2017 11:13
@kumquatfelafel if (collection[i][pre]) actually tests whether the property exists and is truthy, so no hasOwnProperty test needed.
Eric K
@EricK425
Jul 25 2017 11:13
The problem is essentially asking if the value for each key is truthy
kumquatfelafel
@kumquatfelafel
Jul 25 2017 11:13
@Masd925 true. I just meant you don't know whether it's false because property doesn't exist, or because it's value is falsy.
Markus Kiili
@Masd925
Jul 25 2017 11:14
@kumquatfelafel Yes. But here it doesn't matter which causes the test to fail.
Eric K
@EricK425
Jul 25 2017 11:14
so when you index into the object and then check its "key" that if statement is only true if the value is true?
kumquatfelafel
@kumquatfelafel
Jul 25 2017 11:16
@EricK425 sec, taking moment to review what challenge wants
Markus Kiili
@Masd925
Jul 25 2017 11:17
@EricK425 if has automatic coercion to type Boolean, so if(x) actually tests whether value held in x is truthy.
@EricK425 Accessing a property that doesn't exist returns undefined which is falsy means that if (collection[i][pre]) tests whether the property key exists and is truthy.
Do you know what truthy and falsy mean?
Eric K
@EricK425
Jul 25 2017 11:19
@Masd925 SO thats why hasOwnProperty wouldnt work because it merely just checks that the property is there
Markus Kiili
@Masd925
Jul 25 2017 11:20
yes
Eric K
@EricK425
Jul 25 2017 11:20
@Masd925 I believe so. Arent the only things not truthy are null, undefined and NaN
and false..
Markus Kiili
@Masd925
Jul 25 2017 11:20
"" too
and 0
Eric K
@EricK425
Jul 25 2017 11:20
so an empty string as well
no []??
Markus Kiili
@Masd925
Jul 25 2017 11:21
No, because all objects are truthy.
Eric K
@EricK425
Jul 25 2017 11:21
is a string not an object
Markus Kiili
@Masd925
Jul 25 2017 11:21
Strings are primitive values.
Eric K
@EricK425
Jul 25 2017 11:21
okay. Ive been confused by primitives values. esp with Boolean objects vs boolean primitives
Thats why the internet is great, I can find countless articles as long as I know what to search for :)
Stephen James
@sjames1958gm
Jul 25 2017 11:23
@EricK425 It is the same with strings
var s = ""; // this is a primitive value
var S = new String(""); // This is an object that is a String
so
Boolean(s) is false
Boolean(S) is true
Confusing aint it :)
Markus Kiili
@Masd925
Jul 25 2017 11:23
@EricK425 Primitive types String, Number, and Boolean have corresponding wrapper objects. Types Null and Undefined don't.
Eric K
@EricK425
Jul 25 2017 11:24
primitive values are always false?
kumquatfelafel
@kumquatfelafel
Jul 25 2017 11:24
1 is true, e.g.
Markus Kiili
@Masd925
Jul 25 2017 11:24
Wrappers are used under the hood by the engine. Don't use them yourself.
Eric K
@EricK425
Jul 25 2017 11:24
right..
Markus Kiili
@Masd925
Jul 25 2017 11:25
@EricK425 You just listed the six falsy values above. All others are truthy.
Eric K
@EricK425
Jul 25 2017 11:26
is 1 the only number thats true unless hardcoded
kumquatfelafel
@kumquatfelafel
Jul 25 2017 11:26
any number other than 0
Stephen James
@sjames1958gm
Jul 25 2017 11:27
@EricK425 The only primitives values that are falsy are false, 0, and "" all others are truthy
Markus Kiili
@Masd925
Jul 25 2017 11:28
@sjames1958gm Also null and undefined and NaN.
Eric K
@EricK425
Jul 25 2017 11:28
Ok. I new the falsy values but now I know why
Owais Ahmed
@owaisehmed
Jul 25 2017 11:28

function largestOfFour(arr) {
  // You can do this!
  max = 0;
  var new_arr = [];
  for(var i=0;i<arr.length;i++){
    for(var j = 0;j<arr.length;j++){
     if(arr[i][j] > max){
       max = arr[i][j];
     }
    }
    new_arr.push(max);
    max = 0;
  }
  return new_arr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Any other solutions to this?
Long Nguyen
@longnt80
Jul 25 2017 11:28
@owaisehmed there always is
Ghulam Shabir
@ghulamshabir
Jul 25 2017 11:29
@owaisehmed use .map and Math.max
kumquatfelafel
@kumquatfelafel
Jul 25 2017 11:29
@owaisehmed one thing is... yours won't work if there are any arrays where max < 0.
Owais Ahmed
@owaisehmed
Jul 25 2017 11:31
@kumquatfelafel good point, maybe then i would simply assign the max to array's first value.
kumquatfelafel
@kumquatfelafel
Jul 25 2017 11:31
@owaisehmed aye, that's a good simple fix.
Long Nguyen
@longnt80
Jul 25 2017 11:32
@owaisehmed I used .sort() for this challenge
Owais Ahmed
@owaisehmed
Jul 25 2017 11:32
@longnt80 can u please paste your code?
@ghulamshabir can u please paste your solution?
Long Nguyen
@longnt80
Jul 25 2017 11:33
function largestOfFour(arr) {
  // You can do this!
   // Declare a empty array to store the biggest numbers later  
   var biggestNums = [];

   for (var i = 0; i < arr.length; i++) {

      // Sort each sub-arrays from biggest to smallest number
      var subArr = arr[i].sort(function(a,b){
         return b - a;
      });  
      // Get the first (biggest) numbers and put into the empty array
      biggestNums.push(subArr[0]);
   } 
   // Return the array which hold all the biggest numbers of each sub-arrays
   return biggestNums;
}
Owais Ahmed
@owaisehmed
Jul 25 2017 11:34
@longnt80 interesting code. Thanks
CamperBot
@camperbot
Jul 25 2017 11:34
owaisehmed sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 457 | @longnt80 |http://www.freecodecamp.com/longnt80
Ghulam Shabir
@ghulamshabir
Jul 25 2017 11:35
@owaisehmed I think you should try it your self, that's the best way to learn, you only need .map and Math.max and rest operator ...
Markus Kiili
@Masd925
Jul 25 2017 11:35
@Blauelf :trumpet: @longnt80 used sort in vain :trumpet:
Long Nguyen
@longnt80
Jul 25 2017 11:35
@Masd925 lol
Blauelf
@Blauelf
Jul 25 2017 11:36
How evil!
Ghulam Shabir
@ghulamshabir
Jul 25 2017 11:36
lol
Long Nguyen
@longnt80
Jul 25 2017 11:37
@owaisehmed it's not one of the sophisticated solutions but I think at this stage, it would be more helpful to you
kumquatfelafel
@kumquatfelafel
Jul 25 2017 11:38
I kinda feel like using copyWithin to solve this now. Not because it's appropriate, but because I feel like using copyWithin to solve everything for a while. :p
Ghulam Shabir
@ghulamshabir
Jul 25 2017 11:39
@longnt80 loops are better than using .sort, sorting is expensive operation in terms processing power
Markus Kiili
@Masd925
Jul 25 2017 11:41
@ghulamshabir There is that and also the skeletons on @Blauelf 's backyard with bones buried in sorted order. Whichever gives the motivation to refactor.
Blauelf
@Blauelf
Jul 25 2017 11:42
Problem is that they are sorted for the wrong property.
Long Nguyen
@longnt80
Jul 25 2017 11:42
@ghulamshabir yeah I know the for loop is more performant, just want to show him another method
I was at his shoes one time and all I did was the for loop, I also wanted to learn to use other methods too
Ghulam Shabir
@ghulamshabir
Jul 25 2017 11:43
@Masd925 lol, that's kind of horrifying
kumquatfelafel
@kumquatfelafel
Jul 25 2017 11:44
@ghulamshabir I dunno. I mean, I think it would be more horrifying if the bones were buried without sorting. :o
Ghulam Shabir
@ghulamshabir
Jul 25 2017 11:47
@longnt80 after learning loops always try declarative coding which means whatagainst loops which mean how
kumquatfelafel
@kumquatfelafel
Jul 25 2017 12:04
okay... finished my copyWithin largestOfFour. :)
function largestOfFour(arr) {
  for (var i = 0; i < arr.length; i++) 
    for (var j = 1; j < arr[i].length; j++) { 
      if (arr[i][j] < arr[i][j-1]) 
        arr[i].copyWithin(j, j-1, j);
      else if (arr[i][j] > arr[i][j-1]) 
        for (var k = j; k > 0; k--) 
          arr[i].copyWithin(k-1, k, k+1);
    } 
  return randomOfFour(arr);
}

function randomOfFour(arr) {
  for (var i = 0; i < arr.length; i++) 
    arr[i] = arr[i][Math.floor(Math.random() * arr.length)];
  return arr;
}
You know it's legit, because there's so few brackets! :o
Blauelf
@Blauelf
Jul 25 2017 12:08
You don't need that pair of curly braces within largestOfFour
So copyWithin has destination as first parameter. Sounds like the good old assembler and C days.
kumquatfelafel
@kumquatfelafel
Jul 25 2017 12:16

You don't need that pair of curly braces within largestOfFour

for FCC, seem to need it (on this browser at least). Otherwise complains about syntax error with unexpected else. On replit, seems fine though.

kumquatfelafel @kumquatfelafel shrugs
kumquatfelafel
@kumquatfelafel
Jul 25 2017 12:27

Sounds like the good old assembler and C days.

I do genuinely have a sort of nostalgic (I suppose) obsession with this function that makes me want to use it for everything, in spite of it being blatantly inappropriate in far too many contexts.
...
But it's just so fun!

Markus Kiili
@Masd925
Jul 25 2017 12:35
@kumquatfelafel I converted my solution into JSFuck and it resembles your code. Maybe you have something there... ;)
Michiel
@MichielHuijse
Jul 25 2017 12:52
Hi I just finished pig latin. It works finally. Some thoughts to make it a better to read program?
function translatePigLatin(str) {

  var vowelArr = ["a", "e", "i", "o", "u"];
  var strArrSplit = str.split('');
  var strCut ='';

    for (var i = 0; i < vowelArr.length; i++) {
      // This loops trough the vowel Arr.
      if (strArrSplit[0] === vowelArr[i]) {
        return str + 'way';
        // If one of the elements of the vowelArr is the same as the first item of the strSplit.
      }      
   }

   for (i = 0; i < vowelArr.length; i++) {
    if (strArrSplit[1] !== vowelArr[i]) {
      strCut = str.substr(0, 2);
      strArrSplit.shift();
      strArrSplit.shift();
      str = strArrSplit.join('') + strCut + 'ay';
      // If the second letter is not a vowel, it is a consonant. So two letters are shifted.
return str;
    }
    else {
      strCut = str.substr(0, 1);
    strArrSplit.shift();
  str = strArrSplit.join('') + strCut + 'ay';
      // Else the first letter is not a vowel, but the second is. So one letter is shifted.
    return str;
  }
  }
}

translatePigLatin("glove");
`
Blauelf
@Blauelf
Jul 25 2017 12:52
@Masd925 JSFuck has more [].
kumquatfelafel
@kumquatfelafel
Jul 25 2017 12:53
@Masd925 Okay, so I am officially in love with JSFuck. It is just so clean and straightforward.
Blauelf
@Blauelf
Jul 25 2017 12:53
@MichielHuijse Your second for loop does not work, as you always return on the first iteration. What is the result for "three"?
@kumquatfelafel There are katas on codewars where one is restricted to a subset of characters like in JSFuck. Is fun, as is programming AVRs (e.g. Arduino) in assembler.
Michiel
@MichielHuijse
Jul 25 2017 12:55
@Blauelf the return is inside an if statement.
Blauelf
@Blauelf
Jul 25 2017 12:56
The else has a return, too. So no way to not return on first iteration.
Michiel
@MichielHuijse
Jul 25 2017 12:56
@Blauelf ok, so perhaps I should move it one block 'up'
it = the else statment
Blauelf
@Blauelf
Jul 25 2017 12:58
@MichielHuijse There are multiple logic errors, I think. And if you used substring, substr, or slice twice, you would not have to shift.
Does the second letter not being "a" tell you anything about the third one? Does it tell you the second one is not a vowel at all?
Brandon Achu
@bachu-dev
Jul 25 2017 12:59
any1 here used cloud9.io for react development?
Michiel
@MichielHuijse
Jul 25 2017 13:00
@Blauelf thanks
kumquatfelafel
@kumquatfelafel
Jul 25 2017 13:00

@MichielHuijse What if the consonant cluster is three or four letters long? What if it's ten letters long?

strait, for example, should become aitstray
i.e. what @Blauelf said

Long Nguyen
@longnt80
Jul 25 2017 13:01
hey guys, I ran into this issue when doing the Simon Game. Don't know how to describe it, so here's the pen: https://codepen.io/longnt80/pen/ZJYLvX
basically, I want the -- to change to some text and they will have a css animation. But when the text appear, it doesn't blink
Blauelf
@Blauelf
Jul 25 2017 13:02
@MichielHuijse Your outer loop should go over the characters of str/strArrSplit (allowing for any number of consonants), and the then-inner loop over the vowel array could be replaced by indexOf, like if (vowelArr.indexOf(str[0]) !== -1) { return str + 'way'; }
Michiel
@MichielHuijse
Jul 25 2017 13:02
@kumquatfelafel thats true it only checks for two consonants
kumquatfelafel
@kumquatfelafel
Jul 25 2017 13:03
@longnt80 Do you mean you want "Big Ass Text" to blink?
Long Nguyen
@longnt80
Jul 25 2017 13:03
@kumquatfelafel yes
Ghulam Shabir
@ghulamshabir
Jul 25 2017 13:04
@MichielHuijse try to learn little about regex, it will make your life easier
Long Nguyen
@longnt80
Jul 25 2017 13:05
@kumquatfelafel if I add a delay to add the class blink to Big Ass Text then it will work. Like this: https://codepen.io/longnt80/pen/VzYPqJ
Michiel
@MichielHuijse
Jul 25 2017 13:07
@Blauelf @kumquatfelafel @ghulamshabir thanks
CamperBot
@camperbot
Jul 25 2017 13:07
michielhuijse sends brownie points to @blauelf and @kumquatfelafel and @ghulamshabir :sparkles: :thumbsup: :sparkles:
:cookie: 535 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:star2: 1926 | @ghulamshabir |http://www.freecodecamp.com/ghulamshabir
:star2: 4533 | @blauelf |http://www.freecodecamp.com/blauelf
kumquatfelafel
@kumquatfelafel
Jul 25 2017 13:24
@longnt80 so... at least on my firefox, neither one seems to work.
Long Nguyen
@longnt80
Jul 25 2017 13:25
@kumquatfelafel oh, it only work on Chrome then
kumquatfelafel
@kumquatfelafel
Jul 25 2017 13:25
not necessarily.
But i feel like you and my version of firefox must have some kind of bad history. :p
Did you get into a fight in the past?
Long Nguyen
@longnt80
Jul 25 2017 13:26
@kumquatfelafel I just checked my Firefox, it works for the second example (with the delay)
kumquatfelafel
@kumquatfelafel
Jul 25 2017 13:28
@longnt80 so, checking on my end, works on chrome and safari, but not firefox.
Don't feel like testing on internet explorer. :p
Long Nguyen
@longnt80
Jul 25 2017 13:29
@kumquatfelafel you need to ditch your firefox
:smile:
kumquatfelafel
@kumquatfelafel
Jul 25 2017 13:29
oh wait. Suddenly started working on the firefox as well. :laughing:
Guess it was just trying to make a point?
Long Nguyen
@longnt80
Jul 25 2017 13:30
@kumquatfelafel lol
kumquatfelafel
@kumquatfelafel
Jul 25 2017 13:30
(for the second example)
Long Nguyen
@longnt80
Jul 25 2017 13:30
how to avoid adding the delay?
I was thinking of using callback, but not sure how to implement it
Darth Skywalker
@AdiSkywalker
Jul 25 2017 13:31
Don't add the delay? @longnt80 :laughing:
Long Nguyen
@longnt80
Jul 25 2017 13:32
@AdiSkywalker but the text won't blink
kumquatfelafel
@kumquatfelafel
Jul 25 2017 13:32
@longnt80 get rid of delay in both
Long Nguyen
@longnt80
Jul 25 2017 13:32
@kumquatfelafel and?
Darth Skywalker
@AdiSkywalker
Jul 25 2017 13:33

@longnt80 I was just making a joke on this line :laughing:

how to avoid adding the delay?

kumquatfelafel
@kumquatfelafel
Jul 25 2017 13:33
onclick and other
Long Nguyen
@longnt80
Jul 25 2017 13:33
which delay though? I was talking about the 100 milliseconds one
one example has it, one doesn't
Darth Skywalker
@AdiSkywalker
Jul 25 2017 13:34
Callback sounds like what I could do well.. Can I help here?
Long Nguyen
@longnt80
Jul 25 2017 13:34
@AdiSkywalker sure
Darth Skywalker
@AdiSkywalker
Jul 25 2017 13:34
I don't know what problem you guys are facing though
kumquatfelafel
@kumquatfelafel
Jul 25 2017 13:35
$('button').on('click',function(){
      text.text('--').addClass('blink');
      setTimeout(function() {
         text.removeClass('blink');
         changeText();
      },0);
   });
setTimeout(function(){
      text.addClass('blink');
      setTimeout(function() {
         text.removeClass('blink');
      },1000);
   },0);
Note that when have like this, Ass blinks fine, but -- blink no longer works properly
(this was what I meant before)
Long Nguyen
@longnt80
Jul 25 2017 13:36

@AdiSkywalker

I ran into this issue when doing the Simon Game. Don't know how to describe it, so here's the pen: https://codepen.io/longnt80/pen/ZJYLvX
basically, I want the -- to change to some text and they will have a css animation. But when the text appear, it doesn't blink
if I add a delay to add the class blink to Big Ass Text then it will work. Like this: https://codepen.io/longnt80/pen/VzYPqJ

@kumquatfelafel let me see
Darth Skywalker
@AdiSkywalker
Jul 25 2017 13:36
I see.. Let me check
@longnt80
Stuhl
@Stuhl
Jul 25 2017 13:37
Hey guys, can someone explain what a lexial environment/scoping is ?
As I understood it means where a variable or functions was created and thus the this will refer to
kumquatfelafel
@kumquatfelafel
Jul 25 2017 13:38
Essentially, it looks like you need the delays. Otherwise, blink will be added/removed before animation complete
Long Nguyen
@longnt80
Jul 25 2017 13:40
@kumquatfelafel but I need the text to change after 1 second, that's why I have the delay when button clicked
Darth Skywalker
@AdiSkywalker
Jul 25 2017 13:40
@longnt80 Why not do just this?
$('button').on('click',function(){
  text.text('--').addClass('blink');
  changeText();
  /*setTimeout(function() {
     text.removeClass('blink');
     changeText();
  },1000);*/
});
Long Nguyen
@longnt80
Jul 25 2017 13:43
@AdiSkywalker still need to change from -- to some text after 1 second, hence the setTimeout
Darth Skywalker
@AdiSkywalker
Jul 25 2017 13:43

@longnt80 I think I got what you're trying to do... See if this is how you want it

First update your div.blink CSS definition to

div.blink {
   animation: blink 1s infinite;
}

Note the infinite part

Then in your JS

function changeText() {
  text.text('Big Ass Text');
  setTimeout(function(){
     text.removeClass('blink');
  },3000);
}

$('button').on('click',function(){
  text.text('--').addClass('blink');
  setTimeout(function() {
     changeText();
  },1000);
});
The 3000 ms delay (in changeText )is just added to test the animation. You can revert it back to 1000 as you deem fit
Long Nguyen
@longnt80
Jul 25 2017 13:46
@AdiSkywalker yeah without the infinite, it won't work though
I already tried the infinite
the thing is that's not the effect I want
so we have to go without adding infinite
Darth Skywalker
@AdiSkywalker
Jul 25 2017 13:47
@longnt80 I see... but in your .blink the animation is set to run for 1s
so in your click callback, you can reduce the delay to 500
something that is less than the duration of the animation
Long Nguyen
@longnt80
Jul 25 2017 13:48
you mean change the text before the animation ends?
Darth Skywalker
@AdiSkywalker
Jul 25 2017 13:49
Yeah
shivam gupta
@shivamg11000
Jul 25 2017 13:54
xhr is not working correctly
kumquatfelafel
@kumquatfelafel
Jul 25 2017 13:56
Long Nguyen
@longnt80
Jul 25 2017 13:56
@AdiSkywalker ok, I tried to remove the blink class before changing the text. It's still the same principle as my working example though: add some delay. But this could be good alternative for me: https://codepen.io/longnt80/pen/YxPZjG
Stanley Su
@stanley-su
Jul 25 2017 13:56
@shivamg11000 Working for me, I got the data logged in console
Long Nguyen
@longnt80
Jul 25 2017 13:57
@kumquatfelafel @AdiSkywalker btw, thanks guys
CamperBot
@camperbot
Jul 25 2017 13:57
longnt80 sends brownie points to @kumquatfelafel and @adiskywalker :sparkles: :thumbsup: :sparkles:
:cookie: 234 | @adiskywalker |http://www.freecodecamp.com/adiskywalker
:cookie: 536 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Stanley Su
@stanley-su
Jul 25 2017 13:57
@shivamg11000 takes like 10 seconds though
Long Nguyen
@longnt80
Jul 25 2017 13:59
@kumquatfelafel @AdiSkywalker
anyway, here's my Simon game: https://longnt80.github.io/Simon-Game/
might not work on @kumquatfelafel 's Firefox though
kumquatfelafel
@kumquatfelafel
Jul 25 2017 14:00
nah. works on firefox fine. not safari
(but safari version pretty outdated)
Long Nguyen
@longnt80
Jul 25 2017 14:01
@kumquatfelafel I think you need to update everything on your computer
Stephen James
@sjames1958gm
Jul 25 2017 14:02
@shivamg11000 That API is taking > 4.5 seconds to respond
kumquatfelafel
@kumquatfelafel
Jul 25 2017 14:02
one question though. When you wait a long time without doing anything, and get that jarring tone, that's just to tell you "keep going", or was something else planned here?
Michiel
@MichielHuijse
Jul 25 2017 14:03
Well here is an enhancement! Works with every number of consonants in the beginning. Feedback welcome again.

function translatePigLatin(str) {

  var vowelArr = ["a", "e", "i", "o", "u"];
  var strArrSplit = str.split('');
  var strCut ='';
  var strSliced ='';
  var y = 0;

  if (vowelArr.indexOf(str[0]) !== -1) { 
      return str + 'way'; 
    }
        // If one of the elements of the vowelArr is the same as the first item of the strSplit. The first letter is a vowel.

  for (var i=0; i < strArrSplit.length; i++) {
      if (vowelArr.indexOf(str[i]) === -1) {
          y++;
          }
         else {
          strCut = str.substr(0, y);
          strSliced = str.slice(y); // slices the last 
          str = strSliced + strCut + 'ay';
    return str;
     }
}

}


translatePigLatin("glove");
kumquatfelafel
@kumquatfelafel
Jul 25 2017 14:03
ah... so that's relating to strict. gotcha
Long Nguyen
@longnt80
Jul 25 2017 14:03
@kumquatfelafel that's the time limit, you cannot have too much time to think
@kumquatfelafel I never actually play the real Simon game so I might got the rule wrong
Stephen James
@sjames1958gm
Jul 25 2017 14:04
@MichielHuijse I used regex for not-vowels at start and used match to get length of consantants
kumquatfelafel
@kumquatfelafel
Jul 25 2017 14:05

@longnt80 there's a time limit on strict anyway. Time limit for normal just resets timer and replays sequence it seems.

so I might got the rule wrong

Heck if I know. :p

Stephen James
@sjames1958gm
Jul 25 2017 14:05
@MichielHuijse var prefix = str.match(/^[^aeiou]*/); prefix.length will tell you number of consonants
Michiel
@MichielHuijse
Jul 25 2017 14:06
@sjames1958gm aah ok, thanks that makes it even shorter.
CamperBot
@camperbot
Jul 25 2017 14:06
michielhuijse sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8154 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Wisdom Peters
@blackcytographer
Jul 25 2017 14:13
pls can someone pls help me with this code i want it to return hello world or hello there when called., there is the code function sayHello (name) {
if(name === "wisdom"){
return "hello " + name;
}
else {
return "Hello there";
}
}
sayHello(wisdom)
Stephen James
@sjames1958gm
Jul 25 2017 14:13
@MichielHuijse :+1:
@blackcytographer why "wisdom" and not "world"?
@blackcytographer sayHello(wisdom) this is passing a variable, not a string.
Wisdom Peters
@blackcytographer
Jul 25 2017 14:14
@MichielHuijse pls is the code ok
i try but it is not running
kumquatfelafel
@kumquatfelafel
Jul 25 2017 14:15
The code doesn't make sense (I share @sjames1958gm concerns)
Stephen James
@sjames1958gm
Jul 25 2017 14:15
@blackcytographer How is it not running? Do you have a variable called wisdom?
Maybe sayHello("wisdom");
Wisdom Peters
@blackcytographer
Jul 25 2017 14:16
@sjames1958gm it is not returning hello world,...... please any better way?
Stephen James
@sjames1958gm
Jul 25 2017 14:16
@blackcytographer
if(name === "world"){
Guderian Raborg
@hypercuber
Jul 25 2017 14:16
How do I remove front digit of a number like change 125 to 25?
kumquatfelafel
@kumquatfelafel
Jul 25 2017 14:17
@blackcytographer Just to clarify, when exactly do you want it to return hello world and when do you want it to return hello there. Do you want it to return hello world when name is "world"?
Stephen James
@sjames1958gm
Jul 25 2017 14:18

@hypercuber

var x = 125;
+((x + "").slice(1));

Convert to string, slice all but first, convert back to number

Long Nguyen
@longnt80
Jul 25 2017 14:20
@sjames1958gm what about toString compared to x + ""?
Darth Skywalker
@AdiSkywalker
Jul 25 2017 14:22
@longnt80 Same thing, I'd assume
Guderian Raborg
@hypercuber
Jul 25 2017 14:22
@sjames1958gm Thanks. I was wondering if there was a way without turning to string but it works
var x = 125;
x = Number(x.toString().slice(1));
console.log(x);
CamperBot
@camperbot
Jul 25 2017 14:22
hypercuber sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8155 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 25 2017 14:22
@longnt80 6 of one or 1/2 of a dozen of another
Darth Skywalker
@AdiSkywalker
Jul 25 2017 14:24
You can also get first digit by doing
var x = 125;
var firstDigit = parseInt(x/100); // 1
or even var firstDigit = Math.floor(x/100);
kumquatfelafel
@kumquatfelafel
Jul 25 2017 14:26
this works , but only if x is 3 digit number.
Darth Skywalker
@AdiSkywalker
Jul 25 2017 14:27
You can always run a while loop that starts with divide by 10
and do it till the quotient is 0
Wisdom Peters
@blackcytographer
Jul 25 2017 14:30
@kumquatfelafel thanks sir i want the code to return hello world when the fuction is called or hello there when not
CamperBot
@camperbot
Jul 25 2017 14:30
blackcytographer sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 537 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Abhilash Kumar
@apravink
Jul 25 2017 14:34
Hi. So I was going to create the Pomodoro clock and I was wondering if I could bounce my ideas off someone here
Ken Haduch
@khaduch
Jul 25 2017 14:38
@apravink - bounce away, someone will comment
Abhilash Kumar
@apravink
Jul 25 2017 14:38
@khaduch sweet!
So I've been tinkering with React lately and I'm thinking of using it to build two main components that I'm going to render -- One for the form which takes the user input for(such as time) and the other for the clock itself
What I'm a little unsure about is if whether its a good idea to use ReactDOM.render multiple times within the same application?. Or is it a better idea to only use it once and make the form and clock sub-components of a larger component?
Darth Skywalker
@AdiSkywalker
Jul 25 2017 14:41
@kumquatfelafel
function getEachDigit(dividend){
  var divisor = 1;
  var numbers = [];
  var quotient = dividend;
  while(quotient > 10){
    divisor *= 10;
    quotient = parseInt(dividend / divisor);
  }

  while(divisor > 1){
    var digit = parseInt(dividend / divisor);
    numbers.push(digit);
    dividend %= divisor;
    divisor = parseInt(divisor/10);
  }
  numbers.push(dividend);

  return numbers;

}

getEachDigit(123);  // [1,2,3]
Ken Haduch
@khaduch
Jul 25 2017 14:48
@apravink -I don't know the answer to that - I'm not well versed in React at this point. I'm sure that someone here will have a helpful suggestion. Just googling that question comes up with this: https://stackoverflow.com/questions/31302803/is-it-ok-to-use-react-render-multiple-times-in-the-dom on StackOverflow.com - I hope that helps somewhat, and perhaps someone with more React experience can confirm or provide other information.
Abhilash Kumar
@apravink
Jul 25 2017 14:52
Yeah I've been reading into that thread too..I guess my concern is more from a "Does it make sense and is it not overkill" perspective than a "Does it work" perspective lol. I see a lot of tutorials on how to use the different functionalities of x-framework but very few that show you how to architect a full application using x-framework
Appreciate the help though @khaduch :)
kumquatfelafel
@kumquatfelafel
Jul 25 2017 14:54
@AdiSkywalker what you have is a bit wordy.
This will suffice if want to use parseInt.
var numbers = [];
var num = 4134; //hypothetically
while (num > 0) {
  numbers.unshift(num % 10);
  num = parseInt(num/10);
}
Kelechi Chinaka
@ke1echi
Jul 25 2017 14:56
@blackcytographer u should invoke the function with a string
zealsham
@zealsham
Jul 25 2017 14:57
how do i implement role based acess control using nodejs and express
Blauelf
@Blauelf
Jul 25 2017 14:58
@kumquatfelafel I prefer not implicitly converting to string and explicitly back to number:
var numbers = [];
var num = 4134; //hypothetically
while (num > 0) {
  numbers.unshift(num % 10);
  num -= numbers[0];
  num /= 10;
}
kumquatfelafel
@kumquatfelafel
Jul 25 2017 14:59
@Blauelf along those lines. ;)
Simon Cordova
@gbsimon87
Jul 25 2017 15:08
Hey guys, I was hoping to seek an answer in vanilla JS if possible...
I'm trying to find out if more than one element has the class "checked"...
var allRegionLabels = document.querySelectorAll("#destination-region-container label");

allRegionLabels.forEach(function(element) {

var amountChecked;
//     console.log(element);

    if ( element.classList.contains("checked") ) {
            console.log(element);
        }

});
Jason Luboff
@JLuboff
Jul 25 2017 15:11
@gbsimon87 Only ever showing up now when you need help with work eh? ;)
Wisdom Peters
@blackcytographer
Jul 25 2017 15:11
@kelechy thanks
CamperBot
@camperbot
Jul 25 2017 15:11
blackcytographer sends brownie points to @kelechy :sparkles: :thumbsup: :sparkles:
:warning: @kelechy's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
Simon Cordova
@gbsimon87
Jul 25 2017 15:11
Hmm...I wouldn't say so, but that sucks that's the outloojk
outlook**
I was online I think yesterday or two days ago for a while just to help out :)
Jason Luboff
@JLuboff
Jul 25 2017 15:11
@gbsimon87 Don't take me serious, I'm just messing with you
Its all in good fun :D
Simon Cordova
@gbsimon87
Jul 25 2017 15:12
I know I feel you, but I do love helping out, gotta give back to the community can't just take
Jason Luboff
@JLuboff
Jul 25 2017 15:12
Ya, how is the job? Treating you well?
Simon Cordova
@gbsimon87
Jul 25 2017 15:12
lol, trust me, first thing I did when I got my first programming job was came on here and thanked a number of people, some of which are online right now
Yeah, it's going rather well so far, but so challenging at times
Stephen James
@sjames1958gm
Jul 25 2017 15:12
@gbsimon87 That code looks like the right structure, is it not working? Are you not comfortable with it?
Simon Cordova
@gbsimon87
Jul 25 2017 15:13
Lately I'm trying to only code in vanilla JS to get some practice, but man jQuery makes things easier
@sjames1958gm that code is working but I need an if condition that checks whether the amount of elements returned is bigger than 1
Jason Luboff
@JLuboff
Jul 25 2017 15:13
@gbsimon87 I still need to start using Vanilla...I'm just so comfortable with jQuery that I keep putting it off :worried:
@gbsimon87 Make a counter?
Simon Cordova
@gbsimon87
Jul 25 2017 15:14
@JLuboff tbh doing it with vanilla is tougher but has given me different insight into javascript
Jason Luboff
@JLuboff
Jul 25 2017 15:14
Instead of the console.log, do count++ or whatever then check that number after the loop
Stephen James
@sjames1958gm
Jul 25 2017 15:14
@gbsimon87 You'd need to have a variable outside the loop set to 0 and incremented inside the loop.
Simon Cordova
@gbsimon87
Jul 25 2017 15:15
So you guys are saying have the counter add up and then check it against my condition once the foreach has done running

I'll try that out! :)

thanks @sjames1958gm and @JLuboff

CamperBot
@camperbot
Jul 25 2017 15:15
gbsimon87 sends brownie points to @sjames1958gm and @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2096 | @jluboff |http://www.freecodecamp.com/jluboff
:star2: 8156 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Simon Cordova
@gbsimon87
Jul 25 2017 15:15
How are things going for you guys?
Jason Luboff
@JLuboff
Jul 25 2017 15:16
Eh. Alright. I could complain, but no one wants to hear that :D
Simon Cordova
@gbsimon87
Jul 25 2017 15:17
complain == null
sounds like a good formula for a whine and cheese party lol
Jason Luboff
@JLuboff
Jul 25 2017 15:17
Lol
But nah, things are doing alright. Staying busy at work, staying busy at home ( little one on the way), learning as much as I can when I can
kumquatfelafel
@kumquatfelafel
Jul 25 2017 15:18

i want the code to return hello world when the fuction is called or hello there when not

@blackcytographer It is possible to modify the behavior of a function by calling/passing a different function, but I'm 99% certain this isn't what you mean.

These are function calls :point_down:

doSomething();
takeANap(20);
sayHello("World");

Inside the parentheses are "arguments", which are values that get passed to the function.

Here are functions. :point_down:

function doSomething() {
  console.log("Doing something.");
}
function takeANap(min) {
  console.log("Napping for " + min + " minutes.");
}
function sayHello(name) {
  console.log("Hello, to the whole wide " + name);
}

This is the resulting console output, in order, from calling the functions :point_down:
Doing something.
Napping for 20 minutes.
Hello, to the whole wide World

Jason Luboff
@JLuboff
Jul 25 2017 15:19
@kumquatfelafel Actually...the last one would be Hello, to the whole wide World
;)
Darth Skywalker
@AdiSkywalker
Jul 25 2017 15:20
@kumquatfelafel Oh wow! That's pretty sweet.. :+1:
kumquatfelafel
@kumquatfelafel
Jul 25 2017 15:20
@JLuboff I also forgot the . in Doing something.
I should be ashamed! :o
Jason Luboff
@JLuboff
Jul 25 2017 15:20
I'm so disappointed in you right now
Simon Cordova
@gbsimon87
Jul 25 2017 15:21
By the way guys the counter worked :) @JLuboff @sjames1958gm
Jason Luboff
@JLuboff
Jul 25 2017 15:21
@gbsimon87 :+1:
@gbsimon87 Just out of curiosity... Are you a formula 1 fan? I know they had that live event a few weeks ago prior to Silverstone GP, just wondering if you attended
Simon Cordova
@gbsimon87
Jul 25 2017 15:26
Man I've never followed that sport but it's certainly interesting
kumquatfelafel
@kumquatfelafel
Jul 25 2017 15:26
@blackcytographer in your case, it sounds like you want it to maybe output "Hello world" if some condition is met based upon the argument that has been passed into function. To do this, you'd need an if statement, like you have in code you posted earlier.
function sayHello(name) {
  if (name == "Christopher") { //for example, you can change this of course.
    console.log("Hello world"); //using console.log here, but if you wanted to return string, you could do that too.
  } else {
    console.log("Hello there");
  }
}
sayHello("marzipan"); //outputs "Hello there"
sayHello("Christopher"); //outputs "Hello world"
limbu
@limbu
Jul 25 2017 15:26
hi guys i need help with javascript code
can anyone help me?
Darth Skywalker
@AdiSkywalker
Jul 25 2017 15:26
@limbu Shoot
limbu
@limbu
Jul 25 2017 15:27
ok so here's the html
<div class="archiveSearchFacetContainer" data-toggle="archiveSearchDateFacetToggle" data-content="archiveSearchDateFacetContent">
<div class="archiveSearchFacetTitleContainer">
<h2 class="archiveSearchFacetTitle">Date the archives were created</h2>
<div class="archiveSearchFacetContainerToggle"></div>
</div>
<div class="archiveSearchFacetContentContainer">
<div class="archiveSearchFacet">
<label class="archiveSearchFacetLabel">Date after:</label>
<input class="archiveSearchFacetInput" placeholder="dd/mm/yyyy" type="text" />
</div>
<div class="archiveSearchFacet">
<label class="archiveSearchFacetLabel">Date before:</label>
<input class="archiveSearchFacetInput" placeholder="dd/mm/yyyy" type="text" />
</div>
</div>
</div>
i want to be able to add a class to the .archiveSearchFacetContentContainer

define(['jquery'], function archiveSearchFacets($) {
$('.archiveSearchFacetContainerToggle').on('click', function archiveSearchFacetToggle() {
var archiveSearchFacet = $(this).next('.archiveSearchFacetContentContainer');
var subItemContainerOpenClass = 'archiveSubItemContainerOpen';
var subItemContainerIsOpen = archiveSearchFacet.hasClass(subItemContainerOpenClass);

    if (subItemContainerIsOpen) {
        archiveSearchFacet.removeClass(subItemContainerOpenClass);
    } else {
        archiveSearchFacet.addClass(subItemContainerOpenClass);
    }
});

});

here's my js
Jason Luboff
@JLuboff
Jul 25 2017 15:27
@gbsimon87 Ah. It looked like the event was pretty cool. All the drivers (except for Hamilton) were there, driving F1 cars (not this years cars, but still) along the streets of London
Wisdom Peters
@blackcytographer
Jul 25 2017 15:28
@kumquatfelafel thanks
CamperBot
@camperbot
Jul 25 2017 15:28
blackcytographer sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:warning: blackcytographer already gave kumquatfelafel points
Simon Cordova
@gbsimon87
Jul 25 2017 15:28

Hmmm...

hamilton is a fan favourite out here

limbu
@limbu
Jul 25 2017 15:28
i have a feeling i have got the var archiveSearchFacet = $(this).next('.archiveSearchFacetContentContainer'); line wrong
Jason Luboff
@JLuboff
Jul 25 2017 15:28
Yup... people weren't too happy that he didn't show up
limbu
@limbu
Jul 25 2017 15:29
should it be var archiveSearchFacet = $(this).closest('.archiveSearchFacetContentContainer');???
any ideas @AdiSkywalker
????
Wisdom Peters
@blackcytographer
Jul 25 2017 15:29
@kumquatfelafel you are the best 1 luv from nigeria
Stephen James
@sjames1958gm
Jul 25 2017 15:29
@gbsimon87 You could of course use reduce
Here is code that counts the number of p tags with the text of "Two"
[].reduce.call(document.querySelectorAll("p"), (a, e) => 
               e.innerText === "Two" ? a + 1 : a, 0);
limbu
@limbu
Jul 25 2017 15:29
any help would be much appreciated?
kumquatfelafel
@kumquatfelafel
Jul 25 2017 15:31
@Hello911 In that case, you're really just passing the function reference and it is only called when the button is clicked.
Hello911
@Hello911
Jul 25 2017 15:31
function getValue(){
getCoords();
}
I dont get why there are different ways to call a JS function. When do you use parenthese? Ex. element.addEventListener('click', getValue) getValue is a function you have already defined above. But notice how inside getValue function you called getCoords() with PARENTHESES.
Simon Cordova
@gbsimon87
Jul 25 2017 15:31
@sjames1958gm The only thing with that is that es6 isn't supported by IE, plus I don't yet know the reduce function well, but cheers, I'll take a look into it
@sjames1958gm yeah I'm more of a basketball fan than anything, Toronto Raptors all day :)
Hello911
@Hello911
Jul 25 2017 15:32
@kumquatfelafel I finished my question see above
Darth Skywalker
@AdiSkywalker
Jul 25 2017 15:32
@limbu Yes. .closest
Stephen James
@sjames1958gm
Jul 25 2017 15:32
@gbsimon87 well the es6 can be converted to regular functions - Map, Filter, Reduce - are your friends...
kumquatfelafel
@kumquatfelafel
Jul 25 2017 15:32
@Hello911 the thing is, if you had element.addEventListener('click', getValue()) it would call the function getValue immediately, not when button is clicked
limbu
@limbu
Jul 25 2017 15:32
@AdiSkywalker that's not working though
Darth Skywalker
@AdiSkywalker
Jul 25 2017 15:33
@limbu do you have code pen.
This code is very unclear to figureout what is going wrong
Stephen James
@sjames1958gm
Jul 25 2017 15:33
@Hello911 You only call a function with parens. getValue this is a function reference you are passing to addEventListener which is called later
Darth Skywalker
@AdiSkywalker
Jul 25 2017 15:34
@Hello911 element.addEventListener('click', getValue) means, when click event happens on element you should call getValue function.
So you just need to pass function reference that you want to be called when click event happens
kumquatfelafel
@kumquatfelafel
Jul 25 2017 15:37

:point_up:

This is actually possible.

var blah = getValue;
blah(); //calls getValue
blah(); //calls getValue
blah(); //calls getValue

Same idea with your thing, except here we're not passing function reference into a function.

Darth Skywalker
@AdiSkywalker
Jul 25 2017 15:40
or if your getValue returns reference to another function, you can call it in addEventListener

function actualClickEventHandler(){
}

function clickEventHandler(){
  return actualClickEventHandler;
}

element.addEventListener('click', clickEventHandler())
limbu
@limbu
Jul 25 2017 15:41
@AdiSkywalker here you go mate
i want the facetcontentcontainer div to have a red background when i click on the archiveSearchFacetContainerToggle div
does that make sense
?
Darth Skywalker
@AdiSkywalker
Jul 25 2017 15:47
@limbu yeah.. it's clear now
so.. the way you've structured your markup, the closest and next won't work
limbu
@limbu
Jul 25 2017 15:47
what am i doing wrong?
what do i need to use to traverse the sibling ?
Darth Skywalker
@AdiSkywalker
Jul 25 2017 15:47
you need to go to parent of your checkbox and query from there
Like this
var archiveSearchFacet = $(this).parent().next('.archiveSearchFacetContentContainer');
and in your pen you're targeting archiveSearchFacetContainer
which should be archiveSearchFacetContentContainer
limbu
@limbu
Jul 25 2017 15:49
@AdiSkywalker you're a legend thank you mate
CamperBot
@camperbot
Jul 25 2017 15:49
limbu sends brownie points to @adiskywalker :sparkles: :thumbsup: :sparkles:
:cookie: 235 | @adiskywalker |http://www.freecodecamp.com/adiskywalker
limbu
@limbu
Jul 25 2017 15:49
@AdiSkywalker i thought it was a traversal issue
@AdiSkywalker but would have never had figured that out without your help
Darth Skywalker
@AdiSkywalker
Jul 25 2017 15:50
You were thinking in right direction.. You just misunderstood how those jQuery methods work
@limbu :+1:
limbu
@limbu
Jul 25 2017 15:50
@AdiSkywalker thanks adi you are a guru
CamperBot
@camperbot
Jul 25 2017 15:50
limbu sends brownie points to @adiskywalker :sparkles: :thumbsup: :sparkles:
:warning: limbu already gave adiskywalker points
Darth Skywalker
@AdiSkywalker
Jul 25 2017 15:51
aww
You're welcome
Hello911
@Hello911
Jul 25 2017 16:16
function actualClickEventHandler(){
}

function clickEventHandler(){
  return actualClickEventHandler;
}

element.addEventListener('click', clickEventHandler())
So here you can use parenthese because the final function actualClickEventHandler() you are calling is called using 'return' and not parenthese.?
@AdiSkywalker
Traek Wells
@TraekWells
Jul 25 2017 16:18
Can anyone help me? I can’t figure out why I’m getting a null response.
function adjacentElementsProduct(inputArray) {
    let largestProduct = 0;
    let currentProduct = 0;
    for (let i = 0; i < inputArray.length; i++) {
        currentProduct = inputArray[i] * (inputArray[i + 1]);
        if (currentProduct > largestProduct) {
            largestProduct = currentProduct;
            currentProduct = 0;
        }
    }
}
I’m getting null even after I run: adjacentElementsProduct([3, 6, -2, -5, 7, 3]);
Michiel
@MichielHuijse
Jul 25 2017 16:22
@TraekWells current product might be undefined, since you are using let instead of var to declare it.
Jason Luboff
@JLuboff
Jul 25 2017 16:23
@TraekWells Where do you get null? I don't see you return or console.log anything?
Michiel
@MichielHuijse
Jul 25 2017 16:23
In this example I don't see the purpose of using 'let' instead of 'var'.
Stuhl
@Stuhl
Jul 25 2017 16:24
@MichielHuijse There is no real purpose, let is the new var
Jason Luboff
@JLuboff
Jul 25 2017 16:25
Ya, no real disadvantage for using let. We also don't know how this scopes overall, he may have several additional functions, variables, etc
Stuhl
@Stuhl
Jul 25 2017 16:27
afaik, everything is kept in the block and the let i = 0 is not being hoisted outside to the global scope like it would be done with var
Traek Wells
@TraekWells
Jul 25 2017 16:28

Thanks for the responses @JLuboff and @MichielHuijse . Of course I didn’t include a return statement.

function adjacentElementsProduct(inputArray) {
    let largestProduct = 0;
    let currentProduct = 0;
    for (let i = 0; i < inputArray.length; i++) {
        currentProduct = inputArray[i] * (inputArray[i] + 1);
        if (currentProduct > largestProduct) {
            largestProduct = currentProduct;
            currentProduct = 0;
        }
    }
    return largestProduct;
}

it’s updated. Still wrong but at least I’m getting a number returned

CamperBot
@camperbot
Jul 25 2017 16:28
traekwells sends brownie points to @jluboff and @michielhuijse :sparkles: :thumbsup: :sparkles:
:cookie: 289 | @michielhuijse |http://www.freecodecamp.com/michielhuijse
:star2: 2097 | @jluboff |http://www.freecodecamp.com/jluboff
Traek Wells
@TraekWells
Jul 25 2017 16:28
I dont have anything else in the file. just this.
Jason Luboff
@JLuboff
Jul 25 2017 16:28
@TraekWells Whats the expected output?
Traek Wells
@TraekWells
Jul 25 2017 16:29
@JLuboff 21 since [3, 6, -2, -5, 7, 3] is the input
István Kozma
@Manfred28
Jul 25 2017 16:30
inputArray[i] + 1
this is no longer looking at the adjacent element, if thats what you mean to do here
since you changed it from inputArray[i + 1] I suppose thats what you are trying to do, but in that snippet I think you went outside the index range
Traek Wells
@TraekWells
Jul 25 2017 16:31
@Manfred28 thanks. I just noticed that.
CamperBot
@camperbot
Jul 25 2017 16:31
traekwells sends brownie points to @manfred28 :sparkles: :thumbsup: :sparkles:
:cookie: 168 | @manfred28 |http://www.freecodecamp.com/manfred28
Christopher McCormack
@cmccormack
Jul 25 2017 16:51
:wave:
EpicTriffid
@EpicTriffid
Jul 25 2017 16:52
Hey all. So my twitch feed is almost done, and I can push new requests to the usernames array and update the table to show the results. However, everytime i do, it pulls up a duplicate of the last entered search. Is there anyway to refresh the element, but not allow a repeat of the entry? https://codepen.io/EpicTriffid/pen/rwEmgQ
If you add a couple new channels, you'll see what i mean
Jason Luboff
@JLuboff
Jul 25 2017 16:54
@cmccormack Yo
Christopher McCormack
@cmccormack
Jul 25 2017 16:54
@EpicTriffid probably just want to clear the element you're displaying those items within before you display the entire list, or add each new item as a single entry
EpicTriffid
@EpicTriffid
Jul 25 2017 16:55
@cmccormack How would i add as a single entry each time?
Christopher McCormack
@cmccormack
Jul 25 2017 16:55
maybe instead of doing a forEach just add a single item at a time, this way you're not making lots of unnecessary api calls each time you add a user
Jason Luboff
@JLuboff
Jul 25 2017 16:56
@EpicTriffid Just FYI...your empty well is confusing from an UI perspective. I thought that was an input field and couldn't figure out why I couldn't click it to type in.
Christopher McCormack
@cmccormack
Jul 25 2017 16:56
@JLuboff agreed
Jason Luboff
@JLuboff
Jul 25 2017 16:57
@cmccormack Got my Phishing page setup :+1:
Christopher McCormack
@cmccormack
Jul 25 2017 16:57
shared it yet?
Jason Luboff
@JLuboff
Jul 25 2017 16:57
@cmccormack With my group, yes, otherwise, no. We still need to draft an email, etc
dyon3334
@dyon3334
Jul 25 2017 16:59
javascript question: When and why use the "this" method ?
Christopher McCormack
@cmccormack
Jul 25 2017 16:59
Sooner the better!
EpicTriffid
@EpicTriffid
Jul 25 2017 16:59
@cmccormack @JLuboff Thankyou guys! Very helpful!
CamperBot
@camperbot
Jul 25 2017 16:59
epictriffid sends brownie points to @cmccormack and @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2098 | @jluboff |http://www.freecodecamp.com/jluboff
:star2: 1048 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Jul 25 2017 17:00
@EpicTriffid np! You're site looks great, btw. Simple and elegant
Jason Luboff
@JLuboff
Jul 25 2017 17:03
@cmccormack I DM'd you my page if you want to check it out
Christopher McCormack
@cmccormack
Jul 25 2017 17:04
that looks great!
did you also make an e-mail only version - like ask them to reply to an e-mail with their username/password/credit card/etc..
Jason Luboff
@JLuboff
Jul 25 2017 17:06
@cmccormack Nope, haven't done that. We'll see how far they want to go with it
@cmccormack Btw...all I had to do was copy the source code from the office 365 login page and make a few minor adjustments, like moving the sign in button inside the form and then make my backend which was easy
Christopher McCormack
@cmccormack
Jul 25 2017 17:09
yeah it looks great, you can see all the look and feel stuff
Jason Luboff
@JLuboff
Jul 25 2017 17:09
@cmccormack Thanks
CamperBot
@camperbot
Jul 25 2017 17:09
jluboff sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1049 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Jul 25 2017 17:10
now you need to get your company to register something like rnicrosoft.com :D
Jason Luboff
@JLuboff
Jul 25 2017 17:11
That'd be very sneaky
Christopher McCormack
@cmccormack
Jul 25 2017 17:11
yessir!
and you still need harsh punishments for offenders - it needs to be top of their mind for every e-mail they see
Jason Luboff
@JLuboff
Jul 25 2017 17:12
Well I told you we were going to publicly shame them ala Cersai from GoT, didn't I? :joy:
Michiel
@MichielHuijse
Jul 25 2017 17:13
What is wrong with this:
 var pairArr = [];
pairArr = pairArr.push('T');
Jason Luboff
@JLuboff
Jul 25 2017 17:13
@MichielHuijse You're re-assigning the value of pairArr from an array to a number
@MichielHuijse Don't use pairArr = on the second line
Michiel
@MichielHuijse
Jul 25 2017 17:14
Aah ok, thanks @JLuboff
CamperBot
@camperbot
Jul 25 2017 17:14
michielhuijse sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2099 | @jluboff |http://www.freecodecamp.com/jluboff
Jason Luboff
@JLuboff
Jul 25 2017 17:18
@EpicTriffid :+1: UI is much better
EpicTriffid
@EpicTriffid
Jul 25 2017 17:28
Does anyone know why the url to twitch doesnt work?
Christopher McCormack
@cmccormack
Jul 25 2017 17:40
@EpicTriffid which url?
when you click a link and go to Twitch, where it doesn't load the full page?
Stephen James
@sjames1958gm
Jul 25 2017 17:50
@EpicTriffid refresh wipes out any added channels?
Joel Y.
@zapcannon99
Jul 25 2017 17:53
@EpicTriffid I want to know as well. All I can tell is that in chrome and firefox flag it is flagged as insecure, but I don't know why.
Christopher McCormack
@cmccormack
Jul 25 2017 17:54
@zapcannon99 which url
Hemakshi Sachdev
@hemakshis
Jul 25 2017 17:56
function translatePigLatin(str) {
  var i = 0;
  while(str[i] !== 'a' || str[i] !== 'e' || str[i] !== 'i' || str[i] !== 'o' || str[i] !== 'u' && i < str.length) {
    i++;
  }
  var ans = str.substr(i);
  return ans;
  //return str;
}

translatePigLatin("aaaa");
why does it says that there is a potential infinite loop at line 5??
I really don't get this
Stephen James
@sjames1958gm
Jul 25 2017 18:00
@hemakshis Because your && is only associated with the last !==
(str[i] !== 'a' || str[i] !== 'e' || str[i] !== 'i' || str[i] !== 'o' || str[i] !== 'u') && i < str.length
@sjames1958gm Also. The first part is going to be true for all letters.
str[i] !== 'a' || str[i] !== 'e' this is true of every letter even 'a' or 'e' because 'a' is not 'e' and 'e' is not 'a', and the rest are neither
RakeshNerkar
@Rakesh18754
Jul 25 2017 18:03
var a = add(2)(3); //5
is this syntax possible?
if yes ...using closure or curry?
Stephen James
@sjames1958gm
Jul 25 2017 18:03
@Rakesh18754 Yes it is using curry.
@Rakesh18754 add(2) this returns a function (3) calls that returned function
Marco Galizzi
@Tezenn
Jul 25 2017 18:04
stuck in the pairwise challenge, anyone else is doing that one?
EpicTriffid
@EpicTriffid
Jul 25 2017 18:04
@cmccormack the url taken from the twitch api?
RakeshNerkar
@Rakesh18754
Jul 25 2017 18:04
@sjames1958gm so closure is not the right way to do it is it?
EpicTriffid
@EpicTriffid
Jul 25 2017 18:04
I've seen it happen on other twitch viewers as well?
Stephen James
@sjames1958gm
Jul 25 2017 18:05
@Rakesh18754 Closure is part of it as well as the curried function is closing over the parameter 2
RakeshNerkar
@Rakesh18754
Jul 25 2017 18:05
ok @sjames1958gm
Hemakshi Sachdev
@hemakshis
Jul 25 2017 18:06
@sjames1958gm okay i got what you said.. thanks :)
CamperBot
@camperbot
Jul 25 2017 18:06
hemakshis sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8157 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Alexander Køpke
@alexanderkopke
Jul 25 2017 18:07
This message was deleted
Stephen James
@sjames1958gm
Jul 25 2017 18:07
@hemakshis :+1:
RakeshNerkar
@Rakesh18754
Jul 25 2017 18:08
@sjames1958gm can u specify any specific use case of curry?
when to use curry
dyon3334
@dyon3334
Jul 25 2017 18:08
javascript :done with codecamp whats next? any suggestion for video tutorials ?
Alexander Køpke
@alexanderkopke
Jul 25 2017 18:09
maybe but first.. did you get closure on your yesterday question on ternaries vs if vs switch?
Jason Luboff
@JLuboff
Jul 25 2017 18:09
I like to use my curry with seafood or chicken. Tastes great! :P
Stephen James
@sjames1958gm
Jul 25 2017 18:10
@Rakesh18754 If you are using React with es6 classes then you use currying when you bind this to the class functions.
EpicTriffid
@EpicTriffid
Jul 25 2017 18:19
@zapcannon99 the reason the twitch url isn't working is because its trying to load the page from within codepens iframe, which twitch doesn't like. If you view your pen in debug mode, the url will work correctly
Joel Y.
@zapcannon99
Jul 25 2017 18:23
@cmccormack Any hyperlink to the twitch streamers on chrome or firefox
@EpicTriffid Yeah. That's what I've read. But then what are people going to see when they view the codepen. Full or debug?
@EpicTriffid @cmccormack Thanks for the info.
CamperBot
@camperbot
Jul 25 2017 18:28
zapcannon99 sends brownie points to @epictriffid and @cmccormack :sparkles: :thumbsup: :sparkles:
:cookie: 268 | @epictriffid |http://www.freecodecamp.com/epictriffid
:star2: 1050 | @cmccormack |http://www.freecodecamp.com/cmccormack
Jan Shah
@JanShah
Jul 25 2017 18:28
if I want to use cancelAnimationFrame, how do I do it?
current code:
  window.requestAnimationFrame(this.tick);
Moisés Man
@moigithub
Jul 25 2017 18:29

https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame

Return value
A long integer value, the request id, that uniquely identifies the entry in the callback list. This is a non-zero value, but you may not make any other assumptions about its value. You can pass this value to window.cancelAnimationFrame() to cancel the refresh callback request.

Jan Shah
@JanShah
Jul 25 2017 18:32
@moigithub sorry bro, I've struggled with it. it looks like I have to name it first, requestAnimationFrame is working ok, just can't get rid of it when I want to
monkeyfingerz
@monkeyfingerz
Jul 25 2017 18:33
function steamrollArray(arr) {
  // I'm a steamroller, baby
for(var i = 0; i< arr.length ; i++){
  return arr[i].replace(/[/|/]/,"");
}
}
steamrollArray([1, [2], [3, [[4]]]]);
Why isn't replace working on the provided array?
Christopher McCormack
@cmccormack
Jul 25 2017 18:33
@monkeyfingerz arr isn't a string
Ghulam Shabir
@ghulamshabir
Jul 25 2017 18:34
@monkeyfingerz replace is a string method and arr[i] returns a number
Jan Shah
@JanShah
Jul 25 2017 18:34
@monkeyfingerz your regex is good for matching slashes
monkeyfingerz
@monkeyfingerz
Jul 25 2017 18:34
except i need to add a g
Ok thanks everyone
@CentropyIT
Jan Shah
@JanShah
Jul 25 2017 18:34
@monkeyfingerz no you don't
Christopher McCormack
@cmccormack
Jul 25 2017 18:35
you need to rethink your solution
Jan Shah
@JanShah
Jul 25 2017 18:35
nononono, you're going about it the wrong way @monkeyfingerz
monkeyfingerz
@monkeyfingerz
Jul 25 2017 18:35
shooooot ok ill look at it again. Just started this challenge
Moisés Man
@moigithub
Jul 25 2017 18:35
return exit the function immediatelly @monkeyfingerz
placing inside a loop like urs.. will make ur loop iterate only once
monkeyfingerz
@monkeyfingerz
Jul 25 2017 18:35
thanks @CentropyIT @ghulamshabir @cmccormack
CamperBot
@camperbot
Jul 25 2017 18:35
monkeyfingerz sends brownie points to @centropyit and @ghulamshabir and @cmccormack :sparkles: :thumbsup: :sparkles:
:warning: @centropyit's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
:star2: 1051 | @cmccormack |http://www.freecodecamp.com/cmccormack
:star2: 1927 | @ghulamshabir |http://www.freecodecamp.com/ghulamshabir
Christopher McCormack
@cmccormack
Jul 25 2017 18:36
@monkeyfingerz take advantage of the Array.isArray method
monkeyfingerz
@monkeyfingerz
Jul 25 2017 18:36
i don't understand how that will help me yet @cmccormack
Christopher McCormack
@cmccormack
Jul 25 2017 18:37
@monkeyfingerz reread the exercise, check the examples
monkeyfingerz
@monkeyfingerz
Jul 25 2017 18:37
ok thanks
ill be back with something later. until then bye!
Christopher McCormack
@cmccormack
Jul 25 2017 18:37
good luck!
monkeyfingerz
@monkeyfingerz
Jul 25 2017 18:38
@CentropyIT why wouldn't i need a g i mean if it was a string?
Jan Shah
@JanShah
Jul 25 2017 18:39
@monkeyfingerz it's an array
you don't need replace or match or any regex
Stephen James
@sjames1958gm
Jul 25 2017 18:44
@monkeyfingerz You would also need \] not /] if it were a string.
Hemakshi Sachdev
@hemakshis
Jul 25 2017 19:10

var newArr = [];
function steamrollArray(arr) {
  // I'm a steamroller, baby

  for(var i = 0; i < arr.length; i++) {
    if(Array.isArray(arr[i]) === true)
      steamrollArray(arr[i]);
    else newArr.push(arr[i]);
  }
  return newArr;
}

steamrollArray([1, [], [3, [[4]]]]);
it is giving correct ans on the result console of FCC.. but still they are not passing the cases
Why??
Jason Luboff
@JLuboff
Jul 25 2017 19:12
@hemakshis Try moving var newArr = []; inside your function
Hemakshi Sachdev
@hemakshis
Jul 25 2017 19:13
@JLuboff Nope. Not working. Now, I'm getting a wrong ans also
Joel Y.
@zapcannon99
Jul 25 2017 19:18
@hemakshis newArr should be in the function. There's no reason to have it outside.