These are chat archives for FreeCodeCamp/HelpJavaScript

2nd
Jul 2017
jorlee92
@jorlee92
Jul 02 2017 00:01
@sjames1958gm If I am having a hard time wrapping my head around this should I just review algebra?
Or is it just that I should always adjust by one?
Because for some reason I need to use paper for this, and it feels bad
onejo578
@onejo578
Jul 02 2017 00:12
function lookUpProfile(firstName, prop){
// Only change code below this line
if (contacts.hasOwnProperty())//Unsure what to code here
  //(contacts.hasOwnProperty(firstName, prop) && contacts.hasOwnProperty(prop))    ---->failed attempt
{
  return contacts[prop];
}
"The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.
If both are true, then return the "value" of that property."
Can someone help me out here please?
^^apologies, I didn't check the "hints" first. I'll repost if I need help!
Diego Mayer
@Chrono79
Jul 02 2017 00:19
@onejo578 start with using a loop, contacts is an array
aRtoo
@artoodeeto
Jul 02 2017 00:22
guys. need help can you check wheres is the real temp in this api? http://api.openweathermap.org/data/2.5/weather?lat=33.7887586&lon=-117.8836668&APPID=8bc4ea333a5f2b734509a80ef5ce88d6 because on my phone its different. on the json file theres a temp which is 200++ but and a clouds object: all: 75. i tried converting the 200 plus to far and cel its didnt come close to my phone weather
Manish Giri
@Manish-Giri
Jul 02 2017 00:23
this is the temp
"main": {
    "temp": 297.04,
    "pressure": 1011,
    "humidity": 77,
    "temp_min": 292.15,
    "temp_max": 305.15
  },
if you want to avoid conversion, add a units param to the URL and specify the type you want
like I get this when I specify imperial
  "main": {
    "temp": 75,
    "pressure": 1011,
    "humidity": 77,
    "temp_min": 66.2,
    "temp_max": 89.6
  },
@artoodeeto
Ellyria
@Ellyria
Jul 02 2017 00:26
Does anybody know what it means when you run some of your own code and it works fine and there's no error in the console log, but the Firefox tab has a spinning circle icon on it that just continues to spin endlessly?
Diego Mayer
@Chrono79
Jul 02 2017 00:26
@Manish-Giri 297.04 is the temp in Kelvin, imperial is in Fahrenheit
Manish Giri
@Manish-Giri
Jul 02 2017 00:26
probably an infinite loop
@Ellyria
aRtoo
@artoodeeto
Jul 02 2017 00:26
@Manish-Giri thanks bro. let me test
Manish Giri
@Manish-Giri
Jul 02 2017 00:26
@Chrono79 obviously, it can't be in Celsius or F, can it?
CamperBot
@camperbot
Jul 02 2017 00:26
artoodeeto sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6167 | @manish-giri |http://www.freecodecamp.com/manish-giri
Diego Mayer
@Chrono79
Jul 02 2017 00:27
@Manish-Giri sorry, I wanted to mention @artoodeeto instead
Ellyria
@Ellyria
Jul 02 2017 00:27
Oh, that would really be a drag. I've been on this for weeks and finally figured it out, and it would be awful if I came this close and had to start over. Thanks for the hint, @Manish-Giri. I'll see if I can spot something.
CamperBot
@camperbot
Jul 02 2017 00:27
ellyria sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6168 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Jul 02 2017 00:27
@Ellyria good luck
@Chrono79 np
Ellyria
@Ellyria
Jul 02 2017 00:28
Thanks. I have a feeling I'll need it, @Manish-Giri. I'm gonna have grey hair before I finish this project. One question, though. Shouldn't an infinite loop throw an error in the console log?
CamperBot
@camperbot
Jul 02 2017 00:28
ellyria sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:warning: ellyria already gave manish-giri points
Manish Giri
@Manish-Giri
Jul 02 2017 00:29
@Ellyria not really, some code editors do show a warning if there's a chance of an infinite loop, but that's in the editor itself..
I don't think you'll get an error in the console in case of an inf loop..
Ellyria
@Ellyria
Jul 02 2017 00:30
Okay. Well, darn. I've got to sort this out. So close to done with this!
Manish Giri
@Manish-Giri
Jul 02 2017 00:30
lol
hang in there!
Ellyria
@Ellyria
Jul 02 2017 00:31
Hanging! But my arms are getting mighty long!
Fixed it. Weehaw! Thank you, @Manish-Giri! Now I have to go hunting through my collection of JavaScript snippets because I remember seeing the spinning icon before, so I'll want to go find any scripts that do this and fix them, too.
CamperBot
@camperbot
Jul 02 2017 00:36
ellyria sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:warning: ellyria already gave manish-giri points
Manish Giri
@Manish-Giri
Jul 02 2017 00:37
@Ellyria welcome! Happy fixing!
Ellyria
@Ellyria
Jul 02 2017 00:37
Definitely, @Manish-Giri! Finally a good coding day for me after several not so good ones!
aRtoo
@artoodeeto
Jul 02 2017 00:37
@Manish-Giri thanks bro i just need to include metric or imperial on my url. thnaks
CamperBot
@camperbot
Jul 02 2017 00:37
artoodeeto sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:warning: artoodeeto already gave manish-giri points
Manish Giri
@Manish-Giri
Jul 02 2017 00:38
:+1:
ISU
@isu17
Jul 02 2017 00:43
jQuery anyone ?
<script type="text/javascript">
  $(document).ready(function(){
    $('a[data-text]').each(function(){
      $(this).attr('data-text', "This works!");
    });
});

</script>

 <a href="http://twitter.com/share" class="twitter-share-button" data-text="This is what we want to change dynamically" data-count="none" data-via="">Tweet</a>
I cant make this work, "This works!" never shows
Moisés Man
@moigithub
Jul 02 2017 00:44
right click ... inspect element
ISU
@isu17
Jul 02 2017 00:47
well, now it just shows the default text that is hard coded into the html, It seems like I am missing the way to link the function to the html correctly
Moisés Man
@moigithub
Jul 02 2017 00:47
u changin data-* attributes they dont shows on screen
ISU
@isu17
Jul 02 2017 00:50
I get to the share page, but instead of "This works" it shows "This is what we want to dynamically change" that is inside data-text
Moisés Man
@moigithub
Jul 02 2017 00:52
if u right click on ur link.. and inspect element u will see this after run ur code
<a href="http://twitter.com/share" target="_blank" class="twitter-share-button" data-text="This works!"....
Long Nguyen
@longnt80
Jul 02 2017 00:55
anyone knows how to make the sound effect when click and hold the mouse button, and the sound keep going continuously like this
https://codepen.io/Em-Ant/full/QbRyqq/
ISU
@isu17
Jul 02 2017 00:58
@moigithub thanks for the help, but I guess I am too tired now going to sleep
CamperBot
@camperbot
Jul 02 2017 00:58
isu17 sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3458 | @moigithub |http://www.freecodecamp.com/moigithub
Adam Faraj
@adamfaraj
Jul 02 2017 01:07
const button = document.getElementsByClassName('delete');
console.log(button);

button.addEventListener('click', function(){
  console.log('clicked');
})
why do i get this: Uncaught TypeError: button.addEventListener is not a function
Netrunner21
@Netrunner21
Jul 02 2017 01:12
Just popping in here. I'm reading a JS book, and it recommends to almost never use ==, but === (and other strict operators). I've used both, but I'm curious if I've used == more because I'm wirtting sloppy code. Thoughts?
Netrunner21
@Netrunner21
Jul 02 2017 01:18
I'm hoping these chat rooms don't depopulate due to the help link being removed
Ellyria
@Ellyria
Jul 02 2017 01:18
Both are good, @Netrunner21. It depends on what you want to accomplish. == is a less strict comparison, so it will accept "1" == 1 since it doesn't care that one is a string and the other a number. === on the other hand will only accept 1 === 1 or "1" === "1". So it all depends on what you want your code to do or not do or accept or not accept.
Frank McCroy
@fmccroy
Jul 02 2017 01:18
@Netrunner21 What book are you reading? How do you like it so far? and I don’t know about best practices, but can imagine needing to compare values without them being strictly the same type (==).
Ellyria
@Ellyria
Jul 02 2017 01:19
They will. I think that was badly handled, but this isn't the place for that discussion. I mentioned it in the Contributors channel.
Talking about books, I'm reading "You Don't Know JS" and loving it.
Manish Giri
@Manish-Giri
Jul 02 2017 01:21
I need to get a hard copy of YDKJS
I always slack off with online stuff
Frank McCroy
@fmccroy
Jul 02 2017 01:22
I am reading Eloquent Javascript and find it very confusing, but hope it gets better.
YDKJS sounds like it is not a beginner level book
Netrunner21
@Netrunner21
Jul 02 2017 01:23
@Ellyria @fmccroy Thanks for the input. I am reading Eloquent JavaScript.
CamperBot
@camperbot
Jul 02 2017 01:23
netrunner21 sends brownie points to @ellyria and @fmccroy :sparkles: :thumbsup: :sparkles:
:cookie: 485 | @ellyria |http://www.freecodecamp.com/ellyria
:cookie: 366 | @fmccroy |http://www.freecodecamp.com/fmccroy
Netrunner21
@Netrunner21
Jul 02 2017 01:24
@fmccroy I read parts of it a year ago and also found it confusing. Reading it now makes a lot more sense because the contexts make sense after having done many of FCC's projects
Ellyria
@Ellyria
Jul 02 2017 01:24
I'll have to check that out at some point. Thanks!
Stephen James
@sjames1958gm
Jul 02 2017 01:24
@adamfaraj button is likely a collection which you may not be able to call addEventListener on
Netrunner21
@Netrunner21
Jul 02 2017 01:25
I'll have to check out YDKJS as well
Ellyria
@Ellyria
Jul 02 2017 01:25
It's not, @fmccroy, but I'm only considered intermediate in JavaScript, and I'm understanding what he says. It's also really well written. A pure joy to read. And he teaches you some incredibly interesting stuff.
Netrunner21
@Netrunner21
Jul 02 2017 01:26
The first ten pages of Eloquent JavaScript really filled in a ton of holes for me, even after doing almost all of FCC's front end projects (have the simon game left, looks really fun programmingwise)
I'm hoping YDKJS will do the same for me
I also have PROFESSIONAL JAVASCRIPT® FOR WEB DEVELOPERS, but I'm gonna wait until I'm more advanced before I read it.
Ellyria
@Ellyria
Jul 02 2017 01:27
Yeah, I like using a lot of resources so I can learn from a more rounded perspective.
Netrunner21
@Netrunner21
Jul 02 2017 01:28
Yeah for sure
Frank McCroy
@fmccroy
Jul 02 2017 01:29
Are there some nice beginner level JS books? Or other places to learn from that are considered really good?
Netrunner21
@Netrunner21
Jul 02 2017 01:29
There are other sources for sure. Many people do CodeAcademy's free JS course alongside this one.
Ellyria
@Ellyria
Jul 02 2017 01:30
I'm learning at almost all of those.
Netrunner21
@Netrunner21
Jul 02 2017 01:31
Someone else (Joseph I think) dumped a big list of sources here earlier, I made sure to bookmark it. I'll have a look at yours too.
Frank McCroy
@fmccroy
Jul 02 2017 01:34
@Ellyria Cool, thanks! I like looking things up on W3Schools, their examples tend to go better with what FCC, compared to MDN. I bought The Complete Web Developer Course 2.0 on Udemy, but need the patience to sit and watch the videos
CamperBot
@camperbot
Jul 02 2017 01:34
fmccroy sends brownie points to @ellyria :sparkles: :thumbsup: :sparkles:
:cookie: 486 | @ellyria |http://www.freecodecamp.com/ellyria
Ellyria
@Ellyria
Jul 02 2017 01:35
Yeah, I listed some pay stuff in that Gist, but I only do the free ones. I've heard good things about Udemy, though, so I think you'll like it.
Frank McCroy
@fmccroy
Jul 02 2017 01:37
@moigithub Hmm.. I went to that link and the first course that comes up when I search for “Javascript” is “Understanding Dementia”. Are they trying to tell me something ? :)
Moisés Man
@moigithub
Jul 02 2017 01:39
:sweat_smile: :stuck_out_tongue_closed_eyes:
Ednor
@ednor
Jul 02 2017 01:50
Hello guys! How is everything ?
Ellyria
@Ellyria
Jul 02 2017 01:51
Hey there, @ednor.
Ednor
@ednor
Jul 02 2017 01:54
I am asking for help tonight
Using Objects for Lookups challenge (JS)
Frank McCroy
@fmccroy
Jul 02 2017 01:55
Sorry, fresh out of that. :)
What are you having a problem with? Do you have any code yet?
Ednor
@ednor
Jul 02 2017 01:56
yes, here is the Instructions
Convert the switch statement into a lookup table called lookup. Use it to lookup val and assign the associated string to the result variable.
my code

// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
  var lookup = {
    "alpha": "Adams",
    "bravo": "Boston",
    "charlie": "Chicago",
    "delta": "Denver",
    "echo": "Easy",
    "foxtrot": "Frank"
  };



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

// Change this value to test
phoneticLookup("charlie");
now, I ask myself how to process the 2nd step of the instructions: Use it to lookup val and assign the associated string to the result variable.
Ellyria
@Ellyria
Jul 02 2017 01:58
Thanks for those links, @moigithub. I added Gymnasium to my list of code schools.
CamperBot
@camperbot
Jul 02 2017 01:58
ellyria sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3459 | @moigithub |http://www.freecodecamp.com/moigithub
Manish Giri
@Manish-Giri
Jul 02 2017 01:58
this will help
Ednor
@ednor
Jul 02 2017 01:58
in the previews challenges, there has been any functions, that one made me confused completely
Moisés Man
@moigithub
Jul 02 2017 02:00
Accessing Objects Properties with the Dot Operator
Accessing Objects Properties with Bracket Notation
Accessing Objects Properties with Variables :point_left:
Manish Giri
@Manish-Giri
Jul 02 2017 02:00
you also did challenges on FCC prior to this one
how to access object property values
its the same thing here
Ednor
@ednor
Jul 02 2017 02:00
exact !
@moigithub, I am thinking about it, should I create new variables ?
you also did challenges on FCC prior to this one
Yes, I did
Moisés Man
@moigithub
Jul 02 2017 02:02
u have 1 variable.. lookup (which is an object)
and val parameter .. function phoneticLookup(val) {
similar to "variables" this contain the "key" property
sooo......... when u call the function ie: phoneticLookup("charlie");
inside ur function when u use val it will refer to this value :point_up:
Ednor
@ednor
Jul 02 2017 02:04
okay !
let me try once again please, I will get back to you
M-C-Haker
@M-C-Haker
Jul 02 2017 02:11
Having trouble with the casetype algorithm... anyone have any suggestions?
Moisés Man
@moigithub
Jul 02 2017 02:14
any1 know any FREE hosting similar to heroku
wanna upload/deploy a test app :)
Ellyria
@Ellyria
Jul 02 2017 02:19
What does heroku offer?
Manish Giri
@Manish-Giri
Jul 02 2017 02:20
@moigithub glitch
Ellyria
@Ellyria
Jul 02 2017 02:20
Googled it. CodePen?
Moisés Man
@moigithub
Jul 02 2017 02:21
to deploy a MERN stack webapp @Ellyria
codepen is client side only.. no node.js support
Joseph
@revisualize
Jul 02 2017 02:42
hi.
Frank McCroy
@fmccroy
Jul 02 2017 02:43
Good evening!
Nick Janne
@njanne19
Jul 02 2017 02:45
Is there anyway in react if I call a component to render, that I can render that component to somewhere else than the ReactDOM.render I have at the bottom of the page
Manish Giri
@Manish-Giri
Jul 02 2017 02:49
that I can render that component to somewhere else
where else?
a component can render child components, if that's what you're asking
class App extends React.Component {
  render() {
         return (
              <NavBar />
               <SearchBar />
               <Main />
        )
   }
}
ReactDOM.render(<App />, ...)
Nick Janne
@njanne19
Jul 02 2017 02:55
@Manish-Giri sorry I don't think I was specific enough. I'm using a component that I've rendered in a div with ReactDOM.render(<MyComponent />, document.getElementById('#id')); but What I'm trying to do now is use a button to trigger a rendering of a different component In a div with a different ID
Amit Patel
@AmitP88
Jul 02 2017 03:01

hey guys, I need some help with the Diff Two Arrays algorithm. My strategy to solve this was to merge both arrays and filter out the duplicate pairs and return the filtered array. However, I've only managed to filter out the duplicate items, but not the item pairs. I can't seem to figure it out:
function diffArray(arr1, arr2) {
var newArr = [];
// Same, same; but different.

// Merged both arrays together into one (arr3);
var arr3 = arr1.concat(arr2);

// Filtered arr3 of duplicate items in merged array
var filteredArr = arr3.filter(function(item, pos, self) {
return self.indexOf(item) == pos;
});

return filteredArr;

}

diffArray([1, 2, 3, 5], [1, 2, 3, 4, 5]);

Moisés Man
@moigithub
Jul 02 2017 03:05
most of the times u only need to render 1 MAIN APPlication component
and this component "holds" other parts of ur app
soo u only need to use ReactDOM.render 1 time
its NOT common to render multiple times @njanne19
Frank McCroy
@fmccroy
Jul 02 2017 03:05
@AmitP88 Do you need a loop in there to go through everything?
Amit Patel
@AmitP88
Jul 02 2017 03:06
@fmccroy that's what I'm thinking about
Shannon (Cent) Myers
@shannon189
Jul 02 2017 03:07
Hey all, I am having trouble with the "Find the longest word in a string challenge." I am getting "TypeError: Cannot read property 'length' of undefined." My code is here : function findLongestWord(str) {
var arr = str.split(' ');
var longWord = 0;
for(var i = 0; i < arr.length; i++) {
if (arr[(i +1)].length > arr[i].length) {
longWord = arr[(i + 1)].length;
} else {
continue;
}
}
return longWord;
}
Moisés Man
@moigithub
Jul 02 2017 03:08
indexOf returns the first index of the matching element... ie
["hello", "bye", "hello"].indexOf("hello") <-- it will return 0 (the first element index)
@AmitP88
soo one way to know that "hello" is duplicated.. is find the second hello (u can use lastIndexOf)
["hello", "bye", "hello"].lastIndexOf("hello") <-- it will return 2 (the last element index)
then u can compare 0 !== 2.. then u have "hello" duplicated
Marcus Parsons
@marcusparsons
Jul 02 2017 03:09
@shannon189, your if statement is going out of bounds on the lines:
if (arr[(i +1)].length > arr[i].length) {
longWord = arr[(i + 1)].length;
Amit Patel
@AmitP88
Jul 02 2017 03:09
@moigithub actually, someone suggested to just use two filter functions for each array then merge at the end. but thanks for the tip :)
CamperBot
@camperbot
Jul 02 2017 03:09
amitp88 sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3460 | @moigithub |http://www.freecodecamp.com/moigithub
shivam gupta
@shivamg11000
Jul 02 2017 03:10
can anybody explain me this
(function(){
   console.log('Hello');
})();
Shannon (Cent) Myers
@shannon189
Jul 02 2017 03:10
@marcusparsons Ah, I see now, thanks
CamperBot
@camperbot
Jul 02 2017 03:10
shannon189 sends brownie points to @marcusparsons :sparkles: :thumbsup: :sparkles:
:cookie: 426 | @marcusparsons |http://www.freecodecamp.com/marcusparsons
Marcus Parsons
@marcusparsons
Jul 02 2017 03:11
@shivamg11000, that's a self executing function. Everything declared inside that function only has scope to that function. i.e.
(function() {
var a = 0;
})();
//a is undefined outside of the function
console.log(a);
Nick Janne
@njanne19
Jul 02 2017 03:11
@moigithub ok but that's what I'm looking to do. My project looks like this http://prntscr.com/fql2vi and the render target I have for the main application is the well that says "Recipes", and so now I'm trying to push something to the well that says "Shopping list"
Ogundele Olumide
@Lumexralph
Jul 02 2017 03:12
@shivamg11000 it's called IIFE Immediately Invoked Function Expression, it's a function that's executed immediately as the program is parsed ,
shivam gupta
@shivamg11000
Jul 02 2017 03:12
@marcusparsons so that would give error
Moisés Man
@moigithub
Jul 02 2017 03:13
not error.. but return undefined...
a declaration is "encapsulated/issolated" inside the IIFE.. so its not available outside
it only "lives" while the function is "active"
Marcus Parsons
@marcusparsons
Jul 02 2017 03:13
@shivamg11000, it will return an error because it's not defined. a is only defined within that function and not to the window.
shivam gupta
@shivamg11000
Jul 02 2017 03:13
@moigithub the ( ) encapsulates the block
Ogundele Olumide
@Lumexralph
Jul 02 2017 03:14
@shivamg11000 the function did
pramod goyal
@nightraven112
Jul 02 2017 03:33
hi guyz
i need a bit of healp
function isLess(a, b) {
// Fix this code
return a === b;
}
// Change these values to test
isLess(10, 15);
it is not returning true
origina lcode

function isLess(a, b) {
// Fix this code
if (a < b) {
return true;
} else {
return false;
}
}

// Change these values to test
isLess(10, 15);

i am suppose to use
===
Ogundele Olumide
@Lumexralph
Jul 02 2017 03:34
@nightraven112 if you return a < b; that'll give a boolean
pramod goyal
@nightraven112
Jul 02 2017 03:34
no if and else
@Lumexralph kay i will try and tell ya
Dan Stockham
@DanStockham
Jul 02 2017 03:35
@nightraven112 Right return a < b
You're returning an expression that either is either true or false.
pramod goyal
@nightraven112
Jul 02 2017 03:36
@Lumexralph than @DanStockham thank you guyz
CamperBot
@camperbot
Jul 02 2017 03:36
nightraven112 sends brownie points to @lumexralph and @danstockham :sparkles: :thumbsup: :sparkles:
:cookie: 557 | @danstockham |http://www.freecodecamp.com/danstockham
:star2: 2012 | @lumexralph |http://www.freecodecamp.com/lumexralph
pramod goyal
@nightraven112
Jul 02 2017 03:36
it worked
Dan Stockham
@DanStockham
Jul 02 2017 03:36
@nightraven112 You're welcome :) However I would like to ask what you have learned from that?
pramod goyal
@nightraven112
Jul 02 2017 03:37
@DanStockham well i learnt how to compare it woitout using if and else
helps shorten the code riht
*right?
Dan Stockham
@DanStockham
Jul 02 2017 03:38
@nightraven112 Correct, however anytime you use comparison operators, expect a Boolean back.
@nightraven112 You did good :)
pramod goyal
@nightraven112
Jul 02 2017 03:38
@DanStockham couldnt have without ur help guyz thanks again
CamperBot
@camperbot
Jul 02 2017 03:38
nightraven112 sends brownie points to @danstockham :sparkles: :thumbsup: :sparkles:
:warning: nightraven112 already gave danstockham points
shivam gupta
@shivamg11000
Jul 02 2017 03:44
what is meant by hoisting
Ogundele Olumide
@Lumexralph
Jul 02 2017 03:45
@shivamg11000 when a value is moved to the top of the scope of the environment it exists
@shivamg11000 e.g a function, variable, no matter where you declared them they're moved to the top of the scope they exist but let doesn't follow that though
Ellyria
@Ellyria
Jul 02 2017 03:48
This is a really good page for hoisting, @shivamg11000: https://www.w3schools.com/js/js_hoisting.asp
It demonstrates it.
shivam gupta
@shivamg11000
Jul 02 2017 03:51

@Lumexralph that means

function lol1(){
  function lol2(){
     console.log('lol');
   }
}

lol2();

this should work as lol1() should move to the top

srry lol2()
Ogundele Olumide
@Lumexralph
Jul 02 2017 03:52
@shivamg11000 lol1 and lol2 both exist in different scopes
shivam gupta
@shivamg11000
Jul 02 2017 03:54
but you said function no matter where they are declared they will move to the top of the scope
@Lumexralph
Ogundele Olumide
@Lumexralph
Jul 02 2017 03:54
@shivamg11000 lol1 is in the global scope, while lol2 is in the local scope of lol1 both will be moved to the top of the scope of their environment, calling lol2 will give you a Reference Error cos it can't be found

@shivamg11000

function lol1(){
  function lol2(){
     console.log('lol');
   }
   lol2();
}

lol1();

This will work because they're both used in the scope they exist

shivam gupta
@shivamg11000
Jul 02 2017 03:56
@Lumexralph that means hoisting and scope is different
Ogundele Olumide
@Lumexralph
Jul 02 2017 03:57
@shivamg11000 yes, but hoisting is done in relation to scope
shivam gupta
@shivamg11000
Jul 02 2017 03:57
very consufing is js
learning ECMA 6
Ogundele Olumide
@Lumexralph
Jul 02 2017 03:58
@shivamg11000 look at this
lol1();

