These are chat archives for FreeCodeCamp/HelpJavaScript

12th
Apr 2016
Paul Borawski
@iAmNawa
Apr 12 2016 00:02
@kalmont3 how can I help?
Stephane
@overmelo
Apr 12 2016 00:02
apparently sleeping time
John Prada
@jhonsnake
Apr 12 2016 00:06
This message was deleted

function caseInSwitch(val) {
var answer = "";
// Only change code below this line
case val 1:
answer ==="alpha";
break;
case val 2:
answer ==="beta";
break;
case val 3:
answer ==="gamma";
break;
case val 4:
answer ==="delta";
break;

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

// Change this value to test
caseInSwitch(1);

buonarfcc
@buonarfcc
Apr 12 2016 00:14

Hello Please help me with TypeError: cannot read property 'glove box' of undefined with the following codes: var myStorage = {
"car": {
"inside": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};

// Only change code below this line

var gloveBoxContents = myStorage.inside["glove box"];
console.log(gloveBoxContents); Thank you.:)

Rada
@Radascript
Apr 12 2016 00:16
@buonarfcc your inside is inside a car object, you omitted it
myStorage.car.inside["glove box"];
rather than myStorage.inside["glove box"];
V1ad1m1r
@V1ad1m1r
Apr 12 2016 00:18
js
function destroyer(arr) {
  // Remove all the values

  var newArr = [];
       var args = [].slice.call(arguments, 1);



  newArr = arr.filter(function(val){

      for(var x=0; x<args.length; x++){          

             return val != args[x];                 

      }  }  );

  return newArr;
}

destroyer([3, 5, 1, 2, 2], 2, 3, 5);
Guys, Ive been working on this one for 2 days. For some reason it just escapes me. I have it rremoving the arguments, but it jumps out of the for loop before getting past args[0]. I assume thats because I am returning the value... but how do I get what I am looking for without using return...
buonarfcc
@buonarfcc
Apr 12 2016 00:19
Duuuh. Thank you Radascript:)
Tien Anh Nguyen
@tienanh2007
Apr 12 2016 00:20
@bitgrower oh no I already figured it out. I was just see what their solution is and it is more efficient.
Rada
@Radascript
Apr 12 2016 00:25
@buonarfcc yw :)
hrokr
@hrokr
Apr 12 2016 00:27
This message was deleted
V1ad1m1r
@V1ad1m1r
Apr 12 2016 00:28
anyone got any ideas?
hrokr
@hrokr
Apr 12 2016 00:28
Here is the code:
This message was deleted
help formatting
CamperBot
@camperbot
Apr 12 2016 00:28

:point_right: code formatting [wiki]

Multi line Code

```js ⇦ Type 3 backticks and then press [shift + enter ⏎] (type js or html or css)

<paste your code here>,
then press [shift + enter ⏎]

``` ⇦ Type 3 backticks, then press [enter ⏎]

Single line Code

