These are chat archives for FreeCodeCamp/HelpJavaScript

8th
Jul 2017
Ednor
@ednor
Jul 08 2017 00:00
ok, let me try with your explanations
I will get back to you
Janice He
@Janicekwing
Jul 08 2017 00:07
question... in the middle statement of a for loop, can you update it ?
for example
I currently have for (i = 0; i < newStr.length; i++)
but later in my code I use newStr.pop() and newStr.shift()...so I was wondering, if each time I loop the newStr.length also gets updated?
Joseph
@revisualize
Jul 08 2017 00:08
@Janicekwing didja solve your challenge?
Mike Saalwaechter
@dmsdesignz
Jul 08 2017 00:09
can anyone give me a hand, my icons are not showing...
Janice He
@Janicekwing
Jul 08 2017 00:09
well I resolved that issue earlier but I'm still working on the same challenge lol..
Joseph
@revisualize
Jul 08 2017 00:09
@Janicekwing ok
Janice He
@Janicekwing
Jul 08 2017 00:09
This is what I have
Joseph
@revisualize
Jul 08 2017 00:09
@Janicekwing Do you want to pair up on it?
Janice He
@Janicekwing
Jul 08 2017 00:09
Oh
How do you do it..?
do that*
Joseph
@revisualize
Jul 08 2017 00:10
@Janicekwing let me get a link
@Janicekwing can i send you a PM?
Janice He
@Janicekwing
Jul 08 2017 00:11
just did!
John
@AnonymousLords
Jul 08 2017 00:18
Guys, what does nesting arrays inside of each other do?
Does it help?
var myArray = [["Hello", 420], ["why", 69.1]];
Also how do i target one part of the array?
CallMeOrange
@EgnaroDev
Jul 08 2017 00:20
if you want to get "Hello" then write it like this myArray[0][0] myArray[which element?][which item?
]
John
@AnonymousLords
Jul 08 2017 00:22
Would that get hello and why>?
Stephen James
@sjames1958gm
Jul 08 2017 00:22
@John-freeCodeCamp myArray[0] gets you ["Hello", 420] then another [0] gets you the first value in that array "Hello"
CallMeOrange
@EgnaroDev
Jul 08 2017 00:22
Because first 0 select first element then second 0 pick "Hello" from that element
John
@AnonymousLords
Jul 08 2017 00:23
now how would i get why?
"why"
CallMeOrange
@EgnaroDev
Jul 08 2017 00:24
myArray[1][1]
John
@AnonymousLords
Jul 08 2017 00:24
Why not myArray[1][0]
CallMeOrange
@EgnaroDev
Jul 08 2017 00:24
@John-freeCodeCamp Oh sorry you are correctly
[1][1] will get 69.1
Array[which element do you want to select?][which value from this element?]
John
@AnonymousLords
Jul 08 2017 00:25
danke @MCTwoDigitZero @sjames1958gm
CamperBot
@camperbot
Jul 08 2017 00:25
john-freecodecamp sends brownie points to @mctwodigitzero and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: john-freecodecamp already gave mctwodigitzero points
:star2: 8010 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Manish Giri
@Manish-Giri
Jul 08 2017 00:26
hey
congats on 8K! @sjames1958gm
Stephen James
@sjames1958gm
Jul 08 2017 00:27
@Manish-Giri thanks
CamperBot
@camperbot
Jul 08 2017 00:27
sjames1958gm sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6210 | @manish-giri |http://www.freecodecamp.com/manish-giri
CallMeOrange
@EgnaroDev
Jul 08 2017 00:27
@sjames1958gm Your profile picture is sad...
Mike Saalwaechter
@dmsdesignz
Jul 08 2017 00:27
@dmsdesignz
can anyone give me a hand, my icons are not showing...
https://codepen.io/twistedkaos/pen/vZzNVg
please!
John
@AnonymousLords
Jul 08 2017 00:29
Did you open the image in a new tab?
"Open image in new tab"
Right click over icon/ image
it should have a .png or something at teh end of teh url
Use that url
@dmsdesignz did it work?
Gulsvi
@gulsvi
Jul 08 2017 00:43
@dmsdesignz You need to use .add() to get the skycon added. For example, add this after you .append() in your $.each loop:
icons.add(document.getElementById(icon), icon)
The problem is, you need a unique icon for each day, so you need unique IDs.
Anyway, the syntax is: .add(canvas-element, weather-condition-from-dark-sky)
CallMeOrange
@EgnaroDev
Jul 08 2017 00:47
@SkyC0der Hey
Can you take a look at my search result? Link works but google only first name of character
Joseph
@revisualize
Jul 08 2017 00:50
is the darksky api free?
Mike Saalwaechter
@dmsdesignz
Jul 08 2017 00:50
yes
CallMeOrange
@EgnaroDev
Jul 08 2017 00:51
Yea, you can just sign up for a key
No cost
Joseph
@revisualize
Jul 08 2017 00:51
I should do that
Mike Saalwaechter
@dmsdesignz
Jul 08 2017 00:51
well I need to convert it to classes then...
its been really cool, learning lots!
ok I got this!
CallMeOrange
@EgnaroDev
Jul 08 2017 01:10
@sjames1958gm you on?
Mike Saalwaechter
@dmsdesignz
Jul 08 2017 01:14
@SkyC0der does their script require you use the id's? do you know?
Gulsvi
@gulsvi
Jul 08 2017 01:20
@dmsdesignz It doesn't require you to use the IDs, but you do need to provide a selector of some sort - (document.getElementsByClassName('icon')[0]) for example
@MCTwoDigitZero Sorry, stepped away
CallMeOrange
@EgnaroDev
Jul 08 2017 01:22
Its ok, was working on weather app
@SkyC0der for darksky api, I need a key right?
What happen if someone take look at my key in the code?
Normally you want to avoid exposing API keys on CodePen
2895388807
@2895388807
Jul 08 2017 01:24

var count = 0;
function cc(card) {
switch(card){
case 2:
case 3:
case 4:
case 5:
case 6:
count += 1;
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count -= 1;
break;
}

if(count>0){
card=" Bet";
}else if(count<=0){
card=" Hold";
} // If it possible use switch to achieve this like above????

return count + card;
}
cc(2); cc(3); cc(4); cc(5); cc(6);

