These are chat archives for FreeCodeCamp/HelpJavaScript

9th
Aug 2016
Brandon Bowers
@Bowers96
Aug 09 2016 00:07
```js
var oldArray = [1,2,3,4,5];

// Only change code below this line.

var myArray = oldArray.map(function(val) {
  return val + 3;
});
What am I missing?
You should add three to each value in the array.
That is what it says I need to do.
Usmaan Ali
@usyyy
Aug 09 2016 00:08
hello, ive been struggling with generating a dynamic tweet (get the tweet link to contain the selected quote in the text box), can you help?
so far, ive been using the anchor tag to do the tweet, the button is a side project
dont worry about the css, i'll take care of that after the functionality
Stephen James
@sjames1958gm
Aug 09 2016 00:08
@Bowers96 Check the instructions for the result variable (newArray)
Brandon Bowers
@Bowers96
Aug 09 2016 00:09
@sjames1958gm Thank you, going to fast....
CamperBot
@camperbot
Aug 09 2016 00:09
bowers96 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2431 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Brandon Bowers
@Bowers96
Aug 09 2016 00:09
too*
Gryff Coates
@mrbrit2
Aug 09 2016 00:12
¬¬¬
Can anyone working out why this returns [1,2] and not [3]

function slasher(arr, howMany) {
  // it doesn't always pay to be first
  valueOne = arr.splice(0,howMany);
  return valueOne;
}

slasher([1, 2, 3], 2);
Brandon
@Brandons42
Aug 09 2016 00:14
I'm on the challenge Check for Palindromes and I can't figure out how to remove all non-alphanumeric characters with .replace(). Can anyone help me?
CamperBot
@camperbot
Aug 09 2016 00:15
no wiki entry for: regex @brandons42
Stephen James
@sjames1958gm
Aug 09 2016 00:15
@usyyy For your quote button use this:
  var newQuote = quotes[Math.floor(Math.random() * quotes.length)];
  $(".quote").html(newQuote);
  $("a").attr("href", "https://twitter.com/intent/tweet?text=" + newQuote);
Gryff Coates
@mrbrit2
Aug 09 2016 00:16
Wait nevermind i worked it out ^_^
Stephen James
@sjames1958gm
Aug 09 2016 00:16
@usyyy The code outside you click handler only runs once.
Tyler Moeller
@TylerMoeller
Aug 09 2016 00:17
@usyyy The next problem you'll hit is that you'll need to encode the URL for your Tweet so it doesn't stop after apostrophes, semicolons, etc. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
Usmaan Ali
@usyyy
Aug 09 2016 00:21
@sjames1958gm when i do this, the click function doesnt work after the first click?
Greg Duncan
@GregatGit
Aug 09 2016 00:21
@mrbrit2 splice(index, length);
Mike
@MikeJSchorah
Aug 09 2016 00:21
function chunkArrayInGroups(arr, size) {
  var twoD;
  for (var i = 0; i < arr.length && i < arr.size; i++) {
    var sliced = arr.slice(0, size);
    var pull = twoD.push(sliced);
    return pull;
  }
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
Could someone please give me a hint for Chunky Monkey?
Enoch Johnson
@Enocholas
Aug 09 2016 00:21
function myLocalScope() {
  'use strict';
  var loc = "myVar";


  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
Daniel
@clevadani
Aug 09 2016 00:21
Any tips on how to tackle the advanced algorithm scripting challenge Symmetric Difference?? been stuck on it for 3 days now
Enoch Johnson
@Enocholas
Aug 09 2016 00:22
can anybody help me with this? not sure what im doing wrong
Greg Duncan
@GregatGit
Aug 09 2016 00:26
@clevadani I wrote a function that found the sym diff between 2 arrays and then I looped through the arguments
emanual4real
@emanual4real
Aug 09 2016 00:28
Hey
tylerprosper
@removed~tylerprosper
Aug 09 2016 00:28
Hey guys, can somebody explain the purpose behind the i variable inside of results[i] = largestNumber on line 12 of the following code:

function largestOfFour(arr) {
  var results = [];
  for(i=0; i < arr.length; i++){
  var largestNumber = 0;
  for(j=0; j < arr[i].length; j++){
  if(arr[i][j] > largestNumber){
  largestNumber = arr[i][j];
  }
  }

  results[i] = largestNumber;    
  }


  return results;
  }

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
emanual4real
@emanual4real
Aug 09 2016 00:28
freeCodeCamp editor, is there a shortcut to tab to the end and place your semi-colon without having to use the arrow keys?
Enoch Johnson
@Enocholas
Aug 09 2016 00:28
got it, nevermind
Daniel
@clevadani
Aug 09 2016 00:29
@GregatGit looping through the arguments has been my problem. My function exits once it encounters the return keyword. Is there any other keyword that I can use??
Juan Valle
@juanvallecarrillo
Aug 09 2016 00:30
help no repeats please
CamperBot
@camperbot
Aug 09 2016 00:30

:point_right: algorithm no repeats please [wiki]

Algorithm No Repeats Please

: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 task requires us to return the number of total permutations of the provided string that don't have repeated consecutive letters. It is to be assumed that all characters in the provided string are each unique. For example, aab should return 2 because it has 6 total permutations (aab, aab, aba, aba, baa, baa), but only 2 of them (aba and aba) don't have the same letter (in this case a) repeating.

To achieve that, we'll have to look at each possible permutation of a string. There are several ways to do that. A common interview question is building a function that collects all permutations of a string. There are several tutorials available on the internet on how to do that.

Potential Methods Used As Solution

Recursive Method

This task can be daunting even after watching a tutorial. To write a recursive solution, you will want to send each new use of the function three inputs:

  1. A new string (or character array) that is being built.
  2. A position in your new string that's going to be filled next.
  3. An idea of what characters (more specifically positions) from the original string have yet to be used.

:pencil: read more about algorithm no repeats please on the FCC Wiki

Greg Duncan
@GregatGit
Aug 09 2016 00:30
@clevadani can you post what you've done so far
Daniel
@clevadani
Aug 09 2016 00:31
function sym(args) {
  args = Array.prototype.slice.call(arguments);
  var flattened;
  var arr;
  var newarr;
  // flattened is [0, 1, 2, 3, 4, 5]
  for(var i = 0; i < args.length; i++) {
    if(i == args.length - 1) {
      return flattened;
    }else {
      flattened = [args[i], args[i+1]].reduce(function(a, b) {
        return a.concat(b);
      }, []);
    }
  }
  return flattened;

}

sym([5, 2, 1, 4], [1, 2, 3]);
mistake
function sym(args) {
  args = Array.prototype.slice.call(arguments);
  var flattened;
  for(var i = 0; i < args.length; i++) {
    if(i == args.length - 1) {
      return flattened;
    }else {
      flattened = [args[i], args[i+1]].reduce(function(a, b) {
        arr = a.indexOf(b[i]);
        a.splice(arr, 1);
        return a;
      });
    }
  }
  return flattened;

}

sym([5, 2, 1, 4], [1, 2, 3]);
Greg Duncan
@GregatGit
Aug 09 2016 00:33
@clevadani the moment you come to a return statement in a function the function ends returning what ever specified
Daniel
@clevadani
Aug 09 2016 00:35
@GregatGit I know. Is there any other way,, without using return??
Greg Duncan
@GregatGit
Aug 09 2016 00:35
@clevadani write a small function that gets called in the main funciton
@clevadani write a function that takes two arrays and returns the sym difference
Stephen James
@sjames1958gm
Aug 09 2016 00:38
@usyyy You need to calculate a new quote inside your click handler.
var selectedQuote = quotes[Math.floor(Math.random() * quotes.length)];
$(".quote").html(selectedQuote);
/* Need the html change to be the randomly generated quote from the array */

$("#quoteButton").on("click", function() {
  var selectedQuote = quotes[Math.floor(Math.random() * quotes.length)];
  $(".quote").html(selectedQuote);
  $("a").attr("href", "https://twitter.com/intent/tweet?text=" + selectedQuote)
});
Usmaan Ali
@usyyy
Aug 09 2016 00:40
@sjames1958gm Thank you so much!
CamperBot
@camperbot
Aug 09 2016 00:40
usyyy sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2432 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 09 2016 00:40
@tylerprosper You want to put the largest number for the array being processed in the same spot in the arrary.
I would personally use push in this case.
kennyq94
@kennyq94
Aug 09 2016 00:42
hey guys Im back at it again with the basic script what is wrong with my recursion???? it should be returning strings not just one right ?

function repeatStringNumTimes(str, num) {
if(num<1){

return "";
}
else{
repeatStringNumTimes(str, num -1);
}
return str;

}

repeatStringNumTimes("abc", 3);

Daniel
@clevadani
Aug 09 2016 00:43
@GregatGit don't know how to go about it
kennyq94
@kennyq94
Aug 09 2016 00:43

function repeatStringNumTimes(str, num) {
if(num<1){

return "";
}
else{
repeatStringNumTimes(str, num -1);
return str;
}

}

repeatStringNumTimes("abc", 3);

my return was out of the loop but still getting wrong results
Greg Duncan
@GregatGit
Aug 09 2016 00:45
@clevadani I just looked how I did it - I wrote two mini functions inside the main one - one would flatten (get rid of any dupilicates in the arr) and the then the other would find the sys diff between 2 arrs
@clevadani every arr has to be flattened before it can be compared to another arr
Daniel
@clevadani
Aug 09 2016 00:47
@GregatGit ok boss. Let me see if I can do that
Greg Duncan
@GregatGit
Aug 09 2016 00:48
@clevadani so write a function that take two arr
function mySymDiff(arr1, arr2){
   var arr = [];
   // make one arr
   return arr;
}
Stephen James
@sjames1958gm
Aug 09 2016 00:49
@kennyq94 You have to do something with the value from the recursive call
Greg Duncan
@GregatGit
Aug 09 2016 00:50
@clevadani that should work on the first two examples
PETER-IMOISILI JOSHUA OSOISE
@PETER-IMOISILI
Aug 09 2016 00:55
how can i write Convert Celsius to Fahrenheit code?
Daniel
@clevadani
Aug 09 2016 00:59
@GregatGit just made the first function
Greg Duncan
@GregatGit
Aug 09 2016 01:00
@clevadani does it work with the first 2 examples
kennyq94
@kennyq94
Aug 09 2016 01:00
@sjames1958gm yep I just had to add the str to the recursive call... Thanks
return repeatStringNumTimes(str, num -1) + str;
CamperBot
@camperbot
Aug 09 2016 01:00
kennyq94 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2433 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 09 2016 01:01
@kennyq94 :+1:
Mike
@MikeJSchorah
Aug 09 2016 01:03
function chunkArrayInGroups(arr, size) {
  var twoD;
  for (var i = 0; i < arr.length && i < arr.size; i++) {
    var sliced = arr.slice(0, size);
    var pull = twoD.push(sliced);
    return pull;
  }
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
Does anyone know what I'm doing wrong in Chunky Monkey?
JavarriL
@JavarriL
Aug 09 2016 01:05

function rot13(str) { // LBH QVQ VG!
  var str_num;
  var c = [];

  str.split('');
  for(var i = 0; i < str.length; i++) {
    str_num = str.charCodeAt(i);

    if(str_num <= 78) {
      str_num += 13;
    } else if(str_num >= 79) {
      str_num += 13;
      str_num -= 90; //If the new value goes over z, put it back at the beginning of the alphabet
      str_num += 64;
    }

    str_num = String.fromCharCode(str_num);
    c.push(str_num);
  }

  c = c.join('');
  c = c.replace(/-/gi, " ");

  c = c.replace(/;/, ".");
  return c;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
"Caesars Cipher ". The N is supposed to return A but it's returning brackets. Can anyone explain to me where I went wrong and why?
zacharydylan
@zacharydylan
Aug 09 2016 01:05
@MikeJSchorah you have an extra variable(pull), this also means that you could initialize twoD as an empty array outside of your loop. And you need to manipulate what you are slicing with your loop(and possibly increment with a variable). The other option is to use splice and manipulate the size of your loop.
@MikeJSchorah you also don't need two conditionals on the size of your loop. I don't know enough to say if that even works.
Daniel
@clevadani
Aug 09 2016 01:07
@GregatGit no, didn't work
Greg Duncan
@GregatGit
Aug 09 2016 01:07
@clevadani what did you do?
nmaca
@nmaca
Aug 09 2016 01:08
I need help with Title Case a sentence.
'''
CamperBot
@camperbot
Aug 09 2016 01:08
:bulb: to format code use backticks! ``` more info
nmaca
@nmaca
Aug 09 2016 01:08
This message was deleted
This message was deleted
CamperBot
@camperbot
Aug 09 2016 01:08
:bulb: to format code use backticks! ``` more info
Greg Duncan
@GregatGit
Aug 09 2016 01:09
@nmaca ``` not '''
CamperBot
@camperbot
Aug 09 2016 01:09
:bulb: to format code use backticks! ``` more info
Daniel
@clevadani
Aug 09 2016 01:09
function sym(args) {
  args = Array.prototype.slice.call(arguments);
  var arr1 = args[0];
  var arr2 = args[1];
  var flattened;
  var newarr;
  function mySymDiff(arr1, arr2){
      flattened = [arr1, arr2].reduce(function(a, b) {
        return a.concat(b);
      }, []);
  }
  return flattened;


}

sym([5, 2, 1, 4], [1, 2, 3]);
nmaca
@nmaca
Aug 09 2016 01:10
function titleCase(str) {
  var strSplit = str.toLowerCase().split(" ");
  for (i = 0; i<strSplit.length; i++) {
    var placeholder = strSplit[i];
    var upCase = placeholder.charAt(0).toUpperCase();
var lowCase = placeholder.slice(1,placeholder.length);
    var finalString = upCase.concat(lowCase); 
  finalString.join(" ");

  } 


}

titleCase("I'm a little tea pot");
It says final string joined is not a function (i forgot return, still says that)
Greg Duncan
@GregatGit
Aug 09 2016 01:11
@clevadani you should have somewhere
var flattened = mySymDiff( arr1, arr2);
Jaren Escueta
@jarenescueta731
Aug 09 2016 01:12
@JavarriL still have the caesar's cipher problem?
Luke
@lukenetti3
Aug 09 2016 01:12
Hey guys, I am working on the Diff Two Arrays challenge and having a hard time getting started. I am trying to look at one array and compare the first value of that with the rest of the values in the other array and so on with for loops. Am I approachung this wrong?
Greg Duncan
@GregatGit
Aug 09 2016 01:13
@clevadani don't use arr1 when writing the function give it a unique name
DJ
@qualitymanifest
Aug 09 2016 01:15
@nmaca that's because finalString is a string... you can't join a string. thats an array method
JavarriL
@JavarriL
Aug 09 2016 01:15
@jarenescueta731 Yep
Jaren Escueta
@jarenescueta731
Aug 09 2016 01:16
@JavarriL you're only one number off with translating, use <=77 and >=78 instead
the N wasn't being changed properly
JavarriL
@JavarriL
Aug 09 2016 01:19
@jarenescueta731 Thanks a lot, I was looking at that, but when I changed the values it was all off. One more thing, Do you know how to say "If a value is a letter"?
CamperBot
@camperbot
Aug 09 2016 01:19
javarril sends brownie points to @jarenescueta731 :sparkles: :thumbsup: :sparkles:
:cookie: 349 | @jarenescueta731 |http://www.freecodecamp.com/jarenescueta731
Jaren Escueta
@jarenescueta731
Aug 09 2016 01:21
@JavarriL you can find the ranges for the charCodes of a-z and A-Z, and if charCodeAt is between those then it's a letter
not sure if there is an easier way
@JavarriL oh, you could also use regex
Daniel
@clevadani
Aug 09 2016 01:25
@GregatGit I'm confused
JavarriL
@JavarriL
Aug 09 2016 01:25
@jarenescueta731 I was thinking of /a-z-A-Z/ but I forgot how to do the syntax. Thanks a lot, this was a much easier way
CamperBot
@camperbot
Aug 09 2016 01:25
javarril sends brownie points to @jarenescueta731 :sparkles: :thumbsup: :sparkles:
:warning: javarril already gave jarenescueta731 points
Jaren Escueta
@jarenescueta731
Aug 09 2016 01:26
@JavarriL regex101.com is great for testing regex
/[a-zA-Z]/g for all letters
Jacob Stewart
@JacobStewart1
Aug 09 2016 01:28
does anybody want to pair for the wikipedia viewer project
Greg Duncan
@GregatGit
Aug 09 2016 01:29
@clevadani the function should be independent - so it can take in any arrs you give it and it returns a new arr. Then you need to call it
Everton Volpi
@evolpi
Aug 09 2016 01:33
does anybody can help me with the lesson "Return Early Pattern for Functions"?
I thought that the solution is something like:
if (a < 0 || b < 0) {
return "undefined";
}
Teresa Garriot
@garriottteresa
Aug 09 2016 01:35
I have been stuck on the "Record Collection for quite a few sessions. Can't really search google since I do not know how to ask what I don't know.
bitgrower
@bitgrower
Aug 09 2016 01:35
well you do have to return something if a or b isn't less than zero @evolpi
Teresa Garriot
@garriottteresa
Aug 09 2016 01:36

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

// Only change code below this line
function updateRecords(id, prop, value) {
 ( collection[0] = updateRecords[0],
    collection[0.1] = updateRecords[1],
     collection[0.1.2] = updateRecords[2]);

  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
bitgrower
@bitgrower
Aug 09 2016 01:36
@garriottteresa -- there's usually a message about posting your code in a gist ... but I'm not seeing it right now ... maybe you can post your code in a javascript playground like pythontutor.com/javascript.html ?
@garriottteresa -- you have to process the parameters as described in the instructions ...
John
@jpls93
Aug 09 2016 01:37
Is it just me, or are the Advanced Algorithm Challenges not required for the certification? (They don't have an asterisk if you don't finish them)
bitgrower
@bitgrower
Aug 09 2016 01:37
dunno @johnsalcedonetwork -- I know they are re-doing the curriculum ...
John
@jpls93
Aug 09 2016 01:38
I see.. thanks @bitgrower
CamperBot
@camperbot
Aug 09 2016 01:38
johnsalcedonetwork sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star2: 1173 | @bitgrower |http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Aug 09 2016 01:38
yw ...
Teresa Garriot
@garriottteresa
Aug 09 2016 01:40
I struggle to figure out how to code the return statement. I don't see where I need to use the push. guess this challenge is still above my knowledge
bitgrower
@bitgrower
Aug 09 2016 01:41

@garriottteresa to be perfectly honest, I have no idea what you are even trying to do with thecode you put in the function ... do you mean to be using recursion? And I have no clue what collection[0.1] means...

updateRecords[0] doesn't make a lot of sense either, as it seems like you are trying to use updateRecords as an array, and updateRecords is a function ... unless you meant for your updateRecords references to be collection instead ..

@garriottteresa could be ... go review the previous challenges involving objects ...
Everton Volpi
@evolpi
Aug 09 2016 01:42
@bitgrower actually the complete code was:
function abTest(a, b) {
if (a < 0 || b < 0) {return undefined;}
else {return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));}
}
abTest(2,2);
bitgrower
@bitgrower
Aug 09 2016 01:43
so, how do you know which part is broken if your tests aren't passing?
Everton Volpi
@evolpi
Aug 09 2016 01:43
@bitgrower I didn't explain very well, sorry!
And thanks very much for your help!
CamperBot
@camperbot
Aug 09 2016 01:43
evolpi sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star2: 1174 | @bitgrower |http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Aug 09 2016 01:43
yw
Everton Volpi
@evolpi
Aug 09 2016 01:45
so, how do you know which part is broken if your tests aren't passing? @bitgrower I used "undefined", but it was just undefined, witthout quotes
bitgrower
@bitgrower
Aug 09 2016 01:45
@evolpi the code as you posted above passes all tests when I put it into the challenge ...
ah yes ... that will do it ...
pat yourself on the back for finding the problem !!! :)
Everton Volpi
@evolpi
Aug 09 2016 01:46
@bitgrower :smile: just did... thanks for the help
CamperBot
@camperbot
Aug 09 2016 01:46
evolpi sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:warning: evolpi already gave bitgrower points
Teresa Garriot
@garriottteresa
Aug 09 2016 01:47
thanks @bitgrower I am trying to define what definition of id, prop, and value are. Don't know how to code the return to show the entirecollection. although I am not totally wrong I go code written in the answer area and a couple of geen Checks.
CamperBot
@camperbot
Aug 09 2016 01:47
garriottteresa sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star2: 1175 | @bitgrower |http://www.freecodecamp.com/bitgrower
tylerprosper
@removed~tylerprosper
Aug 09 2016 01:49
@sjames1958gm thx
CamperBot
@camperbot
Aug 09 2016 01:49
tylerprosper sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2434 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 09 2016 01:51
@tylerprosper :+1:
Eddie
@Ndaraya
Aug 09 2016 01:54
Thanks @leftynaut for your help with Checkpoint: Profile Lookup
CamperBot
@camperbot
Aug 09 2016 01:54
ndaraya sends brownie points to @leftynaut :sparkles: :thumbsup: :sparkles:
:cookie: 543 | @leftynaut |http://www.freecodecamp.com/leftynaut
Luke
@lukenetti3
Aug 09 2016 01:58
Hey guys, I am working on the Diff Two Arrays challenge and having a hard time getting started. I am trying to look at one array and compare the first value of that with the rest of the values in the other array and so on with for loops. Am I approachung this wrong?
Stephen James
@sjames1958gm
Aug 09 2016 01:59
@garriottteresa id is a parameter (variable) that will contain an album id that can be used to select an album from the collection.
prop is a parameter (variable) that will contain a property name of an album property, such as track, artist, etc.
value is either the value apply to the propert (value !== "") or the empty string, indicating that the property is to be removed.
Ken Haduch
@khaduch
Aug 09 2016 02:01

@garriottteresa - how are you doing with this? If you are still trying to figure out id, prop, and value - if you look at the function calls that they give as the example in the editor window, or the test results, you see something like


updateRecords(5439, "artist", "ABBA");

The first argument (5439 in this example) is an "id" of a record or record album in the collection. It is "tied" to the variable id within the function updateRecords. Similarly for "artist" - refers to the musical artists that are part of the recording objects in the collection. It is tied to the variable prop in the function. "ABBA" in this example is the value (or name of a musical artist, in this case) and is tied to the function argument value. You use those names id, prop, and value within the function code to make changes to the particular collection object, as the instructions direct you to do.

John
@jpls93
Aug 09 2016 02:07
who wants to pair on ExactChange?
Ryan
@rmo005
Aug 09 2016 02:07
Anyone want to answer an easy question on incrementing numbers with JavaScript?
Stephen James
@sjames1958gm
Aug 09 2016 02:07
@rmo005 Sure
Ken Haduch
@khaduch
Aug 09 2016 02:08
@lukenetti3 - that is something that you can do, or you can use one of the array methods like .filter() to do that same comparison.
Ryan
@rmo005
Aug 09 2016 02:08
@sjames1958gm The challenge is to take var myVar = 87; and set myVar = 88
Luke
@lukenetti3
Aug 09 2016 02:08
@khaduch I tried that but had trouble. How can I use filter to compare two different arrays?
Stephen James
@sjames1958gm
Aug 09 2016 02:09
@rmo005 Ok. so what code is there before you change it?
Ryan
@rmo005
Aug 09 2016 02:09
The original code was myVar = myVar +1;
I changed it to myVar=++myVar;
Stephen James
@sjames1958gm
Aug 09 2016 02:09
@rmo005 Ok, in the example code they said you can replace i = i + 1 with i++ so what should you replace that with?
@rmo005 It looks as though you only made a partial substitution?
Ryan
@rmo005
Aug 09 2016 02:11
Maybe? The console shows that myVar = 88. But it doesn't pass the "myVar = myVar should be changed" test
If I write myVar = myVar++; - the console shows myVar = 87
Stephen James
@sjames1958gm
Aug 09 2016 02:13
@rmo005 Replace all of myVar = myVar + 1
Ken Haduch
@khaduch
Aug 09 2016 02:13
@lukenetti3 - you can make a comparison function (I guess you would call it the filter function) that will be operating on one of the arrays (say, arr1) and passing arr2 as the argument that you will be comparing against. .filter() just sequentially looks at each element of the array and does the comparison through the filtering function. So you could use something like .indexOf and decide if an element in arr1 does or does not exist in arr2.
Luke
@lukenetti3
Aug 09 2016 02:17
@khaduch Okay I think I see what your saying. I was thinking now to just have a for loop and call the indexOf the element from arr1 to check if its in array 2. If I get a -1 I was going to store that value in an array. Would that work as well?
Ryan
@rmo005
Aug 09 2016 02:18
@sjames1958gm I'm sure I'm being dense, but what do you mean by replace all of it?
Stephen James
@sjames1958gm
Aug 09 2016 02:18
@rmo005 Replace the entire line with the new code. The example says i = i + 1 can be replaced by i++
@lukenetti3 That should work. You will have to make the opposite loop as well.
@lukenetti3 Meaning checking for arr1 vs. arr2 then arr2 vs. arr1
John Magee
@jemagee
Aug 09 2016 02:21
In javascript objects can you retrieve the KEY if you know the value or is it only a one way identification?
Stephen James
@sjames1958gm
Aug 09 2016 02:21
@jemagee Other than by brute force, no you cannot go from value to key (as there could be multiple keys with same value)
Luke
@lukenetti3
Aug 09 2016 02:22
@sjames1958gm Yeah I see. To check arr2 for values in arr1. When I try to assign that value into my newArr, its only spitting out a single value. I have created var newArr = [] before that call, but why isn’t it putting that number into the array instead of just the number itself?
John Magee
@jemagee
Aug 09 2016 02:22
ah well - so much for the 'exquisite' DNA solution :)
Stephen James
@sjames1958gm
Aug 09 2016 02:22
@lukenetti3 Assign or push?
Ken Haduch
@khaduch
Aug 09 2016 02:23
@lukenetti3 - yes, it should work. Effectively, the .filter() is going to do a lot of that same work for you - but you should be able to do for loops and tests. Go for it!
Luke
@lukenetti3
Aug 09 2016 02:23
@khaduch Okay, thanks!
CamperBot
@camperbot
Aug 09 2016 02:23
lukenetti3 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 1521 | @khaduch |http://www.freecodecamp.com/khaduch
Luke
@lukenetti3
Aug 09 2016 02:23
@sjames1958gm I think I got it. I just used push. Thanks!
CamperBot
@camperbot
Aug 09 2016 02:23
lukenetti3 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2436 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 09 2016 02:23
@khaduch :+1: .filter will build the result array for you
John Magee
@jemagee
Aug 09 2016 02:29
Dear Javascript -you aren't that strict a language - please disposes of the 'use the word var' requirement -
x981
@x981
Aug 09 2016 02:31
I'm at https://www.freecodecamp.com/challenges/exact-change challenge, Can anyone explain to me this case: " checkCashRegister(19.50, 20.00, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.10], ["QUARTER", 4.25], ["ONE", 90.00], ["FIVE", 55.00], ["TEN", 20.00], ["TWENTY", 60.00], ["ONE HUNDRED", 100.00]]) should return [["QUARTER", 0.50]]" => Why is QUATER which is not PENNY or other?
Lily5912
@Lily5912
Aug 09 2016 02:32

Hi. I'm having trouble with storing values with Assignment operator: In JavaScript, you can store a value in a variable with the assignment operator.

myVariable = 5;

Assigns the Number value 5 to myVariable.

Assignment always goes from right to left. Everything to the right of the = operator is resolved before the value is assigned to the variable to the left of the operator.

myVar = 5;           myNum = myVar;

Assigns 5 to myVar and then resolves myVar to 5 again and assigns it to myNum.
Instructions"
Assign the value 7 to variable a.
Assign the contents of a to variable b.

Ken Haduch
@khaduch
Aug 09 2016 02:34
@Lily5912 - hello. Assign the value 7 to variable a is like myVar = 5; and Assign the contents of a to variable b. is like myNum = myVar; If you are creating the variables, you have to use the keyword var, at least that is probably what is expected.
John Magee
@jemagee
Aug 09 2016 02:34
@x981 Love to help you but that is a poorly worded exercise - sheesh
Ken Haduch
@khaduch
Aug 09 2016 02:35

@x981 - I think that you want to use the largest value coins in the drawer, as many as exist. If you only had one QUARTER, then you would have to move on the dimes, nickels, pennies to try and finish making the change. I think that's what you are looking for?

Otherwise, return change in coin and bills, sorted in highest to lowest order - highest to lowest order, implies that you have to try and use the largest value currency or coins to make change, and work your way down the list.

Mike
@MikeJSchorah
Aug 09 2016 02:39
function chunkArrayInGroups(arr, size) {
  var twoD = [];
  for (var i = 0; i < arr.length && i < arr.size; i++) {
    twoD += size.slice(0, arr);
    var pull = twoD.push(sliced);
    return pull;
  }
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
Please let me know what is wrong with my answer for Chunky Monkey.
Lily5912
@Lily5912
Aug 09 2016 02:40
@khaduch Thank you! I got it! Finally!
CamperBot
@camperbot
Aug 09 2016 02:40
lily5912 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 1522 | @khaduch |http://www.freecodecamp.com/khaduch
John Magee
@jemagee
Aug 09 2016 02:44
is it just me or do you hardly ever use the 'suggested' methods - like for the missing letter i didn't use char code or charcode at
Mike
@MikeJSchorah
Aug 09 2016 02:44
@jemagee For which exercise?
Santiago Gómez
@Sperkajugglite
Aug 09 2016 02:44
@jemagee sometimes :P
John Magee
@jemagee
Aug 09 2016 02:45
@MikeJSchorah the missing letters exercise - i used the charcodeat some other time though
function fearNotLetter(str) {
  var alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
  var x = alphabet.indexOf(str[0]);
  var y = [];
  for(i=0; i < str.length; i++  ) {
    if (str[i] == alphabet[x]) {
      y.push(str[i]);
      x += 1;
    } else {
      return alphabet[x];
    }
  }
  return undefined;
}
Mike
@MikeJSchorah
Aug 09 2016 02:46
Oh, you're way ahead of me @jemagee haha
John Magee
@jemagee
Aug 09 2016 02:46
ignore the y stuff - i was just testing something
Ken Haduch
@khaduch
Aug 09 2016 02:46
@Lily5912 - great! You have to get used to the problem statements as much as how to solve the problems... Sometimes studying the test results aids quite a bit in figuring it all out, too.
Mike
@MikeJSchorah
Aug 09 2016 02:46
@jemagee Did you figure out Chunky Monkey?
John Magee
@jemagee
Aug 09 2016 02:46
ok - well don't steal my answer cause it won't do you any good
mike - which one is chunky monkey - i've completed all the exercise up to the missing letters - however i didn't do twitc tv, wikipedia, or a portfolio project page - i'll go back to them
x981
@x981
Aug 09 2016 02:47
Thanks a lot @khaduch
CamperBot
@camperbot
Aug 09 2016 02:47
x981 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 1523 | @khaduch |http://www.freecodecamp.com/khaduch
I am not familiar with blackjack, can someone help me out?
Mike
@MikeJSchorah
Aug 09 2016 02:48
@jemagee It's where you write a function that splits an array into groups the length of size and returns them as a two dimensional array.
function chunkArrayInGroups(arr, size) {
  var twoD = [];
  for (var i = 0; i < arr.length && i < arr.size; i++) {
    twoD += size.slice(0, arr);
    var pull = twoD.push(sliced);
    return pull;
  }
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
Lekecia Entrot
@GurlFriday88
Aug 09 2016 02:49
Justin Clark
@jeclark9063
Aug 09 2016 02:51
Hey guys - I am making a logical error with my for loop for this exercise but can't seem to figure out how to set the loop up correctly, any hints would be appreciated!

function chunkArrayInGroups(arr, size) {
  var newarr = [][5];
  var start = 0;
  var hold = [];


  for (var i = 0; i <= arr.length / size; i++){
    hold[i] = arr.slice(start, size);
    start = start + size;
    size = size + size;
    newarr = hold;
  }

  return newarr;
}
chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3);
John Magee
@jemagee
Aug 09 2016 02:51
@MikeJSchorah Mike - return exits a method - if you put it in your return loop it's only going to run through the array passed in once. - so I think you've written it backwards - also - you indicated 'sliced' haven't defined sliced, and I'm not sure what your doing with a compound argument in your for loop
@jeclark9063 Why are you defining newarr as [][5]?
Justin Clark
@jeclark9063
Aug 09 2016 02:52
@jemagee I'm used to c++ do you not have to define a length for a 2d array in JS?
Luke
@lukenetti3
Aug 09 2016 02:52
Hey guys, if I want to remove null values form an array, can I do it this way? newerArr = newArr.filter(function(val) {
return val !== null;
});
John Magee
@jemagee
Aug 09 2016 02:53
@jeclark9063 you don't have define a length for a 2d array in JS - JS is not a strict language
Justin Clark
@jeclark9063
Aug 09 2016 02:53
@jemagee alright cool - any advice on the for loop? it works for certain ones but I'm not using the correct math because it fails on others
John Magee
@jemagee
Aug 09 2016 02:53
can one of you post the link to the exercise so i can see it from the beginning - i need to refresh my brain
x981
@x981
Aug 09 2016 02:54
@pelicanscarecrow you set a variable, case 2,3,4,5,6 variable +1, case 7,8,9 variable not change, and case 10, j, q, k ,a variable -1. At last check variable, if > 0 then set variable + "Bet" else variable + "hold"
John Magee
@jemagee
Aug 09 2016 02:55
@jeclark9063 don't make your 'end of the for loop' so complicated AND look at your increment - I just looked at my solution and my for loop had one line of code
write out the pseudo code first - what do you want to do on EACH loop ?
Justin Clark
@jeclark9063
Aug 09 2016 02:57
@jemagee i'll go over it again - just realized i didn't need the hold variable too
Ken Haduch
@khaduch
Aug 09 2016 02:57
@jeclark9063 - usually you need i < arr.length, because the length is 1 greater than the highest index.
Justin Clark
@jeclark9063
Aug 09 2016 02:58
@khaduch yes, but you don't need to iterate through the array that many times.
John Magee
@jemagee
Aug 09 2016 02:58
@jeclark9063 it's not your whole issue - but it's a start - your for loop is started off wrong - if you have c++ experience just dump all the code you wrote - hit that reset button in the left bottom and think about the problem just as pseudo code WHAT should happen on each loop
Justin Clark
@jeclark9063
Aug 09 2016 02:58
@jemagee will do thanks
CamperBot
@camperbot
Aug 09 2016 02:58
jeclark9063 sends brownie points to @jemagee :sparkles: :thumbsup: :sparkles:
:cookie: 290 | @jemagee |http://www.freecodecamp.com/jemagee
John Magee
@jemagee
Aug 09 2016 02:59
@jeclark9063 ok - you're on the right track - but the way you've set it up you will only go through a PORTION of your array - think about what the last part of the for statement does
Luke
@lukenetti3
Aug 09 2016 02:59
How can I remove null values from my array? I tried this, newerArr = newArr.filter(function(val) {
return val !== null;
}); but its not working. I plugged in other values to remove and it worked but for some reason this didn’t work.
Ken Haduch
@khaduch
Aug 09 2016 02:59
@jeclark9063 - sorry, I didn't completely look at the code and problem description... my bad...
Mateusz Szymański
@matszym
Aug 09 2016 03:00
@lukenetti3 Looks like values you are trying to filter are not null, your code should work
Bearded One
@EpicBeard
Aug 09 2016 03:00
Anyone on?
Luke
@lukenetti3
Aug 09 2016 03:01
@matszym What do you mean? I will try and paste my code.
function diffArray(arr1, arr2) {
  var newArr = [];
  var newerArr = [];

  var arrLength = Math.max(arr1.length,arr2.length); 
  var val;


  for (var i = 0; i < arrLength; i++) {
    val = arr1.indexOf(arr2[i]);
    if (val == -1) {
      newArr.push(arr2[i]);

    }
  }

 if (arr1.length > arr2.length || arr1.length == arr2.length) {

   for (var j = 0; j < arrLength; j++) {
    val = arr2.indexOf(arr1[j]);
    if (val == -1) {
      newArr.push(arr1[j]);

    }
  }
 }


  newerArr = newArr.filter(function(val) {
      return val !== null;
   });



  return newerArr;
}

diffArray([1, "calf", 3, "piglet"], [7, "filly"]);
Mateusz Szymański
@matszym
Aug 09 2016 03:06

@lukenetti3 I just tested this part

  newerArr = newArr.filter(function(val) {
      return val !== null;
   });

Nothing wronge here, null gets removed

Mike
@MikeJSchorah
Aug 09 2016 03:08
function chunkArrayInGroups(arr, size) {
  var twoD = [];
  for (var i = 0; i < arr.length; i++) {
    twoD += size.slice(0, arr);
    var pull = twoD.push(size);
  }
  return pull;
}
@jemagee Does this look any better?
Luke
@lukenetti3
Aug 09 2016 03:08
@matszym Hmm it wasn’t working for me. I got it working anyway. I decided to get rid of my if statement and push the different values onto 2 separate arrays and then just concatonate them. It was easier than trying to remove the null values. Thanks for your help though!
CamperBot
@camperbot
Aug 09 2016 03:08
lukenetti3 sends brownie points to @matszym :sparkles: :thumbsup: :sparkles:
:cookie: 125 | @matszym |http://www.freecodecamp.com/matszym
Bearded One
@EpicBeard
Aug 09 2016 03:09
Need a little help here. I have a form that has input fields for full name, email, and telephone number and are all required. I'm do some JS making each one's id.value a variable, then throwing those variables into an array. I loop through the array to check to see if they have a value of "" and to alert a thing saying they need to fill them
problem is, you can fill one or two and leave one blank and it fires the alert saying everything is cool but in fact, it's not and doesn't even send the email
Here's my code
John Magee
@jemagee
Aug 09 2016 03:10
@MikeJSchorah Mike - I wish i could say yes - but it just looks different - you've declared a var pull within your for loop - you're redefining it every time you go through the loop - and think about the point of the exercise and look at your increment step
Bearded One
@EpicBeard
Aug 09 2016 03:10
function validateForm() {
                                var a = document.getElementById("full_name").value;
                                var b = document.getElementById("telephone").value;
                                var c = document.getElementById("email").value;

                                var fields = [a, b, c];

                                for(i = 0; i <= fields.length; i++) {
                                    if (fields[i] == "") {
                                        alert("Please fill in all fields.");
                                        return false;
                                    } else {
                                        alert("Thank you for contacting Dev with a Beard. The Bearded One will contact you soon.");
                                        return true;
                                    }
                                }
                            }
Alexios Pantavos
@AlexiosP
Aug 09 2016 03:11

@MikeJSchorah You have mixed up so much the variables in these 2 lines:

    twoD += size.slice(0, arr);
    var pull = twoD.push(size);

You don't need any news variables, also size is a number.

Mateusz Szymański
@matszym
Aug 09 2016 03:11
@MikeJSchorah looks wrong. first of all, twod is array. You cant 'add' anything to array with '+' operator. Second slice accepts numbers, and you are passing array as second argument

@MikeJSchorah third

var pull = twoD.push(size);

pull witll have value of size, so you could just remove all your code, and return size, you will achive same effect, since you dont change size in your code at all

@MikeJSchorah another thing,

size.slice(0, arr)

If I recall correctly, there is not slice method on Numbers, and if size is Number, its not going to work

John Magee
@jemagee
Aug 09 2016 03:15
Is it just me or is indexOf very very useful in so many of these exercises and they never tell you to look at it :)
Alexios Pantavos
@AlexiosP
Aug 09 2016 03:16
@tom103 Consider declaring a boolean outside the for loop and update it as needed inside the for loop
@tom103 After the loop, show an alert based on the boolean
At the moment, after the check on fields[i]=="" with i=0, the function will exit without checking the rest of the values
Mateusz Szymański
@matszym
Aug 09 2016 03:19

@tom103 move else block after for loop

                                        alert("Thank you for contacting Dev with a Beard. The Bearded One will contact you soon.");
                                        return true;

Now, if a field is ommited, you will return false and alert "Please fill in all fields"
if loop ends, you alert "thank you (...)"

@AlexiosP if he does that, he will check just last field, since he will overwrite previous value of bolean
Alexios Pantavos
@AlexiosP
Aug 09 2016 03:20
@matszym Negative. I said "as needed"
Mateusz Szymański
@matszym
Aug 09 2016 03:20
@AlexiosP ok then
Reyner
@ReynerAL
Aug 09 2016 03:20

I am having a problem with this code..
function nextInLine(arr, item) {
// Your code here
arr.push(item);
arr.shift(0);
return item; // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

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

how do i make nextInLine([2], 1) return 2??
Sabrina Ferguson
@itsacoyote
Aug 09 2016 03:21
@ReynerAL you're close. arr.shift(0) is going to return an item, is it the item you want to return?
Alexios Pantavos
@AlexiosP
Aug 09 2016 03:22
var showFillAlert = false;
for(....)
if(fields[i]=="")
showFillAlert = true;

if (showFillAlert)
alert("You miss some fields");
else
alert("All good");
@matszym @tom103
Robert Richey
@0x0936
Aug 09 2016 03:23
@ReynerAL while it's not an error, .shift() doesn't take any arguments. it will instead ignore anything passed into it - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift
Greg Duncan
@GregatGit
Aug 09 2016 03:25
can anyone tell me why this returns undefined?
var arr = [1 , 2 ,3 ,4, 5, 6];

var newArr  = arr.filter(function(num){
    return num % 2 === 0;    
});
console.log("this is " + newArr);
Mateusz Szymański
@matszym
Aug 09 2016 03:25
@GregatGit if you dont return anything, function returns undefined by default
Greg Duncan
@GregatGit
Aug 09 2016 03:26
@matszym thanks for that - very handy to know
CamperBot
@camperbot
Aug 09 2016 03:26
gregatgit sends brownie points to @matszym :sparkles: :thumbsup: :sparkles:
:cookie: 126 | @matszym |http://www.freecodecamp.com/matszym
Reyner
@ReynerAL
Aug 09 2016 03:26
@itsacoyote I don't know what to return there .-.
@0x0936 so.. what should I do?? pretty much confused here..
Robert Richey
@0x0936
Aug 09 2016 03:27
@GregatGit your code prints [2, 4, 6] for me
Mateusz Szymański
@matszym
Aug 09 2016 03:27
@0x0936 and then returns undefined ;)
Sabrina Ferguson
@itsacoyote
Aug 09 2016 03:28
@ReynerAL as @0x0936 said, shift doesn't take anything, it gives something back. The final return of this function is to give back that item.
Mateusz Szymański
@matszym
Aug 09 2016 03:29

@0x0936 @GregatGit basicly console.log() doesnt return anything, and since thats the case undefined is returned by default

var returned = console.log('Hello world')

Value of returned is undefined

Sabrina Ferguson
@itsacoyote
Aug 09 2016 03:29
@ReynerAL so it would be better to assign a variable to whatever shift is returning, then return that variable to complete the function
Greg Duncan
@GregatGit
Aug 09 2016 03:30
@matszym I thought i was missing something but the now I know not to worry
Reyner
@ReynerAL
Aug 09 2016 03:31
@itsacoyote Ah!! I understand now!
thank you!
CamperBot
@camperbot
Aug 09 2016 03:31
reyneral sends brownie points to @itsacoyote :sparkles: :thumbsup: :sparkles:
:cookie: 334 | @itsacoyote |http://www.freecodecamp.com/itsacoyote
Bearded One
@EpicBeard
Aug 09 2016 03:39
@matszym , that did the trick!! Thank you!!
CamperBot
@camperbot
Aug 09 2016 03:39
tom103 sends brownie points to @matszym :sparkles: :thumbsup: :sparkles:
:cookie: 127 | @matszym |http://www.freecodecamp.com/matszym
Chris
@CBedzz
Aug 09 2016 03:51
Is there a better way to turn a variable into a truthy/falsy than !!variableName ?
or more accepted
Farrukh
@Farrukhw
Aug 09 2016 03:52
@MikeJSchorah Why using i<arr.size? I think arr.length is enough!
it should be twoD+=arr.slice,
cherry-geqi
@cherry-geqi
Aug 09 2016 03:54
@CBedo Boolean()
Chris
@CBedzz
Aug 09 2016 03:56
thanks
I'm an idiot. I wasn't capitalizing it..... :(
Mike
@MikeJSchorah
Aug 09 2016 03:59
function chunkArrayInGroups(arr, size) {
  var twoD = [];
  for (var i = 0; i < arr.length; i++) {
    twoD += arr.slice(0, size);
    twoD.push(arr);
  }
  return twoD;
}
Do you have anymore hints, guys? Here is where I am on Chunky Monkey now...
Tim
@x-yz
Aug 09 2016 04:00
return String.fromCharCode(prevVal + 1);
why does that return undefined?
if i type console.log(String.fromCharCode(prevVal + 1)); it returns a letter
i want it to return a string of length one with a character generated from the charCode prevVal + 1
hai.pn
@firefoxvt
Aug 09 2016 04:15
This message was deleted

Hi all, I have a stuck in Record Collection. This is my code:

function updateRecords(id, prop, value) {
  if(prop != "tracks" && value !== "") {

    collection[prop].push(value); 

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

    collection[id].tracks = [];
    collection[id].tracks.push(value);

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

    collection[id].tracks.push(value);

  } else if (value === "") {

    collection.pop(prop);
  }

  return collection;
}

I think I use barracket and dot correctly.

Ryan
@rmo005
Aug 09 2016 04:16
I'm very lost on "Local Scope and Functions"
hai.pn
@firefoxvt
Aug 09 2016 04:20
hi
Jacob Wernerowski
@JacobJW
Aug 09 2016 04:21
Hey guys, I'm not sure what exactly is wrong with my code for the Sum All Numbers in a Range challenge.
function sumAll(arr) {
  var total = 0;
  for (var num = Math.min(arr); num <= Math.max(arr); num++)
    {
      total += num;
    } 
  return total;
} 

sumAll([1, 4]);
Mateusz Szymański
@matszym
Aug 09 2016 04:21
@x-yz it works fine
function test(prev) {
  return String.fromCharCode(prev + 1);
}
test(70) // returns 'G'
hai.pn
@firefoxvt
Aug 09 2016 04:21
This message was deleted
Mateusz Szymański
@matszym
Aug 09 2016 04:22
@JacobJW are you sure Math.min and Math.max accepts array of arguments?
Thomas Gerot
@tjgerot
Aug 09 2016 04:22
Yes
@matszym
Jacob Wernerowski
@JacobJW
Aug 09 2016 04:23
@matszym ahh I see. I guess I'm too used to the easy ways of Python
Mateusz Szymański
@matszym
Aug 09 2016 04:23
@tjgerot did you just google it, or are you actually familiar with the content?
Thomas Gerot
@tjgerot
Aug 09 2016 04:23
Yes.
I'm mostly a Python guy, but JS is my second best language.
ya know... max(stuff)
Jacob Wernerowski
@JacobJW
Aug 09 2016 04:24
@matszym I suppose I could sort the array, and set the starting point as arr[0] and the end as arr[1] then?
@tjgerot high five for python!
Thomas Gerot
@tjgerot
Aug 09 2016 04:24
The language of efficiency!
Jacob Wernerowski
@JacobJW
Aug 09 2016 04:25
I miss some of it's niceties, but I can 100% get why JS is so awesome. I actually like JS for loops more tbh
Mateusz Szymański
@matszym
Aug 09 2016 04:25

@JacobJW You dont have to, you can still use max and min, with apply trick. apply alows you to bind array of arguments to function

Math.max.apply(null, arrayOfArguments)

Robert Richey
@0x0936
Aug 09 2016 04:25
Math.max(...array) spread operator
Thomas Gerot
@tjgerot
Aug 09 2016 04:25
@JacobJW Are you familiar with Java?
Jacob Wernerowski
@JacobJW
Aug 09 2016 04:26
@tjgerot Haven't had a chance to dabble in it at all yet, sadly
MechMat
@MechMat
Aug 09 2016 04:26
I my out put to be :
FirstLine
\SecondLine\
ThirdLine
Jacob Wernerowski
@JacobJW
Aug 09 2016 04:26
@matszym What exactly does apply do that lets Math.max work on it like it normally would with two variables like x, y?
MechMat
@MechMat
Aug 09 2016 04:26
var myStr = "FirstLine\n\SecondLine\rThirdLine"
this is what i'm typing
Jacob Wernerowski
@JacobJW
Aug 09 2016 04:27
@MechMat For the second line, make sure to escape the backslashes
Thomas Gerot
@tjgerot
Aug 09 2016 04:27
@JacobJW Well they have much better for each loops. It's just for (String s : strlist) { }
I wish JS would inherit that
Jacob Wernerowski
@JacobJW
Aug 09 2016 04:28
\n escapes the 'n' and forms a new line. \ escapes the "escape" in a way.
'\'
Mateusz Szymański
@matszym
Aug 09 2016 04:28

@JacobJW apply calls function with array of arguments
First argument is context, value of this. We dont care about it, so we set it to null.
Math.min expects arguments one by one

Math.min(1, 2, 3, 10, 5, 6)

apply does just that. you pass array of arguments to apply, and it passes it one by one, not an array

Jacob Wernerowski
@JacobJW
Aug 09 2016 04:28
lol wtf I can't type two \'s
MechMat
@MechMat
Aug 09 2016 04:28
@JacobJW thanks
CamperBot
@camperbot
Aug 09 2016 04:28
mechmat sends brownie points to @jacobjw :sparkles: :thumbsup: :sparkles:
:cookie: 265 | @jacobjw |http://www.freecodecamp.com/jacobjw
Jacob Wernerowski
@JacobJW
Aug 09 2016 04:29
@matszym Ah I see! I was about to ask about the null, but you answered that for me. Thank you!
CamperBot
@camperbot
Aug 09 2016 04:29
jacobjw sends brownie points to @matszym :sparkles: :thumbsup: :sparkles:
:cookie: 128 | @matszym |http://www.freecodecamp.com/matszym
Mike
@MikeJSchorah
Aug 09 2016 04:30
function chunkArrayInGroups(arr, size) {
  var twoD = [];
  for (var i = 0; i < arr.length; i++) {
    twoD += arr.slice(0, size);
    twoD.push(arr);
  }
  return twoD;
}
What could be the problem with Chunky Monkey at this point, guys?
Mateusz Szymański
@matszym
Aug 09 2016 04:31
@MikeJSchorah you are trying to add element to aray with + operator. You cant do that
@MikeJSchorah
twoD += arr.slice(0, size);
Farrukh
@Farrukhw
Aug 09 2016 04:36
@MikeJSchorah you should simply use twoD.push(arr.slice(0,size);
no need for twoD +=...
and arr.slice(0,size) = arr.slice(size), until you want to specify starting index e.g. arr.slice(2,size) would slice your arry from 3rd element
var Testing="This is just a test code segment";
Mateusz Szymański
@matszym
Aug 09 2016 04:41
@tjgerot es6 have array functions that are very short
strlist.forEach(s => {
 // your code here
})

for (String s : strlist) { }
strlist.forEach(s=>{ })

In fact its little shorter than your python example ;)

Joseph
@revisualize
Aug 09 2016 04:43
Can you do arrow functions with { } s?
I guess you can.
Sweet.
Ryan
@rmo005
Aug 09 2016 05:03
I'm having some trouble with the "Local Scope and Functions" challenge. I created the local variable within the function, but I don't understand the instructions to remove the console line to pass the test.
Mateusz Szymański
@matszym
Aug 09 2016 05:04
@rmo005 When they mention remove, they literaly wants you to remove some code, deleting it manualy, you dont have to look for magic way to delete it with more code
Ryan
@rmo005
Aug 09 2016 05:06
@matszym Thanks! I tried that originally, but it didn't work because I had some other error earlier. I took their "hint" and refreshed the page and it worked the second go-around.
CamperBot
@camperbot
Aug 09 2016 05:06
rmo005 sends brownie points to @matszym :sparkles: :thumbsup: :sparkles:
:cookie: 129 | @matszym |http://www.freecodecamp.com/matszym
hai.pn
@firefoxvt
Aug 09 2016 05:11

Hi all, I have a stuck in Record Collection. This is my code:

function updateRecords(id, prop, value) {
  if(prop != "tracks" && value !== "") {

    collection[prop].push(value); 

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

    collection[id].tracks = [];
    collection[id].tracks.push(value);

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

    collection[id].tracks.push(value);

  } else if (value === "") {

    collection.pop(prop);
  }

  return collection;
}

I think I use barracket and dot correctly. Anyone help me? Thank you.

Markus Kiili
@Masd925
Aug 09 2016 05:12
@firefoxvt You need id here too: collection[prop].push(value);
The dot notation only works if the property key string is a valid JS identifier (for example "12" and "lives left" are not) and you write the key after the dot: var cat={clothes:"pants", "lives left":3}; cat.clothes; //returns "pants". Bracket notation works with keys that can be arbitrary strings cat["lives left"]; //returns 3, variables var key="clothes"; cat[key]; //returns "pants", or expressions cat["lives"+" "+"left"]; //returns 3.
So bracket notation is the general access method and dot notation works in one case only.
Tom
@CodePrime
Aug 09 2016 05:14
Sorry, is anyone available to help me with the Profile Lookup Challenge? https://www.freecodecamp.com/challenges/profile-lookup
Markus Kiili
@Masd925
Aug 09 2016 05:14
@CodePrime Sure.
Tom
@CodePrime
Aug 09 2016 05:15
I'm confused as to where to put return "No contact"
here's what I have
function lookUpProfile(firstName, prop){
// Only change code below this line
  for (var i=0;i<contacts.length;i++) {
    if (firstName==contacts[i].firstName) {
      if (contacts[i].hasOwnProperty(prop)===true)
        return contacts[i][prop];
      else
        return "No such property";
    }
}
wait
i think im an idiot
Markus Kiili
@Masd925
Aug 09 2016 05:15
@CodePrime When do you know there was no such contact in the phonebook?
Tom
@CodePrime
Aug 09 2016 05:16
when firstName!=contactsManageIQ/manageiq@6c40d76.firstName
when firstName==contacts[i].firstName
sorry
Markus Kiili
@Masd925
Aug 09 2016 05:16
When you have checked all the contacts and no return was made -> after the loop block.
Tom
@CodePrime
Aug 09 2016 05:17
@Masd925 yes, but if i put an else statemet after my first if statement, the loop terminates
it never goes beyond contats[0]
Markus Kiili
@Masd925
Aug 09 2016 05:17
Just put it after the loop block.
Tom
@CodePrime
Aug 09 2016 05:17
omg
I wrote No contact instead of No such contact
kill me
@Masd925 thanks
CamperBot
@camperbot
Aug 09 2016 05:18
codeprime sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: codeprime already gave masd925 points
Markus Kiili
@Masd925
Aug 09 2016 05:18
That happens to all ;)
John
@jpls93
Aug 09 2016 05:20
Anybody done with Exact Change?
Markus Kiili
@Masd925
Aug 09 2016 05:22
@johnsalcedonetwork Yes.
And in one line of course ;)
John
@jpls93
Aug 09 2016 05:26
u serious
Markus Kiili
@Masd925
Aug 09 2016 05:26
Actually yes, but it is not a good solution on one line.
John
@jpls93
Aug 09 2016 05:27
I'm trying to debug my 100+ lines of code
Joseph
@revisualize
Aug 09 2016 05:27
@johnsalcedonetwork Good luck!
Markus Kiili
@Masd925
Aug 09 2016 05:28
@johnsalcedonetwork Are you having problems with rounding?
Joseph
@revisualize
Aug 09 2016 05:28
@johnsalcedonetwork maybe try using www.pythontutor.com to visualize your code execution?
John
@jpls93
Aug 09 2016 05:28
I got the rounding part
I'm trying to find the reason why it's behaving strangely
here's a portion of the code, and the corresponding console.log output

code:

    function countChange(change) {
        console.log("####################");
        console.log("# Recursion loop " + recurseCounter + " #");
        console.log("####################");
        console.log("change is " + change);
        console.log("change === 0 ?", change === 0);
        if (change === 0) {
            return "Congratulations!";

console.log:

####################
# Recursion loop 0 #
####################
change is 100.5
change === 0 ? false
@change 100.5
@micr 335.41
@@change 0.5
@@micr 235.41
####################
# Recursion loop 1 #
####################
change is 0.5
change === 0 ? false
@change 0.5
@micr 235.41
@@change 0
@@micr 234.91
####################
# Recursion loop 2 #
####################
change is 0
change === 0 ? true
undefined
It's not returning "Congratulations!" despite passing the condition
I'm not sure if I did something wrong somewhere along the hundreds of lines of code
Jimmy Huynh
@jkchuynh829
Aug 09 2016 05:35
function destroyer(arr) {
    var result = []
    for(var i = 1; i<arr.length; i++) {
        result = arr.filter(function(x) {
            return x !== arguments[i];
        });
    }
    return result;
}

console.log(destroyer([1, 2, 3, 1, 2, 3], 2, 3));
can someone help me with why this doesn't work
Markus Kiili
@Masd925
Aug 09 2016 05:36
@jkchuynh829 Filter callback function has its own arguments object.
Jimmy Huynh
@jkchuynh829
Aug 09 2016 05:36
expected result is
// [1,1]
ohhh
it is a function after all
Markus Kiili
@Masd925
Aug 09 2016 05:36
@jkchuynh829 If you use filter, you don't need a loop through arr.
x is the element being iterated by filter, and the callback should return true for those elements you like filter to keep.
Jimmy Huynh
@jkchuynh829
Aug 09 2016 05:37
i'm confused because i am looping through the first argument, which is an array, with filter. however i want the filter to pass the additional arguments as a test
so im actually looping through that
Markus Kiili
@Masd925
Aug 09 2016 05:38
Filter iterates through arr and jeeps those elements that return true when passed into the callback function as x. So put the logic inside the callback.
Tica Alexandru Adrian
@LunyAlex
Aug 09 2016 05:38
Anyone got any clue as to why I get a "string2.split is not a function" error if I'm doing var string2 = string.toLowerCase above it?
Markus Kiili
@Masd925
Aug 09 2016 05:39
@jkchuynh829 Just return arr.filter(function(elem){...});
Jimmy Huynh
@jkchuynh829
Aug 09 2016 05:39
thanks ill try that
Markus Kiili
@Masd925
Aug 09 2016 05:39
That way your function will return the filtered array.
@LunyAlex .toLowerCase() <- parens
Jimmy Huynh
@jkchuynh829
Aug 09 2016 05:42
actually im stuck again...
function destroyer(arr) {
    return arr.filter(function(e) {
        return e !== something;
    })
}

console.log(destroyer([1, 2, 3, 1, 2, 3], 2, 3));
Tica Alexandru Adrian
@LunyAlex
Aug 09 2016 05:42
Jesus Christ! Thank you so much! Still a noob, heh.
Mateusz Szymański
@matszym
Aug 09 2016 05:44

@johnsalcedonetwork each time you call

countChange(change)

you should have return it

return countChange(change);
Gerren Jackson
@gerrenjj
Aug 09 2016 05:45
function testElse(val) {
  var result = "";
  // Only change code below this line

  if (val > 5) {
    return "Bigger than 5";
  }

  else if (val <= 5) {
    return "5 or Smaller";
  }


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

// Change this value to test
testElse(5);
@Masd925 Hey bro can you help me figure out how to make this into one if?
Anybody
Blauelf
@Blauelf
Aug 09 2016 05:49
@gerrenjj If val is a number (and not NaN, which is Not-a-Number, but of type "number"), it's always either >5 or <=5, so you don't need that second if. And judging from the code, you were supposed to assign to result instead of returning, but that probably does not matter (as long as there is no test checking it - function works the same).
Nupur Roy
@nupur06cherish
Aug 09 2016 05:50
hey guys i need some help in falsy bouncer problem
here is my code
This message was deleted
Blauelf
@Blauelf
Aug 09 2016 05:51
help format
CamperBot
@camperbot
Aug 09 2016 05:51

: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

Gerren Jackson
@gerrenjj
Aug 09 2016 05:51
 @Blauelf ok lemme try that
Nupur Roy
@nupur06cherish
Aug 09 2016 05:51
This message was deleted
Blauelf
@Blauelf
Aug 09 2016 05:51
@gerrenjj A simple if-else will be enough there.
@nupur06cherish Use triple backticks :point_up: 9. August 2016 07:51
Gerren Jackson
@gerrenjj
Aug 09 2016 05:53
function testElse(val) {
  var result = "";
  // Only change code below this line

  if (val > 5) {
    result = "Bigger than 5";
  }

  else (val <= 5) {
    result = "5 or Smaller";
  }

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

// Change this value to test
testElse(4);
That else is getting a red X
@Blauelf
Blauelf
@Blauelf
Aug 09 2016 05:54
@gerrenjj Also remove the (val <= 5)
Nupur Roy
@nupur06cherish
Aug 09 2016 05:54
@Blauelf where should i use a tripple backtricks
Gerren Jackson
@gerrenjj
Aug 09 2016 05:54
Ooooooh ok Thanks @Blauelf
CamperBot
@camperbot
Aug 09 2016 05:54
gerrenjj sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 2331 | @blauelf |http://www.freecodecamp.com/blauelf
Nupur Roy
@nupur06cherish
Aug 09 2016 05:54
moreover its not taking "" or "abc" any string value inside ""
DJ
@qualitymanifest
Aug 09 2016 05:54
@gerrenjj else if statements take a condition. else statements do not
Blauelf
@Blauelf
Aug 09 2016 05:54
@nupur06cherish Like @camperbot told you above, triple backticks around your code.
Gerren Jackson
@gerrenjj
Aug 09 2016 05:55
@qualitymanifest Ok got cha
Nupur Roy
@nupur06cherish
Aug 09 2016 05:56
ok

'function bouncer(arr) {

'var i,temp=[];
'for(i=0;i<arr.length;i++)
''{
'if(arr[i] !== null && Boolean(arr[i]) === true && !isNaN(arr[i]) && arr[i] !== 0 && arr[i] !== undefined )
'' {
'' temp.push(arr[i]);
''}
'' }
'return temp;
''}

'bouncer([1, null, NaN, 2, undefined]);

Markus Kiili
@Masd925
Aug 09 2016 05:56
@nupur06cherish isNaN is really not a test for value NaN.
Blauelf
@Blauelf
Aug 09 2016 05:57
@nupur06cherish Those are not backticks, and you are supposed to place those before and after your code, not before each line.
Markus Kiili
@Masd925
Aug 09 2016 05:57
val!==val is a test for value NaN.
Blauelf
@Blauelf
Aug 09 2016 05:57

@nupur06cherish The working part of your condition is Boolean(arr[i])===true, the others are included in that one. The faulty part is the !isNaN(arr[i]), which converts strings to numbers before checking whether the value is NaN. The right check would be arr[i]===arr[i], as NaN does not equal itself.

You could even further reduce if(Boolean(arr[i])===true), as Boolean(arr[i]) can only be true or false, this is the same as if(Boolean(arr[i])) and even if(arr[i]), where if does an implicit cast to boolean.

Nupur Roy
@nupur06cherish
Aug 09 2016 05:58
ok gotcha
@Blauelf hey thanks...i got it
CamperBot
@camperbot
Aug 09 2016 06:00
nupur06cherish sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 2332 | @blauelf |http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Aug 09 2016 06:01

@nupur06cherish Triple backticks means
```js
console.log("Hello World!");
```
becomes

console.log("Hello World!");

(and indentation, if I had some, would be preserved)
You can insert line breaks using Shift+Return.

@nupur06cherish Mean thing is that the output of the function will show null for undefined or NaN, so people regularly think they are not correctly removing null while they have NaN left (just a display issue in that left-side panel on FCC). You can check for those by including some console.log statements and checking their output on browser console (usually F12 or Ctrl+Shift+I on most browsers). Does not apply to your code as you did not have extras but removed too much, still useful tool for debugging :)
Joseph
@revisualize
Aug 09 2016 06:10
@nupur06cherish My suggestion.. Use the recommended links. They really are helpful for this lesson.
John
@jpls93
Aug 09 2016 06:14
@matszym THANKS!
CamperBot
@camperbot
Aug 09 2016 06:14
johnsalcedonetwork sends brownie points to @matszym :sparkles: :thumbsup: :sparkles:
:cookie: 130 | @matszym |http://www.freecodecamp.com/matszym
Manjot Singh
@msingh18
Aug 09 2016 06:15
I have a problem regarding variable scope in my Local Weather challenge. Can someone please take a look and help me out?
Bilyan Hadzhi
@bilyanhadzhi
Aug 09 2016 06:17
@msingh18 latitude and longitude are within your $(document).ready function, which means those variables will be accessible only within that function or any functions within it. Once that function executes, those variables are deleted.
@msingh18 Or not. I'm blind :D
Manjot Singh
@msingh18
Aug 09 2016 06:18
@Billy5500 but my entire JS code is inside the ready function, how can the variables get deleted
Mateusz Szymański
@matszym
Aug 09 2016 06:19

@msingh18 2 things:

1) If you are on chrome, you dont have access to navigator on unsecure connection (http protocol)
2) Your code is async, meaning, it will execute later

Bilyan Hadzhi
@bilyanhadzhi
Aug 09 2016 06:19
@msingh18 Scratch that :D
@msingh18 But the problem is still the same: latitude and longitude are within your navigator.geolocation.getCurrentPosition's function and you can not access them outside of it.
Mateusz Szymański
@matszym
Aug 09 2016 06:20

@msingh18 so, this line:
console.log(latitude);
is executed before

   latitude = location.coords.latitude;
    longitude = location.coords.longitude;

so its still undefined

Manjot Singh
@msingh18
Aug 09 2016 06:20
@matszym
  1. I figured that out after wasting few hours, I am on Firefox currently
  2. I have read about async parameter inside of an XMLHttpRequest open method but not in context of getJSON
Bilyan Hadzhi
@bilyanhadzhi
Aug 09 2016 06:21
@msingh18 Unless you declare them in the scope you want to use them in.
@msingh18 Wait but you did. OMG I'm sorry
Manjot Singh
@msingh18
Aug 09 2016 06:22
@Billy5500 I want to update the value of the variables declared in the ready function scope, how can I accomplish that?
Mateusz Szymański
@matszym
Aug 09 2016 06:23

@msingh18 Async isnt exclusive for network connections. To see for yourself, place console.log('first') in the callback, and console.log('second') in place where you want to acces latitude. this is output you will get:

second
first

This will shouw you when is your code executed

Manjot Singh
@msingh18
Aug 09 2016 06:23
@matszym I think you are right, how do I make it execute earlier?
Mateusz Szymański
@matszym
Aug 09 2016 06:23
@msingh18 you cant. You have to wait with rest of your code until its resolved
Manjot Singh
@msingh18
Aug 09 2016 06:23
@matszym how do I insert waits?
Mateusz Szymański
@matszym
Aug 09 2016 06:24
@msingh18 you move your code into the callback, or you use promises
Manjot Singh
@msingh18
Aug 09 2016 06:24
@matszym that sounds scary lol, can you provide any references on the web that might be useful for me regarding this?
Mateusz Szymański
@matszym
Aug 09 2016 06:25

@msingh18

executeAsync()
.then(function() {
  //do some magic
  return promise
})
.then(function() {
  // this will execute after previous magic
  return another promise
})
.catch(//handle errors)

Thats how yo uwould do it with promises

Dan Couper
@DanCouper
Aug 09 2016 06:26
$.get().then().then().then() etc etc. It's not easy stuff to understand though, changing the way your code works is
Manjot Singh
@msingh18
Aug 09 2016 06:26
@Billy5500 thanks a lot Mateusz
CamperBot
@camperbot
Aug 09 2016 06:26
msingh18 sends brownie points to @billy5500 :sparkles: :thumbsup: :sparkles:
:cookie: 324 | @billy5500 |http://www.freecodecamp.com/billy5500
Manjot Singh
@msingh18
Aug 09 2016 06:27
Also thanks to @DanCouper @Billy5500
CamperBot
@camperbot
Aug 09 2016 06:27
msingh18 sends brownie points to @dancouper and @billy5500 :sparkles: :thumbsup: :sparkles:
:warning: msingh18 already gave billy5500 points
:cookie: 183 | @dancouper |http://www.freecodecamp.com/dancouper
Mateusz Szymański
@matszym
Aug 09 2016 06:27
@msingh18 if you dont, you can nest callbacks (this is bad design, called pyramide of doom)
navigator.something(function() {
  $.get(function() {
    // another callback
  })
})
Manjot Singh
@msingh18
Aug 09 2016 06:27
@matszym this was going to be next question
Is using promises a good practice? Do you see it often?
Mateusz Szymański
@matszym
Aug 09 2016 06:28
@msingh18 do calback nesting for now, after you are done with challenge, read about bluebird lib (promise lib)

@msingh18 yes, it is. If you have a lot of async code, you have nice structure, then after then after then

if you dont, you end up with a lof of nested functions, with is harder to maintain

Manjot Singh
@msingh18
Aug 09 2016 06:30
@matszym sure, really appreciate your help here. Got exactly what I was looking for
Bilyan Hadzhi
@bilyanhadzhi
Aug 09 2016 06:42
@matszym Thanks! I learnt some stuff as well!
CamperBot
@camperbot
Aug 09 2016 06:42
billy5500 sends brownie points to @matszym :sparkles: :thumbsup: :sparkles:
:cookie: 131 | @matszym |http://www.freecodecamp.com/matszym
Manjot Singh
@msingh18
Aug 09 2016 06:43
@matszym if you are still here
I moved the getJSON request inside the navigator callback function, it works but it loads very slowly compared to the example codepen given in the challenge description. Is it because of any different technique being used there in the Codepen example, or because it has a better weather API service?
Mateusz Szymański
@matszym
Aug 09 2016 06:44
can you link updated codepen?
Mateusz Szymański
@matszym
Aug 09 2016 06:48
@msingh18 After I allow browser to use my location, I see city populated in about 1 second with is fine
Manjot Singh
@msingh18
Aug 09 2016 06:50
@matszym alright, seems like a minor problem. Thanki you Matuesz. Anything else I should be aware of that you have in mind right now?
Mateusz Szymański
@matszym
Aug 09 2016 06:52
@msingh18 You might want to provide fallback, when navigator is not provided. You can approximate location based on ip. You would have to use some 3rd party service, to provide lat and long based on ip address
Sorin Ruse
@sorinr
Aug 09 2016 06:52
@msingh18 for me its not working. if i switch to https instead http i get the lat and lon but openweather api its not working
Manjot Singh
@msingh18
Aug 09 2016 06:52
@sorinr it does not work in Chrome, I think it is an open issue
@matszym thanksi a lot, read about it somewhere else as well
Sorin Ruse
@sorinr
Aug 09 2016 06:54
@msingh18 its working also on chrome. take a look weather
Mark Todd
@Knochenmark
Aug 09 2016 06:56
@sorinr white on white?
Bilyan Hadzhi
@bilyanhadzhi
Aug 09 2016 06:56
@msingh18 I used this to make it work on Chrome.
Manjot Singh
@msingh18
Aug 09 2016 06:57
@sorinr did you use the OpenWeather API?
@Billy5500 I was looking for this kind of solution yesterday, then I decided to just use Firefox
Sorin Ruse
@sorinr
Aug 09 2016 07:00
@msingh18 yes. in my wather.php i am calling openweather api. just used that php to set well the headers and avoid cors problems until my ssl certificate expired :) and for a quick fix i used crossorigin.me until i renew the certificate
@Knochenmark what do you mean by white on white/ there is a bg pic in there
Mark Todd
@Knochenmark
Aug 09 2016 07:03
@sorinr there was no background picture, it was white background with a white symbol with a slight shadow
@Knochenmark what browser are you using?
Mark Todd
@Knochenmark
Aug 09 2016 07:03
@sorinr your crossorigin fails, so the resource is missing
Bilyan Hadzhi
@bilyanhadzhi
Aug 09 2016 07:04
@Knochenmark It works for me on Chrome
Manjot Singh
@msingh18
Aug 09 2016 07:04
@sorinr your code is very clean and organised. I need to study it a bet to get some ideas about how to structure code
The codepen works for me, both in Chrome as well as Firefox
Sorin Ruse
@sorinr
Aug 09 2016 07:06
@Knochenmark tested it also on edge and its working. don't have ff reinstalled yet to test it
Mark Todd
@Knochenmark
Aug 09 2016 07:06
@sorinr its your crossorigin, it fails
@sorinr Failed to load resource: net::ERR_TUNNEL_CONNECTION_FAILED
Markus Kiili
@Masd925
Aug 09 2016 07:08
@geecheeche It is better if you post the code here formatted.
explain format
CamperBot
@camperbot
Aug 09 2016 07:08

: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

Sorin Ruse
@sorinr
Aug 09 2016 07:08
@Knochenmark sorry its not working for you in https. for me and others its ok
Mark Todd
@Knochenmark
Aug 09 2016 07:09
@sorinr well, you might want to consider changing atleast the background color or icon color for that scenario
Mark Todd
@Knochenmark
Aug 09 2016 07:10
@sorinr i doubt iam the only one who will encounter this problem
Manikanth
@manikanth1024
Aug 09 2016 07:10
Hello guys i need ur assisstance
Mark Todd
@Knochenmark
Aug 09 2016 07:10
@manikanth1024 jquery is not defined
@manikanth1024 i think you need to import it on settings first
Manikanth
@manikanth1024
Aug 09 2016 07:11
how do i do that?
Mark Todd
@Knochenmark
Aug 09 2016 07:12
@manikanth1024 settings, javascript quick add jquery
Sorin Ruse
@sorinr
Aug 09 2016 07:13
@Knochenmark do you have location enabled in your browser ?. that can be the issue that generates the error
Mark Todd
@Knochenmark
Aug 09 2016 07:14
@sorinr you mean the geolocation?
@manikanth1024 well, now jquery is defined, but i guess all the html elements are missing you are trying to access
Manikanth
@manikanth1024
Aug 09 2016 07:16
if u dont mind i'll send the file to u
its a project file
Darth Skywalker
@adityaparab
Aug 09 2016 07:16
@manikanth1024 : Just add your html markup in the html section of your codepen
Mark Todd
@Knochenmark
Aug 09 2016 07:16
@manikanth1024 your html is empty
Manikanth
@manikanth1024
Aug 09 2016 07:17
ok
Darth Skywalker
@adityaparab
Aug 09 2016 07:17
@manikanth1024 : Born on Oct 24th?
Sorin Ruse
@sorinr
Aug 09 2016 07:17
@Knochenmark yes
Manjot Singh
@msingh18
Aug 09 2016 07:18
@adityaparab Wrong date format for that
Manikanth
@manikanth1024
Aug 09 2016 07:18
no y?
Mark Todd
@Knochenmark
Aug 09 2016 07:18
@sorinr no its not related to the location, its your crossorigin request that fails. My location shows up and is correct
Manikanth
@manikanth1024
Aug 09 2016 07:19
its an hint to show my passion towards CS
Sorin Ruse
@sorinr
Aug 09 2016 07:19
@Knochenmark so only the bg pic its not showing?
Darth Skywalker
@adityaparab
Aug 09 2016 07:19

@msingh18

@adityaparab Wrong date format for that

For Indian standards. Not for the US and EU :)

Manikanth
@manikanth1024
Aug 09 2016 07:19
1mb=1024kb ....
Manjot Singh
@msingh18
Aug 09 2016 07:19
@manikanth1024 yeah I was gonna guess that
Mark Todd
@Knochenmark
Aug 09 2016 07:20
@sorinr i dont know, there are 2 requests failing, but the background is the most noticable
Manjot Singh
@msingh18
Aug 09 2016 07:20
@adityaparab but I saw that he is from Hyderabad
Darth Skywalker
@adityaparab
Aug 09 2016 07:20
@manikanth1024 : I thought it was Oct(10) 24th
Manjot Singh
@msingh18
Aug 09 2016 07:21
@adityaparab you are born on 24 Oct, right?
Mark Todd
@Knochenmark
Aug 09 2016 07:21
@msingh18 wheres the format wrong?
Sorin Ruse
@sorinr
Aug 09 2016 07:21
@Knochenmark can you try now? just commented out the background pic and made it gray
Darth Skywalker
@adityaparab
Aug 09 2016 07:21
@msingh18 : Yes, you're right!
Manjot Singh
@msingh18
Aug 09 2016 07:22
@Knochenmark the date format in India is different from what is used here in US. That's what we were on about
Mark Todd
@Knochenmark
Aug 09 2016 07:22
@sorinr grey looks better, but you could just do it as a fall back
@msingh18 dont get me started on the US format, that one is plain stupid
@msingh18 whats your format?
Darth Skywalker
@adityaparab
Aug 09 2016 07:23
(210)(2^10) is more like computer science-yy
Mark Todd
@Knochenmark
Aug 09 2016 07:23
@adityaparab what are you trying? :D
Darth Skywalker
@adityaparab
Aug 09 2016 07:24
Why is the LaTeX not transforming correctly :D
Mark Todd
@Knochenmark
Aug 09 2016 07:24
you mean 2^10?
Darth Skywalker
@adityaparab
Aug 09 2016 07:24
Yeah...
It works well for 232^3
or even 292^9
Mark Todd
@Knochenmark
Aug 09 2016 07:25
maybe you can just use single digits :P
Darth Skywalker
@adityaparab
Aug 09 2016 07:25
but fails for the number raised to two or more digit numbers :D
Manjot Singh
@msingh18
Aug 09 2016 07:25
@Knochenmark it is the US format at present. I have to actually think about the format every time I have to read or write a date
Sorin Ruse
@sorinr
Aug 09 2016 07:25
@Knochenmark but the city and weather its reported ok?
Mark Todd
@Knochenmark
Aug 09 2016 07:26
@sorinr yeah thats fine
Darth Skywalker
@adityaparab
Aug 09 2016 07:26

@Knochenmark : Nvm.. math never fails . I can write 2^10 as

29212^9 2^1 = 2102^{10}

doraani
@doraani
Aug 09 2016 07:27
2^{10}
Mark Todd
@Knochenmark
Aug 09 2016 07:27
@msingh18 haha what a pity. the US date format is the most fucked up
Sorin Ruse
@sorinr
Aug 09 2016 07:27
@Knochenmark i really don't know why the background pic was not loading for you but as you said i'll try to make a fallback for that :)
Mark Todd
@Knochenmark
Aug 09 2016 07:27
@sorinr i think its connected to the crossorigin attempt, not working for me for some reason
Darth Skywalker
@adityaparab
Aug 09 2016 07:27
Fuck yeah! got it! 210002^{1000}
Mark Todd
@Knochenmark
Aug 09 2016 07:28
@adityaparab NOT :D
Darth Skywalker
@adityaparab
Aug 09 2016 07:28
check now
that was a typo :D
Mark Todd
@Knochenmark
Aug 09 2016 07:28
yeah now
Manikanth
@manikanth1024
Aug 09 2016 07:28
hey @Knochenmark embedded evrything in codepen
Darth Skywalker
@adityaparab
Aug 09 2016 07:28
2@Knochenmark2^{ @Knochenmark } :P
There is a challenge on FCC which asks you to calculate sum of all the numbers in a range. Who can do that without using for loop?
Mark Todd
@Knochenmark
Aug 09 2016 07:30
In Europe the date System is smallest to biggest DDMMYYYY
In China the date System is biggest to smallest YYYYMMDD, which is actually used in all databases for better sorting too
The Americans just said, lets mix up everything :D MMDDYYYY
Manikanth
@manikanth1024
Aug 09 2016 07:30
@Knochenmark
Markus Kiili
@Masd925
Aug 09 2016 07:30
@adityaparab You can use reduce or just math.
Darth Skywalker
@adityaparab
Aug 09 2016 07:30
@Masd925 : Reduce will internally spanw a loop anyway :D
Mark Todd
@Knochenmark
Aug 09 2016 07:30
@adityaparab Infinite?
Darth Skywalker
@adityaparab
Aug 09 2016 07:31
Math makes programming a lot easy and efficient :D
Markus Kiili
@Masd925
Aug 09 2016 07:31
@adityaparab Yes, but you said for loop ;)
Darth Skywalker
@adityaparab
Aug 09 2016 07:31
@Masd925 : Technically, yes, you are right. What I intended on implying is without iterating on the array.
Mark Todd
@Knochenmark
Aug 09 2016 07:31
@adityaparab actually reduce is super easy for such tasks
Darth Skywalker
@adityaparab
Aug 09 2016 07:31
iterating in any way, shape or form.
@Knochenmark : Do you know what is the costliest operation in computer science?
Mark Todd
@Knochenmark
Aug 09 2016 07:33
var arr = [1,2,3,4,5,6,7];
var sum = arr.reduce(function(p,c){
return p+c;
},0);
Markus Kiili
@Masd925
Aug 09 2016 07:33
@adityaparab Smashing the computer?
Mark Todd
@Knochenmark
Aug 09 2016 07:33
@adityaparab an infinite loop? :D
Darth Skywalker
@adityaparab
Aug 09 2016 07:33

@Masd925

@adityaparab Smashing the computer?

lmao! :D

Mark Todd
@Knochenmark
Aug 09 2016 07:33
@Masd925 thats actually really power saving!
Darth Skywalker
@adityaparab
Aug 09 2016 07:34

@adityaparab an infinite loop? :D

No, the costliest operation is comparison. Comparisons take more time to execute than anything else.

In loop, you compare something in each iteration.
That is why loops tend to slow down the performance.
(x2y3)(\frac{x^2}{y^3})
Mark Todd
@Knochenmark
Aug 09 2016 07:35
well, but you can leave a comparison :P while the infinite loop keeps going
Darth Skywalker
@adityaparab
Aug 09 2016 07:35
(x2y3)\left(\frac{x^2}{y^3}\right)
wow!
Manikanth
@manikanth1024
Aug 09 2016 07:35
helpless leaving this room
Markus Kiili
@Masd925
Aug 09 2016 07:36
@manikanth1024 If you don't get a response here, you can try the general chat https://gitter.im/FreeCodeCamp/FreeCodeCamp
Darth Skywalker
@adityaparab
Aug 09 2016 07:36
@Knochenmark : There is a concept in math called an Arithmetic Progression.
It's formula is - if you want to add all the number from 1 to n, you can do that by
n(n+12)n\left(\frac{n+1}{2}\right)

say you wanna find sum of 1 to 10, your formula will be

10(10+12)10\left(\frac{10+1}{2}\right)

= 10(112)10\left(\frac{11}{2}\right)
Mark Todd
@Knochenmark
Aug 09 2016 07:39
but what if i want to add in a range of 2 to n?
Darth Skywalker
@adityaparab
Aug 09 2016 07:39
= 1102\frac{110}{2}
= 55
2 to n will be easy. Just subtract 1 from whatever you get from your formula
doraani
@doraani
Aug 09 2016 07:40
@adityaparab
Darth Skywalker
@adityaparab
Aug 09 2016 07:40
whats interesting is sum of all the numbers from m to n
where m<n
Mark Todd
@Knochenmark
Aug 09 2016 07:40
yeah that was what i was going for
55 to 77 for example
quite trivial with .reduce() :P
Darth Skywalker
@adityaparab
Aug 09 2016 07:41

assuming m < n

n(n+12)m(m+12)n\left(\frac{n+1}{2}\right) - m\left(\frac{m+1}{2}\right)

This algorithm is of complexity O(1)O(1)
The fastest
Markus Kiili
@Masd925
Aug 09 2016 07:42
@adityaparab You can always just calculate the average of the first and last elements and multiply it with the number of elements, without knowing anything about arithmetic progression. Nothing wrong with what you said, of course.
Mark Todd
@Knochenmark
Aug 09 2016 07:42
sounds interesting for that one task where you had to add sum in range
Darth Skywalker
@adityaparab
Aug 09 2016 07:43
@Masd925 : That, again, is a variant of the implementation of arithmetic progression theorem
Markus Kiili
@Masd925
Aug 09 2016 07:43
@adityaparab Yes.
Darth Skywalker
@adityaparab
Aug 09 2016 07:43
I agree, there are multiple ways.
My only challenge was, you have to get sum of all the number with an algorithm of complexity O(1)O(1)
Mark Todd
@Knochenmark
Aug 09 2016 07:48
@adityaparab you used this for sum all numbers in range?
flipol
@flipol
Aug 09 2016 07:48
hello All
function mutation(arr) {
  var i = 0;
  do {
    arr[1].substr(i, i+1).indexOf(arr[0]);
    i++;
  } while (i < arr[1].length);         
  if (i == arr[1].length){
    return true;
  }return false;
}
Can anyone give me a hint?
Markus Kiili
@Masd925
Aug 09 2016 07:50
@flipol You should first lowercase the strings and then loop or iterate the second string characters and check if they are found on the first string.
@Knochenmark If you were asking for the math solution for the Sum all numbers, it is like this:
function sumAll(arr) {
  var max = Math.max.apply(null,arr);
  var min = Math.min.apply(null,arr);
  return (max+min)/2*(max-min+1);
}
Влад Карцаев
@VladKarcaev
Aug 09 2016 07:55
Help me Guys
CamperBot
@camperbot
Aug 09 2016 07:55
no wiki entry for: me guys
Влад Карцаев
@VladKarcaev
Aug 09 2016 07:55
htlp
help*
CamperBot
@camperbot
Aug 09 2016 07:55

CamperBot

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

Basic Commands:

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

meet CamperBot in FreeCodeCamp/camperbotPlayground

:pencil: read more about camperbot on the FCC Wiki

Влад Карцаев
@VladKarcaev
Aug 09 2016 07:55
find js
Влад Карцаев
@VladKarcaev
Aug 09 2016 07:56
find js
Picshulo
@Picshulo
Aug 09 2016 07:57
Working on "Where do I belong" challenge and have no idea how to solve it.. any help please?
hai.pn
@firefoxvt
Aug 09 2016 08:03

hello. I have a stuck at Profile Lookup. This is my code:

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


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

// Change these values to test your function
lookUpProfile("Kristian", "lastName");

Anyone can figure out? Thank you.

flipol
@flipol
Aug 09 2016 08:06
function mutation(arr) {
  var second = arr[1].toLowerCase();
  var first = arr[0].toLowerCase();
  for (var i = 0; i < second.length; i++){
    if (first.indexOf(second[i]) <0){
      return false;
    }return true;
  }
}
Why it still doesn't work? Anyone :{ ?
Picshulo
@Picshulo
Aug 09 2016 08:09
@flipol I think your second return should be after your for loop like this :
function mutation(arr) {
  var second = arr[1].toLowerCase();
  var first = arr[0].toLowerCase();
  for(var i = 0; i < second.length; i++){
    if(first.indexOf(second[i]) < 0){
      return false;
    } 
  }
  return true;  
}
flipol
@flipol
Aug 09 2016 08:11
Got it:)! Thanks @Picshulo
CamperBot
@camperbot
Aug 09 2016 08:11
flipol sends brownie points to @picshulo :sparkles: :thumbsup: :sparkles:
:cookie: 279 | @picshulo |http://www.freecodecamp.com/picshulo
Picshulo
@Picshulo
Aug 09 2016 08:12
@flipol No problemo :)
Darth Skywalker
@adityaparab
Aug 09 2016 08:23

@Knochenmark

@adityaparab you used this for sum all numbers in range?

Sorry, I was away. Yes. Here it is

function sumAll(arr) {
  var min = Math.min.apply(null, arr);
  var max = Math.max.apply(null, arr);

  return ((((max-min)+1)/2)*(min+max));
}

sumAll([1, 4]);
Ahmad Abdolsaheb
@ahmadabdolsaheb
Aug 09 2016 08:27
This message was deleted
Picshulo
@Picshulo
Aug 09 2016 08:30
It looks like my array is not sorted at all
function getIndexToIns(arr, num) {
  arr.push(num);
  arr.sort();
  return arr.indexOf(num);
}
getIndexToIns([40, 60], 50);
Ahmad Abdolsaheb
@ahmadabdolsaheb
Aug 09 2016 08:30

hello everyone, I have trouble with using .reduce to flatten function arguments. I would appreciate it if you could help me. here is the code snippet.

function uniteUnique(arr) {
  var args = arguments;
 arr = args.reduce(function(a, b) {return a.concat(b);});
  return arr;
}

i get "args.reduce is not a function" , but why?

Mateusz Szymański
@matszym
Aug 09 2016 08:34
@ahmadabdolsaheb arguments is object, not array
Nathaniel Nasarow
@Torgian
Aug 09 2016 08:35
argh
been working smallest common multiple for a week
cant figure it out. I got to a certain point with the loops... but eh. Starting to think I should just look up an answer and study it.
Salama Ashoush
@salamaashoush
Aug 09 2016 08:36
i think there is a bug in this chalange var myStr = "FirstLine\n\\SecondLine\\\rThirdLin";,i test the code in Chrome Devtools and worked nice
Darth Skywalker
@adityaparab
Aug 09 2016 08:37

@Knochenmark @Masd925 :

Check this out ;)

https://repl.it/ClFd

Picshulo
@Picshulo
Aug 09 2016 08:38
@salamaashoush You are missing "E" in "ThirdLine"
Salama Ashoush
@salamaashoush
Aug 09 2016 08:39
oh
@Picshulo thanks
CamperBot
@camperbot
Aug 09 2016 08:39
salamaashoush sends brownie points to @picshulo :sparkles: :thumbsup: :sparkles:
:cookie: 280 | @picshulo |http://www.freecodecamp.com/picshulo
Picshulo
@Picshulo
Aug 09 2016 08:40
@salamaashoush :thumbsup:
Daniel Lailvaux
@DanielLailvaux
Aug 09 2016 08:40
This message was deleted
Darth Skywalker
@adityaparab
Aug 09 2016 08:41

@Knochenmark @Masd925

Along with Reduce

https://repl.it/ClFd/10

:P
Picshulo
@Picshulo
Aug 09 2016 09:00
"Caesars Cipher" - Can i do it with for loop into switch somehow?
Markus Kiili
@Masd925
Aug 09 2016 09:01
@Picshulo Loop, or iterate the string, check the charcode and transform if need be, and change back to a character.
Anna
@Anntol
Aug 09 2016 09:04
@firefoxvt you should check all items before return "No such contact";
@Picshulo please refer documentaion to see how you should do numeric sort
Picshulo
@Picshulo
Aug 09 2016 09:09
@Anntol Well this helped me the most https://www.freecodecamp.com/challenges/sort-arrays-with-sort :)
@Masd925 Thanks, i'll try something.. maybe it will work one day :D
CamperBot
@camperbot
Aug 09 2016 09:09
picshulo sends brownie points to @anntol and @masd925 :sparkles: :thumbsup: :sparkles:
:cookie: 340 | @anntol |http://www.freecodecamp.com/anntol
:star2: 2261 | @masd925 |http://www.freecodecamp.com/masd925
Picshulo
@Picshulo
Aug 09 2016 09:10
This message was deleted
Nupur Roy
@nupur06cherish
Aug 09 2016 09:12
got stuck in seek and destroy
written two set of codes but both of them not working
Benjam Wondafrash
@BenjamWondafrash
Aug 09 2016 09:13
Caesars cipher can make good use of modulo.
Anna
@Anntol
Aug 09 2016 09:13
@Picshulo just check documentation when something is not do as you expects is good developer practice :smile:
weijq
@weijiqiang1024
Aug 09 2016 09:13
I have confused with this challenge "Profile Lookup" in JavaScript practice
anybody can help me?
Nupur Roy
@nupur06cherish
Aug 09 2016 09:13

'function destroyer(arr) {

'var args = Array.prototype.slice.call(arguments);
'var j,i,temp=[];
'for(i=1;i<args.length;i++)
''{
'for(j=0;j<argsxamarin/xamarin-android@a16673d.length;j++){
'if(args[i] == args[0][j]){
'argsxamarin/xamarin-android@a16673d.splice(j,1);
''}
''}
''}

'return argsxamarin/xamarin-android@a16673d;
''}

'destroyer([2, 3, 2, 3], 2, 3);

Anna
@Anntol
Aug 09 2016 09:14
@weijiqiang1024 be sure you check all items before return "No such contact";
Benjam Wondafrash
@BenjamWondafrash
Aug 09 2016 09:14
I mean remainder % n.
Nupur Roy
@nupur06cherish
Aug 09 2016 09:14

'''function destroyer(arr) {

'''var args = Array.prototype.slice.call(arguments);
'''var j,i,temp=[];
'''for(i=1;i<args.length;i++)
'''{
'''for(j=0;j<argsxamarin/xamarin-android@a16673d.length;j++){
'''if(args[i] == args[0][j]){
'''argsxamarin/xamarin-android@a16673d.splice(j,1);
'''}
'''}
'''}

'''return argsxamarin/xamarin-android@a16673d;
'''}