This an inline `<paste code here>` code formatting with a single backtick(`) at start and end around the code.

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

:pencil: read more about code formatting on the FCC Wiki

Tien Anh Nguyen
@tienanh2007
Apr 12 2016 00:29
help Steamroller
CamperBot
@camperbot
Apr 12 2016 00:29

:point_right: algorithm steamroller [wiki]

Explanation:

This problem seems simple but you need to make sure to flatten any array, regardless of the level which is what adds a bit of difficulty to the problem.

:pencil: read more about algorithm steamroller on the FCC Wiki

V1ad1m1r
@V1ad1m1r
Apr 12 2016 00:32
help seek and destroy
CamperBot
@camperbot
Apr 12 2016 00:32

:point_right: algorithm seek and destroy [wiki]

Explanation:

This problem is a bit tricky because you have to familiarize yourself with Arguments, as you will have to work with two or more but on the script you only see two. Many people hardcode this program for three arguments. You will remove any number from the first argument that is the same as any other other arguments.

:pencil: read more about algorithm seek and destroy on the FCC Wiki

Darryn Bourgeois
@nyrrad
Apr 12 2016 00:32
@V1ad1m1r i sent you a private message
hrokr
@hrokr
Apr 12 2016 00:35
This message was deleted
Let's try this once again. I'm having a problem with the 'record collection'. Could someone please give me a hand with it? Here is the code:
// Setup
var collection = {
    2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    2468: {
      album: "1999",
      artist: "Prince",
      tracks: [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    1245: {
      artist: "Robert Palmer",
      tracks: [ ]
    },
    5439: {
      album: "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {


  if ((collection[id][prop] !=="tracks") && (collection[id][value] !== ""));
      {collection[id][prop]= value;}

  else if ((collection[id][prop] === "tracks") && (collection[id][value] !=="" ));
      {collection[id][prop].push(value);}  

  else if (value === "");
      {delete collection[id][prop];}


  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
hrokr
@hrokr
Apr 12 2016 00:43
@V1ad1m1r -- You're ahead of me but would JSON's delete do it?
V1ad1m1r
@V1ad1m1r
Apr 12 2016 00:44
@hrokr in theory .filter should automatically delete the elements rather than having to individually delete them
maybe
Moisés Man
@moigithub
Apr 12 2016 00:47
@hrokr collection dont have any value property
collection[id][value] !== "")); wrong..
what u need to do is check if the variable value is empty or not...
also dont use { code }<<-- curly brackets.. remove em from ur code
@V1ad1m1r problem is u returning too soon from ur filter callback
@V1ad1m1r u need to check each elements from the array val vs both/or ALL args before decides return true or false
Tien Anh Nguyen
@tienanh2007
Apr 12 2016 00:53
Could someone tell me what's wrong with my steamroller recursion ?
function steamrollArray(arr) {
  return sra(arr);
}
function sra(a){
  var arr = [];
  if(Array.isArray(a)){
  for(var i=0;i<a.length;i++)
    arr.concat(sra(a[i]));
  }
  else{
    arr.push(a);
  }

  return arr;
}
steamrollArray(1);
steamrollArray([1, [2], [3, [[4]]]]);
It's just produce an empty array
Darryn Bourgeois
@nyrrad
Apr 12 2016 00:54
@tienanh2007 your function is outside of the steamrollArray
Tien Anh Nguyen
@tienanh2007
Apr 12 2016 00:54
@nyrrad I called it inside steamrollArray though
Darryn Bourgeois
@nyrrad
Apr 12 2016 00:55
not according to the brackets there.
function steamrollArray(arr) {
return sra(arr);
}
Tien Anh Nguyen
@tienanh2007
Apr 12 2016 00:55
@nyrrad sorry, I'm still lost
Darryn Bourgeois
@nyrrad
Apr 12 2016 00:55
or wait im dumb haha
V1ad1m1r
@V1ad1m1r
Apr 12 2016 00:56
@nyrrad @moigithub thanks guys. man that one was a killer for me.
CamperBot
@camperbot
Apr 12 2016 00:56
v1ad1m1r sends brownie points to @nyrrad and @moigithub :sparkles: :thumbsup: :sparkles:
Tien Anh Nguyen
@tienanh2007
Apr 12 2016 00:56
@tienanh2007 it's fine thank you for looking at it thoguht
CamperBot
@camperbot
Apr 12 2016 00:56
:star: 883 | @moigithub | http://www.freecodecamp.com/moigithub
:star: 146 | @nyrrad | http://www.freecodecamp.com/nyrrad
Darryn Bourgeois
@nyrrad
Apr 12 2016 00:56
dont mind me, im blind
Moisés Man
@moigithub
Apr 12 2016 00:56
@moigithub actually. ... if the element found on the args to discard.. return false immediatelly... but its not the same case for true
hrokr
@hrokr
Apr 12 2016 00:57
@moigithub -- So, I think what you're saying is where I put this collection[id][prop].push(value) , since value isn't a property, I can't address it.
Moisés Man
@moigithub
Apr 12 2016 00:59
 && (collection[id][value] !== ""));
@hrokr
if id = 2548
and u do collection[id] u will get this
2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
Tien Anh Nguyen
@tienanh2007
Apr 12 2016 00:59
help Steamroller
CamperBot
@camperbot
Apr 12 2016 00:59

:point_right: algorithm steamroller [wiki]

Explanation:

This problem seems simple but you need to make sure to flatten any array, regardless of the level which is what adds a bit of difficulty to the problem.

:pencil: read more about algorithm steamroller on the FCC Wiki

Moisés Man
@moigithub
Apr 12 2016 00:59
but.... u also including value there...
value dont ahve any property name on it...
so collecion[id][value] will return nothing/probably undefined
@hrokr
the exercise say.. check if value is not empty
if (value !== "") { ..... }
Tien Anh Nguyen
@tienanh2007
Apr 12 2016 01:09
I change the code which provide correct answer but doesn't complete any test-case for some reason
hrokr
@hrokr
Apr 12 2016 01:09
@moigithub -- still working on the meaning moigithub. I can see how checking to see if value is empty or not also streamlines things.
Tien Anh Nguyen
@tienanh2007
Apr 12 2016 01:09
function steamrollArray(arr) {
  return sra(arr);
}
var array = [];
function sra(a){

  if(Array.isArray(a)){
  for(var i=0;i<a.length;i++)
    sra(a[i]);
  }
  else{
    array.push(a);
  }

  return array;
}
steamrollArray([1, [], [3, [[4]]]]);
Moisés Man
@moigithub
Apr 12 2016 01:09

@tienanh2007 recursive.. means.. a function.. call to itself inside
like

  function loopMe(){
         loopMe();
  }

.. this will calling itself INFINITELLY
sooo to avoid this infinite loop.. u need to SetUp a base case or an EXIT point so it STOP at some point

Tien Anh Nguyen
@tienanh2007
Apr 12 2016 01:09
@moigithub yep I think I did call it
Moisés Man
@moigithub
Apr 12 2016 01:10
u calling a different function
not itself
Tien Anh Nguyen
@tienanh2007
Apr 12 2016 01:10
@moigithub yeah read it please
sra it's a recursive function
Moisés Man
@moigithub
Apr 12 2016 01:10
ok.. sra()
Tien Anh Nguyen
@tienanh2007
Apr 12 2016 01:10
it a helper recursive function
Moisés Man
@moigithub
Apr 12 2016 01:10
was reading steamroller
Tien Anh Nguyen
@tienanh2007
Apr 12 2016 01:11
it's fine but what i'm wondering is why it produce the correct answer in the console but doesn't complete the challenge
Moisés Man
@moigithub
Apr 12 2016 01:12
try to refresh the browser
if not work..copy ur code.. reset n paste code
sometimes the test get a hiccup :D
Tien Anh Nguyen
@tienanh2007
Apr 12 2016 01:13
nope even the answer from the wiki doesn't work
I think I'm jsut gonna skip this
Tien Anh Nguyen
@tienanh2007
Apr 12 2016 01:31
help Everything Be True
CamperBot
@camperbot
Apr 12 2016 01:31

:point_right: algorithm everything be true [wiki]

Explanation:

The program needs to check if the second argument is a truthy element, and it must check this for each object in the first argument.

Hint: 1

Remember to iterate through the first argument to check each object.

Hint: 2

Only if all of them are truth will we return true, so make sure all of them check.

Hint: 3

You could use loops or callbacks functions, there are multiple ways to solve this problem.

Spoiler Alert!

687474703a2f2f7777772e796f75726472756d2e636f6d2f796f75726472756d2f696d616765732f323030372f31302f31302f7265645f7761726e696e675f7369676e5f322e676966.gif

Solutions ahead!

:pencil: read more about algorithm everything be true on the FCC Wiki

rphares
@rphares
Apr 12 2016 01:32
@tienanh2007 -- not looking at your code, but i recall there have been so name changes in some of the BFs recently... you might check to see if the names match up with all the tests...
hrokr
@hrokr
Apr 12 2016 01:36
This message was deleted
// Setup
var collection = {
    2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    2468: {
      album: "1999",
      artist: "Prince",
      tracks: [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    1245: {
      artist: "Robert Palmer",
      tracks: [ ]
    },
    5439: {
      album: "ABBA Gold"
    }
};


  // Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {

 if (value !=="") 
   {
      if (collection[id][prop] !=="tracks") {
       collection[id][prop]= value;

      } else {
       collection[id][prop].push(value); 
      }
   }

  else {
      delete collection[id][prop];
  }


  return collection;

}



// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
Jonathan C
@jcupples
Apr 12 2016 01:37
What the heck am I missing?
function largestOfFour(arr) {

  var biggestNum = 0;
  for(i = 0; i < arr.length; i++)
    {
      for (j = 0; j < arr.length; j++)
        {
          if(arr[i][j] > biggestNum)
            {
              biggestNum = arr[i][j];
            }
        }
    }
  return arr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
hrokr
@hrokr
Apr 12 2016 01:38
@moigithub -- here is the weird thing: when I go and feed in the Rober Palmer to see if what help the console log might be, it says everything is fine.
Coy Sanders
@coymeetsworld
Apr 12 2016 01:39
you're just returning the same arr back @jcupples
you need to return a new array, with the largest value of each of those 4 arrays as the values
hrokr
@hrokr
Apr 12 2016 01:42
@moigithub --- I think what I'm doing is putting the value there but am not making an array.
Frank XC
@tenkdayz
Apr 12 2016 01:46
@jcupples youre returning arr not biggestNum
John Drevniok
@johndrevniok
Apr 12 2016 01:47
Hello, I am at the challenge 'Check for Palindromes'
This is my code so far:
function palindrome(str) {
var sanitizedStr = str.replace(/[^A-Z0-9]/ig, "").toLowerCase();
var reverseStr = str.split('').reverse().join('');
return (sanitizedStr == reverseStr);
}
Rich Hopkins
@Rich-Hopkins
Apr 12 2016 01:48
@jcupples also, you are returning the original array, unchanged.
Jonathan C
@jcupples
Apr 12 2016 01:51

It's still just printing out the largest number which would be 1001. Would push() help?

function largestOfFour(arr) {

  var biggestNum = 0;

  for(i = 0; i < arr.length; i++)
    {
      for (j = 0; j < arr.length; j++)
        {
          if(arr[i][j] > biggestNum)
            {
              biggestNum = arr[i][j];

            }
        }
    }
  return biggestNum;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

```

Frank XC
@tenkdayz
Apr 12 2016 01:52
@jcupples what does it need to return?
Jonathan C
@jcupples
Apr 12 2016 01:52
@tenkdayz It needs to return the largest number from each array
Frank XC
@tenkdayz
Apr 12 2016 01:53
oh.. so make biggestNum a = []
and sort every array in arr. then push the last index into biggestNum
wells that one way.
Rich Hopkins
@Rich-Hopkins
Apr 12 2016 01:56
@jcupples you need to return an array.
I started out by creating a newArray variable, and pushed the numbers into it that needed to be in it.
I then returned that new array.
Frank XC
@tenkdayz
Apr 12 2016 02:00
@Rich-Hopkins oh he can also us the newArr.push(Math.max(arr[i]));
Jonathan C
@jcupples
Apr 12 2016 02:03
It's telling me biggestNum.sort() isn't a function
function largestOfFour(arr) {

  var biggestNum = [];
  var newArray =[];

  for(i = 0; i < arr.length; i++)
    {
      for (j = 0; j < arr.length; j++)
        {
          if(arr[i][j] > biggestNum)
            {
              biggestNum = arr[i][j];
             biggestNum.sort();
            }
        }
    }
  return biggestNum.push(newArray);
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
soydeedo
@soydeedo
Apr 12 2016 02:04
biggestNum is a single number
i'm guessing you'd want to sort on the array
Jonathan C
@jcupples
Apr 12 2016 02:06
Still not working no matter what I put in front of sort()
soydeedo
@soydeedo
Apr 12 2016 02:09
keep at it. you might want to try simplifying a bit outside of the for loop first so you understand the core
if you're sorting, you probably want the largest of those numbers, which would be the last item in the array
Kurt Johnson
@pompan129
Apr 12 2016 02:11
@jcupples also sort() doesnt work with numbers unless you provide a callback function. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
Frank XC
@tenkdayz
Apr 12 2016 02:12
@jcupples biggestNum is just one number at the end of the loop thats why it's returning that error message
Nick Robson
@nickrobson
Apr 12 2016 02:14
Hey all. I'm back! :skull:
Coy Sanders
@coymeetsworld
Apr 12 2016 02:15
no you don't need a callback @soydeedo
the problem is calling sort here, you're not sorting anything
and biggestNum keeps getting reassigned to each element which you don't want to do either
if you use sort, you don't need that 2nd loop
Moustafa Ragheb
@Mouragheb
Apr 12 2016 02:26
heeey guys i am stuck in the profile lookup challenge
any hints?
Mauricio
@maudevelop
Apr 12 2016 02:27
Hey, on the Where Art Thou algorithm, i'm having trouble understanding what the program is trying to do, anyone that could help me explaining it better than on the instrunctions please?
Ken Haduch
@khaduch
Apr 12 2016 02:33
@Moeragheb - how much progress have you made on the profile lookup challenge? Could you post your code or ask some specific questions? You can get help here, for sure!
Nick Robson
@nickrobson
Apr 12 2016 02:34
wiki where art thou
CamperBot
@camperbot
Apr 12 2016 02:34

:point_right: algorithm where art thou [wiki]

Problem Explanation

Write an algorithm that will take an array for the first argument and return an array with all the objects that matches all the properties and values in the Object passed as second parameter.

:pencil: read more about algorithm where art thou on the FCC Wiki

Ken Haduch
@khaduch
Apr 12 2016 02:36
@johndrevniok - Palindromes - how is this working out so far?? I find it beneficial to put some console.log statements in there to see what you are getting for strings. Then I compared those against what the tests indicated should be matching and not matching, and then made adjustments until your algorithm implementation was passing the tests. It looks like you are on the right track?
bitgrower
@bitgrower
Apr 12 2016 02:40
evening mr. @khaduch ...
Ken Haduch
@khaduch
Apr 12 2016 02:41
@bitgrower - howdy! How are you doing today?
bitgrower
@bitgrower
Apr 12 2016 02:42
...been a crazy day ... but, pretty good...
Moustafa Ragheb
@Mouragheb
Apr 12 2016 02:45
hey guys any one can tell me what i am doing wrong here
Ken Haduch
@khaduch
Apr 12 2016 02:46

@Moeragheb - on the profile lookup - there are a few things to note, just in case you follow up and I'm not here.

  • you have an array of contacts (some type of construct that examines all of the entries, as necessary, is what you need)
  • you have to make sure that your code is able to examine all of the array locations (the "contacts") - a common thing that people miss is that a return is a final action of a function, so you cannot return before it's time
  • you have to find a contact by matching the firstName property - and once you do, then you can take the next step to check for the property that is requested.

I'm not sure if there are any other hints - the one about exiting via return before you look at all of the contact entries is one of the biggest ones that seems to be overlooked, from what I see here. If you can post your code and ask questions or get comments on what you have so far, please do!

Moustafa Ragheb
@Mouragheb
Apr 12 2016 02:46

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

function lookUpProfile(firstName, prop){
// Only change code below this line
for(i = 0; i< contacts.length; i++){
for(j = 0; j< contacts[i].length; j++){
if(firstName == contacts[i][0] && prop == (contacts[i][j])){
return contacts[i].prop;
} else if (firstName !== contacts[i][0]){
return "No such contact";
} else if (prop!==contacts[i][j]) {
return "No such property";
}
}
}

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Sherlock", "number");
```js

Ken Haduch
@khaduch
Apr 12 2016 02:46
help format
CamperBot
@camperbot
Apr 12 2016 02:46

:point_right: code formatting [wiki]

Multi line Code

```js ⇦ Type 3 backticks and then press [shift + enter ⏎] (type js or html or css)

<paste your code here>,
then press [shift + enter ⏎]

``` ⇦ Type 3 backticks, then press [enter ⏎]

Single line Code

This an inline `<paste code here>` code formatting with a single backtick(`) at start and end around the code.

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

:pencil: read more about code formatting on the FCC Wiki

Ken Haduch
@khaduch
Apr 12 2016 02:47
@Moeragheb - post your code with this ^^^^ technique...
Moustafa Ragheb
@Mouragheb
Apr 12 2016 02:47
ok yup i got it
Jamie Lipschitz
@Jlipschitz
Apr 12 2016 02:48
This message was deleted
Ken Haduch
@khaduch
Apr 12 2016 02:50
@Moeragheb - but a couple things about the code you posted:
  • Having your inner for loop is not correct. That is only useful for arrays that have sub-arrays. You cannot iterate over properties of an object with that type of code construct
  • they mention the object method .hasOwnProperty() - that is what you need to use somewhere in this code.
  • see my other comments above about returning from the for loop before examining all entries for a match.
Jamie Lipschitz
@Jlipschitz
Apr 12 2016 02:50
have //setup go directly underneath your 3 ticks JS @Moeragheb
Ken Haduch
@khaduch
Apr 12 2016 02:52
@Moeragheb - you have to use the backticks, not the normal quote character there is a wiki entry about the backticks... usually the key in the upper left corner of the keyboard, underneath the Esc key...
This message was deleted
CamperBot
@camperbot
Apr 12 2016 02:52
no wiki entry for: backticks
Ken Haduch
@khaduch
Apr 12 2016 02:52
This message was deleted
CamperBot
@camperbot
Apr 12 2016 02:52
no wiki entry for: keyboard
Ken Haduch
@khaduch
Apr 12 2016 02:52
This message was deleted
CamperBot
@camperbot
Apr 12 2016 02:52
no wiki entry for: backtick
Ken Haduch
@khaduch
Apr 12 2016 02:53
@Moeragheb - this link has more details, including the backtick key... https://github.com/freecodecamp/freecodecamp/wiki/code-formatting
Moustafa Ragheb
@Mouragheb
Apr 12 2016 02:53
@khaduch thank you so much
CamperBot
@camperbot
Apr 12 2016 02:53
moeragheb sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 916 | @khaduch | http://www.freecodecamp.com/khaduch
Moustafa Ragheb
@Mouragheb
Apr 12 2016 02:58
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUpProfile(firstName, prop){
// Only change code below this line
  for(i = 0; i< contacts.length; i++){ 
      if(firstName == contacts[i].firstName && prop == (contacts[i].prop)){
        return contacts[i].prop;
      } else if (firstName !== contacts[i].firstName){
        return "No such contact";
      } else if (prop!==contacts[i].prop) {
        return "No such property";
    }
  }

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Sherlock", "number");
still not working that way i tried this many times
Ken Haduch
@khaduch
Apr 12 2016 02:59
@Moeragheb - you're welcome. One other thing that will help you, and I'm not sure if you have your code indented according to some coding standard, but just didn't display because of the formatting, but if you take your main body of the code (which we know needs some work) and just indent it to show nested levels of code, like this:
(I deleted my example code.)
It really makes it a lot easier to analyze and understand. Just in case you haven't gotten exposed to much of that up to this point?
@Moeragheb - okay - you just reposted and I see a better formatting, so it was probably just the lack of posting it as code format...
Moustafa Ragheb
@Mouragheb
Apr 12 2016 03:01
yup I only need to work in the function, you are right
thanks for the hint
but still where you think I should change the code to make it right?
function lookUpProfile(firstName, prop){
  for(i = 0; i< contacts.length; i++){ 
      if(firstName == contacts[i].firstName && prop == contacts[i].prop){
        return contacts[i].prop;
      } else if (firstName !== contacts[i].firstName){
        return "No such contact";
      } else if (prop!==contacts[i].prop) {
        return "No such property";
    }
  }
}
bitgrower
@bitgrower
Apr 12 2016 03:06
@Moeragheb -- so you have 3 different things you can return ... this challenge is a little bit of an exercise in negative logic ...
so ... you have to think about what it takes to determine that there is "no such contact" ...
Chris Buchert
@cbuchert
Apr 12 2016 03:07
I'm working on lesson 154 (Escape Sequences in Strings) and I think I've found a bug. I get get my code to run in console without a hitch. Can anyone confirm this? I'll rtfm again in the meantime.
Ken Haduch
@khaduch
Apr 12 2016 03:07
@Moeragheb - okay... now there are a couple issues.
  • if the function call has the name "Kristian" as the firstName parameter, you can see that that is the last name on the list. Your current code (once it is all correct) will return immediately after it determines that the firstName of the first entry doesn't match.
  • I do not see the .hasOwnProperty() method being used. I think that you are trying to do that property comparison with this:
    prop == (contacts[i].prop)
    comparison. But that doesn't make a valid comparison of the type that you need. You need to see if the contact that you are looking at has the property in existence, that's where .hasOwnProperty() comes in
  • you are using that same comparison twice, but it also doesn't work the second time. Check out my comment here :point_up: April 11, 2016 10:46 PM again and see what I said about matching the firstName first, because you need to have both the firstName as well as the property.
  • you need to use .hasOwnProperty() ( I'm being redundant for emphasis...)
bitgrower
@bitgrower
Apr 12 2016 03:08
whoa, @khaduch ... awesome analysis
Ken Haduch
@khaduch
Apr 12 2016 03:08
@cbuchert - what is your code? I don't think there is a bug there...
Chris Buchert
@cbuchert
Apr 12 2016 03:09
var myStr = '\\t\t\r\n';
Runs like a champ in console.
As much of a champ as var myStr = '\\t\t\r\n'; can run like.
Ken Haduch
@khaduch
Apr 12 2016 03:09
@bitgrower - I wish I had this stuff "canned" in a test file so I could just paste it in. :)
bitgrower
@bitgrower
Apr 12 2016 03:09
what stops ya ?
Moustafa Ragheb
@Mouragheb
Apr 12 2016 03:10
@khaduch thanks again you are awesome
CamperBot
@camperbot
Apr 12 2016 03:10
moeragheb sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:warning: moeragheb already gave khaduch points
Ken Haduch
@khaduch
Apr 12 2016 03:10
@cbuchert - does it say something about having whitespace between each escape sequence?
Chris Buchert
@cbuchert
Apr 12 2016 03:10
Nope.
I don't think.
Ken Haduch
@khaduch
Apr 12 2016 03:10
hmmmm
Chris Buchert
@cbuchert
Apr 12 2016 03:10
I'm going to feel stupid if it does and I breezed over it. lol.
Now that you say that...
bitgrower
@bitgrower
Apr 12 2016 03:11
what is the name of the challenge, @cbuchert ?
Chris Buchert
@cbuchert
Apr 12 2016 03:11
I didn't interpret the directions that way, but it's pretty explicit if you take it literally.
Ken Haduch
@khaduch
Apr 12 2016 03:11
@cbuchert Encode the following sequence, separated by spaces: - don't feel stupid, it's easy to miss those things...
Chris Buchert
@cbuchert
Apr 12 2016 03:11
I needed spaces. Ner dee ner.
Ken Haduch
@khaduch
Apr 12 2016 03:11
:)
Chris Buchert
@cbuchert
Apr 12 2016 03:12
I joined the bootcamp to pick up MEAN. Been working with JS and LAMP for years. I have to turn off skimming mode I guess. lol.
bitgrower
@bitgrower
Apr 12 2016 03:13
well ... don't think angular is part of FCC any more ...
Ken Haduch
@khaduch
Apr 12 2016 03:14
@cbuchert - I'll take the opportunity to say read the lessons and instructions carefully !
also, there is a lot of benefit to be gained by looking at the test code in the lower left corner, it helps to "explain" some things...
Yeah - I came here because of MEAN, but I'm experiencing groundhog's day... :grinning:
bitgrower
@bitgrower
Apr 12 2016 03:14
deja vu all over again, @khaduch ?
Chris Buchert
@cbuchert
Apr 12 2016 03:14
lol.
Ken Haduch
@khaduch
Apr 12 2016 03:15
The thing is that I've never gotten such detailed lessons on javascript and always find things I didn't know about! But I don't have years of experience with it...
Chris Buchert
@cbuchert
Apr 12 2016 03:15
Thanks, @khaduch . It's always a rtfm.
CamperBot
@camperbot
Apr 12 2016 03:15
cbuchert sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 917 | @khaduch | http://www.freecodecamp.com/khaduch
Ken Haduch
@khaduch
Apr 12 2016 03:15
@bitgrower - yup yup yup yup yup yup profile lookup yup yup yup :)
@cbuchert - "you are in a twisty maze of passages that all look alike..."
or I am...
bitgrower
@bitgrower
Apr 12 2016 03:16
you are showing your age ...
Ken Haduch
@khaduch
Apr 12 2016 03:17
@bitgrower - no, the gray hair does that just fine... :older_man:
:)
bitgrower
@bitgrower
Apr 12 2016 03:17
hard to see in a chat ...
Chris Buchert
@cbuchert
Apr 12 2016 03:17
I feel like I need to prove something now.
So n00b. Such mistake.
bitgrower
@bitgrower
Apr 12 2016 03:17
nah ... typical ... happens all the time ...
Chris Buchert
@cbuchert
Apr 12 2016 03:18
Almost as bad as the time I called my grade school teacher mom.
Or my wife mom.
That was really bad.
Memo to anyone who ever intends to marry a woman or is married to a woman and hasn't learned this one yet: don't do that. Ever.
bitgrower
@bitgrower
Apr 12 2016 03:18
you really shouldn't be so hard on yourself ... you are human ...
Ken Haduch
@khaduch
Apr 12 2016 03:19
@cbuchert - well, the longer you spend time here, you'll find that you can offer the same help to others, because you'll see the same things come up again and again... :fax:
bitgrower
@bitgrower
Apr 12 2016 03:19
very very true, @khaduch
Ken Haduch
@khaduch
Apr 12 2016 03:22
@cbuchert - don't worry, you're among friends... carry on!
there is two test sequences that i can't reach yet and i don't know why :D
Moustafa Ragheb
@Mouragheb
Apr 12 2016 03:38
@khaduch
function lookUpProfile(firstName, prop){
  for(i = 0; i< contacts.length; i++){
      if(firstName == contacts[i].firstName && contacts[i].hasOwnProperty(prop)){
        return contacts[i].hasOwnProperty(prop);
      } else if (firstName !== contacts[i].firstName){
        return "No such contact";
      } else if (prop!==contacts[i].hasOwnProperty(prop)) {
        return "No such property";
      }
  }
}
does that look right? or i am missusing the hasOwnProperty method?
Taryn Trueblood
@ttrueblo
Apr 12 2016 03:39
I don't know what this stand in line problem is asking for me to do?
Pawan
@pawan92
Apr 12 2016 03:40
hey guys im doing convert a number to roman numeral and i know i can do it the long way of 50 if/else statements but i know theres got to be an easier way any tips
Jamie Lipschitz
@Jlipschitz
Apr 12 2016 03:40
@zico0o keep in mind that you want to return based on the card count, not on the actual card you are returning. in your code if my count -2 but i draw a positive card your code will tell me to bet when in fact I should hold
Ken Haduch
@khaduch
Apr 12 2016 03:40
@Moeragheb - hello again.
Sean
@ofperfection
Apr 12 2016 03:40
function translatePigLatin(str) {
 var splitArr = str.split("");
  var length = str.length;
  var vowelEnd = ["w","a","y"];
  var consEnd1 = [];
  var consEnd2 = ["a","y"];

  switch(splitArr[0]){
    case "a":
    case "e":
    case "i":
    case "o":
    case "u":

    var answer= splitArr.concat(vowelEnd).join("");



       return answer;
  }
  consEnd1.push(splitArr[0]);
  splitArr.splice(0,1);

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

    if(splitArr[i] != "a" && splitArr[i] != "e" && splitArr[i] != "i" && splitArr != "o" && splitArr[i] != "u"){

      consEnd1.push(splitArr[i]);
      splitArr.splice(0,1);

      console.log(" This is my debugging " + consEnd1 + "This is the splitArr " + splitArr);

    }
    else{
      break;
    }

    var consAnswer = splitArr.concat(consEnd1).concat(consEnd2).join("");

     return consAnswer;
  }



}