If it possible use switch to achieve this like above????
Mike Saalwaechter
@dmsdesignz
Jul 08 2017 01:26
@MCTwoDigitZero I used a proxy from github, its just a URL you append to the url
CallMeOrange
@EgnaroDev
Jul 08 2017 01:27
You mean to use that url instead of key?
Im going to use a key anyway.. dont know what happen if it got exposed
@SkyC0der check it out again please
https://codepen.io/twistedkaos/pen/WOgBZQ?editors=1010
I converted it to classes, but its still not working...
Mike Saalwaechter
@dmsdesignz
Jul 08 2017 01:35
that proxie is very cool, I just fixed the HTTPS error i was getting for the background image!
CallMeOrange
@EgnaroDev
Jul 08 2017 01:36
Im going to use a key
Nick Janne
@njanne19
Jul 08 2017 01:36
Is it possible to set the state of every component in my array of JSX elements at the same time?
For instance is it possible to loop through every element and do this.setState()
Marcus Parsons
@marcusparsons
Jul 08 2017 01:39
@njanne19, do you have a codepen set up for what you're trying to accomplish?
I've been working on this for a couple of hours. I have the cells clickable, but I wanna make it so I can change the active property in every cell's state to off if I hit the clear button
Eric Hasegawa
@EricHasegawa
Jul 08 2017 01:43
function countTo(int) {

for (var i = 1; i < int + 1; i++) {
    console.log(i);
}

}
Could someone tell me why this function doesn't work? I'm not sure what I'm missing, it's just supposed to log integers to the console, starting with 1 and going until int
Nick Janne
@njanne19
Jul 08 2017 01:44
@EricHasegawa is it running and just not producing the results you want?
Eric Hasegawa
@EricHasegawa
Jul 08 2017 01:44
@njanne19 The site I'm on just tells me it's wrong, I'm not seeing results displayed
Nick Janne
@njanne19
Jul 08 2017 01:46
@EricHasegawa I think if you just changed your loop to this:
```
function countTo(int) {
Pardon
Eric Hasegawa
@EricHasegawa
Jul 08 2017 01:46
@njanne19 Oh shoot I'm sorry, it just wanted me to call the function myself and I didn't do that
Thanks anyways!
Nick Janne
@njanne19
Jul 08 2017 01:46
Ahh I see
Eric Hasegawa
@EricHasegawa
Jul 08 2017 01:46
@njanne19 Thanks!
CamperBot
@camperbot
Jul 08 2017 01:46
erichasegawa sends brownie points to @njanne19 :sparkles: :thumbsup: :sparkles:
:cookie: 326 | @njanne19 |http://www.freecodecamp.com/njanne19
Eric Hasegawa
@EricHasegawa
Jul 08 2017 01:46
Sorry just sent twice to give you the points
Nick Janne
@njanne19
Jul 08 2017 01:47
Thank you, no problem
fdemaa
@fdemaa
Jul 08 2017 01:48
anyone know what this mean on codepen ?
Log Skipped: Sorry, this log was too large for our console. You might need to use the browser console instead.
Nick Janne
@njanne19
Jul 08 2017 01:49
@fdemaa It means your log is too big to fit inside the small codepen console. If you want to see what your log says, hit "Change View" then hit debug mode, then open the chrome console on your debug mode page
fdemaa
@fdemaa
Jul 08 2017 01:50
@njanne19 thanks !
CamperBot
@camperbot
Jul 08 2017 01:50
fdemaa sends brownie points to @njanne19 :sparkles: :thumbsup: :sparkles:
:cookie: 327 | @njanne19 |http://www.freecodecamp.com/njanne19
Nick Janne
@njanne19
Jul 08 2017 02:07
I
I'm so stuck on this stupid game of life
CallMeOrange
@EgnaroDev
Jul 08 2017 02:11
@njanne19 Do you know whats wrong with this?
$(document).ready(function() {
  if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(function(position){ 
    });
}
CallMeOrange
@EgnaroDev
Jul 08 2017 02:17
Never mind
Yuserah Din
@YuserahN
Jul 08 2017 02:17
Hey, I just finished my Random Quote Machine. Can someone check it out to see if it's working properly? (The tweeting portion of it was working properly 2 seconds ago. I must have clicked on something because now it's not.)
https://codepen.io/Yuserah/pen/pwZgZy
Marcus Parsons
@marcusparsons
Jul 08 2017 02:17
Okay @njanne19, this has been my first foray into React this night, but I fixed your problem for you. What I did was loop through the available cells, make sure that they have a state property, and if they do, check to see if they're active. If they are active, call "cell.activate()" which will toggle them to be off. This will clear all of the cells that are currently active.
CallMeOrange
@EgnaroDev
Jul 08 2017 02:20
@YuserahN Twitter works but nothing is in text box
Yuserah Din
@YuserahN
Jul 08 2017 02:21
@MCTwoDigitZero Can you tell me why? It was displaying it properly in the Twitter text box but I think I accidentally changed something because now it's not. Is there anyway codepen let's you see the changes you made?
CallMeOrange
@EgnaroDev
Jul 08 2017 02:21
Lemme check
Marcus Parsons
@marcusparsons
Jul 08 2017 02:22
@YuserahN, you have too many spaces in your URL. You need to put text right beside the ? in the URL like so
https://twitter.com/intent/tweet?text=
Also, you should set a default quote so that you can immediately click Tweet This. Otherwise, an error occurs
Yuserah Din
@YuserahN
Jul 08 2017 02:23
@marcusparsons Oh it's working now. Thanks.
CamperBot
@camperbot
Jul 08 2017 02:23
yuserahn sends brownie points to @marcusparsons :sparkles: :thumbsup: :sparkles:
:cookie: 428 | @marcusparsons |http://www.freecodecamp.com/marcusparsons
Mike Saalwaechter
@dmsdesignz
Jul 08 2017 02:23
I'd like my first quote to be displayed on page load, without clicking the button, how can I do this?
https://codepen.io/twistedkaos/pen/ZyjZKG
Marcus Parsons
@marcusparsons
Jul 08 2017 02:24
Also consider using encodeURIComponent() with strings being sent in a GET request (like what you're doing with Twitter) and not relying upon the browser to encode them.
 document.getElementById("tweetQuote").setAttribute("href", "https://twitter.com/intent/tweet?text=" + encodeURIComponent(randQuote));
Mike Saalwaechter
@dmsdesignz
Jul 08 2017 02:24
oh just set a default, I'd like it to be random...
Marcus Parsons
@marcusparsons
Jul 08 2017 02:25
Set the default to be a random quote lol
Mike Saalwaechter
@dmsdesignz
Jul 08 2017 02:25
lol k
Marcus Parsons
@marcusparsons
Jul 08 2017 02:25
This is basic UI stuff man. You want your stuff to work out of the box
Mike Saalwaechter
@dmsdesignz
Jul 08 2017 02:26
of course!
:)
Marcus Parsons
@marcusparsons
Jul 08 2017 02:26
@dmsdesignz but your profile pic is awesome man!
CallMeOrange
@EgnaroDev
Jul 08 2017 02:27
Where can I find an API that will give me my location? not latitude/longitude, like City, region..
Marcus Parsons
@marcusparsons
Jul 08 2017 02:27
@MCTwoDigitZero, if you feed Google Maps a latitude and latitude, it will deliver information like that
Nick Janne
@njanne19
Jul 08 2017 02:28
@marcusparsons That's awesome thank you]
CamperBot
@camperbot
Jul 08 2017 02:28
njanne19 sends brownie points to @marcusparsons :sparkles: :thumbsup: :sparkles:
:cookie: 429 | @marcusparsons |http://www.freecodecamp.com/marcusparsons
Marcus Parsons
@marcusparsons
Jul 08 2017 02:28
CallMeOrange
@EgnaroDev
Jul 08 2017 02:28
@marcusparsons well Im working on my weather app
hm...
Marcus Parsons
@marcusparsons
Jul 08 2017 02:29
@njanne19, you're very welcome! It was pretty cool figuring this out because I've literally never worked with React before your codepen haha I had to decipher what was going on before I could do anything which is why it took a little bit to come up with a solution haha
Yang Lu
@Luyang2016
Jul 08 2017 02:42
function myReplace(str, before, after) {
var strArr=str.split(" ");
var afterArr=after.split("");
  for(var i=0;i<strArr.length;i++){
    if(strArr[i]==before){
      if(strArr[i].toLowerCase()!=strArr[i]){
      var sliced=afterArr.slice(0).join("");
      var convertedAfter=afterArr[0].toUpperCase+spliced;
      strArr[i]=convertedAfter;
        return strArr.join("");
      }
      else{
        strArr[i]=after;
        return strArr.join;
      }

    }

  }

}

myReplace("A quick brown fox jumped over the lazy dog", "jumped", "leaped");
This is Search and Replace in Intermediate Algorithm Scripting, my code can't pass. In fact, it keeps saying "testing challenge..." and there's no response to my code.
Mike Saalwaechter
@dmsdesignz
Jul 08 2017 02:48
@marcusparsons thanks man, simple photoshop stuff!
CamperBot
@camperbot
Jul 08 2017 02:48
dmsdesignz sends brownie points to @marcusparsons :sparkles: :thumbsup: :sparkles:
:cookie: 431 | @marcusparsons |http://www.freecodecamp.com/marcusparsons
Marcus Parsons
@marcusparsons
Jul 08 2017 02:49
@dmsdesignz, I am a n00b at photoshop man! But I think it still rocks anyways! haha
@Luyang2016, which challenge is this? Can you link it please?
abraham anak agung
@padunk
Jul 08 2017 02:50
@Luyang2016 you need to return join(" ")
fdemaa
@fdemaa
Jul 08 2017 02:55
is this wrong ? i jus want to create and append a h1 lol
var parentt = document.getElementsByTagName("div")[0]; 
var referenceChild = document.getElementsByTagName("p")[0]; 
var newElement = document.createElement("h1"); 
var creationOfText = document.createTextNode("Hello World"); 
var result = parentt.insertBefore(newElement, referenceChild);
Nick Janne
@njanne19
Jul 08 2017 03:03
    this.props.cells[this.props.id] = this;
    $(events).on("calcNextMove", this.calcNextMove());
    $(events).on("makeNextMove", this.makeNextMove());
I'm trying to get this.props.cells[this.props.id] to equal the current Component that I am in. Am I doing it correctly or no?
Eric Hasegawa
@EricHasegawa
Jul 08 2017 03:25
function guessNumber(number) {
  // Prompt the user for a number
 var guess = prompt("Guess a number between 1 and 100");

  // Convert their guess to a number using +
  guess = +guess;

  // Define base case
  if (isNaN(guess) === true) {
    return console.log("You got it! The number was " + number);
  }
  // Define recursive case with a function call
  guessNumber(number);
}

// Call the function guessNumber() with an integer for an argument

guessNumber(7);
Can anyone tell me why the prompt just keeps popping up? It doesn't go away
Nick Janne
@njanne19
Jul 08 2017 03:25
@EricHasegawa well for starters you shouldn't be doing return console.log
that's a no no
Second of all, because you're not returning a value (because you have a bad return statement) the recursion continues to happen
Eric Hasegawa
@EricHasegawa
Jul 08 2017 03:29
@njanne19 Okay thanks
CamperBot
@camperbot
Jul 08 2017 03:29
erichasegawa sends brownie points to @njanne19 :sparkles: :thumbsup: :sparkles:
:cookie: 328 | @njanne19 |http://www.freecodecamp.com/njanne19
Eric Hasegawa
@EricHasegawa
Jul 08 2017 03:29
I'm trying to teach myself recursion using Codecademy and it's really rough, they said I had to use return console.log to pass one of the tests
Now my program is passing but it says it's wrong, when earlier it said it was wrong but it progressed me
Nick Janne
@njanne19
Jul 08 2017 03:30
@EricHasegawa that's odd, That's not a common practice
Marcus Parsons
@marcusparsons
Jul 08 2017 03:32
And it doesn't make any sense because console.log is not a command that returns any type of value, object, etc. For example, you can do this and it does nothing because b is undefined:
function a() { 
return console.log('hi'); 
}
var b = a();
console.log(b);
Gulsvi
@gulsvi
Jul 08 2017 04:05
@dmsdesignz You're going to have to loop through the <canvas> elements you create and add the icons to them individually. This is kind of the idea (but not the exact fix):
      $.each($('canvas'), function(i, canvas) {
        icons.add(canvas, $(canvas).attr('class'));
      });
CallMeOrange
@EgnaroDev
Jul 08 2017 04:05
@SkyC0der :wave:
Gulsvi
@gulsvi
Jul 08 2017 04:05
Hey @MCTwoDigitZero
CallMeOrange
@EgnaroDev
Jul 08 2017 04:06
So to set background-image like this $("body").css("background-image", url(""));
@SkyC0der
Gulsvi
@gulsvi
Jul 08 2017 04:07
yes
Try it: $("body").css("background-image", 'url("https://placehold.it/600")');
CallMeOrange
@EgnaroDev
Jul 08 2017 04:09
@SkyC0der I see, thanks
CamperBot
@camperbot
Jul 08 2017 04:09
mctwodigitzero sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:star2: 2010 | @skyc0der |http://www.freecodecamp.com/skyc0der
CallMeOrange
@EgnaroDev
Jul 08 2017 04:09
Didnt know I need a quote around url()
Gulsvi
@gulsvi
Jul 08 2017 04:09
yeah, otherwise it's a variable
You can add all the CSS you want in curly braces like:
$("body").css({
  "background-image": 'url("https://placehold.it/600")',
  "background-position": "center center",
  "background-size": "cover",
  "min-height": "100vh"
});
CallMeOrange
@EgnaroDev
Jul 08 2017 04:11
Hm...
why center center?
Good, this works with if statement
Gulsvi
@gulsvi
Jul 08 2017 04:12
center horizontally and vertically
maybe redundant, I think if you only mention one value, the other will always be center
shivam gupta
@shivamg11000
Jul 08 2017 04:18
how can I extract all the images from the site https://www.templatemonster.com/demo/63629.html
M-C-Haker
@M-C-Haker
Jul 08 2017 04:21
i need some suggestions for the mutations challenge: function mutation(arr) { var lcArr = arr.toString().toLowerCase().split(","); return lcArr[0].indexOf(lcArr[1]) !== -1; } mutation(["hello", "Hello"]);
is what i have so far. I am able to get everything right except for the challenges where the letters are in a different order and on those i am completely lost
i can't really think on anything we've touched on that relates on how to solve that
Joseph
@revisualize
Jul 08 2017 04:23
@M-C-Haker you don't have a loop?
M-C-Haker
@M-C-Haker
Jul 08 2017 04:23
@revisualize i guess that answer my question. i'll let "i" do the heavying lifting then
Joseph
@revisualize
Jul 08 2017 04:24
@M-C-Haker You need to check each character. not the whole string.
M-C-Haker
@M-C-Haker
Jul 08 2017 04:25
@revisualize yeah, i was kind of thinking something along those lines since the ones with the characters in different orders wer the ones i wasn't getting. i'll give it shot now
CallMeOrange
@EgnaroDev
Jul 08 2017 04:31
@SkyC0der hey, is it possible to use two API? would I have to use two $.getJSON? If I had darksky api there is no location like name, region
Gulsvi
@gulsvi
Jul 08 2017 04:32
@MCTwoDigitZero Yes, you can use as many APIs as you want. You just have to make sure that the data comes back in the order you need
CallMeOrange
@EgnaroDev
Jul 08 2017 04:32
I see
@SkyC0der How did you get location with darksky api?
Gulsvi
@gulsvi
Jul 08 2017 04:33
I used google maps API to get the city name
CallMeOrange
@EgnaroDev
Jul 08 2017 04:42
Hm..
Im using different API but they does have location like name,region but icon... not bad
Actually I have an idea
Jeremy
@JeremyAntonoff
Jul 08 2017 04:45
can anyone help me with calculator project
CallMeOrange
@EgnaroDev
Jul 08 2017 04:48
@SkyC0der Sorry since freeCodeCamp said
Jeremy
@JeremyAntonoff
Jul 08 2017 04:48
need a more efficient way of triggering event listeners and removeevents
CallMeOrange
@EgnaroDev
Jul 08 2017 04:48
Rule #1: Don't look at the example project's code. Figure it out for yourself.
Gulsvi
@gulsvi
Jul 08 2017 04:49
Yeah, don't look at the example project :p
Search, find code samples, understand how to do what you want to do, write your code
Jeremy
@JeremyAntonoff
Jul 08 2017 04:50
anyway to remove a bunch of events at once
CallMeOrange
@EgnaroDev
Jul 08 2017 04:51
@SkyC0der Actually I dont need google maps API since Im using different api
Just need temperature and wind | humidity etc.. to load now
@SkyC0der Is it ok to use key for API in my code? :/
Gulsvi
@gulsvi
Jul 08 2017 04:57
Yeah, it's fine @MCTwoDigitZero
CallMeOrange
@EgnaroDev
Jul 08 2017 04:57
Damn there are too many icons for if statements..
Gulsvi
@gulsvi
Jul 08 2017 04:58
Weather Underground is pretty nice
I like the name of Dark Sky better
CallMeOrange
@EgnaroDev
Jul 08 2017 05:00
Im going to use Dark Sky after this
Just like random quote machines :p
Jeremy
@JeremyAntonoff
Jul 08 2017 05:01
can anyone help me with calc project?
CallMeOrange
@EgnaroDev
Jul 08 2017 05:03
Apixu => Dark Sky => Weather underground
I will create at least 2-3 weather apps
Gulsvi
@gulsvi
Jul 08 2017 05:05
If you have to copy/paste if/else statements or make a huge switch statement, you are doing it wrong :)
  var weatherIcon = {
    "Clear": Skycons.CLEAR_DAY,
    "Partly Cloudy": Skycons.PARTLY_CLOUDY_DAY,
    "Mostly Cloudy": Skycons.CLOUDY,
    "Rain": Skycons.RAIN,
    "Light Rain": Skycons.RAIN,
    "Light Thunderstorms and Rain": Skycons.RAIN,
    "Sleet": Skycons.SLEET,
    "Snow": Skycons.SNOW,
    "Windy": Skycons.WIND,
    "Overcast": Skycons.CLOUDY,
    "Heavy Rain": Skycons.RAIN
  };
make a lookup ^^
CallMeOrange
@EgnaroDev
Jul 08 2017 05:09
hm...
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:09
@JToddFL where do you need help in the project?
CallMeOrange
@EgnaroDev
Jul 08 2017 05:10
@SkyC0der then use if statements?
Gulsvi
@gulsvi
Jul 08 2017 05:10
@MCTwoDigitZero The lookup avoids the need for if statements
CallMeOrange
@EgnaroDev
Jul 08 2017 05:11
Im confused lol
This is for background image
Jeremy
@JeremyAntonoff
Jul 08 2017 05:11
@Lumexralph I just need to turn off all click events
Gulsvi
@gulsvi
Jul 08 2017 05:11
skycons.add('document.getElementById(iconDiv), weatherIcon[weatherCondition]);
Jeremy
@JeremyAntonoff
Jul 08 2017 05:12
@Lumexralph or figure something else out to do after someone runs calculations the first time
@Lumexralph I finished pretty much everything up until that last step
Gulsvi
@gulsvi
Jul 08 2017 05:12
@MCTwoDigitZero So, if your weather summary/condition is snow you do weatherIcon[weatherSummary] and it will look up the value for snow in the table. That can be a background image
M-C-Haker
@M-C-Haker
Jul 08 2017 05:13
@revisualize alright i thought i knew how to make it work but still kind of lost, getting the same errors with the loop
CallMeOrange
@EgnaroDev
Jul 08 2017 05:14
@SkyC0der ooh I get it, so if JSON object has "snow" then weatherIcon[weatherSummary=>"snow"]
Gulsvi
@gulsvi
Jul 08 2017 05:14
yes, and that returns "Skycons.SNOW" in the example above, but it could return background image instead.
CallMeOrange
@EgnaroDev
Jul 08 2017 05:15
if weatherSummary was snow then it will select an object from weatherIcon
Gulsvi
@gulsvi
Jul 08 2017 05:15
Then you don't have to have like 15 if/else statements for all the weather conditions
CallMeOrange
@EgnaroDev
Jul 08 2017 05:15
@SkyC0der Thanks, you saved my time lol
CamperBot
@camperbot
Jul 08 2017 05:15
mctwodigitzero sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:star2: 2011 | @skyc0der |http://www.freecodecamp.com/skyc0der
Gulsvi
@gulsvi
Jul 08 2017 05:15
I just started doing that recently...whish I had known earlier
CallMeOrange
@EgnaroDev
Jul 08 2017 05:16
I see
Gulsvi
@gulsvi
Jul 08 2017 05:17
mindblown.gif
saved me a lot of time... mind blown
CallMeOrange
@EgnaroDev
Jul 08 2017 05:17
weatherIcon[json["current"].condition.text] text==="Clear" then it will select "Clear"'s property from weatherIcon
Yeah looks correctly to me
Gulsvi
@gulsvi
Jul 08 2017 05:18
Yeah, that should work
CallMeOrange
@EgnaroDev
Jul 08 2017 05:20
@SkyC0der you said that you wished you knew earlier but isn't it similar to Profile Lookup?
Gulsvi
@gulsvi
Jul 08 2017 05:20
Yeah, but I didn't make the connection
I used a big switch statement and always stared at that code and hated it
CallMeOrange
@EgnaroDev
Jul 08 2017 05:21
lol
Gulsvi
@gulsvi
Jul 08 2017 05:21
then :bulb: :bulb:
mind blown
CallMeOrange
@EgnaroDev
Jul 08 2017 05:21
Same, wonder why Profile lookup was not even in my mind
Thanks to you, I will probably remember it all time
Gulsvi
@gulsvi
Jul 08 2017 05:22
I wonder what other lightbulbs haven't gone off yet
CallMeOrange
@EgnaroDev
Jul 08 2017 05:22
100% useful for weather app
Gulsvi
@gulsvi
Jul 08 2017 05:22
in 10 years I'll laugh at my code :)
CallMeOrange
@EgnaroDev
Jul 08 2017 05:22
lol
Gulsvi
@gulsvi
Jul 08 2017 05:22
in 1 year too probably lol
CallMeOrange
@EgnaroDev
Jul 08 2017 05:22
I will wait at least 5 years to look at my old code then
Gulsvi
@gulsvi
Jul 08 2017 05:23
haha
CallMeOrange
@EgnaroDev
Jul 08 2017 05:23
:bulb:
:fire:
:hospital:
Gulsvi
@gulsvi
Jul 08 2017 05:23
lol
Uggg, time for bed :( I will have to see your weather app tomorrow
CallMeOrange
@EgnaroDev
Jul 08 2017 05:24
@SkyC0der Sounds good, Night
Gulsvi
@gulsvi
Jul 08 2017 05:24
gn :+1:
jasonrest
@jasonrest
Jul 08 2017 05:28
Not understanding what part of this json object should be giving me the link back to the article. I have a codepen if needed.
Object{
ns: 0,
size:34792,
snippet:  "java applet is a small application",
timestamp: "2017 -05-30T",
title:"java servlet"
wordcount: 1610,
}
Hemakshi Sachdev
@hemakshis
Jul 08 2017 05:31
@jasonrest u can get the link from the title of the article
Manish Giri
@Manish-Giri
Jul 08 2017 05:32
is that the Wiki viewer?
jasonrest
@jasonrest
Jul 08 2017 05:32
@hemakshis oh I have to build the link? @Manish-Giri yes
I thought it was a prop of the object that I just extract
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:32
@SkyC0der I am already laughing at my code
Hemakshi Sachdev
@hemakshis
Jul 08 2017 05:32
@jasonrest yes just convert all the spaces in the title's name with a underscore ('_')
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:33
@JToddFL but click event is important for the project
Hemakshi Sachdev
@hemakshis
Jul 08 2017 05:33
and append it to https://wikipedia.org/wiki/
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:33
@Manish-Giri sggggggggggm :smiling_imp: good morning
jasonrest
@jasonrest
Jul 08 2017 05:34
@hemakshis so what would the href look like?
Manish Giri
@Manish-Giri
Jul 08 2017 05:34
lgm :smiling_imp: @Lumexralph
good morning
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:34
@Manish-Giri the urge to come hang out here ain't much as before
Manish Giri
@Manish-Giri
Jul 08 2017 05:34
@Lumexralph yeah I know, same here
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:35
@Manish-Giri you make me want to come though :bow:
Manish Giri
@Manish-Giri
Jul 08 2017 05:35
haha
Hemakshi Sachdev
@hemakshis
Jul 08 2017 05:35
https://wikipedia.org/wiki/java_servlet according to the example u gave
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:36
@Manish-Giri there's work and so much to be learnt, coming here is now a fraction of my time, sometimes I just view or pass by :smile:
Kelechi Chinaka
@ke1echi
Jul 08 2017 05:36
:wave: guys
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:36
@kelechichinaka Brother, can you believe I didn't submit the first Andela assessment ?
jasonrest
@jasonrest
Jul 08 2017 05:37
@hemakshis right and for the sake of each unique article. just put the first part and the title. I will try it. thanks.
CamperBot
@camperbot
Jul 08 2017 05:37
jasonrest sends brownie points to @hemakshis :sparkles: :thumbsup: :sparkles:
:cookie: 280 | @hemakshis |http://www.freecodecamp.com/hemakshis
Kelechi Chinaka
@ke1echi
Jul 08 2017 05:37
:smile: y @Lumexralph
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:37
@kelechichinaka only did it all it showed that green click stuff but don't know how I missed it
M-C-Haker
@M-C-Haker
Jul 08 2017 05:38
function mutation(arr) { var firstLcArr = arr[0].toLowerCase(); var secLcArr = arr[1].toLowerCase(); for (i = 0; i < secLcArr.length; i++) { if (firstLcArr.indexOf(secLcArr[i]) < 0) { return false; } return true; } } mutation(["hello", "hey"]);
hello and hey should return false for some reason i am stuck on this. any ideas?
Kelechi Chinaka
@ke1echi
Jul 08 2017 05:39
wow @Lumexralph
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:39
@kelechichinaka it almost happened the second time, finished it more than a week ago but had the urge to check what I did then out of curiosity I clicked submit assessment button and I was damn! thank God, I hope i'm still in time
CamperBot
@camperbot
Jul 08 2017 05:39
lumexralph sends brownie points to @kelechichinaka :sparkles: :thumbsup: :sparkles:
:cookie: 290 | @kelechichinaka |http://www.freecodecamp.com/kelechichinaka
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:40
@M-C-Haker return true out of the loop
Manish Giri
@Manish-Giri
Jul 08 2017 05:40
@Lumexralph which assessment
M-C-Haker
@M-C-Haker
Jul 08 2017 05:40
isn't -1 false though? @Lumexralph
Kelechi Chinaka
@ke1echi
Jul 08 2017 05:40
u did another test @Lumexralph
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:40
@M-C-Haker your code was difficult to read though
@kelechichinaka yes baba mi
M-C-Haker
@M-C-Haker
Jul 08 2017 05:41
function mutation(arr) {
var firstLcArr = arr[0].toLowerCase();
var secLcArr = arr[1].toLowerCase();
for (i = 0; i < secLcArr.length; i++) {
if (firstLcArr.indexOf(secLcArr[i]) < 0) {
return false;
}
return true;
}
}
mutation(["hello", "hey"]);
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:41
@Manish-Giri heard of Andela ?
M-C-Haker
@M-C-Haker
Jul 08 2017 05:41
i don't know why everyone else can seem to format properly but i can't
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:41
@M-C-Haker '''
CamperBot
@camperbot
Jul 08 2017 05:41
:bulb: to format code use backticks! ``` more info
Manish Giri
@Manish-Giri
Jul 08 2017 05:41
@M-C-Haker use 3 backticks not 1
@Lumexralph nope
who's Andela
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:41
@M-C-Haker click on the more info link
Markus Kiili
@Masd925
Jul 08 2017 05:42
@Lumexralph Morning.
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:42
@Manish-Giri it's a software development company that recruits software developers or should I say prospective train them, pay them and outsource them to clients all over the world
@Masd925 Good Morning, how's vacation going?
Long Nguyen
@longnt80
Jul 08 2017 05:43
can someone explain this Array.prototype.reduce.call:
var uniqueInOrder=function(iterable){

    return Array.prototype.reduce.call(iterable, function(a,b) { 

        if (a[a.length-1] !== b) a.push(b);

        return a;

    }, []);

}