function lol1(){
  lol2();
  function lol2(){
     console.log('lol');
   }

}
Dan Stockham
@DanStockham
Jul 02 2017 03:59
@shivamg11000 Don't worry it gets better :)
@Lumexralph I look but I fail to compute the issue.
shivam gupta
@shivamg11000
Jul 02 2017 03:59

why would this work

lol();
function lol(){
    console.log('lol');
}

unlike in other languages

as the fucntion is defined after calling
Dan Stockham
@DanStockham
Jul 02 2017 04:00
@shivamg11000 Because functions are implemented first before executing the code in JavaScript.
Ogundele Olumide
@Lumexralph
Jul 02 2017 04:00
@shivamg11000 when the program is being executed, it can call those function that way because the functions were hoisted/ moved to the top of the scope during parsing phase
Dan Stockham
@DanStockham
Jul 02 2017 04:00
@shivamg11000 Though, it's bad practice to write code like that.
@Lumexralph In a way yes, however not entirely true.
shivam gupta
@shivamg11000
Jul 02 2017 04:01
@Lumexralph but both the call and function has same scope ie, both are global
Ogundele Olumide
@Lumexralph
Jul 02 2017 04:02
@shivamg11000 it is the way JS engine interprets the code
@shivamg11000 no, they're not
@shivamg11000 function creates a scope in JS
shivam gupta
@shivamg11000
Jul 02 2017 04:03
with IIFE we can stop function hoisting
?
Dan Stockham
@DanStockham
Jul 02 2017 04:04
@Lumexralph Right, functions create scope but it isn't hoisted to the top of the code upon interpretation of the browser
shivam gupta
@shivamg11000
Jul 02 2017 04:05
@DanStockham what does that mean
Ogundele Olumide
@Lumexralph
Jul 02 2017 04:05
@DanStockham it's still same thing in different context, not that functions are implemented first, it just the phases the JS engine uses to implement the code, looks for declarations and expressions, all those happen in lexical scoping phase
@DanStockham did I say top of the code? I said scope
Dan Stockham
@DanStockham
Jul 02 2017 04:06
@shivamg11000 when the program is being executed, it can call those function that way because the functions were hoisted/ moved to the top of the scope during parsing phase
Ogundele Olumide
@Lumexralph
Jul 02 2017 04:06
@shivamg11000 because it's an expression and not a declaration
@DanStockham how is that top of the code?
Dan Stockham
@DanStockham
Jul 02 2017 04:07
@Lumexralph No, when the code is interpreted, the function scope is created first, then the code is executed. Nothing is being hoisted.
M-C-Haker
@M-C-Haker
Jul 02 2017 04:08
How can i make console.log appear on fcc?
Dan Stockham
@DanStockham
Jul 02 2017 04:08
@Lumexralph You're to say in context it does, but that's not happens in technically. As far as I read.
shivam gupta
@shivamg11000
Jul 02 2017 04:08
Now both you are confusing yourself and me also
Ogundele Olumide
@Lumexralph
Jul 02 2017 04:08

@shivamg11000

function a () {

}

is different from  

var a = function() {

}

the way JS engine parses them is different

shivam gupta
@shivamg11000
Jul 02 2017 04:09
@Lumexralph first one is declaration and second one is expression
Dan Stockham
@DanStockham
Jul 02 2017 04:09
@M-C-Haker It should appear in your console within your developer tools
M-C-Haker
@M-C-Haker
Jul 02 2017 04:10
I was looking for it a bit ago but couldnt find it. Using chrome where in the developer tools does it show up?
Ogundele Olumide
@Lumexralph
Jul 02 2017 04:10
@DanStockham are you aware of the phases during the code interpretation?
Dan Stockham
@DanStockham
Jul 02 2017 04:11
@Lumexralph I like to think so.
Ogundele Olumide
@Lumexralph
Jul 02 2017 04:11
@M-C-Haker you can use https://repl.it/languages/JavaScript
Dan Stockham
@DanStockham
Jul 02 2017 04:11
@M-C-Haker There should be a console tab if you're using chrome tools.
Here is a screenshot
M-C-Haker
@M-C-Haker
Jul 02 2017 04:12
Dan im on mobile now screen shot much appreciated thank you
Dan Stockham
@DanStockham
Jul 02 2017 04:12
image.png
M-C-Haker
@M-C-Haker
Jul 02 2017 04:13
@Lumexralph i just saw this earlier today. Looks very good to me compared to codepen and the other popular ones. And fast
Dan Stockham
@DanStockham
Jul 02 2017 04:14

@Lumexralph This is where I'm basing my information off of

As we discussed in Chapter 1, the first traditional phase of a standard language compiler is called lexing (aka, tokenizing). If you recall, the lexing process examines a string of source code characters and assigns semantic meaning to the tokens as a result of some stateful parsing.

It is this concept which provides the foundation to understand what lexical scope is and where the name comes from.

To define it somewhat circularly, lexical scope is scope that is defined at lexing time. In other words, lexical scope is based on where variables and blocks of scope are authored, by you, at write time, and thus is (mostly) set in stone by the time the lexer processes your code.

That's coming from YDKJS Scope & Closure
Ogundele Olumide
@Lumexralph
Jul 02 2017 04:16
@DanStockham the best way to think about things is that all declarations, both variables and functions, are processed first, before any part of your code is executed.
M-C-Haker
@M-C-Haker
Jul 02 2017 04:17
@DanStockham alright ill check it out. You guys are killing me (amazing me) with the level of knowledge of javascript that you have. What do i need to do to get to this level?? I flew through fcc up to the Basic algo waypoints and now im feeling a little bit lost. How long before i feel comfortable how much practice?
Dan Stockham
@DanStockham
Jul 02 2017 04:18
@M-C-Haker Years man. There is a lot I don't know. Actually, @Lumexralph has more knowledge than I do.
@M-C-Haker I'm more about getting the job done and not worrying about the "why" until I at least get the "how"
Ogundele Olumide
@Lumexralph
Jul 02 2017 04:19

@Lumexralph No, when the code is interpreted, the function scope is created first, then the code is executed. Nothing is being hoisted.

@DanStockham and this is also right

@DanStockham there's soooo much I don't know
soo much
Joseph
@revisualize
Jul 02 2017 04:20
hello. :)
Dan Stockham
@DanStockham
Jul 02 2017 04:21
@M-C-Haker So that way I learn is by building projects and fiddling around with what the language has to offer. If you want to pick it up real fast, take the plunge into backend code and with some perseverance you'll be light years ahead of your peers.
@revisualize Hey there! no time no talk.
Joseph
@revisualize
Jul 02 2017 04:21
@DanStockham how are things?
Dan Stockham
@DanStockham
Jul 02 2017 04:22
@Lumexralph That may be true, but you still have more knowledge than I do. At least you explained it like a true scholar :)
@revisualize Good. I decided to attend a bootcamp to pick up .NET
Joseph
@revisualize
Jul 02 2017 04:22
@DanStockham cool. C#?
Ogundele Olumide
@Lumexralph
Jul 02 2017 04:23
@DanStockham :smirk: , I am humbled by that but find that hard to take in
Dan Stockham
@DanStockham
Jul 02 2017 04:23
@revisualize You know, I have to assimilate myself into big enterprise to spread the use of Javascript :)
@revisualize Yessir and ASP.NET as well :)
Joseph
@revisualize
Jul 02 2017 04:23
cool.
Dan Stockham
@DanStockham
Jul 02 2017 04:24
@Lumexralph Just keep up the good work. Employers want people who can explain things articulately and in layman.
Ogundele Olumide
@Lumexralph
Jul 02 2017 04:24
@M-C-Haker an expert was once a beginner, that's what I keep telling myself when i'm trying to do stuffs like this
Dan Stockham
@DanStockham
Jul 02 2017 04:25
@revisualize I still love JavaScript and always yearn to build an application out of Node.
Ogundele Olumide
@Lumexralph
Jul 02 2017 04:25
@DanStockham that goes for you too, thanks :smile:
CamperBot
@camperbot
Jul 02 2017 04:25
lumexralph sends brownie points to @danstockham :sparkles: :thumbsup: :sparkles:
:cookie: 559 | @danstockham |http://www.freecodecamp.com/danstockham
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 04:25
good <time-of-day>
I'm working a challenge and I did it wrong at first.
Joseph
@revisualize
Jul 02 2017 04:26
@DanStockham The knowledge of .Net will carry your overall career forward. :)
@baseballpoetess which?
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 04:27
I'm trying to do it correctly now but am getting a TypeError.
Dan Stockham
@DanStockham
Jul 02 2017 04:27
@revisualize That's good to know man :)
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 04:27
Sorted Union.
I have the ugly code because i'm doing it in bits as I get them .... hopefully .... working
Joseph
@revisualize
Jul 02 2017 04:28
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 04:28
function uniteUnique(arr)  {

 arr = [].slice.call(arguments).reduce(function(a1, a2) {
      return a1.concat(a2);
    }, []);
// return arr;   

 var aNew= arr.reduce(function(a1,item) {
      return (a1.indexOf(item) ==-1) ? a1.push(item) : a1;
  },[]);

  return aNew;
}
jorlee92
@jorlee92
Jul 02 2017 04:28
Hey can anybody tell me what I am doing wrong here?

function destroyer(arr) {
// Remove all the values
res = Array.from(arr[0]);

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

res = res.filter(function(v){
  console.log(i);
  console.log(v);
  return v!=arr[i];


});

}

return res;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);

