These are chat archives for FreeCodeCamp/HelpJavaScript

18th
Jul 2017
Christian
@Neralizer
Jul 18 2017 00:07
thanks @JLuboff
CamperBot
@camperbot
Jul 18 2017 00:07
neralizer sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2077 | @jluboff |http://www.freecodecamp.com/jluboff
Guderian Raborg
@hypercuber
Jul 18 2017 00:09
help me out here: http://beta.freecodecamp.com/en/challenges/regular-expressions/match-single-characters-not-specified

let quoteSample = "3 blind mice.";
let myRegex = /^aeiou0-9/; // Change this line
let result = quoteSample.matches(myRegex); // Change this line
Diego Mayer
@Chrono79
Jul 18 2017 00:10
@hypercuber you missed the []
and the flags
Guderian Raborg
@hypercuber
Jul 18 2017 00:12
@Chrono79 like this?

let quoteSample = "3 blind mice.";
let myRegex = /[^aeiou0-9]/gi; // Change this line
let result = quoteSample.matches(myRegex); // Change this line
Diego Mayer
@Chrono79
Jul 18 2017 00:12
does it work?
it's match, not matches
the regex is ok
Guderian Raborg
@hypercuber
Jul 18 2017 00:14
no but if you are sure then it might be a glitch. I know that in responsive design there was one lesson I could not submit it because of a glitch
Diego Mayer
@Chrono79
Jul 18 2017 00:15
let result = quoteSample.match(myRegex); // Change this line
Guderian Raborg
@hypercuber
Jul 18 2017 00:16
@Chrono79 That works. Didnt see that. Thanks a lot.
CamperBot
@camperbot
Jul 18 2017 00:16
hypercuber sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4489 | @chrono79 |http://www.freecodecamp.com/chrono79
Gurpreet SIngh
@Gurpreet3131
Jul 18 2017 00:20
res.render('index', {views: count});
Is there any other way than this to send data to the handlebars webpage by nodejs?
Rasmus Biehl
@RasBiehl
Jul 18 2017 00:30
Can anyone plz help me with my JS ?, that would be great.
Sam
@sdedison
Jul 18 2017 00:38
Hi all - struggling with using array functions within a reduce function (for the "sorted union" challenge
var cleaned = flattened.reduce(function(accum, curVal, index) {
if (index === 0) {
return accum.push(curVal);
} else if (accum.indexOf(curVal) !== -1) {
return accum.push(curVal);
} else {
return;
}
}, []);
This will run the callback once, and return the first value (it passes the first condition)
but then on the second pass, I get "indexOf is not a function" error
shouldn't the accum value be an array?
Stephen James
@sjames1958gm
Jul 18 2017 00:46
@sdedison You need to return accum, not the result of push (push returns a number and you lose the array)
Sam
@sdedison
Jul 18 2017 00:47
ahh
Stephen James
@sjames1958gm
Jul 18 2017 00:47
@RasBiehl As your question
@Gurpreet3131 You have to pass an object to get the data to the template
Sam
@sdedison
Jul 18 2017 00:49
@sjames1958gm if I simply return accum, will it add on the "curVal" to the resulting array automatically?
Stephen James
@sjames1958gm
Jul 18 2017 00:49
@sdedison No. Don't return inside the if/else, just return accum after the if/else (still doing the push)
@Gurpreet3131 Are you using express-handlerbars?
Sam
@sdedison
Jul 18 2017 00:58
@sjames1958gm Ah - got it to work now! Thank you, (now I feel like I get the reduce function)
CamperBot
@camperbot
Jul 18 2017 00:58
:star2: 8094 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
sdedison sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
Kent Saeteurn
@sansae
Jul 18 2017 01:09

Hi all,

I'm revisiting the local weather challenge. In my attempt to recreate the app from scratch in codepen.io, I discovered something wrong with my code: all of my javascript functions are not working when nested inside "document.ready". I don't know why this is. When I exclude it, it works perfectly. Can anyone help me figure this out?

I tested the following and here's what I found:

//does work
$(document).ready(function() {
  window.myFunction = function() {
    $("#sayHi").html("hi");
  };
});

//does not work, but if I take out document.ready, it does
$(document).ready(function() {
  function myFunction() {
    $("#sayHi").html("hi");
  };
});

I tried the "window." for all of my functions but this did not work. I found "window." while searching through the Stack Overflow forums. The interesting thing is that I never had to use this in my jquery. When I did the weather app challenge last year, I was able to create a working app without it. What's going on? My app, at the moment, works without "window." if I take out document.ready, but for best practice, shouldn't I include "document.ready"?

Michael Duh
@mikaeloduh
Jul 18 2017 01:10
@sansae
$(document).ready(function() {
  function myFunction() {
    $("#sayHi").html("hi");
  };
  myFunction();
});
@sansae Your first code defined a function variable which will execute, second code jsut a declare function.
John
@AnonymousLords
Jul 18 2017 01:17
Guys why doesnt this add to to myMusic?
var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  } 
  "artist": "Donald Trump",
  "title": "Do you want to build a wall?",
  "release_year": 2016,
  "formats": [
  "CD",
  "HTML" ]
];
Im confused on how to add it?
Im not given a clear instrution on how to add values
John
@AnonymousLords
Jul 18 2017 01:22
Karan Nandha
@karann7
Jul 18 2017 01:24
hello guys feel free to join me and code along in making an app in react native on twitch
Ken Haduch
@khaduch
Jul 18 2017 01:26
@AnonymousLords - myMusic is an array, containing one object. You should make a second object in exactly the same format - all of the curly brackets, properties, etc. And array element should be separated by a comma, even if they are objects. [ { }, { } ]
Michael Duh
@mikaeloduh
Jul 18 2017 01:28
@AnonymousLords
var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  } ,
{
  "artist": "Donald Trump",
  "title": "Do you want to build a wall?",
  "release_year": 2016,
  "formats": [
  "CD",
  "HTML" ]
}]
John
@AnonymousLords
Jul 18 2017 01:29
This still doesnt work?

var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  } , 
  {"artist": "Donald Trump"} , {"title": "Do you want to build a wall?"} , {"release_year": 2016,} , {"formats": ["CD", "HTML"] }
];
myMusic[1] should contain a title property which is a string
myMusic[1] should contain a release_year property which is a number
myMusic[1] should contain a formats property which is an array
formats should be an array of strings with at least two elements
Ken Haduch
@khaduch
Jul 18 2017 01:30
@AnonymousLords - they are not to be separate objects.
John
@AnonymousLords
Jul 18 2017 01:30
oh
Ken Haduch
@khaduch
Jul 18 2017 01:30
copy the original object, paste it, separate the two objects with commas, change the title, etc. in the second one. That should work.
John
@AnonymousLords
Jul 18 2017 01:30
It worked, thx @khaduch @khaduch
CamperBot
@camperbot
Jul 18 2017 01:30
anonymouslords sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3114 | @khaduch |http://www.freecodecamp.com/khaduch
John
@AnonymousLords
Jul 18 2017 01:31
How long have you been coding> @khaduch
btw this was teh final code

var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  } , 
  {"artist": "Donald Trump" , "title": "Do you want to build a wall?" , "release_year": 2016 , "formats": ["CD", "HTML"] }
];
Ken Haduch
@khaduch
Jul 18 2017 01:32
@AnonymousLords - various types of coding for a LOOOOOOOONNNNNGGGGGG time... web stuff for a couple years (or three or four?)
John
@AnonymousLords
Jul 18 2017 01:33
wow
FIrst year coding for me
first couple months, really.
Ken Haduch
@khaduch
Jul 18 2017 01:34
@AnonymousLords - when it's new, it is sometimes difficult! You always have to keep the basics in mind at this stage - for this problem, recognizing the data structure that you are dealing with is key. It looks complicated because the declaration of an object is arbitrarily complex, but you just go back to basics all the time...
John
@AnonymousLords
Jul 18 2017 01:35
I wish they showed more examples.
Ken Haduch
@khaduch
Jul 18 2017 01:46
@AnonymousLords - I think that it's a fine line to tread about how many examples to show. Possibly early on it would be more helpful? But I think that it's a balancing act between making the lessons concise, and relying on the foundation of knowledge that is being acquired to help make the (slightly) more complex things approachable. I'm sure that if you went back and carefully read the full description of that lesson, now that you have the solution worked through, it would make more sense. That's one thing about learning this - you have to get to the point where you understand how to use the examples and descriptions that are given. For many of these introductory lessons, they all but give the answer through carefully crafted examples and text. It's just part of the learning process, I would say...
Grigor Minasyan
@gogminsam
Jul 18 2017 01:57
Hey guys I have super simple question (I am really new here) trying to do wikipedia think, and stuck on jquery autocomplete, here is the link to codepen https://codepen.io/gogminsam/pen/pwmRgq and jsfiddle https://jsfiddle.net/gogminsam/m0uodLLa/ I just can't understand why it doesn't work normally in codepen
John
@AnonymousLords
Jul 18 2017 01:57
@khaduch okay, also how long on FCC?
Grigor Minasyan
@gogminsam
Jul 18 2017 01:58
Why in codepen it brings unordered list? and in jsfiddle it works perfectly
Gulsvi
@gulsvi
Jul 18 2017 02:05
@gogminsam Did you maybe forget a theme css file?
(add to your CSS settings in codepen)
Grigor Minasyan
@gogminsam
Jul 18 2017 02:13
@SkyC0der thanks, as i said i'm super beginner, i didn't know i had to include styles, hope I will be able to learn.
CamperBot
@camperbot
Jul 18 2017 02:13
gogminsam sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:star2: 2138 | @skyc0der |http://www.freecodecamp.com/skyc0der
Ken Haduch
@khaduch
Jul 18 2017 02:14
@AnonymousLords - I've been at this for well over a year - bogged down with projects, and conflicts of interest... I keep trying to get back to it!
Gulsvi
@gulsvi
Jul 18 2017 02:14
@gogminsam You're in the right place to ask beginner questions. Glad it worked.
John
@AnonymousLords
Jul 18 2017 02:18
i'm supposed to be coding, but i'm listening to "Spongebob Squarepants - Camp Fire Song [Trap Remix]" Productive day.
Ronique Ricketts
@RoniqueRicketts
Jul 18 2017 02:20
@AnonymousLords go code right now!!!
John
@AnonymousLords
Jul 18 2017 02:22
okay after this song called "SPONGEBOB RAPS PANDA!!!!(krabs diss track)"
especially, implementing enqueue method
Manish Giri
@Manish-Giri
Jul 18 2017 02:33
I think I have
@hupadhyayula
harishgeeth
@hupadhyayula
Jul 18 2017 02:34
do you have a gist of it? @Manish-Giri
Manish Giri
@Manish-Giri
Jul 18 2017 02:35
@hupadhyayula gist?
harishgeeth
@hupadhyayula
Jul 18 2017 02:35
@Manish-Giri
Manish Giri
@Manish-Giri
Jul 18 2017 02:36
oh that
harishgeeth
@hupadhyayula
Jul 18 2017 02:36
:)
Manish Giri
@Manish-Giri
Jul 18 2017 02:36
no I don't use gists
harishgeeth
@hupadhyayula
Jul 18 2017 02:36
is there any way, I can take a look @ your code
Manish Giri
@Manish-Giri
Jul 18 2017 02:36
yup
if you want
this.enqueue = function(arr) {
    //let item = arr[0];
    let priority = arr[1];
    if(!this.collection.length) {
      this.collection.push(arr);
    }
    else {
          for(let i = 0; i < this.collection.length; i++) {
            if(priority >= this.collection[i][1]) {
              //current item has higher priority
                this.collection.splice(i, 0, arr);
                return;
           }      
        }
      this.collection.push(arr);
    }

  };
Saikat-Sinha
@Saikat-Sinha
Jul 18 2017 02:40
guys is there any way that everytime my array goes through some operations like push , pop etc. I can re-render my HTML...
Claudio Restifo
@Marmiz
Jul 18 2017 02:50

@Saikat-Sinha let's say you create a function to render the html:

function renderHtml(arr){
 // loop into array
// render the data
}

Then when another method changes the desired array, all i can do is call this function at the end:

function changeValues(newVal){
// do something with the new value like push into array.
//pass it to rederHtml function
renderHtml(newArr)
}
Saikat-Sinha
@Saikat-Sinha
Jul 18 2017 03:05
@Marmiz thanks bro
CamperBot
@camperbot
Jul 18 2017 03:05
saikat-sinha sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1001 | @marmiz |http://www.freecodecamp.com/marmiz
Joseph
@revisualize
Jul 18 2017 03:11
Hello.
kumquatfelafel
@kumquatfelafel
Jul 18 2017 03:11
hi
abraham anak agung
@padunk
Jul 18 2017 03:12
Hi, anybody use repl.it?
kumquatfelafel
@kumquatfelafel
Jul 18 2017 03:12
from time to time, yes
Joseph
@revisualize
Jul 18 2017 03:14
@padunk I do.
abraham anak agung
@padunk
Jul 18 2017 03:14
how to add library for symbol? i write this code but the print out is empty
const bowl = {
  [Symbol('apple')]: { color: 'red', weight: 136.078 },
  [Symbol('banana')]: { color: 'yellow', weight: 183.15 },
  [Symbol('orange')]: { color: 'orange', weight: 170.097 },
  [Symbol('banana')]: { color: 'yellow', weight: 176.845 }
};
console.log(bowl);
Joseph
@revisualize
Jul 18 2017 03:14
@padunk How do you what?
@padunk I don't think you can use external libraries with repl.it
abraham anak agung
@padunk
Jul 18 2017 03:15
@revisualize add library or something so it could read Symbol es6 symbol
Ooo...ok. my console.log(bowl) return {}
Joseph
@revisualize
Jul 18 2017 03:17
@padunk Why are your object key's arrays?
kumquatfelafel
@kumquatfelafel
Jul 18 2017 03:17
Joseph
@revisualize
Jul 18 2017 03:17
@padunk Your object key's can't be array's.
Don't object key's need to be strings?
kumquatfelafel
@kumquatfelafel
Jul 18 2017 03:18
Actually... @padunk https://repl.it/IYQ3
Joseph
@revisualize
Jul 18 2017 03:19
But, look at their object key's
abraham anak agung
@padunk
Jul 18 2017 03:19
Joseph
@revisualize
Jul 18 2017 03:19
They aren't strings.
@padunk I don't care about that.
@padunk Look
Moisés Man
@moigithub
Jul 18 2017 03:20
es7 feature computed properties or was es6?
{["a"+1 ]: "value"} --> will create {"a1":"value"}
Joseph
@revisualize
Jul 18 2017 03:20
var myObj = {
     []: "Text"
};
That isn't valid.
kumquatfelafel
@kumquatfelafel
Jul 18 2017 03:21

