These are chat archives for FreeCodeCamp/HelpJavaScript

15th
Aug 2017
eeflores
@eeflores
Aug 15 2017 00:01
goot stuff
CallMeOrange
@EgnaroDev
Aug 15 2017 00:22
good
Phillip Kelley-Dotson
@pkdotson
Aug 15 2017 00:29
go
EgnaroDev @EgnaroDev out
kumquatfelafel @kumquatfelafel in
kumquatfelafel
@kumquatfelafel
Aug 15 2017 00:35

...

actually...

CallMeOrange
@EgnaroDev
Aug 15 2017 00:35
lol?
kumquatfelafel @kumquatfelafel sleeping
hillsie
@Hillsie
Aug 15 2017 01:42

Hi regex guru’s, . Trying to get the below to give me the position of the last space in the string.

var str = “this is my string”;   
/* searching for     ^  space */
 var re = /\s/g;
console.log(str.search(re));

Not sure how to get on top of ASCII Soup. Does anyone have some links to some good tutorials?

fdemaa
@fdemaa
Aug 15 2017 01:46
do you want a asciii table ?
Moisés Man
@moigithub
Aug 15 2017 01:47
must be using regex ?
.lastIndexOf(" ") gives u the position of last space
hillsie
@Hillsie
Aug 15 2017 01:47
Got an ascii table thanks
@moigithub @fdemaa thanks, I eventually used .lastIndexOf(“ “ ) :) But it left me with this void. … duh! ...guess it really doen’t matter then.
CamperBot
@camperbot
Aug 15 2017 01:49
hillsie sends brownie points to @moigithub and @fdemaa :sparkles: :thumbsup: :sparkles:
:star2: 3584 | @moigithub |http://www.freecodecamp.com/moigithub
:cookie: 312 | @fdemaa |http://www.freecodecamp.com/fdemaa
fdemaa
@fdemaa
Aug 15 2017 01:50
@Hillsie i was going to tell you to use lastindexof, to get the ocurrence, but good for you to figure it out ;)
hillsie
@Hillsie
Aug 15 2017 01:51
:) I’ll move on. I got too stuck on trying to solve the problem with a regex solution.
back in the days of Perl, I was happy with regex, but put my tools asside for a PM job. What an unfilfilling role.
Ginger
@GingerChew
Aug 15 2017 02:07
@khaduch Thanks mate, that makes it all make sense!
CamperBot
@camperbot
Aug 15 2017 02:07
gingerchew sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3205 | @khaduch |http://www.freecodecamp.com/khaduch
hillsie
@Hillsie
Aug 15 2017 04:43
<edit text mods> The question suggested using slice but I couldn’t get my head around that. Here is my solution. Any suggestions on how to use slice or how to improve this code.
https://gist.github.com/anonymous/9969221c11740be81618c08ca7c9ab50
Manish Giri
@Manish-Giri
Aug 15 2017 04:54
@Hillsie setup your for loop to increment by a factor of size
then in each iteration, you extract chunks beginning at i till i + size, with .slice()
hillsie
@Hillsie
Aug 15 2017 04:56
@Manish-Giri Have you got an example, because I tried that and I kept iether getting a few empty arrays at the end or not picking up all the elements.
Manish Giri
@Manish-Giri
Aug 15 2017 04:57
@Hillsie I have the solution, can't think of an example right now, it's pretty late, lol..
hillsie
@Hillsie
Aug 15 2017 04:58
:smile: 3pm Aus
Manish Giri
@Manish-Giri
Aug 15 2017 04:59
1 AM here
lol
hillsie
@Hillsie
Aug 15 2017 05:01
About time you find some sleep. I’ll see if some of the Euro people pick it up, or might post again later.
Manish Giri
@Manish-Giri
Aug 15 2017 05:01
maybe you could post your code with .slice()
I'll try to figure out what's wrong
hillsie
@Hillsie
Aug 15 2017 05:04
ok, let have another go.
Actually, I have to go. Thanks for offering @Manish-Giri
CamperBot
@camperbot
Aug 15 2017 05:06
hillsie sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 6415 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Aug 15 2017 05:06
okay
hillsie
@Hillsie
Aug 15 2017 05:09
Be back in an hour, but I gues you’ll be asleep :)
hillsie
@Hillsie
Aug 15 2017 05:17
have extra 5 minutes. What do you know, it’s a lot easier than I thought. Coders block…. this works…
function chunkArrayInGroups(arr, size) {
  /* input: array of letters, size of new array
     return: array chunked into groups based on size, 
      return the last array of elements if group cannot be built from the remaining elements to match size
  */

  var returnArr = [];
   for (var i= 0; i < arr.length; i+=size){
       returnArr.push(arr.slice(i,i+size));

   }
  return returnArr;
}

console.log(chunkArrayInGroups(["a", "b", "c", "d"], 2));
console.log(chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3));
console.log(chunkArrayInGroups([0, 1, 2, 3, 4, 5], 2));
console.log(chunkArrayInGroups([0, 1, 2, 3, 4, 5], 4));
console.log(chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6], 3));
console.log(chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4));
console.log(chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 2));
@Manish-Giri :thumbsup:
Manish Giri
@Manish-Giri
Aug 15 2017 05:18
@Hillsie good job :sparkles:
kumquatfelafel
@kumquatfelafel
Aug 15 2017 05:19
@Hillsie I would avoid calling it returnArr though. For a while, I thought you had mistyped return Arr.push(blahblah), which would do something very different.
Playing off the name of function, how about chunks?
hillsie
@Hillsie
Aug 15 2017 05:21
@kumquatfelafel aah, ok, poor choice for a name. Yip, will take note for future.
prakash chandra yadav
@prakashyadav008
Aug 15 2017 05:31
hey can anyone confirm they r getting different weather animation icons based on their location
badalsaibo
@heyDante
Aug 15 2017 05:40
@prakashyadav008 it works, but the icons looks pixelated. You could make the UI much better.
prakash chandra yadav
@prakashyadav008
Aug 15 2017 05:58
icons are not high resolution
and the icons are used from an api i didnt write the css for it
still a beginer though
Gulsvi
@gulsvi
Aug 15 2017 06:16
@prakashyadav008 The icons are blurry because you set them up as 64x64 pixels in the HTML and then set height: 100% in your CSS, so they expand from 64px to the size of their parent container
.icons>canvas{
  margin-right:10px;
  height:100%; /* this will make your icons blurry */
}
Try: document.getElementById("icons").innerHTML = '<canvas id="clear-day" width=164 height=164></canvas>';
Ankur sharma
@ankur1163
Aug 15 2017 06:23
i am trying to create ui in hotoshop
this is empty layer
how di add white background to it
James Dimitrakopoulos
@JamesDimi
Aug 15 2017 06:24
hello everyone
is anyone here?
kumquatfelafel
@kumquatfelafel
Aug 15 2017 06:25
yup
James Dimitrakopoulos
@JamesDimi
Aug 15 2017 06:25
cool lemme paste some code i wrote
// Write a function reverArray that reverses the given array