'''destroyer([2, 3, 2, 3], 2, 3);

CamperBot
@camperbot
Aug 09 2016 09:14
:bulb: to format code use backticks! ``` more info
Benjam Wondafrash
@BenjamWondafrash
Aug 09 2016 09:14
Anyone else see all this xamarin stuff
Anna
@Anntol
Aug 09 2016 09:14
@BenjamWondafrash yes, author should use slash before
Pablo
@Olbap14
Aug 09 2016 09:14
hi, can you help me with the "No repeats please" exercise??
I don't know what is wrong with this function, it's suppose that it should return a string with all the permutations togheter, but it returns a strange string that don't work like it should
This is my code:
   var perm=function(arr,pos,org,used){
    for(pos;pos<org.length;pos++) {
      if(used[pos]!==1){
        arr+=org[pos];
        used[pos]=1;
        arr+=perm(arr,pos+1,org,used);
        used[pos]=0;
      }

    }

    return arr;
  };
Benjam Wondafrash
@BenjamWondafrash
Aug 09 2016 09:16
@Anntol It was not my code blurb
Mark Todd
@Knochenmark
Aug 09 2016 09:16
@adityaparab pretty cool :P
Benjam Wondafrash
@BenjamWondafrash
Aug 09 2016 09:16
@Anntol but how to NOT have that xamarin gibberish
Nupur Roy
@nupur06cherish
Aug 09 2016 09:16

`function destroyer(arr) {

var args = Array.prototype.slice.call(arguments);
var j,i,temp=[];
for(i=1;i<args.length;i++)
{
for(j=0;j<argsxamarin/xamarin-android@a16673d.length;j++){
if(argsManageIQ/manageiq@6c40d76 == args[0][j]){
argsxamarin/xamarin-android@a16673d.splice(j,1);
}
}
}

return argsxamarin/xamarin-android@a16673d;
}

destroyer([2, 3, 2, 3], 2, 3);
`

Anna
@Anntol
Aug 09 2016 09:16
@BenjamWondafrash :smile: I edited
Benjam Wondafrash
@BenjamWondafrash
Aug 09 2016 09:17
@Anntol So three backticks is not all? A slash also needed?
Anna
@Anntol
Aug 09 2016 09:19
@BenjamWondafrash I add slash before each of this stuff, but probably posting js after open code backsticks can help - not checked
weijq
@weijiqiang1024
Aug 09 2016 09:19
@Anntol i have no idea to judge the object have same property or not
Daniel Lailvaux
@DanielLailvaux
Aug 09 2016 09:19
Hey guys, im stuck on counting cards, i just cant seem to get it right. Heres my code
var count = 0;

function cc(card) {
  // Only change code below this line
  switch (card) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count += 1;
      break;
    case 7:
    case 8: 
    case 9:
      count += 0;
      break;
    case 10:
    case 'J':
    case 'Q':
    case 'K':
    case 'A':
      count-= 1;
      break;

  }

  if (card > 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(4); cc(5); cc(6);
Benjam Wondafrash
@BenjamWondafrash
Aug 09 2016 09:20
@Anntol does this mean that gitter has some security flaw? Some code returns something from server that we are not supposed to get? Injection...something
Anna
@Anntol
Aug 09 2016 09:20
@weijiqiang1024 you already had challenge how to check properties
Nupur Roy
@nupur06cherish
Aug 09 2016 09:22

```function destroyer(arr) {

var args = Array.prototype.slice.call(arguments);
var j,i,temp=[];
for(i=1;i<args.length;i++)
{
for(j=0;j<argsxamarin/xamarin-android@a16673d.length;j++){
if(argsManageIQ/manageiq@6c40d76 == args[0][j]){
argsxamarin/xamarin-android@a16673d.splice(j,1);
}
}
}

return argsxamarin/xamarin-android@a16673d;
}

destroyer([2, 3, 2, 3], 2, 3);
```

i am unable to comment the codes...
plz help
Teresa Garriot
@garriottteresa
Aug 09 2016 09:22

Why do we use quote for the value here:

// Setup
var testObj = {
  "hat": "ballcap",
  "shirt": "jersey",
  "shoes": "cleats"
};

but not

var myDog = "Hunter";
var dogs = {
Fido: "Mutt", Hunter: "Doberman", Snoopie: "Beagle"
};
weijq
@weijiqiang1024
Aug 09 2016 09:23
@Anntol ok,i'll review it,thank you
Anna
@Anntol
Aug 09 2016 09:24
@DanielLailvaux what error do you have?
Nupur Roy
@nupur06cherish
Aug 09 2016 09:24

```
function destroyer(arr) {

var args = Array.prototype.slice.call(arguments);
var j,i,temp=[];
for(i=1;i<args.length;i++)
{
for(j=0;j<argsxamarin/xamarin-android@a16673d.length;j++){
if(args[i] == args[0][j]){
argsxamarin/xamarin-android@a16673d.splice(j,1);
}
}
}

return argsxamarin/xamarin-android@a16673d;
}

}

destroyer([2, 3, 2, 3], 2, 3);

Anna
@Anntol
Aug 09 2016 09:25
@nupur06cherish help format
help format
CamperBot
@camperbot
Aug 09 2016 09:25

: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

Ananay
@ananaymital
Aug 09 2016 09:25
@nupur06cherish umm use // in front of the line you want to comment
Anna
@Anntol
Aug 09 2016 09:26
@garriottteresa for one word properties you can do both
Daniel Lailvaux
@DanielLailvaux
Aug 09 2016 09:26
@Anntol the result is:1 bet1 bet1 bet1 bet1 bet instead 5 bet
M-A-P-L-E
@M-A-P-L-E
Aug 09 2016 09:27
Hey! I have some problem at freecodecamp;
is my js code right?
var myStr = "FirstLine \n \ SecondLine \ \r ThirdLine";
Anna
@Anntol
Aug 09 2016 09:28
@DanielLailvaux count += " Bet"; - error is in there
Teresa Garriot
@garriottteresa
Aug 09 2016 09:29
@Anntol standardizing is less complicated............thanks @Anntol I will remember
Daniel Lailvaux
@DanielLailvaux
Aug 09 2016 09:29
@M-A-P-L-E you need two\ in front and behind SecondLine. @Anntol whats the problem? ive been trying to figure it out forever
Anna
@Anntol
Aug 09 2016 09:29
@M-A-P-L-E check whitespaces
Benjam Wondafrash
@BenjamWondafrash
Aug 09 2016 09:29
@garriottteresa If identifier name is Valid Javascript identifier name, no need for quotes. But if u would make the property like 123567:"boo" that handles as a number, so better use quotes. Read more about 'Valid variable names'
Ananay
@ananaymital
Aug 09 2016 09:29
@M-A-P-L-E
var myStr = "FirstLine\nSecondLine\rThirdLine";
Rahul Nayak
@pragyes31
Aug 09 2016 09:30
Hi Guys, how is the new keyword different from object.create while creating new instances of object?
M-A-P-L-E
@M-A-P-L-E
Aug 09 2016 09:30
sorry, actually here: var myStr = "FirstLine \n \ SecondLine \ \r ThirdLine";
But the complier not display right
Anna
@Anntol
Aug 09 2016 09:30
@DanielLailvaux you should return string instead you change your count type to string
Benjam Wondafrash
@BenjamWondafrash
Aug 09 2016 09:30
@M-A-P-L-E instructions say No spaces...
@M-A-P-L-E the backslashes will not show correctly here...
Joni petriashvili
@Jonhnwhantcoding
Aug 09 2016 09:31
could anyone check my code?
why it didn,t work

function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  for (var i = 0; i < arr.length; i++) {
    for (var j = 0; j < arr(i).length; j++)  {
      product *= arr[i][j];
    }
  }
M-A-P-L-E
@M-A-P-L-E
Aug 09 2016 09:32
Oh ! thanks a lot , so silly :))
Anna
@Anntol
Aug 09 2016 09:32
@Jonhnwhantcoding you return nothing
Benjam Wondafrash
@BenjamWondafrash
Aug 09 2016 09:32
@M-A-P-L-E So, no spaces between characters and \n or \r
Joni petriashvili
@Jonhnwhantcoding
Aug 09 2016 09:33
@Anntol I am on loops
Wendy
@WendyLearn
Aug 09 2016 09:33

function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  for (var i = 0; i < arr.length; i++) {
    for (var j = 0; j < arr[i].length; j++)  {
      product *= arr[i][j];
    }
  }
@Jonhnwhantcoding
Benjam Wondafrash
@BenjamWondafrash
Aug 09 2016 09:33
@M-A-P-L-E And read again how to write a backslash so u can SEE it printed
Daniel Lailvaux
@DanielLailvaux
Aug 09 2016 09:33
@Anntol oh i see! but now its still failing one criteria
Anna
@Anntol
Aug 09 2016 09:34
@DanielLailvaux you changed both returns?
@Jonhnwhantcoding you function should return something
Daniel Lailvaux
@DanielLailvaux
Aug 09 2016 09:35
@Anntol Yeah i did but its failing card sequence 7, 8, 9,
Markus Kiili
@Masd925
Aug 09 2016 09:36
@pragyes31 new keyword creates a new plain object and puts it as value of this and runs the given constructor. Object.create creates a new object with given properties and sets the prototype of the new object to given value.
new sets the prototype of the new object to the value of consturctors .prototype property.
M-A-P-L-E
@M-A-P-L-E
Aug 09 2016 09:37
@WendyLearn I see, tks you
Anna
@Anntol
Aug 09 2016 09:37
@DanielLailvaux what it returns?
Mark
@markgtl
Aug 09 2016 09:38
how can i copy code from the freecodecamp enviroment
without using cmd-c cmd-v
Daniel Lailvaux
@DanielLailvaux
Aug 09 2016 09:38
It's suppose to return "0 Hold" to pass and it does but it's still not passing
Mark
@markgtl
Aug 09 2016 09:38
some people copy the code with colors and stuff
Daniel Lailvaux
@DanielLailvaux
Aug 09 2016 09:38
@Anntol
C. Groot
@ClawdStrife
Aug 09 2016 09:39

Could anyone help me understand why this is not reading the 'else' statement?

'''function repeatStringNumTimes(str, num) {
var newstring= str.repeat(num);

if (num > 0){
return newstring;
} else {
return "";
}
}

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