Whoops... looks like posted wrong thing... In any case...

Repl.it supports import for ES6 https://repl.it/site/blog/changelog_5_30_17

abraham anak agung
@padunk
Jul 18 2017 03:21
@moigithub i think it was es6
ok . thanks @kumquatfelafel try to look at that too
CamperBot
@camperbot
Jul 18 2017 03:22
padunk sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 481 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Joseph
@revisualize
Jul 18 2017 03:23
@padunk I don't understand why you're trying to make an Object where you can't access any of the properties.
abraham anak agung
@padunk
Jul 18 2017 03:25
@revisualize :smile: i still learning, still playing with this new ES6 thing.
Joseph
@revisualize
Jul 18 2017 03:26
@padunk If I was trying to learn about Symbol... I wouldn't compound it with something that could add complication.
abraham anak agung
@padunk
Jul 18 2017 03:30

@revisualize i was try to acces this

const bowl = {
  'apple': { color: 'red', weight: 136.078 },
  'banana': { color: 'yellow', weight: 183.151 },
  'orange': { color: 'orange', weight: 170.097 },
  'banana': { color: 'yellow', weight: 176.845 }
};
console.log(bowl);

if you access banana, the first banana will get overwrite by the second, unless i give it different string name

Joseph
@revisualize
Jul 18 2017 03:32
@padunk So, you'll need another data type.
kumquatfelafel
@kumquatfelafel
Jul 18 2017 03:32
@padunk console.log may not be written in a way that the symbol information is accessible... (dunno, haven't really messed with 'em)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertySymbols maybe?
abraham anak agung
@padunk
Jul 18 2017 03:35
@kumquatfelafel yes maybe, i add this var es6Symbol = require('es6-symbol'); from https://github.com/medikoo/es6-symbol#readme in repl.it but still showing nothing in console.log
kumquatfelafel
@kumquatfelafel
Jul 18 2017 03:43
@padunk I think you were supposed to call it Symbol
i.e. Symbol basically holds Symbol. If you store it in variable called es6Symbol instead, you might have to use that instead of Symbol later on.
but again, I'm not very familiar with these aspects of javascript yet.
abraham anak agung
@padunk
Jul 18 2017 03:47
@kumquatfelafel neither do I :smile: just touching the skin of it. but thanks for looking at this.
CamperBot
@camperbot
Jul 18 2017 03:47
padunk sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:warning: padunk already gave kumquatfelafel points
kumquatfelafel
@kumquatfelafel
Jul 18 2017 03:48
@padunk though yeah, from impression I'm getting, start out by trying
var Symbol = require('es6-symbol');
kumquatfelafel
@kumquatfelafel
Jul 18 2017 03:58
Okay... importing symbol like this will work. Not only that, you can remove this statement after you first run program/import it
Guderian Raborg
@hypercuber
Jul 18 2017 04:21
Can someone help me make the array bigger if there is no values in the end
let arr = [[0,1],[2,3]];
if (typeof arr[2] == undefined) { //i want to add arr[2] if there is none
  arr[2] = [];
}
console.log(arr[2]);
Guderian Raborg
@hypercuber
Jul 18 2017 04:26
I need it for this problem: https://projecteuler.net/problem=13
kumquatfelafel
@kumquatfelafel
Jul 18 2017 04:37

@padunk Okay... so a couple notes...
first off.... Symbol('banana') !== Symbol('banana')
So you can have several banana's, and it really could care less. After all, as we all know, banana's come in bunches. The newest "banana" here will not take precedence over the old banana because they are not the same. On the other hand, when you're talking about something like

"grapes" : "yellow",
"grapes" : "brown"

"grapes" === "grapes" so there's really not much choice besides replacement here since the keys are exactly the same.

By contrast, the only way (from what I can tell having done almost no research into the matter :p :laughing: ) to overwrite the value associated with symbol in an object is to access that particular key-value pair, or apply the same exact symbol again (which can't be done without first accessing key-value pair in this case, since that's the only useable reference).

Anywho, I've played around with Symbol a bit in here and you can see some things that work/don't work, and so on and so forth with the caveat that I don't actually know what I'm doing.
https://repl.it/J62a/2

Nick Gray
@nicholasnbg
Jul 18 2017 04:43
@hypercuber can you use
 if(!arr[2]){
   arr[2]=[];
}
fdemaa
@fdemaa
Jul 18 2017 04:46
@kumquatfelafel hey man can you help me with my click event, its not working after the first time i press it ?
kumquatfelafel
@kumquatfelafel
Jul 18 2017 04:47
possibly, possibly not :p
fdemaa
@fdemaa
Jul 18 2017 04:47
haha
Guderian Raborg
@hypercuber
Jul 18 2017 04:47
@nicholasnbg Thanks. That works.
CamperBot
@camperbot
Jul 18 2017 04:47
hypercuber sends brownie points to @nicholasnbg :sparkles: :thumbsup: :sparkles:
:cookie: 328 | @nicholasnbg |http://www.freecodecamp.com/nicholasnbg
fdemaa
@fdemaa
Jul 18 2017 04:47
i had this
document.getElementsByClassName("randombutton")[0].addEventListener("click",function(){
var outputQuote = firstDom.innerHTML = characters[myRange].quotes[myRangeQuotes];
var outputName= secondDom.innerHTML = characters[myRange].name;
});
@kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jul 18 2017 04:49
@fdemaa the idea is that myRange will be randomly generated number referring to the character and myRangeQuotes will be the quote number?
fdemaa
@fdemaa
Jul 18 2017 04:49
yes
thats the idea
kumquatfelafel
@kumquatfelafel
Jul 18 2017 04:49
@fdemaa when you click, does the value of myRange change?
fdemaa
@fdemaa
Jul 18 2017 04:51

yes when i click the button it will always output random name and quotes
but if i want to press the button again it will not work

its like the button is "destroy" lol

let me show you the codepen
so you can look what happen
i had to reload the page so i can use the button again
also i had no errors on console
kumquatfelafel
@kumquatfelafel
Jul 18 2017 04:53
@fdemaa add console.log("Lemons are tasty"); to the inside of your click function. Let's see if it is registering click first ;)
Then we'll talk about what's going wrong.
fdemaa
@fdemaa
Jul 18 2017 04:56
yes the string lemons are tasty is showing in console every time i press my button but my quotes and name dont OMG
:|
@kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jul 18 2017 04:57
Now let's take a look at the values of myRange and myRangeQuotes.
Add
console.log('character # is ' + myRange);
console.log('quote # is ' + myRangeQuotes);
fdemaa
@fdemaa
Jul 18 2017 04:58
lol always the same
number
kumquatfelafel
@kumquatfelafel
Jul 18 2017 04:59
Aye.
So the only piece of code that's gonna get run when you click is what's inside those curly braces. Do we have anything in there at the moment that changes the values of myRange and myRangeQuotes?
fdemaa
@fdemaa
Jul 18 2017 05:00
No it will always be the same number
i had to do something
to change that
kumquatfelafel
@kumquatfelafel
Jul 18 2017 05:01
So what you need to figure out is a way to fix this so that when click, values change
fdemaa
@fdemaa
Jul 18 2017 05:02
:)
thanks man
i know i understand whats going on lol
kumquatfelafel
@kumquatfelafel
Jul 18 2017 05:02
np
fdemaa
@fdemaa
Jul 18 2017 05:02
:+1:
kumquatfelafel @kumquatfelafel away for time being
surferpilgrim
@surferpilgrim
Jul 18 2017 05:15
does anyone know how to keep adding values until a certain threshold is reached? like add all values until you reach four
fdemaa
@fdemaa
Jul 18 2017 05:17

you mean something like these ?

if ( number < 4) {
.push number to the array or whatever you want it to put
}

something like that?

@surferpilgrim
Nick Gray
@nicholasnbg
Jul 18 2017 05:18
var total = 0;
while(total <4){
  total += number;
}
something like that?
surferpilgrim
@surferpilgrim
Jul 18 2017 05:18
@nicholasnbg I think so. does it stop near 4?
Nick Gray
@nicholasnbg
Jul 18 2017 05:20
it stops the first time that total is 4 or more
Guderian Raborg
@hypercuber
Jul 18 2017 05:20
@surferpilgrim Do you have a problem/ lesson that we can help with?
twopointtwo
@twopointtwo
Jul 18 2017 05:22
@twopointtwo
I have a question on a codepen
Wikipedia Viewer
https://codepen.io/twopointtwo/pen/yXWarX
Can someone tell me how to get the search function to work?
surferpilgrim
@surferpilgrim
Jul 18 2017 05:22
@hypercuber I'm gonna try a few things then post my work if I'm stuck
Guderian Raborg
@hypercuber
Jul 18 2017 05:24
Okay.
Rajat
@rajataudichya
Jul 18 2017 05:29
@Blauelf are you there?
Rajat
@rajataudichya
Jul 18 2017 05:34
any1 here that can help me solving the counting cards challenge?
Markus Kiili
@Masd925
Jul 18 2017 05:51
@rajataudichya Sure.
Rajat
@rajataudichya
Jul 18 2017 05:53

var count = 0;

function cc(card) {
  // Only change code below this line

  if (card = 2, 3, 4,5,6) {

    return count += 1 ,"Bet";
  } 
    else if (card = 7,8,9){
      return count += 0, "Hold";
    }

  else if (card=10, 'J', 'Q', 'K', 'A'){
    return count -= 1, "Bet";
  }




  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
what am i doing wrong
Markus Kiili
@Masd925
Jul 18 2017 05:55
@rajataudichya It needs to be like if(card===2 || card===3 ||...)
= is the assignment operator.
Rajat
@rajataudichya
Jul 18 2017 05:56
Thanks markus let me try and get back]
Markus Kiili
@Masd925
Jul 18 2017 05:56
You need to test card and change count accordingly. Then test count and make a return based on it. So the code needs two separate parts.
@rajataudichya
Rajat
@rajataudichya
Jul 18 2017 05:56
ok
i am not that good programmer to understand what you just said
abraham anak agung
@padunk
Jul 18 2017 05:57
@kumquatfelafel nice work on Symbol on your repl.it, Thanks again man. i will take a look more into this new Symbol thing :smile:
CamperBot
@camperbot
Jul 18 2017 05:57
padunk sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 482 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Rajat
@rajataudichya
Jul 18 2017 06:02
this count challenge is hard
abraham anak agung
@padunk
Jul 18 2017 06:05
@rajataudichya try it step by step. it is not that hard
Markus Kiili
@Masd925
Jul 18 2017 06:06
@rajataudichya First test value of card and change count as asked. Don't return anything yet.
Rajat
@rajataudichya
Jul 18 2017 06:06
but this is wrong , why freecodecamp suddenly brings a challenge that is way to hard to figure out?
@Masd925 ok
kumquatfelafel
@kumquatfelafel
Jul 18 2017 06:12
@rajataudichya If you understand the instructions, understand control flow, and apply what you've learned from previous lessons, it is doable.
Nick Gray
@nicholasnbg
Jul 18 2017 06:12
Programming is going to get harder than basic exercises sooner or later, a big part of FCC is building your ability to problem solve, and break down big tasks into smaller tasks @rajataudichya
I found it was usefull to go back through the lessons and see which ones seemed relevant to the problem
Rajat
@rajataudichya
Jul 18 2017 06:15
thanks @nicholasnbg @kumquatfelafel
CamperBot
@camperbot
Jul 18 2017 06:15
rajataudichya sends brownie points to @nicholasnbg and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 483 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:cookie: 329 | @nicholasnbg |http://www.freecodecamp.com/nicholasnbg
kumquatfelafel
@kumquatfelafel
Jul 18 2017 06:20
while (total < 4) {
   total += number;
}
@nicholasnbg @surferpilgrim The one thing I will say here is that if number <= 0, then you're looking at an infinite loop, so just be a little careful with this. ;)
Nick Gray
@nicholasnbg
Jul 18 2017 06:34
yeah I always get a bit scared of using while loops haha, I'm sure there's better ways, that was just the first thing that came to mind. I'd be interested the seeing the problem
Blauelf
@Blauelf
Jul 18 2017 06:36
@rajataudichya Was a bit early in my time zone. ;-)
Kevin
@kevinwr
Jul 18 2017 06:42
Trying to target "title" and "snippet" in "search". Not getting any results.
// 20170718004010
// https://en.wikipedia.org/w/api.php?origin=*&action=query&list=search&srsearch=IHOP&format=json

