These are chat archives for FreeCodeCamp/HelpJavaScript

19th
Jul 2017
monkeyfingerz
@monkeyfingerz
Jul 19 2017 00:00
right on. It's awesome you get to work on code while you work
Jason Luboff
@JLuboff
Jul 19 2017 00:01
I think so :D and now I'm off so heading home, see ya!
monkeyfingerz
@monkeyfingerz
Jul 19 2017 00:01
bye
BrandonTeso
@BrandonTeso
Jul 19 2017 00:02
hello
cowCrazy
@cowCrazy
Jul 19 2017 00:03
hi
Guderian Raborg
@hypercuber
Jul 19 2017 00:28
Can someone find a way to make my code faster
https://projecteuler.net/problem=14
can get help here:
http://www.mathblog.dk/project-euler-14/
Number.prototype.nextCollatz = function() {
  return this % 2 === 0 ? this / 2 : 3 * this + 1;
}
function chainLength(n) { //n is starting num
  let length = 1;
  while (n !== 1) {
    n = n.nextCollatz();
    length++;
  }
  return length;
}
function largestCollatzUnder(n) {
  let num = 1; //num with longest chain
  for (let i = 1; i < n; i++) { //chainLength(1) = 1
    if (chainLength(num) < chainLength(i)) {
      num = i;
    }
  }
  return num;
}
// console.log(largestCollatzUnder(1000000));
Stephen James
@sjames1958gm
Jul 19 2017 00:32
@hypercuber Save off the longest chain, rather than compute it each time.
Colin McAtee
@colinmac17
Jul 19 2017 00:42
Hello can someone work with me on this repl.it? https://repl.it/J759/33 ---- I am having trouble finish the problem. I am supposed to return an object that calculates the simple moving average of the input object with a specified lookback.
var hashInput = {
    '2016-01': 235,
    '2016-02': 250,
    '2016-03': 275,
    '2016-04': 350,
    '2016-05': 450,
    '2016-06': 460,
    '2016-07': 525,
    '2016-08': 675,
    '2016-09': 700,
    '2016-10': 950,
    '2016-11': 1075,
    '2016-12': 1300
};

//set global vars
//create newHash Object to be returned
var newHash = {};
var hashKeys;
var keys;
var movingAvg;
var keyIndex;
var hashValues = [];
var avgArr = [];

function calculateMovingAvg (hash, lookback) {
     //create an array with input hash keys
    hashKeys = Object.keys(hash);
    var maxLookback = hashKeys.length - 1;

    //get an array of hash values for later use
    for (var i = 0; i < hashKeys.length; i++) {
      hashValues.push(hash[hashKeys[i]]);
    }

    console.log(hashValues);

    //make sure lookback is valid
    if (lookback < 1) {
      return 'lookback must be >=1';
    } else if (lookback > maxLookback) {
      return 'lookback must be at least as small as the length of the hash - 1';
    } else {

    var newValues = hashValues.map(function(key) {
        //get the index of each key in hashKeys array
        keyIndex = hashValues.indexOf(key);
        console.log(keyIndex);

      var total = 0;
      if (keyIndex >= lookback) {
        for (var i = 0; i < lookback; i++ ) {
          total += hashValues[i];
          movingAvg = total / lookback;
        }

        key = movingAvg;

        return key;
      } else {
        return key;
      }
    });


    for (var i = 0; i < hashKeys.length; i++) {
        var key = hashKeys[i];
        newHash[key] = newValues[i];
    }

    return newHash;
    }
}

calculateMovingAvg(hashInput, 3);
Guderian Raborg
@hypercuber
Jul 19 2017 00:46
@sjames1958gm thanks
CamperBot
@camperbot
Jul 19 2017 00:46
hypercuber sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8104 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Colin McAtee
@colinmac17
Jul 19 2017 00:47
I am currently getting back the correct input for the 4th key, but it is also being push as the value for the 5-12th keys as well
Stephen James
@sjames1958gm
Jul 19 2017 00:49
@hypercuber you're welcome, hope that helps
@colinmac17 you for loop in the map should be total += hashValue[i + keyIndex] then the average should be after the loop?
Colin McAtee
@colinmac17
Jul 19 2017 00:57

@sjames1958gm yes the moving average being outside works as well. I do like the idea of your suggesstion. I know I am so close! I just am missing one little piece of logic.

Can you check my repl.it now and see if you can see anything my fried eyes cannot? https://repl.it/J759/36

as I just added in your updates
Stephen James
@sjames1958gm
Jul 19 2017 00:58
@colinmac17 You changed your for loop and your indexing.
twopointtwo
@twopointtwo
Jul 19 2017 01:00
@sjames1958gm Need some help !
I tweaked my js
Colin McAtee
@colinmac17
Jul 19 2017 01:00
@sjames1958gm I need to set the parameters of the for loop to something for dynamic. I'v been messing with it.
```
Stephen James
@sjames1958gm
Jul 19 2017 01:00
        for (var i = keyIndex - lookback; i <= keyIndex; i++ ) {
          total += hashValues[i
];
        }
@colinmac17 You need to adjust i in the for loop or i in the [] not both
twopointtwo
@twopointtwo
Jul 19 2017 01:01
how do you cut and paste code into the chat forum? I know they taught this in the introduction
Guderian Raborg
@hypercuber
Jul 19 2017 01:02

@sjames1958gm Like this?

function largestCollatzUnder(n) {
  let num = 1; //num with longest chain
  let length = 1 //chainLength(1) = 1
  for (let i = 1; i < n; i++) {
    if (length < chainLength(i)) {
      num = i;
      length = chainLength(i);
    }
  }
  return num;
}

I still need to find another method because it keep freezing

Colin McAtee
@colinmac17
Jul 19 2017 01:02
@sjames1958gm
var total = 0;
      if (keyIndex >= lookback) {
        for (var i = lookback - keyIndex; i <= keyIndex; i++ ) {
          total += hashValues[i+keyIndex];
        }

        movingAvg = total / lookback;
        key = movingAvg;
Stephen James
@sjames1958gm
Jul 19 2017 01:02
@colinmac17 If you have i go from keyIndex - lookback to keyIndex, then you don't need to add to i on the next line
It has to be keyIndex - lookback
@hypercuber Kind of, don't calculate chainLenth(i) twice either
twopointtwo
@twopointtwo
Jul 19 2017 01:03
Lol
Here it is:
Guderian Raborg
@hypercuber
Jul 19 2017 01:04
@sjames1958gm how?
twopointtwo
@twopointtwo
Jul 19 2017 01:04
shift+enter?
Colin McAtee
@colinmac17
Jul 19 2017 01:04
@sjames1958gm Thank you for clarifying but can you please send a snippet? I'm not sure Im 100% following. Thanks!
CamperBot
@camperbot
Jul 19 2017 01:04
colinmac17 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8105 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 19 2017 01:04
@hypercuber
var testLength = chainLength(i)
if (testLength > length)
@twopointtwo Use console.log to see if searchQuery has the value you want. Also for wikipedia if you add origin=* you don't have to do crossorigin.me proexy
twopointtwo
@twopointtwo
Jul 19 2017 01:06
This is all new to me
Stephen James
@sjames1958gm
Jul 19 2017 01:06
@twopointtwo shift-enter gives you a new line without posting, so
three ``` shift-enter, paste, shift-enter, three ```
twopointtwo
@twopointtwo
Jul 19 2017 01:06
First step, how can I use console.log
Stephen James
@sjames1958gm
Jul 19 2017 01:07
@colinmac17
        for (var i = keyIndex - lookback; i <= keyIndex; i++ ) {
          total += hashValues[i];
        }
Ryan Williams
@Ryanwfile
Jul 19 2017 01:07

How do I sort an array of objects by a property value that's an integer? For example I have

var array = [
    {
        alive : false,
        id : 99
    },
    {
        alive : false,
        id : 16
    }
    {
        alive : false,
        id : 64
    }
]

I have tried

array.sort(function(a, b) {
        return parseFloat(a.id) - parseFloat(b.id);
      }); 
//and also
 array.sort(function(a, b) {
        return a.id - b.id;
    });

Neither of these functions work, any help is greatly appreciated.

Stephen James
@sjames1958gm
Jul 19 2017 01:07
@twopointtwo console.log(searchQuery);
codepen has a console for basic stuff like this
twopointtwo
@twopointtwo
Jul 19 2017 01:07
var searchQuery = $("#searchQuery").val();
var url = "https://crossorigin.me/https://en.wikipedia.org/w/api.php?action=opensearch&gsrnamespace=0&gsrlimit=10&format=json&search=" + searchQuery;
Got it
Thanks
Ok
Stephen James
@sjames1958gm
Jul 19 2017 01:08
@Ryanwfile The second should work, it will sort from smallest id to largest
Ryan Williams
@Ryanwfile
Jul 19 2017 01:08
@sjames1958gm Yea I thought so too, tried it many times and it doesn't work.
Stephen James
@sjames1958gm
Jul 19 2017 01:10
@Ryanwfile There is a typo in your array?
Moisés Man
@moigithub
Jul 19 2017 01:10
,
Ryan Williams
@Ryanwfile
Jul 19 2017 01:10
@sjames1958gm Yea I see the missing comma here, it's not like that on codepen. Thanks for looking, I can link the codepen if it helps
CamperBot
@camperbot
Jul 19 2017 01:10
ryanwfile sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8106 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 19 2017 01:11
@twopointtwo There are some videos later in the MAP that show how to use chrome devtools, if you use chrome, I would suggest going through those, before going much further, it will help considerably
@Ryanwfile sure
Colin McAtee
@colinmac17
Jul 19 2017 01:11

@sjames1958gm Once I figured out that the condition needs to be

i < keyIndex;

it works :)

Stephen James
@sjames1958gm
Jul 19 2017 01:12
@colinmac17 Cool - FYI, the second parameter to the map callback is the array index of the current value
Ryan Williams
@Ryanwfile
Jul 19 2017 01:12
@sjames1958gm https://codepen.io/Ryanwfile/pen/pwXJyP I capslocked commented the sort function that doesn't work
Anthony Contreras
@AmazeCPK
Jul 19 2017 01:14
does anyone here use pretier for vscode?
Stephen James
@sjames1958gm
Jul 19 2017 01:16
@Ryanwfile array is a 2D array, you need to sort each value array[i] ?
Ryan Williams
@Ryanwfile
Jul 19 2017 01:16
@sjames1958gm ahh, that makes sense, I will try that, thank you
CamperBot
@camperbot
Jul 19 2017 01:16
ryanwfile sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: ryanwfile already gave sjames1958gm points
Stephen James
@sjames1958gm
Jul 19 2017 01:17
@Ryanwfile :+1:
Kristi Nushi
@Kristi92
Jul 19 2017 01:17
@camperbot can u help me pls with an issue that i have
?
Ryan Williams
@Ryanwfile
Jul 19 2017 01:18
@sjames1958gm It's much closer, I'm still having an issue of getting the false cells and true cells in order from 1 - 100
Kristi Nushi
@Kristi92
Jul 19 2017 01:19

i don't know where my problem is in this case: var Bike = function() {

// Only change code below this line.

var gear= 0;

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

var myCar = new Car();

var myBike = new Bike();

myBike.setGear(4);
};

is there anyone who can help me ?
kumquatfelafel
@kumquatfelafel
Jul 19 2017 01:25

@Kristi92 For future: if you write it in a code block, it makes it easier to read and allows you to do some formatting. To write it in a code block, use back ticks ` like so...
for one line :point_right: ` code goes here `
or for multiple lines :point_down:
```js
code goes here (important: on a separate line. to do this, ctrl + enter or shift + enter)
```