CamperBot
@camperbot
Aug 09 2016 09:39
:bulb: to format code use backticks! ``` more info
Darth Skywalker
@adityaparab
Aug 09 2016 09:39
@markgtl : Highlight code by using mouse, Right Click -> Copy and then here right click -> paste?
Mark
@markgtl
Aug 09 2016 09:39

@adityaparab // Declare your variable here
var myGlobal = 10;

function fun1() {
// Assign 5 to oopsGlobal Here
oopsGlobal = 5;
}

// Only change code above this line
function fun2() {
var output = "";
if (typeof myGlobal != "undefined") {
output += "myGlobal: " + myGlobal;
}
if (typeof oopsGlobal != "undefined") {
output += " oopsGlobal: " + oopsGlobal;
}
console.log(output);
}

then you get this
but i want it like iopen
this is bad readably
C. Groot
@ClawdStrife
Aug 09 2016 09:40

```function repeatStringNumTimes(str, num) {
var newstring= str.repeat(num);

if (num > 0){
return newstring;
} else {
return "";
}
}

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

Darth Skywalker
@adityaparab
Aug 09 2016 09:40

@markgtl :

If you type

```js
// Declare your variable here
var myGlobal = 10;

function fun1() {
// Assign 5 to oopsGlobal Here
oopsGlobal = 5;
}

// Only change code above this line
function fun2() {
var output = "";
if (typeof myGlobal != "undefined") {
output += "myGlobal: " + myGlobal;
}
if (typeof oopsGlobal != "undefined") {
output += " oopsGlobal: " + oopsGlobal;
}
console.log(output);
}
```

