These are chat archives for FreeCodeCamp/HelpJavaScript

8th
Apr 2016
Dhruv
@printdhruv
Apr 08 2016 00:00
i dont think so
what you do when you see a problem
read theory somewhere or understand it your own
just by coding it
Stephane
@overmelo
Apr 08 2016 00:02
i just needed to put the * before product. @Takumar sometimes the grammar of programming is what need to be understand
Aleksander Gębicki
@Takumar
Apr 08 2016 00:02
@printdhruv hmm it depends on complexity of problem. If I can divide problem to small parts and have enough Math or other knowledge to do it myself I just divide it to pieces, describe in short sentences and try to write code.
Sometimes I write code with others, asking what they are trying to do, and code is my answer to their questions.
In such way whole solution can be written.
@printdhruv for sure you will find many programming gurus who know English language and can describe you theory lying under solving problems better.
I'm still learning how to code, and how to speak and write English - such simultaneous learning takes more time for sure.
Stephane
@overmelo
Apr 08 2016 00:06
sure
Aleksander Gębicki
@Takumar
Apr 08 2016 00:06
@printdhruv returning to your question, of course sometimes you have to find algorithm of solving problem in books (or in the Internet nowadays). There is no way to find all solutions on your own.
@overmelo in IT area many times you are required to know many programming languages and they have their own grammar. Some structures like loops are similar but others may differ a lot.
@printdhruv okay, I hope I answered your question. I have to go now for sure.
Good night!
Stephane
@overmelo
Apr 08 2016 00:09
good night
Josh Bivens
@joshbivens
Apr 08 2016 00:12
Can anyone help me with Diff Two Arrays?
Kevin Mulligan
@kmulligan
Apr 08 2016 00:20
@joshbivens I'll take a crack at it. Hoping someone can tell me why my code doesn't pass Everything Be True
rkDeason
@rkDeason
Apr 08 2016 00:24
Am I way off base here?
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
  var lookup = {
    alpha: "Adams",

    bravo: "Boston",

    charlie: "Chicago",

    delta: "Denver",

    echo: 
      "Easy",

   foxtrot: 
     "Frank"
  };
result=lookup[val];
  // Only change code above this line
  return result;
}

// Change this value to test
phoneticLookup("alpha");
Vik
@vvang044
Apr 08 2016 00:29
hello all can anyone tell me how to approach seek and destroy?
Frank XC
@tenkdayz
Apr 08 2016 00:31
@vvang044 for loop. or filter
Stephane
@overmelo
Apr 08 2016 00:32
@rkDeason put the parameters in "" also
Vik
@vvang044
Apr 08 2016 00:34
thank you.....
rkDeason
@rkDeason
Apr 08 2016 00:34
it didn't like that either.. but thx @overmelo
CamperBot
@camperbot
Apr 08 2016 00:34
rkdeason sends brownie points to @overmelo :sparkles: :thumbsup: :sparkles:
:star: 227 | @overmelo | http://www.freecodecamp.com/overmelo
Vik
@vvang044
Apr 08 2016 00:35
im dumb as a rock.....couldnt figure it out i need this....
help seek and destroy
CamperBot
@camperbot
Apr 08 2016 00:35

:point_right: algorithm seek and destroy [wiki]

Explanation:

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

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

Frank XC
@tenkdayz
Apr 08 2016 00:37
@vvang044 I'm working on it too.. because my first answer was a mess. lol
Vik
@vvang044
Apr 08 2016 00:37
i had to re-do this three times.....i am just about to give up.....lost half my hair from scratching
Frank XC
@tenkdayz
Apr 08 2016 00:38
I'm using something like.. Array.push(arguments[i]);
Stephane
@overmelo
Apr 08 2016 00:38
@rkDeason paste your updated code here, you should have "alpha":"Adams",...
wonsi
@wonsi
Apr 08 2016 00:40
Does navigator.geolocation not work with chrome? Seems to work fine in firefox but I can't get any kind of response in chrome. Thanks
Yomi
@Joll59
Apr 08 2016 00:41
@rkDeason @overmelo I am on same problem and i cant seem to figure out either, @rkDeason our code almost match up
Vik
@vvang044
Apr 08 2016 00:41
i tried that.....
rkDeason
@rkDeason
Apr 08 2016 00:41
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
  var lookup = {
    "alpha":"Adams",

    "bravo":"Boston",

    "charlie":"Chicago",

    "delta":"Denver",

    "echo":"Easy",

   "foxtrot":"Frank"
  };
result=lookup[val];
  // Only change code above this line
  return result;
}

// Change this value to test
phoneticLookup("alpha");
Yomi
@Joll59
Apr 08 2016 00:43

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

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

result = copSpeak.val;
// Only change code above this line
return result;
}

// Change this value to test
phoneticLookup("alpha");
'

oops
Vik
@vvang044
Apr 08 2016 00:44
you can edit that code
rkDeason
@rkDeason
Apr 08 2016 00:44
I just hit reset and pasted that code back and it worked that time! woohoo!!
Yomi
@Joll59
Apr 08 2016 00:44
@rkDeason awesome, i will try the same
Stephane
@overmelo
Apr 08 2016 00:45
i was wondering already
Vik
@vvang044
Apr 08 2016 00:45
@rkDeason add lookup[val] before result=lookup[val]
Yomi
@Joll59
Apr 08 2016 00:46
mine also worked
with the modification from your code thanks @rkDeason
CamperBot
@camperbot
Apr 08 2016 00:46
joll59 sends brownie points to @rkdeason :sparkles: :thumbsup: :sparkles:
:star: 219 | @rkdeason | http://www.freecodecamp.com/rkdeason
rkDeason
@rkDeason
Apr 08 2016 00:46
I pasted my exact same code back in the window and it runs now! the quotes around the parameter were the fix!! :)
Stephane
@overmelo
Apr 08 2016 00:46
congrats
Vik
@vvang044
Apr 08 2016 00:47
@tenkdayz any luck.....?
rkDeason
@rkDeason
Apr 08 2016 00:47
thanks @overmelo
CamperBot
@camperbot
Apr 08 2016 00:47
rkdeason sends brownie points to @overmelo :sparkles: :thumbsup: :sparkles:
:warning: rkdeason already gave overmelo points
rkDeason
@rkDeason
Apr 08 2016 00:47
aww c'mon camperbot that was worth two points!
Vik
@vvang044
Apr 08 2016 00:48
lol
Frank XC
@tenkdayz
Apr 08 2016 00:48
@vvang044 working on it :) I'm trying not to use too many for loops but I'll post the new answer
Vik
@vvang044
Apr 08 2016 00:48
its too confusing to use for loops
good luck @tenkdayz
bitgrower
@bitgrower
Apr 08 2016 00:49
what's too confusing to use for loops for, @vvang044 ?
Vik
@vvang044
Apr 08 2016 00:50
trying to do the exercise seek and destroy
bitgrower
@bitgrower
Apr 08 2016 00:50
yeah, filter's much better :)
Vik
@vvang044
Apr 08 2016 00:50
see.....
rkDeason
@rkDeason
Apr 08 2016 00:51
thanks @Joll59 for the brownie points! glad yours is working too
CamperBot
@camperbot
Apr 08 2016 00:51
rkdeason sends brownie points to @joll59 :sparkles: :thumbsup: :sparkles:
:star: 226 | @joll59 | http://www.freecodecamp.com/joll59
Vik
@vvang044
Apr 08 2016 00:51
is there anyway to write the code without using the argument?
David Gullyas
@dgulyas
Apr 08 2016 00:51
Is there a way to run the code in the editor and see the output? The closest I can find is clicking the Run tests button.
bitgrower
@bitgrower
Apr 08 2016 00:52
if there is, I don't know of it, @dgulyas -- but there are plenty of js "playgrounds"
help js resources
David Gullyas
@dgulyas
Apr 08 2016 00:52
ok, thanks. I'll find one with google.
bitgrower
@bitgrower
Apr 08 2016 00:52
jsfiddle, repl.it, jsbin ... one of my favs is pythontutor.com/javascript.html
...and, of course, there's always codepen ...
henrywashere
@henrywashere
Apr 08 2016 00:57
question, what exactly does the REMAINDER OPERATOR(%) do????
bitgrower
@bitgrower
Apr 08 2016 00:58
you remember when doing long division and there was a remainder if the number didn't go into the number you were dividing into evenly ?
henrywashere
@henrywashere
Apr 08 2016 00:58
ya
bitgrower
@bitgrower
Apr 08 2016 00:59
well ... that remainder is what the reaminder operator gives you ...
Vik
@vvang044
Apr 08 2016 01:00
7 % 3 = 1
bitgrower
@bitgrower
Apr 08 2016 01:00

so ... if I want to see if a number is evenly divisible by 2, I would go ...

num % 2

if the number is 1, then it doesn't, if it's 0, it does

Frank XC
@tenkdayz
Apr 08 2016 01:00
@vvang044 bingo
Vik
@vvang044
Apr 08 2016 01:00
got it?
Frank XC
@tenkdayz
Apr 08 2016 01:00
function destroyer(arr) {
  // Remove all the values
  var arr1 = [], arr2 =[],arr3 = [];
  for(var i=0;i<arguments.length;i++){
    if(i===0){
      arr1=arguments[i];
    }else{
      arr2.push(arguments[i]);
    }
  }
  for(var j=0;j<arr1.length;j++){
    if(arr2.includes(arr1[j])){
      var find = arr1.indexOf(arr1[j]);
      delete arr1[find];
    }
  }

  function trim(array){
    for(var k=0;k<array.length;k++){
      if(Boolean(array[k])){
        arr3.push(array[k]);
      }
    }
  }
  trim(arr1);
  return arr3;
}
Vik
@vvang044
Apr 08 2016 01:00
all i managed to do is write the first for loop....and i dont know how to go after that
Frank XC
@tenkdayz
Apr 08 2016 01:01
I'm sure there
bitgrower
@bitgrower
Apr 08 2016 01:01
that's a lot of hard work there ...
Frank XC
@tenkdayz
Apr 08 2016 01:01
I'm sure there's a better way though
bitgrower
@bitgrower
Apr 08 2016 01:02
yes, like what @vvang044 and I said earlier ... array.filter
Frank XC
@tenkdayz
Apr 08 2016 01:02
yea.. lol
Vik
@vvang044
Apr 08 2016 01:02
i need to sleep on that code in order to understood what is going on
bitgrower
@bitgrower
Apr 08 2016 01:03
...and you can just make an array of arrays to store your arguments in ... naming them literally is kinda hard work ... doesn't make your program general ...
henrywashere
@henrywashere
Apr 08 2016 01:03
ok i think i got it
Frank XC
@tenkdayz
Apr 08 2016 01:03
i can write comments so you know what's happening
henrywashere
@henrywashere
Apr 08 2016 01:03
thanks @bitgrower @vvang044
CamperBot
@camperbot
Apr 08 2016 01:03
henrywashere sends brownie points to @bitgrower and @vvang044 :sparkles: :thumbsup: :sparkles:
bitgrower
@bitgrower
Apr 08 2016 01:03

lol @vvang044 -- yeah ...

@tenkdayz -- if you're gonna write a bunch of lines of code ... and especially if you want others to look at it ... ADD comments, please!

CamperBot
@camperbot
Apr 08 2016 01:03
:star: 969 | @bitgrower | http://www.freecodecamp.com/bitgrower
:star: 267 | @vvang044 | http://www.freecodecamp.com/vvang044
bitgrower
@bitgrower
Apr 08 2016 01:04
LOL ... snap there, @tenkdayz
interesting name ... are you there yet ?
yw @henrywashere
Frank XC
@tenkdayz
Apr 08 2016 01:07
function destroyer(arr) {
  // Remove all the values
  var arr1 = [], arr2 =[],arr3 = [];
  for(var i=0;i<arguments.length;i++){
    if(i===0){//first argument is always an array so set equal to arr1.
      arr1=arguments[i];
    }else{
      arr2.push(arguments[i]);//other arguments pushed to arr2
    }
  }
  for(var j=0;j<arr1.length;j++){
    if(arr2.includes(arr1[j])){//see if any of arr1's values are in arr2
      var find = arr1.indexOf(arr1[j]);//if so find the index of that value
      delete arr1[find];//and delete it
    }
  }
 //delete set's values to null 
  function trim(array){//this function pushes the non null values into arr3
    for(var k=0;k<array.length;k++){
      if(Boolean(array[k])){
        arr3.push(array[k]);
      }
    }
  }
  trim(arr1);//trim arr1
  return arr3;
}
Vik
@vvang044
Apr 08 2016 01:08
@tenkdayz great....code..... my brain is dumb as a rock.....i will save your code for later....but i will try to use filter( ) option.....
and come up other solution
Frank XC
@tenkdayz
Apr 08 2016 01:09
I almost always go the hard route .. that's where I learn more.
Vik
@vvang044
Apr 08 2016 01:11
haha....i go for easy route....thats how i learn
Vik
@vvang044
Apr 08 2016 01:31
.
Vik
@vvang044
Apr 08 2016 01:47
this is quite
leanminmachine
@leanminmachine
Apr 08 2016 02:02
is anyone here.
Alex Boquist
@aplchian
Apr 08 2016 02:02
hi
Kurt Johnson
@pompan129
Apr 08 2016 02:03
@minminimal whats up?
leanminmachine
@leanminmachine
Apr 08 2016 02:03
i need help for bonfire diff two arrays
CamperBot
@camperbot
Apr 08 2016 02:03
type bonfire name to get some info on that bonfire. And check HelpBonfires chatroom
leanminmachine
@leanminmachine
Apr 08 2016 02:03
bonfire diff two arrays
CamperBot
@camperbot
Apr 08 2016 02:03

:fire:Bonfire: Diff Two Arrays :link:

function diff(arr1, arr2) {
  var newArr = [];
  // Same, same; but different.
  return newArr;
}

diff([1, 2, 3, 5], [1, 2, 3, 4, 5]);