Also, note that `≠ '
You can also edit your post if you make a mistake by clicking the … that appears when you hover your mouse over your comment

王想想
@wxxxxxxxx
Jul 19 2017 01:30

function convert(celsius) {
// 请把你的代码写在这条注释以下
var fahrenheit=convert;
console.log(fahrenheit);

// 请把你的代码写在这条注释以上
return fahrenheit;
}

convert(30); // 你可以修改这一行来测试你的代码

help
Stephen James
@sjames1958gm
Jul 19 2017 01:32
@Ryanwfile Seems it woiuld be easier to have a 1D array to store the state and then make it 2D when rendering.
@wxxxxxxxx Use celsius not convert inside the funciton - then use F = C * 9/5 + 32 formula
kumquatfelafel
@kumquatfelafel
Jul 19 2017 01:33
@wxxxxxxxx
convert(30);... the value 30 is being passed into celsius in the function convert.
From here, you have to convert celsius to fahrenheit using the appropriate formula and variables.
王想想
@wxxxxxxxx
Jul 19 2017 01:33
thank you
Ryan Williams
@Ryanwfile
Jul 19 2017 01:33
@sjames1958gm Yes, that's definitely true, I will probably go back and change it
王想想
@wxxxxxxxx
Jul 19 2017 01:33
understood
Stephen James
@sjames1958gm
Jul 19 2017 01:34
@Ryanwfile I think your indexOf check for duplicates only checks the current row
Ryan Williams
@Ryanwfile
Jul 19 2017 01:36
@sjames1958gm It might, a single duplicate breaks the mapping in the render function and it hasn't happened yet. The 1d array idea would make the calculating cell neighbors function much simpler when I get to it
王想想
@wxxxxxxxx
Jul 19 2017 01:37
no, I still can not write
kumquatfelafel
@kumquatfelafel
Jul 19 2017 01:38
@Kristi92 Check your brackets. It looks like you may be missing one.
@wxxxxxxxx post code
王想想
@wxxxxxxxx
Jul 19 2017 01:40
@kumquatfelafel what
kumquatfelafel
@kumquatfelafel
Jul 19 2017 01:41
If you are having trouble, post your code so we have a better idea of what is going wrong.
王想想
@wxxxxxxxx
Jul 19 2017 01:41
I will not write, do not know how to write degrees Fahrenheit degrees
Stephen James
@sjames1958gm
Jul 19 2017 01:44
@Ryanwfile Yes, separation logic from presentation.
@wxxxxxxxx F = C * 9/5 + 32 is the formula - you replace the F with fahrenheit and C with celsius
Ryan Williams
@Ryanwfile
Jul 19 2017 01:45
@sjames1958gm Yes, I'm starting to learn that, I just didn't know where to start with the project and this 2d array was the first grid that was working. Thanks again for all the help
CamperBot
@camperbot
Jul 19 2017 01:45
ryanwfile sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: ryanwfile already gave sjames1958gm points
Stephen James
@sjames1958gm
Jul 19 2017 01:45
@Ryanwfile :+1:
王想想
@wxxxxxxxx
Jul 19 2017 01:47
var fahrenheit;
var c=30;
fahrenheit = c*9/5+32;
so that I know wrong...
kumquatfelafel
@kumquatfelafel
Jul 19 2017 01:52

Say I want to write a function that is supposed to convert kilometers into meters...

I can do something like this.

function kiloToMeters(kilometers) {
    var meters = kilometers * 1000;
    return meters;
}

This function is a reusable piece of code that can be called whenever one wants to convert a value from kilometers to meters. In order to do this conversion, we first call the function, like so...

console.log(kiloToMeters(5));// this will print 5000 in console

With kiloToMeters(5) we are saying "we want to convert 5 km to m". From there, we move onto the function code, where kilometers has been assigned our specified value of 5.

Because kilometers is 5, it multiplies 5 * 1000, and stores that result into meters, which it then returns.

Finally, this result is printed in the console.

@wxxxxxxxx hopefully you can see what is going on here, even if you can't understand quite everything I'm saying (you're not missing much :p )
王想想
@wxxxxxxxx
Jul 19 2017 01:55
@kumquatfelafel I know how to fix it
王想想
@wxxxxxxxx
Jul 19 2017 02:03
😊
aRtoo
@artoodeeto
Jul 19 2017 02:06
hi guys. i hae this animated elements. i want the input element to fadein after onLoad then it will slide to the right 200px. but the slide to the right isnt working. any idea? heres my code:
$('input').addClass('animated fadeIn', function() {
    $('input').animate({
        right: 2000
     })
  });
Joseph
@revisualize
Jul 19 2017 02:10

@wxxxxxxxx
There is the function declaration of function convertToF(celsius) { .. You have a function name of convertToF and a parameter of celsius
Parameters are used just like variables. So, inside of the function you can use celsius JUST like any other variable.
If I have this code:

function addThree (num) {
}

So, when we make the function call of:

addThree(10);

You're calling the function addThree You're also passing a value 10 as an argument.
In the function declaration of function addThree (num) { You see that there is a parameter defined of num
When we do addThree(10) then the value of the parameter num is passed the argument value of ... 10
...
If you then make another function call..

addThree(39);

You can use the same function to follow the operation:
When we do addThree(39) then the value of the parameter num is passed the argument value of ... 39

If you make the function call of addThree(21) the value of num inside the function is 21.
If you make the function call of addThree(1000) the value of num inside the function is 1000.
If you make the function call of addThree(123456) the value of num inside the function is 123456.
function declaration of function convertToF(celsius) { } making the function call convertToF(55) the parameter celsius inside of the function has a value of 55
function declaration of function convertToF(celsius) { } making the function call convertToF(23) the parameter celsius inside of the function has a value of 23

The algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32

kumquatfelafel
@kumquatfelafel
Jul 19 2017 02:11
@artoodeeto Is right: 2000 correct? I... genuinely don't know, but it seems a bit weird to me :p
aRtoo
@artoodeeto
Jul 19 2017 02:11
@kumquatfelafel tried 200 doesnt work too.
korzo
@korzo
Jul 19 2017 02:15
@artoodeeto What is position style property of input?
kumquatfelafel
@kumquatfelafel
Jul 19 2017 02:15
@artoodeeto try "-=200px"?
Saikat-Sinha
@Saikat-Sinha
Jul 19 2017 02:15

Guys need help........
What is wrong with this AJAX request

function geoCode(address, geoCodeFor) {
    $.ajax({
        url: "https://maps.googleapis.com/maps/api/geocode/json?address="+address+"&key=" + API_key,
        success: function (response) {
            var formattedAddress =  response.results[0].formatted_address;     //Formatted Address to the Input
            var lati = response.results[0].geometry.location.lat;               //Latitude of the input address
            var lngi = response.results[0].geometry.location.lng;               //Longitude of the input address
            var newGeoObj = {
                location: formattedAddress,
                stopover: true
            };
            if(geoCodeFor === "startInput"){
                startGeoCodeArr.lat = lati;
                startGeoCodeArr.lng = lngi;
                startGeoCodeArr.location = formattedAddress;
            }
            if(geoCodeFor === "destInput"){
                destGeoCodeArr.lat = lati;
                destGeoCodeArr.lng = lngi;
                destGeoCodeArr.location = formattedAddress;
            }
            if(geoCodeFor === "wayInput"){
                waysGeoCodeArr.push(newGeoObj);
                addWayPointsToHTML();
            }
        }
    });

It is generating output on second click

Joseph
@revisualize
Jul 19 2017 02:17
@Saikat-Sinha Do you have this on a webpage somewhere?
Saikat-Sinha
@Saikat-Sinha
Jul 19 2017 02:17
@revisualize wait a moment i will push it to Pages
aRtoo
@artoodeeto
Jul 19 2017 02:17

@korzo @kumquatfelafel the position of the style is abosulote.

but i think its the code is wrong be i tried this.

$('input').addClass('animated fadeIn', function() {
    /*$('input').animate({
        bottom: 200
     })*/
     console.log('success');
  });

it should console success after the fade in but it didnt. the code is wrong

CamperBot
@camperbot
Jul 19 2017 02:18

freeCodeCamp rooms:

:point_right: Here is a list of our official chat rooms
王想想
@wxxxxxxxx
Jul 19 2017 02:19
var myStr = "I am a, \"double quoted\" string inside \"double quotes\"";
Is that wrong?
Joseph
@revisualize
Jul 19 2017 02:20
@wxxxxxxxx You're missing a .
王想想
@wxxxxxxxx
Jul 19 2017 02:20
@revisualize what
Joseph
@revisualize
Jul 19 2017 02:20
@wxxxxxxxx Your string needs to be EXACT
@wxxxxxxxx \""; missing a .
王想想
@wxxxxxxxx
Jul 19 2017 02:20
console.log()
Joseph
@revisualize
Jul 19 2017 02:21
@wxxxxxxxx a, \" is that , supposed to be there?
王想想
@wxxxxxxxx
Jul 19 2017 02:21
I am a, "double quoted" string inside "double quotes"
Joseph
@revisualize
Jul 19 2017 02:21
I am a "double quoted" string inside "double quotes".
王想想
@wxxxxxxxx
Jul 19 2017 02:21
ok
korzo
@korzo
Jul 19 2017 02:21
@artoodeeto I'm not sure if you can use both parameters in addClass at the same time
Joseph
@revisualize
Jul 19 2017 02:22
@wxxxxxxxx no , and add a .
王想想
@wxxxxxxxx
Jul 19 2017 02:22
...
korzo
@korzo
Jul 19 2017 02:22
@artoodeeto You can't . If you remove first argument, function run
王想想
@wxxxxxxxx
Jul 19 2017 02:22
ok
twopointtwo
@twopointtwo
Jul 19 2017 02:22
Need some help.
with a codepen
Joseph
@revisualize
Jul 19 2017 02:22
@twopointtwo With?
Javascript question
I cant get this to run, I borrowed the code from another codepen
and moved somethings around and renamed a few things
but it was all done in sequence
王想想
@wxxxxxxxx
Jul 19 2017 02:24
"(I am a, \"double quoted\" string inside \"double quotes\").";
How to do
Joseph
@revisualize
Jul 19 2017 02:24
@wxxxxxxxx Why do you have ) now?
@wxxxxxxxx Why do you have a , still?
@wxxxxxxxx Why do you have ( ?
@wxxxxxxxx Remove the ( , )
@wxxxxxxxx There is no ( or , or ) in this:
I am a "double quoted" string inside "double quotes".
王想想
@wxxxxxxxx
Jul 19 2017 02:27
what do you mean
Saikat-Sinha
@Saikat-Sinha
Jul 19 2017 02:27
@revisualize here is code https://github.com/Saikat-Sinha/Maps_Route .........It is taking some time for Github pages to update
王想想
@wxxxxxxxx
Jul 19 2017 02:27
Can not understand
Joseph
@revisualize
Jul 19 2017 02:28
@wxxxxxxxx Is there a ( in this text?
I am a "double quoted" string inside "double quotes".
@wxxxxxxxx No there is not.
@wxxxxxxxx Is there a , in this text:
I am a "double quoted" string inside "double quotes".
@wxxxxxxxx No there is not.
@wxxxxxxxx Is there a ) in this text:
I am a "double quoted" string inside "double quotes".
@wxxxxxxxx No there is not.
@wxxxxxxxx Do not add extra un-needed characters to the string.
王想想
@wxxxxxxxx
Jul 19 2017 02:30
I am a "double quoted" string inside "double quotes" task
I'm looking down
Joseph
@revisualize
Jul 19 2017 02:31
@wxxxxxxxx I know what task you're on.
@wxxxxxxxx Escaping Literal Quotes in Strings
image.png
王想想
@wxxxxxxxx
Jul 19 2017 02:34
var myStr = "I am a, \"double quoted\" string inside \"double quotes\"";
Why not ah
sos
Joseph
@revisualize
Jul 19 2017 02:36
@wxxxxxxxx \""; <--- NO .
@wxxxxxxxx I am a "double quoted" string inside "double quotes".
There is a . at the end.
@wxxxxxxxx a, \"double .. You have a ,
There shouldn't be a , anywhere in the string.
Remove ,
Add .
王想想
@wxxxxxxxx
Jul 19 2017 02:38
Yes, touched China ...
thank you
Joseph
@revisualize
Jul 19 2017 02:38
image.png
@wxxxxxxxx Strings in FreeCodeCamp for the JavaScript lessons need to be EXACT
王想想
@wxxxxxxxx
Jul 19 2017 02:38
Successful
kumquatfelafel
@kumquatfelafel
Jul 19 2017 02:38
Strings have to be written exactly the same. For example, "Hello world""Hello, world"
王想想
@wxxxxxxxx
Jul 19 2017 02:39
The string looked too messy
kumquatfelafel
@kumquatfelafel
Jul 19 2017 02:40
One of the upcoming lessons gives you a trick you can use to (sometimes) make a string look a little less messy.
Saikat-Sinha
@Saikat-Sinha
Jul 19 2017 02:45
@revisualize bro there? link to the page http://juniordev.me/Maps_Route/
Joseph
@revisualize
Jul 19 2017 02:48
@Saikat-Sinha Do you know that you have 404 errors?
Saikat-Sinha
@Saikat-Sinha
Jul 19 2017 02:49
@revisualize yeah bcoz of node_modules..........but the issue is on second submit it generates map
Joseph
@revisualize
Jul 19 2017 02:49
@Saikat-Sinha I can't really help you beyond that.
kumquatfelafel
@kumquatfelafel
Jul 19 2017 02:49
@twopointtwo Could you explain to me what is happening in that for loop?
Saikat-Sinha
@Saikat-Sinha
Jul 19 2017 02:49
@revisualize thanks for trying
CamperBot
@camperbot
Jul 19 2017 02:49
saikat-sinha sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4358 | @revisualize |http://www.freecodecamp.com/revisualize
Kshitijaa Jaglan
@KshitijaaJaglan
Jul 19 2017 02:56
Can someone tell me why isn't the value of i incrementing here?
algorithm challenge- find the longest word in a string

function findLongestWord(str) {
  var strnew=str.split(" ");
  for(i=0; i<strnew.length; i++){
    return strnew[i];
  }
}

findLongestWord("The quick brown fox jumped over the lazy dog");
kumquatfelafel
@kumquatfelafel
Jul 19 2017 02:56
@KshitijaaJaglan return halts function entirely and returns specified value.
Joseph
@revisualize
Jul 19 2017 02:57
https://www.packtpub.com/packt/offers/free-learning
Book of the day:
Git: Version Control for Everyone
Kshitijaa Jaglan
@KshitijaaJaglan
Jul 19 2017 02:57
so what should i replace it with?? @kumquatfelafel
Joseph
@revisualize
Jul 19 2017 02:57
@KshitijaaJaglan You need a comparison
and a storage variable.
kumquatfelafel
@kumquatfelafel
Jul 19 2017 02:57
:point_up:
You will want a return statement eventually, just not in the middle of trying to find the longest word.
Joseph
@revisualize
Jul 19 2017 03:00
@TraekWells Do you have it on a webpage somewhere?
Traek Wells
@TraekWells
Jul 19 2017 03:01
var newQuote = document.getElementById("newQuote");
var result = document.getElementById("result");
var url = "http://api.forismatic.com/api/1.0/";

function newQuoteRequest() {
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
        if(xhr.readyState == XMLHttpRequest.DONE) {
            console.log(responseText);
        } else {
            console.log("There was an error of some sort. Figure it out homie.");
        }
    };
    xhr.open("GET", url, false);
    xhr.send();
}

newQuote.addEventListener("click", newQuote);
updated again. Sorry y’all.
@revisualize I just have it local right now. I could put it on CodePen though if it helps.
Joseph
@revisualize
Jul 19 2017 03:01
@TraekWells Why can't you delete your previous posts?
kumquatfelafel
@kumquatfelafel
Jul 19 2017 03:01
@TraekWells for future, you can edit your posts by clicking the ... that appears in top right when you hover your mouse over your comments
Traek Wells
@TraekWells
Jul 19 2017 03:02
@kumquatfelafel thanks, I had no diea
CamperBot
@camperbot
Jul 19 2017 03:02
:cookie: 493 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
traekwells sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
kumquatfelafel
@kumquatfelafel
Jul 19 2017 03:03
newQuote.addEventListener("click", newQuote);??
twopointtwo
@twopointtwo
Jul 19 2017 03:05

```//declare variables
var searchQuery;
var url;

//allows "enter/return" key to click search
$("#input").keyup(function(event) {
if (event.keyCode == 13) {
$("#search").click();
}
});

//search button
$("#search").on("click", function() {
$("#results").empty();
submit();
});