function reverseArray(array)
{
    var leftIndex = 0;
    var rightIndex = array.length - 1;

    for(leftIndex = 0; leftIndex < (array.length - 1) / 2; leftIndex++){
        var temp = array[leftIndex];
        array[leftIndex] = array[rightIndex];
        array[rightIndex] = temp;
        --rightIndex;
    }

    return array;
}
it works
but is it stupid?
i wanted to make it fast, so i tried to half the times the code has to loop
but i dont know if its "stupid"
because it may not be readable(understandable) code
Markus Kiili
@Masd925
Aug 15 2017 06:28
@JamesDimi Two indices make it hard to read. I think you could do it using only one index.
James Dimitrakopoulos
@JamesDimi
Aug 15 2017 06:29
@Masd925 the two indexes are crucial since you need both to know which to reverse each time..
Abhinav Mishra
@abhinav-m
Aug 15 2017 06:30
@JamesDimi not really..
@JamesDimi i thought you were using two indexes because you wanted to make n/2 iterations over your array
James Dimitrakopoulos
@JamesDimi
Aug 15 2017 06:31
@abhinav-thinktank thats what i use them for
n / 2 loops
Abhinav Mishra
@abhinav-m
Aug 15 2017 06:31
@JamesDimi you could just start from the end of your array and push everything into a new array
Manish Giri
@Manish-Giri
Aug 15 2017 06:31
@abhinav-thinktank :wave:
Abhinav Mishra
@abhinav-m
Aug 15 2017 06:31
@Manish-Giri :wave: Independance day mubarak!
Markus Kiili
@Masd925
Aug 15 2017 06:33
@JamesDimi One index is enough (could be refactored still):
function reverseArray (arr) {
  var len = arr.length;
  for (var i=0; i<(arr.length-1)/2; i++) {
    var temp = arr[len-1-i];
    arr[len-1-i] = arr[i];
    arr[i] = temp;
  }
  return arr;
}
Abhinav Mishra
@abhinav-m
Aug 15 2017 06:33
ya or this solution ^
Manish Giri
@Manish-Giri
Aug 15 2017 06:33
@abhinav-thinktank same to u
@abhinav-thinktank truth
Abhinav Mishra
@abhinav-m
Aug 15 2017 06:34
:'D
too true
Manish Giri
@Manish-Giri
Aug 15 2017 06:35
:smiling_imp:
Abhinav Mishra
@abhinav-m
Aug 15 2017 06:35
roz raatko sone se pehle socho kal jaldi uthuga :'(
Manish Giri
@Manish-Giri
Aug 15 2017 06:35
Lol
kumquatfelafel
@kumquatfelafel
Aug 15 2017 06:35
@abhinav-thinktank the thing with this is, if we want it to behave the same as the reverse method, then it has to modify the original array. Pushing everything into a new array won't do this. Granted, we don't necessarily need it to behave the same.
Abhinav Mishra
@abhinav-m
Aug 15 2017 06:36
@kumquatfelafel yup thats true
Manish Giri
@Manish-Giri
Aug 15 2017 06:38
@abhinav-thinktank raat ke 3 bajne wale hai, kuch nahi hai ghar mein banane ko and bhook bhi lagi hai..maagi zindabad
Abhinav Mishra
@abhinav-m
Aug 15 2017 06:39
udhar bhi maggi?
hai?
Manish Giri
@Manish-Giri
Aug 15 2017 06:39
Yep
Abhinav Mishra
@abhinav-m
Aug 15 2017 06:39
cool
Manish Giri
@Manish-Giri
Aug 15 2017 06:40
Maggi and N Modi
2 things which are everywhere
Abhinav Mishra
@abhinav-m
Aug 15 2017 06:40
:P
Manish Giri
@Manish-Giri
Aug 15 2017 06:40
Lol
hillsie
@Hillsie
Aug 15 2017 06:41
@kumquatfelafel I was going to say that too, you could use the reverse method.
James Dimitrakopoulos
@JamesDimi
Aug 15 2017 06:42
ah right
thanks everyone
actually
wait a minute
you are using 2 indexes too :P
hillsie
@Hillsie
Aug 15 2017 06:44
give me a sec.
Abhinav Mishra
@abhinav-m
Aug 15 2017 06:44
hes using one index, referencing other by subtracting on each iteration
Markus Kiili
@Masd925
Aug 15 2017 06:44
@JamesDimi I meant that you are incrementing two indices there.
Same thing but somewhat easier to read.
Abhinav Mishra
@abhinav-m
Aug 15 2017 06:45
no need to explicitly declare and increment/decrement both
James Dimitrakopoulos
@JamesDimi
Aug 15 2017 06:46
ah ok thanks @Masd925 @abhinav-thinktank :D
CamperBot
@camperbot
Aug 15 2017 06:46
jamesdimi sends brownie points to @masd925 and @abhinav-thinktank :sparkles: :thumbsup: :sparkles:
:cookie: 502 | @abhinav-thinktank |http://www.freecodecamp.com/abhinav-thinktank
:star2: 4414 | @masd925 |http://www.freecodecamp.com/masd925
hillsie
@Hillsie
Aug 15 2017 06:46
Am I missing the point?
var array = [1,2,3,4,5,6,7];
var newArray = array.slice().reverse();
console.log(newarray);
Abhinav Mishra
@abhinav-m
Aug 15 2017 06:46
@Hillsie yeah..
Manish Giri
@Manish-Giri
Aug 15 2017 06:47
I think he meant to reverse it manually
Abhinav Mishra
@abhinav-m
Aug 15 2017 06:47
if you wanted to use that you could just return arr.reverse()
hillsie
@Hillsie
Aug 15 2017 06:47
Oh, ok
yip, I could shorten it.
Abhinav Mishra
@abhinav-m
Aug 15 2017 06:47
yup.. it mutates the array so you don't need to store it in a variable
also dont need the slice
hillsie
@Hillsie
Aug 15 2017 06:49
yip for illustration purposes.
console.log([1,2,3,4,5,6,7].reverse());
Abhinav Mishra
@abhinav-m
Aug 15 2017 06:50
@Hillsie :+1:
James Dimitrakopoulos
@JamesDimi
Aug 15 2017 06:50
sorry i didnt mention it, but we were meant to create our own reverse, without the reverse() function
hillsie
@Hillsie
Aug 15 2017 06:51
:)
James Dimitrakopoulos
@JamesDimi
Aug 15 2017 06:51
:D
Btw if you are interested in a free good JS book here is a link: http://eloquentjavascript.net/
well, thats what i actually follow xD
Joseph
@revisualize
Aug 15 2017 06:55
@JamesDimi I was recommended by a Sr Dev friend to look at: https://www.gitbook.com/book/frontendmasters/front-end-handbook-2017/details
@JamesDimi && You don't know JS
James Dimitrakopoulos
@JamesDimi
Aug 15 2017 06:56
@revisualize i know that i dont know js... u dont need to be mean about it :(
James Dimitrakopoulos
@JamesDimi
Aug 15 2017 06:56
@revisualize haha right i know this one, was just joking :D
CamperBot
@camperbot
Aug 15 2017 06:57
sorry jamesdimi, you can't send brownie points to yourself! :sparkles: :sparkles:
James Dimitrakopoulos
@JamesDimi
Aug 15 2017 06:57
@revisualize thanks for the first one, didn't know that one! :D
Abhinav Mishra
@abhinav-m
Aug 15 2017 06:58
eloquent is really good
Joseph
@revisualize
Aug 15 2017 06:58
@camperbot sudo !!
James Dimitrakopoulos
@JamesDimi
Aug 15 2017 06:58
ill totally check it out once im done with the book im working on :D
Abhinav Mishra
@abhinav-m
Aug 15 2017 06:58
:+1:
Joseph
@revisualize
Aug 15 2017 06:58
ACK!
Give me my brownie you silly bot!
James Dimitrakopoulos
@JamesDimi
Aug 15 2017 06:58
@revisualize THANKS
CamperBot
@camperbot
Aug 15 2017 06:58
jamesdimi sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4434 | @revisualize |http://www.freecodecamp.com/revisualize
James Dimitrakopoulos
@JamesDimi
Aug 15 2017 06:58
there ya go xD
Joseph
@revisualize
Aug 15 2017 06:58
@JamesDimi LOL! That bot!
James Dimitrakopoulos
@JamesDimi
Aug 15 2017 06:58
trollbot
Joseph
@revisualize
Aug 15 2017 06:58
@JamesDimi I'm trying to keep my streak alive for 365 days
:D
James Dimitrakopoulos
@JamesDimi
Aug 15 2017 06:59
@revisualize haha im suprised you actually are able to.. This place used to be more crowded :/
Joseph
@revisualize
Aug 15 2017 06:59
@JamesDimi Yeah, chat participation has dropped off a TON!
Everyone is moving to the forum.
kumquatfelafel
@kumquatfelafel
Aug 15 2017 07:00
I've never been a big fan of forums... too clicky.
James Dimitrakopoulos
@JamesDimi
Aug 15 2017 07:00
yeah i read the post which Quincy replied to considering the chat button. But still its way more fun and interactive on gitter
Manish Giri
@Manish-Giri
Aug 15 2017 07:02
@abhinav-thinktank another one
Abhinav Mishra
@abhinav-m
Aug 15 2017 07:05
@Manish-Giri i wanna laugh
but it makes me cry
lol
Manish Giri
@Manish-Giri
Aug 15 2017 07:05
Lol
James Dimitrakopoulos
@JamesDimi
Aug 15 2017 07:06
may be stupid to ask but is Computer Science considered an "Engineering" class?
This message was deleted
Manish Giri
@Manish-Giri
Aug 15 2017 07:07
One of the fields, yes
Markus Kiili
@Masd925
Aug 15 2017 07:10
@JamesDimi If you do requirements and specifications to the level that actual code can be produced mechanically, then it goes under Engineering. Otherwise under Fine arts.
Abhinav Mishra
@abhinav-m
Aug 15 2017 07:12
lol
James Dimitrakopoulos
@JamesDimi
Aug 15 2017 07:12
what do you mean by "actual code can be produced mechanically"
you mean create a machine that writes code?
Markus Kiili
@Masd925
Aug 15 2017 07:13
@JamesDimi 20 years ago at least in java world, the tendency was to write so specific requirements that the pruduction of classes and code could be automated.
James Dimitrakopoulos
@JamesDimi
Aug 15 2017 07:15
aha thats interesting
Pethaf
@Pethaf
Aug 15 2017 07:19
There can be only one batman.
Pethaf
@Pethaf
Aug 15 2017 07:25
Oh, the CEO of intel is a chemist.
That was unexpected.
Letty
@SimpleProgrammerL
Aug 15 2017 07:41
Where is this mistake?
for (var i = 0;i < multiplyAll.length;i++){
for (var j = 0;j < multiplyAll[i].length; j++){
product*= multiplyAll[i][j];
}
}
kumquatfelafel
@kumquatfelafel
Aug 15 2017 07:41
@SimpleProgrammerL do you have a return statement?
hillsie
@Hillsie
Aug 15 2017 07:41
@Masd925 glad that didn’t last. We’d be automated out of coding.
kumquatfelafel
@kumquatfelafel
Aug 15 2017 07:41
and do you define product?
Blauelf
@Blauelf
Aug 15 2017 07:42
@SimpleProgrammerL The array is not multiplyAll, but arr. multiplyAll is the function. Even though that one has a length property, this is the number of named parameters.
Letty
@SimpleProgrammerL
Aug 15 2017 07:42

function multiplyAll(arr) {
var product = 1;

for (var i = 0;i < multiplyAll.length;i++){
for (var j = 0;j < multiplyAll[i].length; j++){
product*= multiplyAll[i][j];
}
}

return product;
}
multiplyAll([[1,2],[3,4],[5,6,7]]);

kumquatfelafel
@kumquatfelafel
Aug 15 2017 07:43
:point_up: This, too, would be problematic
multiplyAll is the name of the function. The array, [[1,2],[3,4],[5,6,7]], is being passed into the parameter named arr.
Letty
@SimpleProgrammerL
Aug 15 2017 07:45
I've learned
thanks
Blauelf
@Blauelf
Aug 15 2017 07:46
:+1:
hillsie
@Hillsie
Aug 15 2017 07:50
I’m also in favour of gitter. What was the problem with using it that was pointed out?
EpicTriffid
@EpicTriffid
Aug 15 2017 07:59
Morning all!
hillsie
@Hillsie
Aug 15 2017 08:13
G’day. off to put some dinner together here.
Thayyeb salim
@Thayyebsalim
Aug 15 2017 08:15
@Hillsie Have fun
EpicTriffid
@EpicTriffid
Aug 15 2017 08:41
Right, so Im still utterly stumped on the logic behind the Missing Letters task
function fearNotLetter(str) {
  var uni = [];
  for (var i = 0; i < str.length; i++) {
    uni.push(str.charCodeAt(i));
    if (uni[i-1] != uni[i+1]) {
      return uni[i];
    }

  }
}

fearNotLetter("abce");
I know I'm comparing against the previous charcode value, but I dont know how to word that
Markus Kiili
@Masd925
Aug 15 2017 08:55
@EpicTriffid No need for that array. You can just loop the characters and check if the charcode is one above the previous and figure out what to return if it is not.
Another way is to check the charcode of the first letter and then you know that charcodes should be first+i, and compare against that.
EpicTriffid
@EpicTriffid
Aug 15 2017 09:01
@Masd925 I can work with that! thankyou"!
CamperBot
@camperbot
Aug 15 2017 09:01
epictriffid sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4415 | @masd925 |http://www.freecodecamp.com/masd925
kumquatfelafel
@kumquatfelafel
Aug 15 2017 09:10
:point_up: small note here, regardless of which of two you choose, be careful of starting point. You don't want to compare with a value from nonexistent string index.
namethatisnottaken
@namethatisnottaken
Aug 15 2017 09:11
 $("#progressSign").html("Do your thing !");

    minutes = parseInt(sessionTimerInterval / 60, 10);
    seconds = parseInt(sessionTimerInterval % 60, 10);

    minutes = minutes < 10 ? "0" + minutes : minutes;
    seconds = seconds < 10 ? "0" + seconds : seconds;
    $("#minutes").html(minutes);
    $("#seconds").html(seconds);
    //battery progress
    let decrementWidth = (1/sessionTimerInterval) * 100;
    currentBatteryWidth -= decrementWidth;
    //alert(currentBatteryWidth);
    $(".myBar").css("width", currentBatteryWidth);

    if (--sessionTimerInterval < 0) {
      clearInterval(sessionMinutes);
      alertBreak();
    }
hi anyone can help making a progress bar for this code?
the starting css width should be hundred and by the time it finish it has to reach 0
not sure how to do it haha
EpicTriffid
@EpicTriffid
Aug 15 2017 09:13
@kumquatfelafel Hi there waves I'll bear that in mind
Gokula Krishna
@AKX-X-32
Aug 15 2017 09:53
@sjames1958gm thanks for the review
CamperBot
@camperbot
Aug 15 2017 09:53
akx-x-32 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8318 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 15 2017 10:16
@AKX-X-32 :+1:
EpicTriffid
@EpicTriffid
Aug 15 2017 10:20
Nope, hella stuck
I just cannot seem to make sense of the syntax
EpicTriffid
@EpicTriffid
Aug 15 2017 10:26
I've been trying to type out the logic about 5 or 6 times and keep deleting it.
Stephen James
@sjames1958gm
Aug 15 2017 10:27
@EpicTriffid You don't have to start your loop from 0, you could save off the charCode of str[0] (+ 1)
then loop starting at one - if the current charCode matches the stored one then save the current (+1)and loop again
Otherwise you have the answer.
EpicTriffid
@EpicTriffid
Aug 15 2017 10:31
@sjames1958gm Right, I'll try putting that down
Stephen James
@sjames1958gm
Aug 15 2017 10:33
@EpicTriffid Think about how you would do it . for "abce"
Ok there is an a (b should be next), ah b (c should be next), ah c (d should be next), ah e, hey where's my effin 'd' who took my 'd' !!
Just doing it with charCode because adding is easier.
EpicTriffid
@EpicTriffid
Aug 15 2017 10:33
@sjames1958gm Hahaha, thankyou, that gave me a chuckle
CamperBot
@camperbot
Aug 15 2017 10:33
epictriffid sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8319 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 15 2017 10:35
@EpicTriffid :)
Kei Nart
@codenart
Aug 15 2017 10:42
Hi.
Anyone w/ deep react experience?
I need help reviewing my code. :worried:
Fernando
@lestairon
Aug 15 2017 10:50
image.png
Lol????
Anyone knows why is it working?
I didn't expect that
Kei Nart
@codenart
Aug 15 2017 10:52
It's about magic :sparkles:
Fernando
@lestairon
Aug 15 2017 10:53
Haha, i tried to do an infinite loop, but it seems like i failed
Stephen James
@sjames1958gm
Aug 15 2017 11:04
@lestairon don't increment n - but do increment i (i++)
kumquatfelafel
@kumquatfelafel
Aug 15 2017 11:11
@lestairon it's not an infinite loop because in second iteration, when i is 1 and n is 2,
i = 1 + 2, which is three.
n = 2 + 1, which is also three.
Since 3 is not less than 3, the loop ends as the condition necessary for continuation is no longer met.
Stephen James
@sjames1958gm
Aug 15 2017 11:12
@codenart You are using a lot of jquery in your React to manipulate the DOM.
Also, you have one component handling the button clicks of another component?
Components should be more self contained.
@lestairon If you wanted an infinite loop i++ and n++ would do it, or do nothing in the loop
Kei Nart
@codenart
Aug 15 2017 11:13
@sjames1958gm Is it a bad practice fusing jQuery /w React?
kumquatfelafel
@kumquatfelafel
Aug 15 2017 11:14
or
i = n;
n++;
etc. Many ways to accomplish. Though, really the simplest would just be
while(true) {
  blahblahblah
}
Stephen James
@sjames1958gm
Aug 15 2017 11:17
@codenart Using jquery sparingly is probably ok, but not to the level that you have.
Kei Nart
@codenart
Aug 15 2017 11:20
@sjames1958gm ok. I'm gonna do the enhancement to next coming prj.
Kei Nart
@codenart
Aug 15 2017 11:34
@sjames1958gm I've a small question.
I wonder how to have the parent component handle submitted data from a child component (which is a form)
George Kech.
@georgemitnick
Aug 15 2017 11:38
Guys this code :