translatePigLatin("paragraphs");
bitgrower
@bitgrower
Apr 12 2016 03:40
@ttrueblo -- check out the previous 4 challenges ... which show you the push pop shift & unshift array methods ... you need to use 2 of them to solve "Stand In Line"
Sean
@ofperfection
Apr 12 2016 03:41
Can someone tell me why I get an extra vowel pushed to consEnd1
i.e.
aragraphspaay
it passes the vowel tests, and multi consonant tests, but not the single consonant words
bitgrower
@bitgrower
Apr 12 2016 03:41
the most likely thing is you are indexing incorrectly (off by 1 error), @SeanSaibot
Taryn Trueblood
@ttrueblo
Apr 12 2016 03:43
@bitgrower I used 2 of the array methods , I am only getting two of the 4 correct
Sean
@ofperfection
Apr 12 2016 03:43
it looks like it's always pushing 2 letters to the consEnd1
so even though the splitArr[i] != "a", the code executes anyways
bitgrower
@bitgrower
Apr 12 2016 03:44
so ... ask yourself ... how would you code that if you actually wanted that to happen, @SeanSaibot
@ttrueblo -- post your code, please
Jamie Lipschitz
@Jlipschitz
Apr 12 2016 03:44
@zico0o i misread your code. it's actually what happens in the last two returns. if my count is positive and despite me drawing a 7,8,9 i should still be betting since count overall is positive. same thing applies when you decrease count-- in your last return case. look into adding a condition that will handle this in your last two returns.
Taryn Trueblood
@ttrueblo
Apr 12 2016 03:45
@bitgrower function nextInLine(arr, item) {
// Your code here
arr.push(item);
arr.shift(item);
return item; // Change this line
}
Sean
@ofperfection
Apr 12 2016 03:45
it tests for equality and then should break the loop
since it fulfills the conditional statement
bitgrower
@bitgrower
Apr 12 2016 03:46
okay ... so, you need to review how arr.shift works ... you might want to review the MDN page on array.shift and see
zico
@zico0o
Apr 12 2016 03:47
@Jlipschitz how to make it deal with the overall count ?
remove the two if conditions and make one collect both conditions at the end of the switch statement ??
Sean
@ofperfection
Apr 12 2016 03:51
@bitgrower I tried switching the break statement to be tested for first and that didn't fix it
Ken Haduch
@khaduch
Apr 12 2016 03:51

@Moeragheb - i see some improvement.

  • Your first if test looks good... But .... when you get that condition where the firstname matches, and the property exists, what do they ask you to return? (your return is not correct for that case.)
  • what if the contact that you were looking for was "Kristian"? With your current code, the first time through, it would not match the first if, it would match the first else if and return ... "No such contact". But there is a contact with that name - so you have to be able to find it (Hint: do not return the "no such contact" before you get through all of the contacts in the list!)
  • Your check for else if (prop!==contacts[i].hasOwnProperty(prop)) is an incorrect test. prop will have a value such as lastName, likes, etc. The .hasOwnProperty() returns true or false if the property exists. So you'll be comparing a string such as lastName to (true or false) which would never match. So if you can never match a comparison, it probably isn't a good comparison. You really only need to use the fact that .hasOwnProperty() is true or false to meet that check...

The code still needs some work! If you read my last bullet point in here: :point_up: April 11, 2016 10:46 PM - about matching the firstName first, and then making a decision about the property...

@bitgrower - "next in line" ? :)
there has to be some other lesson added prior to Next In Line!!!!!
Jamie Lipschitz
@Jlipschitz
Apr 12 2016 03:53
@zico0o give your condition an else statement. else(count is negative) { //do something other than return bet} else(count is positive) { //do something other than return hold}
bitgrower
@bitgrower
Apr 12 2016 03:53
hmm ... "Stand In Line" isn't it ?
khaduch @khaduch - fading fast...
Ken Haduch
@khaduch
Apr 12 2016 03:53
@bitgrower - maybe?
bitgrower
@bitgrower
Apr 12 2016 03:54
pretty sure it's Stand In Line ... it would be easier for folks if it was "Next In Line" ...
Ken Haduch
@khaduch
Apr 12 2016 03:55
@bitgrower - you're right... I was confused! There needs to be another lesson before "stand in line"!!!
Taryn Trueblood
@ttrueblo
Apr 12 2016 03:57
In Stand in line, I don't how the function should return 2 and 5?
Mauricio
@maudevelop
Apr 12 2016 03:59
I'm completely lost on the where art thou, any hints before i look at the solution code?
```

  for (var i = 0; i<source.length; i++){
      for (var j = 0; j<collection.length; j++){

        if (collection[j].hasOwnProperty(source[i])){
            console.log("Found");
        }    
      }
zico
@zico0o
Apr 12 2016 04:00
@Jlipschitz for cc(2) cc(2) cc( 10) it should return 1 Bet , i'm confused and tried an else statement still the same
Jamie Lipschitz
@Jlipschitz
Apr 12 2016 04:00
post the code you have now
help format
CamperBot
@camperbot
Apr 12 2016 04:00

:point_right: code formatting [wiki]

Multi line Code

```js ⇦ Type 3 backticks and then press [shift + enter ⏎] (type js or html or css)

<paste your code here>,
then press [shift + enter ⏎]

``` ⇦ Type 3 backticks, then press [enter ⏎]

Single line Code

This an inline `<paste code here>` code formatting with a single backtick(`) at start and end around the code.

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

:pencil: read more about code formatting on the FCC Wiki

zico
@zico0o
Apr 12 2016 04:00
it looks like that the code executes the last case it stops at
Ken Haduch
@khaduch
Apr 12 2016 04:00
@ttrueblo - for the case where the function is supposed to return 2, the test function call is:
nextInLine([2], 1) should return 2
nextInLine([5,6,7,8,9], 1) should return 5
is the test function when it should return 5. Do you notice a pattern there? The array being passed in has something in there related to the return...
zico
@zico0o
Apr 12 2016 04:01
case 2:
case 3:
case 4:
case 5:
case 6:
count=count+1;
if(count>=1){return count+ " Bet";}
else {return count;}
break;
case 7:
case 8:
case 9:
if (count ===0){return count+" Hold";}
else {return "zico";}
it print out only the string zico
Jamie Lipschitz
@Jlipschitz
Apr 12 2016 04:02
@zico0o c(2) cc(2) cc( 10) returns 1 bet because 2 is a positive card and 10 is a negative card so it leaves you with a +1 count, which in turn is 1 Bet
Ken Haduch
@khaduch
Apr 12 2016 04:02
@maudevelop - I don't know if I have the best solution, but I had about 15 lines of code in my solution.
Chris Buchert
@cbuchert
Apr 12 2016 04:03
@pawan92 have you figured out the roman numeral thing yet? Still need help? pm me if you want 1 on 1.
Mauricio
@maudevelop
Apr 12 2016 04:03
@khaduch any hint on what am i missing to understand it?
Like im guessing check each argument inputted and then with that check every property of the first argument to see if it "hasOwnProperty" of the source
zico
@zico0o
Apr 12 2016 04:04
i know the algorithm but somehow i don't know how to print the final answer that contains the right count and BET or HOLD !!! @Jlipschitz
Jamie Lipschitz
@Jlipschitz
Apr 12 2016 04:06
if (count ===0){return count+" Hold";} else {return count;} this should be count <= 0, otherwise when your count is any other number than 0 you will get zico when 7,8,9 cards are given.
Jonah Chason
@lemmydog
Apr 12 2016 04:08
I've been stuck on this for a while and I am getting tired of how a lot of these concepts aren't covered! I can't figure out how to use the push method inside an object, inside on object inside an object. For some reason I cannot get the syntax right on line 40. Please help!
*
*
Jamie Lipschitz
@Jlipschitz
Apr 12 2016 04:09
if (count <= 0){return count +" Hold";}
else {return count + " Bet";}
@zico0o you can also remove the "break" statements since return will break out of the switch as well
Jonah Chason
@lemmydog
Apr 12 2016 04:10

var collection = {
2548: {
album: "Slippery When Wet",
artist: "Bon Jovi",
tracks: [
"Let It Rock",
"You Give Love a Bad Name"
]
},
2468: {
album: "1999",
artist: "Prince",
tracks: [
"1999",
"Little Red Corvette"
]
},
1245: {
artist: "Robert Palmer",
tracks: [ ]
},
5439: {
album: "ABBA Gold"
}
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {

if(value === ""){
return collection;
}
else if( prop !== "tracks"){
collection[id][prop]=value;
return collection;
}else if( prop === "tracks"){
collection[id][prop.push(value)];
return collection;
}
}
// Alter values below to test your code
updateRecords(5439, "tracks", "Addicted to Luv");

Ken Haduch
@khaduch
Apr 12 2016 04:11

@maudevelop - well...
Each object in the first argument (the array of objects) has to contain all of the properties and values that are in the second argument.
So if you study the test code that is run, it will give you the expected results.
You need two loops - one that is iterating over all of the objects in the first argument (the array), and within that, you have to see whether or not each property in the "search" object: 1. exists in the current object in the array, and: 2. has the same value.
So some pseudocode would be:

for (each object "A" in the array)
    for ( each property "P" in the search object "S" )
        does the object "A" have the property "P",  AND does the "A"["P"] match the value of "S"["P"]?

It takes a couple variable to track matches and "misses", and if you have any misses, you don't return that object "A".
Maybe that will help? Maybe you need some clarification?

Jamie Lipschitz
@Jlipschitz
Apr 12 2016 04:12
@lemmydog you didn't close your bracket properly on
else if( prop === "tracks"){
collection[id][prop.push(value)];
return collection;
}
collection[id][prop].push(value) @lemmydog
Mauricio
@maudevelop
Apr 12 2016 04:14
@khaduch okay im trying to wrap my head around it. But hold on, is it necessary for ALL of them to be matched? Because for example on the first test case only one is matched and it is anyways passed on as result..?
specially because it is passing only the "last:" property
and it anyways returns the whole object that has that property, not caring about the first: property
Haha, this is the only JS algorithm i've been stuck on for so long
Rada
@Radascript
Apr 12 2016 04:16
@Jlipschitz I was playing with his code and it still doesn't fix after that it seems
zico
@zico0o
Apr 12 2016 04:16
thanks @Jlipschitz its done finally
CamperBot
@camperbot
Apr 12 2016 04:16
zico0o sends brownie points to @jlipschitz :sparkles: :thumbsup: :sparkles:
:star: 89 | @jlipschitz | http://www.freecodecamp.com/jlipschitz
Jamie Lipschitz
@Jlipschitz
Apr 12 2016 04:17
@zico0o glad I could help! :)
@Radascript yeah there are other errors I didn't cover
Jonah Chason
@lemmydog
Apr 12 2016 04:19
@Jlipschitz , I have changed it and still get the error : Cannot read property 'push' of undefined. I guess this means the array is not yet defined, but do not see a way to without exiting the function. Any tips?
Rada
@Radascript
Apr 12 2016 04:20
@lemmydog I think your logic isn't ordered properly. Maybe map an algorithm on a piece of paper then program.
Ivan
@elementWebDev
Apr 12 2016 04:21
Combine the two if statements into one statement which returns "Outside" if val is not between 10 and 20, inclusive. Otherwise, return "Inside". ?
function testLogicalOr(val) {
  // Only change code below this line


    return "Outside";
  }

if (val >= 10 || val <= 20) {
  // Only change code above this line
  return "Inside";
}

// Change this value to test
testLogicalOr(15);
I tried !>= but that doesn't work
Jonah Chason
@lemmydog
Apr 12 2016 04:22
@Radascript , is that based on my code or my last comments?
Jamie Lipschitz
@Jlipschitz
Apr 12 2016 04:23
@lemmydog look into changing your conditions. you really only need three in this assignment 1) one that updates if value !== "" AND != "tracks". If I find this then I want to update the property value to what i'm taking in the function 2) one that if prop is equal to "tracks" AND value !== "" If find this then I want to push this value onto my tracks array 3) deleting if the value === "" blank inside the proprty value (look into using delete )
Ken Haduch
@khaduch
Apr 12 2016 04:24
@maudevelop - right - all of the properties in the "search" object have to be present in the "target" objects from the array, but there could be more properties in the "target" object that are not in the "search" object. That shows up in the test results. So you pass the entire "target" object that has at least all of the "search" object properties (with matching values) back in the result array.
Moustafa Ragheb
@Mouragheb
Apr 12 2016 04:27
@khaduch
thank you so much again for taking from your time to explain
CamperBot
@camperbot
Apr 12 2016 04:27
moeragheb sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 918 | @khaduch | http://www.freecodecamp.com/khaduch
Moustafa Ragheb
@Mouragheb
Apr 12 2016 04:28
i will rework on it tomorrow and i will keep you updated!
severalseas
@severalseas
Apr 12 2016 04:28
I need need help with a problem but dont know how to post my code on here. It's in the freeCodeCamp editor...
kwal0203
@kwal0203
Apr 12 2016 04:29
Hey I'm doing the pig latin translator and for the vowels I can return the correct result but the website will not accept the result. How do I paste my code here?
Ken Haduch
@khaduch
Apr 12 2016 04:29

@maudevelop

Haha, this is the only JS algorithm i've been stuck on for so long

This one does take things up a level, in my opinion. I should look at the provided answers and see if there was something that I could have done more efficiently... But this is a "nice" problem...

@Moeragheb - great! I hope you get it solved!
Tridev
@TridevGuha
Apr 12 2016 04:29
hi, I am using youtubeapi to search a query and show the json output in html, but the problem is that the page is blank. link: http://codepen.io/TridevGuha/pen/eZVjeP?editors=1010 How can I resolve it please?
henrywashere
@henrywashere
Apr 12 2016 04:30
@khaduch remember that Word Blank problem i asked you earlier????
i was wondering if you can just give me the answers
Mauricio
@maudevelop
Apr 12 2016 04:30
@khaduch, okay im gonna write it down and try to get it, thanks for the help by the way, lets see if i can make it haha
CamperBot
@camperbot
Apr 12 2016 04:30
maudevelop sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 919 | @khaduch | http://www.freecodecamp.com/khaduch
Ivan
@elementWebDev
Apr 12 2016 04:30
nm... got it
Jonah Chason
@lemmydog
Apr 12 2016 04:31
@Jlipschitz , one more question. What is the syntax for deleting the property in the last step? I couldn't find it in my resources.
Jamie Lipschitz
@Jlipschitz
Apr 12 2016 04:32
function updateRecords(id, prop, value) {
if(if value not equal to "" and property is not equal to "tracks"){
//update this value

}
else if( property is equal to "tracks" and value is not equal to ""){
//push the value that's being given into the tracks array

}else {
//delete from the collection since property is blank ("")
  delete myObj[id][property]
}
  //collection only needs to be returned once since only condition can be met
  return collection
}
Ken Haduch
@khaduch
Apr 12 2016 04:32
@maudevelop - great, good luck & you'll learn a lot from this one, I think? Catch you later...
Jamie Lipschitz
@Jlipschitz
Apr 12 2016 04:32
@lemmydog @Radascript
khaduch @khaduch - going away for the night... happy coding everyone!
Jamie Lipschitz
@Jlipschitz
Apr 12 2016 04:35
goodnight @khaduch
Ken Haduch
@khaduch
Apr 12 2016 04:37