//function that runs when form is submitted
function submit() {
searchQuery = $("input").val();
url = 'https://en.wikipedia.org/w/api.php?action=query&format=json&list=search&titles=&utf8=1&srsearch=' + searchQuery + '&srlimit=15';
$.ajax({
url: url,
dataType: "jsonp", //indicates that its a jsonp request.
success: function(response) {
for (var i = 0; i < 15; i++) {
$("#results").append("<div class='box'></div>");
$(".box:last-child").addClass("animated fadeIn");
$(".box:last-child").append('<a class="title" target="_blank" href="https://en.wikipedia.org/wiki/' + response.query.search[i].title + '">' + response.query.search[i].title + '</a>');
$(".box:last-child").append('<p id="demo">' + response.query.search[i].snippet + '</p>');
}

    }

});

}```

that didnt work
...
kumquatfelafel
@kumquatfelafel
Jul 19 2017 03:06
@twopointtwo code has to be on separate line from ```
twopointtwo
@twopointtwo
Jul 19 2017 03:06
Ok got it thanks
Have a few questions,
with a codepen Im working on
kumquatfelafel
@kumquatfelafel
Jul 19 2017 03:07
@TraekWells wasn't the second argument of addEventListener supposed to be a function?
twopointtwo
@twopointtwo
Jul 19 2017 03:07
this code seems to makes sense to me
王想想
@wxxxxxxxx
Jul 19 2017 03:08
var myStr = '\ \t \b \r \n';
var myStr = '"\" "\t" "\b" "\r" "\n"';
twopointtwo
@twopointtwo
Jul 19 2017 03:11
What is the best way to learn this. I am learning by adding snippets of code
王想想
@wxxxxxxxx
Jul 19 2017 03:11
Is this output wrong?
kumquatfelafel
@kumquatfelafel
Jul 19 2017 03:12
@wxxxxxxxx what challenge?
王想想
@wxxxxxxxx
Jul 19 2017 03:12
Escape Sequences in Strings
console.log()→ "\" "\t" "\b" "\r" "\n"
Joseph
@revisualize
Jul 19 2017 03:13
@wxxxxxxxx You need to read the instructions.
@wxxxxxxxx That is NOT the proper text
Traek Wells
@TraekWells
Jul 19 2017 04:06
@kumquatfelafel I thought since I already declared newQuoteButton as a function, it would call it
surferpilgrim
@surferpilgrim
Jul 19 2017 04:35
I'm trying to use the forEach method so that the function will evaluate each element of an array. I think the rest of my code works except the forEach method and calling the function parts
function fib(num){
    var arr =[1,num];
    var max = arr.reduce(function(a,b){ return Math.max(a,b);});
    var min = arr.reduce(function(a,b){return Math.min(a,b);});
    var rangeArr = Array.apply(null,Array((max-min)+1)).map(function(discard,n){return n+min;});

    function fibArr(a){
      array.forEach(function(item){
  if(item===0){
    return 0;
  }
  if(item===1){
    return 1;
  }
  return fib(item-2)+fib(item-1);
});
      return fibArr(rangeArr);
    }

  }


fib(8);
kumquatfelafel
@kumquatfelafel
Jul 19 2017 04:41
@TraekWells I'm seeing a newQuoteRequest function, but that's about it. If you don't specify that as the function, I dunno why it would call it.
Guderian Raborg
@hypercuber
Jul 19 2017 04:59
@surferpilgrim Tell me an example of numbers in array and what you want to do with forEach
need help
let say i have let arr = [ 1, 2, 3, 4 ]
I want to make a 2d array with all cominations without each element repeating
like [1,2],[1,3],[1,4][2,3],etc
Also in the combination array I want 3 elements and 4 elements in the sub arrays
kumquatfelafel
@kumquatfelafel
Jul 19 2017 05:02
@surferpilgrim what is "array" in your code?
Guderian Raborg
@hypercuber
Jul 19 2017 05:03
@surferpilgrim The code looks interesting btw but I dont fully follow.
@surferpilgrim to get the max value in an array you can do this btw:
let arr = [1,5,6,7,4];
let max = Math.max(...arr);
console.log(max); //7
surferpilgrim
@surferpilgrim
Jul 19 2017 05:15
@hypercuber what's the difference between let and var?
Brad
@bradtaniguchi
Jul 19 2017 05:17
@surferpilgrim the main difference is let is new in ES6
surferpilgrim
@surferpilgrim
Jul 19 2017 05:17
@bradtaniguchi so it works the same as var?
Brad
@bradtaniguchi
Jul 19 2017 05:17
mainly its for local scope variables, as the classic var declaration has some odd quarks
surferpilgrim
@surferpilgrim
Jul 19 2017 05:18
@bradtaniguchi so you'd use let for local scope and for global scope you'd use let?, I'm trying to ease into es6
Brad
@bradtaniguchi
Jul 19 2017 05:18
but yes, you can think of it as like var, es6 also specifies the 'const' declaration for variables that wont be changed later. So you would use both
Guderian Raborg
@hypercuber
Jul 19 2017 05:18
@surferpilgrim if I do for (var i = 0...) then I can use "i" outside the forloop but not with let
kumquatfelafel
@kumquatfelafel
Jul 19 2017 05:19
@surferpilgrim Your fibArr function would also result in infinite recursion, even if you fixed array.
Guderian Raborg
@hypercuber
Jul 19 2017 05:20
@surferpilgrim your code have "array" but i dont think it is defined
@surferpilgrim I have never use Array.apply(). I should check it out.
kumquatfelafel
@kumquatfelafel
Jul 19 2017 05:22

your code have "array" but i dont think it is defined

@hypercuber Yup. So that would throw an error if fibArr were called. Which it isn't

fdemaa
@fdemaa
Jul 19 2017 05:24
@kumquatfelafel hey man im still having troubles with my random numbers lol, can you help me a bit ?
Veronica Eulenberg
@HappyViki
Jul 19 2017 05:24
I need help with regex. I don’t remember a certain function, or maybe I don’t remember what it’s called…or how to use it.
var calculate = "2+2";
calculate.replace(calculate.match(/(\d)[+](\d)/g),$1+$2)
Guderian Raborg
@hypercuber
Jul 19 2017 05:24
@fdemaa i want to help
Veronica Eulenberg
@HappyViki
Jul 19 2017 05:24
is $1+$2 the right thing?
kumquatfelafel
@kumquatfelafel
Jul 19 2017 05:26
@fdemaa possibly
Veronica Eulenberg
@HappyViki
Jul 19 2017 05:27
@kumquatfelafel do you know regex?
fdemaa
@fdemaa
Jul 19 2017 05:28
the console.log (output names) is showing the correct range of numbers, but when i console.log (output quotes), it only show 0, 1, 2, index only, instead all the possible index my arrays of quotes can have ;
https://s.codepen.io/fdemaa/debug/NgmWvm/dXMqBbnNWOYr
@kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jul 19 2017 05:29
@HappyViki Some. I'm not sure what $1+$2 is supposed to be.
Veronica Eulenberg
@HappyViki
Jul 19 2017 05:30
@kumquatfelafel it’s supposed to be what’s inside the capturing parenthesis
Markus Kiili
@Masd925
Jul 19 2017 05:30
@fdemaa There is an error on browser developer tools console.
Veronica Eulenberg
@HappyViki
Jul 19 2017 05:32
@kumquatfelafel nvm I answered my own question.
fdemaa
@fdemaa
Jul 19 2017 05:33
@Masd925 wich error ? i dont see any , but i new with this browser console ..
kumquatfelafel
@kumquatfelafel
Jul 19 2017 05:33
@HappyViki Well it was a monumental effort on my part, but I finally got you there.
kumquatfelafel @kumquatfelafel bows
kumquatfelafel
@kumquatfelafel
Jul 19 2017 05:34
;) :p
Markus Kiili
@Masd925
Jul 19 2017 05:34
@fdemaa It doesn't give it anymore for some reason. It was about myRange not being defined.
Oleh
@Lufter
Jul 19 2017 05:36

Hello Guys,
I'm done with Weather App, and i would like to ask you for a few things.

  1. Could you please provide me a screenshot of the tab with my Pen
  2. Does anybody know why my Pen is not showing on Mobile?

Random Quotes are showing on my iPhone and Samsung, but Weather App Pen is not showing... and I'm really wondering what the hack...

