These are chat archives for FreeCodeCamp/HelpJavaScript

15th
Jul 2016
llamatarianism
@llamatarianism
Jul 15 2016 00:00
@Mozar10 the array ["foo", "bar", "baz"] is like this object: {0: "foo", 1: "bar", 2: "baz"}`
{0: "foo", 1: "bar", 2: "baz"}
Mo Zargham
@Mozar10
Jul 15 2016 00:00
@llamatarianism rightttt
Kevin Murphy
@kaym0
Jul 15 2016 00:00
Okay, can somebody answer this? Why do I need both of these box2.value = romanized;
$("#box2").return(romanized);
Why do I need both of these? box2.value = romanized;
$("#box2").return(romanized);
Jaren Escueta
@jarenescueta731
Jul 15 2016 00:00
@adampinsky which case?
bitgrower
@bitgrower
Jul 15 2016 00:00
excellent job @DrWhodaFuq -- now you just have to look at the value of count to determine what message to send ... easy ... :) You've done the hard part already ... :)
Adam Pinsky
@adampinsky
Jul 15 2016 00:01
the "<>" case
it will replace one but not the other
llamatarianism
@llamatarianism
Jul 15 2016 00:01
@Mozar10 you access properties of an object the same way you access items in an array
so you access properties of a nested object the same way you access items in a nested array
Mo Zargham
@Mozar10
Jul 15 2016 00:02
@llamatarianism let me let that detonate in my brain for a sec hold on
Adam Pinsky
@adampinsky
Jul 15 2016 00:02
@jarenescueta731 it's returning &lt;> for "<>"
llamatarianism
@llamatarianism
Jul 15 2016 00:02
in these two cases x = [["foo"]] and x = {0: {0: "foo"}}, you would access "foo" in the exact same way: x[0][0]
Jaren Escueta
@jarenescueta731
Jul 15 2016 00:02
@adampinsky i guessed that i'm in jsbin now
Dolan
@dguh
Jul 15 2016 00:03
could someone help me with my code for wherefore art thou? im passing the first 2 tests but not the last 2
mrscouture
@mrscouture
Jul 15 2016 00:03
@KhriztianG I did. Where are you stuck?
Mo Zargham
@Mozar10
Jul 15 2016 00:04
@llamatarianism wow ok i never looked at it that way
riggggght
ok @llamatarianism cause when you do x[0][0] you're accessing the object x which has the property 0 which is also an object that has the property 0 ?
llamatarianism
@llamatarianism
Jul 15 2016 00:06
correct
Mo Zargham
@Mozar10
Jul 15 2016 00:06
@llamatarianism dude
@llamatarianism thank you
CamperBot
@camperbot
Jul 15 2016 00:06
mozar10 sends brownie points to @llamatarianism :sparkles: :thumbsup: :sparkles:
:cookie: 977 | @llamatarianism |http://www.freecodecamp.com/llamatarianism
llamatarianism
@llamatarianism
Jul 15 2016 00:06
no problem :+1:
Dolan
@dguh
Jul 15 2016 00:08
@dguh
heres my code
function whatIsInAName(collection, source) {

  var arr = [];

  var sourceKey = Object.keys(source);

  for (i=0;i<collection.length;i++){
    for (j=0;j<sourceKey.length;j++){
        if (collection[i][sourceKey]==source[sourceKey[j]]){
          arr.push(collection[i]);  
      }//if
    }//for j  
  }//for i
  return arr;
}//whatIsInAName
whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 });
llamatarianism
@llamatarianism
Jul 15 2016 00:09
anyway @bitgrower , whereas map isn't actually implemented in terms of reduce, arrays are quite literally objects with numeric keys
if JS identifiers could start with numbers, you could do arr.0
for..in iterates through the keys of an object. when used on an array, it iterates through its indices.
bitgrower
@bitgrower
Jul 15 2016 00:10
hmm ... okay ... guess I followed the wrong experts wrt array.reduce & array.map ... whatevs
Chris
@KhriztianG
Jul 15 2016 00:10
@mrscouture I gave all my cases the values asked for but the console doesn't read it and they are not checked off
Mo Zargham
@Mozar10
Jul 15 2016 00:11
@llamatarianism ill never look at arrays the same again
mrscouture
@mrscouture
Jul 15 2016 00:12
@KhriztianG Are you getting a specific error message? I got stuck tying to figure what to switch (for the first line)..... switch(val)
Mo Zargham
@Mozar10
Jul 15 2016 00:14
@llamatarianism but one thing
no nvm youre right
Chris
@KhriztianG
Jul 15 2016 00:15
no error but caseinswitch(1-4) aren't checked @mrscouture
'''
CamperBot
@camperbot
Jul 15 2016 00:15
:bulb: to format code use backticks! ``` more info
mrscouture
@mrscouture
Jul 15 2016 00:16
@KhriztianG can you post your code?
Chris
@KhriztianG
Jul 15 2016 00:19
idk how its not letting me @mrscouture
Mo Zargham
@Mozar10
Jul 15 2016 00:20
@KhriztianG what did you assign the result val?
mrscouture
@mrscouture
Jul 15 2016 00:20

@KhriztianG Here is mine that worked:

switch (val) {
case 1:
answer ="alpha";
break;
case 2:
answer ="beta";
break;
case 3:
answer="gamma";
break;
case 4:
answer="delta";
break;
}

Mo Zargham
@Mozar10
Jul 15 2016 00:21
@mrscouture you don't need a break after last case answer
Joshua Minchew
@jminchew97
Jul 15 2016 00:22
Cane somebody please help me out with the Golf Code project
I don't understand golf
Jaren Escueta
@jarenescueta731
Jul 15 2016 00:22
@adampinsky i haven't figured out why yet, but have you noticed if you put any character before '>' in a string of two letters, like "h>", it also doesn't work
Chris
@KhriztianG
Jul 15 2016 00:23
@mrscouture thanks for the help. my problem was i put (answer) instead of (var) and case.log instead of answer
CamperBot
@camperbot
Jul 15 2016 00:23
khriztiang sends brownie points to @mrscouture :sparkles: :thumbsup: :sparkles:
:cookie: 213 | @mrscouture |http://www.freecodecamp.com/mrscouture
Jaren Escueta
@jarenescueta731
Jul 15 2016 00:27
@adampinsky still there? i think i got it
@adampinsky i'll pm you
Norvin Burrus
@ndburrus
Jul 15 2016 00:34
@jminchew97 can you post your code so far?
Alex N.
@N0bl3
Jul 15 2016 00:36
@jminchew97 maybe you should try tennis then ;)
zealsham
@zealsham
Jul 15 2016 00:38
some one review this code for the longes word in a string problem
function findLongestWord(str){
    array=str.split(" ");//turns the string to an array
    arrayLength=array.length;//returns the length of the array
    newArray=[];
    for(var i=0; i<arrayLength; i++){
        var newItems=array[i].length;//shows the length of every item in array
        newArray.push(newItems);//pushes every item into this new aRRAY
    }
    longestString=Math.max.apply(Math,newArray);//prints out the highest value in the array
    return longestString;
}
Adam Pinsky
@adampinsky
Jul 15 2016 00:39
@jarenescueta731 thank you
CamperBot
@camperbot
Jul 15 2016 00:39
:cookie: 317 | @jarenescueta731 |http://www.freecodecamp.com/jarenescueta731
adampinsky sends brownie points to @jarenescueta731 :sparkles: :thumbsup: :sparkles:
Jaren Escueta
@jarenescueta731
Jul 15 2016 00:40
@adampinsky thank you!
CamperBot
@camperbot
Jul 15 2016 00:40
jarenescueta731 sends brownie points to @adampinsky :sparkles: :thumbsup: :sparkles:
:cookie: 397 | @adampinsky |http://www.freecodecamp.com/adampinsky
Jaren Escueta
@jarenescueta731
Jul 15 2016 00:44
@zealsham when you use Math.max.apply on an array, you need to put null as the first parameter, not Math
llamatarianism
@llamatarianism
Jul 15 2016 00:47
@jarenescueta731 nope
the first argument is what's used as this inside the function call
Norvin Burrus
@ndburrus
Jul 15 2016 00:47
@zealsham would it be simpler to: :sparkles:
  • determine the length of each word (string)
  • compare the current iterated word length to a variable
  • retain the longest length
  • return longest length
llamatarianism
@llamatarianism
Jul 15 2016 00:48
since max is a method of Math
Math is what you're supposed to use as the this argument
Jaren Escueta
@jarenescueta731
Jul 15 2016 00:49
llamatarianism
@llamatarianism
Jul 15 2016 00:51
in the case of Math methods it doesn't matter
because they don't use this
but it does matter for many methods of arrays and strings and whatnot
Jaren Escueta
@jarenescueta731
Jul 15 2016 00:51
yup
Jonathan Leon
@Wo1v3r
Jul 15 2016 01:06
What am I doing wrong with geolocation: ?
$(document).ready(function() {
      var weatherObj, lat, lon;
      navigator.geolocation.getCurrentPosition(locationSuccess,locationFailure);

    });

function locationSuccess(position){
 var long= position.coord.longitude;
  var lat = position.coord.latitude;

  console.log(long + ' ' + lat);
}

