These are chat archives for FreeCodeCamp/HelpJavaScript

21st
Jul 2017
Stephen James
@sjames1958gm
Jul 21 2017 00:00
With continue input of 15 gave 9
Guderian Raborg
@hypercuber
Jul 21 2017 00:00
@sjames1958gm I am breaking even numbers to show that the for loop only iterate once
@sjames1958gm Can you show me your code please?
kumquatfelafel
@kumquatfelafel
Jul 21 2017 00:03

@gtodd876 so if you think about it, any number is essentially represented by a sequence of binary 1s and 0s. The more 1s and 0s (i.e. the more bits), the higher (and/or more precise) number you can represent. On the other hand, the more bits, the more memory each number takes up. If we wanted to be able to specify how many decimal places a number had for printing purposes (there's no difference mathematically between 1.5 and 1.50... let's ignore concept of significant figures), then we'd need to include extra bits somewhere specifying to what decimal point number should be displayed when printed (how else would this information be saved). This means either making numbers take up more space for purposes that are, largely, cosmetic... or numbers being the same size (in bits) but unable to represent numbers as large/precisely as before. We'd also need an easy way for the person using the language to change this.

It makes more sense to not have this "decimal place" information as part of the binary representation of number itself, but instead have it so you can take a number and print it as a string with x decimal places.

Stephen James
@sjames1958gm
Jul 21 2017 00:03
@hypercuber All I did was change this if (arr[i] === 1) continue; //arr is to break only not to find maxL
Adam
@iGiblee
Jul 21 2017 00:05
All of my work has been erased, is anyone else seeing this in their account?
Guderian Raborg
@hypercuber
Jul 21 2017 00:05
@sjames1958gm Thanks. Let me check info on break and continue. I thought I had it figure out
CamperBot
@camperbot
Jul 21 2017 00:05
hypercuber sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8124 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
kumquatfelafel
@kumquatfelafel
Jul 21 2017 00:07
@iGiblee You may have solved a bunch of problems in freecodecamp.com. Site has migrated to .org. Your solutions are still visible (they still exist so don't worry) if you go to your profile page and click "view solution" from there, but they won't be visible from map/challenge itself if you solved on .com
@iGiblee If this is not the problem you are encountering, provide more detail.
Stephen James
@sjames1958gm
Jul 21 2017 00:08
@hypercuber continue will skip to the next, break will stop the loop
Adam
@iGiblee
Jul 21 2017 00:08
That's exactly the problem, I wanted to review my work to refresh myself, is there any solution for this or do I just have to redo whatever I want a refresher on? @kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jul 21 2017 00:09
@iGiblee Well... redoing is probably not the worst refresher. :p
But yeah, you can also go to "my profile" then scroll down and click view solution for the challenge you want to review what you did.
aRtoo
@artoodeeto
Jul 21 2017 00:10
yow bro. why is my z-index doesnt work?? i have a div with a class of intro and set the index to z-index:1 and a div with a class of content set index to z-index:10 but i wont overlap after the animation is done. help. :(
Adam
@iGiblee
Jul 21 2017 00:11
Lol damn it... thank you anyways @kumquatfelafel
CamperBot
@camperbot
Jul 21 2017 00:11
igiblee sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 511 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
kumquatfelafel
@kumquatfelafel
Jul 21 2017 00:11

@iGiblee sorry, not "my profile"... click top-right where it says your score or on your profile pic itself.

Having brain farts. :laughing:

Guderian Raborg
@hypercuber
Jul 21 2017 00:12
@sjames1958gm Thanks again
CamperBot
@camperbot
Jul 21 2017 00:12
hypercuber sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: hypercuber already gave sjames1958gm points
Stephen James
@sjames1958gm
Jul 21 2017 00:13
@hypercuber :+1:
Todd Matthews
@gtodd876
Jul 21 2017 00:16
@kumquatfelafel thank you for the great explanation!
CamperBot
@camperbot
Jul 21 2017 00:16
gtodd876 sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:warning: gtodd876 already gave kumquatfelafel points
angus
@dangus21
Jul 21 2017 00:21
can anyone here help me out with a project i'm developing?
Guderian Raborg
@hypercuber
Jul 21 2017 00:21
@sjames1958gm I think my code works correctly now but it is too slow to solve the problem. I am thinking maybe I can .pop() last element of array after every iteration to make it run faster or I need to find another method. Can you check if there is a way to make my code run faster:
Number.prototype.nextCollatz = function() {
  return this % 2 === 0 ? this / 2 : 3 * this + 1;
}
function chainLength(arr, n) { //n is starting num
  let chainL = 1;
  while (n !== 1) {
    n = n.nextCollatz();
    if (arr[n] === 0) arr[n] = 1;
    chainL++;
  }
  return chainL;
}
function largestCollatzUnder(n) { //under
  let arr = new Int8Array(n); ////arr[0] to arr[n - 1], 0 is T && 1 is break
  let testL, maxN, maxL = 1;
  for (let i = n - 1; i > 0; i--) {
    // arr is to continue only, not to find maxL
    testL = chainLength(arr, i);
    if (arr[i] === 1) continue;
    if (maxL < testL) { //both are numbers
      maxN = i;
      maxL = testL;
    }
  }
  return maxN;
}
console.log(largestCollatzUnder(15)); //9
Stephen James
@sjames1958gm
Jul 21 2017 00:22
@hypercuber Didn't the continue help? You removed it.
never mind I see it
angus
@dangus21
Jul 21 2017 00:22
https://codepen.io/angus/pen/xrvaZZ?editors=1011 trying to get this to work, but no success
Stephen James
@sjames1958gm
Jul 21 2017 00:23
@hypercuber Move the continue before the chainLength calculation? Or did that not work. If it is after then it isn't skipping anything?
Guderian Raborg
@hypercuber
Jul 21 2017 00:23
I thought break did what continue does
Stephen James
@sjames1958gm
Jul 21 2017 00:23
@hypercuber No. Break ends the for loop, continue skips to the next iteration of the for loop
Guderian Raborg
@hypercuber
Jul 21 2017 00:24
@sjames1958gm Yea
@sjames1958gm I gotta take my bus. Will keep working on it today. This can help: http://www.mathblog.dk/project-euler-14/
Stephen James
@sjames1958gm
Jul 21 2017 00:26
@dangus21 25 of the 26 aren't going to match, so didn't work will come out a lot. You should break when you find it.
angus
@dangus21
Jul 21 2017 00:26
@sjames1958gm can you make the changes to it?
Stephen James
@sjames1958gm
Jul 21 2017 00:27

@dangus21 if(alphabetic[z].letter == newE[i]){ you were comparing to .number here, should be letter.

         if(alphabetic[z].letter == newE[i]){
            aux.push(alphabetic[z].number)
            break;
         }

then remove the else with doesn't work

angus
@dangus21
Jul 21 2017 00:29
now it doesnt work at all like that
Wadie
@wadie
Jul 21 2017 00:37
Has anyone created "Build a Random Quote Machine" using React ?
Huỳnh Trần Khanh
@khanh2003
Jul 21 2017 01:16
@dangus21 what you need is a hash table:
const alphabet = {
  a: 1,
  b: 2,
  c: 3,
  // you get the idea ...
}
function letterToNumber(char) {
  return alphabet[char];
}
kumquatfelafel
@kumquatfelafel
Jul 21 2017 01:17
@dangus21 why is j 10 and k 12?
王想想
@wxxxxxxxx
Jul 21 2017 01:34
@kumquatfelafel hello Good morning
王想想
@wxxxxxxxx
Jul 21 2017 01:43
switch (card){
case 2,3,4,5,6:
return "5 Bet";
break;
case 7,8,9:
return "0 Hold";
break;
case 10, "J", "Q", "K", "A":
return "-5 Hold";
break;
case 3, 7, 'Q', 8, 'A':
return "-1 Hold";
break;
}
What can not be returned?
Stephen James
@sjames1958gm
Jul 21 2017 01:55
@wxxxxxxxx The instructions are clear that when card is 2-6 you add one to count, 10-A add one to count.
Then after changing count you check for count > 0 and then return the count + string
kumquatfelafel
@kumquatfelafel
Jul 21 2017 01:55

proper syntax: Like this...

case 2:
case 3:
case 4:
//etc.

improper syntax: Not this.

case 2,3,4:

@wxxxxxxxx beyond that there are other problem, but don't have time to address at moment beyond, 2 through 6 increase your "count" by 1, 7 through 9 don't affect count, and 10 through A decrease your "count" by 1. This count is not reset between function calls, so for example if you got 2 and 2, your count would be 2. This count is what you return, in addition to... based on the resulting value of count... whether or not they should "Bet" or "Hold"(if count is greater than 0, you tell them to Bet. Otherwise you tell them to hold).

The basic idea behind this is... https://en.wikipedia.org/wiki/Card_counting

Stephen James
@sjames1958gm
Jul 21 2017 01:57

@dangus21

      for (var z = 0; z < alphabetic.length; z++) {

         if(alphabetic[z].letter == newE[i]){
            aux.push(alphabetic[z].number)
            break;
         }else{
            // console.log('didnt work');
         }

      }

this results in an array of numbers.

[1, 15, 7, 22, 20]
kumquatfelafel @kumquatfelafel is off for now... probably for night.
王想想
@wxxxxxxxx
Jul 21 2017 02:03
@kumquatfelafel ok
thank you
John
@AnonymousLords
Jul 21 2017 02:10
Is anyone here?
Why doesn't this code return the firstName and the prop?
function lookUpProfile(firstName, prop) {
  var result = 0;
  for (var i = 0; i < contacts.length; i++) {
    for (var j = 0; j < contacts[i].length; j++)
      if (firstName == contact[i] && contacts[i][j] == true)
        return contacts[i][j];  
    }
}
Im not worried about the "No such contact" or "No such property" part yet
ill try one more thing
Gulsvi
@gulsvi
Jul 21 2017 02:15
@AnonymousLords contacts is 1D array, so you can only loop through it once.
John
@AnonymousLords
Jul 21 2017 02:16
so no j?
Gulsvi
@gulsvi
Jul 21 2017 02:16
contacts[i][j] will not be valid, correct
John
@AnonymousLords
Jul 21 2017 02:16
okay
is it correct otherwise?
ill try some other code that will allow for the "no contacts" part
Gulsvi
@gulsvi
Jul 21 2017 02:16
No, we should see some use of the hasOwnProperty() method in there
John
@AnonymousLords
Jul 21 2017 02:17
okay
brb on sec
Gulsvi
@gulsvi
Jul 21 2017 02:17
This is a really good exercise for learning how to access these objects - one that I didn't appreciate until later
John
@AnonymousLords
Jul 21 2017 02:18
would i use a loop?
Gulsvi
@gulsvi
Jul 21 2017 02:18
Yes, a loop is great for this one
You basically have 4 objects {} inside an array, so you can loop through the array and test each of those 4 objects for the properties and get their values
John
@AnonymousLords
Jul 21 2017 02:19
okay
John
@AnonymousLords
Jul 21 2017 02:29
@SkyC0der Why wont this work?
function lookUpProfile(firstName, prop) {
  var result = 0;
  for (var i = 0; i < contacts.length; i++) {
    if (contacts[i].hasOwnProperty(firstName))
     return contacts[firstName];
    else return "No such contact";
    if (contacts[i].hasOwnProperty(prop))
      return contacts[prop];
    else return "No such Property";
 }
}
confused .-.
Ken Haduch
@khaduch
Jul 21 2017 02:30
@AnonymousLords - hello... you have to make sure that the firstName argument (the name that you are searching for) and the contacts[i].firstName property match, first, before you can check for the property. So you aren't doing that comparison in your current code.
Gulsvi
@gulsvi
Jul 21 2017 02:30
@AnonymousLords The first if checks if the first object has a property called Akira - that's what the firstName variable will be equal to for that first test case in that challenge
John
@AnonymousLords
Jul 21 2017 02:31
?
Long Nguyen
@longnt80
Jul 21 2017 02:32
@AnonymousLords if (contacts[i].hasOwnProperty(firstName)) this will always be true because all the objects has that firstName property
Gulsvi
@gulsvi
Jul 21 2017 02:32
They do this to add a little confusion. firstName is a variable, but it's also a property name
John
@AnonymousLords
Jul 21 2017 02:32
Okay
is my code close?
Ken Haduch
@khaduch
Jul 21 2017 02:33
@longnt80 @AnonymousLords - that would be if (contacts[i].hasOwnProperty("firstName")) - to be checking for the "firstName" property... which you do not need to do for this challenge... :)
Long Nguyen
@longnt80
Jul 21 2017 02:33
@khaduch oh yes
John
@AnonymousLords
Jul 21 2017 02:33
firstName is a variable
"firstName" is a object
Long Nguyen
@longnt80
Jul 21 2017 02:34
@AnonymousLords you need to compare the firstName with the value of the property firstName in each object
John
@AnonymousLords
Jul 21 2017 02:34
humm
let me try
Long Nguyen
@longnt80
Jul 21 2017 02:35
@AnonymousLords
{
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    }
John
@AnonymousLords
Jul 21 2017 02:35
if (contacts[i] == firstName)) ?
Long Nguyen
@longnt80
Jul 21 2017 02:35
"firstName" is the property, "Akira" is the value
John
@AnonymousLords
Jul 21 2017 02:35
okay
Ohh
Long Nguyen
@longnt80
Jul 21 2017 02:35

if (contacts[i] == firstName))