it will be shown as

 // Declare your variable here
var myGlobal = 10;

function fun1() {
// Assign 5 to oopsGlobal Here
oopsGlobal = 5;
}

// Only change code above this line
function fun2() {
var output = "";
if (typeof myGlobal != "undefined") {
output += "myGlobal: " + myGlobal;
}
if (typeof oopsGlobal != "undefined") {
output += " oopsGlobal: " + oopsGlobal;
}
console.log(output);
}
C. Groot
@ClawdStrife
Aug 09 2016 09:40
sorry for the spam >.> it was unintended
Mark
@markgtl
Aug 09 2016 09:41
@adityaparab thats what I wanted! Thanks
CamperBot
@camperbot
Aug 09 2016 09:41
markgtl sends brownie points to @adityaparab :sparkles: :thumbsup: :sparkles:
:cookie: 526 | @adityaparab |http://www.freecodecamp.com/adityaparab
hai.pn
@firefoxvt
Aug 09 2016 09:41
@Anntol Hi Anna. I try to loop all item with for. What I miss?
C. Groot
@ClawdStrife
Aug 09 2016 09:41
thanks @adityaparab
CamperBot
@camperbot
Aug 09 2016 09:41
clawdstrife sends brownie points to @adityaparab :sparkles: :thumbsup: :sparkles:
:cookie: 527 | @adityaparab |http://www.freecodecamp.com/adityaparab
hai.pn
@firefoxvt
Aug 09 2016 09:41
My code:

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


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