Compare two arrays and return a new array with any items not found in both of the original arrays.

more info:  bf details | bf links | hint

leanminmachine
@leanminmachine
Apr 08 2016 02:03
function diff(arr1, arr2) {

  var newArr = [];

  // Same, same; but different.

  //The concat() method returns a new array comprised of the array on which it is called joined with the array(s) and/or value(s) provided as arguments.

    //slice() copies object references into the new array.

   //The filter() method creates a new array with all elements that pass the test implemented by the provided function.

  //The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.


  // concat all elements into one array first. 

  var holderArr = arr1.concat(arr2);


  // indexOf to return a value of 0 if found or -1 if not found
  // if -1 (ie not found in newArr), use filter to push number into the array

  //Compare two arrays and return a new array with any items only found in one of the two given arrays, but not both. 


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

  var element1 = arr1[i];

  if (arr2.indexOf(element1) === -1) {
    newArr.push(element1);
  }


}

for (var j = 0; j < arr2.length; j++) {
  var element2 = arr2[j];

  if (arr1.indexOf(element2) === -1) {
    newArr.push(element2);
  }
}

    return newArr;


}

diff(["diorite", "andesite", "grass", "dirt", "pink wool", "dead shrub"], ["diorite", "andesite", "grass", "dirt", "dead shrub"]);
Kurt Johnson
@pompan129
Apr 08 2016 02:03
@minminimal whats wrong? have you started it?
leanminmachine
@leanminmachine
Apr 08 2016 02:04
seems like no ticks appear even though i get the right answers returned for the use cases
Jan Nissi Harrison
@NissiHarrison
Apr 08 2016 02:04
hello guys please help.....with this code...it says to multiply all array....pls review my code
function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  for(var i=0;i<arr.length;i++){
    for(var j=0;i<arr[i].length;j++){
      product*=arr[i]; 
    }
   }
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
Ken Truong
@kjjtruong
Apr 08 2016 02:05
hey everyone i'm stuck on the this challenge bonfire mutations
eeflores
@eeflores
Apr 08 2016 02:05
arr[i][j]
:point_up: April 8, 2016 12:05 PM @NissiHarrison
Kurt Johnson
@pompan129
Apr 08 2016 02:06
@minminimal looking now
Jan Nissi Harrison
@NissiHarrison
Apr 08 2016 02:07
still didnt solve the problem @eeflores
Vik
@vvang044
Apr 08 2016 02:07
@tenkdayz you doing the next bon fire?
Ken Truong
@kjjtruong
Apr 08 2016 02:07
where i need to check whether the first argument contains all of the letters in the second argument
eeflores
@eeflores
Apr 08 2016 02:07
@NissiHarrison product *= arr[i][j]; ?
Ken Truong
@kjjtruong
Apr 08 2016 02:07
function mutation(arr) {

  //split arguments and convert to lowercase
  var arg1 = arr[0].toLowerCase();
  var arg2 = arr[1].toLowerCase().split('');

  //Test arg2 against arg1. Return true if arg1 contains all of the letters of arg2
    for(var i = arg2.length - 1; i >= 0 ; i--) {
      if(arg1.indexOf(arg2[i], 0) >= 0) {
          return true;
      } else {
        i = -1;
        return false;
      }
    }

  return arg2;
}

mutation(["hello", "neo"]);
Jan Nissi Harrison
@NissiHarrison
Apr 08 2016 02:08
@eeflores it says an error that line 4 is an infinte loop and it may crash the browwser
Kurt Johnson
@pompan129
Apr 08 2016 02:08
@minminimal I think there is a bug. I just ran my solution (which already passed) and it failed. not even test one ... just return an array
Ken Truong
@kjjtruong
Apr 08 2016 02:08
I got all the tests to check OK with the exception of the one in the code. I suspect it to be something with me not breaking the loop properly...any ideas?
eeflores
@eeflores
Apr 08 2016 02:08
@NissiHarrison second for, the test case uses i instead of j
leanminmachine
@leanminmachine
Apr 08 2016 02:09
oh. its because the name of the function was different from the one they use to generate the usecases @pompan129
Coy Sanders
@coymeetsworld
Apr 08 2016 02:09
@minminimal change your function name from diff to diffArray
it appears they changed it
leanminmachine
@leanminmachine
Apr 08 2016 02:09
i changed mine from diff (the default) to diffArray and it worked
lol
thanks @coymeetsworld
CamperBot
@camperbot
Apr 08 2016 02:09
minminimal sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star: 488 | @coymeetsworld | http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
Apr 08 2016 02:09
too late lol
i was just looking at my solution and wondering why it wasn't working
Jan Nissi Harrison
@NissiHarrison
Apr 08 2016 02:09
@eeflores thnks i works now
CamperBot
@camperbot
Apr 08 2016 02:09
nissiharrison sends brownie points to @eeflores :sparkles: :thumbsup: :sparkles:
Coy Sanders
@coymeetsworld
Apr 08 2016 02:09
theyve been changing alot of their functions
CamperBot
@camperbot
Apr 08 2016 02:09
:star: 659 | @eeflores | http://www.freecodecamp.com/eeflores
Kurt Johnson
@pompan129
Apr 08 2016 02:09
@minminimal THats it! good find.
eeflores
@eeflores
Apr 08 2016 02:09
@NissiHarrison you're welcome
leanminmachine
@leanminmachine
Apr 08 2016 02:10
i know righT! haha
Vik
@vvang044
Apr 08 2016 02:11
anyone completed "where i belong" ?
Coy Sanders
@coymeetsworld
Apr 08 2016 02:12
ya @vvang044
lol they changed the function name there, when I completed it it was called where, now its getIndexToIns
Vik
@vvang044
Apr 08 2016 02:14
so first i need to insert the second argument and then i need to compare which one is the lowest and return the lowest?
is that right
rkDeason
@rkDeason
Apr 08 2016 02:14
Am I not supposed to use an If statement in this challenge? I keep getting Unexpected token {
This message was deleted
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here


 If (checkObj.hasOwnProperty(checkProp)) {
  return myObj[checkProp];
 }
else {
  return "Not Found";
}
}
// Test your code by modifying these values
checkObj("bed");
Coy Sanders
@coymeetsworld
Apr 08 2016 02:15
you're not really inserting @vvang044, you just need to know where in the array (once sorted) you would put that value
Vik
@vvang044
Apr 08 2016 02:15
im returning the index not the value
Coy Sanders
@coymeetsworld
Apr 08 2016 02:16
correct
Vik
@vvang044
Apr 08 2016 02:16
yuck....
Coy Sanders
@coymeetsworld
Apr 08 2016 02:17
well that makes it a little easier at least
just need to know where to put the value, not actually inserting it in
Vik
@vvang044
Apr 08 2016 02:17
so first im going to sort the first array
Coy Sanders
@coymeetsworld
Apr 08 2016 02:18
yes
rkDeason
@rkDeason
Apr 08 2016 02:18
I just changed the if to check myobj instead of checkobj but same error
Vik
@vvang044
Apr 08 2016 02:19
@rkDeason which exercise are you doing?
rkDeason
@rkDeason
Apr 08 2016 02:19
Testing Object for Properties
Coy Sanders
@coymeetsworld
Apr 08 2016 02:19
your If is capitalized @rkDeason
should be lowercase
rkDeason
@rkDeason
Apr 08 2016 02:19
OMG! thank you @coymeetsworld
CamperBot
@camperbot
Apr 08 2016 02:19
rkdeason sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star: 489 | @coymeetsworld | http://www.freecodecamp.com/coymeetsworld
rkDeason
@rkDeason
Apr 08 2016 02:20
I think it's time for me call it a night! LOL
Vik
@vvang044
Apr 08 2016 02:20
lol.....im eating and coding.....
rkDeason
@rkDeason
Apr 08 2016 02:20
lol
Vik
@vvang044
Apr 08 2016 02:20
its like addiction
just dont know when to stop.....
rkDeason
@rkDeason
Apr 08 2016 02:21
for realz! it's a problem! I don't even wanna go to work! i just want to code all nite and sleep all day!
Vik
@vvang044
Apr 08 2016 02:21
i wish.....but for me 5am comes early
Coy Sanders
@coymeetsworld
Apr 08 2016 02:21
np @rkDeason lol
rkDeason
@rkDeason
Apr 08 2016 02:21
I'm not far behind ya, 5:25
Vik
@vvang044
Apr 08 2016 02:22
you will catch up soon.....haha
im going to pick on @coymeetsworld brain little bit till i get the bonfire
lol
rkDeason
@rkDeason
Apr 08 2016 02:24
I've got to call it quits till tmrw! Nite guys!
Coy Sanders
@coymeetsworld
Apr 08 2016 02:24
gd @rkDeason
Vik
@vvang044
Apr 08 2016 02:24
nite
Coy Sanders
@coymeetsworld
Apr 08 2016 02:24
@vvang044 you got about 10 mins lol, have a dinner with a coworker whos leaving us
Vik
@vvang044
Apr 08 2016 02:25
crap.....lol
sorry i cant think straight all i managed to do was write a new variable that will sort the array and after.....poof
Coy Sanders
@coymeetsworld
Apr 08 2016 02:27
yeah, also the array.sort() function won't work there, just an FYI
you'll need to create your own sorting function for numbers, just a tip
Vik
@vvang044
Apr 08 2016 02:28
var newSortedArray = getIndexToIns.sort(arr);
that wont work?
Coy Sanders
@coymeetsworld
Apr 08 2016 02:29
try it :)
it sorts by character
so like [4, 10, 20] would sort to [10, 20, 4]
Vik
@vvang044
Apr 08 2016 02:30
hmm
oh good god know....i so i need to change that to ascending order
Frank XC
@tenkdayz
Apr 08 2016 02:30
@coymeetsworld you need a callback function to sort numbers.
Kurt Johnson
@pompan129
Apr 08 2016 02:31
@vvang044 you can also add a comparator function as 2nd parameter in sort()
Ken Truong
@kjjtruong
Apr 08 2016 02:31
sooo.... I'm still stuck on this if anyone has any ideas?
function mutation(arr) {

  //split arguments and convert to lowercase
  var arg1 = arr[0].toLowerCase();
  var arg2 = arr[1].toLowerCase().split('');

  //Test arg2 against arg1. Return true if arg1 contains all of the letters of arg2
    for(var i = arg2.length - 1; i >= 0 ; i--) {
      if(arg1.indexOf(arg2[i], 0) >= 0) {
          return true;
      } else {  
          return false;
      }

    }

  return arg2;
}

mutation(["hello", "neo"]);
Vik
@vvang044
Apr 08 2016 02:32
comparator?
Coy Sanders
@coymeetsworld
Apr 08 2016 02:32
@tenkdayz yes
i didn't say specifically a callback function but yeah that is what I did
Kurt Johnson
@pompan129
Apr 08 2016 02:33
@vvang044 how to compare elements in array if they are not characters (ie. numbers or objects etc...) check out examples on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
Vik
@vvang044
Apr 08 2016 02:34
thank you @pompan129 i will look at that
CamperBot
@camperbot
Apr 08 2016 02:34
vvang044 sends brownie points to @pompan129 :sparkles: :thumbsup: :sparkles:
:star: 450 | @pompan129 | http://www.freecodecamp.com/pompan129
Kurt Johnson
@pompan129
Apr 08 2016 02:39
@kjjtruong I think your returning after checking very 1st element
Frank XC
@tenkdayz
Apr 08 2016 02:39
@coymeetsworld I see ... I thought you were asking
Vik
@vvang044
Apr 08 2016 02:39
@pompan129 so my array is going to be numbers it will be var newSortedArray = getIndexToIns.sort(function(a-b);
and return a-b
i meant function(a,b)
Kurt Johnson
@pompan129
Apr 08 2016 02:40
@vvang044 right function(a,b){return a - b;}
Vik
@vvang044
Apr 08 2016 02:41
awesome.....first step is done....lol
Kurt Johnson
@pompan129
Apr 08 2016 02:41
@vvang044 :)
Vik
@vvang044
Apr 08 2016 02:42
@tenkdayz did you finish that bonfire?
Frank XC
@tenkdayz
Apr 08 2016 02:43
which one?
Vik
@vvang044
Apr 08 2016 02:43
where i belong
henrywashere
@henrywashere
Apr 08 2016 02:45

GUYS I NEED HELP WITH THIS
To test your learning, you will create a solution "from scratch". Place your code between the indicated lines and it will be tested against multiple test cases.

The algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32.

You are given a variable celsius representing a temperature in Celsius. Create a variable fahrenheit and apply the algorithm to assign it the corresponding temperature in Fahrenheit.