@henrywashere - I just saw your comment... I don't want to give you the answer, but here's another hint. If I have two variables:

var wordOne = "my";
var wordTwo = "dog";

and I want to make a sentence using those words, like "my dog is old.". I might do something like this:

var sentence = wordOne + ' ' + wordTwo + ' ' + "is old.";

and then perhaps return that sentence variable or use it somewhere else in my code. This challenge is very similar - you have a set of words that are passed in, you just have to string them together with the concatenation operator and some spaces and return it. I think that you can add extra words in there, or not?

I have to go - I hope that is helpful to get you to solve the problem?

PattyCreates
@PattyCreates
Apr 12 2016 04:39
Hi hi. i'm having issues with implementing this fiddle. http://jsfiddle.net/GwkQN/
Does anyone have any idea why it doesn't work? I'm currently having success with the toggle of the words. But, the slide toggle aint working.
var rm = $(".about-read-more"),
  moreText = "Read More",
  lessText = "Read Less";

  rm.click(function () {
    // var $this = $(this);
    // $this.prev().slideToggle();
    // $this.text($this.text() == moreText ? lessText : moreText);
    $(this).prev('.about-more').slideToggle();

    if($(this).text()==moreText){
      $(this).text(lessText);
    } else{
      $(this).text(moreText);
    }
  });
Jackson Bates
@JacksonBates
Apr 12 2016 04:41
Sorry for the long post...
Hoping for some help with an issue using a combination of Array.push(), a for loop and some nested ifs. The codepen link at the end should clarify the issue...
Basically, I have an empty array (twitchArr) that should have some JSON data pushed to it. The for loop and ifs treat different responses in different ways and when I use console.log() for the output for each of the variations on the responses it all works as expected.
I switched the console.log() call to twitchArr.push() to catch the info in a more usable way for my purposes, and this works - but accessing the twitchArr is causing problems, because it seems like javascript tries to access it in the final console.log(twitchArr.length) call at the very end of the code before it has finished the for loop.
So in the codepen example, you can see the console prints a '0', suggesting nothing is in the array, but if you then manually type twitchArr.length at the console prompt (in codepen), you will see that the length is '10' as expected. The only difference I can imagine is that by the time I manually call for the array length again, the for loop has finished and the array has been built.
Any ideas why this might be happening, or how to workaround it? Is this a standard JS problem (i.e. it juggles multiple processes simultaneously, not waiting for loops to complete before addressing other commands), or is it a codepen/browser specific problem?
http://codepen.io/Malgalin/pen/BKYRjg?editors=0012
PattyCreates
@PattyCreates
Apr 12 2016 04:42
//toggles
  .about-more {
    display: none;
  }

%p.about-more
          etcetc
        %p
          %a{:class => "about-read-more"}
            Read More
Not sure why it's not sliding.
Anyone?
Jamie Lipschitz
@Jlipschitz
Apr 12 2016 04:44
@PattyCreates it slides for me
PattyCreates
@PattyCreates
Apr 12 2016 04:44
The JS I provided?
Jamie Lipschitz
@Jlipschitz
Apr 12 2016 04:45
Yeah unless i'm missing something here. You want to the words to toggle and the nested words to slide down and be displayed, right? If that's the case then it certainly works for me
PattyCreates
@PattyCreates
Apr 12 2016 04:45
Yeah. it doesn't work locally for me.
Frumps.
The fiddle is something I found online that I'm trying to reproduce.
Jamie Lipschitz
@Jlipschitz
Apr 12 2016 04:46
try on something other than fiddle
PattyCreates
@PattyCreates
Apr 12 2016 04:49
Ah okay. It is working. I think its just the rails routing that is weird.
Luis Filipe Forra
@forral
Apr 12 2016 04:56
Can anyone tell me why my total is 0?
var myArr = [ 2, 3, 4, 5, 6];

var total = 0;
for (var i = 0; i < myArr.lenght; i++) {
  total += myArr[i];
}
Sean
@ofperfection
Apr 12 2016 04:57
myarr.length mispelling maybe?
jiuhua xu
@xujiuhua
Apr 12 2016 04:57
.length
Luis Filipe Forra
@forral
Apr 12 2016 04:58
thank you @SeanSaibot
CamperBot
@camperbot
Apr 12 2016 04:58
forral sends brownie points to @seansaibot :sparkles: :thumbsup: :sparkles:
:star: 297 | @seansaibot | http://www.freecodecamp.com/seansaibot
Sean
@ofperfection
Apr 12 2016 04:59
No problem!
PattyCreates
@PattyCreates
Apr 12 2016 05:00
So I'm confused about calling functions.
Do you have to call a function if it's a click event?
Or it's already being called by the click?
Sean
@ofperfection
Apr 12 2016 05:01
you execute a function when a click occurs
so say in jQuery
.click(function())
PattyCreates
@PattyCreates
Apr 12 2016 05:02
so whats the difference?
Does it still need to be called?
Sean
@ofperfection
Apr 12 2016 05:02
no
well
it depends on how the function is written
but
say you wanted to accomplish a specific thing on click
you'd do
$('divname').click(function(){})
then insert say a simple animation between the brackets
PattyCreates
@PattyCreates
Apr 12 2016 05:06
So, does that function need to be called?
I guess i'm not sure what calling functions really means?
Elbert Cortez
@trip16661
Apr 12 2016 05:09
guys i have a question dunno if someone can help me but :worried: im doing some work with api and i needed to create an if statement but because i wanted it to look neat i wanted to try and make the if inside of a functioninside of an external page and then just call the function so the main page looks neat
but when i call it the api argument says undefined in the second page
Sean
@ofperfection
Apr 12 2016 05:09
so if you create a function that does a specific thing
you invoke or 'call' it by using it
if that makes sense
so if you have a function like
function myFunction(a,b){ return a + b;}
you would be CALLING it
if you did this later in the code
myFunction(1,1); //returns 2
so basically calling the function simply means using it
@trip16661 Are you talking about an external javascript file?
Elbert Cortez
@trip16661
Apr 12 2016 05:13
@SeanSaibot yes
Sean
@ofperfection
Apr 12 2016 05:14
what are you coding exactly?
Aleksandr Kozlov
@Cu3bIu
Apr 12 2016 05:18

How is this piece of code a possible infinite loop ?

'function chunkArrayInGroups(arr, size) {
var resultArr = [];
if ( size > 0) {
for(var i = 0; i < arr.length; i + size){

}
}
return arr;
}

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

Messe
@M3SSI4H
Apr 12 2016 05:19
Anyone able to spare a minute to help me out with the 'Stand in Line' Lesson?
Sean
@ofperfection
Apr 12 2016 05:19
@Cu3bIu You need to add an increase to 'i'
Aleksandr Kozlov
@Cu3bIu
Apr 12 2016 05:20
@SeanSaibot so it has to have i+=size right?
@SeanSaibot Perfect - thank you so much. Such an obvious mistake.... Its a pitty i didnt see it myself.
CamperBot
@camperbot
Apr 12 2016 05:21
cu3biu sends brownie points to @seansaibot :sparkles: :thumbsup: :sparkles:
:star: 298 | @seansaibot | http://www.freecodecamp.com/seansaibot
Sean
@ofperfection
Apr 12 2016 05:21
happy to help!
and @M3SSI4H How can i help you?
Elbert Cortez
@trip16661
Apr 12 2016 05:27

@SeanSaibot i want to do this

$("#channel").append("<div id='channel'>"+"<a href='" + channelD.url + "'>" + channelD.display_name +"</a></br>" + imagen() + "</div>");

where imagen() is a function in a external js page

function imagen() {
    if(channelD.logo !== null){
            $("channel").append("<img src='" + channelD.logo + "'>");

            }else{
                $("channel").append("<img src='http://random image'>")

            }
}
the function is like this
but says channelID is undefined
Eldar Tinjić
@EldarT90
Apr 12 2016 05:28
good morning folks, i need help with wikipedia challenge
how can i connect html and js in order to get real output
atm im getting "Main Page", which means there is connection between the two
but i need to get "real results" of input in search bar
Messe
@M3SSI4H
Apr 12 2016 05:29
@SeanSaibot i got it dude, just had a typo i overlooked like 30 times
jorgon1022
@jorgon1022
Apr 12 2016 05:30
hi guys
Messe
@M3SSI4H
Apr 12 2016 05:30
@SeanSaibot ty tho :D
jorgon1022
@jorgon1022
Apr 12 2016 05:30
any of you able to help a fellow coder?
i cant fix a bug on my calculator project
Elbert Cortez
@trip16661
Apr 12 2016 05:30
@EldarT90 u need to create an event to get the value of the mput and then use it as a placeholder
Eldar Tinjić
@EldarT90
Apr 12 2016 05:30
@trip16661 yes, but how
Elbert Cortez
@trip16661
Apr 12 2016 05:31
@trip16661 check the jquery documentation
google
how to get an imput value
and google
Mauricio
@maudevelop
Apr 12 2016 05:31
function where(collection, source) {
    var arr = collection.filter(function(item) {
        for (var i in source) {
            if (source[i]!=item[i]){
                return false;
            }
        }
    }
    return true;
    });
return arr;
}
Elbert Cortez
@trip16661
Apr 12 2016 05:31
on click events but i guess you already know that one
Mauricio
@maudevelop
Apr 12 2016 05:32
I've been trying to get my own solution to the where art thou for hours and can't get it
Elbert Cortez
@trip16661
Apr 12 2016 05:32
@maudevelop what's the challenge task
Mauricio
@maudevelop
Apr 12 2016 05:32
so i looked up a solution and got that but im having questions about it, anyone who can tell me how is the item[i] working if the source only has an i value of 0?
"Make a function that looks through an array of objects (first argument) and returns an array of all objects that have matching property and value pairs (second argument). Each property and value pair of the source object has to be present in the object from the collection if it is to be included in the returned array."
@trip16661
Eldar Tinjić
@EldarT90
Apr 12 2016 05:35
@trip16661 i know how to use onclick, but what to put in it in order to get the response from wikipedia; i already have json command that retrieves data from wikipedia, so it is somehwere "in the air"
but i cant see it
Elbert Cortez
@trip16661
Apr 12 2016 05:35
@EldarT90 you have to put the request inside of the event
you are just saying this to you webpage
htlm 'load me x thing"
but when you user click something
html will just load the same thing
since you didn-t told it to change when the user want it
Eldar Tinjić
@EldarT90
Apr 12 2016 05:36
@trip16661 so i need to put additional line in my function ?
Elbert Cortez
@trip16661
Apr 12 2016 05:36
but just when it load
the thing is that you don-t have a an event on your code that i can see
all i see is you requesting some information to the wiki api
Eldar Tinjić
@EldarT90
Apr 12 2016 05:38
@trip16661 yes, and now i need to show them and i dont know how to "present " them, even though function is connected to html; i tried with return the variable, but no luck
@trip16661 i understand completely what you are saying but i dont know how to do it, simple as that
Elbert Cortez
@trip16661
Apr 12 2016 05:39
i will show you an interesting channel
so you can study it
start with the first one
it will take u a little bit of time but at the end you will kind of understand how to work with it
Frank XC
@tenkdayz
Apr 12 2016 05:39
trying to make a moving rect bounce off another rect in canvas but i have to get their offsetTop or yPos to make it bounce..
Eldar Tinjić
@EldarT90
Apr 12 2016 05:40
@trip16661 oke tnx, i hope i will understand it lil bit better, because thats the whole purpose of this ^^
CamperBot
@camperbot
Apr 12 2016 05:40
eldart90 sends brownie points to @trip16661 :sparkles: :thumbsup: :sparkles:
:star: 303 | @trip16661 | http://www.freecodecamp.com/trip16661
Mauricio
@maudevelop
Apr 12 2016 05:46
  var newArr = collection.filter (function (citem){
      for (var i = 0; i<source.length; i++){
          if (citem==source[i]){
              return true;
          }
      }    
  });
I was trying something like that for the where art thou problem
bu not entirely sure which concept im not getting because i can't get past it
Mohamed Ameen
@pmohdameen
Apr 12 2016 05:50
@maudevelop challenge number ?
Mauricio
@maudevelop
Apr 12 2016 05:51
@pmohdameen on intermediate algorithm scripting "Where art Thou"
Javier
@sh1g
Apr 12 2016 05:51
function getIndexToIns(arr, num) {
  // Find my place in this sorted array.
  arr.push(arguments[1]);
  var sortedArray = arr.sort();
  var location = 0;
  for(var i = 0; i < sortedArray.length; i++){
    if (sortedArray[i] === num){
      return sortedArray.indexOf(sortedArray[i]);
    }
  }
}

getIndexToIns([40, 60], 50);
Need help on Bonfire Where do i Belong? It seems my loop goes to the next element in the array in my loop when there are multiple elements of the same value. Any tips?
CamperBot
@camperbot
Apr 12 2016 05:51
type bonfire name to get some info on that bonfire. And check HelpBonfires chatroom
Javier
@sh1g
Apr 12 2016 05:52
bonfire Where Do I belong?
CamperBot
@camperbot
Apr 12 2016 05:52

:fire:Bonfire: Where do I belong :link:

function where(arr, num) {
  // Find my place in this sorted array.
  return num;
}

where([40, 60], 50);

Return the lowest index at which a value (second argument) should be inserted into a sorted array (first argument).

more info:  bf details | bf links | hint