almost

Joel Y.
@zapcannon99
Jul 21 2017 02:36
@AnonymousLords more like if(contacts[i].firstName == firstName)
John
@AnonymousLords
Jul 21 2017 02:36
okay let me try'
why isnt the else working?
function lookUpProfile(firstName, prop) {
  var result = 0;
  for (var i = 0; i < contacts.length; i++) {
   if (contacts[i].firstName == firstName );
    return (contacts[firstname]); 
    else return "No such contact"; 
 }
}
John
@AnonymousLords
Jul 21 2017 02:41
unexpected token else?
Joel Y.
@zapcannon99
Jul 21 2017 02:41
the semicolons at the end of the if statement
Claudio Restifo
@Marmiz
Jul 21 2017 02:41
@AnonymousLords the ; at the end of the if
John
@AnonymousLords
Jul 21 2017 02:42
Oh :P
so far am i correct?
Long Nguyen
@longnt80
Jul 21 2017 02:42
yes
Joel Y.
@zapcannon99
Jul 21 2017 02:42
yes
Claudio Restifo
@Marmiz
Jul 21 2017 02:42
@AnonymousLords no
Joel Y.
@zapcannon99
Jul 21 2017 02:42
?
Long Nguyen
@longnt80
Jul 21 2017 02:42
lol
Claudio Restifo
@Marmiz
Jul 21 2017 02:43
how can you return no contact if you have not finished looping into all?
Joel Y.
@zapcannon99
Jul 21 2017 02:43
true, I stand corrected
Long Nguyen
@longnt80
Jul 21 2017 02:45
@Marmiz in a sense, it can still be correct
Joel Y.
@zapcannon99
Jul 21 2017 02:46

I mean, if he's asking if he's on the right track sure, but is the logic correct, nahhh