kumquatfelafel
@kumquatfelafel
Jul 19 2017 05:38
@fdemaa It's probably because not all your characters have same number of quotes, but secondMax and secondMin (which are used to generate the quote #) are determined only once... outside of the function, and then never change. So say secondMax = 7 for a character that has only 3 quotes, e.g.
(if you're referring to how occasionally one of the quotes comes back as "undefined")
That would be my guess at first glance anyway
fdemaa
@fdemaa
Jul 19 2017 05:42
yes it is that i think
i put my variables inside my event
and its working
i think
@kumquatfelafel yes sir ! thanks man
CamperBot
@camperbot
Jul 19 2017 05:43
fdemaa sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 494 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Guderian Raborg
@hypercuber
Jul 19 2017 05:45

Can someone help me in this problem:
Consider a piece of straw with a length of strawLength. You want to break it into smaller pieces with pairwise distinct positive integer lengths. What is the maximum possible number of smaller pieces that you can get from breaking the original piece?

Example

For strawLength = 14, the output should be
piecesOfDistinctLengths(strawLength) = 4.

One of the possible ways to break a straw with a length of 14 into 4 smaller pieces with pairwise distinct integer lengths is to make pieces with lengths of 1, 3, 4, and 6. It is impossible to obtain more than 4 smaller pieces.

so strawLength: 14 return 4

function piecesOfDistinctLengths(strawLength) {

}

Markus Kiili
@Masd925
Jul 19 2017 05:52
@hypercuber What if you just test with 1+2+3+4+... and see that 5 would make 15 that is too much. Or do I understand it wrong?
kumquatfelafel
@kumquatfelafel
Jul 19 2017 05:57
:point_up: I'm tempted to agree with this. Even though 1 2 3 and 4 are not the actual pieces, they are also the smallest possible integers. So if 1+2 + 3 + 4 +5 > strawLength, then there's virtually no way 5 pieces could be returned
If you had to instead return something like a 2d array of different possible piece lengths... I don't want to think about that at this time of night. :p
Brad
@bradtaniguchi
Jul 19 2017 06:00
Yup, that answer sounds pretty much right, I forgot the name of the algorithm
Ryan Kim
@ILoveImages
Jul 19 2017 06:26
var a = 1;
kumquatfelafel
@kumquatfelafel
Jul 19 2017 06:29
var b = 2;
Exciting stuff happening in chat right now! :o
abraham anak agung
@padunk
Jul 19 2017 06:30
Hi, i've seen in MDN especially last section, there is almost always a Polyfill. What is that?
@kumquatfelafel :smile:
Coy Sanders
@coymeetsworld
Jul 19 2017 06:31
var c = 3;
Markus Kiili
@Masd925
Jul 19 2017 06:34
@padunk Code that solves some browser incompatibility issue.
abraham anak agung
@padunk
Jul 19 2017 06:35
@Masd925 So we just copy paste the code into our file?
Markus Kiili
@Masd925
Jul 19 2017 06:38
@padunk Yes, if you need use that method and need to support that browser for example.
abraham anak agung
@padunk
Jul 19 2017 06:39
@Masd925 interesting. Thanks
CamperBot
@camperbot
Jul 19 2017 06:39
padunk sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4307 | @masd925 |http://www.freecodecamp.com/masd925
amatayamada
@amatayamada
Jul 19 2017 07:22
So I've written this little tidbit to wrap a function and count its calls:
#!/usr/bin/env node

module.exports = function Spy(target, method) {
  let oldFun = target[method];
  function newFun() {
    newFun.count += 1;
    return oldFun.apply(target, arguments);
  }
  newFun.count = 0;
  return newFun;
}
however when I call it from REPL it doesn't behave exactly how it should:
> var Spy = require('./ex12-spy.js');
undefined
> var a = Spy(console, 'log');
undefined
> a.count
0
> a('foo', 'bar');
foo bar
undefined
> a.count
0
the wrapped function works, but why doesn't a.count increase?
I also tried to use this.count +=1; inside newFun(), didn't change a thing
Markus Kiili
@Masd925
Jul 19 2017 07:32
@amatayamada I tried it on repl.it, and I see count rising:
function Spy(target, method) {
  let oldFun = target[method];
  function newFun() {
    newFun.count += 1;
    return oldFun.apply(target, arguments);
  }
  newFun.count = 0;
  return newFun;
}

var a = Spy(console,"log");
a.count; // 0
a("cat","pants");
a.count; // 1
amatayamada
@amatayamada
Jul 19 2017 07:33
Huh.
kumquatfelafel
@kumquatfelafel
Jul 19 2017 07:33
@Masd925 I second this. https://repl.it/J8Yx/1
amatayamada
@amatayamada
Jul 19 2017 07:35
indeed!
I guess changing it from this.count += 1; to newFun.count += did help after all
my bad for assuming that calling require() again in REPL would reload the module
starting it in freshly started REPL did work
Markus Kiili
@Masd925
Jul 19 2017 07:37
@amatayamada Using this everywhere works too and just uses a global count variable.
But might not work as intended depending on how you use the functions.
amatayamada
@amatayamada
Jul 19 2017 07:38
@Masd925 I used this.count inside newFun() and newFun.count = 0 outside, before returning newFun
I assumed this means the current object like in C++
I guess that's not how it works
Markus Kiili
@Masd925
Jul 19 2017 07:39
@amatayamada It doesn't. this points to the global object and makes a global variable.
kumquatfelafel
@kumquatfelafel
Jul 19 2017 07:39
@amatayamada yeah. Coming from java, there was a similar learning curve there :p
Walther Cantu
@walthercantu
Jul 19 2017 07:39
Hi all, does anyone know if the FCC weather API has any limitations? It seems like every time it can't resolve a lon/lat it shows the information for Shuzenji, JP.
Walther Cantu
@walthercantu
Jul 19 2017 07:44
Here's my local weather app where it shows the info for Shuzenji, JP even though I'm in Phoenix, AZ. https://codepen.io/walthercantu/pen/ZyNQmJ
Feedback's appreciated.
kumquatfelafel
@kumquatfelafel
Jul 19 2017 07:46
@walthercantu I'm living in undefined, with clouds and -36 ºC :p
Jiri Laza
@N4thyra
Jul 19 2017 07:46
Fellows, is there a CSS guru?
Walther Cantu
@walthercantu
Jul 19 2017 07:46
@kumquatfelafel #facepalm
kumquatfelafel
@kumquatfelafel
Jul 19 2017 07:47
@walthercantu this is a weird browser though. lemme check on different one :laughing:
Markus Kiili
@Masd925
Jul 19 2017 07:47
@N4thyra I think he left the building. You can just ask the question here anyway.
Jiri Laza
@N4thyra
Jul 19 2017 07:48
Let's say I have a <div></div> in which I am dynamically adding <p>, you will normally see the content of <p> showing from top to bottom, how can I achieve showing them the other way around?
kumquatfelafel
@kumquatfelafel
Jul 19 2017 07:48
@walthercantu yeah, still undefined, clouds, 36ºC.
Walther Cantu
@walthercantu
Jul 19 2017 07:49
@kumquatfelafel wonder if it's the API
amatayamada
@amatayamada
Jul 19 2017 07:49
@Masd925 yes, I tried reading that but was quite convoluted...
Markus Kiili
@Masd925
Jul 19 2017 07:49
@N4thyra You wan't the text to flow from bottom to top of p?
amatayamada
@amatayamada
Jul 19 2017 07:49
maybe I'll go back when I understand more
kumquatfelafel
@kumquatfelafel
Jul 19 2017 07:50
@N4thyra are you saying you're adding a bunch of ps and you want the most recently added ps on top?
it says this refers to the current object, the calling object.
Jiri Laza
@N4thyra
Jul 19 2017 07:51
@Masd925 @kumquatfelafel I may have misinterpreted myself. I have a div and I am showing paragraphs in it. I need to make the div of a certain size , and add a scrollbar to it (not a big deal), but the issue I am having is that if I add a scrollbar to the div, the items(paragraphs) that are showing are those at the top(the first ones, not the most recent ones)
amatayamada
@amatayamada
Jul 19 2017 07:51
I tried and replaced line return oldFun.apply(target, arguments); with return oldFun.apply(this, arguments); and it still works
and I don't know the difference
(official solution to the exercise had .apply(this, instead of .apply(target, hence my confusion)
my solution still passed the test tho
Markus Kiili
@Masd925
Jul 19 2017 07:53
@amatayamada When a function is called as a method of an object, this points to the calling object inside that method. When you make a new object with new func(), then inside the constructor this points to the new object being created. I don't see a method or a constructor on your code.
Jiri Laza
@N4thyra
Jul 19 2017 07:53
@Masd925 @kumquatfelafel I need to show the most recent paragraphs on the top, there must be a way to stick them to the top.
kumquatfelafel
@kumquatfelafel
Jul 19 2017 07:55
I... thought I understood what you were saying, but now I'm confused again. :laughing:
Not my area of expertise though, so for what it's worth...
Think gonna call it a night before my brain falls out :p
Markus Kiili
@Masd925
Jul 19 2017 07:56
@N4thyra You can change the html content of the parent element. There is also element.insertBefore() method that might work.
Blauelf
@Blauelf
Jul 19 2017 07:56
@walthercantu Found the line explaining Japan:
url = "https://fcc-weather-api.glitch.me/api/current?lon=" + "30" + "&lat=" + "-110";
amatayamada
@amatayamada
Jul 19 2017 07:58
@Masd925 my bad, that was old version of my code. I misunderstood the exercise and only wrote the wrapper function, without replacing the original function with it as the exercise intended. Here's the code with replacement:
#!/usr/bin/env node

module.exports = function Spy(target, method) {
  let oldFun = target[method];
  function newFun() {
    newFun.count += 1;
    return oldFun.apply(this, arguments);
  }
  newFun.count = 0;
  target[method] = newFun;
  return newFun;
}
from what you said, it would mean that now when I'm calling the replaced version of console.log() it doesn't matter whether I put this or target because in this case, since it became its method by line target[method] = newFun they mean exactly the same thing
is that correct?
I think I get it now, thanks @Masd925
CamperBot
@camperbot
Jul 19 2017 08:00
amatayamada sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4308 | @masd925 |http://www.freecodecamp.com/masd925
amatayamada
@amatayamada
Jul 19 2017 08:00
:)
Blauelf
@Blauelf
Jul 19 2017 08:00
@walthercantu But if I input lat and lon, there's no place like that. I'm not living in a country it seems.
Jiri Laza
@N4thyra
Jul 19 2017 08:00
@Masd925 Thanks for the tips. I was hoping it could be solved by using CSS. Here is what I meant https://codepen.io/N4thyra/pen/WOqRRJ
CamperBot
@camperbot
Jul 19 2017 08:00
n4thyra sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4309 | @masd925 |http://www.freecodecamp.com/masd925
Ogundele Olumide
@Lumexralph
Jul 19 2017 08:05
Hello Everybody! :wave:
Markus Kiili
@Masd925
Jul 19 2017 08:06
@amatayamada If the function is called as a method like console.log(), then this and target are the same inside the method. If you just call that function returned from Spy, it is not called as a method though.
@Lumexralph Yo.
Ogundele Olumide
@Lumexralph
Jul 19 2017 08:06
@Masd925 Good Morning
@Masd925 resumed work?
Markus Kiili
@Masd925
Jul 19 2017 08:08
@Lumexralph Kind of ;) Nobody else here so not too buzy.
abraham anak agung
@padunk
Jul 19 2017 08:09
@N4thyra you mean in your history log? use prepend
Jiri Laza
@N4thyra
Jul 19 2017 08:12
@padunk Thanks. That's exactly what I need. I've forgotten it existed.
CamperBot
@camperbot
Jul 19 2017 08:12
n4thyra sends brownie points to @padunk :sparkles: :thumbsup: :sparkles:
:cookie: 376 | @padunk |http://www.freecodecamp.com/padunk
Ogundele Olumide
@Lumexralph
Jul 19 2017 08:12
@Masd925 :smile: cool
abraham anak agung
@padunk
Jul 19 2017 08:14
@N4thyra np, your calculator color is :+1:
Lay
@L-AY
Jul 19 2017 08:31

Hey All,

I am going through Algo Scripting Challenges to refresh memory and strengthen fundamental understanding.

I have almost completed this following challenge, however require some help using Regex to get rid of the underscore (_). These are the only test cases for which my code is failing. Could somebody please help out?


function palindrome(str) {
  // Good luck!

  var arStr = str.replace(/[^0-9A-z]/g, '').toLowerCase().split("").reverse().join("");

  // [^\w.]+
  // [^0-9A-z]

  var nar = str.replace(/[^0-9A-z]/g, '').toLowerCase().split("").join("");  

  if (arStr == nar){
    return true;
  } else {
    return false;
  }

}

palindrome("_eye");
heroiczero
@heroiczero
Jul 19 2017 08:38
@L-AY the Capital and lowercase should be separated in your regexp[^A-Za-z0-9]
Lay
@L-AY
Jul 19 2017 08:40
@heroiczero Hey, thanks for this - this worked! Would you mind explaining why the above worked and not my solution? :smile:
CamperBot
@camperbot
Jul 19 2017 08:40
l-ay sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1505 | @heroiczero |http://www.freecodecamp.com/heroiczero
heroiczero
@heroiczero
Jul 19 2017 08:46
@L-AY [A-z]you need one for your capitals and lowercase conditions you cannot just mix them together : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp the \W shows you an example to get all nonalphanumeric characters
@L-AY take a look at https://www.w3schools.com/charsets/ref_utf_basic_latin.asp you are including _ and other special characters in your expression when you get all values from A-z
heroiczero
@heroiczero
Jul 19 2017 08:52
@L-AY your getting "ALL" values from capital "A" to lowercase "z" so it would include some characters other than the alphanumeric characters you want
Blauelf
@Blauelf
Jul 19 2017 08:53
@L-AY You could reduce this code a lot. .split("").join("") makes no sense, just reconstructs the string from its characters. You have str.replace(/[^0-9A-Z]/gi, '').toLowerCase() twice, you can use the normalised string stored in one variable to construct the reversed string. Also, review Returning Boolean Values from Functions.
Blauelf
@Blauelf
Jul 19 2017 09:52
One hour of no post, did I kill the chat?
Chris Juchtmans
@kjuchtmans
Jul 19 2017 09:59
Gutemorgen! :wave:
thunderstorm approaching here... time to wrap up my intermediate algorithms, and move on to the advanced stuff :volcano:
Blauelf
@Blauelf
Jul 19 2017 10:00
Time for 昼ご飯 :spaghetti: :)
Dovydas Stirpeika
@Giveback007
Jul 19 2017 10:01
how to wrap a parent in an anchor element without children being affected in html
Chris Juchtmans
@kjuchtmans
Jul 19 2017 10:01
bon appetit!
Blauelf
@Blauelf
Jul 19 2017 10:02
@kjuchtmans Your thunderstorm might reach us here as well (not sure, 3h prediction is usually not really accurate)
Chris Juchtmans
@kjuchtmans
Jul 19 2017 10:03
best bring the cat indoor :watch:
Dovydas Stirpeika
@Giveback007
Jul 19 2017 10:03
<a href="javascript:void(0);" onClick={props.focusOn}>
        <div className='recipe'>
          <button onClick={props.delete}>X</button>
          <h3 className="recipe-name">{props.name}</h3>
          <div>
            <img className='recipe-img' src={props.img}/>
            <h5>Ingredients: {props.ingredientsNum}</h5>
          </div>
        </div>
      </a>
is there a way to avoid having the anchor element from effecting the x button?
Blauelf
@Blauelf
Jul 19 2017 10:05
@Giveback007 Maybe prevent the default in props.delete?
Dovydas Stirpeika
@Giveback007
Jul 19 2017 10:05
@Blauelf I don't think I understand what you mean?
I do want the props.delete function to run but not the <a> element when X is clicked
@Blauelf how do you prevent default?
Markus Kiili
@Masd925
Jul 19 2017 10:08
@Giveback007 You can also stop the event from propagating (bubbling out).
event.stopPropagation()
Dovydas Stirpeika
@Giveback007
Jul 19 2017 10:10
ahh ... you guys are obviously advanced could you dumb it down for me
Markus Kiili
@Masd925
Jul 19 2017 10:12
@Giveback007 Are you using some framework there?
Dovydas Stirpeika
@Giveback007
Jul 19 2017 10:12
React
Markus Kiili
@Masd925
Jul 19 2017 10:13
@Giveback007 Don't know React, but in JS you can stop the event from propagating to outer elements after handling the event on the element event handler function.
Dovydas Stirpeika
@Giveback007
Jul 19 2017 10:15
so... (I think) in other words I can prevent other functions from running after props.delete was executed?
Markus Kiili
@Masd925
Jul 19 2017 10:15
Yes.
Dovydas Stirpeika
@Giveback007
Jul 19 2017 10:15
so i just need to figure out how event.stopPropagation() works
@Masd925 tnx I'll look in to it
CamperBot
@camperbot
Jul 19 2017 10:16
giveback007 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4311 | @masd925 |http://www.freecodecamp.com/masd925
Dovydas Stirpeika
@Giveback007
Jul 19 2017 10:17

:star2: 4311 | @masd925 |http://www.freecodecamp.com/masd925

:bow:

John Alcher
@alchermd
Jul 19 2017 10:19

Hey, React guys out there. Can someone explain the difference between these two snippets:

class Foo extends React.Component {
// ....

handleClick = () => {
    this.setState({
        counter: this.state.counter + 1
    })
  }
}
class Bar extends React.Component {
// ....

handleClick () {
    this.setState({
        counter: this.state.counter + 1
    })
  }
}

I get that arrow functions bind this to the component itself. Then what does the second one bind to? And why does the render() method binds this just fine without using an arrow function?

Dovydas Stirpeika
@Giveback007
Jul 19 2017 10:26
@alchermd where is the second snippet placed? within the render method?
kefah elhelou
@kefelhelou
Jul 19 2017 10:28
hi all
Dovydas Stirpeika
@Giveback007
Jul 19 2017 10:28
@alchermd it's possible that render() is already bound under the hood
John Alcher
@alchermd
Jul 19 2017 10:28
The two snippets are different components. Anyway, I was informed that the second snippet works just fine if it is bound to this in the constructor method. @Giveback007
kefah elhelou
@kefelhelou
Jul 19 2017 10:28
what is the problem in this code please??
var incrementObject = function (object) {
console.log(object);
return Object.keys(object).reduce(function(obj,key))
object.key() = object.key() +1;
return obj;
};
Dovydas Stirpeika
@Giveback007
Jul 19 2017 10:28
but I would check with someone who knows more
John Alcher
@alchermd
Jul 19 2017 10:28
@Giveback007 That makes sense :D
Dovydas Stirpeika
@Giveback007
Jul 19 2017 10:29
@alchermd oh if you bound it in the constructor
then you have to do:
this.handleClick = this.handleClick.bind(this);
class Main extends React.Component {
  constructor(props) {
    super(props);
    // </state>
    this.state = {
      recipes: recipesPreMade,
      focused: false,
      focusedRecipeNum: 0,
      editable: false
    }
    // </bind>
    this.focusOn = this.focusOn.bind(this);
    this.toggleEdit = this.toggleEdit.bind(this);
    this.toggleFocus = this.toggleFocus.bind(this);
  }

  focusOn(num) {
    this.setState({ focused: true, focusedRecipeNum: num });
  }

  toggleEdit() {
    this.setState({ editable: !this.state.editable })
  }

  toggleFocus() {
    this.setState({ focused: !this.state.focused })
  }