Javier
@sh1g
Apr 12 2016 05:52
hint
CamperBot
@camperbot
Apr 12 2016 05:52
:construction: Spoilers are only in the Bonfire's Custom Room :point_right:
Javier
@sh1g
Apr 12 2016 05:52
nvm xD
but yeah, any tips on that bonfire?
kirbyedy
@kirbyedy
Apr 12 2016 05:55
just a quick question
Elbert Cortez
@trip16661
Apr 12 2016 05:55
@sh1g u dont veed a for loop for that
kirbyedy
@kirbyedy
Apr 12 2016 05:55
what does this line do ? var location = 0;
Javier
@sh1g
Apr 12 2016 05:55
@kirbyedy oh that was from some other code. Need to remove that line.
kirbyedy
@kirbyedy
Apr 12 2016 05:55
I dont see you use it in your code
ah ok :)
confused me there :)
Elbert Cortez
@trip16661
Apr 12 2016 05:56
only indexof sort and concat
Javier
@sh1g
Apr 12 2016 05:56
@kirbyedy ahh okay. I'll try that thanks
CamperBot
@camperbot
Apr 12 2016 05:56
sh1g sends brownie points to @kirbyedy :sparkles: :thumbsup: :sparkles:
:star: 835 | @kirbyedy | http://www.freecodecamp.com/kirbyedy
kirbyedy
@kirbyedy
Apr 12 2016 05:57
tax the @trip16661 :)
CamperBot
@camperbot
Apr 12 2016 05:57
kirbyedy sends brownie points to @trip16661 :sparkles: :thumbsup: :sparkles:
:star: 304 | @trip16661 | http://www.freecodecamp.com/trip16661
Javier
@sh1g
Apr 12 2016 05:57
@trip16661 oh my bad thank you trip xD
CamperBot
@camperbot
Apr 12 2016 05:57
sh1g sends brownie points to @trip16661 :sparkles: :thumbsup: :sparkles:
:star: 305 | @trip16661 | http://www.freecodecamp.com/trip16661
Elbert Cortez
@trip16661
Apr 12 2016 05:58
lol dont thanks me just bbecause xD
just do it if it's helpful and it was not really so much
Javier
@sh1g
Apr 12 2016 05:59
I've been stuck on this for a bit, so trying a new approach helps out a lot
buckshot307
@buckshot307
Apr 12 2016 06:01
I'm on the Check for Palindromes challenge and have a question. It says to replace all non-alphanumeric characters in order to check, so do I need to replace each non-alphanumeric character with it's own line?
Markus Kiili
@Masd925
Apr 12 2016 06:03
@buckshot307 You can use string .replace() method and suitable regexp object.
buckshot307
@buckshot307
Apr 12 2016 06:04
Oooh nice thanks @Masd925
CamperBot
@camperbot
Apr 12 2016 06:04
buckshot307 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1352 | @masd925 | http://www.freecodecamp.com/masd925
Javier
@sh1g
Apr 12 2016 06:06
oh wow...I just realized my mistake. I wasn't doing the correct type of sorting..
Markus Kiili
@Masd925
Apr 12 2016 06:07
@sh1g There is also a clever way to solve Where do I belong without sorting.
Javier
@sh1g
Apr 12 2016 06:08
so yeah, by sorting correctly, the rest of my code was right
I want to bang my head on the desk...
@Masd925 which way would that be?
Markus Kiili
@Masd925
Apr 12 2016 06:10
@sh1g After pushing and sorting, you can also use indexOf for getting the result. Without sorting, you can just count the elements <num. It is the answer.
Javier
@sh1g
Apr 12 2016 06:11
@Masd925 ahh yes that would definitely make it easier
Rada
@Radascript
Apr 12 2016 06:13
Help Smallest Common Multiple
CamperBot
@camperbot
Apr 12 2016 06:13

:point_right: algorithm smallest common multiple [wiki]

Explanation:

The smallest common multiple between two numbers is the smallest number that
both numbers can divide into. This concept can be extended to more than two
numbers as well.

We can first start with just finding the smallest common multiple between two
numbers. Naively, you can start writing out multiple of each number until you
write a multiple that exists from both numbers.

An example would be the numbers 3 and 4. The multiples of 3 are 3, 6, 9, 12, 15, 18, ... and the multiples of 4 are 4, 8, 12, 16, 20, .... The
first smallest number we run into in both lists is 12 so this is the smallest
common multiple between 3 and 4.

This problem can be confusing because most people look for the smallest common
multiple of just the two numbers but forget the keyword range. However, this
means that if you are given [1,5], then you have to check for the smallest
common multiple for all the numbers [1,2,3,4,5] that is evenly divisible by
all of them.

:pencil: read more about algorithm smallest common multiple on the FCC Wiki

Rada
@Radascript
Apr 12 2016 06:14
Just wondering, anyone else's solution was really long, or am I just doing it ass backwards?
kirbyedy
@kirbyedy
Apr 12 2016 06:14
@Masd925 so you mean like to push the number to the array then sort and then get the index ? like that ?
Markus Kiili
@Masd925
Apr 12 2016 06:14
@kirbyedy It is one way. Another way is not to sort (or push) and just count elements <num.
kirbyedy
@kirbyedy
Apr 12 2016 06:17
to loop through the array and compare the num with each element ? like that ?
Markus Kiili
@Masd925
Apr 12 2016 06:18
@kirbyedy Yes.
Much faster than pushing and sorting.
kirbyedy
@kirbyedy
Apr 12 2016 06:18
interesting
vetoCode
@vetoCode
Apr 12 2016 06:19
how can i do that the animation gos asyncron?
http://codepen.io/vetoCode/pen/GZQEgp?editors=0010
Coryphaeus
@cvdeby
Apr 12 2016 06:26
Does somebody know, how could I get all channels with one request? Like https://api.twitch.tv/kraken/channels/?somethinghere. I tried to get it so - https://api.twitch.tv/kraken/streams/?channel=freecodecamp,storbeck, but I got nothing if channel is offline or doesn't exist.
kirbyedy
@kirbyedy
Apr 12 2016 06:32
@cvdeby not sure if that is possible
Coryphaeus
@cvdeby
Apr 12 2016 06:33
@kirbyedy Should I make multiple request instead? - It's bad for performance(
Frank XC
@tenkdayz
Apr 12 2016 06:33
@cvdeby for loop?
Coryphaeus
@cvdeby
Apr 12 2016 06:34
@tenkdayz For multiple requests inside the loop
Frank XC
@tenkdayz
Apr 12 2016 06:34
yea
Coryphaeus
@cvdeby
Apr 12 2016 06:35
&stream_type doesn't work too(
Frank XC
@tenkdayz
Apr 12 2016 06:35
@cvdeby to get the info use /channels to see who's online or not use /streams
Coryphaeus
@cvdeby
Apr 12 2016 06:37
@tenkdayz For using /channels I should send multiple request too and I didn't find params for /channels. If streams won't work, I'll use /channels instead.
@tenkdayz Thanks
Frank XC
@tenkdayz
Apr 12 2016 06:38
@cvdeby yeah i guess you can do that with the success function
Messe
@M3SSI4H
Apr 12 2016 06:47
Anyone have a second to answer a question on the 'Selecting from many options with Switch Statements' Lesson?
Frank XC
@tenkdayz
Apr 12 2016 06:48
@M3SSI4H go
Messe
@M3SSI4H
Apr 12 2016 06:48

function caseInSwitch(val) {
var answer = "";
// Only change code below this line
switch (val) {
case 1:
return "alpha";
break;
case 2:
return "beta";
break;
case 3:
return "gamma";
break;
case 4:
return "delta";
break;
}

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

// Change this value to test
caseInSwitch(2);

i finished the lesson but i get 'unreachable break after return warnings
is that normal?
Zach
@Moose1551
Apr 12 2016 06:49
If somebody can help me out with a simple issue, I'd like to send them my code for "Checking for Palindromes" in a PM. I really think it's down to just one character, but I can't figure it out. I don't want to spoil the solution for anyone.
Messe
@M3SSI4H
Apr 12 2016 06:50
my outputs all seem right, just wondering why im getting warnings on all my break; lines
Frank XC
@tenkdayz
Apr 12 2016 06:51
@M3SSI4H to avoid that set answer equal to val.. then return it ouside the switch
Markus Kiili
@Masd925
Apr 12 2016 06:51
@Moose1551 I can try.
Rada
@Radascript
Apr 12 2016 06:51
@Moose1551 it's ok people who haven't done it yet can just choose not to look at it closely
MBJ
@mbjusa
Apr 12 2016 06:53
var Bike = function() {

  // Only change code below this line.

  var gear = 5;
  this.setGear = function(bkGear) {
  var gear = bkGear;
  };
  this.getGear = function() {
    return gear;
  };
};

//var myCar = new Car();

var myBike = new Bike();
Zach
@Moose1551
Apr 12 2016 06:53
@Masd925 , I can't figure out how to PM someone. 1 sec, haha
MBJ
@mbjusa
Apr 12 2016 06:54

myBike.getGear() should return 4 after calling myBike.setGear(4).

this is the error message I get with the code above.

Markus Kiili
@Masd925
Apr 12 2016 06:54
@mbjusa Don't declare gear again in method.
MBJ
@mbjusa
Apr 12 2016 06:55
Anyone see anything wrong??
@Masd925 Thanks alot. Much appreciated!!!
CamperBot
@camperbot
Apr 12 2016 06:56
mbjusa sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1353 | @masd925 | http://www.freecodecamp.com/masd925
Zach
@Moose1551
Apr 12 2016 06:58
How do you send a private message in Github?
or FCC?
Markus Kiili
@Masd925
Apr 12 2016 06:58
@Moose1551 Mouse over the user avatar and choose "Chat privately"
Zach
@Moose1551
Apr 12 2016 06:59
@Masd925, weird. It's not giving me the option.
Frank XC
@tenkdayz
Apr 12 2016 07:01
@Moose1551 sent you a message.. you should have an alert somewhere..
Zach
@Moose1551
Apr 12 2016 07:03
Got it! Thanks!
Messe
@M3SSI4H
Apr 12 2016 07:04
how do i send brownie points
Rada
@Radascript
Apr 12 2016 07:04
you just say "thanks" + @name
CamperBot
@camperbot
Apr 12 2016 07:04
radascript sends brownie points to @name :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for name
Rada
@Radascript
Apr 12 2016 07:05
in the same sentence
Messe
@M3SSI4H
Apr 12 2016 07:05
thanks @Radascript
CamperBot
@camperbot
Apr 12 2016 07:05
m3ssi4h sends brownie points to @radascript :sparkles: :thumbsup: :sparkles:
:star: 294 | @radascript | http://www.freecodecamp.com/radascript
Rada
@Radascript
Apr 12 2016 07:05
ta-da!
Messe
@M3SSI4H
Apr 12 2016 07:05
awesomeness
Javier
@sh1g
Apr 12 2016 07:05
Yay! Caesar Cipher completed as well!!! that one was definitely a lot easier...
Markus Kiili
@Masd925
Apr 12 2016 07:06
@sh1g Nice! Now refactor it into one-line solution ;)
Javier
@sh1g
Apr 12 2016 07:07
@Masd925 there's a one line solution???
Markus Kiili
@Masd925
Apr 12 2016 07:07
@sh1g Yes. I have a gist of all my one-liners if you like to see.
Javier
@sh1g
Apr 12 2016 07:08
yeah definitely =D
Markus Kiili
@Masd925
Apr 12 2016 07:08
This message was deleted
https://gist.github.com/Masd925/8b1a9b1d37c322827dcd
Javier
@sh1g
Apr 12 2016 07:10
ooh I did forget about maps...
Nick Rameau
@R4meau
Apr 12 2016 07:29
@Masd925 Impressive list :thumbsup:
Shivam Arora
@shivamarora13
Apr 12 2016 07:35
@shivamarora13
I can't stop the countdown, once it starts running, can't control it, can anyone help?
http://codepen.io/shivamarora_/full/qZxmpy/
Frank XC
@tenkdayz
Apr 12 2016 07:38
@shivamarora13 use setInterval instead of setTimeout
Ankit Panwar
@coderNoob
Apr 12 2016 07:51
What does this line mean Boolean(val[pre]) in
var values = collection.map(function(val){
    if(val.hasOwnProperty(pre) && Boolean(val[pre]))
       return true;
    return false;
  });
Shivam Arora
@shivamarora13
Apr 12 2016 07:57
@coderNoob Boolean will return value, true, if it has false, else false
Sameer Shamsudeen
@sameershamsudheen
Apr 12 2016 07:58
hello i was doing record collection challenge in JavaScript, pls tell me what is wrong in my code
function updateRecords(id, prop, value) {
  if(id === collection[id]){
    if(value !== "" && prop !== collection[id].tracks){
      collection[id].prop = value;
    }
    if(prop === collection[id].tracks && value !== ""){
      collection[id].tracks.push(value);
    }
    if(value === ""){
      delete collection[id].prop;
    }
  }
  return collection;
}
Ankit Panwar
@coderNoob
Apr 12 2016 07:58
@shivamarora13 Didn't get it.
Shivam Arora
@shivamarora13
Apr 12 2016 07:58
@coderNoob values like, null, 0 , undefined, will throw false, other than those, true
Markus Kiili
@Masd925
Apr 12 2016 07:58
@coderNoob val[pre] accesses object val's property pre. Boolean coerces it to boolean, which is not necessary because if coerces values to boolean.
Ankit Panwar
@coderNoob
Apr 12 2016 07:59
@Masd925 @shivamarora13 Thanks.
CamperBot
@camperbot
Apr 12 2016 07:59
codernoob sends brownie points to @masd925 and @shivamarora13 :sparkles: :thumbsup: :sparkles:
:star: 282 | @shivamarora13 | http://www.freecodecamp.com/shivamarora13
:star: 1354 | @masd925 | http://www.freecodecamp.com/masd925
Shivam Arora
@shivamarora13
Apr 12 2016 08:00
@sameershamsudheen I think u should try, else if, rather than if if and if
not sure, if it will work or not
Ankit Panwar
@coderNoob
Apr 12 2016 08:00
@Masd925 And only if the property exists will it return true otherwise false?
Markus Kiili
@Masd925
Apr 12 2016 08:01
@coderNoob if doesn't test property existence.
Ankit Panwar
@coderNoob
Apr 12 2016 08:01
@Masd925 I was referring to Boolean(val[pre])
Eldar Tinjić
@EldarT90
Apr 12 2016 08:02
i rly need help with this ... i watched these videos and i get the point , but its done on different way than I was doing the first part of it
so i cant really apply it
i need help with the next step, which is when i actually click the button to get something other than "Main page"
Markus Kiili
@Masd925
Apr 12 2016 08:03
@coderNoob val.hasOwnProperty(pre) inside if tests property existence. Boolean(val[pre]) tests if the property value if truthy.
alpox
@alpox
Apr 12 2016 08:04
@EldarT90 It seems that you get a response but i think your query string is wrong. It took me quite long to figure out what it has to look like... The best would be to try it out in the link they provide
Eldar Tinjić
@EldarT90
Apr 12 2016 08:04
@alpox yes, because i cant find good link anywhere on wiki site, so i should use one from example code?
Georg Burgstaller
@Burgi0101
Apr 12 2016 08:04
@coderNoob right now this is doing nothing because pre is not defined :D but other than that @Masd925 is right
Eldar Tinjić
@EldarT90
Apr 12 2016 08:04
@alpox btw good morning
You can experiment around with the api here
Eldar Tinjić
@EldarT90
Apr 12 2016 08:06
@alpox i did experiment but still ti gives me some data, not link which i can use
Gewrgios
@gstavr
Apr 12 2016 08:07
any help to Repeat a string repeat a string

'''function repeatStringNumTimes(str, num) {
// repeat after me
if(num < 0){
return " ";
}else {
return num * (str);
}

}

repeatStringNumTimes("abc", 3);
'''