Guys, why this code:

var john = {
    age: 28,
    height: 185,
    points: function () {
        return this.height + this.age * 5;
    }
};

console.log(john.points);

prints this on the chrome console:

ƒ () {
        return this.height + this.age * 5;
    }
kumquatfelafel
@kumquatfelafel
Aug 15 2017 11:41
@georgemitnick console.log(john.points());
Markus Kiili
@Masd925
Aug 15 2017 11:41
@georgemitnick Yes, property value is a function (method).
George Kech.
@georgemitnick
Aug 15 2017 11:41
Why do we need the extra ()
aha
kumquatfelafel
@kumquatfelafel
Aug 15 2017 11:41
@georgemitnick john.points holds reference to function. () actually invokes function
George Kech.
@georgemitnick
Aug 15 2017 11:42
Thanks guys
kumquatfelafel
@kumquatfelafel
Aug 15 2017 11:42
np
George Kech.
@georgemitnick
Aug 15 2017 11:45
I have another question
why does it have to be returned?
why do we have to use "return" in other words. Can't it work without return?
Ronique Ricketts
@RoniqueRicketts
Aug 15 2017 11:48
Will Fetch replace Xmlhttprequest ?
kumquatfelafel
@kumquatfelafel
Aug 15 2017 11:50

@georgemitnick without an explicit return statement, function will return undefined by default.

Which would result in undefined getting printed in console.

George Kech.
@georgemitnick
Aug 15 2017 11:50
But why? No one really knows?
kumquatfelafel
@kumquatfelafel
Aug 15 2017 11:51
In any case, this return statement is how one actually extracts a value from the function.
George Kech.
@georgemitnick
Aug 15 2017 11:51
Functions always have to be returned?
Thayyeb salim
@Thayyebsalim
Aug 15 2017 11:52
no
kumquatfelafel
@kumquatfelafel
Aug 15 2017 11:52
As stated, you don't need to include a return statement, but then the function will return undefined.
George Kech.
@georgemitnick
Aug 15 2017 11:53
Then what's the purpose of the function if it's not to extra a value?
Markus Kiili
@Masd925
Aug 15 2017 11:53
@georgemitnick Functions can return something or cause side effects.
kumquatfelafel
@kumquatfelafel
Aug 15 2017 11:54
whoops. bad example
George Kech.
@georgemitnick
Aug 15 2017 11:55
in my case the return assigns the value to the function "points"?
Markus Kiili
@Masd925
Aug 15 2017 11:55
@kumquatfelafel forEach is better ;)
George Kech.
@georgemitnick
Aug 15 2017 11:55
So now function points holds that value?
Blauelf
@Blauelf
Aug 15 2017 11:55
console.log returns undefined, too.
kumquatfelafel
@kumquatfelafel
Aug 15 2017 11:55
@Masd925 yeah, that's the one I was thinking of.
lol
Markus Kiili
@Masd925
Aug 15 2017 11:55
@georgemitnick It the function returns something we need, we store or use the return value. If it doesn't, we just call it.
George Kech.
@georgemitnick
Aug 15 2017 11:56
@Masd925 Give me an example.
Two type of functions
Markus Kiili
@Masd925
Aug 15 2017 12:02
function double (num) {
  return 2*num;
}

function doubleArr(arr) {
  for (var i=0; i<arr.length; i++) arr[i]*=2;
}

console.log(double(5)); // logs: 10

var arr = [1,2];
doubleArr(arr); 
console.log(arr); // logs: [2,4]
kumquatfelafel
@kumquatfelafel
Aug 15 2017 12:02
function printHello() {
  console.log("Hello");
}

Only purpose is to print hello to console. We don't really need any kind of return here. The only output we really need is already showing up in console.

function is3(num) {
  return num === 3;
}

Here, we want to know if a number is 3. Thus we need some information to that effect being returned from the function.

Markus Kiili
@Masd925
Aug 15 2017 12:03
@georgemitnick So double returns a value that we use (we log it). doubleArr doesn't have a return. It just mutates the array that is passed as an argument.
George Kech.
@georgemitnick
Aug 15 2017 12:04
I see. The one just prints something the other one actually produces a value that it has to be returned @kumquatfelafel
@Masd925 The second one has to be called as to be executed?
kumquatfelafel
@kumquatfelafel
Aug 15 2017 12:05

It just mutates the array that is passed as an argument.

(and here it could return array if you wanted to, but it doesn't really have to since original array is being mutated) :point_down:

Markus Kiili
@Masd925
Aug 15 2017 12:05
@georgemitnick Both functions need to be called in order for them to be executed.
@georgemitnick doubleArr(arr); evaluates to undefined but the value is ignored.
kumquatfelafel
@kumquatfelafel
Aug 15 2017 12:07
Pretty much, any function can have a return statement, but it's up to the discretion of coder as to whether or not to include one.
Kei Nart
@codenart
Aug 15 2017 12:08
Any experienced react? :sparkles:
I've a small small small question :smile:
George Kech.
@georgemitnick
Aug 15 2017 12:08
hmmm so doubleArr(arr); passes the argument to the functions parameter
Markus Kiili
@Masd925
Aug 15 2017 12:09
@georgemitnick Yes.
George Kech.
@georgemitnick
Aug 15 2017 12:09
Cool, thanks guys.
Tai Jones
@taiJones00
Aug 15 2017 12:11
Hint #1: Here's a URL you can use to get a random Wikipedia article: https://en.wikipedia.org/wiki/Special:Random.
Where in the article does it say you can use this special:random format
There's not action or format parameter or any of the others
Kei Nart
@codenart
Aug 15 2017 12:14
handleOnClick = e => {
   // do something
}

render = () -> {
   <div onClick={ this.handleOnClick }></div>
}

AND

componentDidMount = () => {
   $(this.clickableEle).on('click', (e) => {
      // do something
   });
}

render = () -> {
   <div ref={ ele => { this.clickableEle = ele; } }></div>
}

I need to compare the performance between these two approaches.

kumquatfelafel
@kumquatfelafel
Aug 15 2017 12:15

Though yeah, when you're manipulating primitive values a function, you're generally going to want a return statement in function.

Here's an example where return statement isn't included to see what happens.

function add8 (num) {
  num = num + 8;
}

var num = 9;
add8(num);
console.log(num); //outputs 9.

num = num + 8;
console.log(num); //outputs 17.

console.log(add8(num)); //outputs undefined

The num parameter of function add8 is not the same as the num that has been initialized to 9 underneath it. Only the value gets passed to the function, and is stored in different variable. So when you modify this variable, you're not really doing anything that would have an affect on code outside of scope of function.

Fernando
@lestairon
Aug 15 2017 12:21
Thanks, haha
Now i know what i was doing wrong
Alaa H. Youssef
@alaahamdyy26
Aug 15 2017 12:47
hi :)
pls tell me what you think
sorry i meant this one
the other one is not ready yet!just started with it
Blauelf
@Blauelf
Aug 15 2017 12:53
@alaahamdyy26 Why the quotation marks above the block containing the actual quote? If you want some, shouldn't they be around the quote?
The "Add a Quote" doesn't work.
Text in tweet is undefinedundefined :-/
Alaa H. Youssef
@alaahamdyy26
Aug 15 2017 13:06
Add a quote works for me
@Blauelf
will re check
Blauelf
@Blauelf
Aug 15 2017 13:11
On clicking "Add Quote", I receive ReferenceError: quote is not defined, which seems reasonable to me, as there's no array of that name.
Alaa H. Youssef
@alaahamdyy26
Aug 15 2017 13:17
Yes correct
i forgot i added the API
that y this stopped working
it was working while i had an array of quotes
but i dont get why "tweet out" stopped working as well!!!
Blauelf
@Blauelf
Aug 15 2017 13:21

I used

    $.getJSON(url, function (data) {
      $('#quotes').html((randomQuote=data.quoteText)+ "-" +(randomAuthor=data.quoteAuthor));
    });

and it somewhat worked. You could also place the assignments outside (still within same function), I was just too lazy to add more lines.

Aniculaesei
@Aniculaesei
Aug 15 2017 13:24
@Blauelf THANKS!!!
CamperBot
@camperbot
Aug 15 2017 13:24
aniculaesei sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4567 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Aug 15 2017 13:24
What for?
EpicTriffid
@EpicTriffid
Aug 15 2017 13:24
I was wondering, when i use the below code, I don't quite understand how code (the current element the loop is going over) equals element 0 + "i"? I dont understand what "i" means here.
Alaa H. Youssef
@alaahamdyy26
Aug 15 2017 13:25
@Blauelf THANKS!! :D It worked
CamperBot
@camperbot
Aug 15 2017 13:25
alaahamdyy26 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4568 | @blauelf |http://www.freecodecamp.com/blauelf
EpicTriffid
@EpicTriffid
Aug 15 2017 13:25

function fearNotLetter(str) {
  for (var i = 0; i < str.length; i++) {
    var code = str.charCodeAt(i);
    if (code !== str.charCodeAt(0) + i) {
      return String.fromCharCode(code - 1);
    }
  }
}