function locationFailure(error){
  console.log('Error: ' + error.code + ' ' + error.message);
}
I get this error on the failure console.log :
Error: 1 Only secure origins are allowed (see: https://goo.gl/Y0ZkNV).
Ralph Nahra
@Rallph
Jul 15 2016 01:09
Hey guys I'm doing the challenge with the JSON record collection but I can't add if statements in the function. Not sure how else to do it
branndonm1
@branndonm1
Jul 15 2016 01:11
hey ralph
im also stuck on that one lol
llamatarianism
@llamatarianism
Jul 15 2016 01:12
@Wo1v3r geolocation only works over HTTPS now
codepen uses HTTP
Archangelpak
@Archangelpak
Jul 15 2016 01:12
guys can you please help me with this code ```
function testLogicalAnd(val) {
  // Only change code below this line

  if (val <     50) {
    if(val > 25) {


    }
    if (val > 50 && val < 25) {
      return "Yes";
    }
  }

  // Only change code above this line
  return "No";
}

// Change this value to test
testLogicalAnd(10);
llamatarianism
@llamatarianism
Jul 15 2016 01:13
use some other way of getting people's location
like an API
@Archangelpak it's impossible for a number to be greater than 50 and also less than 50
Mo Zargham
@Mozar10
Jul 15 2016 01:15
function updateRecords(id, prop, value) {
 if(prop!== "tracks" && value !== ""){
   collection[id][prop] = value;
  } 
  else if(prop === "tracks" && id.hasOwnProperty("tracks") === false){
   collection[id][prop] =[value];
  }
  else if(prop === "tracks" && value !== ""){
    collection[id][prop].push(value);
  }
  else if(value === ""){
    delete collection[id][prop];
  }
  return collection;
}
llamatarianism
@llamatarianism
Jul 15 2016 01:15
it's also impossible for a number to be greater than 50 and less than 25
Mo Zargham
@Mozar10
Jul 15 2016 01:15
@llamatarianism this is the closest im getting
llamatarianism
@llamatarianism
Jul 15 2016 01:16
id.hasOwnProperty("tracks")
id is just a number
Archangelpak
@Archangelpak
Jul 15 2016 01:16

@llamatarianism function testLogicalAnd(val) {
// Only change code below this line

if (val < 50) {
if(val > 25) {

}
if (val > 50 && val < 25) {
  return "Yes";
}

}

// Only change code above this line
return "No";
}

// Change this value to test
testLogicalAnd(10);

llamatarianism
@llamatarianism
Jul 15 2016 01:16
you mean collection[id]
Mo Zargham
@Mozar10
Jul 15 2016 01:17
@llamatarianism WOW that took so F*ing long
but DONE!
@llamatarianism thanks
CamperBot
@camperbot
Jul 15 2016 01:17
mozar10 sends brownie points to @llamatarianism :sparkles: :thumbsup: :sparkles:
:cookie: 978 | @llamatarianism |http://www.freecodecamp.com/llamatarianism
Archangelpak
@Archangelpak
Jul 15 2016 01:18
@llamatarianism but I was experimenting with operators and it also said that you should have only one if statement
Andrew
@westhofa
Jul 15 2016 01:18
function myLocalScope() {
  'use strict';

  var myVar = "Fun!"; 


  console.log(myVar);
}
myLocalScope();

// Run and check the console
// myVar is not defined outside of myLocalScope
console.log(myVar);

// Now remove the console log line to pass the test
idk what the challenge is asking for after this
Archangelpak
@Archangelpak
Jul 15 2016 01:19
I changed my code
function testLogicalAnd(val) {
  // Only change code below this line

  if (val <     50) {
    if(val > 25) {


    }
    if (val < 50 && val > 25) {
      return "Yes";
    }
  }

  // Only change code above this line
  return "No";
}

// Change this value to test
testLogicalAnd(10);
branndonm1
@branndonm1
Jul 15 2016 01:20
is there a bug here?

function updateRecords(id, prop, value) {

return collection.id;
}

// Alter values below to test your code
updateRecords(2548, "album", "ABBA");

collection is an object
should only return one element in the object but returns the whole thing
ariefrs
@ariefrs
Jul 15 2016 01:22
Can anyone help me ?
VED
@alexisved
Jul 15 2016 01:23
Can anyone teach me how to post code on the message?
Stephen James
@sjames1958gm
Jul 15 2016 01:23
@branndonm1 id is a variable so collection.id should return undefined.
help format
CamperBot
@camperbot
Jul 15 2016 01:23

: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 thecode`.

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

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

Stephen James
@sjames1958gm
Jul 15 2016 01:23
@alexisved :point_up:
VED
@alexisved
Jul 15 2016 01:23
@sjames1958gm Thanks:)
CamperBot
@camperbot
Jul 15 2016 01:23
alexisved sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1864 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jul 15 2016 01:24
@westhofa You are supposed to notice the error in the little window that myVar is not accessible by the bottom console.log.
Now remove that console.log and it will pass
VED
@alexisved
Jul 15 2016 01:24
function destroyer(arr) {
  // Remove all the values

  return arguments[0].filter(function(val){  
    for(var i = 1;i< arguments.length;i++){
        if(arguments[i]==val) return true;
        else return false;
      }
  });


}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
hum... fail...
lol
Stephen James
@sjames1958gm
Jul 15 2016 01:25
@alexisved three back quotes when multiple lines
Subramanya Chakravarthy
@chakrihacker
Jul 15 2016 01:25
@alexisved read how boolean works
You will find answer easily
Apply boolean to filter that's it
VED
@alexisved
Jul 15 2016 01:26
@sjames1958gm thanks again~
CamperBot
@camperbot
Jul 15 2016 01:26
alexisved sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: alexisved already gave sjames1958gm points
Stephen James
@sjames1958gm
Jul 15 2016 01:26
@alexisved Each function has its own arguments object, so you cannot access the outer functions arguments that way.
you will need to convert to an array first
@alexisved :+1:
@alexisved There is a little menu to the right where the three dots are and you can edit that post to change them
VED
@alexisved
Jul 15 2016 01:27
wow!
I got it.
Keep debuging my code
thanks guys
:)
you are all very kind :)
function destroyer(arr) {
  // Remove all the values
  var target = Array.from(arguments[0]);

  return target.filter(function(val){  
    for(var i = 1;i< arguments.length;i++){
        return arguments[i]==val;
      }
  });


}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
I still don't get it...
why i always got a null array for return
:(
Stephen James
@sjames1958gm
Jul 15 2016 01:35
This message was deleted
Oops
VED
@alexisved
Jul 15 2016 01:36
you mean don't use arguments in the for loop right?
Stephen James
@sjames1958gm
Jul 15 2016 01:37
@alexisved You need an array for arguments[1..n] because arguments in the filter function is not the same as arguments for destroyer function
Joseph
@revisualize
Jul 15 2016 01:37
@MohammadHasham return str.substr(-target.length) === target;
Norvin Burrus
@ndburrus
Jul 15 2016 01:37
@alexisved :sparkles:
using Shift + enter will give you additional line feeds (space) for pasting your code. also, the backticks (`) key is located to the left of the number one (#1) key.
further, you may find the two buttons (chat/compose & markdown - the chat/compose button alternates modes) to the right of the text entry area helpful.
VED
@alexisved
Jul 15 2016 01:38
My god! I got it this time!
Joseph
@revisualize
Jul 15 2016 01:38
@alexisved
function destroyer(arr) { 
    var remove = Array.prototype.slice.call(arguments, 1);
    return arr.filter(v => remove.indexOf(v) === -1);
}
Norvin Burrus
@ndburrus
Jul 15 2016 01:38
@ariefrs post your query in the room! :smile:
Masana
@Masana84
Jul 15 2016 01:38
having some trouble with exercise 151... anyone help?
Norvin Burrus
@ndburrus
Jul 15 2016 01:38
@Masana84 lesson name?
Masana
@Masana84
Jul 15 2016 01:39
really appreciate
Quoting Strings with Single Quotes
VED
@alexisved
Jul 15 2016 01:39
the argument in the function is not the argument in the destoryFunction
Norvin Burrus
@ndburrus
Jul 15 2016 01:39
@Masana84 can you post your code so far?
Stephen James
@sjames1958gm
Jul 15 2016 01:39
@alexisved The arguments object, yes
Joseph
@revisualize
Jul 15 2016 01:40
@alexisved arguments is an object scoped to every function.
Stephen James
@sjames1958gm
Jul 15 2016 01:40
@Masana84 BTW challenges don't have numbers, the number 151 is your progress number.
VED
@alexisved
Jul 15 2016 01:40
how can I make this kind of mistake XD
Masana
@Masana84
Jul 15 2016 01:40
sorry guys
the lesson is Quoting Strings with Single Quotes
VED
@alexisved
Jul 15 2016 01:40
@sjames1958gm thanks again:)
CamperBot
@camperbot
Jul 15 2016 01:40
alexisved sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: alexisved already gave sjames1958gm points
Stephen James
@sjames1958gm
Jul 15 2016 01:41
@Masana84 Do you have any code so far to show?
Masana
@Masana84
Jul 15 2016 01:41
yes
var myStr = '<a href= "http://www.example.com" target="_blank">Link</a>';
Stephen James
@sjames1958gm
Jul 15 2016 01:43
@Masana84 That looks correct, try refreshing the browser
Masana
@Masana84
Jul 15 2016 01:43
I'll give a try tnkx
Stephen James
@sjames1958gm
Jul 15 2016 01:43
@Masana84 Wait
Masana
@Masana84
Jul 15 2016 01:43
ok
Stephen James
@sjames1958gm
Jul 15 2016 01:43
@Masana84 Looks like you inserted a space after first =
Joseph
@revisualize
Jul 15 2016 01:44
ef= "h
Archangelpak
@Archangelpak
Jul 15 2016 01:44
can anyone please help me with this code?
Joseph
@revisualize
Jul 15 2016 01:44
remove that space.
Masana
@Masana84
Jul 15 2016 01:44
wow! thats it
Archangelpak
@Archangelpak
Jul 15 2016 01:44
testLogicalAnd(30) should return "Yes"
testLogicalAnd(50) should return "Yes"
``
Masana
@Masana84
Jul 15 2016 01:45
Thanks a Lot!
Stephen James
@sjames1958gm
Jul 15 2016 01:45
@Masana84 :+1:
Archangelpak
@Archangelpak
Jul 15 2016 01:45

function testLogicalAnd(val) {
// Only change code below this line

if (val < 50 && val == 25) {

  return "Yes";

}

// Only change code above this line
return "No";
}

// Change this value to test
testLogicalAnd(10);

function testLogicalAnd(val) {
  // Only change code below this line

  if (val < 50 && val == 25)  {

      return "Yes";

  }

  // Only change code above this line
  return "No";
}

// Change this value to test
testLogicalAnd(10);
Joseph
@revisualize
Jul 15 2016 01:45
@Archangelpak Look at what you're doing.
Stephen James
@sjames1958gm
Jul 15 2016 01:46
@Archangelpak How would you read that if statement
Archangelpak
@Archangelpak
Jul 15 2016 01:46
@sjames1958gm ?
Stephen James
@sjames1958gm
Jul 15 2016 01:46
@Archangelpak From the instructions: if val is less than or equal to 50 and greater than or equal to 25
DC
@dctor
Jul 15 2016 01:47
I am stuck with symmetric difference algo here is my code i feel arr3 needs a reset for the next loop but nothing seems to be working...can someone give me a hint? thank you
function sym(args) {
var arr = [];
var arr2 = [];
var arr3 = [];
for (var i = 0; i < arguments.length; i++) {
        arr2 = arr.concat(arguments[i]).sort(function s(a,b) {return a-b;});
    for (var j = 0; j < arr2.length; j++) {
        if (arr.indexOf(arr2[j]) < 0 || arguments[i].indexOf(arr2[j]) < 0){
            arr3.push(arr2[j]);
         }
    }arr = arr3;
}console.log(arr3);
}
sym([1, 2, 3], [4, 2, 3], [3, 5, 4]);
Stephen James
@sjames1958gm
Jul 15 2016 01:47
@Archangelpak Read that code in English if val is less than 50 and . . .
Joseph
@revisualize
Jul 15 2016 01:47
if val is less than fifty and val is equal to twenty-five
Archangelpak
@Archangelpak
Jul 15 2016 01:49
@sjames1958gm thank you\
CamperBot
@camperbot
Jul 15 2016 01:49
archangelpak sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1865 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Joseph
@revisualize
Jul 15 2016 01:49
You're welcome.
Stephen James
@sjames1958gm
Jul 15 2016 01:49
@Archangelpak :+1:
Jaren Escueta
@jarenescueta731
Jul 15 2016 01:53
for those who have done the first advanced algo challenge (telephone numbers) is it just a bunch of regex matching and using substrings? it feels like you almost have to hardcode to satisfy the different cases
no one knows?
DC
@dctor
Jul 15 2016 01:56
@jarenescueta731 you can hardcode each case to solve this problem or to find more general regex that can cover more cases
Jaren Escueta
@jarenescueta731
Jul 15 2016 01:56
hardcoding feels like cheating
i will go the second way
feels less like cheating lol
Stephen James
@sjames1958gm
Jul 15 2016 02:00
@jarenescueta731 I ended up with 4 regexp - and hardcoding is cheating
Jaren Escueta
@jarenescueta731
Jul 15 2016 02:01
@dctor @sjames1958gm thanks, that's what i wanted to know. if there was an elegant solution possible
CamperBot
@camperbot
Jul 15 2016 02:01
jarenescueta731 sends brownie points to @dctor and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1866 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:cookie: 301 | @dctor |http://www.freecodecamp.com/dctor
anvarov
@anvarov
Jul 15 2016 02:03
hi
Jaren Escueta
@jarenescueta731
Jul 15 2016 02:04
help hi
CamperBot
@camperbot
Jul 15 2016 02:04

:point_right: algorithm everything be true [wiki]

Algorithm Everything Be True

:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program :busts_in_silhouette: and write your own code :pencil:

:checkered_flag: Problem 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.

Relevant Links

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

Ethan Choi
@ethanchoi812
Jul 15 2016 02:05

Hi all! Do you guys know the difference between
a:
function mutation(arr) {
var target = arr[0].toLowerCase();
var test= arr1.toLowerCase();
for (i=0; i<test.length; i++) {
if (target.indexOf(test[i]) < 0)
return false;
}
return true;}

and b:
function mutation(arr) {
var target = arr[0].toLowerCase();
var test= arr1.toLowerCase();
for (i=0; i<test.length; i++) {
if (target.indexOf(test[i]) < 0) {
return false;} else {return true;}
}
}

anvarov
@anvarov
Jul 15 2016 02:07
i get stuck at pig latin, firstly i should just add 'way' at the of the string, ok, it is solved, but if the string begins with one or more consonants i should slice this character and move it to the end of the string and add 'ay', there i hava a problem

function translatePigLatin(str) {
  var regexp = /^[AEIOU]/i;
  var regexpConsonants = /(^[^AEIOU]{1,})/i;
  if (regexp.test(str)) {
    return str + "way";
  } else if (regexpConsonants.test(str)) {
    return str.replace(regexpConsonants,  + 'ay');
  }


}

translatePigLatin("consonant");
ronaldrdguez
@ronaldrdguez
Jul 15 2016 02:10

@ethanchoi812 don’t see the difference. (also format with ```), incidentally when you have an expresssion like

if ( <predicate>) {
return true;
}
else {
return false;
}

you can pretty much just do return <predicate>

Ethan Choi
@ethanchoi812
Jul 15 2016 02:16
@ronaldrdguez thanks for the response! for the mutation challenge in basic algorithm answer b seems to be incorrect
CamperBot
@camperbot
Jul 15 2016 02:16
ethanchoi812 sends brownie points to @ronaldrdguez :sparkles: :thumbsup: :sparkles:
:cookie: 324 | @ronaldrdguez |http://www.freecodecamp.com/ronaldrdguez
ronaldrdguez
@ronaldrdguez
Jul 15 2016 02:20
@ethanchoi812 No WAIT! yes, b is wrong, you need to format your code. In a the return false is outside the for loop, in b it is not.
Use the backticks to get the indentation right and the black box.
help format
CamperBot
@camperbot
Jul 15 2016 02:21

: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 thecode`.

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

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

Stephen James
@sjames1958gm
Jul 15 2016 02:21
@ronaldrdguez You mean the return true is outside the loop
ronaldrdguez
@ronaldrdguez
Jul 15 2016 02:21
@sjames1958gm yes return true;
Stephen James
@sjames1958gm
Jul 15 2016 02:22
@ronaldrdguez I was thinking that was the case, but didn't see it - but the first one has an if without {} and that threw me off
Ethan Choi
@ethanchoi812
Jul 15 2016 02:30
ah i see now. thanks again!! @ronaldrdguez @sjames1958gm
CamperBot
@camperbot
Jul 15 2016 02:30
ethanchoi812 sends brownie points to @ronaldrdguez and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: ethanchoi812 already gave ronaldrdguez points
:star2: 1867 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Diego Mayer
@Chrono79
Jul 15 2016 02:32
@anvarov why don't you use a loop and move the consonants to the end of the string until a vowel is found and add ay at the end?
hjc
@stori1
Jul 15 2016 02:43

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
// Your code below this line

// Your code above this line
return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");

Diego Mayer
@Chrono79
Jul 15 2016 02:47
@stori1 Read mad libs link and review this challenge: https://www.freecodecamp.com/challenges/constructing-strings-with-variables
crisayala16
@crisayala16
Jul 15 2016 02:55
how does one use the push() method when trying to add a value to a specific property in a complex object?
Jennifer Estelle Bedford
@JenniferEstelle
Jul 15 2016 03:00
SOMEONE, please celebrate with me! My husband helped me solve the Profile lookup and I actually understand what's going on. I love loops * now.
Peter Weinberg
@no-stack-dub-sack
Jul 15 2016 03:00
finished my wiki viewer! would love any feedback or constructive criticism. Try a regular search and then type in "phish" for a little easter egg I programmed in - just for fun and a little added complexity. Thanks for all the help along the way!
http://codepen.io/no_stack_dub_sack/full/akLkZP/
Manish Giri
@Manish-Giri
Jul 15 2016 03:00
@JenniferEstelle congratulations!
Joseph
@revisualize
Jul 15 2016 03:00
@JenniferEstelle Grats.
about @JenniferEstelle
CamperBot
@camperbot
Jul 15 2016 03:00
:cookie: 220 | @jenniferestelle |http://www.freecodecamp.com/jenniferestelle
Jennifer Estelle Bedford
@JenniferEstelle
Jul 15 2016 03:01
I feel the love, people. Thanks! <3
Joseph
@revisualize
Jul 15 2016 03:01
@JenniferEstelle So how did you solve it?
Chad Hurley
@ChadDean82
Jul 15 2016 03:01
Hi Everybody I was wondering if Someone would be so kind as to help or tell Me this got all checked off but one of the challenge requirements. Please
Joseph
@revisualize
Jul 15 2016 03:02
Name of the lesson?
Chad Hurley
@ChadDean82
Jul 15 2016 03:03
function sequentialSizes(val) {
  var answer = "";
  // Only change code below this line
  switch (val) {
    case 1:
    case 2:
    case 3:
      answer = "Low";
      break;
    case 3:
      answer = "3 Low";
     break;

    case 4:
    case 5:
    case 6:
      answer = "Mid";
      break;
    case 6:
      answer = "6 Mid";
      break;

    case 7:
    case 8:
    case 9:
      answer = "High";
      break;
    case 9:
      answer = "9 High";
      break;
  }


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

// Change this value to test
sequentialSizes(1);
Jennifer Estelle Bedford
@JenniferEstelle
Jul 15 2016 03:03
@revisualize Well, after I asked him a billion questions (bit of an exaggeration, but he was super patient). Anyway, I wrote it all out in comments so I could refer back to it if I had a mental block in the future...
I want to loop through all the profiles aka: contacts[i]. In that loop, I want to create an if statement that will store the element in the array to the matchingContact variable if the firstNames match. A) If you find a match, break that loop (which we can do because we are only looking for one name and property, not multiple names...) and continue onto the next if statements (C & D). B) If the firstName's don't match, keep looping through the full length of the contacts until you reach the end of the list. Then break, and continue to step C & D. C) If there is no matching contact, return "No such contact." D) If there is no matching property, return "No such property" */
(I initialized a matching contact variable above the for loop)
crisayala16
@crisayala16
Jul 15 2016 03:05
collection[id][prop].push([value]);
Chad Hurley
@ChadDean82
Jul 15 2016 03:05
You should have nine case statements this is the only one that is keeping from passing the challenge
Joseph
@revisualize
Jul 15 2016 03:05
collection[id][prop].push(value);
Om Carrasquillo
@oc2215
Jul 15 2016 03:05
Stuck in the "Manipulating Complex Objects" exercise; trying to add an additional album to the myMusic array along with a nested array "formats"...It seems to follow the format required , and the output prints both albums; but only one-third of the items received a check mark... Can anyone point out if there are any errors with my code?

var myMusic = [
[{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}],

[{
"artist": "Fat Joe",
"title": "Relativity",
"release_year": 1997,
"formats": [
"CD",
"mp3",
"LP"
],
"gold": true
}]
];

crisayala16
@crisayala16
Jul 15 2016 03:06
can someone tell me if im using the push method correct here?
Jennifer Estelle Bedford
@JenniferEstelle
Jul 15 2016 03:06
This message was deleted
function lookUpProfile(firstName, prop){
/* Only change code below this line, I want to loop through all the profiles aka: contacts[i].  In that loop, I want to create an if statement that will store the element in the array to the matchingContact variable if the firstNames match.  A) If you find a match, break that loop (which we can do because we are only looking for one name and property, not multiple names...) and continue onto the next if statements (C & D).  B) If the firstName's don't match, keep looping through the full length of the contacts until you reach the end of the list.  Then break, and continue to step C & D.  C) If there is no matching contact, return "No such contact." D) If there is no matching property, return "No such property" */

  var matchingContact;


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

    if (firstName === contacts[i].firstName) {
        matchingContact = contacts[i];
        break;
    }
  }

  if (!matchingContact) {
        return "No such contact";
  } 

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

  return contacts[i][prop];

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Bob", "number");
llamatarianism
@llamatarianism
Jul 15 2016 03:08
@crisayala16 you're pushing an array containing value rather than just value
Wali Gauvin
@Docwali777
Jul 15 2016 03:08
I am close - where am I going wrong - GOLF COURSE
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!";}
llamatarianism
@llamatarianism
Jul 15 2016 03:08
so if the array used to be []
Pericles
@periman2
Jul 15 2016 03:08
@crisayala16 is that for the track's element ?
Lee
@leebut
Jul 15 2016 03:08
I've just completed the challenge, 'Selecting from many Options with Switch Statements'. I eventually worked out what to do, but the information in the challenge is so vague.
llamatarianism
@llamatarianism
Jul 15 2016 03:08
it will become [[value]]
Lee
@leebut
Jul 15 2016 03:09
@Docwali777 If par == # && strokes == #
I didn't use any +# operations
Pericles
@periman2
Jul 15 2016 03:11
@oc2215 you don't need to close with ] between the two albums
Peter Weinberg
@no-stack-dub-sack
Jul 15 2016 03:11
@Docwali777 the return strings need to be exactly the same as in the examples
Pericles
@periman2
Jul 15 2016 03:11
that's what's holding them together
Joseph
@revisualize
Jul 15 2016 03:12
@llamatarianism have a second?
Jennifer Estelle Bedford
@JenniferEstelle
Jul 15 2016 03:12
This message was deleted
Pericles
@periman2
Jul 15 2016 03:12
@oc2215 it should be "gold": true
},
{
"artist": "Fat Joe",
Wali Gauvin
@Docwali777
Jul 15 2016 03:13
@no-stack-dub-sack @leebut ----wow duh... So trivial yet so vital... I did not put the exact spelling..... Thanks..........
CamperBot
@camperbot
Jul 15 2016 03:13
docwali777 sends brownie points to @no-stack-dub-sack and @leebut :sparkles: :thumbsup: :sparkles:
:cookie: 201 | @leebut |http://www.freecodecamp.com/leebut
:cookie: 286 | @no-stack-dub-sack |http://www.freecodecamp.com/no-stack-dub-sack
Joseph
@revisualize
Jul 15 2016 03:14
@JenniferEstelle I PM'd you.
Peter Weinberg
@no-stack-dub-sack
Jul 15 2016 03:14
@Docwali777 did that do the trick?
it looks like there could be something else wrong too
oh, never mind, that should have worked, no?
Wali Gauvin
@Docwali777
Jul 15 2016 03:16
@no-stack-dub-sack - you got it..... That did it..!!!!!!!!!! I put "One" instead of -'one'.......
Peter Weinberg
@no-stack-dub-sack
Jul 15 2016 03:17
@Docwali777 nice, yeah I actually caught the exclamation point, I thought the code looked right though so I checked the spelling right away. I remember getting tripped up on stuff like that.
Diego Mayer
@Chrono79
Jul 15 2016 03:17
@oc2215 you've added inner arrays (you shouldn't), myMusic is an array containing objects like this [{},{}]
Lee
@leebut
Jul 15 2016 03:19
@Docwali777 Is it working now?
@Docwali777 What was your solution? I think there are different ways to pass these challenges.
Joseph
@revisualize
Jul 15 2016 03:24
@JenniferEstelle Did you see my PM?
dhuddleston
@dhuddleston
Jul 15 2016 03:45
This code works, but I was wondering if there was a way to change it so that I only have to call the replace function once, using one long regular expression.
function palindrome(str) {

  // Get rid of all capitalization and punctuation marks, etc. This is done by using Regex commands.
  str = str.toLowerCase();

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

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

  str = str.replace(/\:/g,'');

  str = str.replace(/\-/g,'');

  str = str.replace(/\_/g,'');

  str = str.replace(/\(|\)/g,'');

  str = str.replace(/\s+/g, '');

  // Split the string everywhere where there is an empty space in the string, then reverse the string and rejoin it
  // Check to see if the real string matches, if so, it is a palindrome.
  if(str === (str.split('').reverse().join('')))
    {
      return true;
    }
  else
    {
      return false;
    }
}

palindrome("A man, a plan, a canal. Panama");
llamatarianism
@llamatarianism
Jul 15 2016 03:47
@dhuddleston /\W|_/g
matches anything that's not a letter or number
also
dhuddleston
@dhuddleston
Jul 15 2016 03:47
@llamatarianism Woah. I can't believe I didn't know about that one. Thanks!
CamperBot
@camperbot
Jul 15 2016 03:47
dhuddleston sends brownie points to @llamatarianism :sparkles: :thumbsup: :sparkles:
:cookie: 980 | @llamatarianism |http://www.freecodecamp.com/llamatarianism
llamatarianism
@llamatarianism
Jul 15 2016 03:48
if (condition) return true; else return false; is the same as
return condition;
dhuddleston
@dhuddleston
Jul 15 2016 03:48
@llamatarianism Ah, that's another nice way to simplify it down. Thanks!
CamperBot
@camperbot
Jul 15 2016 03:48
dhuddleston sends brownie points to @llamatarianism :sparkles: :thumbsup: :sparkles:
:warning: dhuddleston already gave llamatarianism points
Subramanya Chakravarthy
@chakrihacker
Jul 15 2016 04:00
@dhuddleston read more about regular expressions you will find many ways
Aiden
@AidenMead
Jul 15 2016 04:00
Hey everyone!
I'm having and issue with using objects for lookups, I've been working on it and trying to research lookup tables to figure it out, but nothing I try seems be working.
Subramanya Chakravarthy
@chakrihacker
Jul 15 2016 04:01
@AidenMead where did you find difficulty
Aiden
@AidenMead
Jul 15 2016 04:02
So it has you convert the switch statement to a lookup table, and I follow the example to the left above the instructions, but when I run the test, I get no output. I'm just having a had time figure out where I went wrong.
dhuddleston
@dhuddleston
Jul 15 2016 04:03
@chakrihacker That's a good recommendation, thanks! I keep putting it off but it looks like it's very beneficial regardless of which programming language is used. I've finished all the Algorithm challenges but I'm going back and redoing some of them to find better ways of solving problems.
CamperBot
@camperbot
Jul 15 2016 04:03
dhuddleston sends brownie points to @chakrihacker :sparkles: :thumbsup: :sparkles:
:cookie: 273 | @chakrihacker |http://www.freecodecamp.com/chakrihacker
Aiden
@AidenMead
Jul 15 2016 04:04
Screen Shot 2016-07-15 at 12.03.16 AM.png
Subramanya Chakravarthy
@chakrihacker
Jul 15 2016 04:05
@AidenMead
seethe result is not altered
try result = lookup[val]
dhuddleston
@dhuddleston
Jul 15 2016 04:05
@AidenMead If you want to post that code directly into Gitter, here's an article on how to format the code: https://github.com/freecodecamp/freecodecamp/wiki/code-formatting
Brian
@Brian984
Jul 15 2016 04:06
Can someone tell me what double exclamation marks in front of a value is used for?
Aiden
@AidenMead
Jul 15 2016 04:06
thanks @dhuddleston , i was wondering how to do that!
CamperBot
@camperbot
Jul 15 2016 04:06
aidenmead sends brownie points to @dhuddleston :sparkles: :thumbsup: :sparkles:
:cookie: 348 | @dhuddleston |http://www.freecodecamp.com/dhuddleston
Aiden
@AidenMead
Jul 15 2016 04:07
also, thanks @chakrihacker , i'll give that a go. I was thinking I wasn't supposed to edit the result declaration.
CamperBot
@camperbot
Jul 15 2016 04:07
aidenmead sends brownie points to @chakrihacker :sparkles: :thumbsup: :sparkles:
:cookie: 274 | @chakrihacker |http://www.freecodecamp.com/chakrihacker
Subramanya Chakravarthy
@chakrihacker
Jul 15 2016 04:09
@AidenMead you have to edit the result you can do it any way but the return should result answer
Aiden
@AidenMead
Jul 15 2016 04:10
@chakrihacker thanks, that worked!
CamperBot
@camperbot
Jul 15 2016 04:10
aidenmead sends brownie points to @chakrihacker :sparkles: :thumbsup: :sparkles:
:warning: aidenmead already gave chakrihacker points
Aiden
@AidenMead
Jul 15 2016 04:11
I'm also a bit fuzzy on the reasoning behind the line " var result = ""; "
I've seen that in a lot of the functions and example code, but don't understand the reasoning there, and when it would be applicable to add it in.
(I'm having a rough time with this Javascript section)
dhuddleston
@dhuddleston
Jul 15 2016 04:12
@Brian984 Essentially it's using the ! operator twice. It's kind of like checking for a double negative. For example...
function test(str) {

  // Using the ! operator twice
  if(!!str)
  {
    console.log("The variable contains something!");
  }

  // Setting the string to null to demonstrate the ! operator by itself
  str = null;

  if(!str)
  {
    console.log("The variable contains nothing!");
  }

}



test("Test");
I've seen people put it in brackets before to prevent confusion:
  if(!(!str))
  {
    console.log("The variable contains something!");
  }
Chris Rutherford
@cjrutherford
Jul 15 2016 04:19
okay, so after the intermediate projects, I seem to have forgotten what to do with the algorithms.... "Diff Two Arrays"?
MT
@tnhminh
Jul 15 2016 04:26
Please give me an article about ===, !==, ... etc in jquery or java script ? Thanks
I'm a new member
Ngoc Tu
@htmyheart
Jul 15 2016 04:28
@tnhminh nó là phép so sánh trong js
== là so sánh bằng
về giá trị
còn === là so sánh bằng về cả giá trị lẫn kiểu dữ liệu
Wali Gauvin
@Docwali777
Jul 15 2016 04:29
This is suppsed to be an easy one--what am I missing???
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch (val) {
          1: "alpha";
        break;
      2 : "beta";
        break;
        3: "gamma";
        break;
        4: "delta";
    }


  // Only change code above this line  
  return answer;  
}
Magnus Holm
@mghlm
Jul 15 2016 04:33
Can someone help me understand this: "If compareFunction is supplied, the array elements are sorted according to the return value of the compare function. If a and b are two elements being compared, then:"
in this case, how do I know if it returns -1, 0 or 1 ???
var array = [1, 12, 21, 2];
array.sort(function(a, b) {
  return a - b;
});
Wali Gauvin
@Docwali777
Jul 15 2016 04:36
@leebut it worked.- spelling errors....
Roger K.
@misterhtmlcss
Jul 15 2016 04:38
Hi can someone reexplain to me "Stand in Line"
Lee
@leebut
Jul 15 2016 04:38
@Docwali777 you are missing 'case'.
Roger K.
@misterhtmlcss
Jul 15 2016 04:38
I have no idea what it's asking. Like so much of FCC I'm just overly frustrated by not understanding the questions themselves, nevermind sorting out a solution
:(
Lee
@leebut
Jul 15 2016 04:39
@misterhtmlcss I spent hours on that thing. the instructions are truly awful.
Roger K.
@misterhtmlcss
Jul 15 2016 04:40
yes!! They are :(
Aiden
@AidenMead
Jul 15 2016 04:41
Agreed, it took me a good amount of time, I did a ton of googling before finally getting back and breaking down the question. I ended up looking at it one piece at a time and finally worked through it (very slowly and painfully for me)
Roger K.
@misterhtmlcss
Jul 15 2016 04:43
Got it. Thanks!
Kalyan_Ar
@Kalyan-Ar
Jul 15 2016 04:44
hi everyone
need help with css
Gerard Jorgensen
@gerardjorgensen
Jul 15 2016 04:44
Hey guys I'm working on the wikipedia challenge, but I can't seem to get the information I need from wikipeidia can anyone help?
Here is my codepen: http://codepen.io/GerardJ/pen/rLMXov?editors=0001
Nelya
@NankaBananka
Jul 15 2016 04:50
find Record Collection
CamperBot
@camperbot
Jul 15 2016 04:50

find record collection

:zero: challenge record collection

DJ
@qualitymanifest
Jul 15 2016 04:50
@gerardjorgensen add &callback=? onto the end of your temp2 url
Aiden
@AidenMead
Jul 15 2016 04:50
@Kalyan-Ar what's going on with CSS?
Brian
@Brian984
Jul 15 2016 04:51
@dhuddleston Thanks!
CamperBot
@camperbot
Jul 15 2016 04:51
brian984 sends brownie points to @dhuddleston :sparkles: :thumbsup: :sparkles:
:cookie: 349 | @dhuddleston |http://www.freecodecamp.com/dhuddleston
DJ
@qualitymanifest
Jul 15 2016 04:51
@GregatGit figuring out how to use the wikipedia API is the main point of that challenge IMHO...
Greg Duncan
@GregatGit
Jul 15 2016 04:54
@qualitymanifest no its not -
Gerard Jorgensen
@gerardjorgensen
Jul 15 2016 04:55
@qualitymanifest @qualitymanifest Thank you so much I'll work on it!
CamperBot
@camperbot
Jul 15 2016 04:55
gerardjorgensen sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star2: 1271 | @qualitymanifest |http://www.freecodecamp.com/qualitymanifest
Aiden
@AidenMead
Jul 15 2016 04:55
Anyone remember "Testing Object fro Properties"? I can successfully return the proper true properties, but my false won't return what I tell it to
Nelya
@NankaBananka
Jul 15 2016 04:55
@misterhtmlcss hey, you need to use push and shift here
Gerard Jorgensen
@gerardjorgensen
Jul 15 2016 04:55
@qualitymanifest Thank you
CamperBot
@camperbot
Jul 15 2016 04:55
gerardjorgensen sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:warning: gerardjorgensen already gave qualitymanifest points
Aiden
@AidenMead
Jul 15 2016 04:56
Got it, nevermind
Chad Hurley
@ChadDean82
Jul 15 2016 05:00
quick question should "challenge Counting Cards" have 29 case's? Any help would be greatly appreciated.
Enrique Alejandro Arzamendi Picazzo
@AleCx4
Jul 15 2016 05:02
hi everyone!
DJ
@qualitymanifest
Jul 15 2016 05:03
@ChadDean82 you can use just a if/else if
Nelya
@NankaBananka
Jul 15 2016 05:03
@ChadDean82 no necessarily
DJ
@qualitymanifest
Jul 15 2016 05:03
@ChadDean82 since one set of cards is +1 , another set is -1, another set makes no difference (so do nothing)
Nelya
@NankaBananka
Jul 15 2016 05:03
@ChadDean82 in some cases you don’t need to change the var count
Lee
@leebut
Jul 15 2016 05:04
Just finished 'Return Early Pattern for Functions, but I'm not convinced my solution satisfies the instructions, (Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined). I tried an if statement: fi (a || b < 0) {return undefined;}, but that didn't work. So how can switches be used to return undefined for ANY value less than 0?
// Setup
function abTest(a, b) {
  // Only change code below this line
  switch (a){
    case (-2):
      return undefined;
    }    
  switch (b){
    case (-2):
      return undefined;
  }

  // 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);
Chad Hurley
@ChadDean82
Jul 15 2016 05:04
@qualitymanifest thank You
CamperBot
@camperbot
Jul 15 2016 05:04
chaddean82 sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star2: 1272 | @qualitymanifest |http://www.freecodecamp.com/qualitymanifest
Chad Hurley
@ChadDean82
Jul 15 2016 05:05
@NankaBananka thank You
CamperBot
@camperbot
Jul 15 2016 05:05
chaddean82 sends brownie points to @nankabananka :sparkles: :thumbsup: :sparkles:
:cookie: 211 | @nankabananka |http://www.freecodecamp.com/nankabananka
DJ
@qualitymanifest
Jul 15 2016 05:06
@leebut or (||) doesn't quite work like that. you need to tell it what you want on both sides. (a<0 || b<0)
Andy Zhang
@ialmost
Jul 15 2016 05:07
Check for Palindromes
DJ
@qualitymanifest
Jul 15 2016 05:07
so (this === something || that === something) not (this || that === something)
Chad Hurley
@ChadDean82
Jul 15 2016 05:07
I thought I di a bunch of unnecessary coding. Thank Yall again.
Susannah Skyer Gupta
@SuzGupta
Jul 15 2016 05:08
Ack, help! I'm somewhat stuck on the Record Collection challenge (aside: this chat UI is driving me nuts, with stuff sliding out ... is there a Slack for fcc instead?) anyhow: how to I print to the console the contents of my JSON object so I can see if this is going as I expect? TIA.
Lee
@leebut
Jul 15 2016 05:09
@qualitymanifest Thank you. I forgot all about balancing the condition. However, the weird thing is, the solution I posted passed the challenge. How can it, if it doesn't do what is instructed? I think these challenges have problems, as I would have taken my solution as good code, but it doesn't work.
CamperBot
@camperbot
Jul 15 2016 05:09
leebut sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star2: 1273 | @qualitymanifest |http://www.freecodecamp.com/qualitymanifest
Greg Duncan
@GregatGit
Jul 15 2016 05:09
@SuzGupta you can paste it in at https://repl.it/
Susannah Skyer Gupta
@SuzGupta
Jul 15 2016 05:10
(I am working in CodePen and then will copy into the fcc window.)
DJ
@qualitymanifest
Jul 15 2016 05:10
@SuzGupta paste your codepen
Lee
@leebut
Jul 15 2016 05:12
@misterhtmlcss You only need to use push() and shift() and then return what you shifted.
Susannah Skyer Gupta
@SuzGupta
Jul 15 2016 05:13
@GregatGit @qualitymanifest sorry, I'm confused by your replies; I understand that when I'm ready to have FCC evaluate my solution, then I will need to copy-paste it from CodePen. What I'm asking now is, within the CodePen/ just generally speaking, how can I print or log somehow to the console the contents of the JSON object I'm working with so I can see if my function is working as expected?
DJ
@qualitymanifest
Jul 15 2016 05:13
@leebut i think the reason is because it returns undefined if a or b is -2. otherwise it returns the built in return statement return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));. ironic! may be worth submitting as a bug, if you care to do so.
Greg Duncan
@GregatGit
Jul 15 2016 05:14
@SuzGupta there is a console button for code pen or you can open the chrome console
Subramanya Chakravarthy
@chakrihacker
Jul 15 2016 05:14
help destroyer
CamperBot
@camperbot
Jul 15 2016 05:14
no wiki entry for: destroyer
Subramanya Chakravarthy
@chakrihacker
Jul 15 2016 05:15
help seek
CamperBot
@camperbot
Jul 15 2016 05:15

:point_right: algorithm seek and destroy [wiki]

Algorithm Seek and Destroy

:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program :busts_in_silhouette: and write your own code :pencil:

:checkered_flag: Problem 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.

Relevant Links

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

DJ
@qualitymanifest
Jul 15 2016 05:15
@leebut yeah, in fact, it definitely only expects undefined if either a or b is -2. otherwise it expects that return statement. funny.
@SuzGupta i was asking you to paste the URL to your codepen so i can see what you have going on. are you familiar with console.log?
Magnus Holm
@mghlm
Jul 15 2016 05:16
Why doesn’t this get reversed? I want to first turn string into array, then reverse array, then turn array into string, then return string.
function reverseString(str) {
  var str = str.split(" ");
  var str = str.reverse();
  var str = str.join();
  return str;
}
DJ
@qualitymanifest
Jul 15 2016 05:17
@m4gnusholm you're telling it to reverse str on spaces, not at each character
Roger K.
@misterhtmlcss
Jul 15 2016 05:17
Thank you guys. I grabbed the answer off the web. Was easy once I understood what was being asked. Cheers!
Greg Duncan
@GregatGit
Jul 15 2016 05:17
@SuzGupta you can during your code have way points to see how the variable has changed by using console.log
DJ
@qualitymanifest
Jul 15 2016 05:18
@m4gnusholm if you're trying to reverse each letter, remove the space that you have in your split argument
Susannah Skyer Gupta
@SuzGupta
Jul 15 2016 05:19
@qualitymanifest @GregatGit yes, here's the codepen thus far. I am familiar with console.log. I am not familiar with how to print the contents of a JSON object. http://codepen.io/SuzGupta/pen/RRxkpX
Magnus Holm
@mghlm
Jul 15 2016 05:20
@qualitymanifest Ok, I removed the space, but it still returns “hello”, it doesn’t reverse
Greg Duncan
@GregatGit
Jul 15 2016 05:21
@SuzGupta on the bottom left of the screen is console button
DJ
@qualitymanifest
Jul 15 2016 05:21
@m4gnusholm get rid of var in front of each statement
Magnus Holm
@mghlm
Jul 15 2016 05:21
@qualitymanifest done. still the same
code looks like this now
Lee
@leebut
Jul 15 2016 05:22
@qualitymanifest Ah-ha, maybe I will. Learning false information is not really what anyone desires. The into texts and instructions are not always clear, nor are there always adequate explanations as to how code derives its results for multiple criteria. I like to know how something does what it does. That maths return statement is a bit scary at the moment. Maths is not my strong point, but I feel this course is going to change that a bit. Thank you again.
CamperBot
@camperbot
Jul 15 2016 05:22
leebut sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:warning: leebut already gave qualitymanifest points
Magnus Holm
@mghlm
Jul 15 2016 05:22
function reverseString(str) {
   str = str.split();
   str = str.reverse();
   str = str.join();
  return str;
}

reverseString("hello");
DJ
@qualitymanifest
Jul 15 2016 05:23
@SuzGupta put a console.log(collection); right after var collection ends, on like line 26/27
Susannah Skyer Gupta
@SuzGupta
Jul 15 2016 05:23
@GregatGit yes, I have the console open
DJ
@qualitymanifest
Jul 15 2016 05:23
@m4gnusholm put some quotation marks inside the split argument
Susannah Skyer Gupta
@SuzGupta
Jul 15 2016 05:24
@qualitymanifest oy, that was easier than I thought; for some reason I thought console.log did not work with JSON objects??
thank you @qualitymanifest @GregatGit
CamperBot
@camperbot
Jul 15 2016 05:24
suzgupta sends brownie points to @qualitymanifest and @gregatgit :sparkles: :thumbsup: :sparkles:
:cookie: 689 | @gregatgit |http://www.freecodecamp.com/gregatgit
:star2: 1275 | @qualitymanifest |http://www.freecodecamp.com/qualitymanifest
DJ
@qualitymanifest
Jul 15 2016 05:24
@SuzGupta your for (var p in o) is giving you errors, which is why you couldn't see things happening after that
Susannah Skyer Gupta
@SuzGupta
Jul 15 2016 05:25
@qualitymanifest yeah, I just took that out. You know, classic Stack Overflow copy-pasting with no idea what I'm doing
Rajdeep Roy
@RajdeepRoy
Jul 15 2016 05:25
pls help

getIndexToIns([2, 5, 10], 15) should return 3.

1

2
function getIndexToIns(arr, num) {
3
// Find my place in this sorted array.
4
arr.sort(function(a,b){
5
return a-b;
6
});
7
var b=arr.length;
8
for(i=0;i<=b;i++){
9
if (arr[i]>=num){
10
return arr.indexOf(arr[i]);
11
}
12
}
13
}
14
getIndexToIns([2, 5, 10], 15);

Greg Duncan
@GregatGit
Jul 15 2016 05:26
DJ
@qualitymanifest
Jul 15 2016 05:26
@m4gnusholm working now, yes? before, i was only telling you to delete the space, not the quotation marks
Chad Hurley
@ChadDean82
Jul 15 2016 05:27
Sorry back again went back & cleaned it up a bit but still cant get it to pass on more then 3 code tests. Thinking about converting it to if/else if's but figured I would pass it by the Group b4 I start over. Please take a look & see what Yall think. Thank Yall in advance.
Magnus Holm
@mghlm
Jul 15 2016 05:27
@qualitymanifest now it returns o,l,l,e,h
so it works, but why is there commas between each letter??
Susannah Skyer Gupta
@SuzGupta
Jul 15 2016 05:27
@GregatGit I can see what's in the JSON now and confirm that the new key I'm trying to create and the value I'm trying to put in there is not getting in. So, progress? :D
DJ
@qualitymanifest
Jul 15 2016 05:27
@m4gnusholm tell it where to join (quotation marks again...)
Chad Hurley
@ChadDean82
Jul 15 2016 05:28
var count = 0;

function cc(card) {
  // Only change code below this line
   switch (card) {
    case 2:
    case 3:
    case 4:
     case 5:
     case 6:
    card = "5 Bet";
     break; 

    case 7:
    case 8:
    case 9:
    card = "0 Hold";
      break;

    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
     card = "-5 Hold";


  }

  return card;
  // Only change code above this line
}
DJ
@qualitymanifest
Jul 15 2016 05:28
@m4gnusholm the quotation marks are because you've made an array with your split, but you haven't joined it back into a string anywhere
Magnus Holm
@mghlm
Jul 15 2016 05:29
@qualitymanifest ok, it works now, thank you
CamperBot
@camperbot
Jul 15 2016 05:29
:star2: 1276 | @qualitymanifest |http://www.freecodecamp.com/qualitymanifest
m4gnusholm sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
Magnus Holm
@mghlm
Jul 15 2016 05:30
@qualitymanifest I’m not sure I understand why I have to put quotation marks though...
DJ
@qualitymanifest
Jul 15 2016 05:30
@m4gnusholm '' === empty string, which in this case, means each string character
Magnus Holm
@mghlm
Jul 15 2016 05:30
is it because you use them around strings?
Ok thanks
DJ
@qualitymanifest
Jul 15 2016 05:31
np
Brian
@Brian984
Jul 15 2016 05:36
For intermediate algorithm challenge "Everything Be True," can someone please tell me why this doesn't work?
function truthCheck(collection, pre) {
  for (var i = 0; i < collection.length; i++) {
    if (!collection[i].hasOwnProperty(pre)) {
      return false;
    } else if (Boolean(collection[i].pre) === false) {
      return false;
    }
  } 

  return true;
}
Chad Hurley
@ChadDean82
Jul 15 2016 05:38
think I will rebuild tomorrow eye's are getting heavy & the littlest one will be hungry soon. Happy coding, :-) Good night all, catch yall later.
Subramanya Chakravarthy
@chakrihacker
Jul 15 2016 05:38
Thanks @Rafase282 for your help with Algorithm: Seek and Destroy
CamperBot
@camperbot
Jul 15 2016 05:38
chakrihacker sends brownie points to @rafase282 :sparkles: :thumbsup: :sparkles:
:star2: 1326 | @rafase282 |http://www.freecodecamp.com/rafase282
deepakSpatil
@deepakSpatil
Jul 15 2016 05:42
how to pass function to css attribute in javascript
.attr({
"x": function(d){ return xScale(d.country) +  xScale.rangeBand()/2; },
"y": function(d){ return yScale(d.populationValue)+ 12; },
"text-anchor": 'middle',
"fill": 'yellow',
"transform": 'translate("function(d){ return xScale(d.country) +  xScale.rangeBand()/2; }","function(d){ return yScale(d.populationValue)+ 12; }")rotate(-90)'
Jaren Escueta
@jarenescueta731
Jul 15 2016 05:43
@Brian984 there are a lot of other test cases you need to satisfy besides the ones that "strictly" equal false. there are undefined, 0, NaN, etc...
MT
@tnhminh
Jul 15 2016 05:50
@htmyheart Thank NgocTu so much ^^.
CamperBot
@camperbot
Jul 15 2016 05:50
tnhminh sends brownie points to @htmyheart :sparkles: :thumbsup: :sparkles:
:cookie: 216 | @htmyheart |http://www.freecodecamp.com/htmyheart
Magnus Holm
@mghlm
Jul 15 2016 05:51
why doesn’t this return 1 2 3 4 5??
function factorialize(num) {

  for(var i=1; i<num+1; i++) {
    return num;
  }
}

factorialize(5);
it just returns 5
kirbyedy
@kirbyedy
Jul 15 2016 05:57
This message was deleted
Markus Kiili
@Masd925
Jul 15 2016 05:58
@m4gnusholm You make a return on first loop i=1. It never goes beyond that. A return stops the execution of the entire function.
Brian
@Brian984
Jul 15 2016 05:58
@jarenescueta731 Thanks!
CamperBot
@camperbot
Jul 15 2016 05:58
brian984 sends brownie points to @jarenescueta731 :sparkles: :thumbsup: :sparkles:
:cookie: 318 | @jarenescueta731 |http://www.freecodecamp.com/jarenescueta731
Magnus Holm
@mghlm
Jul 15 2016 05:59
@Masd925 Does it stop when I return?
Markus Kiili
@Masd925
Jul 15 2016 06:00
@m4gnusholm Also there can be only one return value. If you need to return more values, you can return an object or an array etc.
Magnus Holm
@mghlm
Jul 15 2016 06:00
@Masd925 yes, i figured. so now instead I made a new array and pushed the values to the array, so now it works. thanks
CamperBot
@camperbot
Jul 15 2016 06:00
m4gnusholm sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2119 | @masd925 |http://www.freecodecamp.com/masd925
Lusako Njwaba
@lunjwaba1
Jul 15 2016 06:15

```

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

var ttl = 0;
var dec;
for(i=0;i < 5; i++){
if(card >=2 && card<=6){
ttl = (ttl + 1);
}
else if(card >=7 && card<=9){
ttl = ttl + 0;
}
else if(card ==10 || card=="Q" || card == "K" || card =="J" || card == "A"){
ttl = ttl -1;
}
}
if (ttl<=0){dec = " Hold";}
else if (ttl> 0){dec = " Bet";}
return ttl + dec;

// Only change code above this line
}``` I can't seem to figure out what I am messing up here, this is the card counting challenge basic JavaScript

Olly Sholotan
@Ollysho
Jul 15 2016 06:18
Hey this is going to sound stupid but from trial and error I actually passed this algorithm test but I keep looking at my code and I honestly cannot explain how I'm getting it to work, would anyone mind looking at it and explaining it to me?
Markus Kiili
@Masd925
Jul 15 2016 06:18
@Ollysho Sure.
Olly Sholotan
@Ollysho
Jul 15 2016 06:18

function chunkArrayInGroups(arr, size) {   
  var newArr = [];

  for (var i = 0; i < arr.length; i+=size) {
    newArr.push(arr.slice(i, size+i));
  }
  return newArr;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
My goal was to Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a two-dimensional array.
Markus Kiili
@Masd925
Jul 15 2016 06:18
@lunjwaba1 You should be incrementing the global variable count based on card.
@Ollysho Yes, you make new arrays of length size with .slice() and push them into result array.
Olly Sholotan
@Ollysho
Jul 15 2016 06:20
@Masd925 oh! so the slice code makes a completely new array?
Markus Kiili
@Masd925
Jul 15 2016 06:20
@Ollysho Yes.
Olly Sholotan
@Ollysho
Jul 15 2016 06:20
I've been trying to do that for hours and I did it by mistake. I love Javascript
@Masd925 thanks so much man!
CamperBot
@camperbot
Jul 15 2016 06:20
ollysho sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2120 | @masd925 |http://www.freecodecamp.com/masd925
musicsmithnz
@musicsmithnz
Jul 15 2016 06:21
help validate
CamperBot
@camperbot
Jul 15 2016 06:21

:point_right: algorithm validate us telephone numbers [wiki]

Algorithm Validate US Telephone Numbers

:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program :busts_in_silhouette: and write your own code :pencil:

:checkered_flag: Problem Explanation:

The task is not that hard to understand, implementing it is the hardest part. You have a to validate an US phone number. This means there is a certain amount of numbers required, while you don't need to put the country code, you will still need the area code and use one of the few formats allowed.

Relevant Links

:pencil: read more about algorithm validate us telephone numbers on the FCC Wiki

musicsmithnz
@musicsmithnz
Jul 15 2016 06:22
I was actually looking for some validation of my self worth
@camperbot is life worth living?
Magnus Holm
@mghlm
Jul 15 2016 06:23
is there a better way to do this, or is this the best way to write a function that factorializes a number?
function factorialize(num) {

  var newArray = [];

  for(var i=1; i<num+1; i++) {
     newArray.push(i);
  }

  var multiply = 1;
  for (var j=0; j<newArray.length; j++) {
   multiply = multiply * newArray[j];
  }
  return multiply;
}

factorialize(5);
Olly Sholotan
@Ollysho
Jul 15 2016 06:23
@musicsmithnz Alas, I asked camper that a while back and he just stared at me with a blank expression
Markus Kiili
@Masd925
Jul 15 2016 06:23
@m4gnusholm You don't need an array. Just one result variable that you multiply with a for loop over the numbers.
Magnus Holm
@mghlm
Jul 15 2016 06:24
@Masd925 But how can i use the push function then?
musicsmithnz
@musicsmithnz
Jul 15 2016 06:25
@Ollysho ty. such a shame, all this new technology and it can't even give us a reason to live.
CamperBot
@camperbot
Jul 15 2016 06:25
musicsmithnz sends brownie points to @ollysho :sparkles: :thumbsup: :sparkles:
:cookie: 253 | @ollysho |http://www.freecodecamp.com/ollysho
Markus Kiili
@Masd925
Jul 15 2016 06:26
@m4gnusholm I mean just like this:
function factorialize(num) {
  var result = 1;
  for (var i=1;i<=num;i++) result *= i;
  return result;
}
Lusako Njwaba
@lunjwaba1
Jul 15 2016 06:26
@Masd925 Thanks. I worked on that bad boy for a month :) ...finally got it lol! My life is complete.
CamperBot
@camperbot
Jul 15 2016 06:26
lunjwaba1 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2121 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Jul 15 2016 06:26
No need to store all the numbers anywhere. Just the running result.
Magnus Holm
@mghlm
Jul 15 2016 06:27
@Masd925 oh, interesting.
@Masd925 it’s just so much easier to grasp when you store the numbers. but your version is much more simple
what is *= ?
does it mean result * result+i ?
Markus Kiili
@Masd925
Jul 15 2016 06:29
It is the same as result = result * i
Alex N.
@N0bl3
Jul 15 2016 06:29
Hey guys does anyone know react here? :)
Nelya
@NankaBananka
Jul 15 2016 06:30
аштв Record Collection
find Record Collection
CamperBot
@camperbot
Jul 15 2016 06:30

find record collection

:zero: challenge record collection

Magnus Holm
@mghlm
Jul 15 2016 06:30
ok, but in this case, wouldn’t it just return the first calculation (1*2) and then stop running?
Markus Kiili
@Masd925
Jul 15 2016 06:30
@m4gnusholm No, because return is after loop.
Magnus Holm
@mghlm
Jul 15 2016 06:31
@Masd925 ok
Markus Kiili
@Masd925
Jul 15 2016 06:31
It is the same as:

function factorialize(num) {
  var result = 1;
  for (var i=1;i<=num;i++) {
    result *= i;}
  return result;
}
If there is only one statement on the for block, you can just write it after the for loop declaration without braces.
Magnus Holm
@mghlm
Jul 15 2016 06:32
@Masd925 Can I ask why you don’t use curly braces in the loop?
ok got it
@Masd925 thanks!
CamperBot
@camperbot
Jul 15 2016 06:33
m4gnusholm sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: m4gnusholm already gave masd925 points
Markus Kiili
@Masd925
Jul 15 2016 06:33
@m4gnusholm This is also a nice spot to look at ternary operator and recursion:
function factorialize(num) {
  return num!==0 ? num*factorialize(num-1) : 1;
}
Magnus Holm
@mghlm
Jul 15 2016 06:35
@Masd925 cool, even more simple. Do you think fcc will cover it later on? I just started the Basic Algorithm Scripting lessons
Markus Kiili
@Masd925
Jul 15 2016 06:35
@m4gnusholm I don't remember. Not necessarily.
Magnus Holm
@mghlm
Jul 15 2016 06:36
@Masd925 ok i’ll look it up
but i am learning this stuff extremely slowly. it’s many many years since i have used my brain this way
Jack Huo
@Capt-Hyc
Jul 15 2016 06:38
This message was deleted
Markus Kiili
@Masd925
Jul 15 2016 06:39
@Capt-Hyc It is better to forget temp and just look for a character that is not found and return false. After loop return true. Basic loop logic for checking if many things are true.
Jack Huo
@Capt-Hyc
Jul 15 2016 06:44
@Masd925 This is my way to solve 'Mutations',sorry my english is poor.
This message was deleted
Jack Huo
@Capt-Hyc
Jul 15 2016 06:50
This message was deleted
Jack Huo
@Capt-Hyc
Jul 15 2016 06:55
function mutation(arr) {
  var arr1 = arr[0].toLowerCase();
  var arr2 = arr[1].toLowerCase();
  var temp = 0;
  for(var i = 0;i < arr[1].length;i++){
    temp = arr1.indexOf(arr2[i]);
    if(temp !== -1){
      continue;
    }else{
      return false;
    }
  }
  return true;
} 
mutation(["hello", "neo"]);
Andrew
@rexmorgan89
Jul 15 2016 06:58
Anyone finish the "Seek and Destroy" Basic algorithm challenge?
I'm having trouble setting up the first filter function to pass to .filter()...
Markus Kiili
@Masd925
Jul 15 2016 06:58
@rexmorgan89 Yes.
@Capt-Hyc That continue block is redundant. You can simplify it to:
function mutation(arr) {
  var arr1 = arr[0].toLowerCase();
  var arr2 = arr[1].toLowerCase();
  var temp;
  for(var i = 0;i < arr[1].length;i++){
    temp = arr1.indexOf(arr2[i]);
    if(temp === -1) return false;
  }
  return true;
}
Andrew
@rexmorgan89
Jul 15 2016 07:00
@Masd925 I'm confused as how to set up the filter function to recognize x number of arguments to filter out of the array.
Jack Huo
@Capt-Hyc
Jul 15 2016 07:00
@Masd925 Right~
Markus Kiili
@Masd925
Jul 15 2016 07:00
@rexmorgan89 You need to loop or iterate the arguments.
Andrew
@rexmorgan89
Jul 15 2016 07:00
If the number of arguments is variable, I'd need to loop through the arguments
Right
Markus Kiili
@Masd925
Jul 15 2016 07:01
Use arguments.length
Andrew
@rexmorgan89
Jul 15 2016 07:01
I get that... I'm saying, I need my filter function to evaluate to true or false for each value in the array
And those values are supposed to be checked against arguments outside of the array
Larry
@larry1314mvp
Jul 15 2016 07:02
kan bu dong
llamatarianism
@llamatarianism
Jul 15 2016 07:03
@rexmorgan89 so you'd have a for loop inside your filter function
Markus Kiili
@Masd925
Jul 15 2016 07:03
The filter callback function parameter is the arr element being iterated by filter. Loop the arguments inside callback and return false if you find an argument equal to the callback parameter. Return true after loop.
llamatarianism
@llamatarianism
Jul 15 2016 07:03
alternatively
make arguments into an array and use Array.prototype.includes
Markus Kiili
@Masd925
Jul 15 2016 07:04
@llamatarianism .includes has poor browser support. Why not just suggest indexOf.
llamatarianism
@llamatarianism
Jul 15 2016 07:05
who cares about browser support in a challenge that will only ever get executed in my browser
I'll worry about polyfills when I need to
Markus Kiili
@Masd925
Jul 15 2016 07:07
@llamatarianism If only you had a polyfill for making ES6 work on older browsers. Easily compiled to ES5 of course.
Larry
@larry1314mvp
Jul 15 2016 07:08
Hello World!
CamperBot
@camperbot
Jul 15 2016 07:08

welcome to FreeCodeCamp @larry1314mvp!

llamatarianism
@llamatarianism
Jul 15 2016 07:15
that's basically the definition of a polyfill
Array.prototype.includes = function(item) { return this.indexOf(item) !== -1; }
kablam
Magnus Holm
@mghlm
Jul 15 2016 07:17
quick question: if I want to reverse the order of the elements of a string, do I always need to turn it into an array first?
Vyvojar123
@Vyvojar123
Jul 15 2016 07:18
hello Could you recommend me a way to do realtime validation of text input based on regular expression ?
Andrew
@rexmorgan89
Jul 15 2016 07:19
@Masd925 If you loop the arguments inside the callback function, it treats each array element as an argument but not the actual arguments you'd want to compare your values to.
```
function filterArgs(val) {
  for (var i = 1; i<arguments.length;i++){
    console.log(arguments[i]);
    if(val === arguments[i]) return true;
  }
  return false;

}
function destroyer(arr) {
  // Remove all the values

 arr = arr.filter(filterArgs);  

  return arr;
}
I understand the code above is wrong but I use the javascript console to help me understand what's being passed to my loop.
In the scenario above, the arguments object in the filter function is looking at each element in the array as an argument but not referring to the actual arguments I'd like to check each value against.
Larry
@larry1314mvp
Jul 15 2016 07:23
@m4gnusholm str.split('').reverse().join('')
Andrew
@rexmorgan89
Jul 15 2016 07:23
This is where my confusion entered: how am I supposed to insert arguments from my initial function to my filter function?
Jamie
@TheJamieCrawford
Jul 15 2016 07:23
Hey can someone help me with the Concatenating Strings with the plus equals operator lesson
Magnus Holm
@mghlm
Jul 15 2016 07:23
@larry1314mvp not like this:
Jamie
@TheJamieCrawford
Jul 15 2016 07:23