// Change these values to test your function
lookUpProfile("Harry", "likes");
Markus Kiili
@Masd925
Aug 09 2016 09:42
@firefoxvt i<contacts.length
Also your code can return no such contact after checking only one contact.
Darth Skywalker
@adityaparab
Aug 09 2016 09:43
@firefoxvt : You're returning way too early.
hai.pn
@firefoxvt
Aug 09 2016 09:43
Screen Shot 2016-08-09 at 4.42.55 PM.png
Anna
@Anntol
Aug 09 2016 09:43
@DanielLailvaux count += 0; - actually this code is useless, or try resetting your challenge
DiogoCostaCunha
@DiogoCostaCunha
Aug 09 2016 09:43
Can you refer to the element of index [i] when you use str.replace ? Like str.replace( [i], [i] -20)? In order to subtract 20 to every element in the string? ( In a loop)
hai.pn
@firefoxvt
Aug 09 2016 09:43
This message was deleted
Bilyan Hadzhi
@bilyanhadzhi
Aug 09 2016 09:44
Hey! Can anyone help out with the 'Validate US Numbers' advanced algorithm? I've got this so far and it returns true for valid ones but also for some invalid ones. This one seems hella tough.
function telephoneCheck(str) {
  var result = str.match(/[1]?[\s]?[(\d)]{3,}([-]?|[\s]?)[\d]{3,}([-]?|[\s]?)[\d]{4}/g);
  if(result === null) {
    return false;
  }
  return true;
}
Wendy
@WendyLearn
Aug 09 2016 09:44
mycode: 'function lookUpProfile(firstName, prop){
// Only change code below this line
var answer = "No such contact";
contacts.some(function(arg) {
if (arg.firstName === firstName && arg.hasOwnProperty(prop) === true) {
answer = arg[prop];
} else if (arg.hasOwnProperty(prop) === false) {
answer = "No such property";
}
});
return answer;
// Only change code above this line
} '
Darth Skywalker
@adityaparab
Aug 09 2016 09:44