CamperBot
@camperbot
Apr 12 2016 08:08
:bulb: to format code use backticks! ``` more info
Markus Kiili
@Masd925
Apr 12 2016 08:08
@gstavr Loop or recursion.
Gewrgios
@gstavr
Apr 12 2016 08:09
@Masd925 i want to output num time the string
the above example needs to output "abcabcabc"
Markus Kiili
@Masd925
Apr 12 2016 08:10
@gstavr You can make a loop that adds str to result string num times.
Gewrgios
@gstavr
Apr 12 2016 08:10
ohh yes
with a counter
i will try it
Gewrgios
@gstavr
Apr 12 2016 08:21
@Masd925 thx it is done
CamperBot
@camperbot
Apr 12 2016 08:21
gstavr sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1355 | @masd925 | http://www.freecodecamp.com/masd925
Elbert Cortez
@trip16661
Apr 12 2016 08:34
LOl i so need help with this? my json object that im getting is undefine most of it which leads to a funny result but it's not what i want xD
http://codepen.io/Trip1666/full/BKYqab/
DAVIEK22
@DAVIEK22
Apr 12 2016 08:41
Encode the following sequence, separated by spaces:
backslash tab tab carriage-return new-line and assign it to myStr .......var myStr = \ \t \t \r \n \b ..plz help
Danilo
@sennator
Apr 12 2016 08:42
can someone hel me with " Truncate a string
?
help*
CamperBot
@camperbot
Apr 12 2016 08:42

Hi, I'm CamperBot! I can help you in this chatroom :smile:

Basic Commands:

  • find TOPIC find all entries about topic. ex: find js
  • wiki TOPIC show contents of topic page
  • thanks @username send brownie points to another user
  • about @username shows info on that user
  • Algorithm BONFIRENAME info on a Algorithm

:speech_balloon: meet CamperBot in this room!

:pencil: read more about camperbot on the FCC Wiki

Justin
@daemedeor
Apr 12 2016 08:42
@trip16661 have you tried console.logging the channelOffOn?
Elbert Cortez
@trip16661
Apr 12 2016 08:43
y no problem with that one
the problem is with channelID
Justin
@daemedeor
Apr 12 2016 08:43
@trip16661 are you sure?
oh wait
you are using it correctly...
are you sure you have channels that are currently playing something?
Elbert Cortez
@trip16661
Apr 12 2016 08:45
ye
but even if so
the links are undefined
because the channelID is corrupted
@daemedeor the channeOffOn should give back info to transfor it to on or off and it oes
does
the problem comes iwth the second one
Justin
@daemedeor
Apr 12 2016 08:47
@trip16661 did you send an ID?
We require you to send your application's client_id with every request you make to ensure that your application is not rate limited. You should do so by sending the following HTTP header:
?
Danilo
@sennator
Apr 12 2016 08:47
I have a question about "Truncate a string". In assingment it says that we should add ... to our string but in one of the examples solution is "A-tisket a-tasket A green and yellow basket"....
witout three dots at the end
Elbert Cortez
@trip16661
Apr 12 2016 08:48
that it does really gives back the object but it gives it corrupted
so some parts works and some dont
you mean by putting the ?callback=?
for jsonp
Justin
@daemedeor
Apr 12 2016 08:50
@trip16661 oh i found the reason why
Elbert Cortez
@trip16661
Apr 12 2016 08:51
@sennator if longer than something you should add the dots and if you add them you have to do a substration acording to how many dots you put
Justin
@daemedeor
Apr 12 2016 08:51
@trip16661 try console.log(a) after the first json.get
Chris Cullen
@123xylem
Apr 12 2016 08:51
var arr = [
[1,2], [3,4], [5,6]
];
for (var i=0; i < arr.length; i++) {
for (var j=0; j < arr[i].length; j++) {
console.log(arr[i][j]);
}
}
This outputs each sub-element in arr one at a time. Note that for the inner loop, we are checking the .length of arr[i], since arr[i] is itself an array. _Hello, Can some1 tell me how arr[i] is an array? I thought it was a scanning function
Can some1 explain how arr[i] is an array?
Justin
@daemedeor
Apr 12 2016 08:51
@123xylem console.log(arr[i]); :D
Chris Cullen
@123xylem
Apr 12 2016 08:53
it prints 1
MichaelTsang
@MichaelTsang
Apr 12 2016 08:53
have no idea about Roman Numeral Converter ...
any clue? need help
Chris Cullen
@123xylem
Apr 12 2016 08:53
isnt arr[i] just a scanning function and not an aray?
Justin
@daemedeor
Apr 12 2016 08:54
@123xylem nope well according to your code: arr = [[1,2],[3,4],[5,6]] so arr[0] = [1,2] and arr1 = [3,4]
Aleksandr Kozlov
@Cu3bIu
Apr 12 2016 08:54

Guys a quick question: What is more logical to do and more "Resource saving":

  1. to use arr[0].split(); in loops to constatly divide the arr string element and do actions with an array like .length or .indexOf()
  2. or to assign the value of arr[0].split(); to a variable in the beginning of a function and use that instead?

Is there any particular difference in these 2 actions? I feel the second one is less work for processing.

Chris Cullen
@123xylem
Apr 12 2016 08:54
so arr[i] scans the array but stores the scanned info as a new array?
Justin
@daemedeor
Apr 12 2016 08:55
@123xylem nope arr[i] is an accessor (with i being a number) and it access positions in the array
Danilo
@sennator
Apr 12 2016 08:56
please guys
Justin
@daemedeor
Apr 12 2016 08:56
so to access the first position of the array you'd do arr[0]
Danilo
@sennator
Apr 12 2016 08:56
i need help :D
Elbert Cortez
@trip16661
Apr 12 2016 08:56
@daemedeor it shows 11 exctly the quantity of the arraw where the chanels are
Justin
@daemedeor
Apr 12 2016 08:56
@trip16661 isn't that a problem? :)
because it console.logs 11 x 11 times ;D
Elbert Cortez
@trip16661
Apr 12 2016 08:57
i don't seems to get it yet
Justin
@daemedeor
Apr 12 2016 08:58
@trip16661 whats twitchChannels[11]?
Elbert Cortez
@trip16661
Apr 12 2016 08:58
isn't it the last channel ?
Justin
@daemedeor
Apr 12 2016 08:59
@trip16661 is it?
try do it in your console
vetoCode
@vetoCode
Apr 12 2016 08:59
can someone look at my JS code .. why fires the else-statement?
http://codepen.io/vetoCode/pen/GZQEgp?editors=0010
Eldar Tinjić
@EldarT90
Apr 12 2016 09:00
@alpox tnx
CamperBot
@camperbot
Apr 12 2016 09:00
eldart90 sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star: 512 | @alpox | http://www.freecodecamp.com/alpox
Chris Cullen
@123xylem
Apr 12 2016 09:00
so arr[i] isnt really an array then? its an accesor of an array
Elbert Cortez
@trip16661
Apr 12 2016 09:01
@daemedeor oh wait y
is undefined
Justin
@daemedeor
Apr 12 2016 09:01
@123xylem well... the bracket notation on the array means you're trying to access the array value at a specific point and passing in a number means which position you're trying to access in this case the value of the item at arr[0] happens to be another array
@trip16661 remember js is 0 based first of all
Aleksandr Kozlov
@Cu3bIu
Apr 12 2016 09:02
@123xylem arr[i] can return an array if you have arr= [[1, 2, 3], [2, 3, 4]];
Chris Cullen
@123xylem
Apr 12 2016 09:03
ok gotya.. i think the explanation is badly worded..
Elbert Cortez
@trip16661
Apr 12 2016 09:03
so should it be twitchChannel.length-1 ?
Justin
@daemedeor
Apr 12 2016 09:04
@trip16661 yes! but you still have another huge flaw :)
Eldar Tinjić
@EldarT90
Apr 12 2016 09:04
need some1 to patiently explain me certain concepts from wikipedia challenge, thanks
Elbert Cortez
@trip16661
Apr 12 2016 09:06
@daemedeor thanks
CamperBot
@camperbot
Apr 12 2016 09:06
trip16661 sends brownie points to @daemedeor :sparkles: :thumbsup: :sparkles:
:star: 324 | @daemedeor | http://www.freecodecamp.com/daemedeor
John Delaney
@jdpunk1
Apr 12 2016 09:07
blob
Morning all, I'm on the Make a Person challenge. whittling it down to 6 objects is proving difficult; code so far is above..
I've been trying to find a way to get it to invoke setFullName when first run, not sure if this is a dead-end or I should be trying a different route
Blauelf
@Blauelf
Apr 12 2016 09:19
help format
CamperBot
@camperbot
Apr 12 2016 09:19

:point_right: code formatting [wiki]

Multi line Code

```js ⇦ Type 3 backticks and then press [shift + enter ⏎] (type js or html or css)

<paste your code here>,
then press [shift + enter ⏎]

``` ⇦ Type 3 backticks, then press [enter ⏎]

Single line Code

This an inline `<paste code here>` code formatting with a single backtick(`) at start and end around the code.

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

:pencil: read more about code formatting on the FCC Wiki

Blauelf
@Blauelf
Apr 12 2016 09:21
@jdpunk1 Use text Copy&Paste with code, makes things easier.
To your code: You should declare one or more variables inside your constructor that are used for sharing the person's name between the functions. The object itself should have six properties, those six methods you define.
Most people declare name variable(s), methods, and as their last line inside the constructor, they this.setFullName(firstAndLast); (or they do the same thing in initialization, depending on implementation).
Chris Cullen
@123xylem
Apr 12 2016 09:22

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

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

HI this code works.. But can some1 tell me why i++ doesnt add the elements in the array like it did in a previous lesson

Blauelf
@Blauelf
Apr 12 2016 09:22
@123xylem i++ increments i by one, it does not add any elements.
Eldar Tinjić
@EldarT90
Apr 12 2016 09:22
need some1 to patiently explain me certain concepts from wikipedia challenge, thanks
Brendan Kinahan
@BKinahan
Apr 12 2016 09:24
@EldarT90 you may wish to also try https://gitter.im/FreeCodeCamp/HelpFrontEnd for that
Eldar Tinjić
@EldarT90
Apr 12 2016 09:24
oke tnx
altough its highly js related
Chris Cullen
@123xylem
Apr 12 2016 09:26
@Blauelf thanks... mybad i misread the previous lesson that added i... i did think i++ was just a run through functon
CamperBot
@camperbot
Apr 12 2016 09:26
:star: 1582 | @blauelf | http://www.freecodecamp.com/blauelf
123xylem sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
John Delaney
@jdpunk1
Apr 12 2016 09:27
@Blauelf thanks, I just need to add a name variable then.. I'll try that and test it out..
CamperBot
@camperbot
Apr 12 2016 09:27
jdpunk1 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1583 | @blauelf | http://www.freecodecamp.com/blauelf
Brendan Kinahan
@BKinahan
Apr 12 2016 09:27
@EldarT90 I mean, you can ask JS questions here of course, but people in this room who can help are probably more familiar with the JS challenges, and folks in the FrontEnd room are more familiar with the FrontEnd challenges :)
Rada
@Radascript
Apr 12 2016 09:30

hey guys I know it's messy but can you please please see why the comparison on JavaScript lines 51-53 comes up FALSE in console.log, even though values are identical?

http://codepen.io/RadaCodes/pen/NNyEPb?editors=0010#

Chris Cullen
@123xylem
Apr 12 2016 09:32

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

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

Could some1 comment up the function I wrote?.. I dont really understand it fully. Its pretty basic

but its not clicking for me
Brendan Kinahan
@BKinahan
Apr 12 2016 09:35
@Radascript It's too early for spaghetti :P
@Radascript your check that the values are identical comes after lines 51-53
Eldar Tinjić
@EldarT90
Apr 12 2016 09:36
why is this not working
Brendan Kinahan
@BKinahan
Apr 12 2016 09:37
@EldarT90 $("#weather").append('<p>' + data + '</p>'); where is the element with id "weather"?
Eldar Tinjić
@EldarT90
Apr 12 2016 09:37
@BKinahan i changed to searching, but still not working
@BKinahan since i copied from my previous challenge the syntax
Rada
@Radascript
Apr 12 2016 09:38
@123xylem with the first loop, you are telling your function to go through each of the arrays in it (you are saying - please look at array [1,2], then look at array [3,4], then look at array [5,6,7].
With your second (j-)loop, you are telling your function - now that you are at array [1,2], go through each of it's values. multiply sum each of them.
Brendan Kinahan
@BKinahan
Apr 12 2016 09:38
@EldarT90 shouldn't it be 'results'?
@Radascript 'searching' is the button
Eldar Tinjić
@EldarT90
Apr 12 2016 09:38
@BKinahan yes , but nothig is working apparently, i think problem is with syntax
@BKinahan not only with id im targeting
Rada
@Radascript
Apr 12 2016 09:38
@BKinahan I meant these three lines:
 console.log("compare value " + compare[c] + " breakdown value " + breakdown[b][x]);
      var izzet = compare[c] == breakdown[b][x];
      console.log("IS IT TRUE?" + izzet);
@BKinahan I dug myself so deep into a hole with this dumb bonfire. What do you mean searching is the button?
Chris Cullen
@123xylem
Apr 12 2016 09:40
@Radascript thanks... Could you explain this line.. I know what it means but I cant say it in my head? Id say it means "product = position J of arrI times by value of product"
CamperBot
@camperbot
Apr 12 2016 09:40
123xylem sends brownie points to @radascript :sparkles: :thumbsup: :sparkles:
:star: 295 | @radascript | http://www.freecodecamp.com/radascript
Brendan Kinahan
@BKinahan
Apr 12 2016 09:40
@Radascript sorry, @'d the wrong person there, meant @EldarT90
seems to be happening to you a lot lately :P
Blauelf
@Blauelf
Apr 12 2016 09:40
@123xylem Have you tried stepping through the code with pythontutor? Maybe that helps. Also, try using some better formatting, you can try a service like jsbeautifier.org for more readability.
Rada
@Radascript
Apr 12 2016 09:42
@123xylem when you say postion J or array I, you are just narrowing down on each specific value (1,2,3,4,5,6,7). For example, "6" is i=3 (third array) and j=2 (second position in it.) Does that help at all?
@BKinahan I think I often either breeze through a challenge or get stuck and do something ridiculous.
Vivienne Sales
@Natto278
Apr 12 2016 09:43

I'm at the Counting Cards Challenge. This time, I'm writing the code in my paper notebook before entering it online. I got the first sequence correct, but there is a caution message: unreachable 'break' after 'return'. Is something I need to worry about. Here's my code for this challenge (for now): var count = 0;

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

switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
return "5 Bet"; // Should return "5 Bet"
break;

return "Change Me";
}
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

Chris Cullen
@123xylem
Apr 12 2016 09:43
Yea I do know them basics.. its just the little things that Im not fully understanding.. like what is *= in english... WHy do the array[i][j] need square brackets etc
@Radascript @Blauelf
Blauelf
@Blauelf
Apr 12 2016 09:44
@Radascript Add some block after that for-loop. You are looping console.log("compare value " + compare[c] + " breakdown value " + breakdown[b][x]); only.
Chris Cullen
@123xylem
Apr 12 2016 09:44
btw @Blauelf il check out pyton tutor
Blauelf
@Blauelf
Apr 12 2016 09:45
@123xylem a *= b is short for a = a * b, and array[i][j] is the same as (array[i])[j], as both array and array[i] are arrays. No multi-dimensional arrays in Javascript, just arrays with arrays inside.
Rada
@Radascript
Apr 12 2016 09:46
@123xylem ohh I see. Well product=arr[i][j] is just saying
product = product
arr[i][j]. It's saying "take product and multiply it by arr[i][j].
And square brackets are just a notation javascript uses to describe positions inside the arrays.
@Blauelf oh man yikes. thanks
CamperBot
@camperbot
Apr 12 2016 09:47
radascript sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1584 | @blauelf | http://www.freecodecamp.com/blauelf
Brendan Kinahan
@BKinahan
Apr 12 2016 09:47
@EldarT90 You're checking for the value of the submit button, not the value of the text input
Blauelf
@Blauelf
Apr 12 2016 09:48
@Radascript And maybe you meant breakdown[b].splice(indexB, 1);, not breakdown.splice(indexB, 1);
Chris Cullen
@123xylem
Apr 12 2016 09:48
@Radascript , @Blauelf thanks... Hopefully I can start learning more independently soon... Coding can make you feel so stupid sometimes :)
CamperBot
@camperbot
Apr 12 2016 09:48
123xylem sends brownie points to @radascript and @blauelf :sparkles: :thumbsup: :sparkles:
:warning: 123xylem already gave blauelf points
:warning: 123xylem already gave radascript points
Rada
@Radascript
Apr 12 2016 09:49
@Blauelf yes I did. That's really impressive how you managed to quickly see the issues. I often get lost in my own code, let alone other people's.
@123xylem good luck, but don't be shy about coming here for advice. I was self-conscious about it at first, but the people here are really helpful and friendly, and soon you can start helping other newer people as well.
Mooli
@Mooli88
Apr 12 2016 09:54
hi, need help with the twitch api please
how can i know if someone is offline or online without using the stream api but the channel api ?
Blauelf
@Blauelf
Apr 12 2016 09:57
@Radascript Follow the control structures, the path the code takes. If a for-loop or if-statement is not followed by curly brackets, while the code does not look like this was intended, it's most likely a bug (better always use curly brackets there)...
And while I have no idea what that code is meant to do, if you iterate an array and splice it at the same time, you might need to adjust the index.
Bharat
@BharatKalluri
Apr 12 2016 09:57
hey guys
function bouncer(arr) {
  // Don't show a false ID to this bouncer.
   for (var i=0;i<arr.length;i++) {
     if (arr[i]===false || arr[i]===0 || arr[i]==="" || arr[i]===undefined || arr[i]===NaN) {
       arr.splice(arr[i],1);
     }
   }
 return arr;
}