  render() {
...
note the bind I did for the functions because I did not use arrow functions
Markus Kiili
@Masd925
Jul 19 2017 10:36
@kefelhelou What kind of object are you passing into that function?
Stuhl
@Stuhl
Jul 19 2017 10:49
someone knows a good tutorial for react or vue ?
Like a Udemy course or something
abraham anak agung
@padunk
Jul 19 2017 10:53
@Stuhl try https://reacttraining.com they are good. Don't know about vue, i would like to learn it too
This message was deleted
Ronald Rodríguez
@ronrsuarez
Jul 19 2017 11:02
@Stuhl I can recommend this one for vue -> https://www.udemy.com/vuejs-2-the-complete-guide/, haven’t learned react
Pieter Stokkink
@forkerino
Jul 19 2017 11:05
@Stuhl This one's awesome: https://www.udemy.com/react-redux/learn/v4/
Blauelf
@Blauelf
Jul 19 2017 11:16
@Masd925 Thanks for mentioning stopPropagation earlier. I thought that preventDefault would handle this as well.
CamperBot
@camperbot
Jul 19 2017 11:16
blauelf sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
Pjdaze
@Pjdaze
Jul 19 2017 11:16
hello all
CamperBot
@camperbot
Jul 19 2017 11:16
:star2: 4313 | @masd925 |http://www.freecodecamp.com/masd925
Ogundele Olumide
@Lumexralph
Jul 19 2017 11:17
@forkerino Hey Bro! :wave:
Pieter Stokkink
@forkerino
Jul 19 2017 11:17
@Lumexralph :wave:
on my lunchbreak
Pjdaze
@Pjdaze
Jul 19 2017 11:17
can anyone help me understand chunk monkey ? i got a solution which i still dont get
abraham anak agung
@padunk
Jul 19 2017 11:18
@Stuhl This one's awesome: https://www.udemy.com/react-redux/learn/v4/
Bookmarked. i'm going to learn Redux too
Pjdaze
@Pjdaze
Jul 19 2017 11:19
function chunkArrayInGroups(arr, size) {
// Break it up.
var arr2 = [];
for (var i = 0; i < arr.length; i+=size) {
arr2.push(arr.slice(i , i+size));
}
return arr2;
}
Pieter Stokkink
@forkerino
Jul 19 2017 11:19
:+1: I love Redux @padunk
@Pjdaze which part don't you understand?
Pjdaze
@Pjdaze
Jul 19 2017 11:20
why does the second i on the arr.slice(i , i + size) refers to the second iteration inside the loop?
Pieter Stokkink
@forkerino
Jul 19 2017 11:20
@Pjdaze it doesn't, it is the endpoint of the current slice (each slice should be size long)
Blauelf
@Blauelf
Jul 19 2017 11:21
@sjames1958gm The udemy link you posted does not work for me (redirects to homepage, and the course of that name shows up in search autocomplete, but not in courses). Does udemy have country restrictions (me being in Germany)?
Pieter Stokkink
@forkerino
Jul 19 2017 11:21
@Blauelf @sjames1958gm same here.
Pjdaze
@Pjdaze
Jul 19 2017 11:21
ok let me read it again and get back to ya hehe @forkerino
Markus Kiili
@Masd925
Jul 19 2017 11:21
@Pjdaze i iterates through the starting points of the slices.
Stephen James
@sjames1958gm
Jul 19 2017 11:22
@Blauelf Hmm that might be for my courses
Blauelf
@Blauelf
Jul 19 2017 11:22
You mean you bought that course which is no longer available for new customers?
Stephen James
@sjames1958gm
Jul 19 2017 11:25
As a not logged in customer I cannot find that course
Ogundele Olumide
@Lumexralph
Jul 19 2017 11:25
@forkerino what's for lunch?
@Pjdaze show your code
Kelechi Chinaka
@ke1echi
Jul 19 2017 11:25
hi guys :wave:
bro were u hide since @Lumexralph
Stephen James
@sjames1958gm
Jul 19 2017 11:26
The instructor is really thorough - he does have this course - https://www.udemy.com/meteor-react/
Pjdaze
@Pjdaze
Jul 19 2017 11:26
damn why i cant get it! @Masd925 @forkerino lol what i see is push(arr.slice(2, 2 + 2)) which for me it means start slicing at index 2 and stop at index 4 :(
function chunkArrayInGroups(arr, size) {
// Break it up.
var arr2 = [];
for (var i = 0; i < arr.length; i+=size) {
arr2.push(arr.slice(i , i+size));
}
return arr2;
}
Markus Kiili
@Masd925
Jul 19 2017 11:27
@Pjdaze Second index is exclusive so it stops at 3.
Ogundele Olumide
@Lumexralph
Jul 19 2017 11:27
@kelechy bro, work oo, travels within 3 days and Andela Interview
Markus Kiili
@Masd925
Jul 19 2017 11:27
arr.slice(begin, end) extracts up to but not including end.
Ogundele Olumide
@Lumexralph
Jul 19 2017 11:27
@kelechy how're you?
Kelechi Chinaka
@ke1echi
Jul 19 2017 11:28
when is the inyerview? am ok man @Lumexralph
Pjdaze
@Pjdaze
Jul 19 2017 11:28
right but ok inside the condition we say i = i + size which in this case is 2..
Ogundele Olumide
@Lumexralph
Jul 19 2017 11:28
@kelechy done it, it was on Monday
Stuhl
@Stuhl
Jul 19 2017 11:29
@padunk @sjames1958gm @ronrsuarez @forkerino Thanks guys, will see about them
BTW Stephen ur link doesn't work, maybe a typo
CamperBot
@camperbot
Jul 19 2017 11:29
:cookie: 29 | @ronrsuarez |http://www.freecodecamp.com/ronrsuarez
:cookie: 377 | @padunk |http://www.freecodecamp.com/padunk
stuhl sends brownie points to @padunk and @sjames1958gm and @ronrsuarez and @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2871 | @forkerino |http://www.freecodecamp.com/forkerino
:star2: 8108 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Kelechi Chinaka
@ke1echi
Jul 19 2017 11:29
how was it @Lumexralph
Stephen James
@sjames1958gm
Jul 19 2017 11:30
@camperbot Stephen Grider is another instructor on udemy that I have taken courses from and liked
Markus Kiili
@Masd925
Jul 19 2017 11:30
@Pjdaze If size is 2 then i iterates through values 0,2,4,... and then slices are slice(0,2), slice(2,4),... making chunks from indices 0,1, 2,3,...
Stephen James
@sjames1958gm
Jul 19 2017 11:30
@Stuhl It appears that the course that I took is no longer available. :(
Pjdaze
@Pjdaze
Jul 19 2017 11:31
for inside the codeblock when we say slice(i, 2) ---'' for example'' --- we would be starting the slice at index 1? @Masd925
Ogundele Olumide
@Lumexralph
Jul 19 2017 11:31
@kelechy did my best bro, I can't choose myself, waiting for their response though but I think I didn't do badly, code-defence went good and the other stage....I hope that'll be enough
Markus Kiili
@Masd925
Jul 19 2017 11:31
@Pjdaze It is arr.slice(i , i+size)
Value of i depends on which loop step we are on.
Slice size will always be size.
Kelechi Chinaka
@ke1echi
Jul 19 2017 11:33
code defense? sounds new..u mean to explain home study code @Lumexralph
Pjdaze
@Pjdaze
Jul 19 2017 11:33
@Masd925 i appreciate your help a lot but i honestly think i need a special ed tutor :(
Ogundele Olumide
@Lumexralph
Jul 19 2017 11:34
@kelechy I was sent 5 code challenges, to attempt 3 and submit them prior to the interview, I used Python and on getting there I was told JS was accepted too
Markus Kiili
@Masd925
Jul 19 2017 11:35
@Pjdaze Try console.log:ing the values of i, i+size and arr.slice(i , i+size) on each loop step and try it on different arrays and sizes. You will get it then.
Ogundele Olumide
@Lumexralph
Jul 19 2017 11:35
@kelechy yeah, so you'll talk about how you solved the challenge using your submitted code
Pjdaze
@Pjdaze
Jul 19 2017 11:35
lol true
Kelechi Chinaka
@ke1echi
Jul 19 2017 11:36
sounds cool @Lumexralph
Pjdaze
@Pjdaze
Jul 19 2017 11:36
@Masd925 do you currently work in this field?
Markus Kiili
@Masd925
Jul 19 2017 11:37
@Pjdaze Yes, I am a JS programmer.
Pjdaze
@Pjdaze
Jul 19 2017 11:37
sweet for how long? @Masd925
Markus Kiili
@Masd925
Jul 19 2017 11:38
I graduated 1,5 years ago and have been working since.
Kelechi Chinaka
@ke1echi
Jul 19 2017 11:40
when is the bootcamp @Lumexralph
u mean 15 @Masd925
Markus Kiili
@Masd925
Jul 19 2017 11:40
@kelechy I hope :)
I graduated 15 years ago but on another field.
Pieter Stokkink
@forkerino
Jul 19 2017 11:43
@Lumexralph lunch was good. Working at home today, so can make whatever I want. Now back to work, have a Pull Request to do.
Kelechi Chinaka
@ke1echi
Jul 19 2017 11:44
interesting..what field? @Masd925
Markus Kiili
@Masd925
Jul 19 2017 11:45
@kelechy Particle physics, so mostly math.
Kelechi Chinaka
@ke1echi
Jul 19 2017 11:46
wow i love math @Masd925
Blauelf
@Blauelf
Jul 19 2017 11:53

Physics is all about maths. In some cases generalised maths without proof for the generalisation (removing restrictions that were important for the proof, but as long as everything goes well...)

I used to shoot argon on my targets, with far less than the 6MeV our linear accelerator could handle. (Recorded an energy spectrum, I think the technique is called "Rutherford backscattering spectrometry")

Kelechi Chinaka
@ke1echi
Jul 19 2017 11:58
math is cool..am currently taking math course at khan academy
Blauelf
@Blauelf
Jul 19 2017 12:00
Also hit the surfaces with 30keV electrons (raster electron microscopy), which gives real images (which slowly change because... um... energy and charge deposition, changes were too fast at that voltage for a highest-res image)
@kelechy Maths can be very different. Most really cool stuff is cool until you try to apply it. It's like functional programming. If you want to use it, you have to allow for impurities.
Kelechi Chinaka
@ke1echi
Jul 19 2017 12:04
hmm..so it should be more practicing the math concepts @Blauelf
how do u mean by different
Markus Kiili
@Masd925
Jul 19 2017 12:06
@Blauelf Maths get nice with things like Axiom of choice. Can't prove many things without assuming it, but if you do, you can cut a ball into a pieces and make a larger ball.
Blauelf
@Blauelf
Jul 19 2017 12:07
The maths I've seen in studying physics has been very diverse. And the numerics people have some of the most valuable stuff but are sometimes not seen as mathematicians.
Blauelf
@Blauelf
Jul 19 2017 12:14
Things like "rephrase 1+x1x\frac{\sqrt{1+x}-1}{x} to be stable at limx0+\lim_{x \to 0^+}" (just multiply by 1=1+x+11+x+11=\frac{\sqrt{1+x}+1}{\sqrt{1+x}+1} to receive 11+x+1\frac{1}{\sqrt{1+x}+1})
Adri Jenie
@Adrifajar
Jul 19 2017 12:16
why i can not use str=str.toLowerCase();
im doing "Title Case a Sentence" challenge
Markus Kiili
@Masd925
Jul 19 2017 12:17
@Adrifajar You can if str is a string.
Adri Jenie
@Adrifajar
Jul 19 2017 12:17
TypeError: str.toLowerCase is not a function
it is a string

function titleCase(str) {
str= str.split(' ');
str=str.toLowerCase();

return str;
}

titleCase("I'm a little tea pot");

Blauelf
@Blauelf
Jul 19 2017 12:18
@Adrifajar What doesn't work? If str is a string, it should return a lowercased version and assign it to str. If you changed str to be an array or something like that (how misleading!), then it won't.
Markus Kiili
@Masd925
Jul 19 2017 12:18
@Adrifajar str is an array after the split.
toLowerCase only works on strings.
So you need a loop or an iterator like map.
Blauelf
@Blauelf
Jul 19 2017 12:19
@Adrifajar toLowerCase before splitting. You can even chain those, like var arr = str.toLowerCase().split(' ');
Adri Jenie
@Adrifajar
Jul 19 2017 12:19
but why i can do it when i do the "palindrome" challenge

function palindrome(str) {
// Good luck!
str=str.toLowerCase();
str= str.split(' ');
str = str.join("");
str=str.replace(/[\W_]/g,'');

palin = str.split("");
palin =palin.reverse();
palin =palin.join("");

if (str===palin){
return true;
}

return false;
}

//str.replace(/\W/g, '')

palindrome("_eye");

nvm
i saw it now
i split it later
@Blauelf thank you
CamperBot
@camperbot
Jul 19 2017 12:20
adrifajar sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4512 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Jul 19 2017 12:20

@Adrifajar

str= str.split(' ');
str = str.join("");

makes little sense. It removes the spaces, which

str=str.replace(/[\W_]/g,'');

would do on its own.

Adri Jenie
@Adrifajar
Jul 19 2017 12:20
@Masd925 thank you
CamperBot
@camperbot
Jul 19 2017 12:20
adrifajar sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4314 | @masd925 |http://www.freecodecamp.com/masd925
Adri Jenie
@Adrifajar
Jul 19 2017 12:22
@Blauelf thank you
CamperBot
@camperbot
Jul 19 2017 12:22
adrifajar sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:warning: adrifajar already gave blauelf points
Blauelf
@Blauelf
Jul 19 2017 12:23
I really dislike when people store a value just to use it exactly once, on the next line.
Even more I dislike people storing an array in a variable str or a string in a variable arr
That functional programming paradigm with all variables being actually constants, and everything being immutable, is really tempting.
Blauelf
@Blauelf
Jul 19 2017 12:29
As soon as you hit input or output you cannot rely on idempotence and all the other benefits, though, which makes pure functional programming useless. But it's so nice maths :-/
Markus Kiili
@Masd925
Jul 19 2017 12:29
I can feel your anger. It give you focus... makes you stronger.
Blauelf
@Blauelf
Jul 19 2017 12:35
Well spoken, Master Yoda. Lucas' interest in Japanese grammar is 面白い (おもしろい, funny/interesting)
Markus Kiili
@Masd925
Jul 19 2017 12:36
It was actually the supreme chancellor. Yoda thought anger was not a good idea.
Blauelf
@Blauelf
Jul 19 2017 12:36
Oh, that was not Yoda, but Palpatine. But what was the similar thing Yoda said on Dagobah?
There was something with that cave, where Luke thought to meet Vader.
Blauelf
@Blauelf
Jul 19 2017 12:37
Supreme chancellor... at that time he was the Emperor, ruling over the remains of the old republic.
Guess the one I meant was Fear is the path to the dark side. Fear leads to anger. Anger leads to hate. Hate leads to suffering.
I wonder if anyone openly called Darth Sidious by that name?
Boris Yordanov
@borisyordanov
Jul 19 2017 13:11
Has anyone worked with Bing's Image Search API?
Ketan Malwa
@m-ketan
Jul 19 2017 13:15
Can anyone solve a quick jQuery issue that i'm facing?
Boris Yordanov
@borisyordanov
Jul 19 2017 13:19
@m-ketan what's the problem
Abhinav Mishra
@abhinav-m
Jul 19 2017 13:24
Why am i getting an undefined in the global variable here
$(document).ready(function() {
//This variable has global scope (window scope) in browser
var testVar = "globalScope";

differentScope();
});


function differentScope() {
console.log("Printing before testVar's declaration should print global variable's value.Proof"+testVar);
var testVar = "functionCreatedScope";
console.log("different value here for testvar :"+testVar);
{
//Doesnt create a local variable {} is basically an object declaration
var testVar = "stillFunctionCreatedScope";
console.log("this is the same variable as outside as { } doesn't create it's own scope. Proof:"+testVar);
}

{
//However let keyword allows declaration of block scope local variable
let testVar = "blockCreatedScope";
console.log("'let' keyword allows creation of variables with scope within the current block. Proof:"+testVar);
}

console.log("this will print the later initialized variable -1 ie, 5 as it's scope is shared (declared using var) and not the function's scope. Proof:"+testVar);
}
the first console.log should print the global testVar's value?
Ketan Malwa
@m-ketan
Jul 19 2017 13:26
I'm trying to set the display property of the div to block using jQuery when the button is clicked but since I have multiple buttons the div is appearing on each button
<button onclick=handleClick(this) class="btn btn-dropdown"><i class="fa fa-caret-down" aria-hidden="true"></i></button>
<div class="dropdown-opt"></div>
$('.btn-dropdown').click(this, function() {
            $('.dropdown-opt').css({'display': 'block'})
        })
    }
*ignore the onclick on the button
All I want is that the div appears only on the button which gets clicked and not on all the buttons
Abhinav Mishra
@abhinav-m
Jul 19 2017 13:28
@m-ketan add an id to that button and use the id selector in jquery
$("#myButton").click ...
Ketan Malwa
@m-ketan
Jul 19 2017 13:30
@abhinav-thinktank The problem is that I'm having 10 of such buttons on a single page.
Abhinav Mishra
@abhinav-m
Jul 19 2017 13:32
@m-ketan you can assign unique id's to each..
Ketan Malwa
@m-ketan
Jul 19 2017 13:39
@abhinav-thinktank thanks, I'll look into it
CamperBot
@camperbot
Jul 19 2017 13:39
m-ketan sends brownie points to @abhinav-thinktank :sparkles: :thumbsup: :sparkles:
:cookie: 405 | @abhinav-thinktank |http://www.freecodecamp.com/abhinav-thinktank
Joel Y.
@zapcannon99
Jul 19 2017 13:46
@abhinav-thinktank I don't think that's a global variable. If you want a global variable that's outside the scope of $(document).ready, you'll need to put testVar outside of the ready function. Or you move the differentScope function within .ready
Alternatively, you could get rid of the var keyword and make a truely global variable, but but I believe you have to be aware that it might affect other scripts.
Abhinav Mishra
@abhinav-m
Jul 19 2017 13:49
@zapcannon99 even if i place it outside document.ready, i got undefined
@zapcannon99 i think its due to hoisting.
Anyone can confirm?
Blauelf
@Blauelf
Jul 19 2017 13:50
@kjuchtmans Guess the remains of your "thunderstorm" are finally here. It's getting dark. No rain or thunder yet.
Joel Y.
@zapcannon99
Jul 19 2017 13:52
I see. I'll look into it then.
Joel Y.
@zapcannon99
Jul 19 2017 14:00

@abhinav-thinktank Yeah, it's hoisting. So forget all the noob stuff I just said. I read a suggestion that to access the global variable, you'll need to add window. so the first testVar you have in differentScope() should be window.testVar.

Huh, who knew. I learned something, but I'm curious why I haven't come across this problem yet....

Jianhao Tan
@jaanhio
Jul 19 2017 14:00
is this the right place for questions on React?
Abhinav Mishra
@abhinav-m
Jul 19 2017 14:01
@zapcannon99 im just testing scopes.. so its fine, yeap TIL.
Joel Y.
@zapcannon99
Jul 19 2017 14:01
@abhinav-thinktank Oh and you're supposed to get rid of the var in the .ready()
Blauelf
@Blauelf
Jul 19 2017 14:02
@zapcannon99 Global variables (if not declared using ES6 let or const in a global scope but either by assignment without declaration or using var in a global scope) are also properties of the global object, which is window in a browser
Joel Y.
@zapcannon99
Jul 19 2017 14:03
@Blauelf Makes sense. Thanks for clarifying.
CamperBot
@camperbot
Jul 19 2017 14:03
zapcannon99 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4513 | @blauelf |http://www.freecodecamp.com/blauelf
Joel Y.
@zapcannon99
Jul 19 2017 14:03
@abhinav-thinktank Thanks for letting me learn something important.
CamperBot
@camperbot
Jul 19 2017 14:03
zapcannon99 sends brownie points to @abhinav-thinktank :sparkles: :thumbsup: :sparkles:
:cookie: 406 | @abhinav-thinktank |http://www.freecodecamp.com/abhinav-thinktank
Abhinav Mishra
@abhinav-m
Jul 19 2017 14:04
Also , @zapcannon99 let variables are hoisted, but not initialised
@camperbot let var = 5 will be hoisted but not initialised
@zapcannon99
@zapcannon99 throwing reference error
Traek Wells
@TraekWells
Jul 19 2017 14:06
@kumquatfelafel yeah I missed another obvious part. I didn’t call the function on the event listener.
var newQuote = document.getElementById("newQuote");
var result = document.getElementById("result");
var url = "https://quotesondesign.com/api-v4-0/";

function newQuoteRequest() {
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
        if(xhr.readyState == XMLHttpRequest.DONE) {
            console.log(xhr.status);
        } else {
            console.log("There was an error of some sort. Figure it out homie.");
        }
    };
    xhr.open("GET", url, true);
    xhr.send();
}

newQuote.addEventListener("click", newQuoteRequest);
Blauelf
@Blauelf
Jul 19 2017 14:06
@abhinav-thinktank Variables declared with let have a TDZ, when accessed before declaration they throw an error.
Alex
@alexandrupintilei
Jul 19 2017 14:06
@Blauelf can you help me pls?
Blauelf
@Blauelf
Jul 19 2017 14:07
Depends. Pretty much on your problem.
Traek Wells
@TraekWells
Jul 19 2017 14:07
@kumquatfelafel it’s still giving me the else part of the logic. I’m also having a CORS issue that I’m looking into. I thought it would at least give me the xhr.status though.
Victor Popescu
@VicPopescu
Jul 19 2017 14:08
@TraekWells use https://crossorigin.me/https://quotesondesign.com/api-v4-0/ to bypass the CORS problems
Blauelf
@Blauelf
Jul 19 2017 14:08
@kjuchtmans Can confirm thunder and storm, but sadly no cat to save.
Moisés Man
@moigithub
Jul 19 2017 14:10
@TraekWells using proxies is just a temporary fix. probably u should also learn to use jsonp to bypass CORS
probably would be better to have less dependencies on 3rd party services...
Abhinav Mishra
@abhinav-m
Jul 19 2017 14:11
@Blauelf tdz?
Joel Y.
@zapcannon99
Jul 19 2017 14:11

@abhinav-thinktank @Blauelf I guess my question (for my amateur self) is when do you use let, const, and var. I understand using a true global variable (without any preceding keywords) is for when you want access to it from any linked scripts (right?). So correct me if I'm wrong but:

var- like any traditional variable except gets hoisted
let- scope is limited to the "tier" or level of the scope and is unaffected by any assignments from a deeper scope
const: unchangeable variables (like pi or something)

Victor Popescu
@VicPopescu
Jul 19 2017 14:11
@moigithub I agree
Abhinav Mishra
@abhinav-m
Jul 19 2017 14:11
@Blauelf sorry not aware what is TDZ
@zapcannon99 the other day soemone posted an error
Traek Wells
@TraekWells
Jul 19 2017 14:12
@VicPopescu sweet man thanks! I’ll still do what @moigithub says and learn JSONP. The CORS issue isn’t showing in the console anymore though
CamperBot
@camperbot
Jul 19 2017 14:12
traekwells sends brownie points to @vicpopescu and @moigithub :sparkles: :thumbsup: :sparkles:
:cookie: 505 | @vicpopescu |http://www.freecodecamp.com/vicpopescu
:star2: 3518 | @moigithub |http://www.freecodecamp.com/moigithub
Blauelf
@Blauelf
Jul 19 2017 14:12
@abhinav-thinktank Temporal Dead Zone, the time between hoisted declaration (entering the scope of the variable) and the let keyword
Abhinav Mishra
@abhinav-m
Jul 19 2017 14:13
@Blauelf aah, i seee
Victor Popescu
@VicPopescu
Jul 19 2017 14:13
@TraekWells like @moigithub said, that's just a temporary fix to bypass that issue.Learning to use jsonp is way better
Abhinav Mishra
@abhinav-m
Jul 19 2017 14:13
@Blauelf and the ones with var don't , thus they are uninitialized
Alex
@alexandrupintilei
Jul 19 2017 14:13
@Blauelf the if/else statmend dosent work :(
Bradley Sands
@sandsbe
Jul 19 2017 14:14
My .click(), searchTerm, and url (tested from Postman), all work, according to alert tests. For some reason my ajax call is not only not working, but resetting my page (sometimes) or clearing my page entirely.
  alert( "Handler for "+url+" called." );
  $.ajax({
    type: "GET",
    url: url,
    async: false,
    dataType: "json",
    success: function(data) {
      alert(data[1][0]);
      for (var i = 0; i < data.length; i++)
        // http://api.jquery.com/prepend/
        // The .prepend() method inserts the specified content as the first child of each element in the jQuery collection. To insert it as the last child, use .append()
        $("#output").prepend(data[1][0]);
    },
    error: function(errorMessage) {
      alert("Error");
    }
  });
Blauelf
@Blauelf
Jul 19 2017 14:17
@alexandrupintilei Second call results in {"error":"Bad Request","status":400,"message":"No client id specified"}, which is somewhat strange, as it looks very similar to the first.
Alex
@alexandrupintilei
Jul 19 2017 14:18
@Blauelf I fix it
just added client it to getJSON
Stephen James
@sjames1958gm
Jul 19 2017 14:19
@sandsbe Do you have a form? that your search data is in?
Blauelf
@Blauelf
Jul 19 2017 14:20
@alexandrupintilei But why would it complain only the second time? Did you have client-id on the first one already?
Bradley Sands
@sandsbe
Jul 19 2017 14:21
@sjames1958gm I do.
  var searchTerm = $("#searchTerm").val();
  alert( "Handler for "+searchTerm+" called." );
Stephen James
@sjames1958gm
Jul 19 2017 14:21
@sandsbe The likely your form is submitting to the "backend" which you don't have, but it then resets the page.
Your handler needs to use preventDefault() function.
Bradley Sands
@sandsbe
Jul 19 2017 14:22
<form style='padding-top: 10px'>
     <div class='form-group'>
       <input class='form-control' id='searchTerm'>
     </div>
     <button type="submit" class="btn btn-primary" id='search'>Submit</button>
  </form>
Stephen James
@sjames1958gm
Jul 19 2017 14:22
@sandsbe
$("#search).on("click", function(e) {
    e.preventDefault();
   // handle event
});
Murrium
@Murrium123
Jul 19 2017 14:24
@moigithub Thanks... I just saw the feedback now :)
CamperBot
@camperbot
Jul 19 2017 14:24
murrium123 sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3519 | @moigithub |http://www.freecodecamp.com/moigithub
Bradley Sands
@sandsbe
Jul 19 2017 14:24
is preventDefault() common?
Stephen James
@sjames1958gm
Jul 19 2017 14:24
@sandsbe Yes, when you have a form, but are processing it with js
Bradley Sands
@sandsbe
Jul 19 2017 14:25
How else would I process it? php?
Stephen James
@sjames1958gm
Jul 19 2017 14:26
@sandsbe Yes, form would automatically send a POST request to your backend.
Blauelf
@Blauelf
Jul 19 2017 14:27
@sandsbe preventDefault is needed whenever you want to avoid the default action. If you for example have a checkbox you don't just want to disable but instead pop up some license terms, you'd prevent the default (and check it by Javascript once the person has accepted the terms). If you'd want to prevent submission if some input checks fail, the same.
Stephen James
@sjames1958gm
Jul 19 2017 14:28
Which I believe if you look in the network tab of the devtools you will see a POST request
Bradley Sands
@sandsbe
Jul 19 2017 14:29
What is weird is my code was working yesterday and console.log'ing results. Now today it is doing this "default action".
Blauelf
@Blauelf
Jul 19 2017 14:29
@sjames1958gm Isn't the default GET rather than POST? Or has that changed since the 1990s?
Bradley Sands
@sandsbe
Jul 19 2017 14:29
Ok, so because I put the HTML in a <form>, that is what is sending the POST?
Stephen James
@sjames1958gm
Jul 19 2017 14:29
@Blauelf You are correct as usual :) thx
CamperBot
@camperbot
Jul 19 2017 14:29
sjames1958gm sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4514 | @blauelf |http://www.freecodecamp.com/blauelf
Stephen James
@sjames1958gm
Jul 19 2017 14:30
@sandsbe Yes, or the GET as @Blauelf says
Amir Saleem
@amirsaleem96
Jul 19 2017 14:30