Joseph
@revisualize
Jul 02 2017 04:29
@jorlee92 can you show a different test case?
jorlee92
@jorlee92
Jul 02 2017 04:30
@revisualize destroyer([1, 2, 3, 1, 2, 3], 2, 3) should return [1, 1].
destroyer([1, 2, 3, 5, 1, 2, 3], 2, 3) should return [1, 5, 1].
destroyer([3, 5, 1, 2, 2], 2, 3, 5) should return [1].
destroyer([2, 3, 2, 3], 2, 3) should return [].
Dan Stockham
@DanStockham
Jul 02 2017 04:30
@jorlee92 What exactly is the problem? It'll help us understand what is wrong.
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 04:30
TypeError: a1.indexOf is not a function
jorlee92
@jorlee92
Jul 02 2017 04:30
The small pieces seem to work when I try it in Chromes console
But it keeps returning an empty array
Joseph
@revisualize
Jul 02 2017 04:31
@jorlee92 destroyer([ "a" , "b" , "c" ] , "d" , "e" ); ... question.
@jorlee92 with the function declararation of: function destroyer(arr) { } ... what is the arr?
using my example test case
jorlee92
@jorlee92
Jul 02 2017 04:32
["a","b","c"] ?
Joseph
@revisualize
Jul 02 2017 04:33
yes
@jorlee92 so how do you access "d" or "e" ?
jorlee92
@jorlee92
Jul 02 2017 04:34
Wait, i thought it was the entire thing, and that arr[0] would be the small array
Joseph
@revisualize
Jul 02 2017 04:34
@jorlee92 no
Dan Stockham
@DanStockham
Jul 02 2017 04:34
@jorlee92 Why are you calling Array.from(arr[0])?
Joseph
@revisualize
Jul 02 2017 04:34
@jorlee92 just [ "a" , "b" , "c" ] is the arr
jorlee92
@jorlee92
Jul 02 2017 04:35
Oh god, Chrome kept telling me I had a syntax error so I made the entire input into an array
Joseph
@revisualize
Jul 02 2017 04:35
arr[0] is "a"
jorlee92
@jorlee92
Jul 02 2017 04:35
@DanStockham Because I had assumed that the input would be thrown in as an array
Joseph
@revisualize
Jul 02 2017 04:35
@jorlee92 look up the arguments object ... it is linked on the lesson
jorlee92
@jorlee92
Jul 02 2017 04:36
@revisualize Doing it now, thanks
CamperBot
@camperbot
Jul 02 2017 04:36
jorlee92 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4292 | @revisualize |http://www.freecodecamp.com/revisualize
Dan Stockham
@DanStockham
Jul 02 2017 04:36
@jorlee92 When I nixed the Array method, it looked like it worked fine. Something came back.
function destroyer(arr) {
// Remove all the values

for(var i = 1 ; i < arr.length; i++){
arr = arr.filter(function(v){
  console.log(i);
  console.log(v);
  return v!=arr[i];


});
}
return arr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
//[3,3]
Oh you know what, I think the value 2 needs to comeback.
err, wrong 1 and 1
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 04:40

@revisualize

Done running (0 steps)

I'm not sure what I'm supposed to glean from that.
Is it geared for functional programming?
Nitin Sahu
@globefire
Jul 02 2017 04:42
image.png
what is the error in this program?
@nvlled thank
CamperBot
@camperbot
Jul 02 2017 04:43
globefire sends brownie points to @nvlled :sparkles: :thumbsup: :sparkles:
:cookie: 240 | @nvlled |http://www.freecodecamp.com/nvlled
Joseph
@revisualize
Jul 02 2017 04:43
@globefire contacts[i][firstName]
Nitin Sahu
@globefire
Jul 02 2017 04:44
sorry ?
Joseph
@revisualize
Jul 02 2017 04:44
@globefire thats the err
Nitin Sahu
@globefire
Jul 02 2017 04:44
so i should use a dot operator?
Joseph
@revisualize
Jul 02 2017 04:45
@globefire no?
Nitin Sahu
@globefire
Jul 02 2017 04:45
but we can use both na ?
Joseph
@revisualize
Jul 02 2017 04:46
what?
Nitin Sahu
@globefire
Jul 02 2017 04:46
[] and .
Joseph
@revisualize
Jul 02 2017 04:46

@globefire Let's say you have an object.

var myFriend = {
        "firstName": "Happy",
        "lastName": "Feet",
        "number": "-i",
        "likes": ["rhythm", "dancing", "soul"]
    }

How do you access the "firstName" of myFriend?

Nitin Sahu
@globefire
Jul 02 2017 04:47
myFriend[0]
?
Joseph
@revisualize
Jul 02 2017 04:47
no
Nitin Sahu
@globefire
Jul 02 2017 04:47
:worried:
Joseph
@revisualize
Jul 02 2017 04:47
Object.
not Array
Nitin Sahu
@globefire
Jul 02 2017 04:48
ok myFriend["firstName"] or myFriend.firstName ?
Joseph
@revisualize
Jul 02 2017 04:48
correct
Nitin Sahu
@globefire
Jul 02 2017 04:48
ok got ya
thanks man
i forgot the " " in my code
@revisualize thanks
CamperBot
@camperbot
Jul 02 2017 04:49
globefire sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4293 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Jul 02 2017 04:50
woot 5 bps today.. broken wrist and all.
Nitin Sahu
@globefire
Jul 02 2017 04:50
sorry ?
jorlee92
@jorlee92
Jul 02 2017 04:50
@DanStockham @revisualize Thanks I finally figured it out
CamperBot
@camperbot
Jul 02 2017 04:50
jorlee92 sends brownie points to @danstockham and @revisualize :sparkles: :thumbsup: :sparkles:
:warning: jorlee92 already gave revisualize points
:cookie: 560 | @danstockham |http://www.freecodecamp.com/danstockham
jorlee92
@jorlee92
Jul 02 2017 04:50
I should not have skipped over the fact that args is completely not an array
Dan Stockham
@DanStockham
Jul 02 2017 04:50
@jorlee92 Awesome sauce!
@jorlee92 Oh yes, that's a tricky sum bitch with arguments with it being array like :sleepy:
@jorlee92 But you did good!
Joseph
@revisualize
Jul 02 2017 04:51
@globefire my wrist
IMG_20170630_202810.jpg
Nitin Sahu
@globefire
Jul 02 2017 04:52
omg
u r solving doubts with broken hand
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 04:53
arguments is so not an array.
Joseph
@revisualize
Jul 02 2017 04:53
I'm helping
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 04:53
the manual has a how-to to make it one.
right there on the page for Arguments Object.
baseballpoetess @baseballpoetess is helping too
Dan Stockham
@DanStockham
Jul 02 2017 04:53
@revisualize Jesus Christ. The ulnar bone is literally torqued from the wrist bones.
Nitin Sahu
@globefire
Jul 02 2017 04:54
take care @revisualize man
Joseph
@revisualize
Jul 02 2017 04:54
@DanStockham yeah, i f'd up
Nitin Sahu
@globefire
Jul 02 2017 04:54
how did it happen ?
Dan Stockham
@DanStockham
Jul 02 2017 04:54
@globefire Fighting SJWs?
Joseph
@revisualize
Jul 02 2017 04:55
On, Thursday, things happened... and you can see the picture. Basically, I was riding my bike down the bike trail while carrying two backpacks (one strapped to the bike and one on my back). I was going around an S curve and someone flew by me, I hit a wet patch on smooth pavement and I lost control (I think due to the extra weight and mass). I tried to correct and stay upright but, when I hit the grass, I went over the top of the bike. I tried to curl in and save myself but, I broke myself. ... I have surgery next week.
Nitin Sahu
@globefire
Jul 02 2017 04:55
f**k
Dan Stockham
@DanStockham
Jul 02 2017 04:55
@revisualize Damn dude, I hope you have a speedy recover.
Joseph
@revisualize
Jul 02 2017 04:55
8 weeks
1 yr full recovery
Dan Stockham
@DanStockham
Jul 02 2017 04:56
@revisualize That's going to be a lot of one handed typing.
Nitin Sahu
@globefire
Jul 02 2017 04:56
which country?
Joseph
@revisualize
Jul 02 2017 04:56
yeah. I should be able to type with my left hand in 1 week
Ogundele Olumide
@Lumexralph
Jul 02 2017 04:57
@revisualize sorry man, wish you quick recovery sooner than your speculation
Joseph
@revisualize
Jul 02 2017 04:57
Seattle, Washington, USAmerica, North America, Terra, Sol, Local Interstellar Cloud, Local Bubble, Gould Belt, Orion-Cygnus Arm, Milky Way, Milky Way Subgroup, Local Galactic Group, Virgo Supercluster, Laniakea Supercluster, Observable Universe, Universe
Nitin Sahu
@globefire
Jul 02 2017 04:57
:laughing:
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 04:58
ugh
well, that's why you can't help me. kk
Joseph
@revisualize
Jul 02 2017 04:59
heh
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 04:59
thanks @revisualize
CamperBot
@camperbot
Jul 02 2017 04:59
baseballpoetess sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4294 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Jul 02 2017 04:59
sorry, I'm all messed up
that's a harder problem
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:01
nah, I'm trying to do functional programming and I know that it's not something a lot of folks can help with.
I'll bum another room.
Ogundele Olumide
@Lumexralph
Jul 02 2017 05:01
@baseballpoetess you can still ask your question(s)
Joseph
@revisualize
Jul 02 2017 05:02
@baseballpoetess there are others here that can help.
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:02
I have. Okay, let me go grab it again.....
Ogundele Olumide
@Lumexralph
Jul 02 2017 05:02
@baseballpoetess sorry I missed it
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:02
function uniteUnique(arr)  {

 arr = [].slice.call(arguments).reduce(function(a1, a2) {
      return a1.concat(a2);
    }, []);
// return arr;   

 var aNew= arr.reduce(function(a1,item) {
      return (a1.indexOf(item) ==-1) ? a1.push(item) : a1;
  },[]);

  return aNew;
}
I'm getting a type error on a1.indexOf saying it's not a function.
Joseph
@revisualize
Jul 02 2017 05:03
@baseballpoetess spread operator?
@baseballpoetess what does this do:
 arr = [].slice.call(arguments).reduce(function(a1, a2) {
      return a1.concat(a2);
    }, []);
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:04
it takes n arrays and makes them into one gargantuarray
Joseph
@revisualize
Jul 02 2017 05:04
@baseballpoetess var args = [].concat(...arguments);
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:04
from arr which is arguments which is not an array.
Dan Stockham
@DanStockham
Jul 02 2017 05:04
@revisualize That makes more sense to me.
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:05
okay, I was assembling it in pieces as I made them work.
:)
so add this extra line of code is what you're saying and that will make my type error go away?
Joseph
@revisualize
Jul 02 2017 05:06
@baseballpoetess IDK
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:06
lol, kk
Dan Stockham
@DanStockham
Jul 02 2017 05:06
@baseballpoetess Why slice though?
Joseph
@revisualize
Jul 02 2017 05:06
@baseballpoetess I dont think it should be extra.
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:06
no, the type error is in the bottom part. the top part works. uncomment the return and you get a fat array.
Joseph
@revisualize
Jul 02 2017 05:06
@baseballpoetess replacement?
Moisés Man
@moigithub
Jul 02 2017 05:07
@DanStockham to create a copy of arguments.. since this is not a real array..
it dont have array methods
Dan Stockham
@DanStockham
Jul 02 2017 05:07
@moigithub Oh, that's a good point.
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:07
the type error is on a1.indexOf
Ogundele Olumide
@Lumexralph
Jul 02 2017 05:07
@baseballpoetess can you show how the function is called?
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:07
in the bottom .... a different a1 "what happens in braces stays in braces"
Joseph
@revisualize
Jul 02 2017 05:08
@baseballpoetess ohhhhhhhhh
@baseballpoetess ohhhhh
@baseballpoetess return (a1.indexOf(item) ==-1) ? a1.push(item) : a1;
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:08
Which "the function @Lumexralph ?
Joseph
@revisualize
Jul 02 2017 05:08
@baseballpoetess a1.push(item)
@baseballpoetess The push() method adds one or more elements to the end of an array and returns the new length of the array.
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:09
the bottom is supposed to be a ternary operator that, if the item is not in the array yet, puts it there, and if it is, just goes on.
are you familiar with the ternary operator?
Joseph
@revisualize
Jul 02 2017 05:09
i am
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:10
okay, push only happens if the item is not found in the array a1.indexOF(item) == -1
Joseph
@revisualize
Jul 02 2017 05:10
@baseballpoetess what happens when (a1.indexOf(item) ==-1) is true?
Ogundele Olumide
@Lumexralph
Jul 02 2017 05:10
@baseballpoetess ternary operator returned the length of the array after adding the value
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:10
it pushes the item on the array
if it's false, it leaves the array alone.
Joseph
@revisualize
Jul 02 2017 05:10
@baseballpoetess but
@baseballpoetess .push returns
Ogundele Olumide
@Lumexralph
Jul 02 2017 05:11
@baseballpoetess but an integer was returned, not the array
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:11
push returns the array dunnit?
Joseph
@revisualize
Jul 02 2017 05:11
@baseballpoetess your return is returning too
@baseballpoetess The push() method adds one or more elements to the end of an array

and returns the new length of the array.

J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:11
oh
I thought it returned the new array.
okay, I will fix that.
Gracias @revisualize
CamperBot
@camperbot
Jul 02 2017 05:12
baseballpoetess sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: baseballpoetess already gave revisualize points
Ogundele Olumide
@Lumexralph
Jul 02 2017 05:12
@baseballpoetess nope, it doesn't return the array, it returns the length of the array, the side-effect of push is that it adds a value to the end of the array
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:12
and that's my problem. :)
I want concat
or something like it.
Ogundele Olumide
@Lumexralph
Jul 02 2017 05:13
@baseballpoetess yes, because you're trying to use indexOf a number, it'll return a typeError
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:13
:) Bless you all
Gracias @Lumexralph
CamperBot
@camperbot
Jul 02 2017 05:13
baseballpoetess sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 2013 | @lumexralph |http://www.freecodecamp.com/lumexralph
Joseph
@revisualize
Jul 02 2017 05:13
@baseballpoetess why not break the if out?
Ogundele Olumide
@Lumexralph
Jul 02 2017 05:14
@baseballpoetess your function is to give array with unique elements, right?
Joseph
@revisualize
Jul 02 2017 05:15
    if (a1.indexOf(item) === -1) a1.push(item);
    return a1;
Moisés Man
@moigithub
Jul 02 2017 05:15
u can do [...a1, item] instead
or a1.concat(item)
if still wanna use ternary...
Joseph
@revisualize
Jul 02 2017 05:16
or
shivam gupta
@shivamg11000
Jul 02 2017 05:16
var obj = {
  name : 'shivam',
  Age : 20,
  year_born : function(this.Age){
    return (2017-this.Age) ;
  }
};