My code looks like this

var myStr = "This is the first sentence. ";
myStr += "This is the second sentece.";

Magnus Holm
@mghlm
Jul 15 2016 07:23
str = str.split("");
   str = str.reverse();
   str = str.join("");
?
Jamie
@TheJamieCrawford
Jul 15 2016 07:24
I copied the example... but it says the value is wrong
Andrew
@rexmorgan89
Jul 15 2016 07:24
Wait... I should make an arguments array before passing that to my filter function...
rajdash
@ultrageek
Jul 15 2016 07:33
@TheJamieCrawford The 2nd line has "sentence" spelled incorrectly. Could that be the problem?
Magnus Holm
@mghlm
Jul 15 2016 07:35
@larry1314mvp Larry, I get a message saying str.split is not a function
Larry
@larry1314mvp
Jul 15 2016 07:36
..
@m4gnusholm the str is a string
Syed Masrur
@m4srur
Jul 15 2016 07:37
help: Escape Sequences in Strings
CamperBot
@camperbot
Jul 15 2016 07:37

:point_right: challenge escape sequences in strings [wiki]

Challenge Escape Sequences in Strings

Quotes are not the only characters that can be escaped inside a string. Here is a table of common escape sequences:

Code Output
\' single quote
\" double quote
\ backslash
\n new line
\r carriage return
\t tab
\b backspace
\f form feed