fearNotLetter("abce");
Markus Kiili
@Masd925
Aug 15 2017 13:26
@Blauelf I watched Snake in the eagles shadow again. I had totally forgotten that he combined Cats claw with Snake fist.
Blauelf
@Blauelf
Aug 15 2017 13:27
@EpicTriffid i is the position within the string. For all characters before the missing one, the char code is the char code of the first character plus the position. After, it's one ahead (therefore the -1 to adjust)
@Masd925 I am so much into cats that I mostly remembered the cat claw :P
EpicTriffid
@EpicTriffid
Aug 15 2017 13:29
So i, without being linked to an array/string, just signifies the position the loop has reached?
Stephen James
@sjames1958gm
Aug 15 2017 13:32
@codenart I had to go off-line I hope you got an answer, but you can pass callback functions as props to the child
Blauelf
@Blauelf
Aug 15 2017 13:34
@EpicTriffid It's your loop's counter, going from 0 to str.length-1, and you use it for the position within the string in str.charCodeAt(i). So you use it for the position, it's not linked.
Stephen James
@sjames1958gm
Aug 15 2017 13:35
@EpicTriffid Yes.
i is just a number goes from 0 to str.length - 1 - you can of course use it to access str.
but, you can also use it to determine how far you are into the string
Blauelf
@Blauelf
Aug 15 2017 13:37
@EpicTriffid Unlike a for..of loop, which lets you iterate over the values, you deal with the index here (assuming numeric indices from 0 to str.length-1, and determine the corresponding character manually.
So i is just a number.
EpicTriffid
@EpicTriffid
Aug 15 2017 13:41
@sjames1958gm @Blauelf Right, that works in my head. Its just a counter. So, leading on from that, if, for example, str.charCodeAt(i) is currently at the second element in the array (98), how does that then equal str.charCodeAt(0) + i (which i assume would be 97 + 1)?
Oh, I've just read what i wrote
97+1 = 98
Is it really that simple?
Blauelf
@Blauelf
Aug 15 2017 13:42
Yes, it is.
You add one to the position and expect the char code to change by one as well. If it changes by two, you've found the place where the missing letter should have been.
EpicTriffid
@EpicTriffid
Aug 15 2017 13:43
facepalm
Thankyou
Blauelf
@Blauelf
Aug 15 2017 13:43
Sometimes the simplest things aren't that easy.
EpicTriffid
@EpicTriffid
Aug 15 2017 13:43
I appreciate you taking the time to explain it to me
also, so if for..of loops allow you to deal with the values, and for loops allow you to deal with the index, what do for..in loops allow you to look at?
Markus Kiili
@Masd925
Aug 15 2017 13:50
@EpicTriffid Loop through property keys of enumerable properties of the object (and prototype chain).
Blauelf
@Blauelf
Aug 15 2017 13:51
They are for looping over enumerable properties. Like
var dict = {"a":"alpha","b":"bravo","c":"charlie"};
for (var key in dict) {
  console.log(key);
}
a
b
c
Note that for..in also loops over inherited enumerable properties. If somebody added an enumerable property to Object.prototype, it would show up in all objects inheriting from Object.prototype (which are most, unless you used something like Object.create(null))
Huỳnh Trần Khanh
@khanh2003
Aug 15 2017 13:55
Can you explain this line (in regenerator-runtime)?
  var undefined; // More compressible than void 0.
EpicTriffid
@EpicTriffid
Aug 15 2017 13:59
@Masd925 @Blauelf Awesome
The count of i: Does that also start at 0?
Nvm, I worked it out
I thought it would be working out there was a discrepancy when it reached "C", but it actually works it out when it reachs "e"
EpicTriffid
@EpicTriffid
Aug 15 2017 14:04
@Blauelf Also, why is it important that they are "enumerable" properties. I come across it alot
Guderian Raborg
@hypercuber
Aug 15 2017 14:05
Can someone help me rotate my little square 90 degree with left or right click?
EpicTriffid
@EpicTriffid
Aug 15 2017 14:12
@hypercuber I'm not really experienced enough to give this any credence, but I believe you can set actions based on keypresses. Lemme find it
Markus Kiili
@Masd925
Aug 15 2017 14:13
@EpicTriffid Enumerable properties are those that you like to iterate over. You don't wan't some propery keys like toString to appear there. Properties that you assign yourself are by default enumerable and built-in ones are non-enumerable.
EpicTriffid
@EpicTriffid
Aug 15 2017 14:15
@hypercuber So you're looking for the .keypress event and your keycodes to activate your left or right rotations can be found here: http://keycode.info/
EpicTriffid
@EpicTriffid
Aug 15 2017 14:16
@Chrono79 Ah, that looks simpler. @hypercuber Do what Diego said!
@Masd925 Poifect
soulproprietor
@soulproprietor
Aug 15 2017 14:17

Good morning! I have a question:
how can I store the HARD VALUE of a path from an object to a variable, and not store the PATH to the variable?

example of what I DONT want:

relationships.matches[0] = animals[3].username;
I want to use this object inside the animals object so I can't use the animals object as a reference
Blauelf
@Blauelf
Aug 15 2017 14:18
@khanh2003 This declares a variable of name undefined and value undefined. Contrary to popular believe, undefined is not a keyword, but a global variable, and at the same time a property of the global object (window.undefined in a browser). That means that one might define their own undefined variable, with arbitrary value, which could lead to strange behaviour. To avoid using such a variable defined in an outer scope, some people use void 0 instead (the unary void operator turns anything into undefined), or a variable that has not been initialised (I think that's what you see there).
soulproprietor
@soulproprietor
Aug 15 2017 14:19
I want the VALUE of
```animals[3].username
not the path
Diego Mayer
@Chrono79
Aug 15 2017 14:19
@hypercuber you would also want to make your square not so symmetric so you actually see if it's rotated ;)
korzo
@korzo
Aug 15 2017 14:19
@soulproprietor Either use eval or function returning value from given object
George Kech.
@georgemitnick
Aug 15 2017 14:20
Guys, will this loop assign the value of the first array to the second one?
var yearsOfBirth = [1990, 2000, 1986, 2001];

var transfered = [];

for (var i = 0; i < yearsOfBirth.length; i++) {
    yearsOfBirth[i] = transfered[i];
}
korzo
@korzo
Aug 15 2017 14:22
@georgemitnick shouldn't it be transfered[i] = yearsOfBirth[i]; ?
Diego Mayer
@Chrono79
Aug 15 2017 14:22
@georgemitnick you have it the other way around as @korzo pointed it out
George Kech.
@georgemitnick
Aug 15 2017 14:22
@korzo What's the difference?
Diego Mayer
@Chrono79
Aug 15 2017 14:23
assignment goes from right to left of the = sign
George Kech.
@georgemitnick
Aug 15 2017 14:23
oh. The first one will be the one receiving the values
yeah yeah
let me try it
Diego Mayer
@Chrono79
Aug 15 2017 14:23
if you want a copy of an array you could use slice()
George Kech.
@georgemitnick
Aug 15 2017 14:24
transfered.slice(yearsOfBirth[i]): ?
; not :
Diego Mayer
@Chrono79
Aug 15 2017 14:24
transfered = yearsOfBirth.slice();
George Kech.
@georgemitnick
Aug 15 2017 14:25
hmmm
OK. I'll try that too.
Diego Mayer
@Chrono79
Aug 15 2017 14:27
That'll work if your array contains strings, booleans or numbers, if it has arrays or objects it won't be a separate copy, read mdn docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
George Kech.
@georgemitnick
Aug 15 2017 14:27
It's not an object
the console.log(transfered[i]); gives them the value of undefined
what's wrong?
Diego Mayer
@Chrono79
Aug 15 2017 14:28
show your code
George Kech.
@georgemitnick
Aug 15 2017 14:29
var yearsOfBirth = [1990, 2000, 1986, 2001];

var transfered = [];

for (var i = 0; i < yearsOfBirth.length; i++) {
    transfered = yearsOfBirth.slice();
}

console.log(transfered[i]);
Diego Mayer
@Chrono79
Aug 15 2017 14:30
@georgemitnick transfered = yearsOfBirth.slice(); should be done only once and i outside your loop is greater than yearsOfBirth.length
that's why you get undefined
George Kech.
@georgemitnick
Aug 15 2017 14:30
So, I can't really use slice with the loop?
Diego Mayer
@Chrono79
Aug 15 2017 14:31
var yearsOfBirth = [1990, 2000, 1986, 2001];

var transfered = yearsOfBirth.slice();

for (var i = 0; i < yearsOfBirth.length; i++) { // you could use transfered.length but because transfered is a copy of yearsOfBirth their length is the same
    console.log(transfered[i]);
}
George Kech.
@georgemitnick
Aug 15 2017 14:32
then what's the point of using the loop?
Diego Mayer
@Chrono79
Aug 15 2017 14:32
seeing the content of the array?
it has no use for the copy
George Kech.
@georgemitnick
Aug 15 2017 14:33
I need to use a loop to copy the content of the first array to the second
Can that be done?
kumquatfelafel
@kumquatfelafel
Aug 15 2017 14:33
You can use a loop to copy the content of one array to another, yes. :point_down:
Diego Mayer
@Chrono79
Aug 15 2017 14:33
ok, then go back to your code and use push instead of using the i in both sides of the =
George Kech.
@georgemitnick
Aug 15 2017 14:34
How?
transfered = yearsOfBirth.push()
?
inside the loop?
Morchid Chellali
@Morched23MJ
Aug 15 2017 14:35
Simply use your loop, and use transfered.push(yearsOfBirth[i])
kumquatfelafel
@kumquatfelafel
Aug 15 2017 14:35
no assignment. push takes care of that for you
George Kech.
@georgemitnick
Aug 15 2017 14:35
aha
George Kech.
@georgemitnick
Aug 15 2017 14:36
@Morched23MJ it gives undefined again
var yearsOfBirth = [1990, 2000, 1986, 2001];

var transfered = [];

for (var i = 0; i < yearsOfBirth.length; i++) {
    transfered.push(yearsOfBirth[i]);
}

console.log(transfered[i]);
Markus Kiili
@Masd925
Aug 15 2017 14:37
@georgemitnick console.log(transfered);
korzo
@korzo
Aug 15 2017 14:37
@georgemitnick because i after loop is yearsOfBirth.length
kumquatfelafel
@kumquatfelafel
Aug 15 2017 14:37
@georgemitnick at end of loop, i = transferred.length (because :point_up:)
transfered[transfered.length] is undefined
Morchid Chellali
@Morched23MJ
Aug 15 2017 14:37
why the [i]?
Only, the name of the array can do it
George Kech.
@georgemitnick
Aug 15 2017 14:39
But we don't want to see the value of the array?
It's confusing when to use [i] and when not to
kumquatfelafel
@kumquatfelafel
Aug 15 2017 14:40
array[i] for when you want to access value at index i of array.
Morchid Chellali
@Morched23MJ
Aug 15 2017 14:44
You want to see if the values were transfered to the second array transfered, so you use its name to print the whole values, else for a specefic value, you use a number or a defined var which contain a value, which can be used for the array index, so in the loop you used i, and loop stops when the condition isn't verified, which is when i >= array.length, then the i is at the last equal to array.length so, the loop stops, now when you type array[i], it's undefined, since the index doesn't contain that value, if you did console.log(transfered[i-1]);, you would get the last value of the array
kumquatfelafel
@kumquatfelafel
Aug 15 2017 14:44
Whether or not it's what you want for a given scenario is something you'll have to figure out based upon what you're trying to do, and the relevant lines of code.
Morchid Chellali
@Morched23MJ
Aug 15 2017 14:44
specific*
soulproprietor
@soulproprietor
Aug 15 2017 14:50
i'm banging my head agaisnt the wall. I can't for the life of me understand why this is returning a circular object:
var friends = [];
friends.push('duck');

var relationships = {};
relationships.friends = friends;

var matches = [];
relationships.matches = matches;
relationships.matches.push('dog');

for (var i=0;i<animals.length;i++) {
  animals[i].relationships = relationships;
}

console.log(animals);
Markus Kiili
@Masd925
Aug 15 2017 14:51
@soulproprietor Where is animals declared?
Blauelf
@Blauelf
Aug 15 2017 14:51
Is animals considered circular above this code?
soulproprietor
@soulproprietor
Aug 15 2017 14:52
var animals = [];
animals.push(animal);
var quackers = {username: 'DaffyDuck', tagline: 'Yippeee!', noises: ['quack', 'honk', 'sneeze', 'growl']};
var betsy = {username: 'MilkeyCow', tagline: 'Here we go again', noises: ['merr', 'moo', 'acheww', 'arrr']};
var timothy = {username: 'toothFairy', tagline: 'here I come!', noises: ['boing', 'spritz', 'shhhh', 'ufffa']};
animals.unshift(quackers,timothy,betsy);
console.log(animals.length);
kumquatfelafel
@kumquatfelafel
Aug 15 2017 14:52
and where is animal declared?
Markus Kiili
@Masd925
Aug 15 2017 14:53
@soulproprietor Where is animal declared ;)
soulproprietor
@soulproprietor
Aug 15 2017 14:53
//OBJECTS EXCERCISES 
var animal = {};
animal.username = 'ali-bear';
animal['tagline'] = 'oh yeah...';
var noises = [];
animal.noises = noises;
console.log(animal);

for (var i in animal) {
    if (i == 'username') {
      console.log("Hi, my name is " + animal[i]);
    }
     if (i == 'tagline') {
       console.log("I like to say " + animal[i]);
     }
}
Guderian Raborg
@hypercuber
Aug 15 2017 14:54
@Chrono79 @EpicTriffid thanks
CamperBot
@camperbot
Aug 15 2017 14:54
hypercuber sends brownie points to @chrono79 and @epictriffid :sparkles: :thumbsup: :sparkles:
:cookie: 279 | @epictriffid |http://www.freecodecamp.com/epictriffid
:star2: 4522 | @chrono79 |http://www.freecodecamp.com/chrono79
Blauelf
@Blauelf
Aug 15 2017 14:54
I somehow assume that "circular" here might mean "too deep to display in a nice way".
Thomas
@sjurs1
Aug 15 2017 14:54
Hi guys, how is everyone
shaistha
@shaistha24
Aug 15 2017 14:55
hello
could someone help me find the mistake i have made...in java script basics- profile lookup
//Setup
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(var i=0;i< contacts.length;i++){
if(contacts[i].firstName !== firstName){
  return "No such contact";
} else if (contacts.hasOwnProperty(prop) !== prop){
  return "No such property";
} else {
  return contacts[i][prop];

}
  }
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
Blauelf
@Blauelf
Aug 15 2017 14:57
@soulproprietor I just put that code all in repl.it. Unless there's code we don't know of, it works. The only thing is that they all share the same relations object, which might have led to the "circular" claim.
kumquatfelafel
@kumquatfelafel
Aug 15 2017 14:57

https://repl.it/KKao

Can't say I'm running into any "circular" objects here. Is this your full code?

@Blauelf lol
soulproprietor
@soulproprietor
Aug 15 2017 14:58
no
one second
kumquatfelafel
@kumquatfelafel
Aug 15 2017 14:59
@shaistha24 After checking one contact, can we reliably make the assumption that said contact doesn't exist?
soulproprietor
@soulproprietor
Aug 15 2017 14:59
there are a lot of comments so I didnt wanna post everything
Blauelf
@Blauelf
Aug 15 2017 14:59
@shaistha24 No need to post the array, just the function would have been enough. And what does it tell you if the current contact does not have the right name? Right, nothing. Only if all contacts had the wrong name (i.e. after the loop) you know to return "No such contact".
kumquatfelafel
@kumquatfelafel
Aug 15 2017 14:59
(return halts function entirely and returns the specified value to caller)
soulproprietor
@soulproprietor
Aug 15 2017 15:00
var animal = {};
animal.username = 'ali-bear';
animal['tagline'] = 'oh yeah...';
var noises = [];
animal.noises = noises;
console.log(animal);

for (var i in animal) {
    if (i == 'username') {
      console.log("Hi, my name is " + animal[i]);
    }
     if (i == 'tagline') {
       console.log("I like to say " + animal[i]);
     }
}



//ARRAY EXERCISES 

var noiseArray = [];
noiseArray.unshift("roof")
noiseArray.push("meow");
noiseArray[2] = 'blurp';
console.log(noiseArray);
length = noiseArray.length;
animal['noises'] = noiseArray;
console.log(animal);


//ANIMAL COLLECTION
var animals = [];
animals.push(animal);
var quackers = {username: 'DaffyDuck', tagline: 'Yippeee!', noises: ['quack', 'honk', 'sneeze', 'growl']};
var betsy = {username: 'MilkeyCow', tagline: 'Here we go again', noises: ['merr', 'moo', 'acheww', 'arrr']};
var timothy = {username: 'toothFairy', tagline: 'here I come!', noises: ['boing', 'spritz', 'shhhh', 'ufffa']};
animals.unshift(quackers,timothy,betsy);
console.log(animals.length);
kumquatfelafel
@kumquatfelafel
Aug 15 2017 15:01
so for example...
function forExample() {
  for(var i = 0; i < 10; i++)
    return i; // this actually only returns once, with value of i as 0.
}
shaistha
@shaistha24
Aug 15 2017 15:01
@kumquatfelafel @Blauelf did u mean to say that i have to run separate loops for each??/
okey ...so what im doing is checking only one contact and returning the value
soulproprietor
@soulproprietor
Aug 15 2017 15:02
var animal = {};
animal.username = 'ali-bear';
animal['tagline'] = 'oh yeah...';
var noises = [];
animal.noises = noises;
console.log(animal);

for (var i in animal) {
    if (i == 'username') {
      console.log("Hi, my name is " + animal[i]);
    }
     if (i == 'tagline') {
       console.log("I like to say " + animal[i]);
     }
}

//ARRAY EXERCISES 

var noiseArray = [];
noiseArray.unshift("roof")
noiseArray.push("meow");
noiseArray[2] = 'blurp';
console.log(noiseArray);
length = noiseArray.length;
animal['noises'] = noiseArray;
console.log(animal);


//ANIMAL COLLECTION
var animals = [];
animals.push(animal);
var quackers = {username: 'DaffyDuck', tagline: 'Yippeee!', noises: ['quack', 'honk', 'sneeze', 'growl']};
var betsy = {username: 'MilkeyCow', tagline: 'Here we go again', noises: ['merr', 'moo', 'acheww', 'arrr']};
var timothy = {username: 'toothFairy', tagline: 'here I come!', noises: ['boing', 'spritz', 'shhhh', 'ufffa']};
animals.unshift(quackers,timothy,betsy);
console.log(animals.length);

var animals = [];
animals.push(animal);
var quackers = {username: 'DaffyDuck', tagline: 'Yippeee!', noises: ['quack', 'honk', 'sneeze', 'growl']};
var betsy = {username: 'MilkeyCow', tagline: 'Here we go again', noises: ['merr', 'moo', 'acheww', 'arrr']};
var timothy = {username: 'toothFairy', tagline: 'here I come!', noises: ['boing', 'spritz', 'shhhh', 'ufffa']};
animals.unshift(quackers,timothy,betsy);
console.log(animals.length);


// NESTED DATA

var friends = [];
friends.push('duck');

var relationships = {};
relationships.friends = friends;

var matches = [];
relationships.matches = matches;
relationships.matches.push('dog');

for (var i=0;i<animals.length;i++) {
  animals[i].relationships = relationships;
}

console.log(animals);
got it all.. sorry the first time didnt copy all
this retrns the circular object
Blauelf
@Blauelf
Aug 15 2017 15:03
@shaistha24 I'm just saying that you cannot do anything on a name mismatch within the loop. You should return something on a name match, however. No need for any second loop.
kumquatfelafel
@kumquatfelafel
Aug 15 2017 15:04

:point_up:

You can only know that the contact does not exist after checking all of the contacts and not finding.

Huỳnh Trần Khanh
@khanh2003
Aug 15 2017 15:05
@Blauelf Great, thanks. :+1: :sparkles:
CamperBot
@camperbot
Aug 15 2017 15:05
khanh2003 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4569 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Aug 15 2017 15:06
@soulproprietor Whatever tells you "circular", it's wrong. That's not "circular", but not easy to display without ambiguities either. Several objects appear multiple times, while printing them would hide that (they would appear as identical, but not necessarily same objects)
kumquatfelafel
@kumquatfelafel
Aug 15 2017 15:07

@soulproprietor yeah... still not seeing it.

https://repl.it/KKao/2

anim here :point_up: would be example of something circular.

soulproprietor
@soulproprietor
Aug 15 2017 15:07
I checked it in JSbin and in codepen! I too did not believe it :-/
Blauelf
@Blauelf
Aug 15 2017 15:08
@kumquatfelafel I think @soulproprietor is not using repl.it, but a different output routine, which makes mistakes, just like the one used in freeCodeCamp turns all undefined and NaN into null.
soulproprietor
@soulproprietor
Aug 15 2017 15:08
really? you copied and pasted and there is no error?
I am using codepen and jsbin
both give an error
kumquatfelafel
@kumquatfelafel
Aug 15 2017 15:09
@Blauelf agreed (as also noted :point_up: :p )
Blauelf
@Blauelf
Aug 15 2017 15:09
Ah. Chrome shows "Circular" with same code. Firefox doesn't.
soulproprietor
@soulproprietor
Aug 15 2017 15:09
weird...
Blauelf
@Blauelf
Aug 15 2017 15:10
Oh, that was wrong link.
soulproprietor
@soulproprietor
Aug 15 2017 15:10
so my code is fine?
but it still doesn't work :worried:
Blauelf
@Blauelf
Aug 15 2017 15:11
@kumquatfelafel Clicked the wrong link. You clearly stated that the /2 link would contain circular references :P
kumquatfelafel
@kumquatfelafel
Aug 15 2017 15:11
@Blauelf [insert evil laugh here] ;)
soulproprietor
@soulproprietor
Aug 15 2017 15:12
the most recent one I posted has the circular
at 8:02
Blauelf
@Blauelf
Aug 15 2017 15:12
8:02?
kumquatfelafel
@kumquatfelafel
Aug 15 2017 15:13
@Blauelf it's the relationship objects, according to codepen console
Blauelf
@Blauelf
Aug 15 2017 15:13
They are shared, not circular.
it gives me an
error
shaistha
@shaistha24
Aug 15 2017 15:14
@kumquatfelafel @Blauelf
for(var i=0;i< contacts.length;i++){
if(contacts[i].firstName !== firstName){
  return "No such contact";
} 
    if (contacts.hasOwnProperty(prop) !== prop){
  return "No such property";
} 
  if (contacts[i].firstName === firstName && contacts.hasOwnProperty(prop) !== prop) {
  return contacts[i][prop];
}
  }
what about this
Markus Kiili
@Masd925
Aug 15 2017 15:15
@shaistha24 If the first contact is a miss, you are yelling No such contact
Huỳnh Trần Khanh
@khanh2003
Aug 15 2017 15:15
Never trust CodePen console, use Debug mode and look at Chrome DevTools's console instead.
kumquatfelafel
@kumquatfelafel
Aug 15 2017 15:15
contacts.hasOwnProperty returns true or false, not prop. Plus, as
@Masd925 notes :point_up:
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 15:16
https://codepen.io/tiagocorreia/full/brYpog/ why my divs are not together like a perfect circle? can't understand what im doing wrong no padding no margins nothing
Blauelf
@Blauelf
Aug 15 2017 15:16
@shaistha24 Inside the loop, only act on a name match!
kumquatfelafel
@kumquatfelafel
Aug 15 2017 15:17
I love how it calls it a "circular bject". @khanh2003 :p
Huỳnh Trần Khanh
@khanh2003
Aug 15 2017 15:18
yeah, me too @kumquatfelafel
soulproprietor
@soulproprietor
Aug 15 2017 15:19
so i'm not crazy...
i'm banging my head against the wall on this one
kumquatfelafel
@kumquatfelafel
Aug 15 2017 15:19
@soulproprietor Well, I can't guarantee that. :p
bilaal-s
@bilaal-s
Aug 15 2017 15:19
hello guys, im half considering completely rewriting the JS for this project, its gone over 180 lines now with not much functionality. what do you guys think? https://codepen.io/bilaal-s/pen/QMjVKK?editors=1010
Blauelf
@Blauelf
Aug 15 2017 15:19
There really is no simple and unambiguous way to display shared values in a property tree. So they just say "circular" and don't display at all.
soulproprietor
@soulproprietor
Aug 15 2017 15:19
hahahaa
kumquatfelafel
@kumquatfelafel
Aug 15 2017 15:19
;)
Blauelf
@Blauelf
Aug 15 2017 15:20
@soulproprietor Maybe give each animal its own relationships object, with own friends?
Markus Kiili
@Masd925
Aug 15 2017 15:22
@bilaal-s My way was to code an expression parser function for the calculator first.
bilaal-s
@bilaal-s
Aug 15 2017 15:23
@Masd925 I see! so ofcourse your taking into account multiple operations there. I will plan out my second attempt on paper before doing anything
shaistha
@shaistha24
Aug 15 2017 15:24
@Blauelf im still not getting ur point...pls help me understand u that means...i need to mane match !
shaistha
@shaistha24
Aug 15 2017 15:24
not miss match
Markus Kiili
@Masd925
Aug 15 2017 15:24
@bilaal-s I just used a while loop that simplifies the expression. There are some known algorithms too I think.
soulproprietor
@soulproprietor
Aug 15 2017 15:25
@Blauelf I could do that but I was doing exercises, and that wasn't the challenge
bilaal-s
@bilaal-s
Aug 15 2017 15:25
@Masd925 if you dont mind me asking did you do it first attempt?
Blauelf
@Blauelf
Aug 15 2017 15:25
@shaistha24 Inside the loop, whenever the firstName matches, return something (property value or "No such property"). After the loop, where you would end up only if all names were mismatches, you can safely return "No such contact".
Taking all feedback
Blauelf
@Blauelf
Aug 15 2017 15:26
@soulproprietor Codepen complains about objects being in the same tree multiple times.
Markus Kiili
@Masd925
Aug 15 2017 15:26
@bilaal-s I did the parser quite fast. Calculator is yet to be done ;)
Abhinav Mishra
@abhinav-m
Aug 15 2017 15:27
@bilaal-s do it at your own pace
its good that youre considering refactoring stuff
bilaal-s
@bilaal-s
Aug 15 2017 15:27
@Masd925 i see thanks :)
CamperBot
@camperbot
Aug 15 2017 15:27
bilaal-s sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4418 | @masd925 |http://www.freecodecamp.com/masd925
Stephen James
@sjames1958gm
Aug 15 2017 15:27
@Yuriah Looks good - facebook share didn't seem to work
bilaal-s
@bilaal-s
Aug 15 2017 15:27
@abhinav-thinktank indeed, has to be done
Abhinav Mishra
@abhinav-m
Aug 15 2017 15:27
@bilaal-s all you can do is learn :D
bilaal-s
@bilaal-s
Aug 15 2017 15:28
@abhinav-thinktank and learn we must!
Abhinav Mishra
@abhinav-m
Aug 15 2017 15:28
@bilaal-s true danke
CamperBot
@camperbot
Aug 15 2017 15:28
abhinav-thinktank sends brownie points to @bilaal-s :sparkles: :thumbsup: :sparkles:
:cookie: 271 | @bilaal-s |http://www.freecodecamp.com/bilaal-s
bilaal-s
@bilaal-s
Aug 15 2017 15:30
well..... camperbot is not complying.... i think it wants to be rewritten too @camperbot
@abhinav-thinktank thanks
CamperBot
@camperbot
Aug 15 2017 15:30
bilaal-s sends brownie points to @abhinav-thinktank :sparkles: :thumbsup: :sparkles:
shaistha
@shaistha24
Aug 15 2017 15:30

@Masd925 @Blauelf
in my code i want to run a loop to check all the arr elements before giving return

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

the above code in for loop will check the first and give return ...but i want to check all
pls could tell me how...or give a hint how i may do so??

CamperBot
@camperbot
Aug 15 2017 15:30
:cookie: 504 | @abhinav-thinktank |http://www.freecodecamp.com/abhinav-thinktank
bilaal-s
@bilaal-s
Aug 15 2017 15:30
thats a good camperbot!
Abhinav Mishra
@abhinav-m
Aug 15 2017 15:31
:D
Markus Kiili
@Masd925
Aug 15 2017 15:31
@shaistha24 Just if (contacts[i].hasOwnProperty(prop)){...}
shaistha
@shaistha24
Aug 15 2017 15:31
@Masd925 i did the same thing right!!
or is it not
Markus Kiili
@Masd925
Aug 15 2017 15:32
Nest that if inside the first name check if block.
Kelvin Hernandez
@Yuriah
Aug 15 2017 15:32
@sjames1958gm Will fix it thank you :D
CamperBot
@camperbot
Aug 15 2017 15:32
yuriah sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8320 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
kumquatfelafel
@kumquatfelafel
Aug 15 2017 15:32

@shaistha24 Suppose I'm looking at a field that's full of four cows. I decide, "I want to see if any of these cows is blue".

I look at the first cow. It isn't blue. After looking at this first cow, I can not declare "there are no blue cows in this field."
I look at the second cow. It isn't blue either. Same logic holds. I can't say there are no blue cows.
Third... let's consider two different scenarios.
First, let us consider the scenario where the third cow is blue.
In such a case, I can declare definitively "There are blue cow(s) in this field."
Since I've already determined there are blue cow(s), I don't care what color the final cow is, ergo I don't bother checking it.

Now consider the scenario where it isn't blue... Still can't say "there are no blue cows", since there's still one cow left to check.

I check the final cow. It's not blue. At this point, I've checked all the cows, and none of them are blue.

Therefore, I can declare with certainty, "none of the cows in this field are blue".

shaistha
@shaistha24
Aug 15 2017 15:35
@kumquatfelafel thanks for ur explanation ... i do get that ...the thing is im somehow not able to implement it
CamperBot
@camperbot
Aug 15 2017 15:35
:cookie: 609 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
shaistha24 sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
shaistha
@shaistha24
Aug 15 2017 15:37

@kumquatfelafel @Blauelf @Masd925

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


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

return "No such contact";

this too doesn't seem to work!!
am i doing it wrong with my loop??

Markus Kiili
@Masd925
Aug 15 2017 15:37
@shaistha24 Just if (contacts[i].hasOwnProperty(prop)){...}
Moisés Man
@moigithub
Aug 15 2017 15:37
hasOwnProperty method return true or false values
for "no such prop" probably u wanna check if (contacts[i].hasOwnProperty(prop) ===false ){...}
or use ! (not) operator @shaistha24 if (!contacts[i].hasOwnProperty(prop) ){...}
shaistha
@shaistha24
Aug 15 2017 15:38
@Masd925 sorry maybe im kinda slow but i don't get to understand whats in tha{....}
Markus Kiili
@Masd925
Aug 15 2017 15:39
@shaistha24 If block with your code.
Just remove that !==prop
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 15:40
var entrys = [[1,2,3]];
var temp = [];
function play () {
  temp = [];
  if(entrys.length === 0){

  }else{  
    for(var i = 0; i < entrys[entrys.length-1]; i++){
     temp.push(entrys[entrys.length-1][i]);
    }
    console.log(temp);
  }
}

play();
do you see any error with the code I just sent?
shaistha
@shaistha24
Aug 15 2017 15:41
@Masd925 @moigithub @Blauelf @kumquatfelafel thank u for u help!!
CamperBot
@camperbot
Aug 15 2017 15:41
shaistha24 sends brownie points to @masd925 and @moigithub and @blauelf and @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:warning: shaistha24 already gave kumquatfelafel points
:star2: 3585 | @moigithub |http://www.freecodecamp.com/moigithub
:star2: 4419 | @masd925 |http://www.freecodecamp.com/masd925
:star2: 4570 | @blauelf |http://www.freecodecamp.com/blauelf
shaistha
@shaistha24
Aug 15 2017 15:41
finally i understand n did it
Moisés Man
@moigithub
Aug 15 2017 15:42

@tiagocorreiaalmeida entrys[entrys.length-1];
entrys.length-1 ---> will be 0
entrys[0] will be [1,2,3]

for(var i = 0; i < entrys[entrys.length-1]; i++){

soo u saying
if ( i < [1,2,3] )

shaistha
@shaistha24
Aug 15 2017 15:43
@moigithub @Masd925 i would like to know whats the difference between !==prop and === false in that code
y the !== didnt work
am i looking for the return value
Moisés Man
@moigithub
Aug 15 2017 15:43
prop is a variable containing a string like "tracks" @shaistha24
Markus Kiili
@Masd925
Aug 15 2017 15:43
@shaistha24 The parameter prop holds the passed string. It has no place in that condition like that !==prop
shaistha
@shaistha24
Aug 15 2017 15:45
could u pls explain it more??
Stephen James
@sjames1958gm
Aug 15 2017 15:45
@tiagocorreiaalmeida looks like you need one more .length in your for loop
shaistha
@shaistha24
Aug 15 2017 15:45
@Masd925 @moigithub
i mean like v used firstName y not prop??
Moisés Man
@moigithub
Aug 15 2017 15:48
u need to check the function declaration
function lookUpProfile(firstName, prop){
................................................. :point_up: ........... :point_up:
...............lookUpProfile("Akira", "likes"); :point_left: and the function call
when u call the function u pass values...
"Akira" will be passed to firstName
"likes" will be passed to prop
shaistha
@shaistha24
Aug 15 2017 15:50
yes i do understand that
so...
Moisés Man
@moigithub
Aug 15 2017 15:51
soo when u refer to prop inside ur function .. it will use "likes" (on the example) as value
now... hasOwnProperty method return a boolean value.. (true, false)
if u do .hasOwnProp(prop) === prop it will compare (ie) true === "likes" (or false === "likes")
...and different value/data will never be equal
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 15:52
@moigithub Yeah just found out but thanks mate :)
CamperBot
@camperbot
Aug 15 2017 15:52
tiagocorreiaalmeida sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3586 | @moigithub |http://www.freecodecamp.com/moigithub
kumquatfelafel
@kumquatfelafel
Aug 15 2017 15:52
@shaistha24 hasOwnProperty checks for given property, and if found, returns true... if not found, returns false.
what @moigithub said :p
shaistha
@shaistha24
Aug 15 2017 15:54
@kumquatfelafel @moigithub thank u very much now i understand it
CamperBot
@camperbot
Aug 15 2017 15:54
shaistha24 sends brownie points to @kumquatfelafel and @moigithub :sparkles: :thumbsup: :sparkles:
:warning: shaistha24 already gave moigithub points
:warning: shaistha24 already gave kumquatfelafel points
prakash chandra yadav
@prakashyadav008
Aug 15 2017 15:54
@SkyC0der thanks
Joseph
@revisualize
Aug 15 2017 16:39
Hello.
Jason Luboff
@JLuboff
Aug 15 2017 16:39
Hello
Joseph
@revisualize
Aug 15 2017 16:39
@SkyC0der Thanks.
CamperBot
@camperbot
Aug 15 2017 16:39
revisualize sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:star2: 2397 | @skyc0der |http://www.freecodecamp.com/skyc0der
Gulsvi
@gulsvi
Aug 15 2017 16:40
Guess it needs to be capitalized? :p
or just a random hiccup
Hello btw
Joseph
@revisualize
Aug 15 2017 16:43
@camperbot thx
CamperBot
@camperbot
Aug 15 2017 16:43
revisualize sends brownie points to @camperbot :sparkles: :thumbsup: :sparkles:
:star2: 3383 | @camperbot |http://www.freecodecamp.com/camperbot
Joseph
@revisualize
Aug 15 2017 16:43
@SkyC0der Cbot is a bucket of rust sometimes.
@SkyC0der I think they added some code to not allow thanks floods
CamperBot
@camperbot
Aug 15 2017 16:44
revisualize sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:warning: revisualize already gave skyc0der points
Gulsvi
@gulsvi
Aug 15 2017 16:44
That makes sense
Reagan Scofield
@reaganscofield
Aug 15 2017 17:30
Guys I need you help
kumquatfelafel
@kumquatfelafel
Aug 15 2017 17:30
ask away :)
Reagan Scofield
@reaganscofield
Aug 15 2017 17:39
I want send screenshot but I can't see the button to select the pic
Help
Stephen James
@sjames1958gm
Aug 15 2017 17:43
You can paste your code and get
this
Joshua "TechDev" Walker
@JWTechdev
Aug 15 2017 18:04
can anyone help me with a NodeJS question? I went cloud a while back and my JS is embarrassingly rusty :worried:
Gulsvi
@gulsvi
Aug 15 2017 18:06
@JWTechdev feel free to ask, but there is a nodejs room you can try as well if it isn't related to free code camp: https://gitter.im/nodejs/node
Joseph
@revisualize
Aug 15 2017 18:08
@SkyC0der Hehe.. I was going to suggest the same thing.
Gulsvi
@gulsvi
Aug 15 2017 18:09
:)
Joshua "TechDev" Walker
@JWTechdev
Aug 15 2017 18:22
@SkyC0der thanks I will head in there :)
CamperBot
@camperbot
Aug 15 2017 18:22
jwtechdev sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:star2: 2398 | @skyc0der |http://www.freecodecamp.com/skyc0der
Joshua "TechDev" Walker
@JWTechdev
Aug 15 2017 18:24
I started here due to you guys being the "nice people" haha
some forums take you asking for help as a chance to make you feel small
Kelvin Hernandez
@Yuriah
Aug 15 2017 18:26
Alright guys back for more input please
Quote Machine (I am aware of the Facebook not working);
Stephen James
@sjames1958gm
Aug 15 2017 18:28
@Yuriah The note card is nice. Seems like the whole quote is stuck up at the top.
Kelvin Hernandez
@Yuriah
Aug 15 2017 18:30
@sjames1958gm You suggest moving the quote start point a line or two down?
I could have made it responsive to the quote it self. But the change in size every quote gets annoying imo
Stephen James
@sjames1958gm
Aug 15 2017 18:32
@Yuriah Maybe start the quote on the second line of the card. Seems like lots of extra white space for most of the quotes
@Yuriah It looks fine - just my opinion
Kelvin Hernandez
@Yuriah
Aug 15 2017 18:34
Will push it to the next line, no problem. I appreciate all feedback man
Stephen James
@sjames1958gm
Aug 15 2017 18:35
@Yuriah :+1:
Kelvin Hernandez
@Yuriah
Aug 15 2017 18:35
if you refresh, it should have updated to the second line
just gotta find out how to make the Facebook one work and ill submit
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 18:38
hey everyone
need a little help guys
im at the simon game my idea is create a 2 d array to store the 20 sequences my only problem I can't figure out a way like im on the 3 plays (3colors) how can I check 1 by one to see if its doing it right like first click = array [2][0] and further and further
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 18:44
@sjames1958gm any idea ?:d
Kelvin Hernandez
@Yuriah
Aug 15 2017 18:53
darn thats out of my league for right now haha
you can create a nested for loop
im not sure if the .map function works on 2d array
alpox
@alpox
Aug 15 2017 18:54
@Yuriah it works on a 1d array but you can nest maps :D
Kelvin Hernandez
@Yuriah
Aug 15 2017 18:55
true ! XD i havent experimented that far yet
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 18:55
@alpox
can you give a me a little helpp in the question I made?if poss
Kelvin Hernandez
@Yuriah
Aug 15 2017 18:55
well I cant get this stupid share to work for Facebook
alpox share ur codepen
Moisés Man
@moigithub
Aug 15 2017 18:57
pcSequence = [1,2,3,4]
userInput = [1,2]
aaaa =userInput.every( (n,idx )=>n===pcSequence[idx] ) //true
if (aaaa && pcSequence.length === userInput.length) {
   // all input was correct
}
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 18:57
@moigithub but I have to check everytime He presses so I have to call every
every time he clicks?
Moisés Man
@moigithub
Aug 15 2017 18:58
yep
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 18:58
sounds like a good idea tbh, thanks mate
Ronique Ricketts
@RoniqueRicketts
Aug 15 2017 18:59
Just did my first coding interview from a startup. :) Its for a part-time start up so I can get some experience
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 18:59
thanks @moigithub
CamperBot
@camperbot
Aug 15 2017 18:59
tiagocorreiaalmeida sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3587 | @moigithub |http://www.freecodecamp.com/moigithub
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 19:03
$("#row div").click(function(){
 console.log($(this).attr("class"));
});
<div class="row">
<div class="green"></div>
<div class="red"></div>
</div>
shouldnt it work?
Gulsvi
@gulsvi
Aug 15 2017 19:05
@tiagocorreiaalmeida I don't see id="row" in your HTML
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 19:05
fuck me
..
this dumb mistakes
thanks @SkyC0der
CamperBot
@camperbot
Aug 15 2017 19:05
tiagocorreiaalmeida sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:star2: 2401 | @skyc0der |http://www.freecodecamp.com/skyc0der
Gulsvi
@gulsvi
Aug 15 2017 19:05
np
Guderian Raborg
@hypercuber
Aug 15 2017 19:17
how do I do event listener for arrow keys?
window.addEventListener('onkeydown', function(event) {
  if (event.key === 37) console.log('left');
});
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 19:18
@moigithub it looks really good
´´´
$(".row div").click(function(){
 userInput.push($(this).attr("class"));
 temp = userInput.every( (currentValue,index )=>currentValue===entrys[entrys.length-1][index]);
  if(temp){
    console.log("the value is right");
  }else{
    console.log("wrong");
  }
  if (temp && entrys[entrys.length-1].length === userInput.length) {
   console.log("You got them all");
  }
});
thanks for the help
@hypercuber you mean on key press?
Guderian Raborg
@hypercuber
Aug 15 2017 19:20
@tiagocorreiaalmeida idk i want to do the snake game and i need code when you press the arrow keys
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 19:21
sec
$(document).keypress(function(e) {
if(e.which == 13) {
console.log("Enter");
}
});
try this
tell me
what you get
here seems to be working
Ming Zhu
@chocobrownie
Aug 15 2017 19:22
d
Gulsvi
@gulsvi
Aug 15 2017 19:23
@hypercuber
window.addEventListener('keydown', function(event) {
  var key = event.which || event.keyCode || event.charCode;
  if (key === 37) console.log('left');
});
Stephen James
@sjames1958gm
Aug 15 2017 19:30
@RoniqueRicketts :+1:
Aaron Bell
@awb715
Aug 15 2017 19:31
i wanted to add some funcitonality to my calculator by clicking the keys
havent got to it yet
Ronique Ricketts
@RoniqueRicketts
Aug 15 2017 19:33
Anyone has any chatrooms for ccna?
omarraza
@omarraza
Aug 15 2017 19:34
Binary Agents. I'm not quite finished, but what I have so far isn't giving me the expected outcome. Its returning undefined + red dots + "
  var binaryArr = str.split(" ");
  var letter;

  function binaryConv(binaryString){
    var runningTotal = 0;
    for(var i = 0; i < binaryString.length; i++){
      var currentBit = binaryString[i];
      runningTotal += (currentBit * 2^(7-i));

    }
    return String.fromCharCode(runningTotal);
  }


  for (var j = 0; j < binaryArr.length; j++){
    letter += binaryConv(binaryArr[j]);    
  }

  return letter;
Eric Hasegawa
@EricHasegawa
Aug 15 2017 19:37
How can I take this link and make it so it puts in the users longitude and latitude instead of the default ones?https://fcc-weather-api.glitch.me/api/current?lat=35&lon=139 here is my code so far, I know the current link variable is broken https://codepen.io/erichasegawa/pen/brdYKd?editors=1010
Ronique Ricketts
@RoniqueRicketts
Aug 15 2017 19:37
@sjames1958gm I feel like my long studying starts so pay off ;) I feel proud of me.
Stephen James
@sjames1958gm
Aug 15 2017 19:38
@RoniqueRicketts Great - keep us notified of your progress - always good to hear
Ronique Ricketts
@RoniqueRicketts
Aug 15 2017 19:39
@sjames1958gm I will. I am to code in c9 build up a 4 page layout without functionality.
Stephen James
@sjames1958gm
Aug 15 2017 19:41
@EricHasegawa You can put your weather URL and getJSON in a function and call from get position callback.
  // inside of the showPosition callback - getWeather(position.coords.latitude,position.coords.longitude);
  function getWeather(lat, lon) {
  var weatherAPI = `https://fcc-weather-api.glitch.me/api/current?lat=${lat}&lon=${lon}`

  jQuery.getJSON(weatherAPI, function() {
    console.log("Success!")
  }) 
}
Eric Hasegawa
@EricHasegawa
Aug 15 2017 19:43
@sjames1958gm I may have figured it out on my own, does this code achieve the same thing as what you just sent? https://codepen.io/erichasegawa/pen/brdYKd?editors=1010
Guderian Raborg
@hypercuber
Aug 15 2017 19:43

@SkyC0der

Thanks. What is this for though

 event.which || event.keyCode || event.charCode

my guess it is for different browsers...

CamperBot
@camperbot
Aug 15 2017 19:43
hypercuber sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:star2: 2403 | @skyc0der |http://www.freecodecamp.com/skyc0der
Stephen James
@sjames1958gm
Aug 15 2017 19:43
@EricHasegawa yes!
Eric Hasegawa
@EricHasegawa
Aug 15 2017 19:44
@sjames1958gm Sweet! Okay, I'm a little confused as to what I should do next, just to clarify does my code already access the weather API and get the users current weather? In it's raw JSON format of course still
Stephen James
@sjames1958gm
Aug 15 2017 19:44
@omarraza You need to initialize letter to "" (since you += it)
@EricHasegawa Yes, you can do this to see the json in the console.
jQuery.getJSON(weatherAPI, function(json) {
  console.log("Success! " + JSON.stringify(json));
})
Eric Hasegawa
@EricHasegawa
Aug 15 2017 19:47
@sjames1958gm Oh awesome thanks!
CamperBot
@camperbot
Aug 15 2017 19:47
erichasegawa sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8321 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Gulsvi
@gulsvi
Aug 15 2017 19:47
@hypercuber Yeah, it's for browser compatibility. Some use which, others use keyCode, really old ones use charCode
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 19:48
image.png
just a little question I got something like on ppress
add opacity t o1
but I only want that to last like 1 second
how can I do that?
and then be gone
im forgetting simple things hum
Reagan Scofield
@reaganscofield
Aug 15 2017 19:52
hey guys how can send screenshort here
Johnny Meza
@XLpacman805
Aug 15 2017 20:21
upload screenshot to imgur then paste the linl
link
Jason Luboff
@JLuboff
Aug 15 2017 20:21
No need to upload, you can take a screenshot, copy it, then paste it into the chat.
But perferable, use markdown.
```
shift+enter for new line, paste code, shift+enter for new line
```
Johnny Meza
@XLpacman805
Aug 15 2017 20:23
that too ^
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 20:37
https://codepen.io/tiagocorreia/full/brYpog/ I got this after the sound plays I wanna place back the opacity of the color back to normal how can I achieve that?
Jason Luboff
@JLuboff
Aug 15 2017 20:41
@tiagocorreiaalmeida Use setTimeout
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 20:42
thanks @JLuboff
CamperBot
@camperbot
Aug 15 2017 20:42
tiagocorreiaalmeida sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2148 | @jluboff |http://www.freecodecamp.com/jluboff
Guderian Raborg
@hypercuber
Aug 15 2017 20:43
@SkyC0der thanks
CamperBot
@camperbot
Aug 15 2017 20:43
hypercuber sends brownie points to @skyc0der :sparkles: :thumbsup: :sparkles:
:warning: hypercuber already gave skyc0der points
Guderian Raborg
@hypercuber
Aug 15 2017 20:43
How do I swap two values
function swap(a, b) {
  let c = a;
  a = b;
  b = c;
}

let a = 5;
let b = 25;

swap(a, b);

console.log(a);
console.log(b);
Jason Luboff
@JLuboff
Aug 15 2017 20:45
@hypercuber Your values are swapped inside the function
Jay Vora
@jayvora92
Aug 15 2017 20:47
 var regEXTest = /.*google.*|.*accountemps.*|.*creativegroup.*|.*yahoo.*|.*test.*/gi;
can anyone explain what is happening in this
Guderian Raborg
@hypercuber
Aug 15 2017 20:51
@JLuboff so what should i do?
Jason Luboff
@JLuboff
Aug 15 2017 20:51
@hypercuber ...what are you trying to do? Your values are swapped inside your function
Guderian Raborg
@hypercuber
Aug 15 2017 20:52
@JLuboff i am trying to swap them outside
maybe using prototypes...
Jason Luboff
@JLuboff
Aug 15 2017 20:54
@hypercuber Do you have to have the function?
Guderian Raborg
@hypercuber
Aug 15 2017 20:54
@JLuboff No, whatever works
Jason Luboff
@JLuboff
Aug 15 2017 20:55
@hypercuber Then remove the function.
let a = 5;
let b = 25;
  let c = a;
  a = b;
  b = c;

console.log(a); //25
console.log(b); //5
Guderian Raborg
@hypercuber
Aug 15 2017 20:57
@JLuboff Thanks, that works. I think I can do that now but I was thinking I might need to repeat that couple times.
CamperBot
@camperbot
Aug 15 2017 20:57
:star2: 2149 | @jluboff |http://www.freecodecamp.com/jluboff
hypercuber sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 20:59
@JLuboff
function sound(color){
   $(".row div").css("opacity", "0.80");
  switch(color){
    case "green":
      $(".row div.green").css("opacity", "1");
      $(".row div.green audio").trigger('play');
      break;
    case "red":
         $(".row div.red").css("opacity", "1");
        $(".row div.red audio").trigger('play');
      break;
    case "yellow":
         $(".row div.yellow").css("opacity", "1");
         $(".row div.yellow audio").trigger('play');
      break;
    case "blue":
       $(".row div.blue").css("opacity", "1");
       $(".row div.blue audio").trigger('play');
      break;
              }
    setInterval(function() {
       $(".row div").css("opacity", "0.80");

    }, 1000);

}
this was your idea right?
or im doing it wrong?
Jason Luboff
@JLuboff
Aug 15 2017 21:04
@tiagocorreiaalmeida Personally I used setTimeout instead of setInterval, but yes something along those lines
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 21:07
first thing I googled was the difference between those two :D
setTimeout executes the function once on a time out. setInterval executes the function repeatedly on and interval
seems your idea is alot better
thanks
Diego Mayer
@Chrono79
Aug 15 2017 21:54
@hypercuber use destructuring (it's ES6) [a, b] = [b, a];
Bryan Reese
@breese8009
Aug 15 2017 21:58

who can tell me this... why does this work, but not when i use arrow function an const?

so, this works..

function person(name,age){
  this.name=name;
  this.age=age;
}
var myFather = new person("John",50);
var myMother = new person("Sally",48);

myMother;

but this doesnt

const construct = (name, age)=>{
  this.name=name;
  this.age=age;
};

let me = new construct("bryan",32);

me;
Jason Luboff
@JLuboff
Aug 15 2017 21:58
@breese8009 If I remember correctly...this doesn't work with arrow
Diego Mayer
@Chrono79
Aug 15 2017 21:58
@breese8009 arrows don't bind this
Bryan Reese
@breese8009
Aug 15 2017 21:59
thats weird
Jason Luboff
@JLuboff
Aug 15 2017 21:59
You're weird..but we don't tell you anything
:D
it's useful sometimes it is like that
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 22:00
var colors = ["green","red","yellow","blue"];
tempSequence.push(colors[(Math.random()*4).toFixed()]);
why does this returns undifined
sometimes?
Bryan Reese
@breese8009
Aug 15 2017 22:01
@JLuboff lmao thanks
CamperBot
@camperbot
Aug 15 2017 22:01
breese8009 sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2150 | @jluboff |http://www.freecodecamp.com/jluboff
Diego Mayer
@Chrono79
Aug 15 2017 22:02
@tiagocorreiaalmeida because that sometimes returns '4'
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 22:02
should be using a 3
nm :D
Diego Mayer
@Chrono79
Aug 15 2017 22:02
(Math.random()*4).toFixed() it returns '4' too
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 22:02
thanks @Chrono79
CamperBot
@camperbot
Aug 15 2017 22:02
tiagocorreiaalmeida sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4523 | @chrono79 |http://www.freecodecamp.com/chrono79
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 22:02
yeah I know
my bad
Diego Mayer
@Chrono79
Aug 15 2017 22:02
:+1:
use Math.floor instead of toFixed
:wave: see ya
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 22:03
what's the difference between those two?
Keon Samuel
@keonsam
Aug 15 2017 22:07
try a generator.
Jason Luboff
@JLuboff
Aug 15 2017 22:07
@tiagocorreiaalmeida Math.floor rounds down, even 3.9 would be rounded to 3. toFixed rounds up or down. So 3.9 would be 4, 3.4 would be 3
luccifer00
@luccifer00
Aug 15 2017 22:07
 function( data){

    var article = document.getElementById("article");
      for (var i =0; i<data[1].length;i++){
          var div = document.createElement('div');
         var title = data[1][i];
        var resume = data[2][i];
        var link = data[3][i]
      //  div.setAttribute('id', 'article8') ;
      div.setAttribute('class', 'jumbotron');
        $(".jumbotron").css('visibility','visible');
        div.innerHTML = title + "<br>"+ resume+" <a href="+link+">Read more...</a>";
          article.appendChild(div);
      } //end loop

    },// function data
hi there, it is posible to assign a css style to title//resume/?? not to set it inside the .innerHTML, (i think i cant use document.getElementById() inside the innerHTML) anyways, it is posible?? i want to use jquery for that, and not to créate HTML stlye there to do it... if its posible?
*it is posible? :+1:
Keon Samuel
@keonsam
Aug 15 2017 22:09
try addClass
yes
Tiago Correia
@tiagocorreiaalmeida
Aug 15 2017 22:09
thanks @JLuboff
CamperBot
@camperbot
Aug 15 2017 22:09
tiagocorreiaalmeida sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2151 | @jluboff |http://www.freecodecamp.com/jluboff
luccifer00
@luccifer00
Aug 15 2017 22:29
@keonsam sounds perfect for me.... but i cant doit... should i add a w3 library and try with that? the jquery dasent look my solution...
probably you will se some test i did .... $("title").addClass("title") sounds stupid, but i have to test it ....i also test with `title.addClass(".title") at the begining @keonsam
monk
@monkingame
Aug 15 2017 23:01
hi everyone ,I have some code error with:TypeError: Cannot read property 'length' of undefined

var cat = (function (str) {
var init = "";
return function () {
return init += str.length;
}
})();

console.log(cat("a"));
console.log(cat("a"));

What's wrong? Thanks!
Stephen James
@sjames1958gm
Aug 15 2017 23:04
@monkingame str has no value when you return the function
@monkingame perhaps your inner function should have the parameter str?
monk
@monkingame
Aug 15 2017 23:05
@sjames1958gm Yes! I want to pass a string param to the anonymous function.
but how can I pass it?
Stephen James
@sjames1958gm
Aug 15 2017 23:05
@monkingame Then the anonymous function should have the parameter str
return function (str) {
return init += str.length;
}
@luccifer00 cannot you just add class='title' right after you do id='title'?
monk
@monkingame
Aug 15 2017 23:08
@sjames1958gm thanks! I test it at once
CamperBot
@camperbot
Aug 15 2017 23:08
monkingame sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8322 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 15 2017 23:08
@monkingame :+1:
monk
@monkingame
Aug 15 2017 23:09
Yes it works!Thank you ! @sjames1958gm
luccifer00
@luccifer00
Aug 15 2017 23:12
lol @sjames1958gm i am testing, it is just i didt want to use HTML, i'd like to figure out, how can i créate and add the class just with JS, addClass or getElementById dosent work... i think it is becouse i am inside the innerHTML= and when i test it, y get undefiny or null, or [objet][objet] but i am on the way....
Stephen James
@sjames1958gm
Aug 15 2017 23:16
@luccifer00 If you want to add the class then use create element and add the class to the created element then append to the div not set innerHTML
luccifer00
@luccifer00
Aug 15 2017 23:18
@sjames1958gm the problema is, i dont want to créate a class for the whole div, inside the "article" div, i get some info from the Wikipedia API. and i want to set a class for the title, and other class for the content, and other class for the link....
Stephen James
@sjames1958gm
Aug 15 2017 23:19
var span = document.createElement("span");
span.id = "title"
span.classList.add("title")
span.textContent = title;
div.appendChild(span);
luccifer00
@luccifer00
Aug 15 2017 23:19
maybe the best way to do it is with HTML (inside the innerHTML) but i was looking for a different way with JS ..
@sjames1958gm do u think it will be work? inside the loop, and inside the .innerHTML ??
monk
@monkingame
Aug 15 2017 23:22
@sjames1958gm why the function you just written worked?
return function (str) {
return init += str.length;
}
Stephen James
@sjames1958gm
Aug 15 2017 23:50
@monkingame You are passing a value to the function assigned to cat which is the anonymous function.
So you need to give that function the parameter str
@sjames1958gm This is instead of the innerHTML.