i have no idea what im suppose to do
whoopsie890
@whoopsie890
Apr 08 2016 02:46
Hi guys. Does anyone know how to check the hasOwnProperty of a nested JSON object?
Frank XC
@tenkdayz
Apr 08 2016 02:46
@vvang044 yeah.. oh god . it's awful.. everytime i look at my old answers I smh
Vik
@vvang044
Apr 08 2016 02:48
@henrywashere write a variable with the farenheit which equals to the formula
Frank XC
@tenkdayz
Apr 08 2016 02:49
This message was deleted
Vik
@vvang044
Apr 08 2016 02:50
celsius * 9/5 + 32 something like that
@henrywashere ^^^
Frank XC
@tenkdayz
Apr 08 2016 02:52
@whoopsie890 I could help
henrywashere
@henrywashere
Apr 08 2016 02:54
its saying fahrenheit is not defined
thisis cofusing
Vik
@vvang044
Apr 08 2016 02:55
var farenheit = celsius * 9/5 + 32;
whoopsie890
@whoopsie890
Apr 08 2016 02:55
@tenkdayz thanks. I'm on the record collection question of the javascript part. If you know the album id I want to know if if has the property artist. I tried doing collection[id].hasOwnProperty(prop), but it didn't work.
CamperBot
@camperbot
Apr 08 2016 02:55
whoopsie890 sends brownie points to @tenkdayz :sparkles: :thumbsup: :sparkles:
:star: 353 | @tenkdayz | http://www.freecodecamp.com/tenkdayz
Vik
@vvang044
Apr 08 2016 02:56
actually i am spelling fahrenheit
i typed the right spelling
henrywashere
@henrywashere
Apr 08 2016 02:56
huh tahts weird
i tried that before but it didnt work
i spelt it "fahrenheit" and ir finallt worked
Vik
@vvang044
Apr 08 2016 02:57
ok paste your code here
henrywashere
@henrywashere
Apr 08 2016 02:58
thanks @vvang044
CamperBot
@camperbot
Apr 08 2016 02:58
henrywashere sends brownie points to @vvang044 :sparkles: :thumbsup: :sparkles:
:star: 269 | @vvang044 | http://www.freecodecamp.com/vvang044
Vik
@vvang044
Apr 08 2016 02:58
happy coding
Frank XC
@tenkdayz
Apr 08 2016 02:58
@whoopsie890 can i see your code.. let me compare it to what i have
Jan Nissi Harrison
@NissiHarrison
Apr 08 2016 02:58
help me with contacts look up guys
//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
if(firstName==prop||prop=='lastName'||prop=='number'||prop=='likes'){
  for(var i=0;i<contacts.length;i++){
    if(contacts[i].firstName=="Kristian"&&prop=="lastName"){
      return contacts[i][prop];
    }
    else if(contacts[i].firstName=="Sherlock"&&prop=="likes"){
      return contacts[i][prop];
    }
    else if(contacts[i].firstName=="Harry"&&prop=="likes"){
      return contacts[i][prop];
    }
    else if(contacts[i].firstName=="Bon"&&prop=="number"){
      return "No such contact";
    }
    else if(contacts[i].firstName=="Aira"&&prop=="address"){
      return "No such property";
    }
  }
}
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Kristian", "lastname");
CamperBot
@camperbot
Apr 08 2016 02:58
no wiki entry for: me with contacts look up guyssetupvar 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 lookupprofilefirstname prop only change code below this lineiffirstnamepropproplastnamepropnumberproplikes forvar i0icontactslengthi ifcontactsifirstnamekristianproplastname return contactsiprop else ifcontactsifirstnamesherlockproplikes return contactsiprop else ifcontactsifirstnameharryproplikes return contactsiprop else ifcontactsifirstnamebonpropnumber return no such contact else ifcontactsifirstnameairapropaddress return no such property only change code above this line change these values to test your functionlookupprofilekristian lastname
Jan Nissi Harrison
@NissiHarrison
Apr 08 2016 02:59
help Profile Lookup
CamperBot
@camperbot
Apr 08 2016 02:59

:point_right: checkpoint profile lookup [wiki]

Checkpoint: Profile Lookup

Instructions

We have an array of objects representing different people in our contacts lists.

A lookUp function that takes firstName and a property (prop) as arguments has been pre-written for you.

The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.

If both are true, then return the "value" of that property.

If firstName does not correspond to any contacts then return "No such contact"

If prop does not correspond to any valid properties then return "No such property"

Remember to use Read-Search-Ask if you get stuck. Try to pair program. Write your own code.

:pencil: read more about checkpoint profile lookup on the FCC Wiki

Vik
@vvang044
Apr 08 2016 03:11
help where i belong
CamperBot
@camperbot
Apr 08 2016 03:11
no wiki entry for: where i belong
eeflores
@eeflores
Apr 08 2016 03:12
help where do
CamperBot
@camperbot
Apr 08 2016 03:12

:point_right: algorithm where do i belong [wiki]

Explanation:

This can be a tricky problem to understand. You need to find where in the array a number should be inserted by order, and return the index where it should go.

:pencil: read more about algorithm where do i belong on the FCC Wiki

Vik
@vvang044
Apr 08 2016 03:12
thats the one.....lol
too tired to type....i need to head to bed....night all...i will read this over
Jan Nissi Harrison
@NissiHarrison
Apr 08 2016 03:13
please help me in my code above
Daniel Gonzales
@choppd
Apr 08 2016 03:17
@NissiHarrison I think you're missing the point of this exercise. What you're doing is hard-coding the answer in your program. While this method may let you pass, it isn't really the point of the exercise. Try using a for loop with two if-statements embedded inside the for-loop.
Rithvik Vibhu
@rithvikvibhu
Apr 08 2016 03:18
@NissiHarrison Instead of so many IFs, try using .hasOwnProperty()
like contacts[i].hasOwnProperty(prop)
Jan Nissi Harrison
@NissiHarrison
Apr 08 2016 03:22
@rithvikvibhu ill try that
Jan Nissi Harrison
@NissiHarrison
Apr 08 2016 03:27
@choppd i dont really seem to get the idea in there....i cant visualize how to put a for loop with two if statements embedded inside a for loop
whoopsie890
@whoopsie890
Apr 08 2016 03:29
@NissiHarrison use one for loop with two statements
Jan Nissi Harrison
@NissiHarrison
Apr 08 2016 03:29
@whoopsie890 im okay with that but i dont seem to know if i can do it with this challenge
whoopsie890
@whoopsie890
Apr 08 2016 03:33
@NissiHarrison I think I see where you might have trouble. the obj.hasOwnProperty(property) gives you true or false. If you put an ! in front of it it is like putting a not in front of it.
if (!obj.hasOwnProperty(property)) is like saying if it doesn't have a property then do this
Jan Nissi Harrison
@NissiHarrison
Apr 08 2016 03:41
@whoopsie890 ive tried it but still no pass
ALMY91
@ALMY91
Apr 08 2016 03:45
// Setup
function phoneticLookup(val) {
  var result = "";

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

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

// Change this value to test
phoneticLookup("charlie");
anybody able to help me out here?
Daniel Gonzales
@choppd
Apr 08 2016 03:47
@ALMY91 What's the name of the challenge?
Alexandros Phylactou
@alexphylactou
Apr 08 2016 03:48
This message was deleted
Duncan T
@dtweedle
Apr 08 2016 03:49
@ALMY91 Are you trying to use numbers instead of strings?
Alexandros Phylactou
@alexphylactou
Apr 08 2016 03:52
@ALMY91 missing a break; somewhere?
ALMY91
@ALMY91
Apr 08 2016 03:54
wiki Using Objects for Lookups @choppd @Isymm @alexphylactou
CamperBot
@camperbot
Apr 08 2016 03:54
no wiki entry for: using objects for lookups @choppd @isymm @alexphylactou
ALMY91
@ALMY91
Apr 08 2016 03:54
wiki Using Objects for Lookups
CamperBot
@camperbot
Apr 08 2016 03:54

:point_right: challenge using objects for lookups [wiki]

Challenge: Using Objects for Lookups

Objects can be thought of as a key/value storage, like a dictionary. If you have tabular data, you can use an object to "lookup" values rather than a switch statement or an if/else chain. This is most useful when you know that your input data is limited to a certain range.

Here is an example of a simple reverse alphabet lookup:

var alpha = {
  1:"Z",
  2:"Y",
  3:"X",
  4:"W",
  ...
  24:"C",
  25:"B",
  26:"A"
};
alpha[2]; // "Y"
alpha[24]; // "C"

:pencil: read more about challenge using objects for lookups on the FCC Wiki

Daniel Gonzales
@choppd
Apr 08 2016 03:55
@ALMY91 Oh ok, so you don't need to use a switch statement for this one.
Something like:
var lookup = {
    "alpha":"Adams,
};
return lookup[val];
ALMY91
@ALMY91
Apr 08 2016 03:58
@choppd ahhh for some reason i think this was my old code , i just logged on. let me just changed it
Rithvik Vibhu
@rithvikvibhu
Apr 08 2016 04:07
@NissiHarrison Can you paste your latest code here? (if you're still here)
Jan Nissi Harrison
@NissiHarrison
Apr 08 2016 04:08
here is my new code please help me
//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].hasOwnProperty("Kristian")&&prop==contacts[i][prop]){
      return contacts[i][prop];
    }
    else if(firstName!=contacts[i].firstName){
      return "No such contact";
    }
    else if(prop!=contacts[i][prop]){
      return "No such Property";
    }

  }
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Kristian", "lastName");
Rithvik Vibhu
@rithvikvibhu
Apr 08 2016 04:09
Can you edit (hover over message and more options thing on the right side and add the ``` at the beginning of the code?
Jan Nissi Harrison
@NissiHarrison
Apr 08 2016 04:10
@rithvikvibhu finish
@rithvikvibhu kindly review
@rithvikvibhu the only checked there so far is the No such contact part
Leo19909
@Leo19909
Apr 08 2016 04:18
Gaya
Rithvik Vibhu
@rithvikvibhu
Apr 08 2016 04:18
@NissiHarrison First thing, replace the first if condition with: contacts[i].firstName == firstName && contacts[i].hasOwnProperty(prop). So, it checks if firstName (the argument) is equal to firstName (from contacts). It also checks if that contact .hasOwnProperty of prop (from argument). If both conditions are met, it returns the property value.
Leo19909
@Leo19909
Apr 08 2016 04:20

Guys help me to understand, here my site www.chudo-agenstvo.ru

Can you tell why this function is causing the conflict. Uncaught ReferenceError: spnoConflict is not defined
```
<script type="text/javascript">
jQuery(window).on('load', function() {
new JCaption('img.caption');
});
spnoConflict(function($){

                function mainmenu() {
                    $('.sp-menu').spmenu({
                        startLevel: 0,
                        direction: 'ltr',
                        initOffset: {
                            x: 0,
                            y: 0
                        },
                        subOffset: {
                            x: 0,
                            y: 0
                        },
                        center: 0
                    });
        }

        mainmenu();

        $(window).on('resize',function(){
            mainmenu();
        });


        });

window.setInterval(function(){var r;try{r=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}if(r){r.open("GET","./",true);r.send(null)}},3600000);
</script>
```

Rithvik Vibhu
@rithvikvibhu
Apr 08 2016 04:21
@nissiharrison Also, when you call return, the for loop stops and the message is returned. So, only the first contact is checked. (Kristian is not equal to Akira)
Jan Nissi Harrison
@NissiHarrison
Apr 08 2016 04:21
@rithvikvibhu still not working
Rithvik Vibhu
@rithvikvibhu
Apr 08 2016 04:26

@NissiHarrison You need to change the code a bit more. Try this inside the for loop:

If (firstName (from contacts) is equal to firstName (from argument) {
---- if ( contacts[i] has property (prop) {
-------- if ( contacts[i].firstName == firstName && contacts[i].hasOwnProperty(prop) ) { (This you already have)
------------ return contacts[i][prop]
--------}
----}
}

Oops
Let me complete that
@NissiHarrison Check it out
We shouldn't be giving complete answers, but thats the logic
Charly
@Ralooe
Apr 08 2016 04:31
hello eeveryone
how do i paste code here ?
Rithvik Vibhu
@rithvikvibhu
Apr 08 2016 04:31
wiki format
CamperBot
@camperbot
Apr 08 2016 04:31

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

Charly
@Ralooe
Apr 08 2016 04:33
k ... so i'm working on the chunky munky basic algorithm and i dont understand whats wrong with my code ...

```function myFunction(arr, n) {
var newArr = [];
var limit = arr.length/n;
for(i=0; i<= limit; i++){
var genArr = arr.slice(in,(i+1)n);
newArr.push(genArr);
}

return newArr;

}

crap didnt do it right -_-
Rithvik Vibhu
@rithvikvibhu
Apr 08 2016 04:33
@Ralooe The ``` need their own lines
Charly
@Ralooe
Apr 08 2016 04:33
ooooh
Rithvik Vibhu
@rithvikvibhu
Apr 08 2016 04:36
@Ralooe I personally prefer a while loop for this, but your code might work if you replace i++ with i += n
Charly
@Ralooe
Apr 08 2016 04:38
i'll try that ... the code does what its supposed to but its returning an empty array at the end too
Rithvik Vibhu
@rithvikvibhu
Apr 08 2016 04:38
@Ralooe Fixed your prob. Change (in,(i+1)n) to ( i*n , (i + 1)*n)
@Ralooe i <= limit-1 in your for loop instead of i <= limit
So its 1 less
Charly
@Ralooe
Apr 08 2016 04:42
@rithvikvibhu let me see
@rithvikvibhu that works but the code judge is not accepting it
i'm probably missing something else
@rithvikvibhu Thanks !
CamperBot
@camperbot
Apr 08 2016 04:44
ralooe sends brownie points to @rithvikvibhu :sparkles: :thumbsup: :sparkles:
:star: 300 | @rithvikvibhu | http://www.freecodecamp.com/rithvikvibhu
Aman Barnwal
@amanbarnwalce
Apr 08 2016 04:44

Why doesn't it work?

nstr[i].charAt(0).toUpperCase();

Leo19909
@Leo19909
Apr 08 2016 04:44
Guys. Please help with this problem. I want to install on the website feedback form. On the LAN works perfectly, the site is conflict js. Don't know how to solve this problem. Here this link works http://work.plurrimi.com. And I have on the website is not working www.chudo-agenstvo.ru. In logs writes Uncaught ReferenceError: spnoConflict is not defined
(index):175 Uncaught TypeError: Cannot read property 'datepicker' of null
Markus Kiili
@Masd925
Apr 08 2016 04:46
@amanbarnwalce Strings are immutable.
Aman Barnwal
@amanbarnwalce
Apr 08 2016 04:47
What does that mean?
Markus Kiili
@Masd925
Apr 08 2016 04:47
@amanbarnwalce There are no methods that change string content. All methods return a new string that you must assign somewhere.
Aman Barnwal
@amanbarnwalce
Apr 08 2016 04:48
Got it!
Thanks @Masd925
CamperBot
@camperbot
Apr 08 2016 04:48
amanbarnwalce sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1336 | @masd925 | http://www.freecodecamp.com/masd925
Arnaud Casamé
@arnaudcasame
Apr 08 2016 05:08
help Arguments Optional
CamperBot
@camperbot
Apr 08 2016 05:08

:point_right: algorithm arguments optional [wiki]

Explanation:

It can be quite complicated to understand what needs to be done. There are always many ways to do something when coding but regardless of the algorithm used, we have to create a program that does the following:

  • It has to add two numbers passed as parameters and return the sum.
  • It has to check if any of the numbers are actual numbers, otherwise return undefined and stop the program right there.
  • It has to check if it has one or two arguments passed. More are ignored.
  • If it has only one argument then it has to return a function that uses that number and expects another one, to then add it.

:pencil: read more about algorithm arguments optional on the FCC Wiki

Leo19909
@Leo19909
Apr 08 2016 05:16
Guys. Please help with this problem. I want to install on the website feedback form. On the LAN works perfectly, the site is conflict js. Don't know how to solve this problem. Here this link works http://work.plurrimi.com. And I have on the website is not working www.chudo-agenstvo.ru. In logs writes Uncaught ReferenceError: spnoConflict is not defined
(index):175 Uncaught TypeError: Cannot read property 'datepicker' of null
Rithvik Vibhu
@rithvikvibhu
Apr 08 2016 05:17
What is spnoConflict?
Rithvik Vibhu
@rithvikvibhu
Apr 08 2016 05:23
@Leo19909 You seem to be calling spnoConflict() twice, but the function itself is never defined. In your home page source line 106 and http://www.chudo-agenstvo.ru/plugins/system/helix/js/helix.core.js line 8
Leo19909
@Leo19909
Apr 08 2016 05:26
@rithvikvibhu Now she called once, I removed the second call to this function. Any idea how to remove this error?. I am suffering for a week.
now shows error in this code
 <script type="text/javascript">
jQuery(window).on('load',  function() {
                new JCaption('img.caption');
            });
spnoConflict(function($){

                    function mainmenu() {
                        $('.sp-menu').spmenu({
                            startLevel: 0,
                            direction: 'ltr',
                            initOffset: {
                                x: 0,
                                y: 0
                            },
                            subOffset:
Javier
@sh1g
Apr 08 2016 05:30
function updateRecords(id, prop, value) {
  if(value !== "" && value !== "tracks"){
    collection[id][prop] = value;
    return collection;
  }
  else if (prop === "tracks" && value !== ""){
    collection[id] = prop.push(value);
    return collection;
  }
  else if (value === ""){
    delete collection[prop];
    return collection;
  }
  else {
  return collection;
  }
}
any tips on my code. It does what it needs to but it doesn't complete the challenge
Rithvik Vibhu
@rithvikvibhu
Apr 08 2016 05:31
@leo19909 the function is not defined at all. And it isnt about conflict, the function name has the word 'conflict' thats it
Calling the function multiple times is okay, once it is defined
Javier
@sh1g
Apr 08 2016 05:34
do I have my code backwards? DX going to try taht
that*
GowthamReddyAmbati
@GowthamReddyAmbati
Apr 08 2016 05:35
hi i'm unable to finish the challenge.. would you please help me in this
~

~ 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++;
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count--;
break;

}
if(count>0)
{
return count + "bet";
}
else
{

      return count + " Hold";
    }

// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display

cc(2); cc(2); cc(10);
~

Javier
@sh1g
Apr 08 2016 05:36
your bet is lower case
Yomi
@Joll59
Apr 08 2016 05:38
wiki Nesting For Loops
CamperBot
@camperbot
Apr 08 2016 05:38

:point_right: challenge nesting for loops [wiki]

Challenge: Nesting For Loops

If you have a multi-dimensional array, you can use the same logic as the prior Challenge to loop through both the array and any sub-arrays. Here is an example:

    var arr = [
      [1,2], [3,4], [5,6]
    ];
    for (var i=0; i < arr.length; i++) {
      for (var j=0; j < arr[i].length; j++) {
        console.log(arr[i][j]);
      }
    }

This outputs each sub-element in arr one at a time. Note that for the inner loop, we are checking the .length of arr[i], since arr[i] is itself an array.
:pencil: read more about challenge nesting for loops on the FCC Wiki

Leo19909
@Leo19909
Apr 08 2016 05:38
@rithvikvibhu Is it possible to disable this function? The fact that I don't know which file calls it...Remove the file helix.core.js does not help. And even if you comment out the script more error appears.
Markus Kiili
@Masd925
Apr 08 2016 05:40
@sh1g This is wrong: collection[id] = prop.push(value); The push method returns the new length of array (prop is not an array) and you substitute the record with it.
@sh1g This is also wrong delete collection[prop];
Javier
@sh1g
Apr 08 2016 05:43
@Masd925 ahh okay. It's weird how it's actually working and adding the track to the correct place. I switched around the else if statements and it broke. Will keep looking more into it. Thank yoU!
CamperBot
@camperbot
Apr 08 2016 05:43
sh1g sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1337 | @masd925 | http://www.freecodecamp.com/masd925
Aman Barnwal
@amanbarnwalce
Apr 08 2016 05:47

What's wrong here?

function largestOfFour(arr) {
var larr;
var lrg = 0;
for(i=0; i<arr.length; i++) {
for(j=0; j<arr[i].length; j++) {
if(lrg < arr[i][j]) {
larr[i] = arr[i][j];
}
}
}
// You can do this!
return larr;
}

Javier
@sh1g
Apr 08 2016 05:47
@Masd925 figured it out!!! was missing the [prop] in the steps =D
Markus Kiili
@Masd925
Apr 08 2016 05:49
@amanbarnwalce Initialize larr.
Aman Barnwal
@amanbarnwalce
Apr 08 2016 05:50
What does that mean? @Masd925
Markus Kiili
@Masd925
Apr 08 2016 05:50
@amanbarnwalce var larr=[];
This message was deleted
Eldar Tinjić
@EldarT90
Apr 08 2016 05:53
```js
function titleCase(str) {
  var strnew = str.split(" ");
  for (var i = 0; i<strnew.length; i++) {
  var newarr = strnew[i][0].replace([i][0].toUpperCase);
  }
  return newarr;
}

titleCase("I'm a little tea pot");
Markus Kiili
@Masd925
Apr 08 2016 05:53
@amanbarnwalce You should initialize lrg for each subarray and set it when you find a larger number than it.
Eldar Tinjić
@EldarT90
Apr 08 2016 05:53
any help regarding this? tnx
Markus Kiili
@Masd925
Apr 08 2016 05:55
@EldarT90 You should do this inside the loop: strnew[i]=... <- construct the titlecased word here using the original word strnew[i].
Eldar Tinjić
@EldarT90
Apr 08 2016 05:59
function titleCase(str) {
  var strnew = str.split(" ");
  for (var i = 0; i<strnew.length; i++) {
  strnew[i] = strnew[i].toUpperCase;
  }
  return strnew;
}

titleCase("I'm a little tea pot");
is this in better direction ?
Paul Borawski
@iAmNawa
Apr 08 2016 06:02
@EldarT90 what are you trying to do?
Make the string all uppercase?
Eldar Tinjić
@EldarT90
Apr 08 2016 06:02
@iAmNawa only capitalize every word
problem is when i try [i][0] it gives me eerror
so not sure how to target first letter only
without using i-0
Justin
@daemedeor
Apr 08 2016 06:04
@EldarT90 try charAt
Or slice
Eldar Tinjić
@EldarT90
Apr 08 2016 06:04
hmm, let me check that command
Justin
@daemedeor
Apr 08 2016 06:04
or substr
:)
There's a few ways
Eldar Tinjić
@EldarT90
Apr 08 2016 06:05
but still, i am curious why i cant target it the way i ve seen working in other examples
with [i][0]
Paul Borawski
@iAmNawa
Apr 08 2016 06:06
I think you want to make an array, make everything lowercase, then use charAt to capitalize the beginning of every array element
then return it as a string
with .join
@EldarT90 [i][0] won’t work because it’s a string, not an array
Justin
@daemedeor
Apr 08 2016 06:07
You can ... Or should be able to with [i][0] but it's... Probably some error best to tell us the console log probably some error is popping up
@iAmNawa its a js quirk , a string is like an array of charcters
Paul Borawski
@iAmNawa
Apr 08 2016 06:08
but he is trying to target the first word of an array, and then the first letter of it
Justin
@daemedeor
Apr 08 2016 06:09
Btw, charAt lets you get the letters but it doesn't return a mutated string of the rest of the letters
@iAmNawa have fun playing with strings in chrome console. Try "help"[0]
I don't suggest using it though quirky stuff is not fun for other people
Markus Kiili
@Masd925
Apr 08 2016 06:11
@EldarT90 You can get string characters with str[i] but not set them, because strings are immutable. Although str.charAt(i) is preferred over str[i].
Eldar Tinjić
@EldarT90
Apr 08 2016 06:12
@Masd925 so what should i do in the end ...
Justin
@daemedeor
Apr 08 2016 06:12
I'd prob use a custom string extension
Eldar Tinjić
@EldarT90
Apr 08 2016 06:12
at the end i got like 5 different solutions form you guys, and they are all strange to me :/
Justin
@daemedeor
Apr 08 2016 06:12
@EldarT90 i gave you methods to search. Learn! Try!
Markus Kiili
@Masd925
Apr 08 2016 06:13
@EldarT90 strnew[i]=strnew[i].charAt(0).to... <- uppercase the first character and add the rest of the original word lowercased.
Justin
@daemedeor
Apr 08 2016 06:15
The nice thing about programming is that there are many solutions
Paul Borawski
@iAmNawa
Apr 08 2016 06:15
hello world!
CamperBot
@camperbot
Apr 08 2016 06:15