Note that the backslash itself must be escaped in order to display as a backslash.

:pencil: read more about challenge escape sequences in strings on the FCC Wiki

Syed Masrur
@m4srur
Jul 15 2016 07:38
I am stuck on this challenge
Larry
@larry1314mvp
Jul 15 2016 07:39
blob
blob
Magnus Holm
@mghlm
Jul 15 2016 07:39
@larry1314mvp yes
Markus Kiili
@Masd925
Jul 15 2016 07:39
@llamatarianism Yes you can polyfill some ES6 methods, but there is no polyfill for making ES6 work as a whole. ES6 is still another language that compiles into code that actually works on clients browsers. Many people are here to learn to make real production code.
Syed Masrur
@m4srur
Jul 15 2016 07:40

Assign the following three lines of text into the single variable myStr using escape sequences.

FirstLine
\SecondLine\
ThirdLine
You will need to use escape sequences to insert special characters correctly. You will also need to follow the spacing as it looks above, with no spaces between escape sequences or words.

Here is the text with the escape sequences written out.

FirstLinenewlinebackslashSecondLinebackslashcarriage-returnThirdLine

Larry
@larry1314mvp
Jul 15 2016 07:40
@m4gnusholm not like this?
Syed Masrur
@m4srur
Jul 15 2016 07:40
I tried everything but nothing works
Magnus Holm
@mghlm
Jul 15 2016 07:40
my code looks like this
function palindrome(str) {

  str = str.replace(/[^a-z0-9]/gi, '');
  str = str.toLowerCase;

  var newStr = str.split("").reverse().join("");

  if( newStr === str) {
    return true;
  } 
  else {
    return false;
  }
}
I get a message saying str.split is not a function
Markus Kiili
@Masd925
Jul 15 2016 07:41
@rexmorgan89 Yes, filter callback has its own arguments object.
Larry
@larry1314mvp
Jul 15 2016 07:41
@m4gnusholm ok I get. str = str.toLoWerCase(). forget()
toLowerCase()
Magnus Holm
@mghlm
Jul 15 2016 07:42
@larry1314mvp Ohhh, thank you
CamperBot
@camperbot
Jul 15 2016 07:42
m4gnusholm sends brownie points to @larry1314mvp :sparkles: :thumbsup: :sparkles:
:cookie: 3 | @larry1314mvp |http://www.freecodecamp.com/larry1314mvp
Andrew
@rexmorgan89
Jul 15 2016 07:42
help: Seek and Destroy
CamperBot
@camperbot
Jul 15 2016 07:42