So yeah, John still has some logic to sort out (that we weren't focused on to say the least)

John
@AnonymousLords
Jul 21 2017 02:46
Okay
heres my new code

function lookUpProfile(firstName, prop) {
  var result = 0;
  for (var i = 0; i < contacts.length; i++) {
   if (contacts[i] == firstName)
     return contacts[i];
    else return "No such contact";
    if (contacts[firstName].hasOwnProperty(prop))
      return contacts[prop];
    else return "No such Property";
 }
}
Long Nguyen
@longnt80
Jul 21 2017 02:47
@zapcannon99 no, @Marmiz is right, he should move the return outside the loop
Joel Y.
@zapcannon99
Jul 21 2017 02:47
@AnonymousLords I think Claudio would still say that your logic will not do what you want
Long Nguyen
@longnt80
Jul 21 2017 02:48
@AnonymousLords :point_up: July 21, 2017 9:43 AM
John
@AnonymousLords
Jul 21 2017 02:48
so my for needs a return?
Joel Y.
@zapcannon99
Jul 21 2017 02:48
@AnonymousLords Think about what a for loop does and when you need to return no such property
You want to return after you've exhausted all the elements in your object array
return "no such property" that is
John
@AnonymousLords
Jul 21 2017 02:49
okay so put the return outside of teh loop?
Joel Y.
@zapcannon99
Jul 21 2017 02:49
yep, just like Long said
also, what do you hope to do with contacts[i] == firstName?
Long Nguyen
@longnt80
Jul 21 2017 02:51
@AnonymousLords the question is: what is contacts[i]
Joel Y.
@zapcannon99
Jul 21 2017 02:51
A better question :point_up:
John
@AnonymousLords
Jul 21 2017 02:52
You know the time over to teh right hand side of your screen
hover over it and hit alt-click
Joel Y.
@zapcannon99
Jul 21 2017 02:52
:point_up:
ooooh fancy, learned something important
But yeah, Long's question would be better to answer first
John
@AnonymousLords
Jul 21 2017 02:54
contacts i
test each one
like moves threw teh index
like each object will have a number index
Long Nguyen
@longnt80
Jul 21 2017 02:55
no, what is the value of contacts[i]
John
@AnonymousLords
Jul 21 2017 02:55
a number?
Joel Y.
@zapcannon99
Jul 21 2017 02:55
nope
John
@AnonymousLords
Jul 21 2017 02:55
an object?
Joel Y.
@zapcannon99
Jul 21 2017 02:55
yep
so then when you are trying to do object[i] == firstName, what then are you trying to compare?
John
@AnonymousLords
Jul 21 2017 02:56
the object and firstName
Joel Y.
@zapcannon99
Jul 21 2017 02:56
firstName being what?
What is the type of firstName?
John
@AnonymousLords
Jul 21 2017 02:57
Ohhh
You cant compare it
Joel Y.
@zapcannon99
Jul 21 2017 02:57
well you can, but it won't do what I think you're trying to do
John
@AnonymousLords
Jul 21 2017 02:57
all of the inputs are properties
all redo my code .-.
Long Nguyen
@longnt80
Jul 21 2017 02:58
@AnonymousLords https://repl.it/J9zr/2
hit Ctrl+Enter and see the results for each
Joel Y.
@zapcannon99
Jul 21 2017 02:58
not sure what you mean by that, but yes you can't compare them
Don't redo it all, you just need to fix inside the for loop
John
@AnonymousLords
Jul 21 2017 02:59
how off is it?
humm
...
Joel Y.
@zapcannon99
Jul 21 2017 03:00

I'm seeing that you could probably delete 3 lines, fix 1, and move another 1 out of the for loop to summarize all that we said

And take a look at Long's example to better help you understand what you are working with

John
@AnonymousLords
Jul 21 2017 03:01
ok
ill try again
Joel Y.
@zapcannon99
Jul 21 2017 03:01
Good luck!
John
@AnonymousLords
Jul 21 2017 03:04
why doesnt this work? i haventa dded return yet
if (contacts[i].hasOwnProperty == prop)
      return prop;
Joel Y.
@zapcannon99
Jul 21 2017 03:04
hasownproperty is a function
gotta use it in a function format
John
@AnonymousLords
Jul 21 2017 03:05
wy doesnt it work like that?
It tests teh value of each object
Joel Y.
@zapcannon99
Jul 21 2017 03:07
because hasOwnProperty() takes an input and then returns a result. Can't do that if it's a variable (not in javascript at least, or at least that I'm aware of)
John
@AnonymousLords
Jul 21 2017 03:08
okay
So how am i going to test objects for their values?
is anything wrong with my for loop? (var i = 0; i < contacts.length; i++)
Joel Y.
@zapcannon99
Jul 21 2017 03:08
loop is fine
John
@AnonymousLords
Jul 21 2017 03:08
Okay
Joel Y.
@zapcannon99
Jul 21 2017 03:09
I'm not saying you can't use hasOwnProperty, but you need use it as it was intended which is as a function, not a property of contacts[i]
John
@AnonymousLords
Jul 21 2017 03:09
so use a paramenters?
Joel Y.
@zapcannon99
Jul 21 2017 03:09
You had it right in your previous example
yeah
Huỳnh Trần Khanh
@khanh2003
Jul 21 2017 03:10
  • contacts[i].hasOwnProperty(prop)
    or
  • contacts[i][prop] !== undefined
but not contacts[i].hasOwnProperty === prop
John
@AnonymousLords
Jul 21 2017 03:11
@zapcannon99 which example?
nvm
How close was that example
besides the return function
Joel Y.
@zapcannon99
Jul 21 2017 03:11
function lookUpProfile(firstName, prop) {
var result = 0;
for (var i = 0; i < contacts.length; i++) {
if (contacts[i] == firstName)
return contacts[i];
else return "No such contact";
if (contacts[firstName].hasOwnProperty(prop)) <-----------
return contacts[prop];
else return "No such Property";
}
}
Huỳnh Trần Khanh
@khanh2003
Jul 21 2017 03:11
:point_up: July 21, 2017 9:46 AM @AnonymousLords
Joel Y.
@zapcannon99
Jul 21 2017 03:12
actually, nvm
John
@AnonymousLords
Jul 21 2017 03:12
okay
Joel Y.
@zapcannon99
Jul 21 2017 03:12
You need to do a few things to that line
but that has the correct format for using the hasOwnProperty() function
John
@AnonymousLords
Jul 21 2017 03:13
need help know how to tets a object for its value
Joel Y.
@zapcannon99
Jul 21 2017 03:14
okay
so you have contacts[i]
John
@AnonymousLords
Jul 21 2017 03:14
yes
i have a obkect basically
how do i test its value?
Joel Y.
@zapcannon99
Jul 21 2017 03:14
the hasOwnProperty is function of all Object prototypes
John
@AnonymousLords
Jul 21 2017 03:14
?>
Joel Y.
@zapcannon99
Jul 21 2017 03:15
so just contacts[i].hasOwnProperty("firstName");
John
@AnonymousLords
Jul 21 2017 03:15
is wrong right?
Joel Y.
@zapcannon99
Jul 21 2017 03:15
no
why do you say that? You are looking for a property with the name "firstName" right?
John
@AnonymousLords
Jul 21 2017 03:16
yes
Joel Y.
@zapcannon99
Jul 21 2017 03:16
or are you looking for contacts[i].hasOwnProperty(prop);
John
@AnonymousLords
Jul 21 2017 03:16
both
But i thought you said
I thought you said i had to be a parameter
This message was deleted
Joel Y.
@zapcannon99
Jul 21 2017 03:17
hmmm, don't recall saying that.
John
@AnonymousLords
Jul 21 2017 03:17
oh :P
Joel Y.
@zapcannon99
Jul 21 2017 03:17
Like you said before, i was to access the contacts array
John
@AnonymousLords
Jul 21 2017 03:17
yes
How do i acces and check for both?
or do i do two seprate ones
like two separates if
Joel Y.
@zapcannon99
Jul 21 2017 03:18
so you can combine things
you've already accessed the current object by doing object[i]
John
@AnonymousLords
Jul 21 2017 03:19
okay
now i can check its proptery
Joel Y.
@zapcannon99
Jul 21 2017 03:19
since object[i] is an object, you just need to call on its hasOwnProperty() function and put whatever property you need into the parenthesis
John
@AnonymousLords
Jul 21 2017 03:20
okay
Joel Y.
@zapcannon99
Jul 21 2017 03:20
Did you take a look at Long's example?
John
@AnonymousLords
Jul 21 2017 03:21
yes
Joel Y.
@zapcannon99
Jul 21 2017 03:22
console.log(contacts[i].firstName); This line basically what you want
You can chain accesses and functions
John
@AnonymousLords
Jul 21 2017 03:23
okay
This only works for one of the exmaples


function lookUpProfile(firstName, prop) {
  var result = 0;
  for (var i = 0; i < contacts.length; i++) {
    if (contacts[i].hasOwnProperty(firstName))
      return contacts[i][firstName];
    if (contacts[i].hasOwnProperty(prop))
      return contacts[i][prop];
  }

}
Joel Y.
@zapcannon99
Jul 21 2017 03:26
function lookUpProfile(firstName, prop) {
  var result = 0;
  for (var i = 0; i < contacts.length; i++) {
    if (contacts[i].hasOwnProperty(firstName))   //<-------------------- This line has one thing wrong
      return contacts[i][firstName];
    if (contacts[i].hasOwnProperty(prop))
      return contacts[i][prop];
  }
}
John
@AnonymousLords
Jul 21 2017 03:27
hummm
Joel Y.
@zapcannon99
Jul 21 2017 03:27
specifically firstName
John
@AnonymousLords
Jul 21 2017 03:27
but prop is right>?
Joel Y.
@zapcannon99
Jul 21 2017 03:28
not sure what you are trying to find with prop, but from what I can tell, yes
so my question is, what property are you trying to find
`he function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.
Joel Y.
@zapcannon99
Jul 21 2017 03:29
ahhhh, ok
so I can definitely say that prop is correct
Gulsvi
@gulsvi
Jul 21 2017 03:29

@AnonymousLords

    if (contacts[i].hasOwnProperty(firstName)) 
      return contacts[i][firstName];

^^ Those two lines end up becoming:

    if (contacts[i].hasOwnProperty('akira'))
      return contacts[i]['akira'];
Ogundele Olumide
@Lumexralph
Jul 21 2017 03:29
@zapcannon99
Here's an outline, if you follow it step-wise it'll help a great deal in telling you what to do or step you missed
1. you need a loop to pick each objects in the contacts array
    1.1  in the loop you need to 
         1.1.1  check if the objects picked has the firstName property equal to the firstName parameter
                  1.1.1.1 you need to check if it has a property prop
                                  return the value of prop in the object
                 1.1.1.2  return no such property if  1.1.1.1 is false
2.  when your loop is done looking through  contacts return no such contact
Joel Y.
@zapcannon99
Jul 21 2017 03:30
@Lumexralph Though I'm not the one who needs it, thanks
CamperBot
@camperbot
Jul 21 2017 03:30
zapcannon99 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 2041 | @lumexralph |http://www.freecodecamp.com/lumexralph
John
@AnonymousLords
Jul 21 2017 03:30
me :D
Gulsvi
@gulsvi
Jul 21 2017 03:30
important to distinguish the property firstName from the argument firstName. You can access contacts[i].firstName or contacts[i][firstName] and they will output different things
Ogundele Olumide
@Lumexralph
Jul 21 2017 03:30
@zapcannon99 aw.... sorry, didn't follow the thread
Joel Y.
@zapcannon99
Jul 21 2017 03:30
:point_up: The shorter version of where I'm trying to lead you XP
It's fine,
John
@AnonymousLords
Jul 21 2017 03:31
am i close with my code?
Gulsvi
@gulsvi
Jul 21 2017 03:31
No such thing as close
Joel Y.
@zapcannon99
Jul 21 2017 03:31
yeah, I think the only thing you need to change is that one line
@SkyC0der LOL
Gulsvi
@gulsvi
Jul 21 2017 03:31
code is binary :) 1s and 0s
Joel Y.
@zapcannon99
Jul 21 2017 03:31
how about closer
not with quantum computing!!!
Gulsvi
@gulsvi
Jul 21 2017 03:31
lol
John
@AnonymousLords
Jul 21 2017 03:31
Guys :P
So is my code that far off
Gulsvi
@gulsvi
Jul 21 2017 03:32
Yes, you're understanding it better :)
John
@AnonymousLords
Jul 21 2017 03:32
so it is off?
by a far?
Joel Y.
@zapcannon99
Jul 21 2017 03:32
no, listen to what @SkyC0der said
John
@AnonymousLords
Jul 21 2017 03:32
Joel Y.
@zapcannon99
Jul 21 2017 03:32

(dunno how to do that time quote thing) but

important to distinguish the property firstName from the argument firstName. You can access contacts[i].firstName or contacts[i][firstName] and they will output different things

important to distinguish the property firstName from the argument firstName. You can access contacts[i].firstName or contacts[i][firstName] and they will output different things
John
@AnonymousLords
Jul 21 2017 03:33
doesnt mine already do this?
Joel Y.
@zapcannon99
Jul 21 2017 03:33
no what you've done essentially is say "I want to look up the property called <whatever value the input firstName was>
John
@AnonymousLords
Jul 21 2017 03:34
How do i fix this?
Joel Y.
@zapcannon99
Jul 21 2017 03:34
but firstName in quotes
then what you are now saying is "I want to look up the property 'firstName'" rather than what was stored in the variable firstName
an example of what I'm trying to say
John
@AnonymousLords
Jul 21 2017 03:38
if (contacts[i].FirstName == firstName)
hummm
im really stumped
Joel Y.
@zapcannon99
Jul 21 2017 03:39
all you had to do was add quotes around firstName
if(contacts[i].hasOwnProperty("firstName"))
Gulsvi
@gulsvi
Jul 21 2017 03:40

@AnonymousLords It might be easier to start with one object and try to get values from it:

var firstName = "Harry";
var contacts = [{
  "firstName": "Akira",
  "lastName": "Laine",
  "number": "0543236543",
  "likes": ["Pizza", "Coding", "Brownie Points"]
}];

How to check if Harry is equal to Akira?

John
@AnonymousLords
Jul 21 2017 03:40
` if (contacts[i].hasOwnProperty("firstName"))
humm
if (firstName == "FirstName")
Joel Y.
@zapcannon99
Jul 21 2017 03:41
right
I meant :point_up: July 20, 2017 10:40 PM
John
@AnonymousLords
Jul 21 2017 03:42
ik
Joel Y.
@zapcannon99
Jul 21 2017 03:42
if (contacts[i].hasOwnProperty("firstName"))
John
@AnonymousLords
Jul 21 2017 03:42
Okay this is my code
for (var i = 0; i < contacts.length; i++) {
    if (contacts[i].hasOwnProperty("firstName"))
      return firstName;
    if (contacts[i].hasOwnProperty(prop) == prop)
      return prop;
Joel Y.
@zapcannon99
Jul 21 2017 03:43
Good
now let's see what tests we need to pass cuz I'm sure it's not right answer
Gulsvi
@gulsvi
Jul 21 2017 03:43
contacts[0] would be:
{
  "firstName": "Akira",
  "lastName": "Laine",
  "number": "0543236543",
  "likes": ["Pizza", "Coding", "Brownie Points"]
}
John
@AnonymousLords
Jul 21 2017 03:43
okay
ik
@zapcannon99 it only passed
Gulsvi
@gulsvi
Jul 21 2017 03:44
the number 0543236543 would be contacts[0].number
John
@AnonymousLords
Jul 21 2017 03:44
@SkyC0der okay
Gulsvi
@gulsvi
Jul 21 2017 03:44
If we want to get "Brownie Points" from that, what is it?
John
@AnonymousLords
Jul 21 2017 03:44
My code still has nothing right
Joel Y.
@zapcannon99
Jul 21 2017 03:44
right, we are no where near done yet
John
@AnonymousLords
Jul 21 2017 03:44
@SkyC0der it is
contact[0].likes[2]
Gulsvi
@gulsvi
Jul 21 2017 03:45
contacts[0].likes[2]
Yes, awesome :)
Joel Y.
@zapcannon99
Jul 21 2017 03:45
:thumbsup:
Gulsvi
@gulsvi
Jul 21 2017 03:45
So, "Akira" is contacts[0].firstName
Joel Y.
@zapcannon99
Jul 21 2017 03:45
:thumbsup:
Gulsvi
@gulsvi
Jul 21 2017 03:46
if(contacts[0].firstName === firstName)
----- ^ Akira ------------------- ^ Harry
That's tough lol
John
@AnonymousLords
Jul 21 2017 03:46
lol
Joel Y.
@zapcannon99
Jul 21 2017 03:46
LOL yeah
You get what we are trying to tell you though right John?
John
@AnonymousLords
Jul 21 2017 03:47
well
:point_up: July 20, 2017 11:46 PM makes no sense. But i get it otherwise
Contacts[0] seletcs all 4
Gulsvi
@gulsvi
Jul 21 2017 03:47
It's referring back to this:
var firstName = "Harry";
var contacts = [{
  "firstName": "Akira",
  "lastName": "Laine",
  "number": "0543236543",
  "likes": ["Pizza", "Coding", "Brownie Points"]
}];
Joel Y.
@zapcannon99
Jul 21 2017 03:47
Well let's summarize and maybe it'll make more sense
John
@AnonymousLords
Jul 21 2017 03:48
oh
Joel Y.
@zapcannon99
Jul 21 2017 03:48
Or that
John
@AnonymousLords
Jul 21 2017 03:48
Okay that makes sense now
Gulsvi
@gulsvi
Jul 21 2017 03:48
if you want to check if Harry is equal to Akira, you would do if(contacts[0].firstName === firstName) which would be false because "Akira" isn't equal to "Harry"
John
@AnonymousLords
Jul 21 2017 03:48
 if (contact[i].firstName == firstName)
      return firstName;
Joel Y.
@zapcannon99
Jul 21 2017 03:48
that would work
John
@AnonymousLords
Jul 21 2017 03:49
okay
Gulsvi
@gulsvi
Jul 21 2017 03:49
Except, we never need to return the first name
Joel Y.
@zapcannon99
Jul 21 2017 03:49
right
John
@AnonymousLords
Jul 21 2017 03:49
okay
Joel Y.
@zapcannon99
Jul 21 2017 03:49
That's part of the instructions
that was the next step
Gulsvi
@gulsvi
Jul 21 2017 03:49
If the first name is equal, then check if prop is part of that object
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"
Joel Y.
@zapcannon99
Jul 21 2017 03:50
:point_up:
John
@AnonymousLords
Jul 21 2017 03:50
like if contact[0] also included likes?
return "likes"
Gulsvi
@gulsvi
Jul 21 2017 03:50
yes
John
@AnonymousLords
Jul 21 2017 03:50
butr eally thats prop
okay
Gulsvi
@gulsvi
Jul 21 2017 03:51
prop = "likes"
John
@AnonymousLords
Jul 21 2017 03:53
in trh return sentence of firstname, would i put teh prop sentence?
or seprate if?
@SkyC0der @zapcannon99 ello?
Gulsvi
@gulsvi
Jul 21 2017 03:54
You'll need a separate if statement. Check if the name matches, then check if that object has the property prop
Joel Y.
@zapcannon99
Jul 21 2017 03:54
:point_up:
John
@AnonymousLords
Jul 21 2017 03:55
liek if firstName == true?
Gulsvi
@gulsvi
Jul 21 2017 03:55
if (contacts[i].firstName == firstName)
if that's true you check that the object has the prop we need, if so, return the value of that property, else "no such property"
John
@AnonymousLords
Jul 21 2017 03:57
 if (contacts[i].firstName == firstName)
      return firstName;
    if (firstName == true);
    return (contacts[i].hasOwnProperty(prop));
You just told me two seprate things that counteract each other
Is thsi right yes or no?
Joel Y.
@zapcannon99
Jul 21 2017 03:58
no the instructions didn't say for you to return firstName
John
@AnonymousLords
Jul 21 2017 03:59
````
if (contacts[i].firstName == firstName)
    return (contacts[i].hasOwnProperty(prop));
is this close?
HEllo
Joel Y.
@zapcannon99
Jul 21 2017 04:00
a little closer, but you'll be returning booleans
John
@AnonymousLords
Jul 21 2017 04:01
im so tired
how do i return it ina string?
and add teh else
guys
Joel Y.
@zapcannon99
Jul 21 2017 04:03

you need to access the object's property yes?

And as for the else, if didn't find the name, then else
if you didn't find the property after you've searched through all your contacts, then you return "property not found"

Stanley Su
@stanley-su
Jul 21 2017 04:03

@AnonymousLords In

return (contacts[i].hasOwnProperty(prop));

You’re just returning true or false. You can access the property value through [object][propName]

John
@AnonymousLords
Jul 21 2017 04:05
return ([firstName][prop]); is thsi good?
Guys its been 1 hour and 50 minutes
James Patrick Kerrane
@jamesjpk123
Jul 21 2017 04:06

I need help with my code:

var arrcopy = [];
function chunkArrayInGroups(arr, size) {
  arrcopy.push(arr.slice(0, size));
  arrcopy.push(arr.slice(0 + size, size * 2));
  return arrcopy;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);

When it returns, I get [["a", "b"], ["c", "d"]]. I was wondering why there was two brackets, and how to stop it from having the extra bracket.

John
@AnonymousLords
Jul 21 2017 04:07
@stanley-su hello?
Stanley Su
@stanley-su
Jul 21 2017 04:07
@AnonymousLords You haven’t specified what object you’re accessing
John
@AnonymousLords
Jul 21 2017 04:08
so "firstName"
Joel Y.
@zapcannon99
Jul 21 2017 04:08
@AnonymousLords Maybe it would be better to give this a fresh mind tomorrow if you're tired.
John
@AnonymousLords
Jul 21 2017 04:08
i have afresh mind
I enjoy this help
but 3 word responses every 5 minutes can add up
Stanley Su
@stanley-su
Jul 21 2017 04:09
@AnonymousLords You need to specify the original object that contains the firstname property
John
@AnonymousLords
Jul 21 2017 04:09
return (contacts[i].firstName[prop]);
Hello?
Stanley Su
@stanley-su
Jul 21 2017 04:10
@AnonymousLords Could you link me the question, I forgot what it was like
Stanley Su
@stanley-su
Jul 21 2017 04:11
@AnonymousLords From memory, aren’t you meant to be returning what the person likes?
kumquatfelafel
@kumquatfelafel
Jul 21 2017 04:11
@jamesjpk123 it's supposed to have the inner brackets. You want a 2d array... basically, a bunch of arrays inside an array.
Joel Y.
@zapcannon99
Jul 21 2017 04:12
you are trying to find the prop's value after you figure out it exists
if(contacts[i].hasOwnProperty(prop)) {
  return contacts[i][prop];
}
John
@AnonymousLords
Jul 21 2017 04:12
return (contacts[i][prop]);
function lookUpProfile(firstName, prop) {
  var result = 0;
  for (var i = 0; i < contacts.length; i++) {
    if (contacts[i].firstName == firstName)
    return (contacts[i][prop]);
    else return "No such property";
  }
  return "No such contact";
}
James Patrick Kerrane
@jamesjpk123
Jul 21 2017 04:13
@kumquatfelafel is there any way to remove the outer brackets? I'm supposed to return it like this: chunkArrayInGroups(["a", "b", "c", "d"], 2) should return [["a", "b"], ["c", "d"]]
oh wait
nevermind
Thanks @kumquatfelafel!
CamperBot
@camperbot
Jul 21 2017 04:13
jamesjpk123 sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 512 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Joel Y.
@zapcannon99
Jul 21 2017 04:13
@AnonymousLords Try and see what happens to the tests. It looks right.
John
@AnonymousLords
Jul 21 2017 04:14
No checks
no errors
Stanley Su
@stanley-su
Jul 21 2017 04:15
@AnonymousLords GJ :) Going to be a bit nitpicky, but you don’t need the result variable, nor do you need the paranthesis enclosing contacts[i][prop].
Joel Y.
@zapcannon99
Jul 21 2017 04:15

ah, you somehow took out the second if statement before the returning contacts[i][prop]

The one that checks if the property actually exists

kumquatfelafel
@kumquatfelafel
Jul 21 2017 04:15
@jamesjpk123 that being said, your code has other issues you'll have to deal with. For example, there may be more (or less) than two "chunks" (i.e. subarrays). Your code currently assumes there will always be two.
James Patrick Kerrane
@jamesjpk123
Jul 21 2017 04:16
Oh I'm fixing that now, @kumquatfelafel. Thank you for pointing that out though!
CamperBot
@camperbot
Jul 21 2017 04:16
jamesjpk123 sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:warning: jamesjpk123 already gave kumquatfelafel points
Stanley Su
@stanley-su
Jul 21 2017 04:16
@jamesjpk123 Might need a loop
John
@AnonymousLords
Jul 21 2017 04:16
@zapcannon99 im getting told 3 different things
It checks if it exists, then checks for teh prop
Stanley Su
@stanley-su
Jul 21 2017 04:17
@AnonymousLords Like @zapcannon99 said, you left out the hasOwnProperty check
James Patrick Kerrane
@jamesjpk123
Jul 21 2017 04:17
I added this snippet to the code to help with the issue you brought up:
if(arr.length == 1) {
    return arr;
  }
John
@AnonymousLords
Jul 21 2017 04:18
@stanley-su that returns true of false
James Patrick Kerrane
@jamesjpk123
Jul 21 2017 04:18
:point_up: July 20, 2017 10:17 PM @kumquatfelafel
John
@AnonymousLords
Jul 21 2017 04:18
Okay i was told 3 different thinsg so far on how to do this
James Patrick Kerrane
@jamesjpk123
Jul 21 2017 04:19
I will fix things after 2 chunks later @kumquatfelafel
Joel Y.
@zapcannon99
Jul 21 2017 04:19
Sorry if I wasn't clear. You need that if statement, but you don't want to return hasOwnProperty because that will just return a boolean
Stanley Su
@stanley-su
Jul 21 2017 04:19
@AnonymousLords After checking if contacts[i] is the right person, you need to check if contacts[i] has the property passed into the function
John
@AnonymousLords
Jul 21 2017 04:20
okay so
Do i need havea return statemet on teh first if statement?
Joel Y.
@zapcannon99
Jul 21 2017 04:20
no, you do not need a return on the first if
John
@AnonymousLords
Jul 21 2017 04:21
okay
James Patrick Kerrane
@jamesjpk123
Jul 21 2017 04:22

My code

var arrcopy = [];
function chunkArrayInGroups(arr, size) {
  if(arr.length == 1) {
    return arr;
  }
  arrcopy.push(arr.slice(0, size));
  arrcopy.push(arr.slice(0 + size, size * 2));
  if(arrcopy.length == arr.length / size) {
    arr = arrcopy;
    return arr;
  } else {
    return "uh oh...";
  }

}

chunkArrayInGroups(["a", "b", "c", "d"], 2);

returns ["a", "b"], ["c", "d"] when I want it to include a space after the comma (ex : ["a", "b"], ["c", "d"]). How do I accomplish this? (It seems I am doing something wrong with the challenge if I have to manually add a comma)

John
@AnonymousLords
Jul 21 2017 04:23
Should i use a hasown sattement? @zapcannon99 @stanley-su
kumquatfelafel
@kumquatfelafel
Jul 21 2017 04:23
@jamesjpk123 Just keep in mind, your function could be passed a length 300 array, and a size of 2. Your solution should be capable of handling something like this, much like it would handle ['a', 'b', 'c', 'd'] and 2.
Joel Y.
@zapcannon99
Jul 21 2017 04:23
Yes for the second if
James Patrick Kerrane
@jamesjpk123
Jul 21 2017 04:24
Ok @kumquatfelafel, i'll get to work!
Stanley Su
@stanley-su
Jul 21 2017 04:25
@zapcannon99 Yes.
John
@AnonymousLords
Jul 21 2017 04:25
function lookUpProfile(firstName, prop) {
  var result = 0;
  for (var i = 0; i < contacts.length; i++) {
    if (contacts[i].firstName == firstName)
    if (contacts[i].hasOwnProperty(prop))
      return prop;
    else return "No such property";
  }
  return "No such contact";
}
is my code
Still teh first 3 are not checked?
Joel Y.
@zapcannon99
Jul 21 2017 04:26
return contacts[i][prop]
you're very close I think
Stanley Su
@stanley-su
Jul 21 2017 04:29
@AnonymousLords You’re returning prop, but you should be accessing the prop value of contacts[i]
John
@AnonymousLords
Jul 21 2017 04:29
YES I GOT IT! THANKS SO MUCH @zapcannon99 @stanley-su @zapcannon99 @SkyC0der
CamperBot
@camperbot
Jul 21 2017 04:29
anonymouslords sends brownie points to @zapcannon99 and @stanley-su and @skyc0der :sparkles: :thumbsup: :sparkles:
:cookie: 54 | @stanley-su |http://www.freecodecamp.com/stanley-su
:cookie: 304 | @zapcannon99 |http://www.freecodecamp.com/zapcannon99
:star2: 2174 | @skyc0der |http://www.freecodecamp.com/skyc0der
kumquatfelafel
@kumquatfelafel
Jul 21 2017 04:29
@jamesjpk123 another issue is this... var arrcopy = [];... is being created as a global variable. Remember how for the card counting challenge, the value of your global variable keeping track of count is preserved between function calls? Same thing happens here. So after first call, arrcopy won't be [] anymore. It will be [['a', 'b']['c', 'd']], then maybe after next call it will be [['a', 'b']['c', 'd'],['e'],['f']] ... and so on.
Stanley Su
@stanley-su
Jul 21 2017 04:29
@AnonymousLords gj
John
@AnonymousLords
Jul 21 2017 04:29

function lookUpProfile(firstName, prop) {
  for (var i = 0; i < contacts.length; i++) {
    if (contacts[i].firstName == firstName)
    if (contacts[i].hasOwnProperty(prop))
      return contacts[i][prop];
    else return "No such property";
  }
  return "No such contact";
}
Joel Y.
@zapcannon99
Jul 21 2017 04:29
@AnonymousLords Good job!
John
@AnonymousLords
Jul 21 2017 04:29
ill write down this in my notes tomorrow
on what i learned
i have 101 pages of notes in my composition book
I nearly gave up haflway threw
kumquatfelafel
@kumquatfelafel
Jul 21 2017 04:30
@jamesjpk123 Free code camp calls multiple tests, so even if your first one succeeded, arrcopy being global means all the subsequent tests will likely fail.
John
@AnonymousLords
Jul 21 2017 04:30
so proud :D
Joel Y.
@zapcannon99
Jul 21 2017 04:30
That's impressive
Thanks for sticking with me for two hours
John
@AnonymousLords
Jul 21 2017 04:30
:D
Sorry if i used up your time :P
Gulsvi
@gulsvi
Jul 21 2017 04:31
nice work @AnonymousLords :clap:
CamperBot
@camperbot
Jul 21 2017 04:31
zapcannon99 sends brownie points to @anonymouslords :sparkles: :thumbsup: :sparkles:
:warning: @anonymouslords's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
John
@AnonymousLords
Jul 21 2017 04:31
idk why i cant recive any points :P
Joel Y.
@zapcannon99
Jul 21 2017 04:31
Apparently, not linked with GitHub.
John
@AnonymousLords
Jul 21 2017 04:31
it said i wasnt signed in?
Joel Y.
@zapcannon99
Jul 21 2017 04:31
whatever that means....
:warning: @anonymouslords's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
John
@AnonymousLords
Jul 21 2017 04:32
how?
Ever since a couple days ago when i cleared my search history, this happened
Joel Y.
@zapcannon99
Jul 21 2017 04:32
did you clear your cookies and cache, if you did, it defintely did funky things
hmmm, weird, idk
John
@AnonymousLords
Jul 21 2017 04:33
lol
about @AnonymousLords
CamperBot
@camperbot
Jul 21 2017 04:33
:warning: no user found for anonymouslords
John
@AnonymousLords
Jul 21 2017 04:33
hold up
i dont exist?
Joel Y.
@zapcannon99
Jul 21 2017 04:34
....
That's pretty weird
John
@AnonymousLords
Jul 21 2017 04:34
about this @zapcannon99
CamperBot
@camperbot
Jul 21 2017 04:34
:cookie: 304 | @zapcannon99 |http://www.freecodecamp.com/zapcannon99
John
@AnonymousLords
Jul 21 2017 04:35
267 cookies here
kumquatfelafel
@kumquatfelafel
Jul 21 2017 04:35
John
@AnonymousLords
Jul 21 2017 04:35
what do i change
kumquatfelafel
@kumquatfelafel
Jul 21 2017 04:35
The top icon will mention something about github I think???
John
@AnonymousLords
Jul 21 2017 04:35
it says its "update my profile with gthub)
kumquatfelafel
@kumquatfelafel
Jul 21 2017 04:35
Try that.
John
@AnonymousLords
Jul 21 2017 04:35
it just refreshes page and send sme back to my challange
about @AnonymousLords
CamperBot
@camperbot
Jul 21 2017 04:35
:cookie: 267 | @anonymouslords |http://www.freecodecamp.com/anonymouslords
John
@AnonymousLords
Jul 21 2017 04:36
their we go :P
thanks @AnonymousLords @kumquatfelafel
CamperBot
@camperbot
Jul 21 2017 04:36
anonymouslords sends brownie points to @kumquatfelafel :sparkles: :thumbsup: :sparkles:
:cookie: 513 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
Joel Y.
@zapcannon99
Jul 21 2017 04:36
Yays!
John
@AnonymousLords
Jul 21 2017 04:36
i gtg
Joel Y.
@zapcannon99
Jul 21 2017 04:36
@camperbot Thanks for sticking with me
CamperBot
@camperbot
Jul 21 2017 04:36
zapcannon99 sends brownie points to @camperbot :sparkles: :thumbsup: :sparkles:
:star2: 3374 | @camperbot |http://www.freecodecamp.com/camperbot
John
@AnonymousLords
Jul 21 2017 04:36
can bearly keep my eyes awake
i think im seeing things
Joel Y.
@zapcannon99
Jul 21 2017 04:36
go get sleep dude
John
@AnonymousLords
Jul 21 2017 04:37
i keep seeing things move in the cornor of my eye
Stanley Su
@stanley-su
Jul 21 2017 04:37
wait camperbot has a freecodecamp account
John
@AnonymousLords
Jul 21 2017 04:37
lol ikr
@zapcannon99 you thanked camperbot, not me :P
bye
can bearly type im so tired
Joel Y.
@zapcannon99
Jul 21 2017 04:37
@AnonymousLords Thanks
CamperBot
@camperbot
Jul 21 2017 04:37
zapcannon99 sends brownie points to @anonymouslords :sparkles: :thumbsup: :sparkles:
:cookie: 268 | @anonymouslords |http://www.freecodecamp.com/anonymouslords
John
@AnonymousLords
Jul 21 2017 04:37
and im seeing things
i gtg
Joel Y.
@zapcannon99
Jul 21 2017 04:37
k gn
@stanley-su apparently so lol
I've learned so many non-coding related things today, it's funny
kumquatfelafel
@kumquatfelafel
Jul 21 2017 04:43
I shan't thank @camperbot . Everybody knows they're a brownie hoarder.
CamperBot
@camperbot
Jul 21 2017 04:43
kumquatfelafel sends brownie points to @camperbot :sparkles: :thumbsup: :sparkles:
:star2: 3375 | @camperbot |http://www.freecodecamp.com/camperbot
kumquatfelafel
@kumquatfelafel
Jul 21 2017 04:43
See?
Those were meant for everyone.
Joel Y.
@zapcannon99
Jul 21 2017 04:44
LOL
kumquatfelafel
@kumquatfelafel
Jul 21 2017 04:44
find brownies
CamperBot
@camperbot
Jul 21 2017 04:44
find brownies
nothing found
kumquatfelafel
@kumquatfelafel
Jul 21 2017 04:44
liar :o
Joel Y.
@zapcannon99
Jul 21 2017 04:45
wth lol
I'm gonna leave before this gets too funny
gn
kumquatfelafel
@kumquatfelafel
Jul 21 2017 04:45
night
Joseph
@revisualize
Jul 21 2017 04:46

Is writing this code:

if (condition0) {
     // condition0 true statement
} else if (condition1) {
     // condition1 true statement
} else {
     // condition0 && condition1 false statement
}

is the same as writing:

if (condition0) {
     // condition0 true statement
} else {
     if (condition1) {
           // condition1 true statement
     } else {
           // condition0 && condition1 false statement
     }
}

Because the else if is part of the else statement.
How does the JavaScript engine actually interpret the code?
or does the JavaScript engine actually interpret the else if as an additional condition on the "chain"?
cc: @Masd925 @sjames1958gm @Chrono79

kumquatfelafel
@kumquatfelafel
Jul 21 2017 04:54
@revisualize at the very least, i imagine it must be different if you have something like
else {
    var a = blah; //in terms of... you can't declare variable in the middle of chain without breaking it
    if (condition1) {}
    else {}
}
That being said, dunno about when absolutely nothing inside but another chain of if-else statements.
Dovydas Stirpeika
@Giveback007
Jul 21 2017 05:08
@kumquatfelafel do you ever sleep?
Markus Kiili
@Masd925
Jul 21 2017 05:21
@revisualize Those are the same.
fdemaa
@fdemaa
Jul 21 2017 05:22

Can anyone help me on why im getting this 401 error if i put my client id on my request:

{"data":{"error":"Authentication required","request":"\/3\/album\/{{Sw1Lu}}\/images","method":"GET"},"success":false,"status":401}

Markus Kiili
@Masd925
Jul 21 2017 05:24
@revisualize Second comment should read // condition0 false statement && condition1 true statement
Joseph
@revisualize
Jul 21 2017 05:26
@Masd925 So, the else if is actually part of the else block statement where the optional brackets are removed?
Markus Kiili
@Masd925
Jul 21 2017 05:28
@revisualize Yes, using else if and else is the same as using else and putting if and else inside the block.
Joseph
@revisualize
Jul 21 2017 05:33
@Masd925 But, how does the JS engine parse the code for an else if
I think the answer is... It's part of the else block.
Markus Kiili
@Masd925
Jul 21 2017 05:35
@revisualize Yes.
Viktor Tiutiun
@vittorioVT
Jul 21 2017 05:44
@revisualize In the first case, one of the three conditions must be satisfied, in the second case, one of the two, but the second also has two conditions
Joseph
@revisualize
Jul 21 2017 05:55
@vittorioVT What?
Markus Kiili
@Masd925
Jul 21 2017 05:55
@vittorioVT That makes no sense.
Viktor Tiutiun
@vittorioVT
Jul 21 2017 05:56
@Masd925 why?
Markus Kiili
@Masd925
Jul 21 2017 05:57
@vittorioVT First code block is run if the first condition is truthy (second condition can be either). Second block is run if first condition is falsy and second truthy. Third is run if both are falsy.
Viktor Tiutiun
@vittorioVT
Jul 21 2017 05:58
@Masd925 but only one of the three
Markus Kiili
@Masd925
Jul 21 2017 05:58
Yes, only one block is executed.
Viktor Tiutiun
@vittorioVT
Jul 21 2017 06:00
@Masd925 and in the second case only one of two. so because "makes no sense"?
Markus Kiili
@Masd925
Jul 21 2017 06:03
@vittorioVT It is just a bit confusing to talk about three conditions when there are only two conditions here.
Viktor Tiutiun
@vittorioVT
Jul 21 2017 06:06
@Masd925 yes else - dosn't have a condition, just sometimes my English is my problem :smile:
Markus Kiili
@Masd925
Jul 21 2017 06:08
@vittorioVT Yeah. Just trying to make it clear since this is a help channel. :+1:
codeolas
@codeolas
Jul 21 2017 06:20
Hi all,
str = str.split("").forEach(function(currentValue, index, array){ switch(currentValue){ case "G" : array.push("test"); break; } why is this array push not working? It's meant to add "test" to the str array, but it does nothing
Markus Kiili
@Masd925
Jul 21 2017 06:25
@codeolas Mutating the array forEach was called upon on the callback, can cause fun.
You are not really supposed to use it like that.
codeolas
@codeolas
Jul 21 2017 06:27
@Masd925 what do you mean?
Markus Kiili
@Masd925
Jul 21 2017 06:27
@codeolas You are mutating the array you iterate over. That can mess up the indices etc.
codeolas
@codeolas
Jul 21 2017 06:31
Hold on, I don't know what mutating means. Checking. But I figured out my problem, I'm going to push the result into a new array. I have a feeling that's what you wanted to tell me.
Markus Kiili
@Masd925
Jul 21 2017 06:31
@codeolas Yes, don't change the array you iterate over.
codeolas
@codeolas
Jul 21 2017 06:33
@Masd925 will keep that in mind. :+1:
Pieter Stokkink
@forkerino
Jul 21 2017 06:40
@codeolas @Masd925 One of the reasons why it 'does nothing' is because the return value of .forEach is undefined (by definition)
however, changing it to .map for example and returning the currentValue after the switch, doesn't show "test" being added either, because .map returns an array of the same size as the original. Perhaps the original has been altered.
let me check
Markus Kiili
@Masd925
Jul 21 2017 06:43
@forkerino Neither should mutate the array iterated over.
Pieter Stokkink
@forkerino
Jul 21 2017 06:43
@Masd925 it does
both with .map and .forEach
Markus Kiili
@Masd925
Jul 21 2017 06:44
@forkerino Does what?
Pieter Stokkink
@forkerino
Jul 21 2017 06:44
let arr = "GwelkkwjeG".split('')
arr.forEach(function(currentValue, index, array){ switch(currentValue){ case "G" : array.push("test"); break; }})

console.log(arr) // [ 'G', 'w', 'e', 'l', 'k', 'k', 'w', 'j', 'e', 'G', 'test', 'test' ]
same with .map
codeolas
@codeolas
Jul 21 2017 06:48
@forkerino @Masd925 figured it out, it just needed a new array to be pushed into.
case "G" :
      result.push("G", "C");   
        break;
Markus Kiili
@Masd925
Jul 21 2017 06:49
@forkerino Yeah, might work fine when you add to the end, but maybe best not to do such things.
Pieter Stokkink
@forkerino
Jul 21 2017 06:49
@codeolas that is definitely a better way.
@Masd925 I agree.
Markus Kiili
@Masd925
Jul 21 2017 06:52
@forkerino You are one of those guys who tries to delete the class database on the first sql course :fire:
...hmm...can I do that...
but in all seriousness, I'm just investigating to understand it better.
Markus Kiili
@Masd925
Jul 21 2017 06:55
@forkerino Yeah.
Ugo
@uvieugo
Jul 21 2017 07:53
Hey y'all how's it going, i have a question, Javascript is syncronous that means everything runs all at once...is this correct?
Stanley Su
@stanley-su
Jul 21 2017 07:54
@uvieugo No
Ugo
@uvieugo
Jul 21 2017 07:55
uhm okay
the thing is i'm trying to do something like this
function input(){
 //wait for user input
// do something with user input
}
Markus Kiili
@Masd925
Jul 21 2017 07:57
@uvieugo JS engine is synchronous and it runs one function at a time line by line. Browser in the other hand has other parts too and can do things asynchronously.
Ugo
@uvieugo
Jul 21 2017 07:58
how would i wait for a function to do something before going to the next line
Markus Kiili
@Masd925
Jul 21 2017 08:00
@uvieugo You can use a loop, or something like window.alert or window.confirm.
Usually you structure the code in some other way than like that.
You make things happen when user does something.
Ugo
@uvieugo
Jul 21 2017 08:01
yea i thought of that, was trying to avoid that,
Long Nguyen
@longnt80
Jul 21 2017 08:01
@uvieugo I think you're looking for input event :point_up: July 21, 2017 2:55 PM
Ugo
@uvieugo
Jul 21 2017 08:01
i was think on the line like when a user clicks a grid
Theofanis Despoudis
@theodesp
Jul 21 2017 08:02
@forkerino its classic
Ugo
@uvieugo
Jul 21 2017 08:02
or rather wait for the user to click a grid before doing something
Long Nguyen
@longnt80
Jul 21 2017 08:03
@uvieugo is this what you're looking for? https://www.w3schools.com/jsref/met_document_addeventlistener.asp
Theofanis Despoudis
@theodesp
Jul 21 2017 08:04
sql-injection.jpeg
its called SQL injection
Pieter Stokkink
@forkerino
Jul 21 2017 08:04
hahahaha!
Good one
Theofanis Despoudis
@theodesp
Jul 21 2017 08:04
you know what I mean
Rashad Karanouh
@heus92
Jul 21 2017 08:17
hey everyone ! How are you guys doing ? I'm reaching out bc i have trouble understanding the getjson function. Every time I make it work i don't really understand why it works ^^ I'm now stuck on the wikiviewer challenge with a getjson systematically failling. here is the codepen link https://codepen.io/heus92/pen/PjgmZG
any help ? :smile:
Pieter Stokkink
@forkerino
Jul 21 2017 08:28

@heus92 you had the following error:

No 'Access-Control-Allow-Origin' header is present on the requested resource.

wikipedia supports CORS, but you have to add &origin=* to the url.

Rashad Karanouh
@heus92
Jul 21 2017 08:35
@forkerino it works THANK YOUU !! :yum: Could you tell me how you found this error ? The codepen console did not give me anything...
CamperBot
@camperbot
Jul 21 2017 08:35
heus92 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2881 | @forkerino |http://www.freecodecamp.com/forkerino
Pieter Stokkink
@forkerino
Jul 21 2017 08:37
@heus92 that's because the codepen console doesn't show everything. Use your browser's dev console (usually accessible through F12, or Ctrl Shift J, or through the menu), it is a lot better for developing.
Rajat
@rajataudichya
Jul 21 2017 08:37
what are the various ways in javascript to update a variable?
Ogundele Olumide
@Lumexralph
Jul 21 2017 08:38
@rajataudichya I think assigning a new value to it?
Pieter Stokkink
@forkerino
Jul 21 2017 08:38
@rajataudichya I can only think of assignment
@Lumexralph Bro!
Rashad Karanouh
@heus92
Jul 21 2017 08:38
@forkerino Awesome ! will do ! thank you again =D
CamperBot
@camperbot
Jul 21 2017 08:38
heus92 sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:warning: heus92 already gave forkerino points
Ogundele Olumide
@Lumexralph
Jul 21 2017 08:38
@forkerino @Masd925 Hallo :wave:
@forkerino @Masd925 Good Morning
Pieter Stokkink
@forkerino
Jul 21 2017 08:39
@Lumexralph How are you?
How's the Node course?
Ogundele Olumide
@Lumexralph
Jul 21 2017 08:39
@forkerino I'm good, at work.... you?
@forkerino going well, the new picture is cool
Rajat
@rajataudichya
Jul 21 2017 08:41
@Lumexralph @forkerino I am solving the challenge of updating variables using objects and it says (you can update its properties at any time just like you would update any other variable. ) so I was just wondering how many ways are there to update and which are the common ones used by professionals these days
Pieter Stokkink
@forkerino
Jul 21 2017 08:41
Got the day off (only work 4 days a week). Will meet some friends later and hopefully get some work done for a client I promised to make a website for before I got my job. @Lumexralph
@rajataudichya they are referring to assignment. Just as you can do a = 100
you can do object.property = 100
Clyde Lobo
@oppiniated
Jul 21 2017 08:45
or object["property"] = 100
Pieter Stokkink
@forkerino
Jul 21 2017 08:46
indeed
:clap:
Ogundele Olumide
@Lumexralph
Jul 21 2017 08:47
@forkerino cool, I want to make an ecommerce site for event planning, you think we can cook something up together? won't bother you much
Pieter Stokkink
@forkerino
Jul 21 2017 08:48
@Lumexralph what stack were you thinking of using?
Ogundele Olumide
@Lumexralph
Jul 21 2017 08:50
@forkerino when you say stack what are you referring to?
Pieter Stokkink
@forkerino
Jul 21 2017 08:51
@Lumexralph what frameworks? Node? Express? React? Mongo? Something else?
Ogundele Olumide
@Lumexralph
Jul 21 2017 08:52
@forkerino wanted to be cleared, I think it will be in my skill set..... react, nodejs don't know about database to use yet
Pieter Stokkink
@forkerino
Jul 21 2017 08:53
@Lumexralph I have no experience building something that handles payments from the ground up.... yet. Seems like a good thing to learn.
Kelechi Chinaka
@ke1echi
Jul 21 2017 08:53
morning guys :wave:
Pieter Stokkink
@forkerino
Jul 21 2017 08:54
@kelechy :wave:
Kelechi Chinaka
@ke1echi
Jul 21 2017 08:55
morning code warrior :smile: @forkerino
Ogundele Olumide
@Lumexralph
Jul 21 2017 08:55
@forkerino yeah, that's what I think too... a good way to learn, but we have to build a model or prototype
@kelechy Bro! morning
Kelechi Chinaka
@ke1echi
Jul 21 2017 08:56
greetings @Lumexralph
MERN stack should be great for something like that @Lumexralph @forkerino though i dont know the stack
Ogundele Olumide
@Lumexralph
Jul 21 2017 08:58
@kelechy it should and it's a good learning experince too
Kelechi Chinaka
@ke1echi
Jul 21 2017 08:58
yea true
Ogundele Olumide
@Lumexralph
Jul 21 2017 08:58
@forkerino do you have a model ? or know of a prototype I can tweak ?
Pieter Stokkink
@forkerino
Jul 21 2017 08:58
@Lumexralph a model of what? A complete ecommerce site?
or ... ?
Ogundele Olumide
@Lumexralph
Jul 21 2017 08:59
@forkerino more like a wireframe or flow chart ?
Theofanis Despoudis
@theodesp
Jul 21 2017 09:00
you can utilize https://stripe.com/ie payments
const stripe = require('stripe')('sk_test_BQokikJOvBiI2HlWgH4olfQ2');

// Create your first payment from a test card.
const charge = await stripe.charges.create({
  amount: 2000,
  currency: 'usd',
  source: {
    number: '4242424242424242',
    cvc: '123',
    exp_month: 12,
    exp_year: 2018
  }
});
easy as pie
Pieter Stokkink
@forkerino
Jul 21 2017 09:03
@theodesp nice! Last time I checked stripe their international support was crap, so didn't bother to look at it for a while, but now it looks good! thanks
CamperBot
@camperbot
Jul 21 2017 09:03
forkerino sends brownie points to @theodesp :sparkles: :thumbsup: :sparkles:
:cookie: 381 | @theodesp |http://www.freecodecamp.com/theodesp
Ogundele Olumide
@Lumexralph
Jul 21 2017 09:04
@theodesp heard of stripe but do you by chance know an ecommerce site prototype I can use as blueprint
Theofanis Despoudis
@theodesp
Jul 21 2017 09:05
ok I will search in my github stars :P
i have this
I have this
or
Ogundele Olumide
@Lumexralph
Jul 21 2017 09:07
@theodesp will check it out, thanks man
CamperBot
@camperbot
Jul 21 2017 09:07
lumexralph sends brownie points to @theodesp :sparkles: :thumbsup: :sparkles:
:cookie: 382 | @theodesp |http://www.freecodecamp.com/theodesp
Theofanis Despoudis
@theodesp
Jul 21 2017 09:07
you can hack your way up using plain express
Pieter Stokkink
@forkerino
Jul 21 2017 09:07
^ sounds like more fun
Theofanis Despoudis
@theodesp
Jul 21 2017 09:07
yes
Rinor Bivolaku
@RinorNotorious
Jul 21 2017 09:09

Hello guys, can anyone tell me what's the source code for images in the Darksky API? How do you access the icons? I have this render function that renders data from the mentioned API
-
function render(data, c){
var currentWeather = data.currently.summary;
var currentTemp = displayTemp(data.currently.temperature, c);
var icon = data.currently.icon;

$('#currentTemp').html(currentTemp);
$('#currentWeather').html(currentWeather);

var apiIcon = '' + icon + '.png';
$('#weather-picture').prepend('<img src =' + apiIcon + '>');

}
-
Since I've never used API before, I don't really know how to access images from Darksky.

Ogundele Olumide
@Lumexralph
Jul 21 2017 09:10
@forkerino its looking cool
@theodesp :+1:
Theofanis Despoudis
@theodesp
Jul 21 2017 09:10
there is also this http://keystonejs.com/
Sachin
@sachinmc
Jul 21 2017 09:11
hi folks, question, I am trying to create a regex from a value and pass it to the String.prototype.match method. match accepts variables as a parameter if it is of regex type. To create the regex variable, what I have is another variable input in this case. How can I pass the value of input into the regex variable?
function champion(input, str) {
var re = /input/ //this won't work since it has created a regex for `input` literally, when what I want is the value from the input.
str.match(re); 
.
.
Theofanis Despoudis
@theodesp
Jul 21 2017 09:12
anyway the idea is to have a REST API
Ogundele Olumide
@Lumexralph
Jul 21 2017 09:13
@sachinmc use template literals
@sachinmc or a new RegEX constructor instance
Pieter Stokkink
@forkerino
Jul 21 2017 09:14

@RinorNotorious https://darksky.net/dev/docs/faq

Where do I find the icons?
The API itself doesn't come with any icons: instead, we provide a generic icon property so you can select whatever icons you like! If you want to use the same icon set we use on darksky.net, check out our Skycons library. We also really like Adam Whitcroft's Climacons.

links to the libraries in the original

Sachin
@sachinmc
Jul 21 2017 09:14
@Lumexralph , great let me see
Ogundele Olumide
@Lumexralph
Jul 21 2017 09:16
@sachinmc you need an illustration?
Sachin
@sachinmc
Jul 21 2017 09:17
@Lumexralph yes would help :)
Ogundele Olumide
@Lumexralph
Jul 21 2017 09:18
@sachinmc
let re = new RegExp(input, "g");
Sachin
@sachinmc
Jul 21 2017 09:18
var a = 5;
var b = 10;
console.log(`Fifteen is ${a + b} and
not ${2 * a + b}.`);
// "Fifteen is 15 and
// not 20."
that was from JS MDN, let me try on my problem in console.
Ogundele Olumide
@Lumexralph
Jul 21 2017 09:19
@sachinmc or
let re = /`${input}`/g;   //using template literals
Sachin
@sachinmc
Jul 21 2017 09:19
oh great, please carry on, I could see a RegExp example too @Lumexralph
@Lumexralph
hmmm, what have I got wrong
> input
'ai'
> str
'airplane'
> str.match(/`${input}`/)
null
>
Ogundele Olumide
@Lumexralph
Jul 21 2017 09:23
@sachinmc you need to store the returned array
@sachinmc it's advisable you put a g flag so that match returns only what it matches in the string
Sachin
@sachinmc
Jul 21 2017 09:24
> str.match(/ai/)
[ 'ai', index: 0, input: 'airplane' ]
>
really? it looks ok with above ..
@Lumexralph
Ogundele Olumide
@Lumexralph
Jul 21 2017 09:25
@sachinmc then I think there's no match
Sachin
@sachinmc
Jul 21 2017 09:25
@Lumexralph the variable input holds the string ai
anyway, its a good lead for me, thanks @Lumexralph
CamperBot
@camperbot
Jul 21 2017 09:26
sachinmc sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 2042 | @lumexralph |http://www.freecodecamp.com/lumexralph
Rajat
@rajataudichya
Jul 21 2017 09:33
I am not this challenge
I am on this challenge

What am doing wrong?


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

  // Only change code below this line

     var phoneticLookup = {  

     "alpha":"Adams",
     "bravo": "Boston",
     "charlie":"Chicago",
     "delta":"Denver",
     "echo":"Easy",
     "foxtrot": "Frank",
  };

  result=phoneticLookup.alpha;
  result=phoneticLookup.bravo;
  result=phoneticLookup.charlie;
  result=phoneticLookup.delta;
  result=phoneticLookup.echo;
  result=phoneticLookup.foxtrot;

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

// Change this value to test
phoneticLookup("charlie");
challenge link:https://www.freecodecamp.org/challenges/using-objects-for-lookups
Markus Kiili
@Masd925
Jul 21 2017 09:35
@Lumexralph Morning.
Ogundele Olumide
@Lumexralph
Jul 21 2017 09:39
@rajataudichya 1. You used the name of your function also for the variable in the function.
  1. you need to use val parameter to access the object and assign the value to result
Markus Kiili
@Masd925
Jul 21 2017 09:40
@rajataudichya val holds the property key you need to use.
Jake
@JakeDVirus
Jul 21 2017 09:45
when an event handler is registered to a specific event, then do the function of the handler execute first and the defalut function executes latter or vice versa ?
Sachin
@sachinmc
Jul 21 2017 09:45

hello, could someone explain why this doesn't work?
it looks like string interpolation doesn't work inside / /

>
> input = 'vol'
'vol'
> str = 'volcano'
'volcano'
> str.match(/vol/)
[ 'vol', index: 0, input: 'volcano' ]
>
> str.match(/`${input}`/)
null
> `${input}`
'vol'
>

same story when using constructor:

> var x = new RegExp(/`${input}`/)
undefined
> x
/`${input}`/
>
Markus Kiili
@Masd925
Jul 21 2017 09:56
@NeelDVirus You can prevent the default behaviour from the event handler, so seems that handler is run first.
Sachin
@sachinmc
Jul 21 2017 09:57

ok found what the problem is:

> str.match(`${input}`)
[ 'vol', index: 0, input: 'volcano' ]
>

looks like the pattern matching forward slashes are not required, don't understand why, since ${input} resolves to a string, which then has to be matched.

Blauelf
@Blauelf
Jul 21 2017 09:58
@sachinmc // mark a RegExp literal. `` mark a template literal. Those are different. The RegExp constructor however requires a string, not a RegExp, so you could use var x = new RegExp(input); or for whatever reason var x = new RegExp(`${input}`); (which makes little sense to me)
Sachin
@sachinmc
Jul 21 2017 09:59
@Blauelf thanks for the correction on RegExp constructor input, think I was a bit hasty there :)
CamperBot
@camperbot
Jul 21 2017 09:59
sachinmc sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4522 | @blauelf |http://www.freecodecamp.com/blauelf
Jake
@JakeDVirus
Jul 21 2017 10:00
@Masd925 lets say i have and anchor element<a href="xyz">. i have assigned a handler to a click event on this anchor element. what i want is that when the click event is triggered then the value of href is appended, lets say href="xyzABCD". shall i prevent the default behaviour to do this. or how shall i approach?
Blauelf
@Blauelf
Jul 21 2017 10:01

@sachinmc If you don't need a reusable RegExp object, you can indeed pass a string to match:

Parameters

regexp

A regular expression object. If a non-RegExp object obj is passed, it is implicitly converted to a RegExp by using new RegExp(obj). If you don't give any parameter and use the match() method directly, you will get an Array with an empty string:[""].

@sachinmc Is there a reason why you do `${input}` instead of just input?
Markus Kiili
@Masd925
Jul 21 2017 10:03
@NeelDVirus You prevent default if you don't wan't the link to perform as a link automatically.
Sachin
@sachinmc
Jul 21 2017 10:04
@Blauelf ah fantastic, however, with str.match(/${input}/), match should interpret it as a RegExp object?
PS: there are backticks in there, but markdown appears to be taking precedence
Blauelf
@Blauelf
Jul 21 2017 10:07

@sachinmc As I cited above, if you pass a string to match, it will create a RegExp object from that.

str.match(`${input}`)

is same as

str.match(new RegExp(`${input}`))

If you want to put backticks in inline code, use it like ``double backticks around ` single backticks`` => double backticks around ` single backticks (and yes, there are bugs with spaces just before the end of the inline code block)

Sachin
@sachinmc
Jul 21 2017 10:07
@Blauelf was using string interpolation since I was not aware match did implicit conversion of strings passed to it.
Jake
@JakeDVirus
Jul 21 2017 10:07
@Masd925 i think i got little weak in event operation. so if i prevent default and append the href value to xyzABCD, then after this step what shall i do to redirect the user to the page with the new value of href.
its like pausing the defalut function to operate in the last after appending the value of href attribute.
how shall i do it?
Sachin
@sachinmc
Jul 21 2017 10:07
@Blauelf great, thanks again, I think this answered few questions :)
CamperBot
@camperbot
Jul 21 2017 10:07
sachinmc sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:warning: sachinmc already gave blauelf points
Blauelf
@Blauelf
Jul 21 2017 10:08
@sachinmc String interpolation in your case creates a string from what seems a string already.
Pieter Stokkink
@forkerino
Jul 21 2017 10:11
@NeelDVirus What is it exactly you want to do? What happens on the page and what do you want to happen afterwards?
Markus Kiili
@Masd925
Jul 21 2017 10:11
@NeelDVirus What happens if you just change the href inside the handler. Without preventing default.
Pieter Stokkink
@forkerino
Jul 21 2017 10:12
I'm wondering if the href cannot be altered at an earlier point
aww, snap, gotta go. See you guys later :wave:
Jake
@JakeDVirus
Jul 21 2017 10:17
@forkerino @forkerino i want when the click event is triggered, the value of hrefattribute gets appended/edited and then redirect the the new appended link.
In the html page the anchor element is like this (lets say) <a href="https://abc" >
when the user click the link/button, the href value changes to https://abcXYZ and then the user is redirected to the page with URL https://abcXYZ.
Hope you are getting what i mean.
i know i can directly add "abcXYZ" in the html page itself. but just a curiousity that how it should be done, and suppose in future this is the only option i should approach then how should i.
Markus Kiili
@Masd925
Jul 21 2017 10:19
@NeelDVirus Did you try just changing the href on the click handler?
Jake
@JakeDVirus
Jul 21 2017 10:22
@Masd925 yeah i tried. It is the part of that twitter button. everything is working now. just the case is the appened url.
right now the button redirects to the twitter page to tweet the quote. but since the url is not appened so the quote is not selected.
@Masd925 click the tweet button in my pen and you will get redirectly to the twitter page to tweet. but the quote is not preselected to tweet.
https://codepen.io/neel111/pen/dRBQNY
Markus Kiili
@Masd925
Jul 21 2017 10:24
@NeelDVirus What if you prevent default, append the url and then fire a click event manually.
Jake
@JakeDVirus
Jul 21 2017 10:25
@Masd925 yeah that's what i am asking. how to manually fire a click event to redirect to the new url after preventing the default behaviour?
i repeat- my knowledge of event operation got little blurred
Sachin
@sachinmc
Jul 21 2017 10:25
@Blauelf what if you want match to process a flag too. this means I would have to pass it a RegExp object? How would I achieve this without using the constructor ..
Can't use the literal since // cannot have backticks in them ..?
Blauelf
@Blauelf
Jul 21 2017 10:26
Can you provide an example of what you mean? I just totally not get it.
Jake
@JakeDVirus
Jul 21 2017 10:29
@Masd925 oh thanks for the resource. my brain doesn't work when caught in the mess like cowebs :D
CamperBot
@camperbot
Jul 21 2017 10:29
neeldvirus sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4326 | @masd925 |http://www.freecodecamp.com/masd925
Sachin
@sachinmc
Jul 21 2017 10:31

@Blauelf sure:

>
> input = 'Vol'
'Vol'
> str = 'volcano'
'volcano'
>
> str.match(input)
null
>

It doesn't match because of the cap, how can I pass match the i flag in this instance.

Blauelf
@Blauelf
Jul 21 2017 10:32
@sachinmc Use the constructor manually:
var regex = new RegExp(input, "i");
str.match(regex);
Sachin
@sachinmc
Jul 21 2017 10:33
@Blauelf yes, how can I do it without the constructor ? :smile:
Blauelf
@Blauelf
Jul 21 2017 10:33
???
Sachin
@sachinmc
Jul 21 2017 10:33
@Blauelf match can accept RegExp object defined in literal form.
Blauelf
@Blauelf
Jul 21 2017 10:34
match does not care about how you created the RegExp object, whether by using a RegExp literal or the constructor. It won't know.
But RegExp literals just like any other literal are a pretty static thing.
Sachin
@sachinmc
Jul 21 2017 10:35
@Blauelf so a case where the value is from an input variable and you wish to apply a flag to it, the only way to do it is with the constructor. That is:
/``${input}``/i won't work.
Blauelf
@Blauelf
Jul 21 2017 10:36
Again, you cannot mix two literal types that way!
Sachin
@sachinmc
Jul 21 2017 10:37
@Blauelf alright cool, I think I was attempting to do this.
Rajat
@rajataudichya
Jul 21 2017 10:37
guy need help in using objects for lookup challenge..
can anyone helo me
Blauelf
@Blauelf
Jul 21 2017 10:37
@sachinmc Constructor is the way to go. Also, be careful with user input used in constructing a regular expression. It might not be just plain letters.
Sachin
@sachinmc
Jul 21 2017 10:37
@Blauelf cool!
Stanley Su
@stanley-su
Jul 21 2017 10:39
@rajataudichya Sure.
Blauelf
@Blauelf
Jul 21 2017 10:39
@sachinmc While template literals somehow seem dynamic, they also are pretty static, just their rendering happens at evaluation time.
Rajat
@rajataudichya
Jul 21 2017 10:41
```js

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

  // Only change code below this line


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

  // Only change code below this line


      var lookup = {
     "alpha":"Adams",
     "bravo": "Boston",
     "charlie":"Chicago",
     "delta":"Denver",
     "echo":"Easy",
     "foxtrot": "Frank",

  };


   val = lookup;

 result = phoneticLookup.lookup;




 // Only change code above this line

  return result;
}

// Change this value to test
phoneticLookup("charlie");


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

// Change this value to test
phoneticLookup("charlie");
what am i doing wrong
Blauelf
@Blauelf
Jul 21 2017 10:41
Do not assign to val. It initially contains a property name, the name of the property you need to return the value for.
heroiczero
@heroiczero
Jul 21 2017 10:41
@rajataudichya use the object lookup[property] for your result
Rajat
@rajataudichya
Jul 21 2017 10:43
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line


      var lookup = {
     "alpha":"Adams",
     "bravo": "Boston",
     "charlie":"Chicago",
     "delta":"Denver",
     "echo":"Easy",
     "foxtrot": "Frank",

  };




 result = phoneticLookup.lookup;




 // Only change code above this line

  return result;
}

// Change this value to test
phoneticLookup("charlie");
cowCrazy
@cowCrazy
Jul 21 2017 10:44
@rajataudichya obj.lookup means the object has property named "lookup", obj[lookup] first convert the the lookup var to its string value and then searches the object for it
Markus Kiili
@Masd925
Jul 21 2017 10:44
@rajataudichya The parameter val holds the property key to use.
Blauelf
@Blauelf
Jul 21 2017 10:44
Instead of phoneticLookup.lookup, use object lookup and the property name stored in val (you need to use bracket notation)
Rajat
@rajataudichya
Jul 21 2017 10:44
@cowCrazy @Masd925 @Blauelf Thank you guys
CamperBot
@camperbot
Jul 21 2017 10:44
rajataudichya sends brownie points to @cowcrazy and @masd925 and @blauelf :sparkles: :thumbsup: :sparkles:
:cookie: 295 | @cowcrazy |http://www.freecodecamp.com/cowcrazy
:star2: 4523 | @blauelf |http://www.freecodecamp.com/blauelf
:star2: 4327 | @masd925 |http://www.freecodecamp.com/masd925
Rajat
@rajataudichya
Jul 21 2017 10:48
got it guys
heroiczero
@heroiczero
Jul 21 2017 10:49
@rajataudichya :+1:
Sachin
@sachinmc
Jul 21 2017 10:49
@Blauelf here is an instance where string interpolation is handy:
var re = new RegExp(`^${input}`, 'i')
Blauelf
@Blauelf
Jul 21 2017 10:50
In ES5 days, I would just "^"+input :P
Sachin
@sachinmc
Jul 21 2017 10:50
@Blauelf :smile:
Rajat
@rajataudichya
Jul 21 2017 11:12
@Blauelf why do I need to use bracket notation
heroiczero
@heroiczero
Jul 21 2017 11:13
@rajataudichya because it is treated as a variable
Markus Kiili
@Masd925
Jul 21 2017 11:14
@rajataudichya You need to use the bracket notation if the property key needs to be evaluated from an expression, and not given as a string. Here it is stored on a parameter and needs to be evaluated.
Rajat
@rajataudichya
Jul 21 2017 11:14
@heroiczero this was not explained in any of the challenge... that it has to be treated as a well secondly
heroiczero
@heroiczero
Jul 21 2017 11:15
Rajat
@rajataudichya
Jul 21 2017 11:15
as per what I have learn it should have been result = lookup.prop
.prop= whichever property it is
Markus Kiili
@Masd925
Jul 21 2017 11:16
@rajataudichya That code would look for property key "prop"
If the key is stored on a variable or given as an expression, you need to use bracket notation.
heroiczero
@heroiczero
Jul 21 2017 11:19
@rajataudichya obj.prop is more fixed where prop does not change. If your value of prop changes, you need to use bracket like in the exercise of accessing object with properties with variables
Ugo
@uvieugo
Jul 21 2017 11:33
Hello all
i am trying to simulate a turn by turn function, this is what i have so far
function startPlay(){
  $('.hum').on('click', function(){
    $(this).text(Math.floor(Math.random()*10))
  });
  com.push(Math.floor(Math.random()*10))
  console.log(com)
}

function turns(){
  while (moves <=2){
    console.log(moves)
    startPlay()
    moves +=1
  }
}
how do i get the com.push to wait for my click without putting it in the click event, just incase i want the com.push to go first
heroiczero
@heroiczero
Jul 21 2017 11:37
@uvieugo if you want the computer to go first probably have to create another set of button to choose who goes first the player or the computer after you press start
Ugo
@uvieugo
Jul 21 2017 11:39
@heroiczero okay, but for this instance computer plays all rounds before i click, is there away for me to tell it to wait for my click
so the way it will run will be hum, com, hum, com......
Blauelf
@Blauelf
Jul 21 2017 11:40
Let it take its turn only after you had yours (and you didn't win).
Ugo
@uvieugo
Jul 21 2017 11:40
or am i thinking about it wrong
Blauelf
@Blauelf
Jul 21 2017 11:42
So like click -> process user click -> if it was a valid move, either "win", "draw", or have the computer do one turn
heroiczero
@heroiczero
Jul 21 2017 11:42
@uvieugo you could use a conditional statement when if(true){com.push..
Blauelf
@Blauelf
Jul 21 2017 11:43
Think event-driven. Your game is a state machine, and certain events trigger certain transitions.
Or that's what I assume your simulation is about...
Ugo
@uvieugo
Jul 21 2017 11:44
@Blauelf yea...i thinking in that line, not sure how to go about it, i'm googling but not sure what to read on to solve this
Blauelf
@Blauelf
Jul 21 2017 11:47
@uvieugo on('click', installs an event handler, but for the event to be processed, all your code has to end first. One keyword is "event loop". You don't need to write stuff directly into the event handler, but have it be called from the event handler.
Kelechi Chinaka
@ke1echi
Jul 21 2017 11:50
@Blauelf i need a logic to return shortest word in a string, i just cant wrap my head to get a logic
Ugo
@uvieugo
Jul 21 2017 11:50
@Blauelf .....thanks.....i'll read about the event loop then try again or comeback here.....
CamperBot
@camperbot
Jul 21 2017 11:50
uvieugo sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4524 | @blauelf |http://www.freecodecamp.com/blauelf
heroiczero
@heroiczero
Jul 21 2017 11:54
@kelechy maybe you can separate the sting into an array and use length and a loop to find the shortest string
Blauelf
@Blauelf
Jul 21 2017 12:00
@kelechy Shortest, not longest? There are many ways, one would be to walk the string character by character and on each word end, compare the length of the current word with that of the shortest so far, or you could extract all the words, use like .map(word=>word.length), and then use either a loop or Math.min to find that array's minimum.
Ogundele Olumide
@Lumexralph
Jul 21 2017 12:01
@kelechy maybe you can split, sort by length in ascending order then return first element
@kelechy the word or length of the word ?
Blauelf
@Blauelf
Jul 21 2017 12:03

Oh, that's a valid question. With my .map, I'd throw away the words.

On the sort, I don't like O(nlogn)\mathcal{O}(n \log n) algorithms on an O(n)\mathcal{O}(n) problem.

Kelechi Chinaka
@ke1echi
Jul 21 2017 12:05
nice idea @Lumexralph
shortest @Blauelf
Blauelf
@Blauelf
Jul 21 2017 12:06
And the shortest word, or its length?
heroiczero
@heroiczero
Jul 21 2017 12:07
if its the shortest word, isn't it the smallest length of the string? or am i just getting it wrong?
Ogundele Olumide
@Lumexralph
Jul 21 2017 12:07
@Blauelf yeah... sort can be that way with large data, any better way? to get the word without sort ? I'm thinking reduce
Blauelf
@Blauelf
Jul 21 2017 12:08
I think I might just do something like str.split(" ").filter(Boolean).reduce((w1, w2)=>w1.length<w2.length?w1:w2)
Ogundele Olumide
@Lumexralph
Jul 21 2017 12:08
@heroiczero returning the word that's shortest :smile:
@Blauelf yeah, exactly what I was thinking
Blauelf
@Blauelf
Jul 21 2017 12:09
Depending on the definition of "word", a regular expression might be required.
Kelechi Chinaka
@ke1echi
Jul 21 2017 12:09
fixed @Lumexralph @Blauelf
function findShort(str) {
  str = str.split(' ').sort((a, b) => {
    return a.length - b.length
  });
  return str[0].length;
}
Long Nguyen
@longnt80
Jul 21 2017 12:09
@Blauelf what is this for .filter(Boolean)
heroiczero
@heroiczero
Jul 21 2017 12:09
oh thats true
Blauelf
@Blauelf
Jul 21 2017 12:10
@longnt80 In this case, I just want to remove empty strings. Those are probably not words, but pretty short. And empty string is the only falsy string value.
Ogundele Olumide
@Lumexralph
Jul 21 2017 12:10
@longnt80 calls the Boolean function on all the elements in the array returnd from split method and eliminates any one that comes falsy empty string
Markus Kiili
@Masd925
Jul 21 2017 12:10
@longnt80 Filter already coerces return values to type Boolean. @Blauelf doesn't trust it though ;)
heroiczero
@heroiczero
Jul 21 2017 12:10
@longnt80 to make sure it is a string and not a If the value is omitted or is 0, -0, null, false, NaN, undefined, or the empty string ("" https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean
Long Nguyen
@longnt80
Jul 21 2017 12:10
@Blauelf I see
Blauelf
@Blauelf
Jul 21 2017 12:11
@Masd925 I did not want to create a new function just for that.
Markus Kiili
@Masd925
Jul 21 2017 12:11
@Blauelf Yeah, I know.
Ogundele Olumide
@Lumexralph
Jul 21 2017 12:11
@Masd925 being paranoid can be good move in programming, defensive mode
Long Nguyen
@longnt80
Jul 21 2017 12:12
@heroiczero I know Boolean, I just don't know why the need for filter it though. But I got it now.
Markus Kiili
@Masd925
Jul 21 2017 12:16
@Lumexralph Yeah. The government (reptilians) are fooling us to believe that we live in a globe. So that we won't go exploring the disc and instead just work here like ants and do what the government tells us.
Blauelf
@Blauelf
Jul 21 2017 12:17
@Lumexralph With anybody running their code before yours, you should not trust any built-in function. There are features in ES6 that won't be implemented because Microsoft in one of their products did their own extensions to built-in prototypes, and those would crash on any browser implementing ES6 completely.
@Masd925 Those are not reptilians. Hillary might be a reptilian, but I'm pretty sure Trump is an insectoid.
Markus Kiili
@Masd925
Jul 21 2017 12:19
@Blauelf Yeah, not sure of his true form.
Blauelf
@Blauelf
Jul 21 2017 12:19
Which somehow reminds me of Lexx... (good old days)
One of the best bad SF series.
Long Nguyen
@longnt80
Jul 21 2017 12:20
you guys watching GoT?
Ogundele Olumide
@Lumexralph
Jul 21 2017 12:21
:laughing:
Markus Kiili
@Masd925
Jul 21 2017 12:21
@longnt80 Yeah, had to get HBO a couple of days ago to see the new Season.
Ogundele Olumide
@Lumexralph
Jul 21 2017 12:21
@Blauelf so what do we do? write our own? or watch out for such?
Blauelf
@Blauelf
Jul 21 2017 12:22
I still have to read Song of Ice and Fire. As GoT is loosely based on that one, I want to avoid the series.
Long Nguyen
@longnt80
Jul 21 2017 12:22
@Blauelf so you don't watch it?
only read the book
@Masd925 are you from the US too?
Markus Kiili
@Masd925
Jul 21 2017 12:24
@longnt80 No, Finland.
heroiczero
@heroiczero
Jul 21 2017 12:25
GoT is decent show, but I enjoy the novels more. It is more detailed
Blauelf
@Blauelf
Jul 21 2017 12:25
@longnt80 I don't watch TV. Have a device, but that's used about once a week, mostly for the Heute-Show
Long Nguyen
@longnt80
Jul 21 2017 12:26
@heroiczero I knew about the show before the books so it's hard for me to come back and read
Kelechi Chinaka
@ke1echi
Jul 21 2017 12:26
lol..i use to think am the only one that dont watch tv @Blauelf
Blauelf
@Blauelf
Jul 21 2017 12:26
@Lumexralph In some cases, people advice to have your code run first, and save the functions you rely on to private variables, and use those instead.
heroiczero
@heroiczero
Jul 21 2017 12:27
@longnt80 yeah I read the first book then saw the show. It kinda leaves some of the nuances out of the story. I don't know if its the style or something or the description or something. I just remembering the books were better
Long Nguyen
@longnt80
Jul 21 2017 12:27
@Blauelf @kelechy so you don't watch only TV or you don't watch movies too?
Ogundele Olumide
@Lumexralph
Jul 21 2017 12:28
@Blauelf @kelechy that makes me an addition to your clan
Long Nguyen
@longnt80
Jul 21 2017 12:28
@heroiczero yeah, I understand the feeling
Ogundele Olumide
@Lumexralph
Jul 21 2017 12:28
@longnt80 but I watch movies
Markus Kiili
@Masd925
Jul 21 2017 12:29
@Lumexralph I sometimes watch tv because there is a woman on the sofa looking at it. Otherwise would mostly ignore the machine.
Ogundele Olumide
@Lumexralph
Jul 21 2017 12:29
@Masd925 i understand :joy:
Blauelf
@Blauelf
Jul 21 2017 12:29
@longnt80 I have a few movies I want to watch (like Despicable Me 2), but usually don't find the right time for.
Ogundele Olumide
@Lumexralph
Jul 21 2017 12:30
@Blauelf still not gotten the good time for Fate of the Furious
Blauelf
@Blauelf
Jul 21 2017 12:30
@Masd925 I know that effect. In many cases, I have to explain the movie to her.
Kelechi Chinaka
@ke1echi
Jul 21 2017 12:31
anytime i seat in front of a tv..it has to be me playing a game @longnt80
Blauelf
@Blauelf
Jul 21 2017 12:31
console gamer?
Jake
@JakeDVirus
Jul 21 2017 12:46
@Masd925 LOL :D :D :D :D
Sachin
@sachinmc
Jul 21 2017 12:47
hi!, question on how strings are interpreted in JS. No difference between double and single quotes?
since carriage returns within a string is returning an error unless escaped
i have an input string with lots of carriage returns, which I was going to remove with a function, however the input itself is generating an error
Jake
@JakeDVirus
Jul 21 2017 12:49
@sachinmc i presume no difference between double quotes and single quotes in JS. but JSON uses strict double quotes
Sachin
@sachinmc
Jul 21 2017 12:50
@NeelDVirus can I have a JS string with carriage returns in them? without using \ to escape ..
Kelechi Chinaka
@ke1echi
Jul 21 2017 12:53
dont think so @sachinmc
Jake
@JakeDVirus
Jul 21 2017 12:53
@sachinmc substantiate your context with an example what you are up2. i am not getting you precisely
\r is required for carriage return. using \ gives the following character a special meaning. i dont know what you are up2
Sachin
@sachinmc
Jul 21 2017 12:56
@NeelDVirus sure:
> var str = "hello
var str = "hello
          ^^^^^^
SyntaxError: Invalid or unexpected token

> world"
world"
     ^
SyntaxError: Invalid or unexpected token

> var str = "hello\
... world";
undefined
@NeelDVirus so a carriage return would only be accepted within a string if it is escaped with a \
Blauelf
@Blauelf
Jul 21 2017 12:57
@sachinmc So you get that as part of your code, not as a string?
Sachin
@sachinmc
Jul 21 2017 12:58
@NeelDVirus if I have a long string with lots of carriage returns in them, it seems I won't be able to simply assign that string to a JS var without escaping the carriage returns
Blauelf
@Blauelf
Jul 21 2017 12:58
String templates allow for multi-line, but they have special treatment for their own kind of templating language.
Like
let str = `hello
world`; // no error
Jake
@JakeDVirus
Jul 21 2017 12:59
@sachinmc thinks going beyond the context of my knowledge. you can count on @Blauelf for it i presume
Sachin
@sachinmc
Jul 21 2017 13:00
@Blauelf great, reading it now
Shubham Sharma
@shubhamsrkdev
Jul 21 2017 13:05

Guys I am doing a silly mistake, help So my target is to make an array of arrays with increasing random values:

for (i=0;i<=19;i++){
  arr.push(Math.round(Math.random()*3)+1) ;
   console.log(arr) ;
   marr.push(arr) ; 

  }
   console.log(marr) ;

This code is producing this output:
[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array]]

Blauelf
@Blauelf
Jul 21 2017 13:06
Is it possible that arr and marr are the same?
Michiel
@MichielHuijse
Jul 21 2017 13:07
hi, why doesn't this return the last namen?
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line


    var arr = collection.filter(function(collectable){
   {
         if (collection.last == source.last){
             return collection.last;
         }
     }
});




  // Only change code above this line
    console.log(arr);
  return arr;
}

whatIsInAName([{ last: "Capulet" }], { last:"Capulet" });
Blauelf
@Blauelf
Jul 21 2017 13:08
@MichielHuijse You meant collectable.last instead of collection.last?
Shubham Sharma
@shubhamsrkdev
Jul 21 2017 13:09
@Blauelf Nope arr will be a single array with 20 random values while marr will be an array of 20 arrays each having random values increasing from 1 to 20
Blauelf
@Blauelf
Jul 21 2017 13:09
@shubhamsrkdev Show the code.
Michiel
@MichielHuijse
Jul 21 2017 13:10
@Blauelf could be, not sure :)
thinkC
@thinkC
Jul 21 2017 13:11
Hi Campers..pls help check this out...I need the second else if statement to return false
function checkNow(str){
    str = str;
    console.log(str);
   var digit = /\d/;
    var word = /\W/g;
    if(str.match(digit) && str.length  >= 10){
        return true;
    }
    else if(str.match(word) && str.match(digit) ){
      return false;
    }




}

console.log(checkNow("555-555-5555"));
console.log(checkNow("123**&!!asdf#"));
but returning true
Sachin
@sachinmc
Jul 21 2017 13:11
@MichielHuijse looks like it is, collection is the array and collectable is the object whose property last you are trying to access :)
Moisés Man
@moigithub
Jul 21 2017 13:12
\W what means on regex ?? @thinkC
what that whole code should do ?
heroiczero
@heroiczero
Jul 21 2017 13:12
@thinkC are you trying to check if its a phone number, if so then you can try using regexp
thinkC
@thinkC
Jul 21 2017 13:13
it means not word...signs, special charaters
@heroiczero yes
heroiczero
@heroiczero
Jul 21 2017 13:13
@moigithub \W= [^A-Za-z0-9_]
Moisés Man
@moigithub
Jul 21 2017 13:14
if mean NOT words.... maybe word its NOT a good variable naming :P
Dovydas Stirpeika
@Giveback007
Jul 21 2017 13:14
hey peeps I have a performance question regarding java script
which is faster an array of true false or an array of 1 0
heroiczero
@heroiczero
Jul 21 2017 13:14
@thinkC you can solve it with one regexp
thinkC
@thinkC
Jul 21 2017 13:14
\W matches space, signs, special characters
Blauelf
@Blauelf
Jul 21 2017 13:15
It doesn't match underscore _
thinkC
@thinkC
Jul 21 2017 13:16
@Blauelf yes, does not match _
not sure why it's returning true
Blauelf
@Blauelf
Jul 21 2017 13:18
The string contains at least one digit and is at least 10 characters long?
thinkC
@thinkC
Jul 21 2017 13:19
@Blauelf yes
Blauelf
@Blauelf
Jul 21 2017 13:19
Then what should you be unsure about?
thinkC
@thinkC
Jul 21 2017 13:19
that's it
ok @Blauelf but if I remove the length of the digit ...it still return true
Blauelf
@Blauelf
Jul 21 2017 13:21
You remove a restriction and wonder why the condition still applies?
Michiel
@MichielHuijse
Jul 21 2017 13:21
@sachinmc I would say this should console.log : "Capulet" . But it just returns the empty arr.
// Javascript 

function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line

    var arr = collection.filter(function(last){
   {
         if (collection.last == source.last){
             return collection.last;
         }
     }
});

  // Only change code above this line
    console.log(arr);
  return arr;
}

whatIsInAName( [{last: "Capulet" }], { last: "Capulet" })
Shubham Sharma
@shubhamsrkdev
Jul 21 2017 13:22

@Blauelf I will rephrase my question, There is a master array (marr) and a small array (arr) Now my target is to insert these arr into marr. for example first arr=[1] and marr=[[1]] then arr=[1,2] and marr=[[1],[1,2]] and so on.

var arr=[] ;
  var marr=[] ;
  for (i=0;i<=19;i++){
  arr.push(Math.round(Math.random()*3)+1) ;
  console.log(arr) ;
  marr.push(arr) ; 

  }
   console.log(marr) ;

This outputs :[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array], [circular object Array]]

Blauelf
@Blauelf
Jul 21 2017 13:23
Umm... in this case, it looks as you've pushed the same array 20 times.
thinkC
@thinkC
Jul 21 2017 13:24
@Blauelf yes...why does it still apply...if it only digit return true, else if its word and digit return false
Blauelf
@Blauelf
Jul 21 2017 13:24
Not sure how this should become circular, though.
What happens is that you push the same array 20 times, and you push 20 numbers to that array. You'd have to create copies of the arrays to have them be different.
Sachin
@sachinmc
Jul 21 2017 13:26

@ @MichielHuijse try this:

function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line

    var arr = collection.filter(function(collectable){
   {
         if (collectable.last == source.last){
             return collectable.last;
         }
     }
});

  // Only change code above this line
  console.log(arr[0].last);
  return arr;
}

whatIsInAName( [{last: "Capulet" }], { last: "Capulet" })

what I've changed from your original code is console.log(arr[0].last) and replace collection with collectable within the callback function.

Blauelf
@Blauelf
Jul 21 2017 13:27
@shubhamsrkdev I think marr.push(arr.slice()); could work the way you want it to. I don't like that rounding function, though, it makes 1 and 4 less likely than 2 and 3.
@thinkC Why don't you try to build a regular expression that would match only somewhat valid looking phone numbers?
Shubham Sharma
@shubhamsrkdev
Jul 21 2017 13:29
@Blauelf Thank you Got it right!!
CamperBot
@camperbot
Jul 21 2017 13:29
shubhamsrkdev sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4525 | @blauelf |http://www.freecodecamp.com/blauelf
Michiel
@MichielHuijse
Jul 21 2017 13:29
@sachinmc thank u
CamperBot
@camperbot
Jul 21 2017 13:29
michielhuijse sends brownie points to @sachinmc :sparkles: :thumbsup: :sparkles:
:cookie: 259 | @sachinmc |http://www.freecodecamp.com/sachinmc
thinkC
@thinkC
Jul 21 2017 13:30
@Blauelf ok
@Blauelf then return else for the invalid ones
Blauelf
@Blauelf
Jul 21 2017 13:31
@thinkC One can really write that whole function as return /some RegExp/.test(str);
thinkC
@thinkC
Jul 21 2017 13:32
@Blauelf will try that thanks
CamperBot
@camperbot
Jul 21 2017 13:32
thinkc sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4526 | @blauelf |http://www.freecodecamp.com/blauelf
Thayyeb salim
@Thayyebsalim
Jul 21 2017 13:38
thanks @JackEdwardLyons
CamperBot
@camperbot
Jul 21 2017 13:38
thayyebsalim sends brownie points to @jackedwardlyons :sparkles: :thumbsup: :sparkles:
:cookie: 356 | @jackedwardlyons |http://www.freecodecamp.com/jackedwardlyons