uniqueInOrder('AAAABBBCCDAABBB'); // should return ['A', 'B', 'C', 'D', 'A', 'B']
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:43
@Masd925 ES 2017 finally released
Kelechi Chinaka
@ke1echi
Jul 08 2017 05:43
is the application still open @Lumexralph
M-C-Haker
@M-C-Haker
Jul 08 2017 05:43
@Manish-Giri 3 backticks?
Manish Giri
@Manish-Giri
Jul 08 2017 05:44
@M-C-Haker
```
code
Markus Kiili
@Masd925
Jul 08 2017 05:44
@Lumexralph Fine. Just heading for Finnish rapid chess championships. Two days without kids anywhere ;)
Manish Giri
@Manish-Giri
Jul 08 2017 05:44
```
M-C-Haker
@M-C-Haker
Jul 08 2017 05:44
@Manish-Giri oh thanks
CamperBot
@camperbot
Jul 08 2017 05:44
m-c-haker sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6212 | @manish-giri |http://www.freecodecamp.com/manish-giri
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:44
@M-C-Haker you need to return true after the loop is done because your loop has to be done checking all the characters in arr[0]
M-C-Haker
@M-C-Haker
Jul 08 2017 05:44
@Lumexralph if i return true after the loop everything else is incorrect...
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:44
@kelechichinaka always open just different cycles
@Masd925 :joy:
Markus Kiili
@Masd925
Jul 08 2017 05:46
@Lumexralph Did you already print it and put it under your pillow?
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:46
@M-C-Haker (firstLcArr.indexOf(secLcArr[i]) === -1 ) that's to say it found it so
Kelechi Chinaka
@ke1echi
Jul 08 2017 05:47
u play chess? @Masd925
mehn i gats apply @Lumexralph
Markus Kiili
@Masd925
Jul 08 2017 05:47
@kelechichinaka Yes.
Manish Giri
@Manish-Giri
Jul 08 2017 05:47
@Lumexralph is there a fee for the bootcamp period?
Kelechi Chinaka
@ke1echi
Jul 08 2017 05:48
i need that steady light and inrenet @Lumexralph
cool @Masd925 i've always wanted to learn chess
M-C-Haker
@M-C-Haker
Jul 08 2017 05:48
@Lumexralph mutation(["hello", "Hello"]) should return true is incorrect when i reformat the code in that way
Manish Giri
@Manish-Giri
Jul 08 2017 05:49
post your code here then share the link
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:49
@Masd925 going as a competitor or spectator?
@kelechichinaka yeah applied again
Long Nguyen
@longnt80
Jul 08 2017 05:50
can someone explain the .call() method in this example: :point_up: July 8, 2017 12:43 PM
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:50
@Manish-Giri nope, no fee but I have to take care of my accommodation and transportation during the period
@Masd925 nah, i only have an html format I bookmarked
@kelechichinaka you know what keep applying and keep doing FCC and some Python along the line
is what i have though i'm not sure why there is not output @Manish-Giri
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:53
@longnt80 call is a method of the Function object, used to call a function on an iterable/object that doesn't have that method
Manish Giri
@Manish-Giri
Jul 08 2017 05:54
@M-C-Haker don't you need to .split() the strings?
Long Nguyen
@longnt80
Jul 08 2017 05:54
@Lumexralph so in this case it can call the .reduce() method to work with a string?
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:55
@M-C-Haker
function mutation(arr) {
  var firstLcArr = arr[0].toLowerCase();
  var secLcArr = arr[1].toLowerCase();
  for (i = 0; i < secLcArr.length; i++) {
   if (firstLcArr.indexOf(secLcArr[i]) === -1) {
     return false;
   }

 }
  return true;
}
mutation(["Hello", "hello"]);
@longnt80 yes
M-C-Haker
@M-C-Haker
Jul 08 2017 05:56
@Manish-Giri i wouldn't think so... when i specify the arr[0] it is referring directly to a string in that location and if i was splitting it would mean that i had taken it from array made it a string and split it again into an array, right? i dont know lol
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:57
@longnt80 remember that, string and array are similar, they're both iterable and they're both sequences of characters and elements
Manish Giri
@Manish-Giri
Jul 08 2017 05:57
@M-C-Haker okay then
Markus Kiili
@Masd925
Jul 08 2017 05:58
@Lumexralph Playing.
Manish Giri
@Manish-Giri
Jul 08 2017 05:58
also move the return true outside the for loop.
Long Nguyen
@longnt80
Jul 08 2017 05:58
@Lumexralph I know that part, I was confused because reduce is an array method and wouldn't work with a string
M-C-Haker
@M-C-Haker
Jul 08 2017 05:58
@Manish-Giri yes that is the problem. i noticed when @Lumexralph posted that i was still in the loop thanks
CamperBot
@camperbot
Jul 08 2017 05:58
m-c-haker sends brownie points to @manish-giri and @lumexralph :sparkles: :thumbsup: :sparkles:
:warning: m-c-haker already gave manish-giri points
:star2: 2021 | @lumexralph |http://www.freecodecamp.com/lumexralph
M-C-Haker
@M-C-Haker
Jul 08 2017 05:58
it works now