welcome to FreeCodeCamp @iAmNawa!

Justin
@daemedeor
Apr 08 2016 06:16
@iAmNawa did you try out that string thing?
Paul Borawski
@iAmNawa
Apr 08 2016 06:16
I figured out the solution
Justin
@daemedeor
Apr 08 2016 06:16
a solution :)
Paul Borawski
@iAmNawa
Apr 08 2016 06:16
will a little help from my friends, I get by with a little help from my friends
Eldar Tinjić
@EldarT90
Apr 08 2016 06:16
yes, but can some1 explain me why my string is retunring only modified characters, why not the whole string
Paul Borawski
@iAmNawa
Apr 08 2016 06:16
yeah @daemedeor thanks!
CamperBot
@camperbot
Apr 08 2016 06:16
iamnawa sends brownie points to @daemedeor :sparkles: :thumbsup: :sparkles:
:star: 224 | @daemedeor | http://www.freecodecamp.com/daemedeor
Eldar Tinjić
@EldarT90
Apr 08 2016 06:17
if i remove charat, it gives me whole string
Paul Borawski
@iAmNawa
Apr 08 2016 06:17
Are you asking about the problem I was having earlier @daemedeor
Eldar Tinjić
@EldarT90
Apr 08 2016 06:17
so why charAt "removed" unaffected part of string
Justin
@daemedeor
Apr 08 2016 06:18
@iAmNawa nope about trying "help"[0] in the console. But good job on a solution
Elbert Cortez
@trip16661
Apr 08 2016 06:18
one question guys
hello btw
Justin
@daemedeor
Apr 08 2016 06:18
hi trip
Elbert Cortez
@trip16661
Apr 08 2016 06:18
if i name the function inside of a json jquery call
can i use that function to reload the content inside of the page without
Paul Borawski
@iAmNawa
Apr 08 2016 06:18
um yeah it returns h
Elbert Cortez
@trip16661
Apr 08 2016 06:18
actually reloading the whole page
Paul Borawski
@iAmNawa
Apr 08 2016 06:19
I thought you were talking about the code I was trying to figure out all day
Justin
@daemedeor
Apr 08 2016 06:19
@trip16661 youre looking for jquery.ajax
Sandra
@sandrabpineda
Apr 08 2016 06:19
This message was deleted

function largestOfFour(arr) {

var array;
var allNumbers;
var numbers=[];
var finished=[];// You can do this!
for (var i=0;i<arr.length; i+=1) {
for (var j=0; j<arr[i].length; j+=1){
array=arr[i][j];
numbers.push(array);
allNumbers=Math.max.apply(Math,numbers);

    }

    finished.push(allNumbers);

  }

return finished;
}

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