@firefoxvt : You can fix it by removing your last else if

and placing your return 'No such contact; after your for loop

hai.pn
@firefoxvt
Aug 09 2016 09:44
@Masd925 @adityaparab okay, I will assign to a variable and return after loop, thanks
CamperBot
@camperbot
Aug 09 2016 09:44
firefoxvt sends brownie points to @masd925 and @adityaparab :sparkles: :thumbsup: :sparkles:
:cookie: 528 | @adityaparab |http://www.freecodecamp.com/adityaparab
:star2: 2262 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
Aug 09 2016 09:45
@firefoxvt No need for that. Just place the returns correctly.
Wendy
@WendyLearn
Aug 09 2016 09:46

function lookUpProfile(firstName, prop){
// Only change code below this line
var answer = "No such contact";
contacts.some(function(arg) {
if (arg.firstName === firstName && arg.hasOwnProperty(prop) === true) {
answer = arg[prop];
} else if (arg.hasOwnProperty(prop) === false) {
answer = "No such property";
}
});
return answer;
// Only change code above this line
}

@firefoxvt

Darth Skywalker
@adityaparab
Aug 09 2016 09:46

@WendyLearn : Just a suggestion,

if you type

```js

console.log('test');
// and your other js code
```

it will be displayed as

console.log('test');
// and your other js code
Wendy
@WendyLearn
Aug 09 2016 09:48
I tried but I can't type it like you example
hai.pn
@firefoxvt
Aug 09 2016 09:48
thanks @WendyLearn
CamperBot
@camperbot
Aug 09 2016 09:48
firefoxvt sends brownie points to @wendylearn :sparkles: :thumbsup: :sparkles:
:cookie: 233 | @wendylearn |http://www.freecodecamp.com/wendylearn
Joni petriashvili
@Jonhnwhantcoding
Aug 09 2016 09:48
guys i would like to know how i,m getting 20 in this challange
could anyone answer me?
Daniel Lailvaux
@DanielLailvaux
Aug 09 2016 09:48
@Anntol I reset and took it out but still not passing me
DiogoCostaCunha
@DiogoCostaCunha
Aug 09 2016 09:49
This message was deleted
hai.pn
@firefoxvt
Aug 09 2016 09:49
@WendyLearn Can you post your full code?
Anna
@Anntol
Aug 09 2016 09:49
@DanielLailvaux show last code or consider removing useless part at all
DiogoCostaCunha
@DiogoCostaCunha
Aug 09 2016 09:49
@Jonhnwhantcoding you have to add
@Jonhnwhantcoding var total =0;
for (var i =0; i < myArr.length; i++); {
total +=myArr[i];
}
Sergi
@SergiOca87
Aug 09 2016 09:50

Can anyone see anything wrong with this simple code? It gives me an error but it's writen like this in every example: var lookUp = {

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

lookUp["bravo"];

DiogoCostaCunha
@DiogoCostaCunha
Aug 09 2016 09:50
@Jonhnwhantcoding that way you define the first var as 0 and then you keep track of the loop process in it
@Sergi-O no errors
Wendy
@WendyLearn
Aug 09 2016 09:50
@firefoxvt

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

function lookUpProfile(firstName, prop){
// Only change code below this line
var answer = "No such contact";
contacts.some(function(arg) {
if (arg.firstName === firstName && arg.hasOwnProperty(prop) === true) {
answer = arg[prop];
} else if (arg.hasOwnProperty(prop) === false) {
answer = "No such property";
}
});
return answer;
// Only change code above this line
}

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

jamesmillerho
@jamesmillerho
Aug 09 2016 09:51
@Billy5500 reread regex MDN, wrong syntax
hai.pn
@firefoxvt
Aug 09 2016 09:51
what is contacts.some(function(arg) ? I dont understand @WendyLearn
Sergi
@SergiOca87
Aug 09 2016 09:51
@DiogoCostaCunha It says expected an assignment or function instead saw an expression