:point_right: algorithm seek and destroy [wiki]

Algorithm Seek and Destroy

:triangular_flag_on_post: Remember to use Read-Search-Ask if you get stuck. Try to pair program :busts_in_silhouette: and write your own code :pencil:

:checkered_flag: Problem 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.

Relevant Links

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

Markus Kiili
@Masd925
Jul 15 2016 07:43
@rexmorgan89 You can store destroyers arguments in a variable, turn it into an array or pass it into filter callback as value of this using filter syntax arr.filter(callback[, thisArg])
John Alcher
@alchermd
Jul 15 2016 07:45

Hey fellas. I'm pretty sure I'm missing something here. I'm currently solving
https://www.freecodecamp.com/challenges/arguments-optional
and I think I already got the working solution. But one of the conditions to pass is

function addTogether() {
    .....
}
addTogether(2)(3); // should return 5.

How does addTogether(2)(3) even work as a function with arguments? If I understood it correctly, it's calling the addTogether function then passing it the argument of 2)(3 which is afaik not a valid value. Where am I wrong?

Markus Kiili
@Masd925
Jul 15 2016 07:46
@alchermd addTogether(2) returns a function. (3) invokes that function.
Andrew
@rexmorgan89
Jul 15 2016 07:47
Thanks for the solid tips @Masd925 & @llamatarianism!
CamperBot
@camperbot
Jul 15 2016 07:47
rexmorgan89 sends brownie points to @masd925 and @llamatarianism :sparkles: :thumbsup: :sparkles:
:cookie: 984 | @llamatarianism |http://www.freecodecamp.com/llamatarianism
:star2: 2122 | @masd925 |http://www.freecodecamp.com/masd925
John Alcher
@alchermd
Jul 15 2016 07:49
@Masd925 hey. Can you enlighten me on what does 'invoking a function' mean? For the meantime, addTogether(2)(3) is giving me a
TypeError: addTogether(...) is not a function
Markus Kiili
@Masd925
Jul 15 2016 07:50
@alchermd Invoking means calling a function with arguments. Then the function executes and returns a value. addTogether(2) calls the function with one argument. As stated in the description, when called with one argument, the addTogether should return a function of one parameter.
Vyvojar123
@Vyvojar123
Jul 15 2016 07:51
if i want to use regexp, do I need an external library or it is included in JS?
Markus Kiili
@Masd925
Jul 15 2016 07:51
@Vyvojar123 It is built-in.
Vyvojar123
@Vyvojar123
Jul 15 2016 07:54
i have this: var validation = new RegExp('/^+[0-9]{3}\s[0-9]{3}\s[0-9]{3}\s[0-9]{3}$/');
if(validation.test(VAL)) {
alert("it is OK");
}
else {
alert("it is not OK");
}
and it does not anything
no alert window is shown
John Alcher
@alchermd
Jul 15 2016 07:58
This message was deleted
Markus Kiili
@Masd925
Jul 15 2016 08:00
You need a function declaration or function expression and then return that function. Or you can use addTogether.bind() method to make a partial function and return it.
John Alcher
@alchermd
Jul 15 2016 08:01
@Masd925 This is quite confusing haha.
First of all, why am I getting a TypeError:addTogether(...) is not a function?
Markus Kiili
@Masd925
Jul 15 2016 08:01
@alchermd Most likely the return value from addTogether is not a function.
anvarov
@anvarov
Jul 15 2016 08:03
hi everyone, i didn't get DNA Pairing bonfire, what is it, i'm stuck
John Alcher
@alchermd
Jul 15 2016 08:04