Hi all, I have a question.
I have an API which uploads image to google cloud bucket and returns the image url. This works fine with formData when doing upload.

Now, let us say I have an image on some other server (I have image url) and I want to upload this image to google cloud server using API call. How to do this??

I am using nodesJS + express at backend. I don't want to refresh the page. Till now I am able to download image on my server, now, how can I send this image to API call using AJAX?

Stephen James
@sjames1958gm
Jul 19 2017 14:30
And that is why it is resetting the page.
Bradley Sands
@sandsbe
Jul 19 2017 14:30
But I want the get in my ajax. So its sending a GET before it "gets" to my ajax GET...?
Blauelf
@Blauelf
Jul 19 2017 14:30
@sjames1958gm I even did form as mail, which opens your mail client with the form data, depending on client either in subject or in body (I think Outlook Express 6 was a bit ugly there as well)
Stephen James
@sjames1958gm
Jul 19 2017 14:31
@sandsbe This is a different GET, you want to disable that behavior so you can use AJAX to send the GET to the API server.
The GET that would be sent from the form will go to the domain of the page that the form loaded from.
Bradley Sands
@sandsbe
Jul 19 2017 14:32
Ok. This all makes a ton of sense. TY @sjames1958gm & @Blauelf
CamperBot
@camperbot
Jul 19 2017 14:32
sandsbe sends brownie points to @sjames1958gm and @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4515 | @blauelf |http://www.freecodecamp.com/blauelf
:star2: 8110 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 19 2017 14:32
@amirsaleem96 You can use the request package or axios library to send requests from your backend inside of node.
@sandsbe :+1:
Blauelf
@Blauelf
Jul 19 2017 14:32
@sjames1958gm Is that one of the cases for onsubmit="return false"?
Looks like it
Amir Saleem
@amirsaleem96
Jul 19 2017 14:34
@sjames1958gm
can it be done with request without page load??
I am using jquery ajaxSubmit library.
would be better if you share the reference links
Abhinav Mishra
@abhinav-m
Jul 19 2017 14:36
@Blauelf Thanks man!
CamperBot
@camperbot
Jul 19 2017 14:36
abhinav-thinktank sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4516 | @blauelf |http://www.freecodecamp.com/blauelf
Abhinav Mishra
@abhinav-m
Jul 19 2017 14:36
can you confirm this question too
Stephen James
@sjames1958gm
Jul 19 2017 14:37
@amirsaleem96 If you can get the image to your backend, then the backend should be able to load to the google cloud.
Not sure exactly how to do it. But you can do API calls from the backend.
Abhinav Mishra
@abhinav-m
Jul 19 2017 14:37
var globalVar;