{
  "batchcomplete": "",
  "continue": {
    "sroffset": 10,
    "continue": "-||"
  },
  "query": {
    "searchinfo": {
      "totalhits": 238
    },
    "search": [
      {
        "ns": 0,
        "title": "International House Of Pancakes",
        "size": 9448,
        "wordcount": 830,
        "snippet": "International House of Pancakes, stylized as its acronym, <span class=\"searchmatch\">IHOP</span> (/ˈaɪhɒp/), is an American multinational pancake house/fast casual family restaurant chain",
        "timestamp": "2017-07-14T03:58:50Z"
      },
      {
        "ns": 0,
        "title": "2011 IHOP shooting",
        "size": 9765,
        "wordcount": 914,
        "snippet": "identified as 32-year-old Eduardo Sencion, opened fire in a branch of the <span class=\"searchmatch\">IHOP</span> in Carson City, Nevada, killing four people, including three members of the",
        "timestamp": "2017-07-15T01:55:14Z"
      },
      {
        "ns": 0,
        "title": "IHOP (disambiguation)",
        "size": 439,
        "wordcount": 54,
        "snippet": "<span class=\"searchmatch\">IHOP</span> may refer to: International House of Pancakes, known as <span class=\"searchmatch\">IHOP</span>. dineEquity, formerly known as <span class=\"searchmatch\">IHOP</span> Corporation. International House of Prayer, an evangelical",
        "timestamp": "2017-07-14T03:57:37Z"
      },
      {
        "ns": 0,
        "title": "The IHOP Papers",
        "size": 5969,
        "wordcount": 686,
        "snippet": "The <span class=\"searchmatch\">IHOP</span> Papers is the debut novel of American author Ali Liebegott, and was first published on December 13, 2006 by Carroll &amp; Graf. The story revolves",
        "timestamp": "2016-10-10T19:14:50Z"
      },
      {
        "ns": 0,
        "title": "Information Hyperlinked over Proteins",
        "size": 3000,
        "wordcount": 338,
        "snippet": "For other uses of &quot;<span class=\"searchmatch\">IHOP</span>&quot;, see <span class=\"searchmatch\">IHOP</span> (disambiguation).      Information Hyperlinked over Proteins (or <span class=\"searchmatch\">iHOP</span>) is an online text-mining service that provides",
        "timestamp": "2016-06-09T19:06:58Z"
      },
      {
        "ns": 0,
        "title": "DineEquity",
        "size": 5639,
        "wordcount": 441,
        "snippet": "DineEquity, Inc., formerly known as <span class=\"searchmatch\">IHOP</span> Corporation, is an American company that franchises and operates <span class=\"searchmatch\">IHOP</span> and Applebee's restaurants. The company",
        "timestamp": "2017-07-14T14:06:21Z"
      },
      {
        "ns": 0,
        "title": "International House of Prayer",
        "size": 15049,
        "wordcount": 1465,
        "snippet": "The International House of Prayer (<span class=\"searchmatch\">IHOP</span> or IHOPKC) is a charismatic Pentecostal Christian movement and missions organization based in Kansas City, Missouri",
        "timestamp": "2017-04-27T19:51:09Z"
      },
      {
        "ns": 0,
        "title": "Pasadena International House of Prayer",
        "size": 1382,
        "wordcount": 120,
        "snippet": "after being sued by <span class=\"searchmatch\">IHOP</span> pancake house&quot;. Pasadena Star-News.   Bradley, Donald (Sep 14, 2010). &quot;<span class=\"searchmatch\">IHOP</span> (the pancake-maker) sues <span class=\"searchmatch\">IHOP</span> (the prayer center)",
        "timestamp": "2016-04-27T22:16:56Z"
      },
      {
        "ns": 0,
        "title": "List of pancake houses",
        "size": 1755,
        "wordcount": 168,
        "snippet": "Golden Nugget Pancake House Hash House a go go Honey Jam Cafe Huddle House <span class=\"searchmatch\">IHOP</span>  The Original Pancake House Pamela's Diner Pancake Parlour Perkins Restaurant",
        "timestamp": "2017-05-04T00:51:28Z"
      },
      {
Here is what I'm using: alert(jsonData.query.search[0].title);
Theofanis Despoudis
@theodesp
Jul 18 2017 06:44
@forkerino
challenge accepted
Venkateshwaran
@Venkateshwaran
Jul 18 2017 06:44
Hi everyone,
addTogether(2)(3) -how do I access (3) here?
Hi everyone,
addTogether(2)(3) -how do I access (3) here?
cowCrazy
@cowCrazy
Jul 18 2017 06:46
@kevinwr for me it is working look here
have I done anything different than you?
Markus Kiili
@Masd925
Jul 18 2017 06:46
@Venkateshwaran addTogether(2) should return a function and (3) calls that function. So the returned function should have one parameter you can use to access the argument.
Kevin
@kevinwr
Jul 18 2017 06:48
@cowCrazy nope. nothing except changing the alert to console.log
cowCrazy
@cowCrazy
Jul 18 2017 06:49
but I see in the console the title of the first element
for you it is not working?
Kevin
@kevinwr
Jul 18 2017 06:49
hmmmmm
nope
I alerted just the jsonData, and that returns the json file info fine
but when I try to select anything, it returns nothing
cowCrazy
@cowCrazy
Jul 18 2017 06:50
can you give a link to the code?
Markus Kiili
@Masd925
Jul 18 2017 06:51
@kevinwr Check whether the variable holds a string or an object.
Kevin
@kevinwr
Jul 18 2017 06:51
image.png
just checked my dev tools and this is the error I'm getting
Darren
@DarrenfJ
Jul 18 2017 06:52
evening fCC
cowCrazy
@cowCrazy
Jul 18 2017 06:53
@kevinwr try to console.log(jsonData.query) what do you get?
Kevin
@kevinwr
Jul 18 2017 06:53
yeah,w as just going to try that
let me check
undefined
I did console.log(typeof jsonData.query);
cowCrazy
@cowCrazy
Jul 18 2017 06:55
@kevinwr but console.log(jsonData) gives you the json file with all the data?
Markus Kiili
@Masd925
Jul 18 2017 06:55
@kevinwr typeof jsonData
Kevin
@kevinwr
Jul 18 2017 06:55
console.log(typeof jsonData); gives me a string
Markus Kiili
@Masd925
Jul 18 2017 06:56
You need to JSON.parse() the string into an object before accessing.
Sweet Coding :)
@SweetCodingInc
Jul 18 2017 06:56
@kevinwr then do jsonData = JSON.parse(jsonData) first and then run your query
cowCrazy
@cowCrazy
Jul 18 2017 06:56
@kevinwr :thumbsup: for @Masd925 I was just about to say that :)
Kevin
@kevinwr
Jul 18 2017 06:56
oh crap. that's right
ugh
I'm an idiot
Sweet Coding :)
@SweetCodingInc
Jul 18 2017 06:57
well, you got that part right... ;)
Kevin
@kevinwr
Jul 18 2017 06:57
:(
cowCrazy
@cowCrazy
Jul 18 2017 06:58
@kevinwr coding when tired? ;)
Kevin
@kevinwr
Jul 18 2017 06:59
sorta' tired. Just have only done a XHR call once before, and forgot JSON is always returned in a string format
or type
rather
or whatever the hell
lol
kumquatfelafel
@kumquatfelafel
Jul 18 2017 07:00

sorta' tired

@kevinwr Can't say the feeling ain't mutual :p

cowCrazy
@cowCrazy
Jul 18 2017 07:00
@kevinwr Ahhh!!! you see not an idiot, simply new to it ;)
Kevin
@kevinwr
Jul 18 2017 07:00
@kumquatfelafel no doubt haha
@cowCrazy let's hope I remember this haha
MWUAHAHAHAHA now it's working
Thanks for the help, everyone
Kevin
@kevinwr
Jul 18 2017 07:09
Does anyone know if it's possible to create a new HTML element with JS?
Manish Giri
@Manish-Giri
Jul 18 2017 07:09
@kevinwr yup
cowCrazy
@cowCrazy
Jul 18 2017 07:09
yes
Kevin
@kevinwr
Jul 18 2017 07:09
ok I'll see if I can find it
cowCrazy
@cowCrazy
Jul 18 2017 07:10
document.createElement("div/li/p")
Manish Giri
@Manish-Giri
Jul 18 2017 07:10
document.createElement('"...")
Kevin
@kevinwr
Jul 18 2017 07:10
even if we already have one defined and we want it to create the exact element we have defined already in our HTML?
cowCrazy
@cowCrazy
Jul 18 2017 07:11
then you can create element as above, then to add the data to it with innerHTML and then to push it to the DOM
Markus Kiili
@Masd925
Jul 18 2017 07:13
@kevinwr You can copy the html content or clone the dom node.
Kevin
@kevinwr
Jul 18 2017 07:15
dom node?
Markus Kiili
@Masd925
Jul 18 2017 07:15
@kevinwr The html creates a dynamical dom tree on the browser memory that you can change and access with JS.
cowCrazy
@cowCrazy
Jul 18 2017 07:15
@kevinwr DOM, your html
Kevin
@kevinwr
Jul 18 2017 07:15
yeah I know what the dom is
what's a node?
cowCrazy
@cowCrazy
Jul 18 2017 07:16
node another name for element
Kevin
@kevinwr
Jul 18 2017 07:16
oh ok
Markus Kiili
@Masd925
Jul 18 2017 07:17
@kevinwr Document and elements are nodes.
Kevin
@kevinwr
Jul 18 2017 07:17

Right now, I'm trying to basically create this div using a loop

<div id="searchResults">
                <div id="resultsEntry">
                    <div id="reTitle">

                    </div>
                    <div id="reSnippet">

                    </div>

                </div>
            </div>

and in the same loop, apply data from the JSON file to specific parts of the div, then push it to the DOM

cowCrazy
@cowCrazy
Jul 18 2017 07:20
@kevinwr this should help you with creating and adding nodes to the DOM
Kevin
@kevinwr
Jul 18 2017 07:21
ok I'll take a look. Thanks @cowCrazy
CamperBot
@camperbot
Jul 18 2017 07:21
kevinwr sends brownie points to @cowcrazy :sparkles: :thumbsup: :sparkles:
:cookie: 282 | @cowcrazy |http://www.freecodecamp.com/cowcrazy
cowCrazy
@cowCrazy
Jul 18 2017 07:22
if you wanna use an existing node, you can get it, modify it, set it inside the new node you wanna push to the DOM, and then to push it
@kevinwr you can try to think about it as using a template
Kevin
@kevinwr
Jul 18 2017 07:23
hmmm ok
let's see what I come up with
wish me luck
hah
AdamCS
@csikos3d
Jul 18 2017 07:42
hi, i am about to count the elements of an array but it is log the character count of the first element...Should I convert it beforehand someways?
function foo(test){

console.log(test.length);

};

foo("f47","f5","g6","h7","j8","k9","l9");
//3
heroiczero
@heroiczero
Jul 18 2017 07:45
@csikos3d foo("f47","f5","g6","h7","j8","k9","l9")that does not look like an array. it looks more like arguments https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments
AdamCS
@csikos3d
Jul 18 2017 07:47
@heroiczero thank you thats niceto kno :-). But is there any why to count the elements of it?
CamperBot
@camperbot
Jul 18 2017 07:47
csikos3d sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1501 | @heroiczero |http://www.freecodecamp.com/heroiczero
heroiczero
@heroiczero
Jul 18 2017 07:48
@csikos3d do you want to know how many elements are in your argument?
AdamCS
@csikos3d
Jul 18 2017 07:51
@heroiczero yes, this is my goal.
heroiczero
@heroiczero
Jul 18 2017 07:52
@heroiczero try var args = Array.prototype.slice.call(arguments); to store it in an array called args and args.length; will tell you the number of elements in your arguments
Jor
@joreyesl
Jul 18 2017 07:52
@csikos3d functions have an arguments object that holds the arguments that are passed to it. You can use arguments.length to get the number of arguments that were passed to the function.
kumquatfelafel
@kumquatfelafel
Jul 18 2017 07:56

So is it just me, or could the Validate US Telephone Number do with some more test cases? Was able to pass with this.

function telephoneCheck(str) {
  // Good luck!
  var leftPInd = str.indexOf("(");
  var rightPInd = str.indexOf(")");
  testStr = str.replace(/([^\d])/g, "");
  if(testStr.length !== 10 && testStr.length !== 11)
    return false;
  if(testStr.length === 11 && str[0] !== '1')
    return false;
  if(leftPInd !== -1) {
    if(rightPInd !== leftPInd + 4)
      return false;
    else if (str.length - 1 !== str.replace(/\(/g, "").length 
             || str.length - 1 !== str.replace(/\)/g, "").length)
      return false;
  } else if(rightPInd !== -1)
    return false;
  return true;
}
telephoneCheck("1a555b555c5555");

Or was it not supposed to be as strict a check as I'm making it out to be?