@Masd925 ohhh. So, how does that work? I'm returning a

if (there is only one argument) {
   return functionName(argument[0]);
}

which I presume returns the value from functionName.

@anvarov just pair A with T and C with G
anvarov
@anvarov
Jul 15 2016 08:05
i'm bad in chemistry)
Vyvojar123
@Vyvojar123
Jul 15 2016 08:05
@Masd925 it is just a part of function which does not work
Darth Skywalker
@adityaparab
Jul 15 2016 08:05
Whats going wrong here? Perhaps I am not correctly understanding the problem statement?
var count = 0;

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


  if(card >= 2 && card <=6 ){
    count+=1;
  } else if(card >= 7 && card <=9){
    count+=0;
  } else if(card === 10 || card === 'J' || card === 'Q' || card === 'K' || card === 'A'){
    count-=1;
  }

  if(count > 0){
    return count+' Bet';
  } else {
    return count+ 'Hold';
  }


  // 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');
Markus Kiili
@Masd925
Jul 15 2016 08:06
@alchermd This is how you can return a function:
function outer () {
    return inner;

    function inner () {

    }
}
anvarov
@anvarov
Jul 15 2016 08:06
@alchermd For example, for the input GCG, return [["G", "C"], ["C","G"],["G", "C"]]
@Masd925 is it a closure?
Markus Kiili
@Masd925
Jul 15 2016 08:07
@alchermd When you return the inner function, don't invoke it with arguments, because then you return the return value of inner function.
@anvarov Yes. When a function is returned in JS, actually a closure is returned.
LordYamanouchi
@LordYamanouchi
Jul 15 2016 08:08
Hey can I use and if and for statement together? With the if statement inside the for to make an if this else this ?
Lee
@leebut
Jul 15 2016 08:09
Hello. I'm working on, 'Accessing Objects Properties with Variables', but the challenge seems to have a missing variable above the object. It isn't the same structure as the examples given in the description about objects.

One of the examples:

var myDog = "Hunter";
var dogs = {
  Fido: "Mutt",
  Hunter: "Doberman",
  Snoopie: "Beagle"
}
var breed = dogs[myDog];
console.log(breed);// "Doberman"

Now the challenge:


// Setup
var testObj = {
  12: "Namath",
  16: "Montana",
  19: "Unitas"
};

// Only change code below this line;

var playerNumber;       // Change this Line
var player = testObj;   // Change this Line
Shouldn't there be a variable above the line // Setup?
Markus Kiili
@Masd925
Jul 15 2016 08:11
@leebut Assign the number to playerNumber and then use the variable as the key when you access testObj property value.
LordYamanouchi
@LordYamanouchi
Jul 15 2016 08:12
@Masd925 Hey can I use and if and for statement together? With the if statement inside the for to make an if this else this ?
Markus Kiili
@Masd925
Jul 15 2016 08:12
Assign that property value to player variable.
LordYamanouchi
@LordYamanouchi
Jul 15 2016 08:12
@Masd925 if (contacts[i].firstName == firstName){
return "Contact Found";
} else {
return "No such contact";
}
}
Syed Masrur
@m4srur
Jul 15 2016 08:12

Here is the text with the escape sequences written out.

Help: FirstLinenewlinebackslashSecondLinebackslashcarriage-returnThirdLine

Markus Kiili
@Masd925
Jul 15 2016 08:12
@LordYamanouchi You can.
John Alcher
@alchermd
Jul 15 2016 08:12
@Masd925 Thank you. It's making some sense now though I still can't figure out the practical applications of it :D
CamperBot
@camperbot
Jul 15 2016 08:12
alchermd sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2123 | @masd925 |http://www.freecodecamp.com/masd925
Syed Masrur
@m4srur
Jul 15 2016 08:12
my code: var myStr = "\FirstLine\n"; "\SecondLine\r"; "\ThirdLine\t";
what am i doing worng?
*wrong
I am on the Escape Sequences in Strings challenge for Javascript
Lee
@leebut
Jul 15 2016 08:14

@Masd925 Okay. Thank you.

// Setup
var testObj = {
  12: "Namath",
  16: "Montana",
  19: "Unitas"
};

// Only change code below this line;

var playerNumber = 16;       // Change this Line
var player = testObj[playerNumber];   // Change this Line

Why FCC makes some challenges different from the examples they provide escapes me.

CamperBot
@camperbot
Jul 15 2016 08:14
leebut sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2124 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Jul 15 2016 08:15
@leebut You need to learn the concepts and apply your knowledge.
LordYamanouchi
@LordYamanouchi
Jul 15 2016 08:15
Why doesn't this work then ? if (contacts[i].firstName == firstName){
return "Contact Found";
} else {
return "No such contact";
}
} @Masd925
John Alcher
@alchermd
Jul 15 2016 08:15
@alchermd Ohh one last thing, how do I access (3) in addTogether(2)(3) ?
Lee
@leebut
Jul 15 2016 08:16
@Masd925 That is true, but when what is provided is different from what is expected, it's a bit of a curve-ball sometimes.
Markus Kiili
@Masd925
Jul 15 2016 08:16
@LordYamanouchi That works as a test for the firstname of the looped contact.
Syed Masrur
@m4srur
Jul 15 2016 08:16
@Masd925 can u plz look at my challenge?
any advice?
Markus Kiili
@Masd925
Jul 15 2016 08:16
@alchermd The returned function should have one parameter that catches one passed argument.
LordYamanouchi
@LordYamanouchi
Jul 15 2016 08:17
@Masd925 Well it doesn't say contact Found for the firstName's that are there
Syed Masrur
@m4srur
Jul 15 2016 08:18
var myStr = "\FirstLine\n"; "\SecondLine\r"; "\ThirdLine\t";
Mahade Walid
@walidmahade
Jul 15 2016 08:18
@Masd925 in which way the algorithm challenges will benefit someone in programming?
Brendan Kinahan
@BKinahan
Jul 15 2016 08:18
@m4srur too many semi-colons!
Syed Masrur
@m4srur
Jul 15 2016 08:18
@BKinahan thnx
CamperBot
@camperbot
Jul 15 2016 08:18
m4srur sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star2: 1993 | @bkinahan |http://www.freecodecamp.com/bkinahan
Brendan Kinahan
@BKinahan
Jul 15 2016 08:18
and quotation marks
Markus Kiili
@Masd925
Jul 15 2016 08:18
@walidmahade You will encounter similar situations where you have to solve some problem.
John Alcher
@alchermd
Jul 15 2016 08:19
@Masd925 How does that look like? I have:
function inner() {
  function outer(x) {
    return arguments[0] + x;
  }
}
Markus Kiili
@Masd925
Jul 15 2016 08:20
@alchermd Both functions have their own arguments objects.
Mahade Walid
@walidmahade
Jul 15 2016 08:21
is it okay, if I try to solve them from others solution ?
Syed Masrur
@m4srur
Jul 15 2016 08:21
@BKinahan var myStr = "\FirstLine\n \SecondLine"\r "\ThirdLine\t"; still problem
kirbyedy
@kirbyedy
Jul 15 2016 08:21
@m4srur too much ", watch the spaces
@m4srur also \ is escaped like this \\
LordYamanouchi
@LordYamanouchi
Jul 15 2016 08:21
This message was deleted
for (var i = 0; i < contacts.length && contacts[i].firstName !== firstName; i++){
    if (contacts[i].firstName == firstName){
      return "Contact Found";
    } else {
      return "No such contact";
    }
  }