$(document).ready(function() {
//This variable has global scope (window scope) in browser
globalVar = "globalScope";
console.log("currently global scope");
differentScope();
testGlobal();
});


function differentScope() {
//WRONG! globalVar get's hoisted to the top and console.log prints undefined, not the global variable.
console.log("different value here for globalVar :"+globalVar);

var globalVar;
globalVar = "localFunctionScope";
console.log("different value here for globalVar :"+globalVar);
}
it will print undefined then localFunctionscope
correct?
Amir Saleem
@amirsaleem96
Jul 19 2017 14:38
@sjames1958gm
without page refresh??
Stephen James
@sjames1958gm
Jul 19 2017 14:39
@amirsaleem96 I would think so, but without trying I am only speculating.
Amir Saleem
@amirsaleem96
Jul 19 2017 14:40
@sjames1958gm
okay thanks for giving your time, appreciate your effort.
CamperBot
@camperbot
Jul 19 2017 14:40
amirsaleem96 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8111 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 19 2017 14:40
@amirsaleem96 good luck.
Amir Saleem
@amirsaleem96
Jul 19 2017 14:41
@sjames1958gm
Thanks again.
CamperBot
@camperbot
Jul 19 2017 14:41
amirsaleem96 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: amirsaleem96 already gave sjames1958gm points
Bradley Sands
@sandsbe
Jul 19 2017 14:41
So, what finally allowed my JS to get to the ajax call was a change to the HTML. It was because I put my <input> within a <form> that necessitated the action='' and onsubmit='return false'
<form style='padding-top: 10px' action='' onsubmit='return false'>
    <div class='form-group'>
      <input class='form-control' id='searchTerm'>
    </div>
    <button type="submit" class="btn btn-primary" id='search'>Submit</button>
  </form>
Joel Y.
@zapcannon99
Jul 19 2017 14:45
@abhinav-thinktank yeah. I think so
Amir Saleem
@amirsaleem96
Jul 19 2017 14:46
@sjames1958gm
One more question, I am calling several api's in sequence using jquery ajax, there are total 3 api's. When calling all three together (in sequence) the third api creates new sql connection (I use show processlist for this) and this connection never dies even when using connection pooling and timeout but when calling only two the connection remains only one and it refreshes each time I call API's using radio buttons or refreshes the page. What could be the cause?
Diego Mayer
@Chrono79
Jul 19 2017 14:46
@abhinav-thinktank that seems to be the case, yes
Abhinav Mishra
@abhinav-m
Jul 19 2017 14:46
@Chrono79 and this is due to hoisting?
Diego Mayer
@Chrono79
Jul 19 2017 14:46
yes
Abhinav Mishra
@abhinav-m
Jul 19 2017 14:46
@Chrono79 ok ok ! thanks!
CamperBot
@camperbot
Jul 19 2017 14:46
abhinav-thinktank sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4490 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Jul 19 2017 14:47
JavaScript only hoists declarations, not initializations.
Abhinav Mishra
@abhinav-m
Jul 19 2017 14:47
Yes, i read that part.
Daniel Kang
@a1mighty
Jul 19 2017 14:47
can anyone help me with the backend MongoDB part
Abhinav Mishra
@abhinav-m
Jul 19 2017 14:47
but if you use let , it throws a reference error due to TDZ
Amir Saleem
@amirsaleem96
Jul 19 2017 14:47

@Chrono79

@sjames1958gm
One more question, I am calling several api's in sequence using jquery ajax, there are total 3 api's. When calling all three together (in sequence) the third api creates new sql connection (I use show processlist for this) and this connection never dies even when using connection pooling and timeout but when calling only two the connection remains only one and it refreshes each time I call API's using radio buttons or refreshes the page. What could be the cause?

Stephen James
@sjames1958gm
Jul 19 2017 14:47
@amirsaleem96 I don't have enough experience with SQL to answer that. Maybe someone else on line does.
Diego Mayer
@Chrono79
Jul 19 2017 14:47
that's why even if you initialize your local globalVar, you'll get undefined in the first console .log inside the function
Amir Saleem
@amirsaleem96
Jul 19 2017 14:48
@sjames1958gm
Okay
Abhinav Mishra
@abhinav-m
Jul 19 2017 14:48
@Chrono79 ok
Daniel Kang
@a1mighty
Jul 19 2017 14:48
image.png
image.png
sorry for the double post
why does the count function require a "+" for the age variable
it doesn't work if you do {age: {$gt: age}}
what does the "+" do?
Diego Mayer
@Chrono79
Jul 19 2017 14:50
coerces to number?
Daniel Kang
@a1mighty
Jul 19 2017 14:50
ah so the + means positive
Jan Shah
@JanShah
Jul 19 2017 14:51
has anyone done this part of fcc? 'Save your Code Revisions Forever with Git'
Diego Mayer
@Chrono79
Jul 19 2017 14:51
@amirsaleem96 sorry Idk
Daniel Kang
@a1mighty
Jul 19 2017 14:51
@Chrono79 Thanks
CamperBot
@camperbot
Jul 19 2017 14:51
a1mighty sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4491 | @chrono79 |http://www.freecodecamp.com/chrono79
Amir Saleem
@amirsaleem96
Jul 19 2017 14:51
@Chrono79
its okay.
Daniel Kang
@a1mighty
Jul 19 2017 14:53
@CentropyIT Yea I have
Jan Shah
@JanShah
Jul 19 2017 14:54
@a1mighty I haven't got a credit card, there should be an alternative that doesn't require it. it's been suggested that I skip it
I think that's a better idea under the circumstances
Daniel Kang
@a1mighty
Jul 19 2017 14:55
@CentropyIT to use cloud9?
Jan Shah
@JanShah
Jul 19 2017 14:56
@a1mighty it requires a credit card to sign up, even though its free
Daniel Kang
@a1mighty
Jul 19 2017 14:56
image.png
I never used a credit card to sign up
Abhinav Mishra
@abhinav-m
Jul 19 2017 14:57
@Chrono79 Do you have some good resource to learn OOP with js
Diego Mayer
@Chrono79
Jul 19 2017 14:58
@abhinav-thinktank Not really
Abhinav Mishra
@abhinav-m
Jul 19 2017 14:58
@Chrono79 ok :(
Abhinav Mishra
@abhinav-m
Jul 19 2017 14:59
@Chrono79 Thanks!
CamperBot
@camperbot
Jul 19 2017 14:59
abhinav-thinktank sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: abhinav-thinktank already gave chrono79 points
Abhinav Mishra
@abhinav-m
Jul 19 2017 15:00
Any other topics on js you recommend brushing up
@Chrono79 have an interview tomorrow
Diego Mayer
@Chrono79
Jul 19 2017 15:00
Good luck then :+1:
Abhinav Mishra
@abhinav-m
Jul 19 2017 15:00
This is what i've done - > scopes closures, read through eloquent once
Diego Mayer
@Chrono79
Jul 19 2017 15:02
j113203
@j113203
Jul 19 2017 15:03
@CentropyIT um..here one free credit card ready to use :point_up: July 7, 2017 11:25 PM
Jan Shah
@JanShah
Jul 19 2017 15:04
cn I use it to buy stuff?
j113203
@j113203
Jul 19 2017 15:04
prepaid card
Daniel Kang
@a1mighty
Jul 19 2017 15:06
Christian
@Neralizer
Jul 19 2017 15:06
can anyone help me start with my weather icon on my project? https://codepen.io/cneral21/pen/XMRgap?editors=0010
Abhinav Mishra
@abhinav-m
Jul 19 2017 15:06
ty @a1mighty
CamperBot
@camperbot
Jul 19 2017 15:06
abhinav-thinktank sends brownie points to @a1mighty :sparkles: :thumbsup: :sparkles:
:cookie: 297 | @a1mighty |http://www.freecodecamp.com/a1mighty
Christian
@Neralizer
Jul 19 2017 15:08
I think I'm all set except for the icon
Murrium
@Murrium123
Jul 19 2017 15:09
Wouldnt the icon be an image that you could insert into the HTML?
Daniel Kang
@a1mighty
Jul 19 2017 15:10
@Neralizer I don't see a "#" for icon in the Jquery and I don't see an icon div in your html
where would the icon go
Christian
@Neralizer
Jul 19 2017 15:12
well I'm asking because there's this new api thing https://fcc-weather-api.glitch.me/
Daniel Kang
@a1mighty
Jul 19 2017 15:13
@Neralizer I don't see where the icon goes in your html, for example <div id="icon">
Christian
@Neralizer
Jul 19 2017 15:18
okay, that's there
hang on, I think I've got it, thanks @a1mighty
CamperBot
@camperbot
Jul 19 2017 15:18
neralizer sends brownie points to @a1mighty :sparkles: :thumbsup: :sparkles:
:cookie: 298 | @a1mighty |http://www.freecodecamp.com/a1mighty
Bradley Sands
@sandsbe
Jul 19 2017 15:19
@Neralizer Need to insert the 'img', then bring in the icon
iconDOM = document.createElement("img"); at least how I did it
then just appendChild
Besides that your codepen worked for my location
Christian
@Neralizer
Jul 19 2017 15:24
is iconDom your variable?
Bradley Sands
@sandsbe
Jul 19 2017 15:24
Its my first variable
then icon = iconDom
One sec, I'm skipping a step.
iconDOM.src = icon;
Then, document.getElementById("icon").appendChild(iconDOM);
Daniel Kang
@a1mighty
Jul 19 2017 15:28
@Neralizer or you could make a <div id="icon"> then $("#icon").html('<img src='+icon+'/>');
Alexander Køpke
@alexanderkopke
Jul 19 2017 15:28
src needs quotes though
Daniel Kang
@a1mighty
Jul 19 2017 15:29
not if it's a variable
Bradley Sands
@sandsbe
Jul 19 2017 15:29
It requires the "extra" step of the src though, whether jQuery or JS...?
Alexander Køpke
@alexanderkopke
Jul 19 2017 15:29
ok
Bradley Sands
@sandsbe
Jul 19 2017 15:29
It wouldn't work for me otherwise
Daniel Kang
@a1mighty
Jul 19 2017 15:30
he already wrote the Jquery code but incorrect syntax
I just fixed it for it
Christopher McCormack
@cmccormack
Jul 19 2017 15:32
:wave: good morning
Bradley Sands
@sandsbe
Jul 19 2017 15:34
How do you do icons?
Christopher McCormack
@cmccormack
Jul 19 2017 15:38
@sandsbe in what context? Create an icon, use an icon, reference an icon library...?
Christian
@Neralizer
Jul 19 2017 15:45
that's what I'm trying to do @a1mighty , I think I like that solution a bit better since that's how I'm doing it for the rest of my project
dang that's not it
$("icon").html("img src =https://cdn1.iconfinder.com/data/icons/hawcons/32/698868-icon-132-cloud-128.png"));
Sweet Coding :)
@SweetCodingInc
Jul 19 2017 15:47
@Neralizer it should be an html tag
$("icon").html('<img src="https://cdn1.iconfinder.com/data/icons/hawcons/32/698868-icon-132-cloud-128.png">');
Christian
@Neralizer
Jul 19 2017 15:49
getting closer, but still no icon
Bradley Sands
@sandsbe
Jul 19 2017 15:49
@cmccormack How'd you do the wave icon in the chat?
Christian
@Neralizer
Jul 19 2017 15:49
Sweet Coding :)
@SweetCodingInc
Jul 19 2017 15:49
I guess you also need $('#icon') instead of $("icon")
@Neralizer
Christian
@Neralizer
Jul 19 2017 15:49
gosh I always do that! okay so now the link is showing up instead of the image
Sweet Coding :)
@SweetCodingInc
Jul 19 2017 15:50
$("#icon").html('<img src="https://cdn1.iconfinder.com/data/icons/hawcons/32/698868-icon-132-cloud-128.png">');
is the right line
Christopher McCormack
@cmccormack
Jul 19 2017 15:50
@sandsbe :wave:
Sweet Coding :)
@SweetCodingInc
Jul 19 2017 15:50
you misplaced " in your code
Bradley Sands
@sandsbe
Jul 19 2017 15:51
Thats great
Is there a list of options somewhere?
Christian
@Neralizer
Jul 19 2017 15:51
there it is, thanks @SweetCodingInc
CamperBot
@camperbot
Jul 19 2017 15:51
neralizer sends brownie points to @sweetcodinginc :sparkles: :thumbsup: :sparkles:
:cookie: 132 | @sweetcodinginc |http://www.freecodecamp.com/sweetcodinginc
Christian
@Neralizer
Jul 19 2017 15:51
and ty @sandsbe
thanks @sandsbe
CamperBot
@camperbot
Jul 19 2017 15:51
neralizer sends brownie points to @sandsbe :sparkles: :thumbsup: :sparkles:
:cookie: 310 | @sandsbe |http://www.freecodecamp.com/sandsbe
Bradley Sands
@sandsbe
Jul 19 2017 15:52
Gotta get them brownie points
Christopher McCormack
@cmccormack
Jul 19 2017 15:52
@sandsbe no clue, I just try to type them hoping one exists that fills the current need :smile:
Bradley Sands
@sandsbe
Jul 19 2017 15:53
:coffee:
Christopher McCormack
@cmccormack
Jul 19 2017 15:53
haha exactly
Bradley Sands
@sandsbe
Jul 19 2017 15:53
:fu: <- not directed at anyone, just testing
Sweet Coding :)
@SweetCodingInc
Jul 19 2017 15:54
:fu:
Bradley Sands
@sandsbe
Jul 19 2017 15:54
I could do this all day :grey_exclamation:
Sweet Coding :)
@SweetCodingInc
Jul 19 2017 15:54
awww
Abhinav Mishra
@abhinav-m
Jul 19 2017 15:54
// This example is explained in detail below (just after this code box).​function celebrityIDCreator (theCelebrities) {
    var i;
    var uniqueID = 100;
    for (i = 0; i < theCelebrities.length; i++) {
      theCelebrities[i]["id"] = function ()  {
        return uniqueID + i;
      }
    }

    return theCelebrities;
}
​
​var actionCelebs = [{name:"Stallone", id:0}, {name:"Cruise", id:0}, {name:"Willis", id:0}];
​
​var createIdForActionCelebs = celebrityIDCreator (actionCelebs);
​
​var stalloneID = createIdForActionCelebs [0];