heroiczero
@heroiczero
Jul 18 2017 07:59
@kumquatfelafel personally i just did it in a line of regexp
kumquatfelafel
@kumquatfelafel
Jul 18 2017 07:59
well sure, but where's the fun in that? :p
It just feels... kinda like the requirements are a bit lax if I'm able to get away with this.
Rajat
@rajataudichya
Jul 18 2017 08:00
Hello guys I need some clarity in understanding increment and decrement operators
```js
// Postfix 
var x = 3;
y = x++; // y = 3, x = 4

// Prefix
var a = 2;
b = ++a; // a = 3, b = 3
Blauelf
@Blauelf
Jul 18 2017 08:00

@kumquatfelafel If you want to suggest some test case, you can file a bug report, and if you want even write the test case yourself and do a pull request.

I used a somewhat simple regular expression (well, the only advanced feature I used was a group () with alternative matching |)

hrlp
help
Blauelf
@Blauelf
Jul 18 2017 08:00
@rajataudichya Both increment the variable. But x++ returns the pre-increment value, while ++a returns the value after incrementing.
Rajat
@rajataudichya
Jul 18 2017 08:00
y= y+1; can be written as y++
heroiczero
@heroiczero
Jul 18 2017 08:01
@wk1507341428 what do you have so far?
Blauelf
@Blauelf
Jul 18 2017 08:01
@rajataudichya y=y+1 or y+=1 is more like ++y if you use its value.
kumquatfelafel
@kumquatfelafel
Jul 18 2017 08:02

@rajataudichya y = x++; is similar to if you said

y = x;
x = x + 1;

whereas a = ++x is like

x = x+1;
a = x;
cowCrazy
@cowCrazy
Jul 18 2017 08:03
@rajataudichya look here
Blauelf
@Blauelf
Jul 18 2017 08:03
@wk1507341428 Two parts, which are somewhat independent and should not be mixed:
  1. For certain values of card, increment or decrement global variable count
  2. Return a string built from count and either Bet or Hold (depending on count but not on card), with a space between the number and the word.
EpicTriffid
@EpicTriffid
Jul 18 2017 08:03
Mornin all!
cowCrazy
@cowCrazy
Jul 18 2017 08:03
@rajataudichya it is explaining exactly what you want, and tells you the difference between ++a and a++
Rajat
@rajataudichya
Jul 18 2017 08:04
@ @cowCrazy i have come from there only
EpicTriffid
@EpicTriffid
Jul 18 2017 08:05
So in my codepen I'm trying to get it that when i click on the random button, if the search box is open, it will close it, but I think I'm having trouble working out how to reference it. You can see my attempts in randbut to initialize closeSearch when clicked, but its not working. Any ideas? https://codepen.io/EpicTriffid/pen/WOYrzg
cowCrazy
@cowCrazy
Jul 18 2017 08:05
@rajataudichya have you seen what is written above it?
silly
@wk1507341428
Jul 18 2017 08:06
@Blauelf Thank you. I'll try
CamperBot
@camperbot
Jul 18 2017 08:06
wk1507341428 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4501 | @blauelf |http://www.freecodecamp.com/blauelf
Rajat
@rajataudichya
Jul 18 2017 08:06
@cowCrazy I wish to know the use of this is real time as it will help me understand better
kumquatfelafel
@kumquatfelafel
Jul 18 2017 08:07
@rajataudichya did you understand what I said above?
Rajat
@rajataudichya
Jul 18 2017 08:07
@cowCrazy my brain is telling me that in the first example y should be 4 and x should be 3...
@kumquatfelafel I am trying to understand it
Blauelf
@Blauelf
Jul 18 2017 08:08

The side-effects of the increment/decrement operators can lead to strange results:

var a = 0;
console.log(++a === a++); // true
console.log(a++ === ++a); // false

As they can be confusing, Douglas Crockford ("JavaScript: The Good Parts") votes for using a+=1 instead of a++ or ++a, and maybe changing code that relies on a++ not being ++a.

@rajataudichya x is the variable that's incremented as a side-effect of ++
Rajat
@rajataudichya
Jul 18 2017 08:09
@Blauelf what you are saying that it is better to use a+=1 rather than a++?
cowCrazy
@cowCrazy
Jul 18 2017 08:09
@rajataudichya if x++ then first it returns x (while it is still 3), then incrementing it a by 1. so it makes x=4.
Blauelf
@Blauelf
Jul 18 2017 08:10
@rajataudichya At least it's clear that an assign operator always evaluates to the assigned value, and not like the postfix notation to the pre-increment value.
Rajat
@rajataudichya
Jul 18 2017 08:11
Thank you so much people for helping me @cowCrazy @Blauelf @kumquatfelafel
CamperBot
@camperbot
Jul 18 2017 08:11
rajataudichya sends brownie points to @cowcrazy and @blauelf and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 283 | @cowcrazy |http://www.freecodecamp.com/cowcrazy
:cookie: 486 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:star2: 4502 | @blauelf |http://www.freecodecamp.com/blauelf
cowCrazy
@cowCrazy
Jul 18 2017 08:11
@rajataudichya it is important that you use something that is clear to you what it is doing. There are many ways for doing it, but use the ones you feel ok with to get the result you want
Rajat
@rajataudichya
Jul 18 2017 08:11
@cowCrazy can you share the same example using assignment operator so i can understand like @Blauelf said
I mean by using x+=1
AdamCS
@csikos3d
Jul 18 2017 08:13
@heroiczero @joreyesl thank you guys!
CamperBot
@camperbot
Jul 18 2017 08:13
csikos3d sends brownie points to @heroiczero and @joreyesl :sparkles: :thumbsup: :sparkles:
:cookie: 826 | @joreyesl |http://www.freecodecamp.com/joreyesl
:warning: csikos3d already gave heroiczero points
Blauelf
@Blauelf
Jul 18 2017 08:13
One probably does not have to be as religious about that as Douglas Crockford is, but the add-assign or subtract-assign operators are sometimes more obvious in their meaning, as their value is always the assigned value (as with any assign operator).
kumquatfelafel
@kumquatfelafel
Jul 18 2017 08:14
@rajataudichya I would not use ++ outside of relatively simple applications. Mind you, for me, I consider your example as an acceptable use of ++
If I only needed to say x=x+1, like in for loop, I would definitely just go with x++
Blauelf
@Blauelf
Jul 18 2017 08:15

@rajataudichya I have an ugly one-line solution to card counting:

    return (count += (card < 7) - !(card < 10)) + [" Hold", " Bet"][+(count > 0)];

That one uses the result of the add-assign to construct the string. Definitely not an example for great readability with all its implicit and explicit conversions.

Rajat
@rajataudichya
Jul 18 2017 08:21
@kumquatfelafel i got your what you were trying to make me understand thank you so much, I believe FCC should have added this to the challenges
CamperBot
@camperbot
Jul 18 2017 08:21
rajataudichya sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:warning: rajataudichya already gave kumquatfelafel points
this challenges is not worth it
kumquatfelafel
@kumquatfelafel
Jul 18 2017 08:22
@rajataudichya well... it's true. It's just not the whole truth :p
If you're not immediately using that value in situ, you don't really have to worry about when the 1 is added.
So that kind of scenario is pretty much the perfect time for ++ operator
kumquatfelafel
@kumquatfelafel
Jul 18 2017 08:29
they also do link to here which explains difference between post and pre inc/dec
Blauelf
@Blauelf
Jul 18 2017 08:30
I used to have like i++ in expressions, especially in array indices. But that way to use it often is highly fragile. One should not code golf production code. Unless of course you're paid well for achieving same for less (Jobs was, and he did not like sharing)
Chris Juchtmans
@kjuchtmans
Jul 18 2017 08:31
Gutemorgen coders! :wave:
Blauelf
@Blauelf
Jul 18 2017 08:32
@kumquatfelafel If you have links with ) in, consider replacing them with %29 so that they are not taken for markdown (( is %28, not sure whether one should replace those as well)
Rajat
@rajataudichya
Jul 18 2017 08:32
@kumquatfelafel I don't understand that much situ and all , I am new to js
Chris Juchtmans
@kjuchtmans
Jul 18 2017 08:33

"Binary Agents"

Why is return str from my below code interspersed with white spaces?

code:

str=str.replace(/[01]{8}/g, function(bin){
    parsed = parseInt(bin, 2);
    return String.fromCharCode(parsed);
  });
  return str;

thanks! k

cowCrazy
@cowCrazy
Jul 18 2017 08:33
@rajataudichya something like that
kumquatfelafel
@kumquatfelafel
Jul 18 2017 08:35
@Blauelf the %29 would work fine. Ran out of time to edit
@rajataudichya disregard "in situ". Not important
Blauelf
@Blauelf
Jul 18 2017 08:37
@kjuchtmans There are spaces within the input string, grouping the binary digits. You could for example use / ?[01]{8}/g, leading spaces are probably ignored by parseInt, or you could remove them at any stage.
Chris Juchtmans
@kjuchtmans
Jul 18 2017 08:38
@Blauelf danke , I'm trying to chain another .replace( ) method removing them, thanks
CamperBot
@camperbot
Jul 18 2017 08:38
kjuchtmans sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4503 | @blauelf |http://www.freecodecamp.com/blauelf
Rajat
@rajataudichya
Jul 18 2017 08:38
https://www.freecodecamp.com/challenges/increment-a-number-with-javascript in this challenge it doesn not matter's if i use pre or post why is tha?t
kumquatfelafel
@kumquatfelafel
Jul 18 2017 08:39
Because you're just adding one, you're not actually doing anything with that value immediately.
x++;

gives same result as

++x;

but

y = x++;

does not behave the same as

y = ++x;

Because now you've got it in a statement where the value of x is being used.

Rajat
@rajataudichya
Jul 18 2017 08:43
okay....
thanks now let me use this in counting card challenge thanks
Ahmad Abdolsaheb
@ahmadabdolsaheb
Jul 18 2017 09:18
I have a question about git push :)
anyone would like to h elp
Sweet Coding :)
@SweetCodingInc
Jul 18 2017 09:20
@ahmadabdolsaheb Shoot
@kumquatfelafel Just a note: Even though it looks seemingly similar, preincrement and postincrement are vastly different.
kumquatfelafel
@kumquatfelafel
Jul 18 2017 09:21
@SweetCodingInc no disagreement.
Ahmad Abdolsaheb
@ahmadabdolsaheb
Jul 18 2017 09:22
@SweetCodingInc wait I think I find the answer :)
Sweet Coding :)
@SweetCodingInc
Jul 18 2017 09:22
@ahmadabdolsaheb :+1:
let me guess, you forgot to add and commit before push?
abraham anak agung
@padunk
Jul 18 2017 09:23
Question: how to make object iterable using [Symbol.iterable]?
Ahmad Abdolsaheb
@ahmadabdolsaheb
Jul 18 2017 09:25
@SweetCodingInc no lols, I still could not figure it out. so I git push -u origin master and I get the message "Branch master set up to track remote branch master from origin.
Everything up-to-date". however, github repo does not update...
Sweet Coding :)
@SweetCodingInc
Jul 18 2017 09:29
can you do git status
and see if you have any untracked changes
@ahmadabdolsaheb
Ahmad Abdolsaheb
@ahmadabdolsaheb
Jul 18 2017 09:30
"HEAD detached from 59d9b8a
nothing to commit, working tree clean"
@SweetCodingInc
a7n007
@a7n007
Jul 18 2017 09:32

function diffArray(arr1, arr2) {
var c,i,j,newArr = [];
for(i=0;i<arr1.length-1;i++)
{
c=0;
for(j=0;j<arr2.length-1;j++)
{
if(arr1[i]!=arr2[j])
c++;
}
if(c==arr2.length)
newArr.push(arr1[i]);
}

for(i=0;i<arr2.length-1;i++)
{
 c=0;
  for(j=0;j<arr1.length-1;j++)
    {
      if(arr1[j]!=arr2[i])
        c++;
    }
  if(c==arr1.length)
    newArr.push(arr2[i]);
}

return newArr;
}

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

why is my code not working
Sweet Coding :)
@SweetCodingInc
Jul 18 2017 09:32
@ahmadabdolsaheb have you really added any files to your local repo?
Ahmad Abdolsaheb
@ahmadabdolsaheb
Jul 18 2017 09:33
@SweetCodingInc it looks like I was on another branch, I will try to figure it out by merging or something
thanks
@SweetCodingInc thanks
CamperBot
@camperbot
Jul 18 2017 09:33
ahmadabdolsaheb sends brownie points to @sweetcodinginc :sparkles: :thumbsup: :sparkles:
:cookie: 130 | @sweetcodinginc |http://www.freecodecamp.com/sweetcodinginc
Sweet Coding :)
@SweetCodingInc
Jul 18 2017 09:35
@ahmadabdolsaheb :+1:
first do git branch
to see what branch you're on
if that's not master, then do git checkout master
once that is done do git merge <your-branch-name>
Blauelf
@Blauelf
Jul 18 2017 09:36
@a7n007 Why i<arr1.length-1? I don't see why you subtract 1.
Sweet Coding :)
@SweetCodingInc
Jul 18 2017 09:36
and then do git push origin master
kumquatfelafel
@kumquatfelafel
Jul 18 2017 09:37
@SweetCodingInc (first two examples were just focusing on the end result, which in those specific cases are exactly the same, which answers the question as to why the FCC challenge in question wouldn't care which of the two is used.)
Ahmad Abdolsaheb
@ahmadabdolsaheb
Jul 18 2017 09:37
@SweetCodingInc thanks, it seems like i was on a detached HEAD and when I checked out to master all my commits are gone now...
CamperBot
@camperbot
Jul 18 2017 09:37
ahmadabdolsaheb sends brownie points to @sweetcodinginc :sparkles: :thumbsup: :sparkles:
:warning: ahmadabdolsaheb already gave sweetcodinginc points
Blauelf
@Blauelf
Jul 18 2017 09:37
@a7n007 BTW, check out indexOf, it returns the index of the first occurrence in an array, or -1 if the element could not be found. That could save you the inner loops.
@ahmadabdolsaheb Commits are not "gone" that easily. Even if there's no branch pointing there, you can still address them by their hash.
ioakeimo
@ioakeimo
Jul 18 2017 09:39
Hello everyone, I just finished "Inventory Update" challenge. Any comments for improvement? That's the simplest (1st) solution I could think of:
function updateInventory(arr1, arr2) {

  if(arr1.length === 0) { return arr2.sort((a,b) => a[1].localeCompare(b[1])); }
  let temp = [];

// Iterating backwards because it's faster
  for(let i=arr2.length-1; i>-1; i--) {
    for(let j=arr1.length-1; j>-1; j--) {

      if(arr1[i][1].localeCompare(arr2[j][1]) === 0) {
        arr1[j][0] += arr2[i][0];
        break;
      }

      if(j === 0) {
        temp.push(arr2[i]);
      }
    }
  }

  arr1 = arr1.concat(temp);
  arr1.sort((a,b) => a[1].localeCompare(b[1]));

  return arr1;

}
Sweet Coding :)
@SweetCodingInc
Jul 18 2017 09:41
@ahmadabdolsaheb : Your commit are not gone, per say
if you switch back to your older branch, you will still be able to see them
Markus Kiili
@Masd925
Jul 18 2017 09:46
@ioakeimo That is one way to do it. I used methods and first concated and sorted the arrays. Then combined same product elements with reduce.
ioakeimo
@ioakeimo
Jul 18 2017 09:47
@Masd925 nice thinking! Should be faster too, right?
Markus Kiili
@Masd925
Jul 18 2017 09:48
@ioakeimo I would guess loops being faster, but method way might be more compact and elegant.
Hard to say because you are sorting too there.
ioakeimo
@ioakeimo
Jul 18 2017 09:49
I'm also using sort and concat, and I'm also using a temp array which otherwise would not be needed
Plus your solution should be about what, 2 lines?
@Masd925 Let me try it... Thanks for the insight :)
CamperBot
@camperbot
Jul 18 2017 09:51
ioakeimo sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4305 | @masd925 |http://www.freecodecamp.com/masd925
makalohri
@makalohri
Jul 18 2017 09:52
@knrt10 thank you
CamperBot
@camperbot
Jul 18 2017 09:52
makalohri sends brownie points to @knrt10 :sparkles: :thumbsup: :sparkles:
:cookie: 461 | @knrt10 |http://www.freecodecamp.com/knrt10
Markus Kiili
@Masd925
Jul 18 2017 09:53
@ioakeimo It is about same length as your solution. I do have a one-line solution though ;)
ioakeimo
@ioakeimo
Jul 18 2017 09:54
@Masd925 in your reduce callback do you use an if statement to check if keys match?
Markus Kiili
@Masd925
Jul 18 2017 09:55
@ioakeimo Yes.
Sweet Coding :)
@SweetCodingInc
Jul 18 2017 09:58

@Masd925

It is about same length as your solution. I do have a one-line solution though

Let me guess, you used .some ;)

Markus Kiili
@Masd925
Jul 18 2017 09:58
@SweetCodingInc No, it was a reduce solution. You can find my gist of FCC one-liners if you like.
Sweet Coding :)
@SweetCodingInc
Jul 18 2017 09:59
:+1:
Saw your answer... Good collection of one liners ! :+1:
@Masd925
here is how I'd do it
function updateInventory(arr1, arr2) {
    return arr2.reduce(
      (x,y)=>{
        if(!x.some(z=>z[1]===y[1]?(z[0]+=y[0])||1:0))
          x.push(y);
        return x;
      },
      arr1.slice()
    ).sort(
      (x,y)=>(x[1]>y[1])-(y[1]>x[1])
    );
}
Roman
@BolhovRoman
Jul 18 2017 10:03
hi there
i need help with regular expression
a7n007
@a7n007
Jul 18 2017 10:03
@Blauelf thanks
CamperBot
@camperbot
Jul 18 2017 10:03
a7n007 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4504 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Jul 18 2017 10:03
I would assume more like
function updateInventory(arr1, arr2) {
    return arr1.concat(arr2).sort((a,b)=>(a[1]>b[1])-(b[1]>a[1])).reduce((res, item)=>(res.length&&res[res.length-1][1]===item[1]?(res[res.length-1][0]+=item[0]):res.push(item),res),[]);
}
Roman
@BolhovRoman
Jul 18 2017 10:04
How can i remove all non-alphabetical simbols from the string?
a7n007
@a7n007
Jul 18 2017 10:04
@Blauelf arr1 starts storing the elements from 0 and not from 1
abraham anak agung
@padunk
Jul 18 2017 10:05
How to access only this object keys? I mean console.log(Object.keys(james).... so it will return name or heigth
const james = {
    name: 'James',
    height: `5'10"`,
    weight: 185,
};
@BolhovRoman with regex
Roman
@BolhovRoman
Jul 18 2017 10:06
where i can read about reel?
regex
Markus Kiili
@Masd925
Jul 18 2017 10:06
@padunk You can loop the array Object.keys(james)
Sweet Coding :)
@SweetCodingInc
Jul 18 2017 10:08
@BolhovRoman http://regexr.com/
take a look at cheatsheet on left panel
abraham anak agung
@padunk
Jul 18 2017 10:09
@Masd925 ah, of course it is an array. thanks
CamperBot
@camperbot
Jul 18 2017 10:09
padunk sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4306 | @masd925 |http://www.freecodecamp.com/masd925
Roman
@BolhovRoman
Jul 18 2017 10:09
tnx i’ll try
Markus Kiili
@Masd925
Jul 18 2017 10:09
@padunk You could use a for...in loop too, but it would needlessly look up the prototype chain for enumerable properties (which there are none).
abraham anak agung
@padunk
Jul 18 2017 10:12
:+1:
Andres Diaz-Pinto
@diazandr3s
Jul 18 2017 10:16
@BolhovRoman I really about Regex here https://regexone.com/lesson/introduction_abcs
Learnt :) @BolhovRoman
ioakeimo
@ioakeimo
Jul 18 2017 10:30
Edit: I had more than just 1 error...
Blauelf
@Blauelf
Jul 18 2017 10:55
@a7n007 With the < in i<arr1.length (as opposed to <=), you probably already take this into account
tundeiness
@tundeiness
Jul 18 2017 10:58