```
function mutation(arr) {
var firstLcArr = arr[0].toLowerCase();
var secLcArr = arr[1].toLowerCase();
for (i = 0; i < secLcArr.length; i++) {
if (firstLcArr.indexOf(secLcArr[i]) < 0) {
return false;
}
}
return true;

}
mutation(["hello", "hey"]);

@Manish-Giri but the 3 backticks don't for me!
Manish Giri
@Manish-Giri
Jul 08 2017 05:59
where's the closing set of 3 ```
```
code
```
Ogundele Olumide
@Lumexralph
Jul 08 2017 05:59
@Masd925 I wish you beat them all to make up for the diving championship.....all the best
@longnt80 the question is how does reduce work
M-C-Haker
@M-C-Haker
Jul 08 2017 06:01
ah i see. @Manish-Giri and after reviewing the other solutions there is one where they split but i have no idea what's going on there, that's the "advanced solution" function mutation(arr) { return arr[1].toLowerCase() .split('') .every(function(letter) { return arr[0].toLowerCase() .indexOf(letter) != -1; }); }
Manish Giri
@Manish-Giri
Jul 08 2017 06:01
.every() returns true if the callback you pass to it, returns true for every element in the array you're using .every() on @M-C-Haker
try a simpler example first
Long Nguyen
@longnt80
Jul 08 2017 06:02
@Lumexralph reduce is to apply a function to each item and a accumulator value and return a single value (accumulator), right?
Manish Giri
@Manish-Giri
Jul 08 2017 06:02
[2, 4, 6].every(num => num % 2 === 0);
@M-C-Haker
this will return true, can you guess why?
Jeremy
@JeremyAntonoff
Jul 08 2017 06:04
should i initiate my ready() function at the top or bottom of my js file
is there a best practice?
Long Nguyen
@longnt80
Jul 08 2017 06:05
@Lumexralph if in the example above, I use the reduce method on iterable, it wouldn't work because iterable is a string:
return iterable.reduce(function(a,b) { 

        if (a[a.length-1] !== b) a.push(b);

        return a;

    }, []);
Ogundele Olumide
@Lumexralph
Jul 08 2017 06:05
@longnt80
[0, 1, 2, 3, 4].reduce(
  function (
    accumulator,
    currentValue,
    currentIndex,
    array
  ) {
    return accumulator + currentValue;
  }
);
//The callback would be invoked four times, with the arguments and return values in each call being as follow
M-C-Haker
@M-C-Haker
Jul 08 2017 06:06
@Manish-Giri because there is no remainder when divided by 2?
Manish Giri
@Manish-Giri
Jul 08 2017 06:06
@M-C-Haker yes
M-C-Haker
@M-C-Haker
Jul 08 2017 06:07
@Manish-Giri dude that just made my night tbh. thanks..
CamperBot
@camperbot
Jul 08 2017 06:07
m-c-haker sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:warning: m-c-haker already gave manish-giri points
Manish Giri
@Manish-Giri
Jul 08 2017 06:07
:+1:
Long Nguyen
@longnt80
Jul 08 2017 06:07
@Lumexralph I think I can understand how reduce() works, what I haven't grasped is the call() method
Ogundele Olumide
@Lumexralph
Jul 08 2017 06:09
@longnt80 when you use call it uses a function on the this object, it only got the function from the Array.prototype object
M-C-Haker
@M-C-Haker
Jul 08 2017 06:10
some challenge i breeze through. other's not so much,but it's nice to get those one offs that confirm you're at least learning something! I could use more of those kind of syntax/theory tests, i think. Do you have any good references? @Manish-Giri
Manish Giri
@Manish-Giri
Jul 08 2017 06:11
@M-C-Haker yup, try out hackreactor prep
the free course
M-C-Haker
@M-C-Haker
Jul 08 2017 06:12
i definitely will, they just got a bookmark. thanks again
Manish Giri
@Manish-Giri
Jul 08 2017 06:12
all the best!
Ogundele Olumide
@Lumexralph
Jul 08 2017 06:12
@longnt80 it's just a kind of hack so to speak, ordinarily, reduce should not work on string but call, apply method gave that power to us, call is a method of the Function object, even when reduce was created for array, it still is a function, that made it possible to be able to use call on it,
@longnt80 so whatcall did was just allowed you to be able to use reduce on the string
Long Nguyen
@longnt80
Jul 08 2017 06:14
@Lumexralph thanks man
CamperBot
@camperbot
Jul 08 2017 06:14
longnt80 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 2022 | @lumexralph |http://www.freecodecamp.com/lumexralph
Ogundele Olumide
@Lumexralph
Jul 08 2017 06:14
@Manish-Giri i want to use OOP for my pomodoro clock
Manish Giri
@Manish-Giri
Jul 08 2017 06:14
nice
Ogundele Olumide
@Lumexralph
Jul 08 2017 06:14
@longnt80 you're welcome
@Manish-Giri motivation from Python class, it makes the code look so easy compared to procedural way
@Manish-Giri still miss the lecturers though :smile: cool guys and I want to improve on my Python but JS is in the way, what do you think I can do :worried:
rybka02
@rybka02
Jul 08 2017 06:31
Anyone stuck?
i'm bored
Dovydas Stirpeika
@Giveback007
Jul 08 2017 06:39
hey anyone can point to some documentation regarding using 'this' in React?
@rybka02 you can explain 'this' in react in a way that I would use it with confidence
rybka02
@rybka02
Jul 08 2017 06:40
Sorry. I don't use react. I could explain its use in Javascript or Jquery.
Dovydas Stirpeika
@Giveback007
Jul 08 2017 06:41
@rybka02 I understand it in a basic way
but tnx anyways
maybe you can explain anyways, maybe intermediate and advanced use cases
Long Nguyen
@longnt80
Jul 08 2017 06:46
@Giveback007 so this in React is different from this in vanilla JS?
Dovydas Stirpeika
@Giveback007
Jul 08 2017 06:47
@longnt80 I want to know the differences, and maybe use cases that should be noted in react
I assume it's the same for the most part
assumptions are assumptions
Long Nguyen
@longnt80
Jul 08 2017 06:49
@Giveback007 I haven't learned React but I also assume it would be the same as regular JS
Manish Giri
@Manish-Giri
Jul 08 2017 06:56
@Giveback007 it's the same
a (stateful) component in React is just like a class
the this behaves the same way as you would expect to, with regular JS classes
Dovydas Stirpeika
@Giveback007
Jul 08 2017 06:59
@Manish-Giri what is the 'get' business in react
should I always try to use this.methodName in react classes?
Manish Giri
@Manish-Giri
Jul 08 2017 06:59
@Giveback007 get business?
Dovydas Stirpeika
@Giveback007
Jul 08 2017 07:01
Capture.PNG
Manish Giri
@Manish-Giri
Jul 08 2017 07:01
that's not react specific
get is just the pattern for creating a getter in JS
Dovydas Stirpeika
@Giveback007
Jul 08 2017 07:02

@Manish-Giri ahh tnx

hudge gaps in my knowledge

CamperBot
@camperbot
Jul 08 2017 07:02
giveback007 sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6213 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Jul 08 2017 07:03
I don't think you'll need to use get in react apps
but I might be wrong
Dovydas Stirpeika
@Giveback007
Jul 08 2017 07:04
whoa 6213 start. You are busy in here :smile:
Manish Giri
@Manish-Giri
Jul 08 2017 07:04
haha
lol
Dovydas Stirpeika
@Giveback007
Jul 08 2017 07:06
:bow: master teach me!!
Manish Giri
@Manish-Giri
Jul 08 2017 07:06
i'm no master buddy
I'm also learning..doing redux at the moment.
other regulars like @sjames1958gm know much more than me
Dovydas Stirpeika
@Giveback007
Jul 08 2017 07:08
@Manish-Giri (whispers quietly) ~master~
Manish Giri
@Manish-Giri
Jul 08 2017 07:08
rofl
:joy:
Manish Giri
@Manish-Giri
Jul 08 2017 07:09
lol
Dovydas Stirpeika
@Giveback007
Jul 08 2017 07:10
@Manish-Giri what did you use to learn react?
Manish Giri
@Manish-Giri
Jul 08 2017 07:10
@Giveback007 the official docs
they're very good
Dovydas Stirpeika
@Giveback007
Jul 08 2017 07:10
I keep getting bored sooo fast when I'm learning, I can't stay focused
Dovydas Stirpeika
@Giveback007
Jul 08 2017 07:12
I did the first fcc react project in 2-3 hours (I think), but to learn ReactDOM.render took a week ... because it's soooooo booooring
Munkhmanlai
@munkhmanlai
Jul 08 2017 07:12

Nesting for Loops

function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line

  for(var i=0;i<arr.length;i++){
    for (var j=0; j < arr[i].length; j++){
      product*=arr[i][j];
    }
  }
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);

haha i finished the challenge but boy wtf just happened i don't get it is anyone care to explain

Manish Giri
@Manish-Giri
Jul 08 2017 07:13
how did you write the code if you don't get it?
Dovydas Stirpeika
@Giveback007
Jul 08 2017 07:13
@munkhmanlai do you know how arr.length works?
alpox
@alpox
Jul 08 2017 07:13
@Manish-Giri there is a 2d loop example right in fhe exercise - its almost copypaste except the return and the thing inside the loops :D
Munkhmanlai
@munkhmanlai
Jul 08 2017 07:14
yeah it means whatever the length run the code @Giveback007
Manish Giri
@Manish-Giri
Jul 08 2017 07:14
@alpox oh yeah probably
alpox
@alpox
Jul 08 2017 07:14
@munkhmanlai
It means you get the length of the array
Dovydas Stirpeika
@Giveback007
Jul 08 2017 07:14
for every 1 run of the outer loop the inner loop runs the j < arr[i].length
Munkhmanlai
@munkhmanlai
Jul 08 2017 07:14
@Giveback007 for example,
```
for(i=0; i<5; i++){
Dovydas Stirpeika
@Giveback007
Jul 08 2017 07:16
eg: [ [1,2,3], [a,b,c], [4,5,6] ]
arr[0] aka arr[i] on first run of i loop will be [1,2,3]
the inner loop will then iterate trough that loop
so arr[i][0] will be 1
aka arr[i][j] first run of i loop and first run of j loop
you can figure out the rest this way by imagining step by step how the loop travels
Dovydas Stirpeika
@Giveback007
Jul 08 2017 07:23
I hope that made sense
jasonrest
@jasonrest
Jul 08 2017 07:39
what am i doing wrong here? trying to concat. the beginning of the url with the object title.
$('#output').prepend("<li><a href=" "wikipedia.com/wiki/" + test[i].title + ">" + test[i].title + "</a><br/><span>" + test[i].snippet +"</span></li>");
Manish Giri
@Manish-Giri
Jul 08 2017 07:40
" "wikipedia.com/wiki/"
this looks wrong
jasonrest
@jasonrest
Jul 08 2017 07:41
without those quotes then....
$('#output').prepend("<li><a href=" wikipedia.com/wiki/ + test[i].title + ">" + test[i].title + "</a><br/><span>" + test[i].snippet +"</span></li>");
CodeGeek3
@codeGeek3
Jul 08 2017 08:41
hey
luccifer00
@luccifer00
Jul 08 2017 08:55
'''$.getJSON(gooloc, function(loc){
$("#locate").html(loc.address_components.results.long_name["country"]);
var city = loc.address_components["administrative_area_level_1"];
var state = loc.address_components["country"];
var province = loc.address_components["administrative_area_level_2"];
  $("#locate").html(city); '''. Hello! Is this code well writted?? I cant get the locatión name ....
CamperBot
@camperbot
Jul 08 2017 08:55
:bulb: to format code use backticks! ``` more info
luccifer00
@luccifer00
Jul 08 2017 08:55
''' $.getJSON(gooloc, function(loc){
$("#locate").html(loc.address_components.results.long_name["country"]);
var city = loc.address_components["administrative_area_level_1"];
var state = loc.address_components["country"];
var province = loc.address_components["administrative_area_level_2"];
  $("#locate").html(city); '''