console.log(obj.year_born);
It says unexpected token
Joseph
@revisualize
Jul 02 2017 05:17
return (a1.indexOf(item) == -1) ? ( a1.push(item) , a1 ) : a1;
Ronald T. Casili
@nvlled
Jul 02 2017 05:17
@shivamg11000 remove this.Age in the parameter list
shivam gupta
@shivamg11000
Jul 02 2017 05:18
@nvlled but I need the age of the object to compile the year_born
Joseph
@revisualize
Jul 02 2017 05:18
@baseballpoetess ---^^^^^^^
Ronald T. Casili
@nvlled
Jul 02 2017 05:18
I mean, just year_born: function() {
And it's supposed to be console.log(obj.year_born()); since it's a function
shivam gupta
@shivamg11000
Jul 02 2017 05:21
@nvlled its quivalent shuold be this
```
() => (2017-this.Age)
right hA
var obj = {
  name : 'shivam',
  Age : 20,
  year_born : () => (2017-this.Age) 

};
Ronald T. Casili
@nvlled
Jul 02 2017 05:27

I don't fully understand what you're saying but this works

var obj = {
  name : 'shivam',
  Age : 20,
  year_born () { return 2017-this.Age }
}

And this

var obj = {
  name : 'shivam',
  Age : 20,
  year_born:  () => 2017-obj.Age 
}
shivam gupta
@shivamg11000
Jul 02 2017 05:27
the upper is one is correct
@nvlled
Its ECMA6
Ronald T. Casili
@nvlled
Jul 02 2017 05:32
But the bottom one works too, and it uses arrow functions which is ES6 as well
shivam gupta
@shivamg11000
Jul 02 2017 05:35

@nvlled but when i use

year_born () {return "lol"}

outside the object it does not work

J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:37
No, @Lumexralph not unique .... I solved that and it was the wrong problem.
it is to be one copy of each element.
(sorry, I was feeding my cats)
Ogundele Olumide
@Lumexralph
Jul 02 2017 05:45
@baseballpoetess it's okay :smile:
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:46
lol they think so. :)
Ogundele Olumide
@Lumexralph
Jul 02 2017 05:47
they?
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:51
It works now. I fixed it. It even works if there are arrays of .... arrays.
Ogundele Olumide
@Lumexralph
Jul 02 2017 05:54
@baseballpoetess :clap:
J-Mag Guthrie
@baseballpoetess
Jul 02 2017 05:55
:) thank you everyone.
CallMeOrange
@EgnaroDev
Jul 02 2017 06:13
I completed Slasher Flick, here's my code (Its probably not good, maybe?)
function slasher(arr, howMany) {
  if (howMany === 0) {
    return arr;
  } else if (arr.length > howMany) {
    return arr.slice(howMany, arr.length);
  }
  arr = arr.splice(howMany, 1);
  return arr;
}

slasher([1, 2, 3], 2);
This works also
function slasher(arr, howMany) {
  if (howMany === 0) {
    return arr;
  } else {
    return arr.slice(howMany, arr.length);
  }
  arr = arr.splice(howMany, 1);
  return arr;
}

slasher([1, 2, 3], 2);
but I think else if is much better
Im done with "talking" to myself
:)
aRtoo
@artoodeeto
Jul 02 2017 06:16
hey guys. can i have a help. can you check on the console what are the meaning of the error because on my local i dont have an error
https://codepen.io/artoo/pen/XgEVaE
Pieter Stokkink
@forkerino
Jul 02 2017 07:18
@MCTwoDigitZero it is really much simpler. arr.slice(howMany) always gives you the right result.
@artoodeeto you cannot use http:// api's on codepen, because codepen uses https://
Viktor Tiutiun
@vittorioVT
Jul 02 2017 07:23
@MCTwoDigitZero Why do you need arr.splice() if arr.slice() already works?
Kelechi Chinaka
@ke1echi
Jul 02 2017 07:28
morning guys
Ronald T. Casili
@nvlled
Jul 02 2017 07:33
good afternoon
Kelechi Chinaka
@ke1echi
Jul 02 2017 07:34
function removeEveryOther(arr) {
  return arr.filter( function (element) { return arr.indexOf(element) % 2 === 0;});
}
why does it return false for an element at index 4
what am i doing wrongly
['o',4,'d','q',4] returns false for element 4
4 % 2 == 0
Manish Giri
@Manish-Giri
Jul 02 2017 07:39
@kelechichinaka indexOf(4) will return 1
because it is first present at index 1
The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.
first index
Kelechi Chinaka
@ke1echi
Jul 02 2017 07:44
i meant the last 4 in the array @Manish-Giri
Manish Giri
@Manish-Giri
Jul 02 2017 07:44
you should really read the docs
4 is present twice
Sweet Coding :)
@SweetCodingInc
Jul 02 2017 07:44
@kelechichinaka indexOf returns index of the first matching element
Manish Giri
@Manish-Giri
Jul 02 2017 07:44
so it will refer the first index at which is matched
no matter if you have 2 4s or hundreds
Sweet Coding :)
@SweetCodingInc
Jul 02 2017 07:45
4 is at index 1 and at index 4. But indexOf(4) will always return 1 (the first matching element)
Kelechi Chinaka
@ke1echi
Jul 02 2017 07:45
oh i get it now
are there no work around it
Manish Giri
@Manish-Giri
Jul 02 2017 07:45
lastIndexOf
but again, not completely accurate
Sweet Coding :)
@SweetCodingInc
Jul 02 2017 07:46
@kelechichinaka .filter also gives you current index
so instead of using indexOf(element) % 2 === 0, use index % 2 === 0
Manish Giri
@Manish-Giri
Jul 02 2017 07:47
return arr.filter( function (element, index) { ....
use the index param
Sweet Coding :)
@SweetCodingInc
Jul 02 2017 07:48
@kelechichinaka like this
var arr = ['o',4,'d','q',4];

function removeEveryOther(arr) {
  return arr.filter( function (element, index) { // NOTE : index is passed as 2nd argument
    return index % 2 === 0;
  });
}

console.log(arr); // ['o',4,'d','q',4]
console.log(removeEveryOther(arr)); // [ 'o', 'd', 4 ]
Kelechi Chinaka
@ke1echi
Jul 02 2017 07:49
hmm cool..always a good time to learn from u guys
Sweet Coding :)
@SweetCodingInc
Jul 02 2017 07:49
@kelechichinaka :+1:
Kelechi Chinaka
@ke1echi
Jul 02 2017 07:49
i would checkout the docs..thanks @Manish-Giri @SweetCodingInc
CamperBot
@camperbot
Jul 02 2017 07:49
kelechichinaka sends brownie points to @manish-giri and @sweetcodinginc :sparkles: :thumbsup: :sparkles:
:cookie: 53 | @sweetcodinginc |http://www.freecodecamp.com/sweetcodinginc
:star2: 6171 | @manish-giri |http://www.freecodecamp.com/manish-giri
Ogundele Olumide
@Lumexralph
Jul 02 2017 08:18
@kelechichinaka Bro!
Jonathan Meier
@jntme
Jul 02 2017 08:18
wasaap
Ogundele Olumide
@Lumexralph
Jul 02 2017 08:19
@Manish-Giri wonder if @joreyesl will come around, the ggggggm partner :smiling_imp:
@jntme Hi
Jor
@joreyesl
Jul 02 2017 08:19
:smiling_imp:
Ogundele Olumide
@Lumexralph
Jul 02 2017 08:20
whaaaaaaaat!!
Jor
@joreyesl
Jul 02 2017 08:20
someone summoned me?
Ogundele Olumide
@Lumexralph
Jul 02 2017 08:20
was that automated? or it was a bot ?
Jor
@joreyesl
Jul 02 2017 08:21
bot
Ogundele Olumide
@Lumexralph
Jul 02 2017 08:21
@joreyesl are you kidding me?
Jor
@joreyesl
Jul 02 2017 08:21
how are u
Ogundele Olumide
@Lumexralph
Jul 02 2017 08:21
where've you been?
Jor
@joreyesl
Jul 02 2017 08:21
busy
Ogundele Olumide
@Lumexralph
Jul 02 2017 08:21
i'm great, thanks
Jor
@joreyesl
Jul 02 2017 08:21
cool
Ogundele Olumide
@Lumexralph
Jul 02 2017 08:22
good to have you around :smile:
Jor
@joreyesl
Jul 02 2017 08:22
thx :)
how have things been?
Ogundele Olumide
@Lumexralph
Jul 02 2017 08:23
not smooth, could be better but definitely good prospects
you?
Jor
@joreyesl
Jul 02 2017 08:23
better now, gonna have 4 days to myself
4th of july weekened
Manish Giri
@Manish-Giri
Jul 02 2017 08:23
the legendary ggm @joreyesl is always lurking :smiling_imp:
:bow:
Kelechi Chinaka
@ke1echi
Jul 02 2017 08:23
:wave: @Lumexralph
Ogundele Olumide
@Lumexralph
Jul 02 2017 08:24
@Manish-Giri not sure he was, so coincidental I asked and he came online
Jor
@joreyesl
Jul 02 2017 08:24
@Manish-Giri sgm :smiling_imp: :bow:
Ogundele Olumide
@Lumexralph
Jul 02 2017 08:25
@kelechichinaka how're you?
Kelechi Chinaka
@ke1echi
Jul 02 2017 08:26
am ok @Lumexralph hws the day looking like?
Ogundele Olumide
@Lumexralph
Jul 02 2017 08:26
@kelechichinaka i've no idea but I'm optimistic, how area?
Kelechi Chinaka
@ke1echi
Jul 02 2017 08:28
area de ok..i get to mark pupils' script @Lumexralph
CallMeOrange
@EgnaroDev
Jul 02 2017 09:00
@forkerino Oh you are correct, I never tried arr.slice(start) thanks
CamperBot
@camperbot
Jul 02 2017 09:00
mctwodigitzero sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2807 | @forkerino |http://www.freecodecamp.com/forkerino
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:10
can anyone tell me what is the difference between Null and undefined//
i am little confused
in javascript
Ogundele Olumide
@Lumexralph
Jul 02 2017 09:11
@SHAKTISINGH2323 The value null represents the intentional absence of any object value. It is one of JavaScript's primitive values.
@SHAKTISINGH2323 undefinedit's a value of the global object property Undefined
@SHAKTISINGH2323
// foo does not exist. It is not defined and has never been initialized:
foo;
"ReferenceError: foo is not defined"

// foo is known to exist now but it has no type or value:
var foo = null; foo;
"null"
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:13
the null has a type object right so what does the type object specify?
what i understand about the type of null ie object
Ogundele Olumide
@Lumexralph
Jul 02 2017 09:14
@SHAKTISINGH2323
typeof null        // "object" (not "null" for legacy reasons)
typeof undefined   // "undefined"
according to MDN
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:14
yes ur right
Ogundele Olumide
@Lumexralph
Jul 02 2017 09:15
it doesn't make null an object
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:16
for eg like var c=2; //type of c is a number so i understand that it is a number but in case of null the type is object what does it means
Ogundele Olumide
@Lumexralph
Jul 02 2017 09:17
@SHAKTISINGH2323 it's for JS sake, null just has its literal form, it's not an object, JS gave it a type object for reasons best known to them
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:18
okk somewhat i am getting but they do that
Jor
@joreyesl
Jul 02 2017 09:18
they wanted null to stand for an undefined object
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:19
also when we compare null with undefined it founds true
if(null==undefined){
}
its true
Ogundele Olumide
@Lumexralph
Jul 02 2017 09:20
@SHAKTISINGH2323 so incase you're dealing with different datatype and using typeof operator, watch out for that, null was intended to take the place of missing object value
@SHAKTISINGH2323 try ===
Jor
@joreyesl
Jul 02 2017 09:20
they are both falsy values, == will coerce them to booleans so they both will be false
Ogundele Olumide
@Lumexralph
Jul 02 2017 09:20
@SHAKTISINGH2323 == allows coercion
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:20
=== is strict equality so this gives false
becus both has diff types
Jor
@joreyesl
Jul 02 2017 09:21
yea, they are not equal, but they are both falsy
Ogundele Olumide
@Lumexralph
Jul 02 2017 09:21
@SHAKTISINGH2323 yes, just as @joreyesl said null and undefined are falsy in JS
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:21
yes okk
is there is any way we get a null like in any expn,or somewhere
like undefined
for eg whie declaring the variable using var but not initilising it here we get undifined
so like that
can we get null
any where
Ogundele Olumide
@Lumexralph
Jul 02 2017 09:24
@SHAKTISINGH2323 i don't think so, except explicitly done
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:24
yes that way we can do
but how it can happen its own...
Jor
@joreyesl
Jul 02 2017 09:25
it can't at least not in JS
Ogundele Olumide
@Lumexralph
Jul 02 2017 09:25
@SHAKTISINGH2323 in JS I don't think so
Jor
@joreyesl
Jul 02 2017 09:25
other languages have null pointers
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:26
so why this null is introduced in js
Ogundele Olumide
@Lumexralph
Jul 02 2017 09:26
@SHAKTISINGH2323 anything in JS missing or not found is undefined
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:26
yes right
Jor
@joreyesl
Jul 02 2017 09:27
other languages used null to signify an empty reference to an object, when JS was created they wanted to follow the same paradigm
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:28
then ,we can use in same way the null
if we want to access a variable but the variable is not declare or defined then what we get in result when we access it
Jor
@joreyesl
Jul 02 2017 09:30
i supposed so, kinda what its there for.
It just wont appear on its own, since js variables are not strictly typed. You have to assign it yourself
Ogundele Olumide
@Lumexralph
Jul 02 2017 09:30
@SHAKTISINGH2323 that should be a Reference Error
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:31
my friend give me a statement
here it is
see imagine u have a box
an empty box means zero
but if the box is behind a curtain u cant actually say if there is a box ot not or which box it is therefore undefined
but if there is no box it is null
can u explain me the last line?
in JS manner
how can i relate it the last line in js way
Jor
@joreyesl
Jul 02 2017 09:33
in JS its different. Null is an actual value. The box will not be empty, instead it will have the value of null. But null is supposed to represent no value. So its kinda
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:34
so what is the value of null
Jor
@joreyesl
Jul 02 2017 09:34
Null, that is the value
Manish Giri
@Manish-Giri
Jul 02 2017 09:34
Lol
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:35
if i define var q=null;
Manish Giri
@Manish-Giri
Jul 02 2017 09:35
Fun Q&A!
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:35
what it means
Jor
@joreyesl
Jul 02 2017 09:35
Like, True, False. They are values. They represent, well true/false. And Null is a value also, and it represents no value
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:35
so what the heck undefined is
Ogundele Olumide
@Lumexralph
Jul 02 2017 09:36
@SHAKTISINGH2323 if there's box that you have to fill up by default which in JS a variable is a box to hold something, you want to be sure you have the box and since it can't be empty, you have to fake it by using nullbut if you have a box and you don't put anything there JS will see it as undefined
Jor
@joreyesl
Jul 02 2017 09:36
undefined is an empty box, undefined means the variable has no value assigned. null is a value that is supposed to represent a variable that has no value assigned. The key word is represent
Ogundele Olumide
@Lumexralph
Jul 02 2017 09:37
@SHAKTISINGH2323 JS will see it as it's a box containing something but it's no value
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:37
okk
Ogundele Olumide
@Lumexralph
Jul 02 2017 09:38
@SHAKTISINGH2323 in that way null keeps the box alive through the program, undefined doesn't
@SHAKTISINGH2323 don't confuse yourself, see undefined as an emptiness, something missing, not in the program except you intentionally made it missing using null
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:41
so undefined is something which is not defined or can't be defined
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 09:43
@SHAKTISINGH2323
var a;
a; //undefined
a = 5;
a; // 5
a = null;
a; // null
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:43
yes get it
by using null we can make a variable's value empty right!
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 09:44
yes
@SHAKTISINGH2323
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:44
so null is used to make something empty
Jor
@joreyesl
Jul 02 2017 09:45
in JS, variables can hold objects or primitives. If its undefined means it hasn't been initialized. null is an actual value. if you assign it to a variable, it wont make it empty, it will be holding the value null.
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 09:45
@SHAKTISINGH2323 you can also assign undefined to it.
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:46
@saifsmailbox98 both means same in ur code if i used undefined instead of null
is both have no value
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 09:46
@SHAKTISINGH2323 null is an actual value. It is just null, not undefined (no values set yet)
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:47
okk
Jor
@joreyesl
Jul 02 2017 09:48
@SHAKTISINGH2323 undefined means the variable is empty. null is a value that is used to represent no value, but the variable will not be empty, it's value will be null
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:48
@joreyesl so by making a variable's value null what it makes us benifit
Jor
@joreyesl
Jul 02 2017 09:50
@SHAKTISINGH2323 honestly cant think of a situation where you would benefit from it. Its very old relic from the creation of JS
Ogundele Olumide
@Lumexralph
Jul 02 2017 09:52

@SHAKTISINGH2323 e.g

let obj = Object.create(null);

here you don't want the created obj object have a prototype object linked to any object null saves you

@SHAKTISINGH2323 if you use undefined e.g let obj = Object.create(undefined); this is what you get
TypeError: Object prototype may only be an Object or null: undefined
@SHAKTISINGH2323 in my early programming days when I didn't know it's a bad idea to mutate an array you're iterating, i used null to help maintain the length of the array, undefined couldn't in the context I wanted it
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:56
@Lumexralph okk great in that way we can use null instead of undefined
Ogundele Olumide
@Lumexralph
Jul 02 2017 09:56
@SHAKTISINGH2323 yes
especially the first example, ignore the second
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 09:56
@SHAKTISINGH2323
var a = {}
a.foo; // undefined
var a = {
  "foo" : null
}
a.foo; // null
var a = {
  "foo" :   // SyntaxError
}
a.foo; // SyntaxError
var a = {
  "foo" : undefined
}
a.foo; // undefined
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:57
@saifsmailbox98 so in first we have not defined the value to foo okk
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 09:57
@SHAKTISINGH2323 yes
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 09:58
@saifsmailbox98 and then we make a room suppose so that we can put the value in it later by using null
@saifsmailbox98 room or space
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 09:59
@SHAKTISINGH2323 you can assign null, undefined, any other value to the variable, but when it's not defined it's undefined
Jor
@joreyesl
Jul 02 2017 10:00
null shows intent, you explicitly assigned it that value. Whereas undefined can happen on its own.
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 10:00
^
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 10:00
@joreyesl yes right
@saifsmailbox98 so in ur code 2 and 3 blocks whats the diff
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 10:03
@SHAKTISINGH2323 you mean these two?
var a = {
  "foo" : null
}
a.foo; // null
var a = {
  "foo" : undefined
}
a.foo; // undefined
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 10:03
null one and the undefined one
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 10:05
@SHAKTISINGH2323 null is a value, that I wanted the variable to contain, but if its not defined js assigns it the value undefined, you can empty a variable by assigning undefined to it.
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 10:06
is we make a variable empty using null?
no
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 10:07
@SHAKTISINGH2323 no
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 10:08
@saifsmailbox98 have u ever used null in ur codes
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 10:08
var a = {
 }
a.foo; // undefined
a.hasOwnProperty("foo"); // false
var a = {
 "foo" : undefined
}
a.foo; // undefined
a.hasOwnProperty("foo"); // true
var a = {
 "foo" : null
}
a.foo; // null
a.hasOwnProperty("foo"); //true
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 10:09
what hasOwn property does?
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 10:09
@SHAKTISINGH2323 it checks if the property foo is present or not.
Jor
@joreyesl
Jul 02 2017 10:10
undefined can mean the property does not exist or it can mean it has no value. But no matter whatnull means the property does exist.
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 10:11
okk i get it
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 10:12
@SHAKTISINGH2323 In some of the other languages, when you declare a variable and not assign a value to it, some random value is assign to it, it's good that js assigns undefined to the undefined variable.
SHAKTI SINGH
@SHAKTISINGH2323
Jul 02 2017 10:12
yes thats great
@saifsmailbox98 @joreyesl @Lumexralph thanks
CamperBot
@camperbot
Jul 02 2017 10:13
shaktisingh2323 sends brownie points to @saifsmailbox98 and @joreyesl and @lumexralph :sparkles: :thumbsup: :sparkles:
:cookie: 690 | @saifsmailbox98 |http://www.freecodecamp.com/saifsmailbox98
:cookie: 822 | @joreyesl |http://www.freecodecamp.com/joreyesl
:star2: 2014 | @lumexralph |http://www.freecodecamp.com/lumexralph
Daniel Lim
@ddanielnp
Jul 02 2017 10:37
does anyone know how i can remove a class from html using javascript?
<div id='box' class='element'>
the problem that the class element will be added randomly of 7 classes
Jor
@joreyesl
Jul 02 2017 10:37
vanilla js?
Harut
@harut-g
Jul 02 2017 10:38
@ddanielnp document.getElementById("box").classList.remove("element");
Daniel Lim
@ddanielnp
Jul 02 2017 10:38
yes, but i wont know what the class name will be
Pieter Stokkink
@forkerino
Jul 02 2017 10:39
@joreyesl :wave:
Daniel Lim
@ddanielnp
Jul 02 2017 10:39
depends on user input of the classlist
Jor
@joreyesl
Jul 02 2017 10:39
@forkerino morning
Pieter Stokkink
@forkerino
Jul 02 2017 10:39
@joreyesl how's it going?
Jor
@joreyesl
Jul 02 2017 10:39
good, u? I heard you got a new job!
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 10:39
@ddanielnp $("#box").removeClass(); removes all the classes
Daniel Lim
@ddanielnp
Jul 02 2017 10:40
great
Harut
@harut-g
Jul 02 2017 10:40
@ddanielnp document.getElementById("box").className="";
@ddanielnp by this way
Daniel Lim
@ddanielnp
Jul 02 2017 10:40
but does it leave the div as ```<div id='box' class=''>
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 10:41
@ddanielnp you can empty the attribute value also
$("#box").attr("class", "");
Pieter Stokkink
@forkerino
Jul 02 2017 10:41
@joreyesl yeah, first programmer job, I started on monday. Lots of fun installing docker and getting it to work... :P
Jor
@joreyesl
Jul 02 2017 10:41
document.getElementById("theID").removeAttribute("class")
@forkerino awesome!!
Daniel Lim
@ddanielnp
Jul 02 2017 10:41
from <div id='box' class='elements'> to <div id='box' class=''>
Harut
@harut-g
Jul 02 2017 10:41
@forkerino congrats!
Pieter Stokkink
@forkerino
Jul 02 2017 10:41
@joreyesl but started to learn some advanced redux patterns as well, I'm very happy to be able to make a living and code at the same time.
@harut-g @joreyesl thanks
CamperBot
@camperbot
Jul 02 2017 10:42
forkerino sends brownie points to @harut-g and @joreyesl :sparkles: :thumbsup: :sparkles:
:cookie: 280 | @harut-g |http://www.freecodecamp.com/harut-g
:cookie: 823 | @joreyesl |http://www.freecodecamp.com/joreyesl
Harut
@harut-g
Jul 02 2017 10:42
@forkerino what is your position now?
Daniel Lim
@ddanielnp
Jul 02 2017 10:42
@saifsmailbox98 does $("#box").removeClass(); will there will be an empty <div id='box' class=''>
Harut
@harut-g
Jul 02 2017 10:43
@ddanielnp do you want remove class attribute also?
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 10:43
@ddanielnp I think so, you can try.
Daniel Lim
@ddanielnp
Jul 02 2017 10:43
nope
i want to leave it as <div id='box' class=''>
Pieter Stokkink
@forkerino
Jul 02 2017 10:44
@harut-g I'll start mostly on front end (Angular with Redux), but it's a small team and we review each other's code all the time.
Harut
@harut-g
Jul 02 2017 10:44
@ddanielnp yes it leave so
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 10:44
@ddanielnp try document.getElementById('box').className = '';
Daniel Lim
@ddanielnp
Jul 02 2017 10:44
@harut-g @saifsmailbox98 thanks
CamperBot
@camperbot
Jul 02 2017 10:44
ddanielnp sends brownie points to @harut-g and @saifsmailbox98 :sparkles: :thumbsup: :sparkles:
:cookie: 281 | @harut-g |http://www.freecodecamp.com/harut-g
:cookie: 691 | @saifsmailbox98 |http://www.freecodecamp.com/saifsmailbox98
Jor
@joreyesl
Jul 02 2017 10:45
@forkerino thats great! I'm happy for you. I need to start focusing more on the same goal
Harut
@harut-g
Jul 02 2017 10:45
@forkerino very good! Good luck!
Pieter Stokkink
@forkerino
Jul 02 2017 10:46
:pray:
Harut
@harut-g
Jul 02 2017 10:46
@forkerino have you plans to learn node js for back end?
Pieter Stokkink
@forkerino
Jul 02 2017 10:49
@harut-g I already learned some node, did three of the full stack projects and then decided it was time to learn React.
Harut
@harut-g
Jul 02 2017 10:49
@forkerino :+1:
Keon Samuel
@keonsam
Jul 02 2017 10:52
@forkerino so we have equal power levels?
Jor
@joreyesl
Jul 02 2017 10:54
over 9000, id say
Pieter Stokkink
@forkerino
Jul 02 2017 11:07
about @keonsam
CamperBot
@camperbot
Jul 02 2017 11:07
:cookie: 409 | @keonsam |http://www.freecodecamp.com/keonsam
Pieter Stokkink
@forkerino
Jul 02 2017 11:08
who knows
Not sure how to measure power levels
Keon Samuel
@keonsam
Jul 02 2017 11:17
neither do the creator, lol.
koder3
@koder3
Jul 02 2017 11:40
How do i go about using reduce in the symmetric difference challenge? ive read about three links (apart from MDN) that explain reduce in easy terms i wasnt able to understand them that much. how do i use reduce in that challenge. any help?
function sym(args) {


var w = []
var e = Array.prototype.slice.call(arguments)
return e.reduce(function(a, b){
return a + b
}, [])

}
sym([1, 2, 3], [5, 2, 1, 4])
this is all i got
Pieter Stokkink
@forkerino
Jul 02 2017 11:43
@koder3 let's think it through. What does the .reduce need to return?
be as specific as you can
Sweet Coding :)
@SweetCodingInc
Jul 02 2017 11:43
@koder3 : A quick observation, get rid of , [] from }, [])
koder3
@koder3
Jul 02 2017 11:43
okay. it needs to check if the first element of the first array is the same as the first element from the second array.
then second element of second array
Pieter Stokkink
@forkerino
Jul 02 2017 11:45
@koder3 maybe in more abstract terms? It needs to return an array consisting of.....
koder3
@koder3
Jul 02 2017 11:45
consisting of things that are in only 1 arr but not both
Pieter Stokkink
@forkerino
Jul 02 2017 11:46
exactly
koder3
@koder3
Jul 02 2017 11:46
how do you
access each elemtent
in a for loop u use [i]
how do u do that in a reduce
Pieter Stokkink
@forkerino
Jul 02 2017 11:47
@koder3 you'll need something inside the .reduce that somehow filters the values out that need to go out.
Sounds like a job for ...
koder3
@koder3
Jul 02 2017 11:47
i can use filters in reduces ?
Pieter Stokkink
@forkerino
Jul 02 2017 11:47
oh yes
that's the beauty of it
koder3
@koder3
Jul 02 2017 11:47
oh my god
i thought u cant make functions in function
cuz they loop twice
ive thought about it be4
but predicted it wouldnt work
btw can you explain me how the initial value works
what is it used for?
im thiinkin of using filters and indexOf inside the reduce is that cool?
Pieter Stokkink
@forkerino
Jul 02 2017 11:50
@koder3 initial value will be the value of the first argument in the first round. If it is omitted, the first argument will be the first element in the array. When working with primitive types, like numbers, it is often possible to not use initial value, but if you use something more complex, like an object or array, it often becomes useful, depending on what you need to get out of the .reduce
@koder3 filter + indexOf sounds good.
Go puzzle a little and come back once you have something more
koder3
@koder3
Jul 02 2017 11:52
thanks a lot @forkerino
CamperBot
@camperbot
Jul 02 2017 11:52
koder3 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2808 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jul 02 2017 11:52
:+1:
koder3
@koder3
Jul 02 2017 11:52
so the initial value
is like [i] ??
Pieter Stokkink
@forkerino
Jul 02 2017 11:53
not sure I'm following