Justin
@daemedeor
Apr 08 2016 06:19
@iAmNawa i havent been on all day
Sandeep Prasad Bhatt
@sandy100
Apr 08 2016 06:19
hi,
```

// Setup
var myStorage = {
"car": {
"inside": {
"glove box": "maps",
"passenger seat": "crumbs"
},
"outside": {
"trunk": "jack"
}
}
};

// Only change code below this line

var gloveBoxContents = myStorage.car. inside ["glove box"]; // Change this line

what's wrong with that
Paul Borawski
@iAmNawa
Apr 08 2016 06:20
@sandy100 what are you trying to do?
Justin
@daemedeor
Apr 08 2016 06:20
@trip16661 you should just do a named function call in both
Sandeep Prasad Bhatt
@sandy100
Apr 08 2016 06:20
error: Use dot and bracket notation to access myStorage
@iAmNawa i wanna access "glove box" key's value
Elbert Cortez
@trip16661
Apr 08 2016 06:20
you mean make a function that calls the api? and then whenever an even is trigger it calls the function with different arguments
right?
Eldar Tinjić
@EldarT90
Apr 08 2016 06:21
K let me rewrite the question : If I use strnew[i] = strnew[i].charAt(0).toUpperCase(); it gives me only first letters (charat0) in the return string, BUT if i dont use charat(0) it gives me whole string; shouldnt charat(0) only modify first letters and not remove all unaffected letters @daemedeor @iAmNawa
Elbert Cortez
@trip16661
Apr 08 2016 06:21
I was thinking about it
Justin
@daemedeor
Apr 08 2016 06:21
@sandy100 yoi have an extra space
Sandeep Prasad Bhatt
@sandy100
Apr 08 2016 06:21
@daemedeor before inside ?
Justin
@daemedeor
Apr 08 2016 06:22
@EldarT90 ya you'll have to do a little bit more work. It's not the final piece. But look for slice
Elbert Cortez
@trip16661
Apr 08 2016 06:22
but im not sure if that would be correct
Justin
@daemedeor
Apr 08 2016 06:22
@sandy100 ya
Sandeep Prasad Bhatt
@sandy100
Apr 08 2016 06:22
i have removed and run
the problem is , Use dot and bracket notation to access myStorage
Justin
@daemedeor
Apr 08 2016 06:22
@sandy100 did you also get rid of the space between inside and the bracket notation?
Sandeep Prasad Bhatt
@sandy100
Apr 08 2016 06:22
i have already used both to access that
Eldar Tinjić
@EldarT90
Apr 08 2016 06:23
@daemedeor its not problem, but why it removes the rest of string, that is what i want to learn, same as i 've learned why [i][0] wont work - it wont work on strings and now i have it learned
Justin
@daemedeor
Apr 08 2016 06:23
@EldarT90 charat only returns the letter at the position you specified
Paul Borawski
@iAmNawa
Apr 08 2016 06:23
@sandy100 how about this? var gloveBoxContents = myStorage.car.inside["glove box"];
Sandeep Prasad Bhatt
@sandy100
Apr 08 2016 06:24
Oh yes @daemedeor @iAmNawa . THanks
CamperBot
@camperbot
Apr 08 2016 06:24
sandy100 sends brownie points to @daemedeor and @iamnawa :sparkles: :thumbsup: :sparkles:
:star: 355 | @iamnawa | http://www.freecodecamp.com/iamnawa
:star: 225 | @daemedeor | http://www.freecodecamp.com/daemedeor
Sandeep Prasad Bhatt
@sandy100
Apr 08 2016 06:24
the space creates the problem
but why is that , i don't understand
Justin
@daemedeor
Apr 08 2016 06:25
@sandy100 because of the way js parses, while it normally ignores whitespace but in those cases you have to get rid of them
Eldar Tinjić
@EldarT90
Apr 08 2016 06:25
@daemedeor so basicaly its checking for every char if its on specified position and if its not it ignores it completely - "deletes it" ?
Justin
@daemedeor
Apr 08 2016 06:26
@EldarT90 doesn't delete it, just returns the letter at the position you specify (in this case 0) you can use [i][0] but you need to do more wokr than just that
imo though, you should not use [i][0] it can be ... quirky
Eldar Tinjić
@EldarT90
Apr 08 2016 06:27
@daemedeor i deleted i-0 part, im trying with charAt
Justin
@daemedeor
Apr 08 2016 06:27
@EldarT90 yea but you still need to do a little more manipulation :D
Eldar Tinjić
@EldarT90
Apr 08 2016 06:28
@daemedeor yea i can see ^^ but if i try some cheezy move like strnew[i] = strnew[i] , it wont work because these letters are already gone oout of equatiion
@daemedeor and if i do the same BEFORE charat, it still wont work;
Justin
@daemedeor
Apr 08 2016 06:28
@EldarT90 you can still access it, you're not mutating strnew[i] if you do it on the same line, you're saving it over
thats the problem
so you can use a new variable
strnew[i] = strnew[i].charAt(0) will modify whats in strnew[i]
Eldar Tinjić
@EldarT90
Apr 08 2016 06:29
@daemedeor and try to merge variable with capitalized letters + normal letters?
Justin
@daemedeor
Apr 08 2016 06:29
so it makes sense
Shivam Arora
@shivamarora13
Apr 08 2016 06:29
How to find &, < , >, " , with the help of regular expression?
can any body please help?
Justin
@daemedeor
Apr 08 2016 06:30
var newStr = newVar + strnew[i].slice(1); @EldarT90 thats how you can do contatenation
Sandeep Prasad Bhatt
@sandy100
Apr 08 2016 06:30
@daemedeor oh , I will take care of that from next time :)
Justin
@daemedeor
Apr 08 2016 06:30
@sandy100 those spaces can getcha if you're not careful, im just used to parsing
Shivam Arora
@shivamarora13
Apr 08 2016 06:31
@shivamarora13
How to find &, < , >, " , with the help of regular expression?
can any body please help?
Justin
@daemedeor
Apr 08 2016 06:31
@shivamarora13 you should try out regexr.com ;D helps with building regex
i mean i could do it, but its easier to link that site
/[\&\<\>\"]/g
basically
plus its better to have a reference ...
its not the most elegant regex but it'll do the job
Eldar Tinjić
@EldarT90
Apr 08 2016 06:32
function titleCase(str) {
  var strnew = str.split(" ");
  for (var i = 0; i<strnew.length; i++) {
  var capital = strnew[i].charAt(0).toUpperCase();
  var rest = capital + strnew[i].slice(1);


  }
  return rest;
}

titleCase("I'm a little tea pot ");
it returns empty string, or empty something ...
Justin
@daemedeor
Apr 08 2016 06:33
@EldarT90 now you're always overwriting rest on every for loop
:)
and your last char in the array will be an empty string
hence the empty string return
Eldar Tinjić
@EldarT90
Apr 08 2016 06:34
@daemedeor if i put it outside of the loop, it still gives the error
Justin
@daemedeor
Apr 08 2016 06:34
@EldarT90 maybe because you are not creating the final sentence just doing the last array item (happens to be an empty string)
see the " " at the end which is what you're splitting on ;)
Paul Borawski
@iAmNawa
Apr 08 2016 06:35
We should write a script where everyone can bet their bitcoins on a grid and the person who takes all the bitcoins is the one that guesses what time daemador will sign on daily.
Justin
@daemedeor
Apr 08 2016 06:35
@iAmNawa and at some point i won't log on :O
@trip16661 sure sorry missed your last question
Paul Borawski
@iAmNawa
Apr 08 2016 06:36
@daemedeor someone can bet on that as well
Elbert Cortez
@trip16661
Apr 08 2016 06:36
@daemedeor don't worry thanks for answering anyway
CamperBot
@camperbot
Apr 08 2016 06:36
trip16661 sends brownie points to @daemedeor :sparkles: :thumbsup: :sparkles:
:star: 226 | @daemedeor | http://www.freecodecamp.com/daemedeor
Paul Borawski
@iAmNawa
Apr 08 2016 06:36
also, how many brownie points you get in a day, week, or month
Justin
@daemedeor
Apr 08 2016 06:36
@iAmNawa sniff
Paul Borawski
@iAmNawa
Apr 08 2016 06:37
daemycoin.com
Eldar Tinjić
@EldarT90
Apr 08 2016 06:37
@daemedeor you mean from str.split?
Justin
@daemedeor
Apr 08 2016 06:37
well... there are more people than I who come on often, daily
Shivam Arora
@shivamarora13
Apr 08 2016 06:37
@daemedeor Ok thanks
CamperBot
@camperbot
Apr 08 2016 06:37
shivamarora13 sends brownie points to @daemedeor :sparkles: :thumbsup: :sparkles:
:star: 227 | @daemedeor | http://www.freecodecamp.com/daemedeor
Justin
@daemedeor
Apr 08 2016 06:37
@EldarT90 yea if you conosle log that array then you'll see an empty one at the end
Eldar Tinjić
@EldarT90
Apr 08 2016 06:38
@daemedeor but if i remove that line entirely and switch strnew to just str, it still gives empty solution
Vivienne Sales
@Natto278
Apr 08 2016 06:38
I'm on the 'Adding a Default Option in Switch Statement challenge. I keep getting this reference error: switchOfStuff is not defined. What am I doing wrong? Here's my code:

function myTest(val) {
var answer = "";

// Only change code below this line

var switchOfStuff = "";

switch (answer) {
case "a":
console.log("apple");
break;

case "b":
  console.log("bird");
  break;

case "c":
  console.log("cat");
  break;

default:
  console.log("stuff");

}

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

// Change this value to test
switchOfStuff("b");

Aman Barnwal
@amanbarnwalce
Apr 08 2016 06:40

I did it this way and it works pretty well but I want to know if there's any other way around?

function repeatStringNumTimes(str, num) {
var nstr = str;
// repeat after me
if(num < 0) {
return "";
}
else{
for(i=1; i<num; i++) {
nstr = nstr.concat(str);
}
return nstr;
}
}

repeatStringNumTimes("abc", 3);

Olawale Akinseye
@brainyfarm
Apr 08 2016 06:40
@Natto278 it should be switch(val) remember val is the test case.
@amanbarnwalce, good job, you could also use a while loop or recursion as well.
Justin
@daemedeor
Apr 08 2016 06:42
@EldarT90 yup just keep trying ;)
Eldar Tinjić
@EldarT90
Apr 08 2016 06:43
@daemedeor so yeah, i can get last word capitalized, but only last one; but if i remove it from the loop i get none; is it time for yet another new var ?
Vivienne Sales
@Natto278
Apr 08 2016 06:43
I changed switch (answer) to switch (val) and I got rid of var switchOfStuff = answer. However, nothing is happening. Where did I go wrong @brainyfarm ?
Should I reset my code and start over?
Justin
@daemedeor
Apr 08 2016 06:43
@EldarT90 yes
Vivienne Sales
@Natto278
Apr 08 2016 06:44

Here's my new code: function myTest(val) {
var answer = "";

// Only change code below this line

switch (val) {
case "a":
console.log("apple");
break;

case "b":
  console.log("bird");
  break;

case "c":
  console.log("cat");
  break;

default:
  console.log("stuff");

}

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

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

Shivam Arora
@shivamarora13
Apr 08 2016 06:45
help Convert HTML Entities
CamperBot
@camperbot
Apr 08 2016 06:45

:point_right: algorithm convert html entities [wiki]

Problem Explanation:

  • You have to create a program that will convert HTML entities from string to their corresponding HTML entities. There are only a few so you can use different methods.

:pencil: read more about algorithm convert html entities on the FCC Wiki

Leo19909
@Leo19909
Apr 08 2016 06:46
Is it possible to disable this function Uncaught ReferenceError: spnoConflict is not defined? The fact that I don't know which file calls it...Remove the file helix.core.js does not help. And even if you comment out the script more error appears. here my site www.chudo-agenstvo.ru
Eldar Tinjić
@EldarT90
Apr 08 2016 06:48
@daemedeor var latest = rest.push(); - if i use command like this it wont work ... how can i add an element to the new variable, if not push or unshift
@daemedeor is it even possible to do with command?
Justin
@daemedeor
Apr 08 2016 06:48
@EldarT90 nope
V Arun Kumar
@arunvkumr
Apr 08 2016 06:49
@Natto278 you have to store the string to answer because that's what you are returning at the end of function.
after console.log() add another line for answer... like answer = 'apple' for all the cases
Olawale Akinseye
@brainyfarm
Apr 08 2016 06:49
@Natto278, instead of console.log(something), assign something as the value of answer variable.
V Arun Kumar
@arunvkumr
Apr 08 2016 06:49
or remove console.log and add answer statement.. @Natto278
Eldar Tinjić
@EldarT90
Apr 08 2016 06:50
@daemedeor than i dont know in which direction to go
Justin
@daemedeor
Apr 08 2016 06:50
@EldarT90 you can construct a new string to save it to ;)
kirbyedy
@kirbyedy
Apr 08 2016 06:50
@Leo19909 I think this is your problem: <link rel="stylesheet" media="screen" type="text/css" href="/templates/pri_simple/css/datepicker.css">
Vivienne Sales
@Natto278
Apr 08 2016 06:51

I just noticed that switchOfStuff("d") and switchOfStuff(4) should have the value of "stuff". Do I need to make a string like this: case "d":
console.log("stuff");
break;

case 4:
  console.log("stuff");
  break;

default:
  console.log("stuff");

I'm going to take your suggestions @arunkumrv and @brainyfarm and try again.

AaronCs
@AaronCs
Apr 08 2016 06:51
Is it just me or do the Basic Algorithm Challenges get gradually easier?
V Arun Kumar
@arunvkumr
Apr 08 2016 06:52
@Natto278 not required.. anything other than a,b,c willl automatically go to default case
Paul Borawski
@iAmNawa
Apr 08 2016 06:53
@AaronCs I think you are getting better
AaronCs
@AaronCs
Apr 08 2016 06:53
Oh sweet :D
Paul Borawski
@iAmNawa
Apr 08 2016 06:53
Pineapple makes you smart
Eldar Tinjić
@EldarT90
Apr 08 2016 06:54
@daemedeor that was nice hint ty ^^, but i have problem with spaces now
function titleCase(str) {
  var last = "";
  var strnew = str.split(" ");
  for (var i = 0; i<strnew.length; i++) {
  var capital = strnew[i].charAt(0).toUpperCase();
  var rest = capital + strnew[i].slice(1); 
   last += rest;
  }

  return last;
}

titleCase("I'm a little tea pot");
Olawale Akinseye
@brainyfarm
Apr 08 2016 06:54
@AaronCs, some are easy, some are hard and some would make you feel very dumb.
Vivienne Sales
@Natto278
Apr 08 2016 06:55
@arunkumrv Okay. How do you know when to use single quotes over double quotes?
Eldar Tinjić
@EldarT90
Apr 08 2016 06:55
aaa
Olawale Akinseye
@brainyfarm
Apr 08 2016 06:55
@EldarT90 you should trim the trailing space, there is no way you can get rid of it in your for loop.
Leo19909
@Leo19909
Apr 08 2016 06:56
@kirbyedy no, I removed that file and still the error
Eldar Tinjić
@EldarT90
Apr 08 2016 06:56
@brainyfarm im getting the right solution, i mean it looks right, but it doesnt check as right
@brainyfarm maybe i have white space at the end of string or ?
Vivienne Sales
@Natto278
Apr 08 2016 06:59

I have made the changes you have suggested @brainyfarm and @arunkumrv. The console.log shows the correct results when I change the values, but the program won't let me move to the next level. What am I doing wrong? Here's my code. function myTest(val) {
var answer = "";

// Only change code below this line

switch (val) {
case "a":
answer = "apple";
break;

case "b":
  answer = "bird";
  break;

case "c":
  answer = "cat";
  break;


default:
  answer = "stuff";

}

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

// Change this value to test
myTest(4);

Eldar Tinjić
@EldarT90
Apr 08 2016 06:59
@brainyfarm if i do the - return last - " " ; it wont work
Olawale Akinseye
@brainyfarm
Apr 08 2016 06:59
Yes @EldarT90, I had that issue too while I was doing the challenge, it is most likely the case that you have the white space. Use trim(last).
Before returning last
Eldar Tinjić
@EldarT90
Apr 08 2016 07:00
@brainyfarm it says that trim is not defined ... is it native function ?
@brainyfarm i mean built-in
V Arun Kumar
@arunvkumr
Apr 08 2016 07:00
@Natto278 you can use either of them of almost all cases.. the major diff i think is whatever you write in single quotes it exactly gets outputed and when you use double quotes you have to think about escape sequences and stuff.
Olawale Akinseye
@brainyfarm
Apr 08 2016 07:00
Hold on @EldarT90, let me check my solution.
Eldar Tinjić
@EldarT90
Apr 08 2016 07:02
@brainyfarm ok i got it
@brainyfarm it is built in function, thanks
CamperBot
@camperbot
Apr 08 2016 07:02
eldart90 sends brownie points to @brainyfarm :sparkles: :thumbsup: :sparkles:
:star: 1787 | @brainyfarm | http://www.freecodecamp.com/brainyfarm
Olawale Akinseye
@brainyfarm
Apr 08 2016 07:03
@EldarT90 it should be last.trim() and good job :+1:
Eldar Tinjić
@EldarT90
Apr 08 2016 07:03
@brainyfarm now its time to think about uncapitalizing properly
V Arun Kumar
@arunvkumr
Apr 08 2016 07:03
@Natto278 is this Adding a default option in Switch statements challenge?
Olawale Akinseye
@brainyfarm
Apr 08 2016 07:04
What do you mean @EldarT90?
Vivienne Sales
@Natto278
Apr 08 2016 07:04
@arunkumrv Yes, it is. I changed all of my double quotes to single quotes. I tested the values and got the correct outputs, but it still won't let me move the the next level. I think this challenge hates me.
Eldar Tinjić
@EldarT90
Apr 08 2016 07:04
@brainyfarm it was simple task, 1 line to make it all lowercase, so was easy job
@brainyfarm @daemedeor thanks once again , to both
CamperBot
@camperbot
Apr 08 2016 07:04
eldart90 sends brownie points to @brainyfarm and @daemedeor :sparkles: :thumbsup: :sparkles:
:warning: eldart90 already gave brainyfarm points
:star: 228 | @daemedeor | http://www.freecodecamp.com/daemedeor
V Arun Kumar
@arunvkumr
Apr 08 2016 07:05
@Natto278 i see the problem... Please don't change the function names defined in the fcc ide. you changed the function name to myTest(val)change it back to switchOfStuff(val).
kirbyedy
@kirbyedy
Apr 08 2016 07:06
@Leo19909 you removed the file and that line of code ?
Leo19909
@Leo19909
Apr 08 2016 07:06
@kirbyedy yes
kirbyedy
@kirbyedy
Apr 08 2016 07:07
but I still see it when I open your page
V Arun Kumar
@arunvkumr
Apr 08 2016 07:08
@Natto278 did it work? Only change the code that is mentioned in the comment.. :smile:
Leo19909
@Leo19909
Apr 08 2016 07:09
@kirbyedy no, I removed that file and still the error
@kirbyedy datepicker.css
Vivienne Sales
@Natto278
Apr 08 2016 07:10
I changed function myTest(val) to function switchOfStuff(val) and it worked! :-) Thank you, @arunkumrv and @brainyfarm! Moral of the story: You can change the code above this line!!
CamperBot
@camperbot
Apr 08 2016 07:10
natto278 sends brownie points to @arunkumrv and @brainyfarm :sparkles: :thumbsup: :sparkles:
:star: 1790 | @brainyfarm | http://www.freecodecamp.com/brainyfarm
:star: 430 | @arunkumrv | http://www.freecodecamp.com/arunkumrv
kirbyedy
@kirbyedy
Apr 08 2016 07:10
yes, but if you dont remove it from your html it will still call it, and cause an error in console
V Arun Kumar
@arunvkumr
Apr 08 2016 07:11
You're welcome.. :+1:
Leo19909
@Leo19909
Apr 08 2016 07:12
@kirbyedy I removed it from html and even css folder completely
kirbyedy
@kirbyedy
Apr 08 2016 07:12
give me the link again
after you saved it
Leo19909
@Leo19909
Apr 08 2016 07:13
kirbyedy
@kirbyedy
Apr 08 2016 07:13
yes, you see now that error is gone, but you have another one
Leo19909
@Leo19909
Apr 08 2016 07:16
@kirbyedy I don't know how to fix it and what file caused it
kirbyedy
@kirbyedy
Apr 08 2016 07:20
search for spnoConflict in your scripts that causes your problem right now, the template you are using has many scripts, so you will have to go through them to find exact problem
Aleksandr Kozlov
@Cu3bIu
Apr 08 2016 07:25
Im trying to add another object to JSON but i fail somehow.... something wrong with the syntax but I cant understand what exactly: var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
// Add record here
{
"artist": "Michael Jackson",
"title": "Billy Jeans",
"release_year": 1970,
"formats": [
"CS",
"8T",
"LP"],
"gold": true
}
];
Emil Aasa
@emilaasa
Apr 08 2016 07:25
I'm a bit confused about what the difference architecturally between an "engine" (like V8) or a VM (like JVM) is. Could anyone ELI5?
Dorel
@rubikxx
Apr 08 2016 07:26
function myTest(val) {
  var answer = "";
  // Only change code below this line

  switch (val) {
    case "a":
      answer = "apple"
      break;
    case "b":
      answer = "bird"
      break;
    case "c":
      answer = "cat"
      break;

    default:
      answer = "stuff"
  }


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

// Change this value to test
myTest('default');
Jackson Bates
@JacksonBates
Apr 08 2016 07:27
@Cu3bIu each object in myMusic needs to be separated by a comma. You have two objects, but a missing comma...
Dorel
@rubikxx
Apr 08 2016 07:27
Stuck at "Adding a default option in Switch statements". Won't allow me to go on. Don't know why
Aleksandr Kozlov
@Cu3bIu
Apr 08 2016 07:27
@JacksonBates thank you soo much!
CamperBot
@camperbot
Apr 08 2016 07:27
cu3biu sends brownie points to @jacksonbates :sparkles: :thumbsup: :sparkles:
:star: 288 | @jacksonbates | http://www.freecodecamp.com/jacksonbates
Jackson Bates
@JacksonBates
Apr 08 2016 07:28
@Cu3bIu np :)
V Arun Kumar
@arunvkumr
Apr 08 2016 07:29
@rubikxx your code is completely right.. the problem is the function name.. copy you code inside the comments that says.. don't change code below and above this line.. reset the code and paste it back.
@rubikxx or just change the function name to switchOfStuff(val).
Dorel
@rubikxx
Apr 08 2016 07:32
"thanks @arunkumrv "
CamperBot
@camperbot
Apr 08 2016 07:32
rubikxx sends brownie points to @arunkumrv :sparkles: :thumbsup: :sparkles:
:star: 431 | @arunkumrv | http://www.freecodecamp.com/arunkumrv
Leo19909
@Leo19909
Apr 08 2016 07:32
@kirbyedy Fix this error now writes spmenu is not a function
Dorel
@rubikxx
Apr 08 2016 07:32
Second option worked. Thank you!
V Arun Kumar
@arunvkumr
Apr 08 2016 07:33
You're welcome. :+1: :smile:
Shivam Arora
@shivamarora13
Apr 08 2016 07:39
help
Sum All Odd Fibonacci Numbers
CamperBot
@camperbot
Apr 08 2016 07:39

:point_right: algorithm sum all odd fibonacci numbers [wiki]

Explanation:

You will need to gather all the Fibonacci numbers and then check for the odd ones. Once you get the odd ones then you will add them all. The last number should be the number given as a parameter if it actually happens to be an off Fibonacci number.

:pencil: read more about algorithm sum all odd fibonacci numbers on the FCC Wiki

Aman Barnwal
@amanbarnwalce
Apr 08 2016 07:43
how do i initialize a 2d array?
Aleksander Gębicki
@Takumar
Apr 08 2016 07:44
@amanbarnwalce var arr = [ [3, 5], [6, 8] ];
Just put arrays into an array.
Aman Barnwal
@amanbarnwalce
Apr 08 2016 07:50
I want to create a blank 2d array to put the value later
ALMY91
@ALMY91
Apr 08 2016 07:51
// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
 var lookup = {
    1: "alpha",
    2: "bravo",
    3: "charlie",
    4: "delta",
    5: "echo",
    6:"foxtrot" };
      result = "Adams";
      break;
    case "bravo": 
      result = "Boston";
      break;
    case "charlie": 
      result = "Chicago";
      break;
    case "delta": 
      result = "Denver";
      break;
    case "echo": 
      result = "Easy";
      break;
    case "foxtrot": 
      result = "Frank";
  }

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

// Change this value to test
var val[2];
lookup[val];
anyone able to help me out in here?
i know that my code is wrong with the way im incorporating the results
but im not too sure how do i incorporate the results into the code
im on using objects for Looup challenge for Javascript
lookup
Aleksander Gębicki
@Takumar
Apr 08 2016 07:53
@ALMY91 lookup should be object, you need key:value pairs in it:
var lookup = {
  "alpha": "Adams",
  "beta": "Boston",
  ...
};
@ALMY91 after that you should assign value to result variable selected from lookup object - it should be val property from that object. val is parameter containing name of property.
You've made earlier challenge where you used variable to access property of object - check it on the map if you don't remember how to do it.
@amanbarnwalce just declare basic array, and insert arrays to it later: var arr = [];
ALMY91
@ALMY91
Apr 08 2016 07:58
@Takumar this is so frustrating sigh
@Takumar okay let me check tt challenge out again
@Takumar ahh i rbr i was bad at this challenge
poojaja
@poojaja
Apr 08 2016 08:05
Hi,I m stuck at here--> item +=arr.push([item]);
return item+=arr.shift() ; In output window ,Before :[1,2,3,4,5] 17 After : [2,3,4,5,10]
Eldar Tinjić
@EldarT90
Apr 08 2016 08:09
function largestOfFour(arr) {
  newarr = [];
  counter = 0;
  for (i = 0; i<arr.length; i++) {
    for (j = 0; j<arr[i].length; j++) {
      if (j>counter) {
        counter = j;
      }
      newarr.push(counter);
    }
  }
  return newarr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
am i on a right track?
Alessandro Nardecchia
@Sandronicus
Apr 08 2016 08:12

I'm stuck at here

// Example
var firstNameLength = 0;
var firstName = "Ada";

firstNameLength = firstName.length;

// Setup
var lastNameLength = 0;
var lastName = "Lovelace";

// Only change code below this line.

lastNameLength = lastName;

Use the .length property to count the number of characters in the lastName variable and assign it to lastNameLength

usharya
@usharya
Apr 08 2016 08:14
has anyone noticed, javascript is very similar to python
as someone who knows python well, I am sailing through the js course xD
Eldar Tinjić
@EldarT90
Apr 08 2016 08:14
@usharya yep, they are very similar, only syntax is different
usharya
@usharya
Apr 08 2016 08:15
yeah, in python we don't need var for defining variable
quite refreshing
quick question, for backend, we can use python? instead of using mongodb/node?
Moon Man
@CEREBR4L
Apr 08 2016 08:20
@usharya you can indeed
usharya
@usharya
Apr 08 2016 08:22
which framework will be needed then? dJango? or there is something better?
kirbyedy
@kirbyedy
Apr 08 2016 08:50
@CEREBR4L klingon... lol :D
Moon Man
@CEREBR4L
Apr 08 2016 08:52
@kirbyedy it's all qmike's fault
:'(
kirbyedy
@kirbyedy
Apr 08 2016 08:58
:D
WalaBenGharbia
@WalaBenGharbia
Apr 08 2016 09:00
hi , how to do the "Escape Sequences in Strings" test ?
it doesn't work with me
Markus Kiili
@Masd925
Apr 08 2016 09:00
@usharya Javascript, Java, Python etc are all C-family languages, so the syntax is similar.
Alessandro Nardecchia
@Sandronicus
Apr 08 2016 09:05

I need help with this challenge

// Example

var firstNameLength = 0;

var firstName = "Ada";

firstNameLength = firstName.length;

// Setup

var lastNameLength = 0;

var lastName = "Lovelace";

// Only change code below this line.

lastNameLength = lastName;

​Instructions

Use the .length property to count the number of characters in the lastName variable and assign it to lastNameLength.

Brendan Kinahan
@BKinahan
Apr 08 2016 09:09
follow the example
Alessandro Nardecchia
@Sandronicus
Apr 08 2016 09:10
i tried lastNameLenght = lastName.lenght but it doesn't work
WalaBenGharbia
@WalaBenGharbia
Apr 08 2016 09:11
var lastNameLength = lastName.length;
Brendan Kinahan
@BKinahan
Apr 08 2016 09:11
try fixing the spelling
WalaBenGharbia
@WalaBenGharbia
Apr 08 2016 09:12
write var before lastnamelength
Brendan Kinahan
@BKinahan
Apr 08 2016 09:12
@WalaBenGharbia nope, already declared
Alessandro Nardecchia
@Sandronicus
Apr 08 2016 09:12
@BKinahan I feel so dumb now ahaha..thanks
CamperBot
@camperbot
Apr 08 2016 09:12
sandronicus sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1245 | @bkinahan | http://www.freecodecamp.com/bkinahan
WalaBenGharbia
@WalaBenGharbia
Apr 08 2016 09:14
@BKinahan can you help me in "Escape Sequences in Strings" test
Brendan Kinahan
@BKinahan
Apr 08 2016 09:17
@WalaBenGharbia sure
You basically need to make a new string that translates to the requested sequence, using the table in the instructions to encode it. What have you tried so far?
WalaBenGharbia
@WalaBenGharbia
Apr 08 2016 09:19
i write var myStr = "\ \t \t \r \n " but it doesn't work
Brendan Kinahan
@BKinahan
Apr 08 2016 09:21
@WalaBenGharbia That's very close! check the third entry on the table: backslash is encoded by an escaped backslash, so two backslashes, like \\
also the space at the end doesn't need to be there, after \n
WalaBenGharbia
@WalaBenGharbia
Apr 08 2016 09:24
i wrote it like this \ but it still doesn't work
\\ *
Brendan Kinahan
@BKinahan
Apr 08 2016 09:26
@WalaBenGharbia with the extra space removed from the end?
WalaBenGharbia
@WalaBenGharbia
Apr 08 2016 09:28
i removed and it still doesn't work
Brendan Kinahan
@BKinahan
Apr 08 2016 09:28
What do you have now?
WalaBenGharbia
@WalaBenGharbia
Apr 08 2016 09:28
"\\ \t \t \r \n"
Brendan Kinahan
@BKinahan
Apr 08 2016 09:29
Is that your entire code?
WalaBenGharbia
@WalaBenGharbia
Apr 08 2016 09:29
var myStr = " \\ \t \t \r \n";
Brendan Kinahan
@BKinahan
Apr 08 2016 09:30
now you have an extra space at the start :)
Truedrog
@Truedrog
Apr 08 2016 09:30
Hi guys! Hi do i achieve singleton pattern in es6?
WalaBenGharbia
@WalaBenGharbia
Apr 08 2016 09:30
finally it's work
Brendan Kinahan
@BKinahan
Apr 08 2016 09:30
@WalaBenGharbia great :)
WalaBenGharbia
@WalaBenGharbia
Apr 08 2016 09:30
thanks @BKinahan
CamperBot
@camperbot
Apr 08 2016 09:30
walabengharbia sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1246 | @bkinahan | http://www.freecodecamp.com/bkinahan
Brendan Kinahan
@BKinahan
Apr 08 2016 09:34
@Truedrog No idea, but maybe this is a good start on your search: http://amanvirk.me/singleton-classes-in-es6/
kirbyedy
@kirbyedy
Apr 08 2016 09:35
@CEREBR4L does every company in england has that... we work until 13h on friday
Spartano
@Spartano
Apr 08 2016 09:39
hello, i am not able to set the text on my twitter button so it takes the random quote and paste it directly inside of the tweet. http://codepen.io/Spartano/pen/JXremW?editors=1010
Moon Man
@CEREBR4L
Apr 08 2016 09:43
@kirbyedy nope I work till 5:30pm everyday
Javier
@sh1g
Apr 08 2016 09:49
wiki Generate random Whole Numbers within a Range
CamperBot
@camperbot
Apr 08 2016 09:49

:point_right: challenge generate random whole numbers within a range [wiki]

Generate Random Whole Numbers within a Range

We can use a certain mathematical expression to get a random number between two numbers.

Math.floor(Math.random() * (max - min + 1)) + min

See Also: :scroll: Explanation | Explanation in SO

:pencil: read more about challenge generate random whole numbers within a range on the FCC Wiki

Eldar Tinjić
@EldarT90
Apr 08 2016 10:06
function truncateString(str, num) {
  var newstr = str.slice(0,num-3);
  var neweststr = newstr + "...";
  return neweststr;
}

truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length);
Aman Barnwal
@amanbarnwalce
Apr 08 2016 10:06

What's the Problem here??

function mutation(arr) {
var str1 = arr[0].toLowerCase();
var str2 = arr[1].toLowerCase();
for(i=0; i<str1.length; i++) {
if(str1.indexOf(str2[i]) < 0) {
return false;
}
else{
return true;
}
}
}
mutation(["Alien", "line"]);

kirbyedy
@kirbyedy
Apr 08 2016 10:07
@CEREBR4L ugh, thats crap
Craig Banach
@CraigBanach
Apr 08 2016 10:07
@amanbarnwalce You loop over string1 length (5) instead of string 2 length (4)
Markus Kiili
@Masd925
Apr 08 2016 10:08
@amanbarnwalce You also return true at wrong spot.
kirbyedy
@kirbyedy
Apr 08 2016 10:08
plus you have to spend at least 30min. in commuting...
Moon Man
@CEREBR4L
Apr 08 2016 10:08
@kirbyedy i commute 20mins a day over all so it's ok
Andreas Alme
@Addibro
Apr 08 2016 10:09
Hey guy, can you have a look at this please. I wonder if I could make this code shorter using some other strategy? Here it is:
Aman Barnwal
@amanbarnwalce
Apr 08 2016 10:09
Where should i return it then?
Andreas Alme
@Addibro
Apr 08 2016 10:09
function largestOfFour(arr) { 

  var newArr = [];

  var largestNum = 0;

  for (var i = 0; i < arr.length; i++) {
    for (var j = 0; j < arr[i].length; j++) {
      if (largestNum < arr[i][j]) {
        largestNum = arr[i][j];
      }
    }
    newArr.push(largestNum);
    largestNum = 0;
  }

  return newArr;
}

largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
ALMY91
@ALMY91
Apr 08 2016 10:09
// Setup
function phoneticLookup(val) {
  var result = "";

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



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

// Change this value to test
var val=testObj.lookup;
var Lookup ;
Craig Banach
@CraigBanach
Apr 08 2016 10:10
@Addibro Probably, why do you want to make it shorter?
ALMY91
@ALMY91
Apr 08 2016 10:10
im stuck on the last 2 criterias
Andreas Alme
@Addibro
Apr 08 2016 10:11
@CraigBanach I just feel it look's messy, perhaps there are more elegant code with same result
Craig Banach
@CraigBanach
Apr 08 2016 10:11
@Addibro what do you mean by "elegant"?
Aman Barnwal
@amanbarnwalce
Apr 08 2016 10:11
Where to return true??
Craig Banach
@CraigBanach
Apr 08 2016 10:11
Your code is clear to read and I understand how it works, I don't see how it gets more "elegant" than that
Aman Barnwal
@amanbarnwalce
Apr 08 2016 10:12

Still doesn't work

function mutation(arr) {
var str1 = arr[0].toLowerCase();
var str2 = arr[1].toLowerCase();
for(i=0; i<str1.length; i++) {
if(str1.indexOf(str2[i]) < 0) {
return false;
}
}
return true;
}
mutation(["Alien", "line"]);

Andreas Alme
@Addibro
Apr 08 2016 10:12
Well, maybe using another function or method. I don't know
Brendan Kinahan
@BKinahan
Apr 08 2016 10:14
@Addibro ES6 solution: largestOfFour = a => a.map(s=>Math.max(...s));
Andreas Alme
@Addibro
Apr 08 2016 10:15
@BKinahan Ah, that's what I'm talking about
not possible on FCC right
Brendan Kinahan
@BKinahan
Apr 08 2016 10:17
@Addibro the ES6 concepts involved are arrow functions and the spread operator. The code works on FCC (possibly depending on your browser), but will show a warning flag unless you include //jshint esversion: 6 at the top of your code.
Vivienne Sales
@Natto278
Apr 08 2016 10:18

I'm at the Return Early Pattern for Function challenge. When I wrote my code, I got null for abTest(-2, 2) and abTest (2, -2). Are we supposed to use switches for this challenge? Here's my code: // Setup
function abTest(a, b) {

// Only change code below this line
switch (a, b) {
case (-2, 2):
answer='undefined';
break;
}

// Only change code above this line

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

// Change values below to test your code
abTest(2,-2);

Andreas Alme
@Addibro
Apr 08 2016 10:18
@BKinahan right, cool! thanks man
Clem
@ctataru
Apr 08 2016 10:18
hey guys. i have an infinite loop on the exercise i'm currently working on. it keeps crashing my browser when i go on the browser page. anyway to go around this?
CamperBot
@camperbot
Apr 08 2016 10:18
addibro sends brownie points to @bkinahan :sparkles: :thumbsup: :sparkles:
:star: 1247 | @bkinahan | http://www.freecodecamp.com/bkinahan
Clem
@ctataru
Apr 08 2016 10:19
especially without losing all of my code, if possible!
Blauelf
@Blauelf
Apr 08 2016 10:19
help autorun
CamperBot
@camperbot
Apr 08 2016 10:19
no wiki entry for: autorun
Blauelf
@Blauelf
Apr 08 2016 10:19
search autorun
usharya
@usharya
Apr 08 2016 10:19
how will you solve the lesson "Stan in Line"?
Blauelf
@Blauelf
Apr 08 2016 10:20
wiki auto run
CamperBot
@camperbot
Apr 08 2016 10:20

:point_right: disable code auto run [wiki]

By default, the Free Code Camp site automatically loads and runs your last recorded solution. If you have accidentally created an infinite loop or other irrecoverable error or simply don't trust the code, you can disable code auto-run by putting the following in your URL:
run=disabled

Example:

URL: http://www.freecodecamp.com/challenges/Algorithm-meet-Algorithm#?solution=function%20meetBonfire(argument)

No-Run URL: http://www.freecodecamp.com/challenges/Algorithm-meet-Algorithm#?run=disabled&solution=function%20meetBonfire(argument)

:pencil: read more about disable code auto run on the FCC Wiki

usharya
@usharya
Apr 08 2016 10:20
how will you solve the lesson "Stan in Line"?
Blauelf
@Blauelf
Apr 08 2016 10:20
(note to myself: auto run are two words)
Clem
@ctataru
Apr 08 2016 10:20
ahh @Blauelf thanks
CamperBot
@camperbot
Apr 08 2016 10:20
ctataru sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1546 | @blauelf | http://www.freecodecamp.com/blauelf
Clem
@ctataru
Apr 08 2016 10:20
haha
usharya
@usharya
Apr 08 2016 10:20
how will you solve the lesson "Stand in Line"?
Vivienne Sales
@Natto278
Apr 08 2016 10:21
@usharya: Where's your code for "Stand in Line"?
Blauelf
@Blauelf
Apr 08 2016 10:21
@usharya By reading the task and using arr and item :) (Two parts: Append item to arr, remove first element of arr returning it.)
usharya
@usharya
Apr 08 2016 10:21
function nextInLine(arr, item) {
// Your code here
arr = item.push();
return arr; // Change this line
}
Robert Uivarosi
@URobert
Apr 08 2016 10:23
@usharya you have the syntax wrong
usharya
@usharya
Apr 08 2016 10:23
what is wrong?
Blauelf
@Blauelf
Apr 08 2016 10:23
The other way around, push is a method of arrays (use arr.push(item); without any assignment). And you don't want to return arr, but the first element of arr (and in the same step remove it from arr, you can use shift() for that)
Robert Uivarosi
@URobert
Apr 08 2016 10:23
@usharya you want to push item into arr
@Blauelf just gave it away :)
usharya
@usharya
Apr 08 2016 10:24
Its correct now?
function nextInLine(arr, item) {
  // Your code here
  arr = arr.push(item);
  return arr[0];  // Change this line
}
Robert Uivarosi
@URobert
Apr 08 2016 10:24
Blauelf
@Blauelf
Apr 08 2016 10:24
@usharya No assignment. arr.push(item); appends item to arr (you are finished with the first part here), but returns the new length of arr, which you don't want to replace arr.
Robert Uivarosi
@URobert
Apr 08 2016 10:24
@usharya you don't need arr=
Vivienne Sales
@Natto278
Apr 08 2016 10:25
@usharya You've have some typs with the first line of code. And yes, @Blauelf gave away the answer.
This message was deleted
This message was deleted
@usharya I meant typos. Get rid of the "=" and replace it with a "."
Blauelf
@Blauelf
Apr 08 2016 10:26
? arr.arr.push(item)? Nah, just remove arr =.
Craig Banach
@CraigBanach
Apr 08 2016 10:26
@Natto278 You can edit your previous comment by pressing up arrow
usharya
@usharya
Apr 08 2016 10:27
function nextInLine(arr, item) {
  // Your code here
  arr.push(item);
  return arr[0];  // Change this line
}
Robert Uivarosi
@URobert
Apr 08 2016 10:27
@usharya one more thing... as the return of the function, you won't return the first element of the array, but the array without its first element and for that you can use shift() method
Vivienne Sales
@Natto278
Apr 08 2016 10:27
@CraigBanach Thank you for the tip. I didn't know about that.
CamperBot
@camperbot
Apr 08 2016 10:27
natto278 sends brownie points to @craigbanach :sparkles: :thumbsup: :sparkles:
:star: 410 | @craigbanach | http://www.freecodecamp.com/craigbanach
Blauelf
@Blauelf
Apr 08 2016 10:27
@Natto278 Unless you are on a mobile you can hover over comments and edit/delete them from the three-dot menu icon.
Daniel Sverner
@dansverner
Apr 08 2016 10:28
Hey everyone
Vivienne Sales
@Natto278
Apr 08 2016 10:29
@Blauelf I didn't know about that option, either. I have deleted my first two repeating posts. Thank you, @Blauelf
CamperBot
@camperbot
Apr 08 2016 10:29
natto278 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
usharya
@usharya
Apr 08 2016 10:29
@URobert for the end, I should return return arr.shift();?
CamperBot
@camperbot
Apr 08 2016 10:29
:star: 1547 | @blauelf | http://www.freecodecamp.com/blauelf
Daniel Sverner
@dansverner
Apr 08 2016 10:29
I'm stuck in the record collection activity
Blauelf
@Blauelf
Apr 08 2016 10:29
@usharya There's push/pop, and another pair, unshift/shift, that does the same, just with the start of the array, not with the end. Pick the one that suits your needs for the second part.
Umm... took too long... yes, arr.shift() is right :)
usharya
@usharya
Apr 08 2016 10:30
Thank you @Blauelf :D
CamperBot
@camperbot
Apr 08 2016 10:30
usharya sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1548 | @blauelf | http://www.freecodecamp.com/blauelf
Robert Uivarosi
@URobert
Apr 08 2016 10:30
@usharya yes
Vivienne Sales
@Natto278
Apr 08 2016 10:30
@usharya Did you figure out the Stand in Line exercise, yet?
Theodore P.
@Ierofantis
Apr 08 2016 10:30
@mutantspore thank you this what I was looking for. To tell you the truth I didn't work with foreach...in so I have to study further this solution to understand it. Anyway I appreciate It a lot!
CamperBot
@camperbot
Apr 08 2016 10:30
ierofantis sends brownie points to @mutantspore :sparkles: :thumbsup: :sparkles:
:star: 1370 | @mutantspore | http://www.freecodecamp.com/mutantspore
Daniel Sverner
@dansverner
Apr 08 2016 10:31
How do I send a pic of my code?
Robert Uivarosi
@URobert
Apr 08 2016 10:31
@usharya got it working, right? :P
Blauelf
@Blauelf
Apr 08 2016 10:31
help format
CamperBot
@camperbot
Apr 08 2016 10:31

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

Blauelf
@Blauelf
Apr 08 2016 10:32
@dansverner Don't send pics, send properly formatted code (allows for copy&paste)
usharya
@usharya
Apr 08 2016 10:32
@URobert Yes haha I have to read the references more from w3schools xD
Thank you guys :D
Daniel Sverner
@dansverner
Apr 08 2016 10:33
function updateRecords(id, prop, value) {
  var newValue;

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

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

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


  return collection;
}
anyway, probably very wrong but I have no clue how to do this lol
Robert Uivarosi
@URobert
Apr 08 2016 10:33
@usharya yw
Daniel Sverner
@dansverner
Apr 08 2016 10:33
thanks @Blauelf
CamperBot
@camperbot
Apr 08 2016 10:33
dansverner sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1549 | @blauelf | http://www.freecodecamp.com/blauelf
Daniel Sverner
@dansverner
Apr 08 2016 10:33
forget the newValue btw, forgot to delete it
Robert Uivarosi
@URobert
Apr 08 2016 10:34
@usharya brownies are welcome for activity
usharya
@usharya
Apr 08 2016 10:38
I thought I gave you
Sorry, Thank you @URobert
CamperBot
@camperbot
Apr 08 2016 10:38
usharya sends brownie points to @urobert :sparkles: :thumbsup: :sparkles:
:star: 770 | @urobert | http://www.freecodecamp.com/urobert
pgjones72
@pgjones72
Apr 08 2016 10:39
Good Morning FCC!
Robert Uivarosi
@URobert
Apr 08 2016 10:39
@usharya no worries, happy coding
usharya
@usharya
Apr 08 2016 10:39
I was mentioning so many people that I forgot to thank you xD
Robert Uivarosi
@URobert
Apr 08 2016 10:39
@pgjones72 good morning
usharya
@usharya
Apr 08 2016 10:39
what does brownie points do?
pgjones72
@pgjones72
Apr 08 2016 10:40
I have a quick, no code question: In JS, can we compare the values of array indexes of one array directly to the index values of another array?
E YG
@laed37
Apr 08 2016 10:41
I just learned you can't do comparisons like a < function < b you have to do function > a && function < b
Blauelf
@Blauelf
Apr 08 2016 10:41
@dansverner A few things: prop contains a property name, so you want to use bracket notation (collection[id].prop is the same as collection[id]["prop"] and not what you want). Then, for non-"tracks", it should be a simple assignment. And no idea where you got the idea of that [0].
Markus Kiili
@Masd925
Apr 08 2016 10:41
@pgjones72 No, but easily done with suitable iterator.
pgjones72
@pgjones72
Apr 08 2016 10:42
if [i]=[j].... that sort of thing? @Masd925
Aman Barnwal
@amanbarnwalce
Apr 08 2016 10:42
I am unable to filter null from an array
how to do so?

This is what i tried

arr = arr.filter(function(x){
return x !== '' && x !== false && x !==0 && x != NaN && x !== undefined && x !== null;
});

it filters everything except null
Blauelf
@Blauelf
Apr 08 2016 10:44
@laed37 You can do a < b < c (this is valid code), it's just not doing what you would expect (a < b will return a boolean that is then compared to c).
@amanbarnwalce That's a display error, you are unable to filter NaN which is displayed as null. NaN unequals everything, even itself (you can use that by saying x === x instead)
Acmer77
@Acmer77
Apr 08 2016 10:45
why does this return false?
``
V Arun Kumar
@arunvkumr
Apr 08 2016 10:45
@amanbarnwalce Try with boolena objects, that's the objective of challenge.
Acmer77
@Acmer77
Apr 08 2016 10:45
function mutation(arr) {
  var arr1 = arr[0];
  var arr2 = arr[1].split('');
  for (i = 0; i < arr2.length; i++) {
    if (arr1.indexOf(arr2[i])) {
      continue;
    } else {
      return false;
    }    
  }
  return true;
}

mutation(["floor", "for"]);
Blauelf
@Blauelf
Apr 08 2016 10:46
@arunkumrv No boolean objects, but using the Boolean function (which serves both as the boolean object constructor and a converter to boolean), one can write this with very little code (but does not construct any boolean object)
Markus Kiili
@Masd925
Apr 08 2016 10:47
@pgjones72 Something like this or same with for loop:
function compareArrays (arr1,arr2) {
    if (arr1.length!==arr2.length) return false;
    return arr1.every(function(elem,index){
        return elem===arr2[index];
    })
}
Daniel Sverner
@dansverner
Apr 08 2016 10:48
@Blauelf the idea of the [0] was more something random that I tried after being stuck on it for quite a while lol. So I don't have to use push in this function? Also what is confusing me is the case where the property doesn't exist... should I assign the prop and assign the value just after?
V Arun Kumar
@arunvkumr
Apr 08 2016 10:48
@Acmer77 use !== -1 in your if condition, because indexOf return index values of the elem when it is found in the string.. so for first iteration.. when the condition returns 0 which if assumes as false moves to else part
Markus Kiili
@Masd925
Apr 08 2016 10:49
@Blauelf In the problem description there is a link to Boolean object, which is wrong.
Blauelf
@Blauelf
Apr 08 2016 10:49
@Acmer77 You don't need that .split(''), and you might want to introduce some toLowerCase() or toUpperCase() to ignore the case. But the main problem is the test with indexOf: Element-not-found makes it return -1, not falsy.
Acmer77
@Acmer77
Apr 08 2016 10:49
it seems to ignore the case anyway
V Arun Kumar
@arunvkumr
Apr 08 2016 10:49
@Blauelf thanks for pointing out.. :smile: . i'll keep in mind..
CamperBot
@camperbot
Apr 08 2016 10:49
arunkumrv sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
pgjones72
@pgjones72
Apr 08 2016 10:49
@Masd925 hmmm. Not sure if i've seen code like that before. Let me do some more reading- that never hurts :) Thanks!
CamperBot
@camperbot
Apr 08 2016 10:49
pgjones72 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1550 | @blauelf | http://www.freecodecamp.com/blauelf
:star: 1338 | @masd925 | http://www.freecodecamp.com/masd925
Jalay
@JalaySimaria
Apr 08 2016 10:50
@Acmer77 you're confused with variables
arr1 is string and arr2 is an array
function mutation(arr) {
  var arr1 = arr[0];
  var arr2 = arr[1].split('');
  for (i = 0; i < arr2.length; i++) { // it should be arr1
    if (arr1.indexOf(arr2[i])) {    // arr1 is a string which doesn't have method indexOf 
      continue;
    } else {
      return false;
    }    
  }
  return true;
}
Acmer77
@Acmer77
Apr 08 2016 10:50
thanks @arunkumrv
CamperBot
@camperbot
Apr 08 2016 10:50
acmer77 sends brownie points to @arunkumrv :sparkles: :thumbsup: :sparkles:
:star: 432 | @arunkumrv | http://www.freecodecamp.com/arunkumrv
Stefan Gisi
@stgisi
Apr 08 2016 10:50
Hello all. Can someone check out my Simon app please ma'ams sirs?
Acmer77
@Acmer77
Apr 08 2016 10:50
thanks @Blauelf
CamperBot
@camperbot
Apr 08 2016 10:50
acmer77 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1551 | @blauelf | http://www.freecodecamp.com/blauelf
V Arun Kumar
@arunvkumr
Apr 08 2016 10:51
@Acmer77 you're welcome :+1:
Markus Kiili
@Masd925
Apr 08 2016 10:51
@pgjones72 Same with for loop:
function compareArrays (arr1,arr2) {
    if (arr1.length!==arr2.length) return false;
    for (var i=0; i<arr1.length; i++) {
        if (arr1[i]!==arr2[i]) return false
    }
    return true;
}
Blauelf
@Blauelf
Apr 08 2016 10:52
@dansverner You create properties usually by assigning to them. (yes, there is a more sophisticated way for creating properties with getter/setter, or that are not enumerable)
Daniel Sverner
@dansverner
Apr 08 2016 10:53
@Blauelf I see! Thought it was weird not having to create them before assigning a value. I got it now, thanks!
CamperBot
@camperbot
Apr 08 2016 10:53
dansverner sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:warning: dansverner already gave blauelf points
pgjones72
@pgjones72
Apr 08 2016 10:53
@Masd925 That last snippet you posted would complain about not having an arr2[i], wouldn't it? I do see where you are headed with this though. Thanks
CamperBot
@camperbot
Apr 08 2016 10:53
pgjones72 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: pgjones72 already gave masd925 points
pgjones72
@pgjones72
Apr 08 2016 10:54
dammit, I should be able to give as many brownie points as I want!
Markus Kiili
@Masd925
Apr 08 2016 10:57
@pgjones72 Yes. You can handle different size arrays as you like by changing the code.
Eldar Tinjić
@EldarT90
Apr 08 2016 10:58
whatta nice feeling is when you solve some algorithm that you think that you will never be able to solve, and do so without help
when i look at full algorithm, its like i have no clue what is this; but when i section it piece by piece, i understand it fully heh
alpox
@alpox
Apr 08 2016 10:59
@EldarT90 Thats why you cut tasks in pieces
mintyme777
@mintyme777
Apr 08 2016 11:13
hi my code is working its lesson called "Chaining If Else Statements"
mintyme777
@mintyme777
Apr 08 2016 11:20
anyone here?
kirbyedy
@kirbyedy
Apr 08 2016 11:22
yes
mintyme777
@mintyme777
Apr 08 2016 11:22
well at least I am not talking to my self
kirbyedy
@kirbyedy
Apr 08 2016 11:23
:)
what seems to be a problem ?
mintyme777
@mintyme777
Apr 08 2016 11:23
cant get my code for lesson Chaining If Else Statements working properly
kirbyedy
@kirbyedy
Apr 08 2016 11:23
ok, whats your code, copy/paste here
wiki format
CamperBot
@camperbot
Apr 08 2016 11:24

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

kirbyedy
@kirbyedy
Apr 08 2016 11:24
use this help to paste properly your code
mintyme777
@mintyme777
Apr 08 2016 11:24

function myTest(num) {
// Only change code below this line
if (num < 5)
{
return "Tiny";
}
else if (num < 10)
{
return "Small";
}
else if (num < 15)
{
return "Medium";
}
else if (num < 20)
{
return "Large";
}
else if (num >= 20)
{
return "Huge";
}

// Only change code above this line
}

// Change this value to test
myTest(7);

Vivek
@vivek28111992
Apr 08 2016 11:25
@mintyme777 your condition are not proper
mintyme777
@mintyme777
Apr 08 2016 11:25
I dont understand what you mean by that/
?
Vivek
@vivek28111992
Apr 08 2016 11:26
it should be like this else if (num >= 5 && num < 10)
kirbyedy
@kirbyedy
Apr 08 2016 11:26
the last one is not quite right
mintyme777
@mintyme777
Apr 08 2016 11:27
ahhh ok should just be an else statement rather than else if?
Vivek
@vivek28111992
Apr 08 2016 11:27
@mintyme777 sorry your code will also work
kirbyedy
@kirbyedy
Apr 08 2016 11:28
I was about to say that :)
but never mind
you just need to remove the if from the last else IF
so the last one should be only else...
Vivek
@vivek28111992
Apr 08 2016 11:28
but @kirbyedy it is good practice to solve like that
kirbyedy
@kirbyedy
Apr 08 2016 11:28
agree
Vivek
@vivek28111992
Apr 08 2016 11:29
ya last will be just else
mintyme777
@mintyme777
Apr 08 2016 11:29
I removed the if statement from the end still doesnt work!
kirbyedy
@kirbyedy
Apr 08 2016 11:30
how about removing this: (num >= 20)
Vivek
@vivek28111992
Apr 08 2016 11:30
@mintyme777 have you removed condition also?
kirbyedy
@kirbyedy
Apr 08 2016 11:30
just leave else... nothing else
Eldar Tinjić
@EldarT90
Apr 08 2016 11:31
what is wrong with this code js ```
js
function mutation(arr) {
  if (arr[0].indexOf(arr[1]) !== -1) {
    return true;
      }
  else {
    return false;
  }
}

mutation(["hello", "hey"]);

js```
function mutation(arr) {
if (arr[0].indexOf(arr[1]) !== -1) {
return true;
}
else {
return false;
}
}

mutation(["hello", "hey"]);

```

sakram07
@sakrma07
Apr 08 2016 11:35

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

// Only change code below this line

var lookUp = {
"alpha": "Adams",
"bravo": "Boston",
"charlie": "Chicago",
"del