Does anyone know why this isn't working ?
Markus Kiili
@Masd925
Jul 15 2016 08:23
@LordYamanouchi Putting complicated logic on for loop condition is evil. Just the loop over contacts array is better.
@LordYamanouchi Then two nested if's inside it is the simplest structure.
LordYamanouchi
@LordYamanouchi
Jul 15 2016 08:24
@Masd925 So I shouldn't use an else?
John Alcher
@alchermd
Jul 15 2016 08:24
@Masd925 Thank you very much!
CamperBot
@camperbot
Jul 15 2016 08:24
alchermd sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: alchermd already gave masd925 points
Markus Kiili
@Masd925
Jul 15 2016 08:24
@LordYamanouchi If you make two nested if's for the firstname and property existence tests, the elses are optional.
LordYamanouchi
@LordYamanouchi
Jul 15 2016 08:27
@Masd925 The thing is it's like the loop isn't running at all
Nelya
@NankaBananka
Jul 15 2016 08:28
hello everybody
need some help with Profile Lookup
totally stuck and don’t understand why this is not working as waited
for (i = 0; i < contacts.length; i++) {
if (contacts[i].firstName == firstName) {
if (contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
} else {
return "No such property";
}
} else {
return "No such name";
}
btw how can I insert here code in more normal view?
Markus Kiili
@Masd925
Jul 15 2016 08:30
@NankaBananka Wrong spelling: return "No such name"
Also no such contact should be returned after the loop.
Nelya
@NankaBananka
Jul 15 2016 08:31
@Masd925 don’t get((
andybmx20
@andybmx20
Jul 15 2016 08:31
Hi guys my code work fine , i tried tests in console and work fine but i cant skip tests.... its a bug or something...?

function truncate(str, num) {

if (str.length <= num) {
return str;
} else if (num <= 3){
return str.slice(0, num) + '...';
} else {

return str.slice(0, num - 3) + '...';

}
}

truncate("Absolutely Longer", 2);

Markus Kiili
@Masd925
Jul 15 2016 08:32
@NankaBananka It is return "No such contact"; and you cannot return it before you have checked all the contacts -> after the loop block.
Nelya
@NankaBananka
Jul 15 2016 08:33
@Masd925 so in for loop I should just check is firstName here or not? Using some counter or what?
Markus Kiili
@Masd925
Jul 15 2016 08:33
@NankaBananka Make two nested if's inside the loop block.
@NankaBananka Firstname test with === and property existence check with .hasOwnProperty().
Nelya
@NankaBananka
Jul 15 2016 08:34
@Masd925 they are already nested
tatendamar
@tatendamar
Jul 15 2016 08:35
Hello guys, im a javascript beginner and would really appreciate all the help from you guys
Nelya
@NankaBananka
Jul 15 2016 08:35
@NankaBananka I don’t know how to insert code here
Markus Kiili
@Masd925
Jul 15 2016 08:35
explain format
CamperBot
@camperbot
Jul 15 2016 08:35

: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 thecode`.

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

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

Nelya
@NankaBananka
Jul 15 2016 08:38
@Masd925
for (i = 0; i < contacts.length; i++) {
  if (contacts[i].firstName == firstName) {
    if (contacts[i].hasOwnProperty(prop)) {
      return contacts[i][prop];
    } else {
      return "No such property";
    }
  } else {
    return "No such contact";
  }
Markus Kiili
@Masd925
Jul 15 2016 08:39
@NankaBananka Your code can return no such contact after checking only one contact.
Tessa Bradford
@trose1189
Jul 15 2016 08:39

Hey guys. I'm working on my tic tac toe project (very much still in progress-- lots to do before it's finished), but I'm having a problem. When the user wins, it's running my "winner" function twice... this is not the case if the computer wins though. The function is at the bottom of my js.

I know my checkWinner function is super long and repetitive... it'll get re-worked eventually. But right now, I need to figure out why it's adding two points each time the user wins. Anyone have any ideas? Thanks!

http://codepen.io/trose1189/pen/Gqygmg?editors=0011

Nelya
@NankaBananka
Jul 15 2016 08:41
@Masd925 I’ve already get it) but I don’t understand how to change it
Markus Kiili
@Masd925
Jul 15 2016 08:41
@NankaBananka Move the last return outside the loop (after the loop block).
LordYamanouchi
@LordYamanouchi
Jul 15 2016 08:41
@NankaBananka My loop keeps closing at 0 too
Nelya
@NankaBananka
Jul 15 2016 08:43
@Masd925 if I move return outside, than it will be outside the if statements too
Markus Kiili
@Masd925
Jul 15 2016 08:43
@NankaBananka Yes.
@NankaBananka When the loop runs out, you know there was no such contact with given first name.
Nelya
@NankaBananka
Jul 15 2016 08:44
@Masd925 so I need some var to make it
Markus Kiili
@Masd925
Jul 15 2016 08:44
@NankaBananka No.
@NankaBananka The loop checks all the contacts and makes a return if correct firstname is found. After the loop you can return no such contact.
LordYamanouchi
@LordYamanouchi
Jul 15 2016 08:46
@Masd925 But it stops executing at 0
@Masd925 for no f* reason
Markus Kiili
@Masd925
Jul 15 2016 08:46
@LordYamanouchi You have to post your code if you wan't to discuss it.
trần nguyễn minh anh
@Anntran2222
Jul 15 2016 08:46
how can we check a palindrome
Nelya
@NankaBananka
Jul 15 2016 08:46
This message was deleted
LordYamanouchi
@LordYamanouchi
Jul 15 2016 08:46
function lookUpProfile(firstName, prop){
// Only change code below this line
  var propertyFound;  
for (var i = 0; i < 3 ; i++){
    if (contacts[i].firstName == firstName){
     propertyFound = "Contact Found";
    } if (contacts[i].firstName !== firstName) {
      propertyFound = "No such contact";
    } 

  }
  return propertyFound;
// Only change code above this line
}
Nelya
@NankaBananka
Jul 15 2016 08:47
@Masd925
for (i = 0; i < contacts.length; i++) {
  if (contacts[i].firstName == firstName) {
    if (contacts[i].hasOwnProperty(prop)) {
      return contacts[i][prop];
    } else {
      return "No such property";
    }
  } 

  return "No such contact";
Ngoc Tu
@htmyheart
Jul 15 2016 08:47
@Anntran2222 what does that mean?
Markus Kiili
@Masd925
Jul 15 2016 08:48
@NankaBananka Where is the loop block ending?
Nelya
@NankaBananka
Jul 15 2016 08:48
@Masd925 just before return ‘No such contact'
Ngoc Tu
@htmyheart
Jul 15 2016 08:48
@Anntran2222 palindrome?
Markus Kiili
@Masd925
Jul 15 2016 08:48
@NankaBananka You are missing a }
Brendan Kinahan
@BKinahan
Jul 15 2016 08:48
@NankaBananka ah, but that's where your if statement ends.
Nelya
@NankaBananka
Jul 15 2016 08:49
@BKinahan get it
@Masd925 yep, my mistake. But I anyway don’t understand why this works((((
Markus Kiili
@Masd925
Jul 15 2016 08:51
@NankaBananka The loop checks all the contacts and makes a return if the correct contact is there. If there is no contact with given first name, the loop ends and then return "No such contact"; is executed as should.
Nelya
@NankaBananka
Jul 15 2016 08:52
@Masd925 hey, if in loop was return statement executed, loop just stops and last statement with ‘No such contact’ will no be executed
@Masd925 finally get it)))
Markus Kiili
@Masd925
Jul 15 2016 08:52
@NankaBananka Yes, a return stops the function execution.
trần nguyễn minh anh
@Anntran2222
Jul 15 2016 08:52
yes @htmyheart
Nelya
@NankaBananka
Jul 15 2016 08:52
@Masd925 thanks a lot!
CamperBot
@camperbot
Jul 15 2016 08:52
nankabananka sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2125 | @masd925 |http://www.freecodecamp.com/masd925
Nelya
@NankaBananka
Jul 15 2016 08:53
@Masd925 my head almost exploded))) thanks for patience %)
CamperBot
@camperbot
Jul 15 2016 08:53
nankabananka sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
trần nguyễn minh anh
@Anntran2222
Jul 15 2016 08:53
how do we use the replace()?
CamperBot
@camperbot
Jul 15 2016 08:53
:warning: nankabananka already gave masd925 points
Markus Kiili
@Masd925
Jul 15 2016 08:54
@NankaBananka Gray matter eating your skull away.
LordYamanouchi
@LordYamanouchi
Jul 15 2016 08:57
@Masd925 so if there are not two nested if statements they won't work under a for statement
Mitul Islam
@MitulIslam
Jul 15 2016 08:57
hi , can any one explain how this sort function in working
what is taken as argument in that callback function how and why
var arr = [5, 3, 20, 3];
arr.sort(function(a,b){return a-b;});
Keone Martin
@Athaman
Jul 15 2016 08:57
@Anntran2222 stringName.replace(toBeReplaced, replacedWith); but that will only replace the first instance it comes across. if you want to do it with every thing you'll need to use regular expressions
Kenny Jeurissen
@Digital-Banana
Jul 15 2016 08:58
Looking for advice on Seek and Destroy. I am pretty much stuck here.

function destroyer(arr) {
  var args = Array.prototype.slice.call(arguments);

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Markus Kiili
@Masd925
Jul 15 2016 08:58
@LordYamanouchi They work. Forget the result variable and just return then you know the return value.
@Digital-Banana You could loop arr and then check with indexOf whether the looped element is found on args. Better to do var args = Array.prototype.slice.call(arguments,1); so you skip the first argument (the array arr).
Kenny Jeurissen
@Digital-Banana
Jul 15 2016 09:00
@Masd925 is this best done with a for loop or while loop?
Keone Martin
@Athaman
Jul 15 2016 09:00
@MitulIslam the sort function passes elements from the array to the internal function for sorting. a and b are the current index and the next index. so first up would be arr[0] and arr[1] and then increment them both up
Brendan Kinahan
@BKinahan
Jul 15 2016 09:00
have a read through http://mdn.io/sort Each browser has its own sorting implementation
@MitulIslam
Markus Kiili
@Masd925
Jul 15 2016 09:00
@Digital-Banana For loop or .filter().
@BKinahan Standard says nothing of the actual sorting algorithm.
Brendan Kinahan
@BKinahan
Jul 15 2016 09:02
@Masd925 right, that's what I mean about the browsers implementing their own
Markus Kiili
@Masd925
Jul 15 2016 09:03
@BKinahan Yes.
Brendan Kinahan
@BKinahan
Jul 15 2016 09:03
Yes.
BKinahan @BKinahan nods, quite solemnly.
Keone Martin
@Athaman
Jul 15 2016 09:03
serious dialogue is serious
Markus Kiili
@Masd925
Jul 15 2016 09:05
Yes, it is.
BKinahan @BKinahan nods, a bit less-solemnly.
Pepecode
@Pepecode
Jul 15 2016 09:07
Hello I need some help with "using objects for lookups" chalenge, this is my code:
Mitul Islam
@MitulIslam
Jul 15 2016 09:08
@Athaman @BKinahan thanks :+1:
CamperBot
@camperbot
Jul 15 2016 09:08
mitulislam sends brownie points to @athaman and @bkinahan :sparkles: :thumbsup: :sparkles:
:cookie: 573 | @athaman |http://www.freecodecamp.com/athaman
:star2: 1994 | @bkinahan |http://www.freecodecamp.com/bkinahan
Pepecode
@Pepecode
Jul 15 2016 09:09

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

  // Only change code below this line
    }

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

  };
result = lookup[val];

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

// Change this value to test
phoneticLookup("charlie");
Keone Martin
@Athaman
Jul 15 2016 09:10
@MitulIslam you're welcome
@Pepecode you have a brace } on the first line after only change code below which closes the function there.
oooh @BKinahan almost 2k brownie points >.> getting close
Brendan Kinahan
@BKinahan
Jul 15 2016 09:11
@Athaman yup :D
Keone Martin
@Athaman
Jul 15 2016 09:11
if you delete that you should be good
gitter... why you get my message send order so confused?
Pepecode
@Pepecode
Jul 15 2016 09:12
@Athaman shit, you are right XD , I'm still asleep. Thanks
CamperBot
@camperbot
Jul 15 2016 09:12
pepecode sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
:cookie: 574 | @athaman |http://www.freecodecamp.com/athaman
Markus Kiili
@Masd925
Jul 15 2016 09:12
@Athaman He will not make it. It is tough. Everyone notices you when you are in a grocery store etc.
Keone Martin
@Athaman
Jul 15 2016 09:13
@Pepecode no problem :)
I have faith in you @BKinahan
Palade Radu-Paul
@Raduuu
Jul 15 2016 09:13
Hello guys
I'm trying to complete the weather challenge
and I can't seem to get a response from ajax, even though the url is fine
could it be something wrong with the weather api or?
Keone Martin
@Athaman
Jul 15 2016 09:14
it probably won't be
have you checked your console logs?
Palade Radu-Paul
@Raduuu
Jul 15 2016 09:15
yes, it gets me to error
Keone Martin
@Athaman
Jul 15 2016 09:15
also are you trying to access a http:// from a https:// connection?
96street
@96street
Jul 15 2016 09:15

can somone please tell me what:

+after.substr(1)

is doing here?

function myReplace(str, before, after) {

  var upper = '/[A-Z]/';
  if(before.charAt(0) == before.charAt(0).toUpperCase()) {
    after = after.charAt(0).toUpperCase()+after.substr(1);
  }
  else {
    after = after.charAt(0).toLowerCase()+after.substr(1);
  }

  return str.replace(before, after);

}

myReplace("He is Sleeping on the couch", "Sleeping", "sitting");
Palade Radu-Paul
@Raduuu
Jul 15 2016 09:15
96street
@96street
Jul 15 2016 09:15
in the first if
Keone Martin
@Athaman
Jul 15 2016 09:15
cos the openweather api needs a paid subscription for https: and mixing the two will break
Palade Radu-Paul
@Raduuu
Jul 15 2016 09:15
hmm, I'm on codepen
is it https?
Keone Martin
@Athaman
Jul 15 2016 09:16
i think so
Palade Radu-Paul
@Raduuu
Jul 15 2016 09:16
well, the challenge states that that's where we need to code it
and to use the openweather api
Keone Martin
@Athaman
Jul 15 2016 09:17
@96street substr() gets a substring from a string. the first argument is the starting index and the second is where you want to finish. if only given one argument it will take from that index to the end of the string. so here you're getting after.substr(1) which will grab all the letters in after starting at index 1 (the second letter)
the whole line is saying 'take the first letter and make it a capital then add all the rest of the letters to the end of it and save it over the original string after'
@Raduuu yeah, https is quite new and being rolled out at the moment. the openweather API and codepen may have changed since the challenge was released.
Palade Radu-Paul
@Raduuu
Jul 15 2016 09:19
hmm, should I file a bug about this?
Keone Martin
@Athaman
Jul 15 2016 09:19
i suspect people are aware of it, it happens a fair bit, but feel free to file one anyway. it's not strictly a bug but it would be nice to update the challenge to avoid this confusion.
Palade Radu-Paul
@Raduuu
Jul 15 2016 09:20
well, I'm trying to use wunderground first
but yes, it's a confusion
96street
@96street
Jul 15 2016 09:21
when you say "then add all the rest of the letters to the end of it" - arn't the rest of the letters already there?
@Athaman
Keone Martin
@Athaman
Jul 15 2016 09:21
there are some fairly easy fixes for it i think... i just can't remember them >.>
96street
@96street
Jul 15 2016 09:21
oh wait i gotcha
yeah i get it now ty @Athaman
CamperBot
@camperbot
Jul 15 2016 09:21
:cookie: 575 | @athaman |http://www.freecodecamp.com/athaman
96street sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
Keone Martin
@Athaman
Jul 15 2016 09:22
@96street strings are immutable (unchangeable) in js so if you say after.charAt(0).toUpperCase(); it will make that letter upper case but not doing anything with it and never change the original string... so you need to catch the result of that, then save it to the variable after... but if you just do that then you'll only have the first letter, so then you have to grab the rest of the letters and add them on before saving it to after
... and maybe i didn't need to type all that :D
also no problem.
96street
@96street
Jul 15 2016 09:23
thankyou for clarifying (yes i already knew) but good to put it into the context of the question
Keone Martin
@Athaman
Jul 15 2016 09:26
yeah, it seems like a lot of work just to make a capital letter :)
Dany Din
@danydin
Jul 15 2016 09:26
@Athaman good morning
Keone Martin
@Athaman
Jul 15 2016 09:27
morning
sophie90909
@sophie90909
Jul 15 2016 09:28
Access MultiDimensional Arrays With Indexes
@Athaman morning
would you be able to help me please
if you have time
Keone Martin
@Athaman
Jul 15 2016 09:28
sure, what's the problem?
Mahmoud AbuHadr
@MahmoudAbuHadr
Jul 15 2016 09:28

I need help
what is wrong with this code

var Car = function() {
this.wheels = 4;
this.engines = 1;
this.seats = 1;
};

// Only change code below this line.

var myCar = new Car();
myCar.neckname = "twin";

it keeps telling me : the property of myCar should be a string
sophie90909
@sophie90909
Jul 15 2016 09:28
you need something in newCar
Keone Martin
@Athaman
Jul 15 2016 09:28
@MahmoudAbuHadr do you mean myCar.nickname?
sophie90909
@sophie90909
Jul 15 2016 09:29
@MahmoudAbuHadr
Haib Zhang
@nperhb
Jul 15 2016 09:29
sophie90909
@sophie90909
Jul 15 2016 09:29
yes i will try
@nperhb
Mahmoud AbuHadr
@MahmoudAbuHadr
Jul 15 2016 09:29
This message was deleted
sophie90909
@sophie90909
Jul 15 2016 09:30
@Athaman

// Setup
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

// Only change code below this line.
var myData = myArray[0][0];

myData should be equal to 8.
You should be using bracket notation to read the value from myArray.
You should only be reading one value from myArray.
Mahmoud AbuHadr
@MahmoudAbuHadr
Jul 15 2016 09:30
yes @Athaman
Jovan
@Jocke86
Jul 15 2016 09:30
Hi campers, can somebody help me with this javascript code:
Nathaniel Nasarow
@Torgian
Jul 15 2016 09:30
yo
Jovan
@Jocke86
Jul 15 2016 09:31
Screenshot_1.png
Nathaniel Nasarow
@Torgian
Jul 15 2016 09:31
I also need a code review, just started intermediate algorithms
Haib Zhang
@nperhb
Jul 15 2016 09:31
@sophie90909 thanks
CamperBot
@camperbot
Jul 15 2016 09:31
nperhb sends brownie points to @sophie90909 :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for sophie90909
Keone Martin
@Athaman
Jul 15 2016 09:31
@sophie90909 what's the challenge name?
@Jocke86 you need to use the .push() and .shift() methods
Rahul Deewan
@deewanrd
Jul 15 2016 09:32
Hello I need some help with "Testing Objects for Properties" challenge, this is my code:

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

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

// Test your code by modifying these values
checkObj("gift");

Keone Martin
@Athaman
Jul 15 2016 09:32
@deewanrd can you copy paste the code here, clicking links resets our code
Jovan
@Jocke86
Jul 15 2016 09:32
Ok, thanks Martin
kirbyedy
@kirbyedy
Jul 15 2016 09:33
@Athaman ty
CamperBot
@camperbot
Jul 15 2016 09:33
kirbyedy sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
:cookie: 576 | @athaman |http://www.freecodecamp.com/athaman
Rahul Deewan
@deewanrd
Jul 15 2016 09:33
Ok.I have done it @Athaman
Keone Martin
@Athaman
Jul 15 2016 09:33
congrats :)
Rahul Deewan
@deewanrd
Jul 15 2016 09:34
@Athaman Have you found some error in my code?
Keone Martin
@Athaman
Jul 15 2016 09:34
oh right, i thought you meant you'd passed it >.>
Dhruv Kumar
@IMDhruv
Jul 15 2016 09:35
@trose1189 Was your Tic tac toe issue fixed?
Keone Martin
@Athaman
Jul 15 2016 09:36
@deewanrd it's to do with using .notation vs [bracket] notation. when you use .variableName it looks for that as a string and doesn't unpack what is stored inside the variable name.
change it to myObj[checkProp] and it should be fine
Rahul Deewan
@deewanrd
Jul 15 2016 09:37
@Athaman It worked. Thank you
CamperBot
@camperbot
Jul 15 2016 09:37
deewanrd sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
:cookie: 577 | @athaman |http://www.freecodecamp.com/athaman
Keone Martin
@Athaman
Jul 15 2016 09:38
you're welcome
Rahul Deewan
@deewanrd
Jul 15 2016 09:39
@camperbot how to do that?
Keone Martin
@Athaman
Jul 15 2016 09:39
camperbot is a bot... he's not a real boy
whenever a message gets sent that includes thanks or ty or similar things and @name he looks for that name and gives them brownie points as a reward for being helpful
CamperBot
@camperbot
Jul 15 2016 09:40
athaman sends brownie points to @name :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for name
Rahul Deewan
@deewanrd
Jul 15 2016 09:41
@Athaman thanks
CamperBot
@camperbot
Jul 15 2016 09:41
deewanrd sends brownie points to @athaman :sparkles: :thumbsup: :sparkles:
:warning: deewanrd already gave athaman points
Keone Martin
@Athaman
Jul 15 2016 09:42
it only lets you do it once an hour or so to stop people abusing it :)
which is why i only offer advice once per hour per individual >.>
Lee
@leebut
Jul 15 2016 09:43
Hello. Could someone explain why this isn't working, please? Challenge , 'Testing Objects for Properties'.
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

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

// Test your code by modifying these values
checkObj("gift");
Dhruv Kumar
@IMDhruv
Jul 15 2016 09:44