console.log(stalloneID.id()); // 103
Can anyone explain why the id of all celebrities are initialised as 103
the inner function's loop executes first or something?
yes , im aware of that..
It's an example on closure
Christian
@Neralizer
Jul 19 2017 15:57
awesome, it looks good now
Sweet Coding :)
@SweetCodingInc
Jul 19 2017 15:57

@abhinav-thinktank try doing

for (let i = 0; ...

instead of

for (i = 0;

;)

Christopher McCormack
@cmccormack
Jul 19 2017 15:58
@abhinav-thinktank here are some different examples of scoping issues that you can resolve in a few ways. One is to use let as @SweetCodingInc suggested. https://codepen.io/cmccormack/pen/VWwQGm
Abhinav Mishra
@abhinav-m
Jul 19 2017 15:58
@cmccormack im not looking to solve scoping issues..
Christopher McCormack
@cmccormack
Jul 19 2017 15:58
ah but you are
the way i is bound to the outer function will cause you to get the same value for all celebrities
that's one of the reasons closures are used in loops like that
Sweet Coding :)
@SweetCodingInc
Jul 19 2017 16:00

@abhinav-thinktank : the reason for that is, you call celebrityIDCreator and it runs a loop. and assigns id as a function to each celebrity.

So when you call .id() in celebrity it will execute

function ()  {
  return uniqueID + i;
}

And since this is a closure, the values of it's parent scope will be retained. This function is called in future, by which time, the value of i has become 3. So it will give you 100 (uniqueID) + 3 (i)

Abhinav Mishra
@abhinav-m
Jul 19 2017 16:00
I understand,
It gets bounded to the updated value of i ie, 3
function celebrityIDCreator (theCelebrities) {
    var i;
    var uniqueID = 100;
    for (i = 0; i < theCelebrities.length; i++) {
        theCelebrities[i]["id"] = function (j)  { // the j parametric variable is the i passed in on invocation of this IIFE​
            return function () {
                return uniqueID + j; // each iteration of the for loop passes the current value of i into this IIFE and it saves the correct value to the array​
            } () // BY adding () at the end of this function, we are executing it immediately and returning just the value of uniqueID + j, instead of returning a function.​
        } (i); // immediately invoke the function passing the i variable as a parameter​
    }
​
    return theCelebrities;
}
​
​var actionCelebs = [{name:"Stallone", id:0}, {name:"Cruise", id:0}, {name:"Willis", id:0}];
​
​var createIdForActionCelebs = celebrityIDCreator (actionCelebs);
​
​var stalloneID = createIdForActionCelebs [0];

console.log(stalloneID.id); // 100​
​
​var cruiseID = createIdForActionCelebs [1];
console.log(cruiseID.id); // 101
The next part of the example does this
which i can't understand
Christopher McCormack
@cmccormack
Jul 19 2017 16:03
@abhinav-thinktank i is being passed as an argument to your outer function each iteration of the loop, and assigned to j. j is now a unique number that won't change when i updates during the next loop iteration
Ronique Ricketts
@RoniqueRicketts
Jul 19 2017 16:03
This message was deleted
Christopher McCormack
@cmccormack
Jul 19 2017 16:03
it may be better to read those comments from the bottom up, @abhinav-thinktank, or at least 4,3, 1, 2
Sweet Coding :)
@SweetCodingInc
Jul 19 2017 16:05
function celebrityIDCreator (theCelebrities) {
    var i;
    var uniqueID = 100;
    for (i = 0; i < theCelebrities.length; i++) {
      theCelebrities[i]["id"] = (function(n){
        return function ()  {
          return uniqueID + n;
        }
      })(i);
    }

    return theCelebrities;
}
@abhinav-thinktank
Oh! Right.. You already posted something similar
So what happens here is you assign an IIFE (Immediately invoked function expression) to the id property
and you pass in i to it. which becomes j inside the IIFE closuse
and since this expression executes, it returns
function ()  {
  return uniqueID + j;
}
which then gets assigned to id property
and since it is returned from the closure, when j is coming from the parent scope, it will be retained inside that function.
Abhinav Mishra
@abhinav-m
Jul 19 2017 16:08
@cmccormack @SweetCodingInc so in this case, each value is bound immediately when the loop executes, and in the previous case, it occurs on the call of ​var createIdForActionCelebs = celebrityIDCreator (actionCelebs);
which leads to the current value of i being referenced, which is 3
Sweet Coding :)
@SweetCodingInc
Jul 19 2017 16:08
@abhinav-thinktank yes
Abhinav Mishra
@abhinav-m
Jul 19 2017 16:08
@cmccormack do you concur
Christopher McCormack
@cmccormack
Jul 19 2017 16:09
Pretty much
Abhinav Mishra
@abhinav-m
Jul 19 2017 16:09
ok ok i get it now
aah quite clear
ok thanks @cmccormack @SweetCodingInc !
CamperBot
@camperbot
Jul 19 2017 16:10
abhinav-thinktank sends brownie points to @cmccormack and @sweetcodinginc :sparkles: :thumbsup: :sparkles:
:cookie: 133 | @sweetcodinginc |http://www.freecodecamp.com/sweetcodinginc
:star2: 1043 | @cmccormack |http://www.freecodecamp.com/cmccormack
Abhinav Mishra
@abhinav-m
Jul 19 2017 16:10
are IIFE's common?
Christopher McCormack
@cmccormack
Jul 19 2017 16:10
I still have to use my own codepen example occasionally just to make sure I'm doing it right :D
@abhinav-thinktank not as much when using let keyword or a closure outside your loop
Abhinav Mishra
@abhinav-m
Jul 19 2017 16:11
yes, i read about let and var earlier, prepping for an interview
any other topic comes to mind which i should go through?
Ronique Ricketts
@RoniqueRicketts
Jul 19 2017 16:12
Hello @everyone I am a bit confused on a section in OOP. If i have a Class Me and I am building another Class of Self that inherits some details from Me and I use the call() on Me to pass the prototype to self, If I do not pass all the parameters in Me to self will that break the inheritance? eg
function Me(){
this.name ={
first,
last
}
this.age = age;
this.gender = gender;
}
function Self(first, last, age, height){
Me.call(this, last,  age)
this.height =height;
}
Lay
@L-AY
Jul 19 2017 16:13

Hi,

I know I am making a silly mistake here somewhere regarding the updating of each letter at index 0 to a capital. Would you somebody please mind just looking over my code to provide some feedback please?


function titleCase(str) {

  var spStr = str.toLowerCase().split(' ');

  for (var i = 0; i < spStr.length; i++){
    spStr[i].charAt(0).toUpperCase();
  }

  return spStr;

}

titleCase("I'm a little tea pot");
Abhinav Mishra
@abhinav-m
Jul 19 2017 16:14
@L-AY are you forgetting to convert it back
@L-AY :)
Sweet Coding :)
@SweetCodingInc
Jul 19 2017 16:14
@L-AY Strings are immutable. So you can't change string in place
Christopher McCormack
@cmccormack
Jul 19 2017 16:14
@L-AY you have to assign your uppercase to a new variable, you can't modify strings in place as they are immutable
Sweet Coding :)
@SweetCodingInc
Jul 19 2017 16:14
you can, however, reassign string with a new value
so spStr[i].charAt(0).toUpperCase(); will return you uppercased letter, but you won't change your spStr
Abhinav Mishra
@abhinav-m
Jul 19 2017 16:15
Also, it won't actually solve this problem..
Sweet Coding :)
@SweetCodingInc
Jul 19 2017 16:16
so you have have to catch result of spStr[i].charAt(0).toUpperCase(); in a temporary variable, then then, create a new string by concatenating rest of the string to this temporary variable.
Lay
@L-AY
Jul 19 2017 16:17
@SweetCodingInc @abhinav-thinktank Thanks, I will implement and let you know!
CamperBot
@camperbot
Jul 19 2017 16:17
l-ay sends brownie points to @sweetcodinginc and @abhinav-thinktank :sparkles: :thumbsup: :sparkles:
:cookie: 407 | @abhinav-thinktank |http://www.freecodecamp.com/abhinav-thinktank
:cookie: 134 | @sweetcodinginc |http://www.freecodecamp.com/sweetcodinginc
Christopher McCormack
@cmccormack
Jul 19 2017 16:17
@RoniqueRicketts what exercise are you referencing?
Sweet Coding :)
@SweetCodingInc
Jul 19 2017 16:19
@RoniqueRicketts The way you're doing it will inherit properties of Self into Me but not the other way around
Ronique Ricketts
@RoniqueRicketts
Jul 19 2017 16:20
@cmccormack I am just learning more about OOP, extensive learning, I am told that I have to understand OOP in order to Dive into ReactJS
Christopher McCormack
@cmccormack
Jul 19 2017 16:25
@RoniqueRicketts I'm not sure any of the code you have above will work as you expect
you don't have several of the variables as function parameters so you're going to get errors
JLuis Avalos
@avalos010
Jul 19 2017 16:27
Wassup guys.. anyone got any tips for getting better at algorithms
Christopher McCormack
@cmccormack
Jul 19 2017 16:28
@avalos010 keep doing them :)
Ronique Ricketts
@RoniqueRicketts
Jul 19 2017 16:28
@SweetCodingInc ok I am confused. MDN is teaching something else.
Christopher McCormack
@cmccormack
Jul 19 2017 16:28
break them apart into small pieces and try to tackle them one by one, and use other algorithms you have learned to help solve more difficult challenges
@RoniqueRicketts link the MDN article
odm275
@odm275
Jul 19 2017 16:29
for the tictactoe project. Do i have to state every possible situation where the player is about to win so the computer blocks?
or is there some adaptive way to make the computer realize that without writting like 30 lines of conditions
Christopher McCormack
@cmccormack
Jul 19 2017 16:29
@odm275 Google the minimax algorithm
odm275
@odm275
Jul 19 2017 16:30
@cmccormack I'll check this out
Christopher McCormack
@cmccormack
Jul 19 2017 16:30
it's a brute force but easy to implement algorithm that assigns a point value for moves based on how effective they may be
may not be less than 30 lines though :D
odm275
@odm275
Jul 19 2017 16:33
@cmccormack that sounds way better, im going crazy over here lol
@cmccormack thanks
CamperBot
@camperbot
Jul 19 2017 16:33
odm275 sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1044 | @cmccormack |http://www.freecodecamp.com/cmccormack
Javi Ferré
@CurrentDate
Jul 19 2017 16:33
why /^( ((\d{3})\s)(\d{3})(-)(\d{4})$/g is not working with this string (555) 555-5555 ?
Christopher McCormack
@cmccormack
Jul 19 2017 16:36
@CurrentDate use code tags ` code `
Saikat-Sinha
@Saikat-Sinha
Jul 19 2017 16:36
can anyone help me debug http://juniordev.me/Maps_Route/
after adding locations, clicking on the 'tick ' button does not work on the first time,
but works on 2nd click.
code here: https://github.com/Saikat-Sinha/Maps_Route
It is due to AJAX request, but not able to solve
Javi Ferré
@CurrentDate
Jul 19 2017 16:37
@CurrentDate use code tags ` code `My apologies!
Christopher McCormack
@cmccormack
Jul 19 2017 16:39
@CurrentDate use code tags or we won't know if what you pasted is 100% accurate, some symbols may convert to markdown
Ronique Ricketts
@RoniqueRicketts
Jul 19 2017 16:40
@cmccormack here is the article https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Inheritance Header Defining a Teacher() constructor function
Javi Ferré
@CurrentDate
Jul 19 2017 16:43
@cmccormack /^( ((\d{3})\s)(\d{3})(-)(\d{4})$/g
Jason Luboff
@JLuboff
Jul 19 2017 16:44
@odm275 just create an array of winning combo of moves. It's only 8 or 9 combos if I remember correctly
Christopher McCormack
@cmccormack
Jul 19 2017 16:45
@Saikat-Sinha directionsDisplay.setMap(map); should probably be above your ajax call right?
@Saikat-Sinha it's tough to debug this from a static site though, sorry
odm275
@odm275
Jul 19 2017 16:47
@JLuboff i did that to check when someone won. My goal right now is to program the computer interface that responds to the player's moves
Christopher McCormack
@cmccormack
Jul 19 2017 16:47
@CurrentDate I believe you need to escape your parenthesis else they will be used as a capture group
Ronique Ricketts
@RoniqueRicketts
Jul 19 2017 16:48
@SweetCodingInc so what I want to know is if I drop off a property inside the Self() would it still inherit from Me() all the properties.
Javi Ferré
@CurrentDate
Jul 19 2017 16:50
@cmccormack this (\(\d{3}\)\s)(\d{3})(\-)(\d{4}) works for (555) 555-5555 but also works for 2 (757) 622-7382, when I try to add ^ and $ fails for both
Christopher McCormack
@cmccormack
Jul 19 2017 16:51
@CurrentDate what's the full regex with the ^$ symbols included?
Sweet Coding :)
@SweetCodingInc
Jul 19 2017 16:51
@RoniqueRicketts do you have working example
?