If you have

arr.reduce(function(acc, curr, index){
//....
}, 0);

the first cycle, acc will be 0. If there was no 0 as initial value, the first time acc would be arr[0]

koder3
@koder3
Jul 02 2017 11:55
for example in a for loop you can use arr[i] to loop through each element in the array, does the initial value accomplish something similar
i read this on the forum but it didnt make any sense So, we can deduce that reduce() takes your custom callback and executes it on each element of the Array. While doing so, it makes the current item available to the custom callback as item argument. what does that mean?
Pieter Stokkink
@forkerino
Jul 02 2017 11:56
@koder3 not really, it is more like an outside variable that you alter inside a loop as product in the example
var product = 1;
for (var i  = 0; i< arr.length; i++){
  product *= arr[i];
}
Dan Couper
@DanCouper
Jul 02 2017 11:56
It's more like you're declaring a variable before the loop, then doing stuff to it in the loop.
Ah, snap
Pieter Stokkink
@forkerino
Jul 02 2017 11:57
@koder3 that sentence you quoted is very dense
i have named the current item curr above.
@DanCouper :smile:
Great minds think alike
koder3
@koder3
Jul 02 2017 11:59
alright. whats a custom callback ?
teevik
@teevik
Jul 02 2017 12:00
The function you pass in the reduce method
Dan Couper
@DanCouper
Jul 02 2017 12:00
Just a function that you've written that you give to reduce
koder3
@koder3
Jul 02 2017 12:01
it makes the current item available to the custom callback as item argument. what does this mean
Pieter Stokkink
@forkerino
Jul 02 2017 12:02
@koder3 if you have a callback like so: function(accumulator, item){, item is the parameter containing the current item, it is always the second parameter of the callback.
koder3
@koder3
Jul 02 2017 12:03
is the current item the first element of the array in the first iteration ?
Pieter Stokkink
@forkerino
Jul 02 2017 12:04
@koder3 only if there is an initial value
otherwise it is the second element
and the first element becomes the accumulator
koder3
@koder3
Jul 02 2017 12:07
function sym(args) {


var w = []
var e = Array.prototype.slice.call(arguments)
return e.reduce(function(a, b){
return b
}, )

}
sym([1, 2, 3], [5, 2, 1, 4])
when i return b i get the second array [5, 2, 1, 4] and when i return a instead of b, i get the first array [1, 2, 3] why is that
Pieter Stokkink
@forkerino
Jul 02 2017 12:08
because there is no initial value, try putting in a 0 or something and see how the return values change
koder3
@koder3
Jul 02 2017 12:09
b didnt change. a gave me 0
why does b just give me the second array ?
i though it iterates through the first array
Pieter Stokkink
@forkerino
Jul 02 2017 12:10
@koder3 e is an array of arrays. b will be the current subarray. So each cycle you return the current subarray and finally the last subarray will be the result of the reduce.
@koder3 fyi, you cannot understand everything about it just by thinking about it, build something with it and you'll learn it much quicker.
korzo
@korzo
Jul 02 2017 12:11
@koder3 If you omit initial value for reduce first element of array is not processed by reduce and rather is passed as accumulator at first pass
@koder3 So in your code a is first array and b is second array
koder3
@koder3
Jul 02 2017 12:16
@forkerino @korzo alright thaks a lot.
UnkyKong
@UnkyKong
Jul 02 2017 12:39
https://codepen.io/Unky/pen/WOzozg?editors=0010
I'm recieving an object of objects and i can't figure out how to iterate on each inner object
Stephen James
@sjames1958gm
Jul 02 2017 12:41
@UnkyKong you can use Object.keys to get an array of keys, or use for .. in loop
UnkyKong
@UnkyKong
Jul 02 2017 12:43
@sjames1958gm I found that. was trying to Object.keys(obj).length
ok, now how do i access each inner object. obj[0] returns null
Hemakshi Sachdev
@hemakshis
Jul 02 2017 12:47
Hey everyone.. I am trying to make my search box expand on mouseenter nd if the input box has not been focused then hide it again.. this all works fine but when i make the input box focused nd then click somewhere else in my window to make the focus go away my input box does not hides.. i've tried doing this by a lot of ways but nothing seems to work.. can please someone suggest me how to do it, here's my pen -
https://codepen.io/hemakshis/pen/BZrYjZ
koder3
@koder3
Jul 02 2017 12:48
function sym(args) {


var w = []
var e = Array.prototype.slice.call(arguments)

var ewew = e.reduce(function(a, b){
return a.filter(function(val){
if (b.indexOf(val) === -1 ){
return val
}


})

})

var wqw = e.reduce(function(a, b){
return b.filter(function(val){
if (a.indexOf(val) === -1 ){
return val
}
})                
})
return ewew.concat(wqw)



}
sym([3, 3, 3, 2, 5], [2, 1, 5, 7], [3, 4, 6, 6], [1, 2, 3])
im able to pass the first 6 tests but why not the others? @forkerino
UnkyKong
@UnkyKong
Jul 02 2017 12:49
@hemakshis that looks so cool
maybe
Odin Jorna
@OdinJorna
Jul 02 2017 12:56
hey coders, I am trying to do the Seek and Destroy challange, but I am getting errors that .pop() and .filter() are not a function. What am i doing wrong?

function destroyer(arr) {
  // Remove all the values

  var valueToDestroy = arr.pop().pop();

for (var i = 0; i < arr.length; i++) {
var newArr = arr[i].filter(function check(arrayValue){
    return arrayValue != valueToDestroy;
});

  return newArr;
}
                 }

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Stephen James
@sjames1958gm
Jul 02 2017 12:59
@OdinJorna arr is only the array [1, 2, 3, 1, 2, 3] you will need to use the arguments object (link in instructions) to access other values passed in
Odin Jorna
@OdinJorna
Jul 02 2017 12:59
@sjames1958gm i tried that too but that still gives me the same errors
Stephen James
@sjames1958gm
Jul 02 2017 13:01
well pop().pop() wouldn't work because pop would return a number so the second pop() is invalid.
you need to filter on arr, not arr[i]
Pieter Stokkink
@forkerino
Jul 02 2017 13:01
@koder3 not sure I understand your logic. Maybe concatenate inside the reduce, so you won't have to use two of them? And check if each element is in one but not two of the arrays?
Stephen James
@sjames1958gm
Jul 02 2017 13:02
@OdinJorna probably best to convert arguments to an array - as arguments doesn't have the same set of functions as an array
mithun
@dmithun
Jul 02 2017 13:03
unction confirmEnding(str, target) {
// "Never give up and good luck will find you."
// -- Fstalcor
var x=str.slice(-1);
return x===target;
}
confirmEnding("Bastian", "n");
Odin Jorna
@OdinJorna
Jul 02 2017 13:03
@sjames1958gm okay
mithun
@dmithun
Jul 02 2017 13:03
how am i gonna compare between this two words("sesame" & "same") in this challenge ?
Pieter Stokkink
@forkerino
Jul 02 2017 13:03
@dmithun you're gonna need a bigger slice
Hemakshi Sachdev
@hemakshis
Jul 02 2017 13:05
@UnkyKong Hehe.. thanks :)
but along with too cool things come tooo much of complications.. nd so now i am cursing on why i made it so complicated.. but the effort is worth it i'm learning a lot with this..
Thankyou it worked.. even though i tried focusout previously but it was making things even worse but this time i did with more care.. thnku :)
CamperBot
@camperbot
Jul 02 2017 13:05
hemakshis sends brownie points to @unkykong :sparkles: :thumbsup: :sparkles:
:cookie: 265 | @unkykong |http://www.freecodecamp.com/unkykong
koder3
@koder3
Jul 02 2017 13:10
@koder3 not sure I understand your logic. Maybe concatenate inside the reduce, so you won't have to use two of them? And check if each element is in one but not two of the arrays?
how do i access each element ? @forkerino
Kelechi Chinaka
@ke1echi
Jul 02 2017 13:12
function countPositivesSumNegatives(input) {
  var sum = [], count = [], output = [];  
  input.map( function (element) {
      if (element >= 0) {
        count.push(element)
      }else {
        sum.push(element);
      }
  });
  sum = sum.reduce( function (a, b) { return a + b }, 0);
  output.push(count.length);
  output.push(sum)
  return output;
}
the code is verbose, wud refactor soon
it passed all test cases except one
TypeError: Cannot read property 'map' of null
@forkerino @sjames1958gm
i dont understand that error msg
Stephen James
@sjames1958gm
Jul 02 2017 13:12
@kelechichinaka can input be null?
Maks Ushakov
@maks-ushakov
Jul 02 2017 13:13
@kelechichinaka Can you show full falled test case?
Stephen James
@sjames1958gm
Jul 02 2017 13:14
@kelechichinaka just use reduce on input, don't build an array to reduce.
You are just using map as a loop, use forEach if you are not really mapping.
Anyway the map seems extraneous
Oliver Webb
@Ollie15
Jul 02 2017 13:15
Anyone on profile lookup javascript challenge looking for someone to pair code with?
Kelechi Chinaka
@ke1echi
Jul 02 2017 13:16
yes input could be empty or null @sjames1958gm
Maks Ushakov
@maks-ushakov
Jul 02 2017 13:16
how does the pair coding work?
Stephen James
@sjames1958gm
Jul 02 2017 13:16
Then you need to check for that.
Oliver Webb
@Ollie15
Jul 02 2017 13:16
@maks-ushakov just over skype or somthing
*something
ISU
@isu17
Jul 02 2017 13:17
how to go about the apis for the weather app, I found dark sky api on github etc. but it needs to be installed, while codepen you can only use cdn stuff or stuff that are built in, should I make a site on its own or something ? Or is there any other apis that are lighter and can work as a little js lib ?
Pieter Stokkink
@forkerino
Jul 02 2017 13:19
@koder3 that's what filter does for you
koder3
@koder3
Jul 02 2017 13:20
@forkerino am i supposed to filter through a or b?
Stephen James
@sjames1958gm
Jul 02 2017 13:22
@isu17 darksky has an API that can be queried using ajax (using getJSON) nothing has to be installed
there might be backend support for darksky but that is different
ISU
@isu17
Jul 02 2017 13:25
ohh my bad
Pieter Stokkink
@forkerino
Jul 02 2017 13:25
@koder3 the concatenation of a and b, that way you have all values in both, and filter out the ones you don't need. The resulting array can then go on to the next cycle as accumulator of the reduce.
ISU
@isu17
Jul 02 2017 13:25
@sjames1958gm any guide lines on where to start ?
Amit Patel
@AmitP88
Jul 02 2017 13:25
hey guys, how do I get better at solving algorithms? Whenever I try to solve one on FCC, I always hit a wall and end up wasting hours before resorting to finding the solution online (which I hate doing). I want to be able to solve them on my own, but I can never see the solution even after reading through the provided documentation links. Anyone else struggle with this problem? =/
Stephen James
@sjames1958gm
Jul 02 2017 13:27
@isu17 This is the website to start at https://darksky.net/dev/
They should have some examples of the URL that is required to request the data.
ISU
@isu17
Jul 02 2017 13:31
thanks @sjames1958gm
CamperBot
@camperbot
Jul 02 2017 13:31
isu17 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7978 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
ISU
@isu17
Jul 02 2017 13:33
@AmitP88 I have the same problem, but try not to look for ready solution and just copy it, instead try to read the question several times, understand what is wanted from you, pen and paper might help, writing down stuff you might need, and try do dissolve the problem into many smaller ones. Thats what I do and it helps, I still (at times) spend hours when I encounter something new, but overall it gets better in time. Don't worry.
Amit Patel
@AmitP88
Jul 02 2017 13:34
@isu17 thank you. yeah, I tend to spend a lot of time doing that too. Even got a whiteboard just for algorithms and I tend to write pseudocode first for each step. I guess I just have to get better at reading and piecing together the documentations
CamperBot
@camperbot
Jul 02 2017 13:34
amitp88 sends brownie points to @isu17 :sparkles: :thumbsup: :sparkles:
:cookie: 266 | @isu17 |http://www.freecodecamp.com/isu17
Ahmed Ramy
@Shadilix
Jul 02 2017 13:34