CamperBot
@camperbot
Jul 08 2017 08:55
:bulb: to format code use backticks! ``` more info
luccifer00
@luccifer00
Jul 08 2017 08:57
``` $.getJSON(gooloc, function(loc){
$("#locate").html(loc.address_components.results.long_name["country"]);
var city = loc.address_components["administrative_area_level_1"];
var state = loc.address_components["country"];
var province = loc.address_components["administrative_area_level_2"];
  $("#locate").html(city); ```.  Sorry i am with the mobile..... 
Viktor Tiutiun
@vittorioVT
Jul 08 2017 08:58
@luccifer00 better use dot. for example: var state = loc.country;
luccifer00
@luccifer00
Jul 08 2017 09:00
@vittorioVT , in the google example, i think i have to write from the root.... i will try that
Maybe i have wrong write the http API

var gooloc ="https://maps.googleapis.com/maps/api/geocode/json?latlng="+ lat + "," + long +"&key=AIzaSyBUzuWvyNu66-dU5DW8DfMqNQ87JgFPCUs";
i should add something at the end??? I just follow the html example....
should i add ?callback?=?
Viktor Tiutiun
@vittorioVT
Jul 08 2017 09:04
@luccifer00 sometimes at the end you need to add a key
luccifer00
@luccifer00
Jul 08 2017 09:06
@vittorioVT yes i know, the lat and long and keys are mine.... it isnt the example key
Viktor Tiutiun
@vittorioVT
Jul 08 2017 09:07
@luccifer00 If in your example isn't key, then it isn't necessary. I used a source where a unique key was required
Viktor Tiutiun
@vittorioVT
Jul 08 2017 09:21
@luccifer00 your function ( $.getJSON(darkSky1, function(json){...) have already timezone, latitude and longitude, why do you need var gooloc else?
Michiel
@MichielHuijse
Jul 08 2017 09:29
Hi I am working on the wikipedia viewer. I was wondering if I can use a <form> and a submit button. To start the search. Or will that mean that the page will be reloaded?
luccifer00
@luccifer00
Jul 08 2017 09:30
@vittorioVT in that function i tried to get timezone, but i return nothing (empty field) on html box. That is the reason i need to use google api. Anyway i dont understand why $("#locate").html("momo"); dosent return nothing, even "momo" was a city var, it is like the $(#locate") was ommited for some reason...
maybe i should chang that for .add??
luccifer00
@luccifer00
Jul 08 2017 09:49
In the darksky website said that time zone is required, but i can not figure out how to get it without google api
makalohri
@makalohri
Jul 08 2017 09:58
@knrt10 thank you mate
CamperBot
@camperbot
Jul 08 2017 09:58
makalohri sends brownie points to @knrt10 :sparkles: :thumbsup: :sparkles:
:cookie: 451 | @knrt10 |http://www.freecodecamp.com/knrt10
Michiel
@MichielHuijse
Jul 08 2017 10:11
@luccifer00 you don't need the timezone for darksky, just lon and lat
Jianhao Tan
@jaanhio
Jul 08 2017 10:12
hi all, i am trying to implement a feature on tumblr where upon hover, the title will be rearranged to form another word. the below code works fine when i tested it on my other sites (not tumblr) but doesnt animate on tumblr. any idea why?
.name-container{
  display: inline-block;
  border-bottom: 1px dotted black;
  margin-top: -10px;
  font-size: 15px;
  //background-color: pink;
}
span.char3:hover{
    transform: translateX(0);
  }
span.char2:hover{
    transform: translateX(0);
  }
span.char4:hover{
    transform: translateX(0);
  }
span.char5:hover{
    transform: translateX(0);
  }
span.char6:hover{
    transform: translateX(0);
  }
}

span{
  display: inline-block;
  margin-left: 0.5px;
}

span.char2{
  transform: translateX(3.54em);
  transition: transform 500ms;
}

span.char3{
  transform: translateX(0.34em);
  transition: transform 500ms;
}

span.char4{
  transform: translateX(0.32em);
  transition: transform 500ms;
}

span.char5{
  transform: translateX(0.32em);
  transition: transform 500ms;
}

span.char6{
  transform: translateX(-3.21em);
  transition: transform 500ms;
}
Joseph Joe
@JoeTinnySpace
Jul 08 2017 10:14
$(document).ready(function(){
  $('#search-btn').click(function(){
    var keyword =$('#keyword').val();
    var url = "https://en.wikipedia.org/w/api.php?action=opensearch&search="+keyword+"&format=json&callback=?";
    //api call
    $.ajax({
      type: "GET",
      url: url,
      async: false,
      dataType: "json",
      success: function(data){
        //retriving data
        for(var i= 0; i<data[1].length; i++){
          //sending markups to the ul tag with data
          $('#results').prepend("<li><a href="+data[3][i]+">"+data[1][i]+"</a><p>"+data[2][i]+"</p></li>");
        }

      },
      error: function(errorMessage){
        //in-case of error
        alert("error");
      }
    });
  });
});
The wikipedia project.
I can't retrieve the data into html.
Sometimes it shhows for a split second, but then the whole body goes white....
Diego Mayer
@Chrono79
Jul 08 2017 10:18
@JoeTinnySpace check if you use a submit button from a form, you have to use preventDefault
Otherwise the page refresh
Joseph Joe
@JoeTinnySpace
Jul 08 2017 10:19
@Chrono79 I just noticed, now the console.log doen't work either. But was working before ... Can you look into the code? https://codepen.io/CallMeJoe/pen/JJmjxj?editors=1011
Diego Mayer
@Chrono79
Jul 08 2017 10:21
@JoeTinnySpace add e.preventDefault(); below $('#search-btn').click(function(e){
Joseph Joe
@JoeTinnySpace
Jul 08 2017 10:23
@Chrono79 wow, thanks
CamperBot
@camperbot
Jul 08 2017 10:23
joetinnyspace sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4467 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Jul 08 2017 10:24
:+1:
Manny Hagman
@mannyhagman
Jul 08 2017 10:31
M
Joseph Joe
@JoeTinnySpace
Jul 08 2017 10:31

@Chrono79 why isn't the

for(var i= 0; i<data[1].length; i++){
         // sending markups to the ul tag with data
          $('#results').prepend("<li><a href="+data[3][i]+">"+data[1][i]+"</a><p>"+data[2][i]+"</p></li>");
        }

doesn't work, after this $('#results').htmll('');

alright got it
stupid me!
Manny Hagman
@mannyhagman
Jul 08 2017 10:33
M
Michiel
@MichielHuijse
Jul 08 2017 11:19
why isn't there a semicolon after the last expression: for (i = 0; i<10; i++)?
Diego Mayer
@Chrono79
Jul 08 2017 11:19
@MichielHuijse because it isn't needed
Stephen James
@sjames1958gm
Jul 08 2017 11:20
@MichielHuijse Because the semi-colons are only to seperate the values inside the for loop definition
They are not the same as statement ending semi-colons
Michiel
@MichielHuijse
Jul 08 2017 11:20
@Chrono79 but if you paste a semicolon the code will produce an error
Diego Mayer
@Chrono79
Jul 08 2017 11:21
for ([initialization]; [condition]; [final-expression])
   statement
Stephen James
@sjames1958gm
Jul 08 2017 11:21
Sometimes rules is rules, that is how it is defined
Diego Mayer
@Chrono79
Jul 08 2017 11:22
if (a < b) you don't put a semicolon inside those parentheses either
Michiel
@MichielHuijse
Jul 08 2017 11:22
@sjames1958gm so they are expressions instead of statements
thanks for the quick reply both! @Chrono79 @sjames1958gm
CamperBot
@camperbot
Jul 08 2017 11:23
michielhuijse sends brownie points to @chrono79 and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8011 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:star2: 4468 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Jul 08 2017 11:23
:+1:
Stephen James
@sjames1958gm
Jul 08 2017 11:23
@MichielHuijse yw
That for loop format is from the early 70s when C was invented.
Michiel
@MichielHuijse
Jul 08 2017 11:26
it is kind of confusing for me. I thought it would be something like declaring variables. like so: for (i = 0, i<10, i++;) :D
Stephen James
@sjames1958gm
Jul 08 2017 11:28
@MichielHuijse The for loop can be converted to a while loop. You can see each piece here.
var i = 0;
while (i < 10) {
<body>
i++;
}
Vivek Ranjan
@vivekranjan92
Jul 08 2017 11:31
hi can anyone tell me the meaning of
for(int num:numbers)
what is num:numbers here?
Michiel
@MichielHuijse
Jul 08 2017 11:32
Just a minor detail, think I will get used to it.
Sweet Coding :)
@SweetCodingInc
Jul 08 2017 11:32
@vivekranjan92 for in loop in java
Stephen James
@sjames1958gm
Jul 08 2017 11:32
@MichielHuijse :)
Vivek Ranjan
@vivekranjan92
Jul 08 2017 11:33
@SweetCodingInc didn't get you
Diego Mayer
@Chrono79
Jul 08 2017 11:33
@vivekranjan92 that's not javascript, that's java (or some other language with that syntax)
Vivek Ranjan
@vivekranjan92
Jul 08 2017 11:33
@Chrono79 yes I know
thought some genius will help me
Vivek Ranjan
@vivekranjan92
Jul 08 2017 11:35
@Chrono79 yeah thanks but can learn from googling it... I want some one to explain me
CamperBot
@camperbot
Jul 08 2017 11:35
vivekranjan92 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4469 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Jul 08 2017 11:35
afaik numbers is an array of integers there, and num is the var name you can use to hold them
what is it you don't get? Maybe with that we can help you better
I know very little of java tho
Vivek Ranjan
@vivekranjan92
Jul 08 2017 11:37
i was looking the code to find the duplicate in an array
there i found this thing
@Chrono79 np that will be fine if you explain me a bit
Diego Mayer
@Chrono79
Jul 08 2017 11:38
and you have the full code?
GeorgeII
@GeorgeII
Jul 08 2017 11:38

Hello everybody! Can anyone explain me why does my code not work?

function truthCheck(collection, pre) {
  // Is everyone being true?

  collection.forEach(function(element) {
    if (pre in element === false)
      return false;
  });
  return true;
}

truthCheck([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");

If every object contains second argument ("sex") function should return true else false.

Sanket Chaudhari
@sanket143
Jul 08 2017 11:39
How could I clear the content of <h1></h1>
to fill it from another
Stephen James
@sjames1958gm
Jul 08 2017 11:39
@vivekranjan92
int num : numbers
num is the loop variable and will be assigned a value from numbers for each loop iteration
WAINGOR
@WAINGOR
Jul 08 2017 11:39
Hi all I am going nuts here. The code here below logs NaN.... But then if I replace the last line with console.log(typeof newAr) it logs number!!!! What duh hellllllll
var myArr1 = [2, 2, 2, 2, 2];

var newArr = myArr1.reduce(
    function(val, idx) {
        console.log(idx);
        console.log(val);
    return myArr1[idx] += val;
     });
console.log(newArr);
Stephen James
@sjames1958gm
Jul 08 2017 11:40
@GeorgeII The return inside the forEach does nothing other than go to the next loop iteration
@WAINGOR
typeof NaN
"number"
Diego Mayer
@Chrono79
Jul 08 2017 11:40
@WAINGOR the arguments of reduce's callback aren't those
Krishna Biradar
@kr5hn4
Jul 08 2017 11:41
@WAINGOR Welcome to the weird world of JavaScript, in javascript typeof NaNis a number
GeorgeII
@GeorgeII
Jul 08 2017 11:41
@sjames1958gm ty
CamperBot
@camperbot
Jul 08 2017 11:41
georgeii sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8012 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
WAINGOR
@WAINGOR
Jul 08 2017 11:41
looooool
Sanket Chaudhari
@sanket143
Jul 08 2017 11:41
How could I clear the content of <h1></h1>
to fill it from another with a click on button
WAINGOR
@WAINGOR
Jul 08 2017 11:41
but how is 2+2+2+2 not a number?
Stephen James
@sjames1958gm
Jul 08 2017 11:42
@WAINGOR idx is not and index it is a value from the array. val is the accumulator
@sanket143 If you are using jquery there is the empty() function.
Sanket Chaudhari
@sanket143
Jul 08 2017 11:44
@sjames1958gm How could I use it in
https://codepen.io/Sanket143/pen/YQaWvO
WAINGOR
@WAINGOR
Jul 08 2017 11:47
@sjames1958gm that makes sense. But still, how does it log NaN? I suspect it is because I try to reach an item that isnt there... (very quickly this code says myArr1[6] += val , and myArr1 only has 5 items in it...
Stephen James
@sjames1958gm
Jul 08 2017 11:49
@WAINGOR where are you running this code?
WAINGOR
@WAINGOR
Jul 08 2017 11:49
in the browser
Stephen James
@sjames1958gm
Jul 08 2017 11:49
How? devtools console?
WAINGOR
@WAINGOR
Jul 08 2017 11:49
yes
ahh yes I see that reduce can even change the original array! as a matter of fact, it does exactly that in this example
Stephen James
@sjames1958gm
Jul 08 2017 11:49
undefined is the result of the final statement and console.log() returns undefined
@WAINGOR When you get to element [4] it has the value of 6 and is past the end of the array.
WAINGOR
@WAINGOR
Jul 08 2017 11:51
@sjames1958gm is doesnt log undefined in my browser... do you have JS harmony activated @ chrome? I do.. idk if that makes a difference
Stephen James
@sjames1958gm
Jul 08 2017 11:51
@sanket143 just do this to replace the current quote
roll.innerHTML = ourData[count];
Sanket Chaudhari
@sanket143
Jul 08 2017 11:51
okay
Diego Mayer
@Chrono79
Jul 08 2017 11:52
Stephen James
@sjames1958gm
Jul 08 2017 11:52
@WAINGOR test gets logged then it shows the result of the last statement which is the return from console.log which is always undefined in chrome
console.log("test")
 test
undefined
WAINGOR
@WAINGOR
Jul 08 2017 11:54
@sjames1958gm idk about the above, but when I drop the code into a .html file and run it in the browser it logs NaN :)
Sanket Chaudhari
@sanket143
Jul 08 2017 11:54
thats cool .... @sjames1958gm thanks
CamperBot
@camperbot
Jul 08 2017 11:54
sanket143 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8013 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 08 2017 11:54
@WAINGOR Yes, NaN is the result of the statement (you will only see undefined in the console)
    function(acc, val) {
        console.log(acc);
        console.log(val);
    return acc + val;
     }
If you want to sum the values in the array. And reduce doesn't return an array (unless the function passed to it does)
WAINGOR
@WAINGOR
Jul 08 2017 11:59
helpful as always, thanks @sjames1958gm
CamperBot
@camperbot
Jul 08 2017 11:59
waingor sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8014 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 08 2017 11:59
@WAINGOR :+1:
Munkhmanlai
@munkhmanlai
Jul 08 2017 12:01

Profile Lookup

We have an array of objects representing different people in our contacts lists.

A lookUpProfile function that takes firstName and a property (prop) as arguments has been pre-written for you.

The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.

If both are true, then return the "value" of that property.

If firstName does not correspond to any contacts then return "No such contact"

If prop does not correspond to any valid properties then return "No such property"

var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUpProfile(firstName, prop){
// Only change code below this line

  for(i=0;i<contacts.length;i++){
    if (firstName,prop==contacts.firstName){
      return contacts;
    }
  }

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");

How should i approach this challenge i am confused as fuck when it comes to loops and object

Ken Haduch
@khaduch
Jul 08 2017 12:03
@munkhmanlai - the first thing to realize is that contacts is an array, so you have to use array indexing in some form to access the objects within the array. You are generating the index with your variable i, but you aren't using it.
Stephen James
@sjames1958gm
Jul 08 2017 12:04
@munkhmanlai firstName, prop are two separate values passed to the function
And firstName is a property on the contact in the array, not the array itself
Munkhmanlai
@munkhmanlai
Jul 08 2017 12:04
@khaduch but i have to use for loop right
@sjames1958gm so check them separately then
Stephen James
@sjames1958gm
Jul 08 2017 12:05
@munkhmanlai You should use a for loop
Yes, as the instructions say.
Munkhmanlai
@munkhmanlai
Jul 08 2017 12:06
@sjames1958gm damn it is hard
@sjames1958gm in for loop, i am using IF to check right how should i check if firstName is in my array
?
Stephen James
@sjames1958gm
Jul 08 2017 12:08
@munkhmanlai Takes time to learn these new concepts.
Munkhmanlai
@munkhmanlai
Jul 08 2017 12:08
@sjames1958gm did u struggle when u are learning these or was it just breeze
Stephen James
@sjames1958gm
Jul 08 2017 12:08
@munkhmanlai Each contact has a firstName property which you need to compare to the parameter
@munkhmanlai I am not a general case - I have been programming in other languages already
Munkhmanlai
@munkhmanlai
Jul 08 2017 12:09
@sjames1958gm yeah i know but how to compare is my confusion
Krishna Biradar
@kr5hn4
Jul 08 2017 12:10
@munkhmanlai
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUpProfile(firstName, prop){
// Only change code below this line

  for(i=0;i<contacts.length;i++){
    if (firstName==contacts[i].firstName){
      return contacts[i];
    }
  }

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
Munkhmanlai
@munkhmanlai
Jul 08 2017 12:10
@kr5hn4 aah i seee thanks
CamperBot
@camperbot
Jul 08 2017 12:10
munkhmanlai sends brownie points to @kr5hn4 :sparkles: :thumbsup: :sparkles:
:cookie: 199 | @kr5hn4 |http://www.freecodecamp.com/kr5hn4
Munkhmanlai
@munkhmanlai
Jul 08 2017 12:15
@khaduch @sjames1958gm how many loops do i have to use?
Diego Mayer
@Chrono79
Jul 08 2017 12:18
1
review all past object's related challenges
Ayush Kumar
@Gr8ayu
Jul 08 2017 12:18
why course++; is not working ?? https://codepen.io/gr8ayu/pen/yXRLep?editors=1010
on clicking correct button
Ken Haduch
@khaduch
Jul 08 2017 12:21
@munkhmanlai - you only need one loop, all of the condition testing takes place within one loop.
Munkhmanlai
@munkhmanlai
Jul 08 2017 12:21
@khaduch thanks
CamperBot
@camperbot
Jul 08 2017 12:21
munkhmanlai sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3081 | @khaduch |http://www.freecodecamp.com/khaduch
Stephen James
@sjames1958gm
Jul 08 2017 12:23
@Gr8ayu YOu have both click handlers on pass, so it goes up then goes down
Diego Mayer
@Chrono79
Jul 08 2017 12:23
lol
good catch
Stephen James
@sjames1958gm
Jul 08 2017 12:24
:)
Munkhmanlai
@munkhmanlai
Jul 08 2017 12:25

@khaduch

var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUpProfile(firstName, prop){
// Only change code below this line

  for(i=0;i<contacts.length;i++){
    if (firstName==contacts[i].firstName){
      return contacts[i].firstName;
    }else return "No such contact";

    if (prop==contact[i].likes){
      return contacts[i].likes;
    }else return "No such property";
  }

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");

it doesn't giving me likes or the prop?

Stephen James
@sjames1958gm
Jul 08 2017 12:25
@munkhmanlai you are comparing a property name to a property value.
@munkhmanlai YOu need to check the property only when the firstName matches
Ken Haduch
@khaduch
Jul 08 2017 12:26
@Gr8ayu - you have two event handlers for .pass and none for .fail - so when you click, it increments and then decrements your value and updates it twice. (I see that someone answered while I wasn't looking... :) )
Munkhmanlai
@munkhmanlai
Jul 08 2017 12:27
@sjames1958gm likes is property name isn't it?
@sjames1958gm or property value?
Stephen James
@sjames1958gm
Jul 08 2017 12:30
@munkhmanlai contact[i].likes this result of this expression is a property value.
prop is a variable with a property name.
You need to check if the property exists on the contact - https://www.freecodecamp.com/challenges/testing-objects-for-properties
Vivek Ranjan
@vivekranjan92
Jul 08 2017 12:31
@Chrono79 yes i have
Amit Patel
@AmitP88
Jul 08 2017 12:31
hey guys, I'm working on creating a javascript game that combines a 2d classic rpg dungeon crawler with 3 match puzzle game like Candy Crush. I've gotten my assets in place (just placeholders for now), but I'm wondering if I should choose a game engine to work in or try to create my own, since my game will be combining two game types. What do you guys think?
Ayush Kumar
@Gr8ayu
Jul 08 2017 12:31
@sjames1958gm @khaduch thanks
CamperBot
@camperbot
Jul 08 2017 12:31
gr8ayu sends brownie points to @sjames1958gm and @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3082 | @khaduch |http://www.freecodecamp.com/khaduch
:star2: 8015 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Vivek Ranjan
@vivekranjan92
Jul 08 2017 12:32
@Chrono79 Do you want full code?
shivam gupta
@shivamg11000
Jul 08 2017 12:32
@AmitP88 phantom.js is popular to make games
Ayush Kumar
@Gr8ayu
Jul 08 2017 12:33
@vivekranjan92 you can edit your message
Amit Patel
@AmitP88
Jul 08 2017 12:33
@shivamg11000 thanks, i'll check it out :)
CamperBot
@camperbot
Jul 08 2017 12:33
amitp88 sends brownie points to @shivamg11000 :sparkles: :thumbsup: :sparkles:
:cookie: 370 | @shivamg11000 |http://www.freecodecamp.com/shivamg11000
WAINGOR
@WAINGOR
Jul 08 2017 12:34
@munkhmanlai thank you so much for your choice of language. It rllly cheers my day up here in Holland
Vivek Ranjan
@vivekranjan92
Jul 08 2017 12:34
@Gr8ayu thanks i was not aware of it
CamperBot
@camperbot
Jul 08 2017 12:34
vivekranjan92 sends brownie points to @gr8ayu :sparkles: :thumbsup: :sparkles:
:cookie: 332 | @gr8ayu |http://www.freecodecamp.com/gr8ayu
shivam gupta
@shivamg11000
Jul 08 2017 12:37
anybody who code reactjs and angular both
Ayush Kumar
@Gr8ayu
Jul 08 2017 12:37
how these websites are made , they scroll whole screen at once ??
Felipe Yudi
@fyudi
Jul 08 2017 12:41
help guys! i´m doing a challing in javascript now, the output is correct, but the site says it is not correct

function titleCase(str) {

  str = str.split(" ");

  var arraySize =str.length;

  var arrayStr;
  var newStr = "";


  for (var i = 0; i < arraySize; i++){

    arrayStr = str[i].charAt(0).toUpperCase() + str[i].substr(1).toLowerCase();

    newStr =  newStr + " " +(str[i].charAt(0).toUpperCase() + str[i].substr(1).toLowerCase()).toString(); 

  }

  return newStr;
}

titleCase("I'm a little tea pot");
Gulsvi
@gulsvi
Jul 08 2017 12:41
@Gr8ayu fullPage.js is a plugin that lots of sites use to do that: https://github.com/alvarotrigo/fullPage.js
Here's a codepen showing how to do it: https://codepen.io/alvarotrigo/pen/qqgPNy
Ayush Kumar
@Gr8ayu
Jul 08 2017 12:43
@SkyC0der thanx
CamperBot
@camperbot
Jul 08 2017 12:43
gr8ayu sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:star2: 2012 | @skyc0der |http://www.freecodecamp.com/skyc0der
Stephen James
@sjames1958gm
Jul 08 2017 12:43
@fyudi probably an extra space at the front.
@fyudi easier to put the modified word back into the array and join at the end
Felipe Yudi
@fyudi
Jul 08 2017 12:44
@sjames1958gm wow thanks :))
CamperBot
@camperbot
Jul 08 2017 12:44
fyudi sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8016 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Munkhmanlai
@munkhmanlai
Jul 08 2017 12:55
god this JS object is making me mad
gadzet
@gadzet
Jul 08 2017 12:55
@sjames1958gm do you know how to get refs from inside the render function? I was trying to pass it via componentdidmount state but it is not getting set
shivam gupta
@shivamg11000
Jul 08 2017 12:55
@munkhmanlai like
gadzet
@gadzet
Jul 08 2017 12:59
export default class Timeline extends Component {
    constructor(props) {
         super(); 
            this.arr = this.generateTimelineArray();
            this.state = {el : 'empty'};
          }
    componentDidMount() {
        // it is a regular DOM node

           this.setState({
          el: this.refs.el
        });
        console.log('------------------');
           console.log(this.state.el)
    }
render() {
    const timeList = list.map((element) =>
        <TimelineElement element={element}/>
        );
    return (
      <div  className="timeline__container" >
      <div  className="timeline__container--line" ref="el" >
                  </div>
          {timeList}
      </div>
    ); 
  }
How could i get timeline__container--line ref to be set in the state ?
Munkhmanlai
@munkhmanlai
Jul 08 2017 13:02
Can anyone explain WTF :angry: is going on here?
Testing Objects for Properties

// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
  if(checkObj.hasOwnProperty(checkProp)){
    return myObj(checkProp);
  }else
  return "Not found";
}

// Test your code by modifying these values
checkObj("gift");
Diego Mayer
@Chrono79
Jul 08 2017 13:03
@munkhmanlai checkObj is your function's name
your object's name is myObj
gadzet
@gadzet
Jul 08 2017 13:03
it checks if your object has gift
and then return the value of it
if the the key is not in the object it returns not found
anyone can give me a hand on react ? :(
Munkhmanlai
@munkhmanlai
Jul 08 2017 13:05
@Chrono79 i really don't get wtf is going on after function
gadzet
@gadzet
Jul 08 2017 13:06
after function you are calling the function
all the functions have to be called
"gift is the value you pass to the function - checkProp
2895388807
@2895388807
Jul 08 2017 13:07
下面的代码将输出数组 arr 的每个元素到控制台:
var arr = [10,9,8,7,6];
for (var i=0; i < arr.length; i++) {
console.log(arr[i]);
}
记住数组的索引从零开始的,这意味着数组的最后一个元素的下标是:数组的长度 - 1。我们这个循环的 条件 是 i < arr.length,当 i 的值为 长度-1 的时候循环就停止了
Diego Mayer
@Chrono79
Jul 08 2017 13:08
@munkhmanlai if(checkObj.hasOwnProperty(checkProp)){ <- this line is wrong
2895388807
@2895388807
Jul 08 2017 13:08
I dont understand why .length is -1.
Is it should be 5?
gadzet
@gadzet
Jul 08 2017 13:09
@2895388807 wheredo you get the -1 from
Munkhmanlai
@munkhmanlai
Jul 08 2017 13:09
@Chrono79 yeah i fixed it to myObj.hasOwnProperty(checkProp)
@Chrono79 but how do u return the value of myObj property if it is true
2895388807
@2895388807
Jul 08 2017 13:09
description
this sentence is right . I just dont under the description.
Munkhmanlai
@munkhmanlai
Jul 08 2017 13:10
@2895388807
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
  if(myObj.hasOwnProperty(checkProp)){
    return myObj(checkProp);
  }else
  return "Not found";
}

// Test your code by modifying these values
checkObj("gift");
Gulsvi
@gulsvi
Jul 08 2017 13:10
@munkhmanlai Also watch the casing for "Not Found", as "Not found" (lower-case 'f') won't pass.
To access the property, refer to: https://www.freecodecamp.org/challenges/accessing-objects-properties-with-bracket-notation
2895388807
@2895388807
Jul 08 2017 13:11
@munkhmanlai thank you
CamperBot
@camperbot
Jul 08 2017 13:11
2895388807 sends brownie points to @munkhmanlai :sparkles: :thumbsup: :sparkles:
:cookie: 236 | @munkhmanlai |http://www.freecodecamp.com/munkhmanlai
Munkhmanlai
@munkhmanlai
Jul 08 2017 13:13
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
  if(myObj.hasOwnProperty(checkProp)){
    return myObj(checkProp);
  }else
  return "Not found";
}

// Test your code by modifying these values
checkObj("gift"
does anyone know wtf is wrong with this
2895388807
@2895388807
Jul 08 2017 13:13
the description mean when i's length is -1 it cycle stoped.
@munkhmanlai plz show me the title. I just pass this class.
let me see maybe help you
Munkhmanlai
@munkhmanlai
Jul 08 2017 13:15
@2895388807 Testing Objects for Properties
IggySmith
@IggySmith
Jul 08 2017 13:15
image.png
code outputs correctly so whats wrong?
2895388807
@2895388807
Jul 08 2017 13:16
@munkhmanlai take off else and try
Ghost
@ghost~56ef2a8b85d51f252ab9dec9
Jul 08 2017 13:16
@IggySmith It shouldn't be gear += addGear
IggySmith
@IggySmith
Jul 08 2017 13:16
@thomlom then?
Ghost
@ghost~56ef2a8b85d51f252ab9dec9
Jul 08 2017 13:17
@IggySmith You want to set the number of gear, not to add the number of gear :)

According to your code :

myBike.setGear(1)
myBike.getGear() // evaluates to 1
myBike.setGear(4)
myBike.getGear() // evaluates to 5
myBike.setGear(3)
myBike.getGear() // evaluates to 8

Instead it should be :

myBike.setGear(1)
myBike.getGear() // evaluates to 1
myBike.setGear(4)
myBike.getGear() // evaluates to 4
myBike.setGear(3)
myBike.getGear() // evaluates to 3
IggySmith
@IggySmith
Jul 08 2017 13:19
@thomlom thanks
CamperBot
@camperbot
Jul 08 2017 13:19
iggysmith sends brownie points to @thomlom :sparkles: :thumbsup: :sparkles:
:cookie: 496 | @thomlom |http://www.freecodecamp.com/thomlom
WAINGOR
@WAINGOR
Jul 08 2017 13:19
Hi all, a little question on reduce here. I am trying to make the excercise "Render Images from Data Sources " (JSON API's and AJAX) using map instead of .forEach . Does anybody know why this code returns "<div><img src='<div><img src='<div><img src=" as the beginning of the string? I would say that at the beginning of each loop it would prepend that string to the rest...
var json = 
[
  {
    "id": 0,
    "imageLink": "https://s3.amazonaws.com/freecodecamp/funny-cat.jpg",
    "altText": "A white cat wearing a green helmet shaped melon on it's head. ",
    "codeNames": [
      "Juggernaut",
      "Mrs. Wallace",
      "Buttercup"
    ]
  },
  {
    "id": 1,
    "imageLink": "https://s3.amazonaws.com/freecodecamp/grumpy-cat.jpg",
    "altText": "A white cat with blue eys, looking very grumpy. ",
    "codeNames": [
      "Oscar",
      "Scrooge",
      "Tyrion"
    ]
  },
  {
    "id": 2,
    "imageLink": "https://s3.amazonaws.com/freecodecamp/mischievous-cat.jpg",
    "altText": "A ginger cat with one eye closed and mouth in a grin-like expression. Looking very mischievous. ",
    "codeNames": [
      "The Doctor",
      "Loki",
      "Joker"
    ]
  }
];

var Y = json.reduce(function(accumulator,currentvalue) {
 return "<div><img src='" + accumulator + currentvalue.imageLink;
    // Only change code above this line.



},"");
console.log(Y);
excuse me I mean .reduce not map :)
gadzet
@gadzet
Jul 08 2017 13:22
you dont have closing tags
return "<div><img src='" + accumulator + currentvalue.imageLink"'/></div>";
Diego Mayer
@Chrono79
Jul 08 2017 13:27
@munkhmanlai Use bracket notation, parentheses are for functions/methods, not to get object's properties
Review https://www.freecodecamp.org/challenges/accessing-objects-properties-with-variables
WAINGOR
@WAINGOR
Jul 08 2017 13:30
@gadzet that syntax is not valid... a + needs to come after .imagelink , and I tried that already :)
is gets the same result
Bimal Raj Sitaula
@challenger11
Jul 08 2017 13:31
var runIt = function (a) {
console.log(a);
a();
}
Could somebody explain to me what is this (a) here, as far as I understand it is a parameter, but I hear somebody saying it is a passed value, even calling it a variable, i think name maynot make that big difference but still want to make it clear. Also, I don't get it why a() is used, it says to execute the function but I think that why not just use paranthesis.
Stephen James
@sjames1958gm
Jul 08 2017 13:35
@WAINGOR Every loop it adds that string to the front of the existing string. You should do
return accumulator + "<div><img src='" + currentvalue.imageLink + "></div>";
gadzet
@gadzet
Jul 08 2017 13:35
@WAINGOR I think accumulator and currentValue are not set
Stephen James
@sjames1958gm
Jul 08 2017 13:36
@challenger11 Well it is all of those, it is a parameter, operates as a variable and contains the value passed to the function in the first argument.
in this code it assumes that the value passed is a function so a() is calling the passed in function
Bimal Raj Sitaula
@challenger11
Jul 08 2017 13:39
@sjames1958gm thanks but I get it and I don't get it , because I need to practice more.
CamperBot
@camperbot
Jul 08 2017 13:39
challenger11 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8017 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 08 2017 13:40
@challenger11 The a() is unique to the case where the value passed is a function.
WAINGOR
@WAINGOR
Jul 08 2017 13:40
@sjames1958gm your sense of logic is gargantuan. The force is is definitely strong with you. Thnx this works perfectly
CamperBot
@camperbot
Jul 08 2017 13:40
waingor sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8018 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Bimal Raj Sitaula
@challenger11
Jul 08 2017 13:41
@sjames1958gm is this a() common in javascript? I mean is it used frequently as u said its a unique case.
@sjames1958gm is this a() common in javascript? I mean is it used frequently as u said its a unique case.
Stephen James
@sjames1958gm
Jul 08 2017 13:43
@challenger11 Passing functions as arguments is used a lot in javascript for example
arrays sort, map, reduce, forEach, every, some all take a function as a parameter.
My point was calling a() like this is only when a is a function.
gadzet
@gadzet
Jul 08 2017 13:46
@sjames1958gm can you help me with a little thing, i was trying to get div offset inside componentDidMount function using refs in the div, but i can't use it in constructor because it is called on the first render, how could i then get the divs ref from render(), and then pass it into another component ?
Bimal Raj Sitaula
@challenger11
Jul 08 2017 13:46
@sjames1958gm well, so if this function had a name and its not anonymous, will it still take (a) as a function??
Stephen James
@sjames1958gm
Jul 08 2017 13:47
@challenger11 the name of the function outside doesn't matter when passed into the function.
Saif Ur Rahman
@saifsmailbox98
Jul 08 2017 13:48
@challenger11 Just like you pass any other value, in js you can even pass functions, so the parameter takes the value of the function or the definition. If you want to use that function inside you refer to it by the name of the parameter.
Bimal Raj Sitaula
@challenger11
Jul 08 2017 13:50

@sjames1958gm lets say,

function someThing (a) {
console.log (a);
a();
}

will it still be like this?

Stephen James
@sjames1958gm
Jul 08 2017 13:50
@gadzet I believe only in componentDidMount can you get the actual rendered layout including offsets.
I guess you could update the state with the offsets and use them in the next render pass. Interesting problem.
Saif Ur Rahman
@saifsmailbox98
Jul 08 2017 13:50
@challenger11 you can only call a(); if the passed value is a function.
Stephen James
@sjames1958gm
Jul 08 2017 13:50
@challenger11 Assuming you do something like:
someThing(function() { })'

Or

function x() {
}
someThing(x);

In both cases the function will still do a()

Munkhmanlai
@munkhmanlai
Jul 08 2017 13:51
Profile Lookup :confused: :gun: please help wtf is going on?
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUpProfile(firstName, prop){
// Only change code below this line

  for(i=0;i<contacts.length;i++){
    if (firstName==contacts[i].firstName){
      return contacts[i].firstName;
    }else return "No such contact";

    if (prop==contact[i].hasOwnProperty(prop)){
      return contacts[i].prop;
    }else return "No such property";
  }

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
gadzet
@gadzet
Jul 08 2017 13:52
@sjames1958gm I was able to set the state but since it state is async function i was only able to get the state with the callback function in the componentDidMount, could therefore not pass the value inside the render
Bimal Raj Sitaula
@challenger11
Jul 08 2017 13:52
@saifsmailbox98 @sjames1958gm thanks guys, I need to dig little bit more into this??
CamperBot
@camperbot
Jul 08 2017 13:52
challenger11 sends brownie points to @saifsmailbox98 and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: challenger11 already gave sjames1958gm points
:cookie: 738 | @saifsmailbox98 |http://www.freecodecamp.com/saifsmailbox98
Saif Ur Rahman
@saifsmailbox98
Jul 08 2017 13:53
@munkhmanlai You are returning firstName or"No such contact", by checking the first contact object only.
Stephen James
@sjames1958gm
Jul 08 2017 13:53
@gadzet If you update the state, then that value should be available the next time render is called (which I would think is immediately
Saif Ur Rahman
@saifsmailbox98
Jul 08 2017 13:53
@munkhmanlai Also, no need to return the firstName
Stephen James
@sjames1958gm
Jul 08 2017 13:54
@munkhmanlai make sure you use contacts every time.
hasOwnProperty returns true/false - why compare to property name in prop
You are supposed to check hasOwnProperty only when firstName matches then if it exits return the value of the property prop
Diego Mayer
@Chrono79
Jul 08 2017 13:54
@munkhmanlai prop==contact[i].hasOwnProperty(prop) will be false always for that array
it is contacts too
Saif Ur Rahman
@saifsmailbox98
Jul 08 2017 13:54
*exist
Munkhmanlai
@munkhmanlai
Jul 08 2017 13:57
@sjames1958gm ok so am i using .hasOwnProperty on firstName, not on the prop
Stephen James
@sjames1958gm
Jul 08 2017 13:57
@munkhmanlai no, use it on prop - then if true return prop
Munkhmanlai
@munkhmanlai
Jul 08 2017 13:57
@sjames1958gm i thought that is what i did
2895388807
@2895388807
Jul 08 2017 13:58
does anyone can reference "Profile Lookup"in basic java script answer to me ?
Krishna Biradar
@kr5hn4
Jul 08 2017 13:58
@munkhmanlai if you need to check for more than one condition inside an if , you can use logical AND operator, like if(x==1 && y==2) { //do something}
2895388807
@2895388807
Jul 08 2017 13:59
can I reference answer of "Profile Lookup"in basic javascript from you?
too hard
Saif Ur Rahman
@saifsmailbox98
Jul 08 2017 13:59
@munkhmanlai
var myObj = {
  "x": 50,
  "y": 40
  }
myObj.hasOwnProperty("x");  //true
myObj.hasOwnProperty("y");  //true
myObj.hasOwnProperty("z");  //false
dxd1108
@dxd1108
Jul 08 2017 14:00
console.log(str2); 是输出str2的值吧?在哪能看到来的?
Munkhmanlai
@munkhmanlai
Jul 08 2017 14:02
@saifsmailbox98 what is this sorcery?
@saifsmailbox98 @saifsmailbox98 right, i understand what u wrote but can u show me if it is true, then return or do something
@saifsmailbox98 that part where if it true, then return something that part confuses me
Diego Mayer
@Chrono79
Jul 08 2017 14:03
@munkhmanlai You have seen how to do that earlier
Munkhmanlai
@munkhmanlai
Jul 08 2017 14:03
@saifsmailbox98 do u get what i am saying or no?
@Chrono79 did i?
Diego Mayer
@Chrono79
Jul 08 2017 14:03
In Testing Objects for properties
yes
Munkhmanlai
@munkhmanlai
Jul 08 2017 14:04
@Chrono79 damn
Saif Ur Rahman
@saifsmailbox98
Jul 08 2017 14:04
@munkhmanlai check if its hasOwnProperty returns true then return the property.
@dxd1108 in the developer console. https://www.freecodecamp.org/videos/console-and-logging
gadzet
@gadzet
Jul 08 2017 14:06
@sjames1958gm was able to solve it by setting initial value of state to 0 and checking if the state is more than that
Stephen James
@sjames1958gm
Jul 08 2017 14:06
@gadzet :+1:
gadzet
@gadzet
Jul 08 2017 14:07
@sjames1958gm thanks
CamperBot
@camperbot
Jul 08 2017 14:07
gadzet sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8019 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
gadzet
@gadzet
Jul 08 2017 14:07
But is it possible to send the state value to components that are not children
?
Stephen James
@sjames1958gm
Jul 08 2017 14:08
@gadzet There are ways, for example the parent can pass a function that the child calls to pass the value up the hierarchy.j
gadzet
@gadzet
Jul 08 2017 14:14
hmm ok, but i see that you have to have a handling event to do this like onClick, is there something like onRenderSecondTime ? :D :D
probably not but you get what i mean
WAINGOR
@WAINGOR
Jul 08 2017 14:15
Hi all , I want to ask a question on reduce... Suppose I wanted to use only 2 of the four parameters, namely currentvalue and index. Could I do this without specifying the other ones in my function? And if yes, how will JS see which of the four parameters I intend to use?
Example
array.reduce(function(currentval, index) {

}
Diego Mayer
@Chrono79
Jul 08 2017 14:16
@WAINGOR again, the second argument isn't index
check MDN docs
WAINGOR
@WAINGOR
Jul 08 2017 14:17
@Chrono79 please read my question :)
Diego Mayer
@Chrono79
Jul 08 2017 14:17
you can't
WAINGOR
@WAINGOR
Jul 08 2017 14:17
this example is hypothetical
allright, thanks @Chrono79
CamperBot
@camperbot
Jul 08 2017 14:17
waingor sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4470 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Jul 08 2017 14:17
:+1:
maybe map is more suited to do what you want
WAINGOR
@WAINGOR
Jul 08 2017 14:18
@Chrono79 are you saying that in this case I use code like this? Even though I will not use the 2nd parameter?
array.reduce(function(accum, currentval, currentindex) {

}
Diego Mayer
@Chrono79
Jul 08 2017 14:19
what are you trying to do, let's start with that
WAINGOR
@WAINGOR
Jul 08 2017 14:19
I am not aiming for a specific goal here... I just want to get my knowledge right
Diego Mayer
@Chrono79
Jul 08 2017 14:20
yes, you have to define them, even if you don't use them
unless you only want ot use the first 2
2895388807
@2895388807
Jul 08 2017 14:20

//初始化变量
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["Javascript", "Gaming", "Foxes"]
}
];

function lookUp(firstName, prop){
// 请把你的代码写在这条注释以下
while(contacts.hasOwnProperty(firstName)){
return contacts[firstName];
}return "No such contact";

while(contacts.hasOwnProperty(prop)){
  return contacts[prop];
}return "No such property";

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

// 你可以修改这一行来测试你的代码
lookUp("Akira", "likes");

Diego Mayer
@Chrono79
Jul 08 2017 14:21
you can skip the next 2 in that case, but if you want to use the first and the third one, you have to define the second, you can't skip it @WAINGOR
2895388807
@2895388807
Jul 08 2017 14:21
im going crazy
Diego Mayer
@Chrono79
Jul 08 2017 14:21
@2895388807 contacts is an array, it hasn't those properties
use only one loop to run through it
use a for loop instead
2895388807
@2895388807
Jul 08 2017 14:24
ok i try thx man
Munkhmanlai
@munkhmanlai
Jul 08 2017 14:26
:confused: :gun:
Raymond Igle
@r-igle
Jul 08 2017 14:28
@WAINGOR hey, I wonder if pasing in "" or None will work?
Guderian Raborg
@hypercuber
Jul 08 2017 14:46

I am doing this problem https://projecteuler.net/problem=12 and I made a function on how many divisors a number have like 28 have 1,2,4,7,14,28.

function divs(n) { //28 => 6
 let arr = [1];
 for (let i = 2; i <= n/2; i++) {
   if (n % i === 0) {
     arr.push(i);
   }
 }
 arr.push(n);
 return arr.length;
}

The problem is that my function is not fast enough. I found this function

function divs(n) { 
  let nod = 0;
  let sqrt = Math.sqrt(n);
  for (let i = 1; i <= sqrt; i++) {
    if (n % i === 0) {
      nod += 2;
    }
  }
  if (sqrt * sqrt === n) {
    nod--;
  }
  return nod;
}

I dont understand why it uses sqrt(n) and nod += 2. Can someone help me understand this?

Diego Mayer
@Chrono79
Jul 08 2017 14:47
@hypercuber all numbers above sqrt(n) can't divide n exactly
GeorgeII
@GeorgeII
Jul 08 2017 14:53

Hello! My string should include only numbers or brackets or dashes or spaces. Can you help me with RegExp?

var reg = /[\s\d)(-]/;

I want to use test() function for every character of my string but I can't declare RegExp correctly

Stuhl
@Stuhl
Jul 08 2017 14:58
@hypercuber Not fast enough ? You do know that the JS engines would run ur function millions of times if it wanted to ? Making micro perf optimizations is pointless and should only be done on workload heavy things like 3D games or big big databases
Diego Mayer
@Chrono79
Jul 08 2017 14:59
@GeorgeII brackets have a special menaing in regex, you should probably escape them, parentheses too
@Stuhl maybe the tests for that problem time out
What is the value of the first triangle number to have over five hundred divisors?
Diego Mayer
@Chrono79
Jul 08 2017 15:27
@GeorgeII /[\s\d\(\)\-\[\]]/g
Guderian Raborg
@hypercuber
Jul 08 2017 15:28

@Chrono79 Thanks. @Stuhl Well, my divs() function runs okay but all my code to work on that problem in project euler is not fast

function nthLayer(n) {
  return .5 * n * (n + 1);
}
// function divs(n) { //28 => 6
//  let arr = [1];
//  for (let i = 2; i <= n/2; i++) {
//    if (n % i === 0) {
//      arr.push(i);
//    }
//  }
//  arr.push(n);
//  return arr.length;
// }
function divs(n) { 
  let nod = 0;
  let sqrt = Math.sqrt(n);
  for (let i = 1; i <= sqrt; i++) {
    if (n % i === 0) {
      nod += 2;
    }
  }
  if (sqrt * sqrt === n) {
    nod--;
  }
  return nod;
}
function divsNeeded(m) {
  let n = 1
  while (divs(nthLayer(n)) < m) {
    n++;
  }
  return nthLayer(n);
}

console.log(divsNeeded(501));
I need to use another method. I can get some hits here: http://www.mathblog.dk/triangle-number-with-more-than-500-divisors/

CamperBot
@camperbot
Jul 08 2017 15:28
hypercuber sends brownie points to @chrono79 and @stuhl :sparkles: :thumbsup: :sparkles:
:cookie: 169 | @stuhl |http://www.freecodecamp.com/stuhl
:star2: 4471 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Jul 08 2017 15:40
@hypercuber why are you starting with n = 1 in divsNeeded?
you should improve that part
shivam gupta
@shivamg11000
Jul 08 2017 15:42
can anyone explain difference between one way data binding vs two way data binding
Sweet Coding :)
@SweetCodingInc
Jul 08 2017 15:44
@shivamg11000 In what context, template to controller or between two components?
shivam gupta
@shivamg11000
Jul 08 2017 15:44
@SweetCodingInc in comparision to angular vs react
model view controller
Sweet Coding :)
@SweetCodingInc
Jul 08 2017 15:44
@shivamg11000 : Conceptually there is none
in React as well, you have two way and one way binding
if you update something in template, it reflects in your component controller
shivam gupta
@shivamg11000
Jul 08 2017 15:45
whats the meaning of one way an two way data binding
Sweet Coding :)
@SweetCodingInc
Jul 08 2017 15:45
(in case of react, it's not called controller it's just component)
Krishna Biradar
@kr5hn4
Jul 08 2017 15:45
@shivamg11000 oneway data binding is when data flows in one way, two way data binding is when data flows in two ways. In context to MVC, One way binding means that the scope variable in the html will be set to the first value its model is bound to (i.e. assigned to) i.e. Model to View. Two way binding means that the scope variable will change it’s value every time its model is assigned to a different value i.e. Model to View and View to Model.
shivam gupta
@shivamg11000
Jul 08 2017 15:46
after scope nothing understood
data cannot be passed in siblings directly in readct
react*
Sweet Coding :)
@SweetCodingInc
Jul 08 2017 15:47

Let;s assume you have nested components like

<list>
  <list-child from-parent="listItem"></list-child>
</list>

If you enable one way binding for list-child no matter what you do with listItem in list-child component, the reference of it in list will not be affected

that is one way binding
shivam gupta
@shivamg11000
Jul 08 2017 15:48
I dont't know angular
Sweet Coding :)
@SweetCodingInc
Jul 08 2017 15:48
if you allow your list-child to update listItem which is referred to as fromParent in your list-child component, whatever changes you make to fromParent will reflect in listItem of list component
concept is same for both angular and react
shivam gupta
@shivamg11000
Jul 08 2017 15:49
@alpox
alpox
@alpox
Jul 08 2017 15:49
@shivamg11000 sry :D clicked enter too early
@shivamg11000
one-way-binding: component will be updated with data as soon as there is new data. If you type something in the component(input) your data will not update.
two-way-binding: component will be updated with data as soon as there is new data. If you type something in the component (input) your data will be updated with the input data.
gadzet
@gadzet
Jul 08 2017 15:50
any react lifecycle experts here ?
shivam gupta
@shivamg11000
Jul 08 2017 15:50
newbiew @gadzet
Sweet Coding :)
@SweetCodingInc
Jul 08 2017 15:50
@gadzet Shoot
alpox
@alpox
Jul 08 2017 15:51
@shivamg11000 one-way means your data goes only one way - to the element but not back
gadzet
@gadzet
Jul 08 2017 15:51
the problem is that i am getting the offset of the div in the second render and passing it to the parent
shivam gupta
@shivamg11000
Jul 08 2017 15:51
@alpox whats react
one way or two way
gadzet
@gadzet
Jul 08 2017 15:52
in constructor i initialize the value which calls the function
alpox
@alpox
Jul 08 2017 15:52
@shivamg11000 one-way only
gadzet
@gadzet
Jul 08 2017 15:52
but it only returns the first value
from the first render
Sweet Coding :)
@SweetCodingInc
Jul 08 2017 15:52
@shivamg11000 There is a context to one way or two way. Template to component is always 2 way
component to component can be either one way or two way
alpox
@alpox
Jul 08 2017 15:52
@SweetCodingInc In react there is no two-way
shivam gupta
@shivamg11000
Jul 08 2017 15:52
@SweetCodingInc whats Template in MVC
Sweet Coding :)
@SweetCodingInc
Jul 08 2017 15:52
in case of react, even component to component is always one way
alpox
@alpox
Jul 08 2017 15:53
@SweetCodingInc Nope
gadzet
@gadzet
Jul 08 2017 15:53
@shivamg11000 template is V
Sweet Coding :)
@SweetCodingInc
Jul 08 2017 15:53
@shivamg11000 tempalate = view
shivam gupta
@shivamg11000
Jul 08 2017 15:53
but every component is a view
gadzet
@gadzet
Jul 08 2017 15:53
@SweetCodingInc did you check out my problem ?
alpox
@alpox
Jul 08 2017 15:53
@SweetCodingInc In react is NO two-way. At all. Thats one of their selling points ;-)
Sweet Coding :)
@SweetCodingInc
Jul 08 2017 15:53
@gadzet do you have codepen where I can see this problem?
gadzet
@gadzet
Jul 08 2017 15:53
ill make
Sweet Coding :)
@SweetCodingInc
Jul 08 2017 15:54
@alpox okay you win
shivam gupta
@shivamg11000
Jul 08 2017 15:54
React will take lot time to expertisr
parent can pass data to child but child cannot pass data to parent only trigger change in the parent
GeorgeII
@GeorgeII
Jul 08 2017 15:55
@Chrono79 ty. Gonna try it
CamperBot
@camperbot
Jul 08 2017 15:55
georgeii sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4472 | @chrono79 |http://www.freecodecamp.com/chrono79
Sweet Coding :)
@SweetCodingInc
Jul 08 2017 15:56
@gadzet sure
Diego Mayer
@Chrono79
Jul 08 2017 15:56
@GeorgeII that regex is very basic, if you need your brackets and parentheses in the right order, you'll have to use a more complex one
Sweet Coding :)
@SweetCodingInc
Jul 08 2017 15:56
@shivamg11000 on the contrary, react is pretty fast to get started with (as compared to Angular (2+))
shivam gupta
@shivamg11000
Jul 08 2017 15:56
@SweetCodingInc yes
Sweet Coding :)
@SweetCodingInc
Jul 08 2017 15:56
that is exactly why you see too many mediocre devs flaunting react and writing bad code
shivam gupta
@shivamg11000
Jul 08 2017 15:56
@SweetCodingInc until someone sees lifecycles
Sweet Coding :)
@SweetCodingInc
Jul 08 2017 15:57
when they really run into scenario where the seeming two way binding doesn't seem to work....
for example complex nested component hierarchy
shivam gupta
@shivamg11000
Jul 08 2017 15:57
but theres no two way data binding
redux can help here
Guderian Raborg
@hypercuber
Jul 08 2017 15:59
@Chrono79 Instead of one what should I start with? Also I am trying to change my code to have Math.sqrt(n). I gotta go soon so I will do it when I come back. It should look like this:
function nthLayer(n) {
  return .5 * n * (n + 1);
}
function divs(n) { //28 => 6
 let arr = [1];
 for (let i = 2; i <= Math.sqrt(n); i++) {  //what if it is perfect sq ***
   if (n % i === 0) {
     arr.push(i);
   }
 }
 arr.push(n);
 return arr.length;
}
// function divs(n) { //yt || ask why this work  ***
//   let nod = 0;
//   let sqrt = Math.sqrt(n);
//   for (let i = 1; i <= sqrt; i++) {
//     if (n % i === 0) {
//       nod += 2;
//     }
//   }
//   if (sqrt * sqrt === n) {
//     nod--;
//   }
//   return nod;
// }
function divsNeeded(m) {
  let n = 1;
  while (divs(nthLayer(n)) < m) {
    n++;
  }
  return nthLayer(n);
}
console.log(divsNeeded(501));
Sweet Coding :)
@SweetCodingInc
Jul 08 2017 15:59
@shivamg11000 : That is why I am saying over and over again. There is a context to the argument whether there is two way binding in react or not.
Within component, it's always bound two way
between component, it's not (in react)
alpox
@alpox
Jul 08 2017 15:59
Nothing is bound two-way
In react
Just to say it again
Sweet Coding :)
@SweetCodingInc
Jul 08 2017 15:59
In Angular one way or two way is design choice
alpox
@alpox
Jul 08 2017 15:59
Yes in angular
In angular you can easily specify it
gadzet
@gadzet
Jul 08 2017 16:00
Sweet Coding :)
@SweetCodingInc
Jul 08 2017 16:00