bouncer([false, null, 0, NaN, undefined, ""]);
why is this code not working (exercise falsey Bouncers)
Brendan Kinahan
@BKinahan
Apr 12 2016 09:59
@Bharat-Kalluri other than changing the length of arr while running a for loop depending on its length, comparison with NaN doesn't work the way you'd expect. check out https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN
@Bharat-Kalluri Maybe look into the filter method as well, it's really useful here.
Blauelf
@Blauelf
Apr 12 2016 10:00
@Bharat-Kalluri You cannot check that way for NaN, as NaN does not equal anything (not even itself). You could use arr[i]!==arr[i] for that test. Also, check for null is missing. And you would have to i-- after splicing to account for changed indexes (the index would be increased on next iteration, making you skip one element).
Chris Cullen
@123xylem
Apr 12 2016 10:01
@Radascript ;)
I keep having to check answers at each checkpoint.. Is that normal or should I have the knowledge as I go ?
Bharat
@BharatKalluri
Apr 12 2016 10:03

after modifying the code as such

function bouncer(arr) {
  // Don't show a false ID to this bouncer.
   for (var i=arr.length;i>=0;i--) {
     if (arr[i]===false || arr[i]===0 || arr[i]==="" || arr[i]===null || arr[i]===undefined || isNaN(a[i])) {
       arr.splice(arr[i],1);
     }
   }
 return arr;
}

it returns an empty array..?

Brendan Kinahan
@BKinahan
Apr 12 2016 10:03
depends on what you mean by checking answers at each checkpoint. do you mean the solutions on the wiki?
@Bharat-Kalluri for the input bouncer([false, null, 0, NaN, undefined, ""]); an empty array is correct.
Bharat
@BharatKalluri
Apr 12 2016 10:04
@BKinahan can you breifly explain how to use filter method? I tried reading docs but still I could not understand
@BKinahan it returns an empty arr for all iputs
Brendan Kinahan
@BKinahan
Apr 12 2016 10:05
@Bharat-Kalluri but I think you have an off-by-one error
Markus Kiili
@Masd925
Apr 12 2016 10:05
@Bharat-Kalluri isNaN does not test for NaN. It has to be combined with type check, to make it a test for NaN. isNaN gives true for many other values besides just NaN.
Brendan Kinahan
@BKinahan
Apr 12 2016 10:06
@Bharat-Kalluri When you call filter() on an array, it checks each element of the array one at a time. It puts each one through the callback function of the filter, and if that function returns true (or a non-falsy value) then the element is added to a new array. Once all elements are checked, the new array is returned.
(that comes later, but it could be useful to try)
Actually it's kind of odd that the introduction to filter comes after Falsy Bouncer, which lists the docs for filter as a useful link, now that I think of it..
Markus Kiili
@Masd925
Apr 12 2016 10:12
@BKinahan It is also odd that helpful links contain link to Boolean objects, when it should be to Boolean function.
Bharat
@BharatKalluri
Apr 12 2016 10:13
@BKinahan here is the modified code
function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  array = arr.filter(function(val){
  return val !== false || val !== 0 || val !== "" || val !== undefined || isNaN(val);
});
  return array;
}
Vivienne Sales
@Natto278
Apr 12 2016 10:13

Hi. I re-did my code for the Counting Card challenge and got the first three items and the last item correct. I'm having trouble with the 4th, 5th and 6th items. Are we allowed to use if / if else statements for this challenge? Here's my code: var count = 0;

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

switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
return "5 Bet"; // Should return "5 Bet"
break;

case 7:
case 8: 
case 9:
  return "0 Hold";
  break;

case 10:
case 'J':
case 'Q':
case 'A':
  return "-5 Hold";
  break;

case 3:
case 7:
case 'Q':
case 8:
case 'A':
  return "-1 Hold";
  break;

case 2: 
case 'J':
case 9:
case 2:
case 7:
  return "1 Bet";
  break;

case 2:
case 2:
case 10:
  return "1 Bet";
  break;

case 'K':
case 10:
case 'A':
case 2: 
case 3:
  return "-1 Hold";
  break;

return "Change Me";
}
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(3);

Brendan Kinahan
@BKinahan
Apr 12 2016 10:16
@Natto278 The betting decision and count returned should depend not only on the currently drawn card, but the ongoing count of the cards.
Bharat
@BharatKalluri
Apr 12 2016 10:19
@BKinahan why is my filter function not working
Brendan Kinahan
@BKinahan
Apr 12 2016 10:20
@Bharat-Kalluri think of ("" !== false || "" !==0 || ...)
Bharat
@BharatKalluri
Apr 12 2016 10:21
@BKinahan i do not understand
Vivienne Sales
@Natto278
Apr 12 2016 10:21
@BKinahan So, I need to add code that shows the cards being drawn and the cards that still need to be drawn? Are we allowed to use if and if else statements for the Counting Cards challenge?
Markus Kiili
@Masd925
Apr 12 2016 10:22
@Bharat-Kalluri Add a test for value null and test for not being NaN with val===val. And use && instead of ||. Then it works.
MichaelTsang
@MichaelTsang
Apr 12 2016 10:23
https://www.freecodecamp.com/challenges/roman-numeral-converter
is there any boy can solve this problem?
Brendan Kinahan
@BKinahan
Apr 12 2016 10:23
@Natto278 you can use if/else, but the important thing to know is that the global count variable is for keeping track of the card count between different calls to the function.
@MichaelTsang that's sexist :P
Bharat
@BharatKalluri
Apr 12 2016 10:24
@Masd925
function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  array = arr.filter(function(val){
  return val === false && val === 0 && val === "" && val === undefined && val===val && val===null;
});
  return array;
}
Rodney Jan Mandap
@r0dJm4n
Apr 12 2016 10:24
Hello Guys, need help I can't get this output right "abTest(2, -2) should return undefined"
function abTest(a, b) {
  // Only change code below this line

  if(a < 0){
    c = a;
  } else if (b < 0){
    c = b;
  }

  console.log(c);
  // Only change code above this line

  return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}

// Change values below to test your code
abTest(2,-2);
Brendan Kinahan
@BKinahan
Apr 12 2016 10:25
@Bharat-Kalluri NOT false, NOT 0, etc
@r0dJm4n no need for c, just return undefined inside both of those if statements
Rodney Jan Mandap
@r0dJm4n
Apr 12 2016 10:25
how?
Brendan Kinahan
@BKinahan
Apr 12 2016 10:26
@r0dJm4n return undefined; or simply return; :P Also else isn't really necessary since it won't be reached unless a>=0
Bharat
@BharatKalluri
Apr 12 2016 10:27
@BKinahan still not working :-(
Rodney Jan Mandap
@r0dJm4n
Apr 12 2016 10:27
I tried it once before it comes with an error because the keyword return already exist below
Brendan Kinahan
@BKinahan
Apr 12 2016 10:27
@r0dJm4n post that code instead :)
MichaelTsang
@MichaelTsang
Apr 12 2016 10:27
Brendan Kinahan
@BKinahan
Apr 12 2016 10:27
@MichaelTsang what have you tried?
Rodney Jan Mandap
@r0dJm4n
Apr 12 2016 10:28
where should I post it?
@BKinahan
Brendan Kinahan
@BKinahan
Apr 12 2016 10:30
right here :>
Rodney Jan Mandap
@r0dJm4n
Apr 12 2016 10:30
I already posted it :smile:
Brendan Kinahan
@BKinahan
Apr 12 2016 10:34
@r0dJm4n I mean the code where you tried returning undefined instead of using a c variable.
Vivienne Sales
@Natto278
Apr 12 2016 10:36
@BKinahan Thank you for answering my questions. I'm going to look up how to use global count variables on Google and rethink my code offline.
CamperBot
@camperbot
Apr 12 2016 10:36
natto278 sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1267 | @bkinahan | http://www.freecodecamp.com/bkinahan
Rodney Jan Mandap
@r0dJm4n
Apr 12 2016 10:37
Sorry for that @BKinahan :smile:
This is the code:
// Setup
function abTest(a, b) {
  // Only change code below this line

  if(a < 0){
    return a;
  } else if (b < 0){
    return b;
  }

  return;
  // Only change code above this line

  return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}

// Change values below to test your code
abTest(2,-2);
Brendan Kinahan
@BKinahan
Apr 12 2016 10:43
@r0dJm4n don't return a or b, just return undefined if either is negative. remove the return; line
usharya
@usharya
Apr 12 2016 10:43
Hello, having trouble with the challenge 'Golf Code'
I don't understand the table :(
Chris Cullen
@123xylem
Apr 12 2016 10:44
Could some1 help me with this one? One thing im struggling with is the firstName variable surely it should be like this"firstName".. Either way my code isnt working
https://www.freecodecamp.com/challenges/profile-lookup#?solution=%2F%2FSetup%0Avar%20contacts%20%3D%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Akira%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Laine%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220543236543%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Pizza%22%2C%20%22Coding%22%2C%20%22Brownie%20Points%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Harry%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Potter%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220994372684%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Hogwarts%22%2C%20%22Magic%22%2C%20%22Hagrid%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Sherlock%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Holmes%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220487345643%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Intriguing%20Cases%22%2C%20%22Violin%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Kristian%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Vos%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%22unknown%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Javascript%22%2C%20%22Gaming%22%2C%20%22Foxes%22%5D%0A%20%20%20%20%7D%0A%5D%3B%0A%0A%0Afunction%20lookUpProfile(firstName%2C%20prop)%7B%0A%20%20%0A%2F%2F%20Only%20change%20code%20below%20this%20line%0Afor%20(i%3D0%3B%20i%3Ccontacts.length%3B%20i%2B%2B)%0A%7Bif%20(contacts%5Bi%5D.firstName%20%3D%3D%3D%20%22firstName%22)%3B%0A%20%7Bif%20(contacts%5Bi%5D%5Bprop%5D)%7Breturn%20contacts%5Bi%5D%5Bprop%5D%3B%7D%0A%20%20else%20%7Breturn%20%22No%20such%20property%22%3B%7D%7D%0A%20return%20%22No%20such%20contact%22%3B%7D%0A%2F%2F%20Only%20change%20code%20above%20this%20line%0A%0A%0A%7D%0A%2F%2F%20Change%20these%20values%20to%20test%20your%20function%0AlookUpProfile(%22Bob%22%2C%20%22number%22)%3B%0A
Rodney Jan Mandap
@r0dJm4n
Apr 12 2016 10:46
@BKinahan should I also change my condition?
Brendan Kinahan
@BKinahan
Apr 12 2016 10:47
@123xylem contacts[i].firstName is the value of the firstName property of each contact. None of the first names are "firstName". "firstName Potter and the Sorcerer's Stone" would never sell.
@usharya if your number of strokes is one under par, you have a Birdie. strokes == par - 1: "Birdie"
@r0dJm4n the conditions are fine
Vivienne Sales
@Natto278
Apr 12 2016 10:52
@r0dJm4n I saw your code for the Return Early Pattern for Functions. When I did that exercise, I wrote two separate 'if' statements and didn't use any 'else if' statements. Here's a hint: if (x < 0) return undefined;
Rodney Jan Mandap
@r0dJm4n
Apr 12 2016 10:54
Gotcha :smile: Thanks @BKinahan and @Natto278 for the help.
CamperBot
@camperbot
Apr 12 2016 10:54
r0djm4n sends brownie points to @bkinahan and @natto278 :sparkles: :thumbsup: :sparkles:
:star: 212 | @natto278 | http://www.freecodecamp.com/natto278
:star: 1268 | @bkinahan | http://www.freecodecamp.com/bkinahan
usharya
@usharya
Apr 12 2016 10:55
@BKinahan What about the Hole in one?
Brendan Kinahan
@BKinahan
Apr 12 2016 10:56
@usharya In golf, a hole in one happens when you reach the whole in one (stroke)
usharya
@usharya
Apr 12 2016 10:56
(stroke == 1) return "Hole in one";
?
Ignore the formatting
this is okay then?
if (strokes == 1 && par == 1) {
    return "Hole-in-one!";
  }
Sonya Moisset
@SonyaMoisset
Apr 12 2016 10:58
@usharya
if (strokes === 1) {
    return "Hole-in-one!";
  }
Brendan Kinahan
@BKinahan
Apr 12 2016 10:58
@usharya if strokes == 1 it doesn't matter what par is
usharya
@usharya
Apr 12 2016 10:58
@SonyaMoisset Thank you :)
CamperBot
@camperbot
Apr 12 2016 10:58
usharya sends brownie points to @sonyamoisset :sparkles: :thumbsup: :sparkles:
:star: 1175 | @sonyamoisset | http://www.freecodecamp.com/sonyamoisset
usharya
@usharya
Apr 12 2016 10:59
I am currently making the code, so I will paste the end code @BKinahan
Brendan Kinahan
@BKinahan
Apr 12 2016 10:59
@usharya okay
usharya
@usharya
Apr 12 2016 11:03
function golfScore(par, strokes) {
  // Only change code below this line
  if (strokes == 1) {
    return "Hole-in-one!";
  } else if (strokes <= par -2) {
    return "Eagle";
  } else if (strokes = par - 1) {
    return "Birdie";
  } else if (strokes == par) {
    return "Par";
  } else if (strokes = par + 1) {
    return "Bogey";
  } else if (strokes = par + 2){
    return "Double Bogey";
  } else if (strokes >= par + 3) {
    return "Go Home!";
  }
  return "Change Me";
  // Only change code above this line
}
@BKinahan is this okay?
Paulo
@redcinelli
Apr 12 2016 11:04
Hey peeps ... I am strugguling with something stupid .. but I can't sort it out ... I am need to find in a array the index for a number to fit in .
function getIndexToIns(arr, num) {
// Find my place in this sorted array.
arr = arr.sort();
arr.forEach(function(a,b,c){
if(a>num)return b;
});
return arr.length-1;
}
Islam Ibakaev
@dagman
Apr 12 2016 11:05
@redcinelli whats the bonfire name
?
Paulo
@redcinelli
Apr 12 2016 11:05
where do I belong
Islam Ibakaev
@dagman
Apr 12 2016 11:07
@redcinelli you should push number to array then sort array then return num index
Paulo
@redcinelli
Apr 12 2016 11:08
@dagman well seems more efficent ty
Blauelf
@Blauelf
Apr 12 2016 11:08