can someone help take a look at this Ajax request:
var weblink = "https://fcc.weather-api-glitch.me";

$.ajax({
url: weblink,
type: "GET",
dataType: JSON

      success:  function ( data ){
                         console.log(data.weather.icon);
                         });
     error: function (error){
                    alert("Error retrieving");
                 }

});
this code will just retrieve the icon properties in the API. Is this code correct?
_

can someone help take a look at this Ajax request:
var weblink = "https://fcc.weather-api-glitch.me";

$.ajax({
           url: weblink,
           type: "GET",
           dataType: JSON

          success:  function ( data ){
                             console.log(data.weather.icon);
                             });
         error: function (error){
                        alert("Error retrieving");
                     }
});

this code will just retrieve the icon properties in the API. Is this code correct?
_

Blauelf
@Blauelf
Jul 18 2017 10:59
Maybe JSON should be "JSON" or even "json"
Also, object properties need to be separated with commata
So more like
var weblink = "https://fcc.weather-api-glitch.me";
$.ajax({
    url: weblink,
    type: "GET",
    dataType: "json", // fixed that to be a string, added comma

    success: function(data) {
        console.log(data.weather.icon);
    }, // removed ); and added comma
    error: function(error) {
        alert("Error retrieving");
    }
});
tundeiness
@tundeiness
Jul 18 2017 11:09
@Blauelf okay..thanks...there is a coord properties in this API too, how will I get that too?
CamperBot
@camperbot
Jul 18 2017 11:09
tundeiness sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4505 | @blauelf |http://www.freecodecamp.com/blauelf
json
@swoppy
Jul 18 2017 11:10
hi guys, I have the most cryptic regex ever. lol can you guys help? I'm trying to validate a phone number
this what i've come up so far
/(1\s?)?(\(?\d{3}\))?(-|\(|\s)(\d{3})(-|\(|\s)(\d{4})/gi;
Stephen James
@sjames1958gm
Jul 18 2017 11:11
@n4poleon You will probably want start and end anchors ^ $ if you want to match only the whole string.
What strings does it fail on?
json
@swoppy
Jul 18 2017 11:12
I'm confuse as well, if should I use capturing on this as I will not do anything with those varialbes at all.
Stephen James
@sjames1958gm
Jul 18 2017 11:13
@n4poleon They provide grouping so you can make the whole group optional
(1\s?)? the second ? applies to the whole ()
json
@swoppy
Jul 18 2017 11:13
@sjames1958gm well i just run it and failed a lot. lol
ioakeimo
@ioakeimo
Jul 18 2017 11:14
How can I set initial value of reduce to be a sub-array of the array I apply it on?
Blauelf
@Blauelf
Jul 18 2017 11:14
@n4poleon For the three digits with or without parentheses, you could use like (\d{3}|\(\d{3}\)) (first version without, second with both parentheses, so does not match when there's only one). Do not use a g flag ("global" makes no sense here), and i ("case-insensitive") for non-letter sequences also does not make much sense.
Stephen James
@sjames1958gm
Jul 18 2017 11:15
@ioakeimo arr.reduce(function() {}, arr[1]);
that would use arr[1]
if you want the first subarray of arr then don't supply a second arg and it will be the first
json
@swoppy
Jul 18 2017 11:15
@Blauelf yes the ```g```` made no sense. lol thanks. I'm still trying to catch up with all the details. hold on.
CamperBot
@camperbot
Jul 18 2017 11:15
n4poleon sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4506 | @blauelf |http://www.freecodecamp.com/blauelf
ioakeimo
@ioakeimo
Jul 18 2017 11:15
@sjames1958gm what about chaning (streams)?
What I want to do is something in the lines of:
arr.concat(otherArr)
   .sort(someFunc)
   .reduce( something, [resultingArray[1]])
Stephen James
@sjames1958gm
Jul 18 2017 11:18
@ioakeimo You have to break the chaining in that case, as far as I know
json
@swoppy
Jul 18 2017 11:19

@Blauelf I'm trying to translate this to human languange

(\d{3}|\(\d{3}\))

3 digits or '(' followed by 3 digits followed by ')', am i correct??

ioakeimo
@ioakeimo
Jul 18 2017 11:19
dammit, I've been struggling to figure this out for a one-liner
@sjames1958gm thanks
CamperBot
@camperbot
Jul 18 2017 11:19
ioakeimo sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8096 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Blauelf
@Blauelf
Jul 18 2017 11:19
@n4poleon Yes. It will match either of them.
Stephen James
@sjames1958gm
Jul 18 2017 11:21
@ioakeimo I guess you could do something hacky like
.reduce(function(a, c, i, arr) {
   a = a || [arr[1]];
   // something
 },  false);
ioakeimo
@ioakeimo
Jul 18 2017 11:22
@sjames1958gm wow, I would have never thought of this one! :P
this would execute in each callback though, wouldn't it?
Stephen James
@sjames1958gm
Jul 18 2017 11:22
Yeah, but it would only do a = a after the first
I did say Hacky :)
ioakeimo
@ioakeimo
Jul 18 2017 11:23
:smile:
I'll give it another 5 mins of thought and go with it if I don't come up with something else
Stephen James
@sjames1958gm
Jul 18 2017 11:24
Standard disclaimer - that code is not warranted against bugs or typos
json
@swoppy
Jul 18 2017 11:26
:) now I cant match the numbers without () and - and whitespace
ioakeimo
@ioakeimo
Jul 18 2017 11:26
I thought of another hack as well, but it would still be one extra check per callback
json
@swoppy
Jul 18 2017 11:30
@sjames1958gm okay, how do I say optional or without '(' and '-' and whitespace?
in regex
(\(-\s?|^)
is that accurate?
Blauelf
@Blauelf
Jul 18 2017 11:33
@n4poleon I think you meant something like ^(1[-\s]?)?? After the beginning of the string an optional group of a 1 optionally followed by a dash or space.
json
@swoppy
Jul 18 2017 11:36
@Blauelf okay how does [] works? I assumed everything in it is OR? sorry my english is bad. lo
ioakeimo
@ioakeimo
Jul 18 2017 11:36
I'm getting: TypeError: inventory.push is not a function, shouldn't my initial value be already in place?
function updateInventory(arr1, arr2) {

 return arr1.concat(arr2)
            .sort((str1,str2) => str1[1].localeCompare(str2[1]))
            .reduce((inventory, product) => {
                let index = inventory.length-1;
                return (inventory[0] && inventory[index][1] === product[1]) 
                     ? (inventory[index][0] += product[0])
                     : (inventory.push(product));
                }
                ,[]);
}
Blauelf
@Blauelf
Jul 18 2017 11:38
@n4poleon [] matches any character within. It also knows ranges, like [A-Z] for any character from A to Z. In [-\s], - is taken literally.
json
@swoppy
Jul 18 2017 11:39
right. we have narrowed it down. :)
@Blauelf
Markus Kiili
@Masd925
Jul 18 2017 11:39
@ioakeimo Maybe some problem when inventory is [] at first.
ioakeimo
@ioakeimo
Jul 18 2017 11:40
@Masd925 yeah but [].push should indeed be a function
Markus Kiili
@Masd925
Jul 18 2017 11:41
@ioakeimo Might not be on the next step when you do fun things on the first.
json
@swoppy
Jul 18 2017 11:42
does the ^ only applies on this capture or it applies until the end of the regex?
@Blauelf
Blauelf
@Blauelf
Jul 18 2017 11:42
@ioakeimo The problem is that push returns a number, the new array length.
@n4poleon ^ outside of character sets refers to the beginning of the string (or line in multi-line mode)
ioakeimo
@ioakeimo
Jul 18 2017 11:43
@Blauelf I'm an idiot! Of course it does :P Thanks
CamperBot
@camperbot
Jul 18 2017 11:43
ioakeimo sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4507 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Jul 18 2017 11:44
@n4poleon ^ is a zero-width special character (like \b which matches between word and non-word characters)
ioakeimo
@ioakeimo
Jul 18 2017 11:44
I need to find a way of writing this whole reduce cleaner and better
Blauelf
@Blauelf
Jul 18 2017 11:46
In my ugly version ( :point_up: 18. Juli 2017 12:03), I used the comma operator. But maybe you're better off with an if-else instead of the ternary operator?
Markus Kiili
@Masd925
Jul 18 2017 11:49
@ioakeimo I used a test for accumulator being empty.
ioakeimo
@ioakeimo
Jul 18 2017 11:52
@Masd925 you mean something other than my inventory[0] ?
@Blauelf never used comma operator before but it seems to work perfectly in this case!
My now working code:
function updateInventory(arr1, arr2) {

 return arr1.concat(arr2)
            .sort((str1,str2) => str1[1].localeCompare(str2[1]))
            .reduce((inventory, product) => {
                let index = inventory.length-1;
                return (inventory[0] && inventory[index][1] === product[1]) 
                     ? (inventory[index][0] += product[0])
                     : (inventory.push(product)),inventory;
                }
                ,[]);
}
Markus Kiili
@Masd925
Jul 18 2017 11:53
@ioakeimo I tested if inventory.length was 0 and acted based on that.
If it is zero, you cannot access inventory.
Maybe you are testing it too, not sure.
ioakeimo
@ioakeimo
Jul 18 2017 11:55
@Masd925 I thought I'd use inventory[0] as a faulty value in the initial state. After that phase inventory[0] won't be null so I'm good to go
The one thing I'm not sure about is if declaring index in my reduce does actually help or not.
ioakeimo
@ioakeimo
Jul 18 2017 12:02
Because it could just be:
function updateInventory(arr1, arr2) {

 return arr1.concat(arr2)
            .sort((str1,str2) => str1[1].localeCompare(str2[1]))
            .reduce((inventory, product) => (
                (inventory[0] && inventory[inventory.length-1][1] === product[1]) 
                    ? (inventory[inventory.length-1][0] += product[0])
                    : (inventory.push(product)),inventory)
            ,[]);
}
Moisés Man
@moigithub
Jul 18 2017 12:07
: (inventory.push(product)),inventory;
: [...inventory, product] <-- spread operator
or
: inventory.concat( product ) <-- concat
check it out if u like
tundeiness
@tundeiness
Jul 18 2017 12:08
@Masd925 can you help review this code:
@Masd925
var geoL = navigator.geolocation.getCurrentPosition(function(position) { (position.coords.longitude + ' , ' + position.coords.latitude); }


var weblink = "https://fcc.weather-api-glitch.me";

var FCCgeoL =  $.ajax({ url: weblink, 
                                      type: "GET", 
                                     dataType: "json", 
                                     success: function(data) {
                                       return data.weather.coord;
                                     }, 
                                    error: function(error) { 
                                       alert("Error retrieving"); } 
                           });

var clouds; 
var icon;
var winds;
var pWeather;

if ( geoL == FCCgeoL) {

clouds = data.weather.clouds;
icon = data.weather.icon;
winds = data.weather.winds;
pWeather = data.weather; 

return clouds, icon, winds, pWeather; 
} else {
     return "Cannot access your location. You have to select Allow in the alert box.       Refresh the page again and slecet allow"; 
}
ioakeimo
@ioakeimo
Jul 18 2017 12:08
@moigithub I actually like the use of spread operator there! Nice!
@moigithub it still produces a TypeError though
Moisés Man
@moigithub
Jul 18 2017 12:12
u using comma op to return ur inventory... did u removed that ? @ioakeimo
ioakeimo
@ioakeimo
Jul 18 2017 12:13

@moigithub

function updateInventory(arr1, arr2) {

 return arr1.concat(arr2)
            .sort((str1,str2) => str1[1].localeCompare(str2[1]))
            .reduce((inventory, product) => (
                (inventory[0] && inventory[inventory.length-1][1] === product[1]) 
                    ? (inventory[inventory.length-1][0] += product[0])
                    : [...inventory,product])
            ,[]);
}

Throws: TypeError: inventory[Symbol.iterator] is not a function

Moisés Man
@moigithub
Jul 18 2017 12:14
return 1,2 <-- will make return to "return" last value after comma (comma op)
u will need to change ? (inventory[inventory.length-1][0] += product[0]) too if u wanna replace entirelly comma op too
ioakeimo
@ioakeimo
Jul 18 2017 12:14
There is no comma op above ^
Moisés Man
@moigithub
Jul 18 2017 12:15
oh yea.. sry ..copy paste :P
was meant for push part.. but... u could replace ? part with.. (thinking) :)
ioakeimo
@ioakeimo
Jul 18 2017 12:18
I don't really get what the error is about. Shouldn't [...a,b] return an array?
Moisés Man
@moigithub
Jul 18 2017 12:19
yep
but ? ternary first part isnt returning an array
ioakeimo
@ioakeimo
Jul 18 2017 12:20
it is mutating an existing one though (in theory)
initial value is an array, so in 1st callback the return value should be that of executing return [...[],product]
Maybe there is the problem...? Can spread be applied on an empty array?
Moisés Man
@moigithub
Jul 18 2017 12:23
ofc but probably would be useless... (nothing to extract)
(if using a array variable wouldnt matter)
ioakeimo
@ioakeimo
Jul 18 2017 12:24
Then where is the error? Yes ? part of ternary does not return an array but mutates one (it can only be executed if an array is in place, see check inventory[0] &&
Moisés Man
@moigithub
Jul 18 2017 12:24
it mutates.. but its not returnin the array
ioakeimo
@ioakeimo
Jul 18 2017 12:25
it doesn't need to
Moisés Man
@moigithub
Jul 18 2017 12:25
it does.. cuz reduce return value from callback will be the next value for ur "inventory"
ioakeimo
@ioakeimo
Jul 18 2017 12:26
Why does this one work then?
function updateInventory(arr1, arr2) {

 return arr1.concat(arr2)
            .sort((str1,str2) => str1[1].localeCompare(str2[1]))
            .reduce((inventory, product) => (
                (inventory[0] && inventory[inventory.length-1][1] === product[1]) 
                    ? (inventory[inventory.length-1][0] += product[0])
                    : (inventory.push(product)),inventory)
            ,[]);
}
Oh, wait... I see. Is the comma op applied to the whole ternary?
Nick Janne
@njanne19
Jul 18 2017 12:27
For working with react, does everyone think the best way for listening to key presses is through jQeuryu
Moisés Man
@moigithub
Jul 18 2017 12:28
not easy to make 1 liner for ternary true part..
u need to separate last element mutate it.. and join back to make a full array again (which will be ur returning value)
probably this code will be longer than what u had at start :P
?[...inventory.slice(0,inventory.length-1), [inventory.pop()[0]+product[0], product[1]] ]
should work i think
@ioakeimo yep cuz after comma is the "real" returning value
shivam gupta
@shivamg11000
Jul 18 2017 12:32
with respect to react
why would handleClick here be executed only once while rendering
<h1 onClick={this.handleClick()}></h1>
张宏利
@axhuangs
Jul 18 2017 12:34

function queue(arr, item) {
// 请把你的代码写在这里

return item; // 请修改这一行
}

// 初始化测试数据
var testArr = [1,2,3,4,5];

// 控制台输出
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // 你可以修改这一行来测试你的代码
console.log("After: " + JSON.stringify(testArr));

Blauelf
@Blauelf
Jul 18 2017 12:34
@ioakeimo Comma operator has very low precedence. The operator itself evaluates the left side, throws it away (only side-effects stay), and evaluates to the value of the right side. Comma operator usually creates less readable code, it was just a way to create a somewhat short one-liner.
张宏利
@axhuangs
Jul 18 2017 12:34
这里可以用 push和shift方法吗 怎么我这老是不对
Nick Janne
@njanne19
Jul 18 2017 12:35
@shivamg11000 It's being called on render because you have the () in the call
ioakeimo
@ioakeimo
Jul 18 2017 12:35
@Blauelf Yeah, I figured that out. @moigithub thank you both. I ended up submiting this one:
function updateInventory(arr1, arr2) {

 return arr1.concat(arr2)
            .sort((str1,str2) => str1[1].localeCompare(str2[1]))
            .reduce((inventory, product) => (
                (inventory[0] && inventory[inventory.length-1][1] === product[1]) 
                    ? (inventory[inventory.length-1][0] += product[0])
                    : (inventory.push(product))
                ,inventory)
            ,[]);
}
CamperBot
@camperbot
Jul 18 2017 12:35
ioakeimo sends brownie points to @blauelf and @moigithub :sparkles: :thumbsup: :sparkles:
:warning: ioakeimo already gave blauelf points
:star2: 3516 | @moigithub |http://www.freecodecamp.com/moigithub
张宏利
@axhuangs
Jul 18 2017 12:36
要求是将6添加到最后结尾,删除第一个元素 并抛出
Nick Janne
@njanne19
Jul 18 2017 12:36
@shivamg11000 change it to onClick={this.handleClick} or onClick={()=> this.handleClick}
shivam gupta
@shivamg11000
Jul 18 2017 12:36
@njanne19 but its applied to onClick, it should be executed on click
Blauelf
@Blauelf
Jul 18 2017 12:36
@axhuangs If you don't speak English, there's also a Chinese channel
张宏利
@axhuangs
Jul 18 2017 12:36
oh sorry
Nick Janne
@njanne19
Jul 18 2017 12:37
@shivamg11000 I understand that but when you have the () it calls the method as soon as it's read not when the click happens
Blauelf
@Blauelf
Jul 18 2017 12:37
@axhuangs If you ask in English, that's also ok, just not too many Chinese speakers here ;)
shivam gupta
@shivamg11000
Jul 18 2017 12:38
@njanne19 thats why I am asking the why
why it is called as soon as it's read as it is applied to a event handler
张宏利
@axhuangs
Jul 18 2017 12:38
ok thank you
shivam gupta
@shivamg11000
Jul 18 2017 12:38
either it should never be called
@njanne19
Nick Janne
@njanne19
Jul 18 2017 12:38
I'm confused as to what you're trying to ask
shivam gupta
@shivamg11000
Jul 18 2017 12:39
@njanne19 I am saying why it works like that
Moisés Man
@moigithub
Jul 18 2017 12:39
adding a set of () to a function name execute/calls the function .. returning some value
like @njanne19 said @shivamg11000
Blauelf
@Blauelf
Jul 18 2017 12:39
@shivamg11000 Looks like the part in the {} is evaluated instantly, and is probably expected to return a handler function. Adding the () in this case calls the function.
shivam gupta
@shivamg11000
Jul 18 2017 12:40
@moigithub I know
but it should execute on every click event
Moisés Man
@moigithub
Jul 18 2017 12:40
event handler requires u pass a function itself
soo no () after its name (unless its a "function factory" )
shivam gupta
@shivamg11000
Jul 18 2017 12:40
it only executes for only one time which is not when the user clicks
张宏利
@axhuangs
Jul 18 2017 12:41
@Blauelf I will only a little English, although is learning, but very slowly
@Blauelf Thank you very much for your reminder
CamperBot
@camperbot
Jul 18 2017 12:42
axhuangs sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4508 | @blauelf |http://www.freecodecamp.com/blauelf
Moisés Man
@moigithub
Jul 18 2017 12:42
:point_up: July 18, 2017 7:36 AM @shivamg11000 should work
shivam gupta
@shivamg11000
Jul 18 2017 12:42
I know
@moigithub
张宏利
@axhuangs
Jul 18 2017 12:43
@camperbot Thank you very much
@Blauelf
CamperBot
@camperbot
Jul 18 2017 12:43
axhuangs sends brownie points to @camperbot and @blauelf :sparkles: :thumbsup: :sparkles:
:warning: axhuangs already gave blauelf points
:star2: 3370 | @camperbot |http://www.freecodecamp.com/camperbot
shivam gupta
@shivamg11000
Jul 18 2017 12:44
@moigithub how you send that July 18, 2017
Moisés Man
@moigithub
Jul 18 2017 12:45
hover on the timestamp ------------------------------------>
alt + click to quote
Abhinav Mishra
@abhinav-m
Jul 18 2017 12:46
Hey guys, this is my simon game project, i can't figure out for the life of me what is bugging the red circle
can anyone help figuring it out :|
shivam gupta
@shivamg11000
Jul 18 2017 12:48
张宏利
@axhuangs
Jul 18 2017 12:56
Problem solved, it is I think too complicated. Ha ha
Thank you for your attention
a7n007
@a7n007
Jul 18 2017 13:16

function diffArray(arr1, arr2) {
var c,i,j,newArr = [];
for(i=0;i<arr1.length-1;i++)
{
if(arr2.indexOf(arr1[i]));
newArr.push(arr1[i]);
}

for(i=0;i<arr2.length-1;i++)
{
if(arr1.indexOf(arr2[i]));
newArr.push(arr2[i]);
}
return newArr;
}

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

why is my code still not working
Moisés Man
@moigithub
Jul 18 2017 13:19
; is statement terminator @a7n007
push inside for-loop is ALWAYS adding values to newArr
shivam gupta
@shivamg11000
Jul 18 2017 13:26
hey whats the use of react-router
odm275
@odm275
Jul 18 2017 13:30
@odm275
var compId = {"one":"A1","two":"A2","three":"A3",
"four":"B1","five":"B2","six":"B3",
"seven":"C1","eight":"C2":,"nine":"C3"};
I'm getting "SyntaxError: missing } after property list"
Any clues
?
Blauelf
@Blauelf
Jul 18 2017 13:30
@a7n007 Use if (arr2.indexOf(arr1[i]) === -1), and I think I told you not to use -1 in i < arr1.length
odm275
@odm275
Jul 18 2017 13:31
var compId = {"one":"A1","two":"A2","three":"A3",
"four":"B1","five":"B2","six":"B3",
"seven":"C1","eight":"C2":,"nine":"C3"};
I'm getting "SyntaxError: missing } after property list"
Any clues
?
Blauelf
@Blauelf
Jul 18 2017 13:31
@odm275 Remove extra : after "C2"
a7n007
@a7n007
Jul 18 2017 13:32

function diffArray(arr1, arr2)
{
var c,i,j,newArr = [];
for(i=0;i<arr1.length-1;i++)
{
if (arr2.indexOf(arr1[i]) === -1)
newArr.push(arr1[i]);
}

for(i=0;i<arr2.length-1;i++)
{
if (arr1.indexOf(arr2[i]) === -1)
newArr.push(arr2[i]);
}
return newArr;
}

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

odm275
@odm275
Jul 18 2017 13:32
@Blauelf eagle eye mate!
a7n007
@a7n007
Jul 18 2017 13:32
still it was not working
odm275
@odm275
Jul 18 2017 13:32
@Blauelf thanks
CamperBot
@camperbot
Jul 18 2017 13:32
odm275 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4509 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Jul 18 2017 13:32
@a7n007 Use if (arr2.indexOf(arr1[i]) === -1), and I think I told you not to use -1 in i < arr1.length
a7n007
@a7n007
Jul 18 2017 13:33
sorry my bad its working
thanks everyone
Blauelf
@Blauelf
Jul 18 2017 13:33
:+1:
a7n007
@a7n007
Jul 18 2017 13:33
@Blauelf thanks to you
CamperBot
@camperbot
Jul 18 2017 13:33
a7n007 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4510 | @blauelf |http://www.freecodecamp.com/blauelf
ioakeimo
@ioakeimo
Jul 18 2017 13:33
Is there any built-in function that could return a set of characters given a string?
Like setFrom("abcde...abcde") -> "abcde..."
a7n007
@a7n007
Jul 18 2017 13:34

@Blauelf

@a7n007 Use `if (arr2.indexOf(arr1[i]) === -1)``but why cant i use my version

Blauelf
@Blauelf
Jul 18 2017 13:37
@ioakeimo What do you mean? Like [...new Set("abcde...abcde").values()].sort().join("")?
@a7n007 What is your version?
ioakeimo
@ioakeimo
Jul 18 2017 13:38
@Blauelf something like that but I was hoping as simple as new Set""abcde...abcde"
Blauelf
@Blauelf
Jul 18 2017 13:38
Most of that is just for building a string from that set.
values returns an iterator, so I unroll it into an array. sort ensures alphabetical sorting (well, sorting by unicode code point), and join makes it a string.
ioakeimo
@ioakeimo
Jul 18 2017 13:39
I see
I might not need that though. I'm trying to achieve the permutations challenge using only math
Blauelf
@Blauelf
Jul 18 2017 13:42

Oh, great. Last guy that claimed to have found that solution made me file a bug, now we have three new test cases that all made his solution fail.

I would really appreciate a working maths-based solution, especially if it comes with a decent explanation :)

Jeff
@jolove011
Jul 18 2017 13:48
Hello everyone, I am
Blauelf
@Blauelf
Jul 18 2017 13:50
You think, therefore you are? Cogitas, ergo es?
Nana Owusu
@nanaowusunyamekye
Jul 18 2017 13:51

Hey guys, if I want to check if the value of a property on an object is a string, can i do

if (typeof object[property] === "string"

??

Blauelf
@Blauelf
Jul 18 2017 13:51
Sure you can (given you close these parentheses somewhere)
ioakeimo
@ioakeimo
Jul 18 2017 13:53
@Blaulef I already have one in my mind, I just need to translate it to code
Nana Owusu
@nanaowusunyamekye
Jul 18 2017 13:55
@Blauelf hahahaha, missed that. so this if (typeof object[property] === "string") should work fine right?
ioakeimo
@ioakeimo
Jul 18 2017 13:55
But the first thing I need is to get how many unique elements are in the provided string with an easy, built-in, elegant way. So @Blauelf would let unique = new Set(string).size give me what I want?
Guderian Raborg
@hypercuber
Jul 18 2017 13:57
@ioakeimo
let str = 'abcde...abcde';
let arr = Array.from(new Set(str)).length;
console.log(arr); //6
ioakeimo
@ioakeimo
Jul 18 2017 13:58
@hypercuber why use array? Doesn't Set have a size property?
Guderian Raborg
@hypercuber
Jul 18 2017 13:58
idk much about new Set
ioakeimo
@ioakeimo
Jul 18 2017 14:01
My solution for getting the unique elements seem to work so I'll go with it. Creating an array would be redundant. Set has some great functionality in specific cases, I'd suggest you give it a chance if you ever need to work with unique elements
Guderian Raborg
@hypercuber
Jul 18 2017 14:02
@ioakeimo Thanks for your advice. I was overlooking at this
CamperBot
@camperbot
Jul 18 2017 14:02
hypercuber sends brownie points to @ioakeimo :sparkles: :thumbsup: :sparkles:
:cookie: 308 | @ioakeimo |http://www.freecodecamp.com/ioakeimo
Moisés Man
@moigithub
Jul 18 2017 14:02
s=new Set("asd")
//Set(3) {"a", "s", "d"}
s.size
//3
i got used to use devtools/console to test code snippets
i like the autocomplete feature
s<dot> and a list of properties/methods pops out
ioakeimo
@ioakeimo
Jul 18 2017 14:03
@moigithub yeah but I'm using chrome so pressing Enter (which I'm used to for auto-completing) messes up every time, and I don't want to get used to using arrows for completion
While on fcc, I usually just return what I want to log
function permAlone(str) {
  let unique = new Set(str).size;
  return unique;
}
Blauelf
@Blauelf
Jul 18 2017 14:07
Shift+Return is a common key combo for multi-line
I like using repl.it, though it emulates a text console, so does not log browsable objects.
Abhinav Mishra
@abhinav-m
Jul 18 2017 14:14
https://codepen.io/abhinavthinktank/full/RgmBjZ/ Can anyone help me figure out what's wrong with the red circle in my simon game
Basically , it blinks the first time then doesn't, happening only with this one
John Alcher
@alchermd
Jul 18 2017 14:25
Quick question: How do I add a class to an element when another element comes into view?
Quang-Thuy Hoang
@averageAZNguy
Jul 18 2017 14:26
@alchermd are you adding another elementing?
wouldn't addClass do?
John Alcher
@alchermd
Jul 18 2017 14:27
@averageAZNguy Example: I'm scrolling through a page and the projects section comes into view. The projects link in the navbar then gets highlighted.
@averageAZNguy addClass does, but I need to setup the condition to determine if the element is in view.
Quang-Thuy Hoang
@averageAZNguy
Jul 18 2017 14:29
that i'm not sure. my best attempt personally would be something with onload and then with delay transition + display
John Alcher
@alchermd
Jul 18 2017 14:32
@averageAZNguy After looking a bit through my old github projects, I realized I used scrollspy.js.
ioakeimo
@ioakeimo
Jul 18 2017 14:45
@Blauelf I don't have energy left to work on it but I suppose this would work link
Ayush Mahajan
@ay2306
Jul 18 2017 14:45
Hey guys can you help me. I am searching for how to animate an image to shrink to expand its size upon clicking in given time
Blauelf
@Blauelf
Jul 18 2017 14:46
@ioakeimo That's not maths, that's counting. A little bit like my JavaScript version.
a7n007
@a7n007
Jul 18 2017 14:46
@Blauelf my version is if(arr2.indexOf(arr1[i]))
ioakeimo
@ioakeimo
Jul 18 2017 14:46
@Blauelf but it is :P Actually permutations in general is math :P
This specific problem is based on this
just modified so the numbers are different
Blauelf
@Blauelf
Jul 18 2017 14:48
@a7n007 You need to check whether arr1[i] can be found in arr2 (and if not push the element). indexOf returns -1 if it could not find the element. Without ===-1, you are testing whether the result itself is truthy, and both -1 and an index other than 0 are truthy, while only an index of 0 is falsy. So this gives no useful information.
ioakeimo
@ioakeimo
Jul 18 2017 14:48
Not sure if you checked the question or the answer of that stackoverflow post though...
Blauelf
@Blauelf
Jul 18 2017 14:49
@ioakeimo I don't think those two are that similar.
ioakeimo
@ioakeimo
Jul 18 2017 14:49
the principle is the same (inclusion-exclusion)
@Blauelf just to be sure, did you check the answer of the stackoverflow post or the question?
teevik
@teevik
Jul 18 2017 14:52
@shivamg11000 Not sure if you got an answer, but it makes react be able to show different components based on the url path
Blauelf
@Blauelf
Jul 18 2017 14:53
Oh, checked the "question". Not sure about that answer.
ioakeimo
@ioakeimo
Jul 18 2017 14:55
That explains it. Yeah the answer is code for a limited area of that problem based on the inclusion-exclusion principle. Probably needs recursion to make it generally applicable but it is pure math.
GeorgeII
@GeorgeII
Jul 18 2017 14:58

Can someone tell me why click event doesn't work? I mean this 2 last strings of my code

  $("#online-button").click(function() {
    $("li").fadeIn('slow');

https://codepen.io/GeorgeIV/pen/jwRmvp?editors=1010

Blauelf
@Blauelf
Jul 18 2017 14:58
@ioakeimo I don't really get that part with subtracting 11, then adding those with 11 and 22. What about those with 33?
ioakeimo
@ioakeimo
Jul 18 2017 15:02
@Blauelf tbh I'm too tired atm to fully get the concept too, but it is based on unions. What you basically do, is calculate all permutations (which is a lot easier) then subtract a union of those that don't meet your criteria, then add some because the math you used subtracted them 2 times instead of 1 etc etc
Christian
@Neralizer
Jul 18 2017 15:03
can anyone give me a hand with my weather app? https://codepen.io/cneral21/pen/XMRgap?editors=0010
Boris Yordanov
@borisyordanov
Jul 18 2017 15:03
@GeorgeII the event listner is working, what exactly is the problem?
@Neralizer what do you need help with?
Christian
@Neralizer
Jul 18 2017 15:04
I'm getting error codes when I try to log a few of my api variables
Says, "cannot read property '1' of undefined", which I think is referring to data
Blauelf
@Blauelf
Jul 18 2017 15:05
@GeorgeII The element you fade in is already visible, so what should fadeIn do?
Christian
@Neralizer
Jul 18 2017 15:05
and data main temp isn't even showing up
Jason Luboff
@JLuboff
Jul 18 2017 15:05
@Neralizer Geolocation is async, so while it's waiting to run, your .getJSON runs with the url having undefined for the lat and lon
@Neralizer Put the .getJSON inside your geolocation
GeorgeII
@GeorgeII
Jul 18 2017 15:07
@borisyordanov @Blauelf Mystic. That did not work earlier
Blauelf
@Blauelf
Jul 18 2017 15:08
Maybe the page reload did not work, and you saw a previous version.
Sometimes the page reload in codepen is annoying (reloads on every single character, and complains about invalid JavaScript, yeah, I'm typing as fast as I can!), other times it won't recognise any changes until you manually hit the run button. I totally not get it.
Jason Luboff
@JLuboff
Jul 18 2017 15:12
@Blauelf oh man.. I hate that. Let me finish typing out my console.log damn it!! Then of course I finish...and it doesn't run :joy:
Christian
@Neralizer
Jul 18 2017 15:13
@JLuboff https://codepen.io/cneral21/pen/XMRgap?editors=0010 I moved some things around, might have some of my brackets messed up and that's why it's not fixed
Jiri Laza
@N4thyra
Jul 18 2017 15:14
Hi folks, could anyone give me a piece of advice? I'd like to know whether there is a way to short a statement like this x === 5 || x === 6 || x === 8 and so on, can I omit repeating x === ?
*shorten
Jason Luboff
@JLuboff
Jul 18 2017 15:15
@Neralizer Shouldn't this line: $("#weather").html(JSON.stringify(json)); be $("#weather").html(JSON.stringify(data));?
Christopher McCormack
@cmccormack
Jul 18 2017 15:15
@Neralizer your weather array is only 1 length so use weather[0]
Blauelf
@Blauelf
Jul 18 2017 15:15
@N4thyra If you have a range, you could use <= and >= (or < or > or whatever is appropriate). If you have a finite list (and it does not contain NaN), you could store everything in an array, like [5, 6, 8].indexOf(x) !== -1
Jason Luboff
@JLuboff
Jul 18 2017 15:15
@Neralizer And also...there is nothing in your DOM with the ID of weather?
Boris Yordanov
@borisyordanov
Jul 18 2017 15:16
@N4thyra you can take the statement, store it in the variable and use that instead
Jason Luboff
@JLuboff
Jul 18 2017 15:16
@cmccormack Its actually length of 2, not sure why
Christian
@Neralizer
Jul 18 2017 15:16
bingo, thanks @cmccormack @JLuboff
CamperBot
@camperbot
Jul 18 2017 15:16
neralizer sends brownie points to @cmccormack and @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2078 | @jluboff |http://www.freecodecamp.com/jluboff
:star2: 1034 | @cmccormack |http://www.freecodecamp.com/cmccormack
Christopher McCormack
@cmccormack
Jul 18 2017 15:17
@JLuboff weird maybe different areas have different length weather:Array(1)
Jason Luboff
@JLuboff
Jul 18 2017 15:17
@cmccormack Likely so
Christian
@Neralizer
Jul 18 2017 15:17
good catch @JLuboff I originally had a div with the id of weather but got rid of it and didn't change
Ogundele Olumide
@Lumexralph
Jul 18 2017 15:18
Hello Everybody! :wave:
Keith
@7KAG7
Jul 18 2017 15:19
for (var i = 0; i < this.length; i++) why is 'i' always used?
Jiri Laza
@N4thyra
Jul 18 2017 15:19
@Blauelf @borisyordanov thanks for the tips. I have an array like this: symbol = ['+', '-', '÷', '×']; and basically I need to check whether my variable 'buttonValue' is equal to each of the item in the array. I can write down: buttonValue === '+' || buttonValue === '-' and so on, but it seems to be inefficient
CamperBot
@camperbot
Jul 18 2017 15:19
n4thyra sends brownie points to @blauelf and @borisyordanov :sparkles: :thumbsup: :sparkles:
:cookie: 357 | @borisyordanov |http://www.freecodecamp.com/borisyordanov
:star2: 4511 | @blauelf |http://www.freecodecamp.com/blauelf
Jason Luboff
@JLuboff
Jul 18 2017 15:19
@dudeguykid You can use anything, just i is commonly used I assume since its our 'iterator' so.... i for iterator
@Neralizer :+1:
@Lumexralph :wave:
Blauelf
@Blauelf
Jul 18 2017 15:19
@N4thyra So like symbol.indexOf(buttonValue) !== -1?
Keith
@7KAG7
Jul 18 2017 15:19
@JLuboff thanks!
CamperBot
@camperbot
Jul 18 2017 15:19
dudeguykid sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2079 | @jluboff |http://www.freecodecamp.com/jluboff
Keith
@7KAG7
Jul 18 2017 15:20
just one of those weird things ive been typing for so long and never knew why
Jiri Laza
@N4thyra
Jul 18 2017 15:20
@Blauelf That makes sense and should do the work. I'll try that
Christopher McCormack
@cmccormack
Jul 18 2017 15:21
@Lumexralph :wave:
Ogundele Olumide
@Lumexralph
Jul 18 2017 15:21
@dudeguykid it's just a common thing, more like saying initializer, stolen from C
@dudeguykid but you can use anything as @JLuboff said
@cmccormack @JLuboff How're you guys doing?
Jason Luboff
@JLuboff
Jul 18 2017 15:22
@Lumexralph Doing alright. Yourself?
Christopher McCormack
@cmccormack
Jul 18 2017 15:23
@Lumexralph doing great!
Ogundele Olumide
@Lumexralph
Jul 18 2017 15:23
@JLuboff been travels since Saturday, just got some lil time to myself
Keith
@7KAG7
Jul 18 2017 15:23
feelin good feelin great
Ogundele Olumide
@Lumexralph
Jul 18 2017 15:25
@dudeguykid @cmccormack cool to know :smile: it's time to dive deep into NodeJS
Christopher McCormack
@cmccormack
Jul 18 2017 15:26
That should be fun. Any particular project?
Ogundele Olumide
@Lumexralph
Jul 18 2017 15:28
@cmccormack i need to go deep about what handles my requests from the front-side....just curiousity
Christopher McCormack
@cmccormack
Jul 18 2017 15:29
That's cool. I need to do that too but with Django for work. Need to get a login flow setup to use an internal API
KatieCz
@KteCz77
Jul 18 2017 15:29
Is anyone here also doing the Udemy Web Developer Bootcamp? I don't see a group for it but I'd love someone to pair with or to know if there is a group that i'm missing. I'm on section 11, lecture 130
Ogundele Olumide
@Lumexralph
Jul 18 2017 15:29
@cmccormack my second love Python
Christopher McCormack
@cmccormack
Jul 18 2017 15:30
I think a lot of people bought that course but no idea how to reach them :)
Ogundele Olumide
@Lumexralph
Jul 18 2017 15:30
@KteCz77 you can still ask where you need understanding or help, great guys here to help
KatieCz
@KteCz77
Jul 18 2017 15:31
@Lumexralph yes, i might have to do that. i'm not totally lost but not totally getting it either. thanks!
CamperBot
@camperbot
Jul 18 2017 15:31
ktecz77 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 2035 | @lumexralph |http://www.freecodecamp.com/lumexralph
Ogundele Olumide
@Lumexralph
Jul 18 2017 15:32
@KteCz77 yeah, I can be lost too at times :wink:
Bradley Sands
@sandsbe
Jul 18 2017 15:49
@KteCz77 have you finished fCC or are you doing it concurrently?
or neither. Either way, the fCC program could help get over hurdles with Udemy.
KatieCz
@KteCz77
Jul 18 2017 15:51
@sandsbe i'm doing them together. i do the udemy course then i search the fcc map for related topics and i do those to help get a different perspective and more practice. are you familiar with both? would you do something differently?
Andres Diaz-Pinto
@diazandr3s
Jul 18 2017 15:54
Hi everyone! :)
Bradley Sands
@sandsbe
Jul 18 2017 15:56
So, IMO, at least crank out fCC's front-end certificate first. Maybe back-end too. You'll get into a timing/scheduling/workflow groove. Not saying Udemy is bad/good but sometimes those courses breeze through concepts and without the paired support, hard to get help. Here, with fCC and Gitter, the support is FANTASTIC and everyone knows exactly what problem you're learning on. Then, you'll mow through Udemy, have built relationships, and have a lot of success under your belt for when you hit tough patches in Udemy.
Jason Luboff
@JLuboff
Jul 18 2017 15:56
Hello\
Abhinav Mishra
@abhinav-m
Jul 18 2017 15:56
@KteCz77 What other stuff are you ing
Pieter Stokkink
@forkerino
Jul 18 2017 15:56
:wave:
Jason Luboff
@JLuboff
Jul 18 2017 15:56
@forkerino Morning (afternoon)
Abhinav Mishra
@abhinav-m
Jul 18 2017 15:56
@sandsbe Im finally done with my front end cert! Just got it today! You recommend starting backend straight away or going through the intermediate section first?
Bradley Sands
@sandsbe
Jul 18 2017 15:57
What intermediate section?
Ya, backend is super important.
Abhinav Mishra
@abhinav-m
Jul 18 2017 15:57
The one with react and d3
@forkerino :wave:
Bradley Sands
@sandsbe
Jul 18 2017 15:57
"super important" <- I type like a 12 yr old
Jason Luboff
@JLuboff
Jul 18 2017 15:57
Thats Data Viz
It is its own section
Abhinav Mishra
@abhinav-m
Jul 18 2017 15:57
Yeap, intermediate as in lies between frontend and backedn , hehe
KatieCz
@KteCz77
Jul 18 2017 15:58
@abhinav-thinktank I've got some js books that i'm using for reference and i'm doing the udemy web dev course and fcc together. any other ideas?
Bradley Sands
@sandsbe
Jul 18 2017 15:58
Backend, IMO. Understand Git, learn Node. Get the "full stack". Then, make it dance with Viz stuff.
Abhinav Mishra
@abhinav-m
Jul 18 2017 15:58
i think i'll concurrently do backend and data vis, unless ofc someone else recommends something else
@sandsbe that sounds convenient.
Bradley Sands
@sandsbe
Jul 18 2017 15:58
Works just as well. It's all gravy.
Abhinav Mishra
@abhinav-m
Jul 18 2017 15:59
@KteCz77 what Im only focusing on completing fcc stuff, i just built minesweeper apart from that on my own.
Jason Luboff
@JLuboff
Jul 18 2017 15:59
Wouldn't you need some sort of data viz (angular/react/ whatever) to get full stack though?
Abhinav Mishra
@abhinav-m
Jul 18 2017 15:59
@KteCz77 What books are you using for reference?
I plan to code some decent looking websites and improve my portfolio page
as practice
Bradley Sands
@sandsbe
Jul 18 2017 16:00
I have Get Programming with JavaScript and its so far my favorite. Great examples, good pacing. Really designed to teach OOP with JS for beginnners.
Also gets into Node in the end
KatieCz
@KteCz77
Jul 18 2017 16:01
@abhinav-thinktank I have the Head First book, Javascript for Absolute Beginners and JavaScript 24 Hour Trainer
Abhinav Mishra
@abhinav-m
Jul 18 2017 16:04
@KteCz77 There is a very highly recommended book which i can't remember the name of..
Pieter Stokkink
@forkerino
Jul 18 2017 16:04

i just built minesweeper apart from that on my own.

@abhinav-thinktank Last weekend I wrote an algorithm to solve MineSweeper puzzles. https://www.codewars.com/kata/mine-sweeper/train/javascript Much fun!

taylor-rasnic
@taylor-rasnic
Jul 18 2017 16:06
Is anyone else having a hard time getting the twitter button to work on the quote generator challenge? It will bring up a post filled with the original quote but it won't update to the new quotes after the "new quote" button is pressed. Any suggestions? Here is the codepen page..https://codepen.io/Taylor-Rasnic/pen/PjvPmR
Abhinav Mishra
@abhinav-m
Jul 18 2017 16:06
@forkerino wow. That sounds super cool
Cale Riggs
@caleriggs
Jul 18 2017 16:07
Can someone tell me why this code doesn't work? I'm very confused....
var Bike = function() {

  var gear =0;

  this.setGear = function(gear) {
    gear = gear; 
  };

  this.getGear = function() {return gear;};


};

var myCar = new Car();

var myBike = new Bike();
myBike.gear = myBike.setGear(4);
myBike.getGear();
Jason Luboff
@JLuboff
Jul 18 2017 16:08
@caleriggs in your setGear, have your parameter name something different than gear
Cale Riggs
@caleriggs
Jul 18 2017 16:09
@JLuboff is that something that will fail in Javascript, or is it something that is just failing this FCC test? I know in Java/Swift you it doesn't matter if they are named the same thing.
Abhinav Mishra
@abhinav-m
Jul 18 2017 16:09
@forkerino What do you recommend, should i try to tackle both data vis and backend section simultaneously or should i approach them one by one
Bradley Sands
@sandsbe
Jul 18 2017 16:09
@taylor-rasnic I wasted a TON of time on the twitter button issue
The best approach is to do it very bland, don't use Twitter's js widget
Cale Riggs
@caleriggs
Jul 18 2017 16:10
@JLuboff that definitely worked though, thanks for the help!
CamperBot
@camperbot
Jul 18 2017 16:10
caleriggs sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2080 | @jluboff |http://www.freecodecamp.com/jluboff
Jason Luboff
@JLuboff
Jul 18 2017 16:11
@caleriggs See if @forkerino can answer that one. I don't know that I'll answer correctly lol
@forkerino :point_up: July 18, 2017 9:09 AM
Pieter Stokkink
@forkerino
Jul 18 2017 16:11
@abhinav-thinktank I started with Backend (which I still haven't finished, 2 projects left). At some point I wanted to learn React and did so. Also haven't finished the DataViz yet, but I did get hired as a developer in the meantime, so not much time at the moment. Either way is fine, do that which attracts you most.
taylor-rasnic
@taylor-rasnic
Jul 18 2017 16:11
@sandsbe Glad I'm not the only one. I finished the rest of the page in no time but this twitter button is driving me insane . haha
Abhinav Mishra
@abhinav-m
Jul 18 2017 16:12
@forkerino allright, and is a 2 months timeline too thin to complete both?
Pieter Stokkink
@forkerino
Jul 18 2017 16:12
@caleriggs @JLuboff I'm not 100% sure, but the code seems ambiguous. Which gear needs to be set to which gear?
@abhinav-thinktank I think that's a little short. Unless you already know a lot. But the projects still take quite some time to complete.
Jason Luboff
@JLuboff
Jul 18 2017 16:15
The first dynamic web app took me 2.5ish weeks?
Abhinav Mishra
@abhinav-m
Jul 18 2017 16:15
@forkerino oww, i was hoping i would be done with them , hmm i guess i'll stretch the timeline a bit more, thank you.
CamperBot
@camperbot
Jul 18 2017 16:15
abhinav-thinktank sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2864 | @forkerino |http://www.freecodecamp.com/forkerino
Abhinav Mishra
@abhinav-m
Jul 18 2017 16:15
@JLuboff oh, and react stuff?
Bradley Sands
@sandsbe
Jul 18 2017 16:15
@taylor-rasnic I addressed it this way
document.querySelector("#share").setAttribute("href","https://twitter.com/intent/tweet?text="+quoteArr[last]['quote'])
Pieter Stokkink
@forkerino
Jul 18 2017 16:15
It took me ~3 months to finish the backend api projects and the first 3 full stack projects. I wasn't working on it full time, but spend a lot of time on it. Learning how everything fit together in the backend and how to make front and backend communicate took some time to wrap my head around @abhinav-thinktank
Ogundele Olumide
@Lumexralph
Jul 18 2017 16:15
@caleriggs what I think about the code is how it was executed, gear will be read as the argument or parameter, then you assigned gear to it, more like same thing and it doesn't refer to the private variable gear only paying attention to the parameter, blocking out the gear class attribute @JLuboff @forkerino
Jason Luboff
@JLuboff
Jul 18 2017 16:16
@abhinav-thinktank I haven't done any Data Viz stuff. Only frontend (complete) and backend. The API projects for backend are pretty quick, but dynamic apps require a lot more
Pieter Stokkink
@forkerino
Jul 18 2017 16:16
@Lumexralph makes sense. The private variable might be masked by the function parameter.
@caleriggs
Ogundele Olumide
@Lumexralph
Jul 18 2017 16:16
@forkerino yeah
Bradley Sands
@sandsbe
Jul 18 2017 16:16
<div class="text-center" id="socialbuttons" style="padding:5px">
        <button class="btn btn-primary"><a href="https://twitter.com/intent/tweet?text=" target="_blank" class=" twitter-share-button" id="share" style="color:white"><span class="fa fa-twitter"></span> Tweet</a></button>
      </div>
Abhinav Mishra
@abhinav-m
Jul 18 2017 16:16
@forkerino @JLuboff Thanks for the insights, i guess i'll extend my timeline and try to set a realistic goal
CamperBot
@camperbot
Jul 18 2017 16:16
abhinav-thinktank sends brownie points to @forkerino and @jluboff :sparkles: :thumbsup: :sparkles:
:warning: abhinav-thinktank already gave forkerino points
:star2: 2081 | @jluboff |http://www.freecodecamp.com/jluboff
Ogundele Olumide
@Lumexralph
Jul 18 2017 16:17
@JLuboff it's so cool looking at the web architecture.... of most webapps
Pieter Stokkink
@forkerino
Jul 18 2017 16:17
@JLuboff the next projects will go a lot quicker, btw, I really felt when I read the user stories for the second and third full stack apps: Is that it?
Bradley Sands
@sandsbe
Jul 18 2017 16:17
So, the workaround is blank links and just add your content as a string to the end of the intent URL.
Abhinav Mishra
@abhinav-m
Jul 18 2017 16:17
Oh and, I dont NEED to learn anything in the Data vis section to do the backend section do i?
Jason Luboff
@JLuboff
Jul 18 2017 16:17
@Lumexralph My folder structure still probably needs some work... but ya :D
Bradley Sands
@sandsbe
Jul 18 2017 16:17
blank = blankd
bland
Jason Luboff
@JLuboff
Jul 18 2017 16:18
@forkerino Ya, I don't feel like the nightlife app will take that long. I just need to get the Yelp API working but I can recycle a lot of my code
Pieter Stokkink
@forkerino
Jul 18 2017 16:18
@abhinav-thinktank no, it's not completely necessary. It will be easier to build something dynamic fast if you know React (or another framework) though.
Abhinav Mishra
@abhinav-m
Jul 18 2017 16:19
@forkerino oh ok, i guess i'll do the first section of the backend first, then for the big projects ill try to finish react and data vis , then approach them
taylor-rasnic
@taylor-rasnic
Jul 18 2017 16:19
thanks @sandsbe ! I'll try that out!
CamperBot
@camperbot
Jul 18 2017 16:19
taylor-rasnic sends brownie points to @sandsbe :sparkles: :thumbsup: :sparkles:
:cookie: 309 | @sandsbe |http://www.freecodecamp.com/sandsbe
Alex
@alexandrupintilei
Jul 18 2017 16:19
https://codepen.io/balexoy/pen/zzQymP?editors=1010
Why if/else statment dosent work and also link?
Abhinav Mishra
@abhinav-m
Jul 18 2017 16:20
allright thanks for all the info , im gonna get some sleep now and start fresh tomorrow :D
Ogundele Olumide
@Lumexralph
Jul 18 2017 16:20
@JLuboff @forkerino I think I'll pick up my React from where I left it when I'm done absorbing the functional programming paradigm
Bradley Sands
@sandsbe
Jul 18 2017 16:20
Question I posed to Twitter help, still not answered: https://twittercommunity.com/t/accounting-for-dom-changes-in-js-widget/90578
Ogundele Olumide
@Lumexralph
Jul 18 2017 16:20
for now, NodeJS has my mind
Pieter Stokkink
@forkerino
Jul 18 2017 16:21
@Lumexralph React <3 FP
Jason Luboff
@JLuboff
Jul 18 2017 16:21
@Lumexralph I may actually start looking at react..
Pieter Stokkink
@forkerino
Jul 18 2017 16:21
@Lumexralph btw, I wrote my first CodeWars Kata last night. https://www.codewars.com/kata/596d2447c4a959794d000007
Not too hard if you take the functional approach.
;)
Ogundele Olumide
@Lumexralph
Jul 18 2017 16:22
@forkerino already loving the benefits of FP..... Pure Function is actually good concept, makes my head think about my codes that way
@forkerino nah...... no CW for me now, I'm at peace
Pieter Stokkink
@forkerino
Jul 18 2017 16:22
hahaha
Ogundele Olumide
@Lumexralph
Jul 18 2017 16:23
@forkerino i'll go to war when my artillery is upgraded and my Arsenal is deadly
@forkerino learning from Russia's loss from WW2
Pieter Stokkink
@forkerino
Jul 18 2017 16:23
@Lumexralph A great book on FP in JS is JavaScript Allonge - the 6 edition. https://leanpub.com/javascriptallongesix/read
Jason Luboff
@JLuboff
Jul 18 2017 16:23
@forkerino How difficult is react to understand and integrate with node?
Ogundele Olumide
@Lumexralph
Jul 18 2017 16:24
@JLuboff should it be difficult?
Jason Luboff
@JLuboff
Jul 18 2017 16:24
@Lumexralph I don't know? I've never used it
Pieter Stokkink
@forkerino
Jul 18 2017 16:24
@JLuboff Not difficult. I haven't integrated both yet, as I only did pure React projects, but React is good at just keeping itself in the frontend.
Ogundele Olumide
@Lumexralph
Jul 18 2017 16:24
@JLuboff what I think is node is on server side, react is on client side, just like VanillaJS it shouldn' be that crazy I think
Jason Luboff
@JLuboff
Jul 18 2017 16:25
@Lumexralph Ya but it's getting everything server side to be talking with everything client side that can be difficult
@forkerino Got it.
Pieter Stokkink
@forkerino
Jul 18 2017 16:25
@JLuboff I found it easier to consume an API with React than with Vanilla JS
maybe it's just experience.
but still
Ogundele Olumide
@Lumexralph
Jul 18 2017 16:26
@JLuboff in the few times I spent with it, the writing JS, DOM and Design on a single page is cool for reading :smile:
Jason Luboff
@JLuboff
Jul 18 2017 16:26
One of the problems I had with my voting app is that its not truly "dynamic"... You vote, it technically redirects you to the same page instead of having that page update without a redirect
@forkerino @Lumexralph Thanks
CamperBot
@camperbot
Jul 18 2017 16:27
jluboff sends brownie points to @forkerino and @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 2865 | @forkerino |http://www.freecodecamp.com/forkerino
:star2: 2036 | @lumexralph |http://www.freecodecamp.com/lumexralph
Alex
@alexandrupintilei
Jul 18 2017 16:27
so,none can help me? :(
wenchaoWu
@wenchaoWu
Jul 18 2017 16:27
这里可以说中文吗?
Ogundele Olumide
@Lumexralph
Jul 18 2017 16:27
@JLuboff i'm thinking AJAX ? or something related ? I've not done it and you have experience with it than I can think
Michiel
@MichielHuijse
Jul 18 2017 16:28
Hi I am stuck with the Diff two arrays assignment. I can filter all the double values from the short array out of the long array. But can't save the onused values of the shorter array into a new array. My code looks like this now. Some tips highly appreciated.
 function diffArray(arr1, arr2) {
     3
     4
     var newArr = [];
     5
     var shortArrLength, longArrLength, longestArr, shortestArr;
     6
     7 arrLength();
     8 FilterArr();
     9
     10
     11
     function arrLength() {
         12
         if (arr1.length >= arr2.length) {
             13 longestArr = arr1;
             14 shortestArr = arr2;
             15
         } else {
             16 longestArr = arr2;
             17 shortestArr = arr1;
             18
         }
         19
         20
         21 shortArrLength = shortestArr.length;
         22 longArrLength = shortestArr.length;
         23
     }
     24
     25
     function FilterArr() {