function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  if (target===str.substr(str.length -1))
    {
      return true;
    }
  else{return false;}
}

confirmEnding("Bastian", "n");
so i manged to get this far to check if the last letter is true
now i need to add something so that there would be a check for the last word too ... any ideas ?
Pieter Stokkink
@forkerino
Jul 02 2017 13:37
@Shadilix you'll need a more dynamic substring
Ahmed Ramy
@Shadilix
Jul 02 2017 13:38
yea ,true
Pieter Stokkink
@forkerino
Jul 02 2017 13:38
The length should depend on the length of target
Ahmed Ramy
@Shadilix
Jul 02 2017 13:38
but i thought that i only need to check the last letter so that would be achieved by this simple if condition
Pieter Stokkink
@forkerino
Jul 02 2017 13:41
90% of solving the problem is understanding what the problem asks for
koder3
@koder3
Jul 02 2017 13:47
@forkerino i passed all the tests but the issue is they have more elements than needed. to be specific they have a duplicate of one of those elements
function sym(args) {


var w = []
var e = Array.prototype.slice.call(arguments)

var u = e.reduce(function(a, b){
return a.concat(b).filter(function(val){
if (b.indexOf(val) === -1 ) {
return val
}
if (a.indexOf(val) === -1){
return val
}



})


})

return u

}
sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5])
not passing 3 of them because i have more elements than they want
Pieter Stokkink
@forkerino
Jul 02 2017 13:53
@koder3 I think you may need to remove duplicate values before the reduce
maybe after works as well
Ahmed Ramy
@Shadilix
Jul 02 2017 13:57