@redcinelli If you really want to use sort (you don't have to, the solution can be obtained by simply counting the array elements that are <num), you'll have to do numerical sort:

arr.sort(function(a,b) {
  return a-b;
});

(the arr = is redundant, as sort sorts in-place, so changes the array)
Sort will occasionally test whether element a is greater than b, call that callback, and if the return value is greater than 0, assume that a is indeed greater than b. Without callback, sort will alphabetically sort by string representation.

Paulo
@redcinelli
Apr 12 2016 11:09
@Blauelf thank you :)
CamperBot
@camperbot
Apr 12 2016 11:09
redcinelli sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1585 | @blauelf | http://www.freecodecamp.com/blauelf
Zabe Sangary
@zabesangary
Apr 12 2016 11:12
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firxstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUpProfile(firstName, prop){
   if(firstName === prop[contacts]){
     return contacts[3].lastName;
   }
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
Islam Ibakaev
@dagman
Apr 12 2016 11:12
@redcinelli also works
 arr.sort(function(a, b) {
    return a > b;
  });
Zabe Sangary
@zabesangary
Apr 12 2016 11:12
need some help
Blauelf
@Blauelf
Apr 12 2016 11:13
@redcinelli If you wanted to keep your code, in addition to sorting numerically, you would have to adjust to for (var b = 0; b < arr.length; b++) { if (arr[b]>=num) return b; } (you cannot return the outer function from an inner function) and return arr.length;
I still prefer simply counting the elements that are <num :D
  return arr.reduce((count, elem) => count + (elem < num), 0);
Paulo
@redcinelli
Apr 12 2016 11:16
@Blauelf @dagman Thank a lot guys. It perfect
CamperBot
@camperbot
Apr 12 2016 11:16
redcinelli sends brownie points to @blauelf and @dagman :sparkles: :thumbsup: :sparkles:
:warning: redcinelli already gave blauelf points
:star: 389 | @dagman | http://www.freecodecamp.com/dagman
Chris Cullen
@123xylem
Apr 12 2016 11:17

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

function lookUpProfile(firstName, prop){


// Only change code below this line
for (i=0; i<contacts.length; i++)
{if (contacts[i].firstName === firstName);
{if (contacts[i][prop]){return contacts[i][prop];}
else {return "No such property";}}
return "No such contact";}
// Only change code above this line

}
// Change these values to test your function
lookUpProfile("Bob", "number");

Any idea why my Fucntion isnt working?
I think it may have something to do with the firstName bit...
Im not sure though...
Ken Haduch
@khaduch
Apr 12 2016 11:36

@123xylem - here is your code posted in a better format:

function lookUpProfile(firstName, prop) {
  // Only change code below this line
  for (i = 0; i < contacts.length; i++)
  {
    if (contacts[i].firstName === firstName);
    {
      if (contacts[i][prop]) {
        return contacts[i][prop];
      } 
      else {
        return 'No such property';
      }
    }
    return 'No such contact';
  }
  // Only change code above this line

}
// Change these values to test your function

One problem, and this is a very common one with this challenge, is that you have to consider what would happen if the contact that is being searched for is not the first in the list. And know that when you return, that ends the operation of the function. The for loop has to be able to get through the entire list to look for matching firstName values before it determine No such contact... so you have to move that return 'No such contact'; elsewhere.

Dave
@copendaven
Apr 12 2016 11:37
Hey guys, i’m on the where art thou challenge, and i’m having some difficulty understanding how to loop through an array, test conditions and only perform an action if ALL conditions are true, but with an unknow number of conditions. At the moment, my code pushes the collection element to the result array as soon as a condition is true i.e if first names are the same… can anyone shed some light on how I can only push to the array if each keys value matches?
Ken Haduch
@khaduch
Apr 12 2016 11:37
@123xylem - also, what you're doing to check for the property might work here, but they suggest using .hasOwnProperty() to test for it, you should have another look at that...
Dave
@copendaven
Apr 12 2016 11:38
This message was deleted
This message was deleted
Ken Haduch
@khaduch
Apr 12 2016 11:38
help format
CamperBot
@camperbot
Apr 12 2016 11:38

:point_right: code formatting [wiki]

Multi line Code

```js ⇦ Type 3 backticks and then press [shift + enter ⏎] (type js or html or css)

<paste your code here>,
then press [shift + enter ⏎]

``` ⇦ Type 3 backticks, then press [enter ⏎]

Single line Code

This an inline `<paste code here>` code formatting with a single backtick(`) at start and end around the code.

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

:pencil: read more about code formatting on the FCC Wiki

Chris Cullen
@123xylem
Apr 12 2016 11:39
ahhh... My loop is ending too soon because once the If fails it ends... With regard to the .hasOwnProperty() im using contacts[i][prop] instead.. could you explain the difference?
Ken Haduch
@khaduch
Apr 12 2016 11:39
@copendaven - backticks... :) you're probably trying to get them... if you have trouble with that, check the link https://github.com/freecodecamp/freecodecamp/wiki/code-formatting
Adam Dąbrowski
@a-dabrowski
Apr 12 2016 11:40

Hey guys, I'm struggling with Stand in Line challenge, and i'm not quite sure whether i did wrong or there is a bug in this challenge.

nextInLine([5,6,7,8,9], 1) should return 5, and it actually does, but it doesn't take to me the next challenge (other requirements are met)

function nextInLine(arr, item) {
// Your code here
testArr.push(testArr[0]);
testArr.shift(testArr.length);
if(item == 10){testArr[4]=10}
return testArr[testArr.length-1]*item; // Change this line
}

// Test Setup
var testArr = [5,6,7,8,9];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 1)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

Chris Cullen
@123xylem
Apr 12 2016 11:41
@khaduch ahhh... My loop is ending too soon because once the If fails it ends... With regard to the .hasOwnProperty() im using contacts[i][prop] instead.. could you explain the difference? btw thanks it worked!
CamperBot
@camperbot
Apr 12 2016 11:41
123xylem sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star: 920 | @khaduch | http://www.freecodecamp.com/khaduch
Zabe Sangary
@zabesangary
Apr 12 2016 11:42
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firxstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


var flag=false;
for(var i=0;i<contacts.length;i++)
   if(contacts[i].firstName===firstName)
   {
       if(contacts[i].hasOwnProperty(prop))
       {
        flag=true;
        return contacts[i][prop];
       }
       else return "No such property";
   }
    if(flag===false){
      return = "No such contact";
}

// Change these values to test your function
lookUpProfile("Akira", "likes");
returns illegal statement?
Ken Haduch
@khaduch
Apr 12 2016 11:43
@123xylem - Object.hasOwnProperty() returns a Boolean (i.e. true or false) if the object has the property. It might be working for you the way you are doing it if the property contains a "truthy" value, but if it doesn't then you won't recognize that the property is there, perhaps with an empty string or null or false, etc. That's the difference, at least the main one, as I see it.
Sameer Shamsudeen
@sameershamsudheen
Apr 12 2016 11:43
hello please help me with the record collection challenge in Javascript, tell me what i done wrong, this is my code
function updateRecords(id, prop, value) {
  if(id === collection[id]){
    if(value !== "" && prop !== collection[id].tracks){
      collection[id].prop = value;
    }
    if(prop === collection[id].tracks && value !== ""){
      collection[id].tracks.push(value);
    }
    if(value === ""){
      delete collection[id].prop;
    }
  }
  return collection;
}
Dave
@copendaven
Apr 12 2016 11:44
function whereAreYou(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line

  for(var i=0; i<collection.length; i++)
  {
    for(var key in source)
    {
      if(collection[i].hasOwnProperty(key))
      {
        if(collection[i][key] == source[key])
        {
          arr.push(collection[i]);
        }
      }
    }
  }

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

whereAreYou([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 });
Ok there we go, it was the cmd+enter to send that was getting me!!! can anyone help with how I can only push to the array if all keys have a matchng value??
Chris Cullen
@123xylem
Apr 12 2016 11:48
@khaduch so how could it return true if it wasnt true? Sorry im missing something really basic.. i know roughly what your saying but i dont understand how it can sometimes be false
Blauelf
@Blauelf
Apr 12 2016 11:56

@copendaven You should probably not push every time you have a match (so for two properties you get no, one, or two copies). I think I used

if (Object.keys(source).every(function(key) {
  return collection[i].hasOwnProperty(key) && collection[i][key] == source[key];
}) {
  arr.push(collection[i]);
}

or PASCAL-style (programming language of my first coding years):

var keys = Object.keys(source),
    include;
for (var i = 0; i < collection.length; i++) {
  include = true;
  for (var key of keys) {
    if (!collection[i].hasOwnProperty(key) || collection[i][key] !== source[key]) {
      include = false;
    }
  }
  if (include) {
    arr.push(collection[i]);
  }
}
vetoCode
@vetoCode
Apr 12 2016 11:58
why my start btn dosn't fire after I start the game and reset it to start it again?
http://codepen.io/vetoCode/pen/GZQEgp?editors=0010
Dave
@copendaven
Apr 12 2016 12:00
Thanks again @Blauelf !! what does include; add? I’ve done a search but I can only find how to include other files
CamperBot
@camperbot
Apr 12 2016 12:00
copendaven sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1586 | @blauelf | http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Apr 12 2016 12:01
@copendaven That's an arbitrary name. A variable meant to keep track if there are any mismatches for that array element, or if I should include it in the final array. PASCAL had no functional programming, so one would use a variable and a loop for that.
Dave
@copendaven
Apr 12 2016 12:02
@Blauelf ahh, yes, if i’d read it all i’d have seen that!! ok, I’ll try and adapt my code to use a similar flag
usharya
@usharya
Apr 12 2016 12:06
why should we use if else statements, when we can use switch?
Ken Haduch
@khaduch
Apr 12 2016 12:09

@123xylem - the idea that I'm trying to get across is that if you have an object and code like this:

var myTestObj = {
  propA: 'apple',
  propB: ''
};
if (myTestObj.hasOwnProperty('propB')) {
  console.log('value of hasOwnProperty for propB = true');
} 
else
{
  console.log('value of hasOwnProperty for propB = false');
}
if (myTestObj.propB) {
  console.log('value of myTestObj.propB = true');
} 
else
{
  console.log('value of myTestObj.propB = false');
}

This is the output that this little test program returns:

value of hasOwnProperty for propB = true
value of myTestObj.propB = false

So if you have a property that has a "falsey" value, you won't get an indication that the property exists. In the case of this challenge for contacts, all of the properties probably have values, so your code / test for the property works...

Chris Cullen
@123xylem
Apr 12 2016 12:13
ah so the difference is hasOwnProperty will show if it exists or not regardless of value but obj.test will only show the value as true if its a recognised value?
Blauelf
@Blauelf
Apr 12 2016 12:15
obj.hasOwnProperty("test") is true if obj.test exists
obj.test is truthy if obj.test exists and has a truthy value.
HellzHero
@HellzHero
Apr 12 2016 12:18
function palindrome(str) {
  var alpha = str.replace(/\W|_/g,""); // remove non-alphanumeric
    var lowerCase = alpha.toLowerCase(); //  turn to lower case
      var arr = lowerCase.split(""); // split characters in array
    for (var i = 0; i < arr.length; i++) {    
            if (arr[i] === arr[arr.length - i - 1]) {
              return true;
            } else {
              return false;
            }
          }

  return arr;
}



palindrome("almostomla");
Still getting wrong result on one of the tests, but getting green on all other, any ideias why?
Blauelf
@Blauelf
Apr 12 2016 12:18
If you consider a falsy value as non-existant property (if all valid values are objects, for example, which are always truthy, and a value of null might initially exist), obj.test would be the way to go. Depends on your application. (Been raised in more static programming languages, I still find those silent fails of Javascript somewhat disturbing)
@HellzHero Don't return true inside that loop. Move that to below the loop (where that odd return arr; is). And no need to split(""), you could work on lowerCase instead of arr without changing anything (other than moving return true; out).
HellzHero
@HellzHero
Apr 12 2016 12:21
@Blauelf i used split to put all the letters in an array, to be able to compare them with: if (arr[i] === arr[arr.length - i - 1])
Blauelf
@Blauelf
Apr 12 2016 12:22
@HellzHero You can also use if (lowerCase[i] === lowerCase[lowerCase.length - i - 1]) :P
HellzHero
@HellzHero
Apr 12 2016 12:22
@Blauelf ow, that does look simpler
Blauelf
@Blauelf
Apr 12 2016 12:23
It does not, as "lowerCase" is longer than "arr", but you get the idea. (also, you might want to use !== to switch the paths and remove the now empty else-path)
HellzHero
@HellzHero
Apr 12 2016 12:25
@Blauelf Yes, i got the ideia
Thank you!
Keith Coffel
@kinslay3r
Apr 12 2016 12:26
Hello all.
ALMY91
@ALMY91
Apr 12 2016 12:27
// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
  var lookup (val)= {
  "alpha": "Adams",
  "bravo": "Boston",
  "charlie":"Chicago",
  "delta": "Denver",
   "echo": "Easy",
   "foxtrot":"Frank"
  };

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

// Change this value to test
phoneticLookup("charlie");
whats wrong with my code guys
HellzHero
@HellzHero
Apr 12 2016 12:28
This message was deleted
CamperBot
@camperbot
Apr 12 2016 12:28
hellzhero sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1587 | @blauelf | http://www.freecodecamp.com/blauelf
eduaupin
@eduaupin
Apr 12 2016 12:30
can someone help me with the Counting Cards? i dont know how to start code D:
Ed
@sdet-ro
Apr 12 2016 12:32
@eduaupin what do you got so far?
vetoCode
@vetoCode
Apr 12 2016 12:33
why my if and my else statement fires the same time?!
http://codepen.io/vetoCode/pen/GZQEgp?editors=0010
ALMY91
@ALMY91
Apr 12 2016 12:33
heeelp
karim khalfaoui
@Kaiiim
Apr 12 2016 12:34
hi all
eduaupin
@eduaupin
Apr 12 2016 12:34
@1greenapplee will call you private!
karim khalfaoui
@Kaiiim
Apr 12 2016 12:35
someone can help me i am trying to do the Check for Palindromes
vetoCode
@vetoCode
Apr 12 2016 12:35
@ALMY91 you have to try a siwtch statement
switch(val){
case "" charlie":
return "something"
Alex
@rootisenabled
Apr 12 2016 12:37
help Seek and Destroy
CamperBot
@camperbot
Apr 12 2016 12:37

:point_right: algorithm seek and destroy [wiki]

Explanation:

This problem is a bit tricky because you have to familiarize yourself with Arguments, as you will have to work with two or more but on the script you only see two. Many people hardcode this program for three arguments. You will remove any number from the first argument that is the same as any other other arguments.

:pencil: read more about algorithm seek and destroy on the FCC Wiki

vetoCode
@vetoCode
Apr 12 2016 12:38

again:

switch(val){
case "alpha":
result = "Adams"

karim khalfaoui
@Kaiiim
Apr 12 2016 12:38
how can i to copy my code here ?
Islam Ibakaev
@dagman
Apr 12 2016 12:38
@Kaiiim