function repeatStringNumTimes(str, num) {
  // repeat after me
   str = str.repeat(num);

  return str;
}

repeatStringNumTimes("abc", 3);
okay now every challenge is checked except the one which asks if the num = -2 it should return " "
if ( num < 0 )
{
   return str = "";
}
would that work ?
koder3
@koder3
Jul 02 2017 13:59
@forkerino solved it. thanks for all the help.
CamperBot
@camperbot
Jul 02 2017 13:59
koder3 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2809 | @forkerino |http://www.freecodecamp.com/forkerino
koder3
@koder3
Jul 02 2017 14:00
@forkerino why do i get duplicates? any clue?
Stephen James
@sjames1958gm
Jul 02 2017 14:18
@koder3 You need to return true/false not the value from filter, I think it is accidently working for some cases.
@koder3 They want you to remove duplicates. 1, 1, 2, 5 is going to pass both 1s.
koder3
@koder3
Jul 02 2017 14:19
@sjames1958gm why would i need to return true/false ?
Stephen James
@sjames1958gm
Jul 02 2017 14:20
@koder3 If any of the values in the array were falsy then return val would not keep them
@koder3 It might pass these tests, but in my mind it wouldn't be correct
koder3
@koder3
Jul 02 2017 14:24
i understand. what should i change then? @sjames1958gm
Stephen James
@sjames1958gm
Jul 02 2017 14:25
@koder3 My code removed the duplicates from each array before doing the difference
koder3
@koder3
Jul 02 2017 14:28
@sjames1958gm i too feel like some of the things i did were quite random. can you explain why exactly you think my code is not correct? i could use the info to make some changes
Stephen James
@sjames1958gm
Jul 02 2017 14:31
@koder3 Your code should work, if none of the input arrays had duplicates, since they do your code doesn't remove them.
sym([1, 1, 2, 5], [2, 2, 3, 5], [3, 4, 5, 5]) for example.
I would also suggest that when you post your code, post an example of one that fails and the bad result
koder3
@koder3
Jul 02 2017 14:38
i remeoved the duplicates at the end then i passed the challenge, is that not a good approach? example of what, i dont understand. @sjames1958gm
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 14:38
@Shadilix repeat() returns repeated string, only if the value of count is non-negative. If its a negative value it will throw an error RangeError: repeat count must be non-negative. But if you like you can create your own repeat() like function with + operator by concatenating the strings to an empty string, multiple times, so then you don't need to do the if(num<0) part.

@Shadilix
Try this

repeatStringNumTimes("abc", 2.9999999999999999); // "abcabcabc"

and this

repeatStringNumTimes("abc", 2.99999); // "abcabc"

With repeat();

Vasile Cojusco
@AlexK89
Jul 02 2017 14:43

hi, everyone. I am working on my quote machine and got the issue. I want to add a string as a part of href. I have wrote that code

quoteToLink = "https://twitter.com/intent/tweet?text=" + quoteStr;

but it returned me

"https://twitter.com/intent/tweet?text="I begin by taking. I shall find scholars later to demonstrate my perfect right.””

how to remove extra quotes

Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 14:44
@AlexK89 put \" to escape quotes
or use ' inside of string, and " to wrap the whole string.
Vasile Cojusco
@AlexK89
Jul 02 2017 14:45
@saifsmailbox98 I have thought about it but it will work for the berining of “quoteStr"
the string is from the object
so all I can do is transform it to something
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 14:47
@AlexK89 is quoteStr a string?
Vasile Cojusco
@AlexK89
Jul 02 2017 14:47
manually - yes, it will work, but what if I haven’t control under the quoteStr.
@saifsmailbox98 yes
it is a string
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 14:48
then quoteToLink must also be a string.
Vasile Cojusco
@AlexK89
Jul 02 2017 14:48
I need something like “filter” for arrays
jordyweerwag
@jordyweerwag
Jul 02 2017 14:48

what do i wrong it says

here is a list what i must do:

myVar should equal 88 DONE
myVar = myVar should be changed NOT DONE
Use the ++ operator DONE
Do not change code above the line DONE

var myVar = 87;

// Only change code below this line
myVar = ++myVar;
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 14:48
@jordyweerwag just myVar++
no need to asssign it back
++ operator increments and assigns back.
Vasile Cojusco
@AlexK89
Jul 02 2017 14:49
@jordyweerwag
myVar++
jordyweerwag
@jordyweerwag
Jul 02 2017 14:49
oke thanks
Vasile Cojusco
@AlexK89
Jul 02 2017 14:51

@saifsmailbox98

quoteStr.slice(1,-1);

works for me))

Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 14:52
@AlexK89 I think you have quotes " inside quoteStr.
you can escape that.
:+1:
Vasile Cojusco
@AlexK89
Jul 02 2017 14:54
yes they were)
Bennpierce4077
@Bennpierce4077
Jul 02 2017 14:58
hello
Robert Fischer
@midknight23
Jul 02 2017 14:59
Any tips for which API to use for the random quote generator?
Ogundele Olumide
@Lumexralph
Jul 02 2017 15:04
@midknight23 some people use forismatic I think if I am right
Marco Galizzi
@Tezenn
Jul 02 2017 15:04
hello guys if i have an array of objects and i want to change one key and one value of each object what should i do
Ogundele Olumide
@Lumexralph
Jul 02 2017 15:06
@midknight23 some people use forismatic API I think
@Bennpierce4077 Hi
Pieter Stokkink
@forkerino
Jul 02 2017 15:06
@Tezenn what was your first idea?
Robert Fischer
@midknight23
Jul 02 2017 15:06
Thanks @Lumexralph
CamperBot
@camperbot
Jul 02 2017 15:06
midknight23 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 2015 | @lumexralph |http://www.freecodecamp.com/lumexralph
Stephen James
@sjames1958gm
Jul 02 2017 15:08
@Tezenn If you have an array and want to change each element, array.map comes to mind
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 15:11
pick up an object, select the key, assign the value.
@Tezenn
Robert Fischer
@midknight23
Jul 02 2017 15:18
Is it cheating if you use the same API as the one in the example?
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 15:19
@midknight23 no.
Marco Galizzi
@Tezenn
Jul 02 2017 15:19
@sjames1958gm @saifsmailbox98 @forkerino thanks guys today i'm a bit hangover and i can't focus too well, in the end i used map
var x = arr.map(function(item){
    var A = earthRadius + item.avgAlt;
    var T = (2*Math.PI)*(Math.sqrt(Math.pow(A,3) / GM));
    item.orbitalPeriod = Math.round(T);
    delete item.avgAlt;
    return item;

  });
  return x;
CamperBot
@camperbot
Jul 02 2017 15:19
tezenn sends brownie points to @sjames1958gm and @saifsmailbox98 and @forkerino :sparkles: :thumbsup: :sparkles:
:cookie: 692 | @saifsmailbox98 |http://www.freecodecamp.com/saifsmailbox98
:star2: 2810 | @forkerino |http://www.freecodecamp.com/forkerino
:star2: 7979 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 15:19
@Tezenn :+1:
Alexandru Marian
@marinik17
Jul 02 2017 15:36
Hello everybody. I have a small issue. It is just me or somethig is wrong with my code,because i can`t see displayed my current location. here is the link to my project: https://codepen.io/marinik17/pen/bRvMOq
anybody?
@saifsmailbox98 can you hel me,please?
*help me
@sjames1958gm maybe you can help me with my small issue?
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 15:42
@marinik17 you don't have an element with id="data"
Jonathan Meier
@jntme
Jul 02 2017 15:42
@marinik17 do you receive the mixed content error?
Saif Ur Rahman
@saifsmailbox98
Jul 02 2017 15:43
@marinik17 try $("#city").html("latitude: " + lat + "<br>longitude: " + long);
@marinik17 As you are working on codepen, you can't use http, codepen now supports only https
try putting this before api url https://cors-anywhere.herokuapp.com/
Alexandru Marian
@marinik17
Jul 02 2017 15:45
ok
Alexandru Marian
@marinik17
Jul 02 2017 15:53
still not working
:(
I put also an par