These are chat archives for FreeCodeCamp/HelpJavaScript

18th
Feb 2016
John Roman
@jrroman
Feb 18 2016 00:02
i know it says create an array but can you create an object and just use key value pairs?
instead of creating two arrays
Norman Dela Cruz
@dcnr
Feb 18 2016 00:03
@jrroman do what you think you need to do, and work from there :P
John Roman
@jrroman
Feb 18 2016 00:07
:smile: ill play around see what i come up with
@dcnr
Alex Tze
@Tze14
Feb 18 2016 00:09
function palindrome(str) {

  var replacedArray = str.replace(/\W/g, '').toLowerCase().split('');

  var reversedArray = [];
  reversedArray = replacedArray.reverse();

  return replacedArray;
}


palindrome("not a palindrome");
why is this returning the reversedArray ?
Blauelf
@Blauelf
Feb 18 2016 00:11
@Tze14 reverse changes the array and returns a reference to that very same array, so both variables now point to the same reversed array.
Alex Tze
@Tze14
Feb 18 2016 00:12
do I need a var replacedArray = []; ?
JackeL
@jackel27
Feb 18 2016 00:12
@Tze14 you could return replacedArray.reverse();
@Tze14 but probably not the best approach.
Alex Tze
@Tze14
Feb 18 2016 00:13
what I want to do is have 2 different arrays
one replaced and one reversed
Norman Dela Cruz
@dcnr
Feb 18 2016 00:13
@Tze14 because objects are referenced rather than copied, reversedArray is just another name for replacedArray now
JackeL
@jackel27
Feb 18 2016 00:13
@Tze14 okay, so assign reversedArray to replaced array, on new line add reverse to reversedArray.
Blauelf
@Blauelf
Feb 18 2016 00:13
@Tze14 You should compare strings, so save your filtered string without splitting it, use splitting only for reversing (and later joining).
@Tze14 If you really wanted to have separate arrays, you would have to copy it using .slice()
But I really recommend doing a string compare, as you cannot easily compare arrays based on content.
Alex Tze
@Tze14
Feb 18 2016 00:14
my idea on this Palindrome Challenge
was to have 2 different arrays which later on compare
if both are equal than the word is a palindrome, if not its not a palindrome
Sravani Vegesna
@sravanivegesna
Feb 18 2016 00:15
function lookUp(firstName, prop){
// Only change code below this line
  var value ='';
  for ( var i =0 ; i < contacts.lenght ; i++) {
    if(contacts[i].firstName === firstName) {

      if(contacts[i].hasOwnProperty(prop)) {
        value = contacts[i][prop];
      }
      else {
        value = "No such property";
      }
    }
    else {
      value = "No such contact";
    }
  }
  return value;
// Only change code above this line
}
i am unable to run please can any one say what wrong i did
Blauelf
@Blauelf
Feb 18 2016 00:15
Comparing two strings is easier, is a single == (or ===), arrays would require looping.
JackeL
@jackel27
Feb 18 2016 00:15
@sravanivegesna mispelled length
@sravanivegesna
for ( var i =0 ; i < contacts.lenght ; i++) {
Blauelf
@Blauelf
Feb 18 2016 00:16
@sravanivegesna You should probably return as soon as you have a result instead of setting a "value" variable...

BTW, finally! My solution to "Exact Change" is able to handle my very private challenge:

drawer(19.70, 20.00, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0.50], ["QUARTER", 0.50], ["ONE", 1.00], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]])

returns

[["Dime", 0.3]]

:)
I don't know if there is another solution that does, as the test cases don't require full functionality.

JackeL
@jackel27
Feb 18 2016 00:20
@Blauelf private challenge?
Blauelf
@Blauelf
Feb 18 2016 00:20
It's no official test case, but I think a program should be able to handle it.
Norman Dela Cruz
@dcnr
Feb 18 2016 00:20
I tried using contacts.find for Profile Lookup and it's at least 10x slower than just a for loop. I thought a built in function would be better, I guess it's all the overhead
Alex Tze
@Tze14
Feb 18 2016 00:21
function palindrome(str) {

  var replace = str.replace(/\W/g, '').toLowerCase().split('');

  return replace;
}


palindrome("not a palindrome");
why is this an array?
Blauelf
@Blauelf
Feb 18 2016 00:21
@dcnr contacts.find is using callbacks, so there is some overhead.
Norman Dela Cruz
@dcnr
Feb 18 2016 00:21
@jackel27 it's something like if you need 0.30 change and you have a quarter and 3 dimes, you should return 3 dimes and not insufficient funds :D or at least that's what I think from how @Blauelf described it, I'm trying to do it myself
JackeL
@jackel27
Feb 18 2016 00:22
sounds like a challenge. so is there any other way to do it?
Blauelf
@Blauelf
Feb 18 2016 00:22
Yes, exactly that way :)
I solved that using a recursive inner function.
JackeL
@jackel27
Feb 18 2016 00:23
nice
I'll attempt?
Norman Dela Cruz
@dcnr
Feb 18 2016 00:23
must resist looking @Blauelf 's profile solution :P
JackeL
@jackel27
Feb 18 2016 00:24
i'll try different way.
Norman Dela Cruz
@dcnr
Feb 18 2016 00:24
@Tze14 split converts your string to an array of however you split it
Alex Tze
@Tze14
Feb 18 2016 00:26
function palindrome(str) {

  var replace = str.replace(/\W/g, '').toLowerCase().split('');

  if (replace == replace.reverse()); {
    return true;
  }
}


palindrome("not a palindrome");
@dcnr replace is not the same with replace.reverse() so how is this true?
Blauelf
@Blauelf
Feb 18 2016 00:27
@jackel27 Let me know if you can solve that in a somewhat elegant way (preferably no hard-coding of dime/quarter relations) :D
JackeL
@jackel27
Feb 18 2016 00:27
@Blauelf so no dime:.10 ?
Blauelf
@Blauelf
Feb 18 2016 00:27
@Tze14 Do not compare arrays. Does not work that way.
Alex Tze
@Tze14
Feb 18 2016 00:28
oh
I went too far
Im losing touch right now, been working on this for far too long
JackeL
@jackel27
Feb 18 2016 00:28
or if 30{ return quarter+dime} ... hahah
Alex Tze
@Tze14
Feb 18 2016 00:28
Im not sleeping until I get it right
Blauelf
@Blauelf
Feb 18 2016 00:29
@jackel27 I meant not hardcoding that the combination of dime and quarter might cause issues, as the values might be different in other currencies, and the programme should be easily adjustable (that's how I built mine, starts with a list of units and values).
JackeL
@jackel27
Feb 18 2016 00:30
@Blauelf okay. so 100% Functional Programming :)
Nick Robson
@nickrobson
Feb 18 2016 00:31
function palindrome(str) {
   str = str.toLowerCase().replace(/[^a-z0-9]/g, '');
   for (var i = 0; i < str.length; i++) {
      if (str[i] != str[str.length-i-1])
         return false;
   }
   return true;
}
JackeL
@jackel27
Feb 18 2016 00:31
@Blauelf thanks for this insane challenge :/ should have never asked hahaha
Blauelf
@Blauelf
Feb 18 2016 00:31
@nickrobson You remove numbers, these are neither punctuation nor space. Add them to your exclude list.
JackeL
@jackel27
Feb 18 2016 00:32
@Blauelf can't turn back now.
Nick Robson
@nickrobson
Feb 18 2016 00:34
are you not able to see your solution for challenges?
JackeL
@jackel27
Feb 18 2016 00:34
@Blauelf do I need to refer to Decimalisation ?
Blauelf
@Blauelf
Feb 18 2016 00:34
@nickrobson You could use i < (str.length-1)/2 for only half of the comparisons (as the others are redundant). Probably not worth it, as regex is probably a lot slower.
Nick Robson
@nickrobson
Feb 18 2016 00:35
@Blauelf No, it would have to be str.length/2 or (str.length - (str.length & 1))/2
Blauelf
@Blauelf
Feb 18 2016 00:36
@nickrobson Believe me, that number works well, as JS has floating point division.
str.length - (str.length & 1) is about the same as str.length & ~1
Nick Robson
@nickrobson
Feb 18 2016 00:38
@Blauelf Ah, true. I still think it's better practise not to teach that though since people will then move to C, C++, Java, C#, or similar and wonder why that doesn't work.
JackeL
@jackel27
Feb 18 2016 00:38
@Blauelf change can be any type of change amt (bills, etc.. ?)
Tarik Nachat
@intertarik
Feb 18 2016 00:38
why this does't work
var array = [1,2,3,4,5,6,7];
var newArray = [];

// Only change code below this line.

newArray = array.reverse();
Nick Robson
@nickrobson
Feb 18 2016 00:38
@Blauelf True indeed.
(str.length & ~1)/2 would work in that case.
Alex Tze
@Tze14
Feb 18 2016 00:39
@Blauelf FINALLY omg , I just had to compare 2 strings after passing them through some checks , omg
@Blauelf My head is spinning, I was thinking of a more complex thing
thanks to all of you
Blauelf
@Blauelf
Feb 18 2016 00:40
But (str.length & ~1)/2 should be the same as str.length>>1 (oh, that's the same number of iterations!)
Nick Robson
@nickrobson
Feb 18 2016 00:41
!!
well there we go
xD
function palindrome(str) {
   str = str.toLowerCase().replace(/[^a-z0-9]/g, '');
   for (var i = 0; i < (str.length >> 1); i++) {
      if (str[i] != str[str.length-i-1])
         return false;
   }
   return true;
}
magic answer
it works :p
Blauelf
@Blauelf
Feb 18 2016 00:44
I did that another way (borrowing your code):
function palindrome(str) {
   str = str.toLowerCase().replace(/[^a-z0-9]/g, '');
   for (var i = 0, j = str.length - 1; i < j; i++, j--) {
      if (str[i] != str[j])
         return false;
   }
   return true;
}
Mariya
@mariyadiminsky
Feb 18 2016 00:45
Can someone please advice me on my every function? It's supposed to take an array and a callback function and return false if even one instance returns false in the callback function. So EVERY iteration must be true. I figured this out easily with a for loop but I want to try it with a reduce and it just doesn't work for me. Why do I keep getting undefined?
http://goo.gl/7Pnp1u
console.log(every([2, 4, 6], function(elem) {
  return elem % 2 == 0;
}));  // true

console.log(every([2, 4, 7], function(elem) {
  return elem % 2 == 0;
}));  // false

// BONUS: use reduce in your answer
function every(array, func) {
    array.reduce(function(item) {
     if(!func(item)) {
        return false; 
     }
    })

    return true;
}
Nick Robson
@nickrobson
Feb 18 2016 00:46
function palindrome(str) {
   str = str.toLowerCase().replace(/[^a-z0-9]/g, '');
   for (var i = 0, j = (str.length >> 1); i < j; i++) {
      if (str[i] != str[str.length-i-1])
         return false;
   }
   return true;
}
seems to work the best
an even better method would be to use the char codes instead of regex
Blauelf
@Blauelf
Feb 18 2016 00:47
@Mashadim You are using array.reduce, not array.every. Also, your inner function can return false, or not return at all (equals returning undefined, which is falsy).
@nickrobson That way you cache the result of str.length>>1 and do a variable lookup each iteration instead of variable lookup, property lookup, calculation. So yes, better performance.
Joshua Abu
@Absolutestunna
Feb 18 2016 00:48
Is there anyone who has done the calc have some time to work through the calculator problem with me. I have the numbers and operators working but I can't get it to calculate more than three numbers..
Nick Robson
@nickrobson
Feb 18 2016 00:48
@Blauelf ik lol :P
Mariya
@mariyadiminsky
Feb 18 2016 00:49
@Blauelf What do you mean I am using array.reduce. I know I am using array.reduce INSIDE of every. I know my inner function can return false or not return at all, I am asking why I keep getting undefined.
Blauelf
@Blauelf
Feb 18 2016 00:50
@Mashadim I thought you were trying to use Array.every inside that function. What challenge are you on exactly?
Mariya
@mariyadiminsky
Feb 18 2016 00:50
@Blauelf It's not an FCC challenge. You didn't see the code I posted?
Nick Robson
@nickrobson
Feb 18 2016 00:51
You could just use:
return arr.filter(func).length == arr.length
(if I understood the question correctly)
@Mashadim see above.
Mariya
@mariyadiminsky
Feb 18 2016 00:53
@nickrobson I'm using reduce because I have to
Nick Robson
@nickrobson
Feb 18 2016 00:53
@Mashadim Nowhere there does it say you need to lol.
Blauelf
@Blauelf
Feb 18 2016 00:53
I see it, but I don't understand what you are supposed to do. Something like return array.every(func);? That would be the same as return array.reduce(function(state, item) { return state && func(item); }, true);. No idea why one would do that with reduce, so I assume I misunderstood the task.
Nick Robson
@nickrobson
Feb 18 2016 00:53
It says "BONUS: use reduce"
Mariya
@mariyadiminsky
Feb 18 2016 00:53
@nickrobson yep
JackeL
@jackel27
Feb 18 2016 00:54
@Blauelf so, is it okay to make a codepen? user input... etc.. and jquery?
Blauelf
@Blauelf
Feb 18 2016 00:54
@jackel27 What for?
JackeL
@jackel27
Feb 18 2016 00:54
@Blauelf your challenge of correct change.
Moisés Man
@moigithub
Feb 18 2016 00:55
@Mashadim do u know the syntax of reduce ? n the values the callback uses
Blauelf
@Blauelf
Feb 18 2016 00:55
@jackel27 I just used the FCC challenge and tried to get the right return on my sample case (as seen above).
JackeL
@jackel27
Feb 18 2016 00:56
@Blauelf oh, hah. I was thinking way in depth...
Asif Norzai
@Pashtunzoy
Feb 18 2016 00:57
Hey guys need a little help here with Diff Two Arrays challenge here is my code:
function diff(arr1, arr2) {
  var newArr = [];
  var arr = [];
  arr = arr1.concat(arr2);
    for(var i = 0; i < arr.length; i += 1){
      if(newArr.indexOf(arr[i]) === -1) {  
        newArr.push((arr[i]));
      }
    }
  return newArr;
}

diff(["diorite", "andesite", "grass", "dirt", "pink wool", "dead shrub"], ["diorite", "andesite", "grass", "dirt", "dead shrub"]);
Nick Robson
@nickrobson
Feb 18 2016 00:58
@Mashadim
return arr.reduce((prev, curr) => {
   if (func(curr))
      prev.push(curr);
   return prev;
}, []).length == arr.length;
minified:
return arr.reduce((prev,curr)=>{if(func(curr))prev.push(curr);return prev;},[]).length==arr.length;
Blauelf
@Blauelf
Feb 18 2016 01:00
@AsipNorzai Your filter criterion is not right. That one creates a list of unique values, but does not remove all the duplicates. Use arr1.indexOf(arr[i])==-1 || arr2.indexOf(arr[i])==-1 (either not in the first or not in the second array, otherwise it is in both and to be removed) instead.
Jonathan Mitchell
@Vanhealen
Feb 18 2016 01:00
Hi all, I had a quick question, below I am having some trouble with the mutation function.
function mutation(arr) {
    for (var i = 0; i < arr[1].length; i++) {
        //Below is the true condition, but my return should not be inside of the for loop because then it will return the first true and not the rest
    }
    if (arr[0].indexOf('arr[1][i]') !== -1) {
        return true;
    }  else {
        return false;
    }
}
Asif Norzai
@Pashtunzoy
Feb 18 2016 01:01
@Blauelf Ahhh yep, cheers mate.
Blauelf
@Blauelf
Feb 18 2016 01:01
@nickrobson Why so complicated? That is the same as
  return array.reduce(function(state, item) {
    return state && func(item);
  }, true);
MikeBeers
@MikeBeers
Feb 18 2016 01:02
I am looking for some help on Random Quote challenge.
Norman Dela Cruz
@dcnr
Feb 18 2016 01:03
@Vanhealen remove the quotes on your arr[1][i]
MikeBeers
@MikeBeers
Feb 18 2016 01:03
Codepen.io
Jonathan Mitchell
@Vanhealen
Feb 18 2016 01:03
@dcnr It needs quotes right? Because .indexOf(‘stringhere’)
@dcnr or would it be a string anyways because i am accessing an element of a string
Norman Dela Cruz
@dcnr
Feb 18 2016 01:03
@Vanhealen by quoting it you turned it to a string! also don't return true immediately
Jonathan Mitchell
@Vanhealen
Feb 18 2016 01:04
@dcnr your right, I don’t know when to return true
@dcnr because I want it to run through all the iterations before returning true
Norman Dela Cruz
@dcnr
Feb 18 2016 01:04
@Vanhealen since you want to test all values first, you should just return false if a value isn't found
@Vanhealen and when the iteration is over, it means all the chars are in there right? then you return true
JackeL
@jackel27
Feb 18 2016 01:05
@Blauelf confused how you did that. did you not express a division for your dimes in drawer? would think you would have to hard code that
Blauelf
@Blauelf
Feb 18 2016 01:05
@Vanhealen Quotes mark a string literal. A variable might hold a string, but you wouldn't use quotes around that variable name.
Jonathan Mitchell
@Vanhealen
Feb 18 2016 01:06
@dcnr That won’t work because I may have values in the first parameter that don’t matter because I only need to match the values from the second parameter to the first.
@dcnr I may need to change my .indexOf operation to work on the first parameter and not the second
Blauelf
@Blauelf
Feb 18 2016 01:07
@jackel27 I gave the script the money types and their values ("quantization"), but no direct advice to avoid quarters in certain situations. Would solve the problem for Euro coins (everything starting with 1, 2, or 5), too (e.g. have 5x 2cent and 1x 5cent, change is 6cent or 8cent)
I am am trying to figure out if I can assign my random number to be the same for both assignments
Norman Dela Cruz
@dcnr
Feb 18 2016 01:09

@Vanhealen I think you're already on a good track, just remove the quotes, turn !== -1 to === -1 and make return true toreturn false and remove the else clause altogether. Outside your for loop, do a return true

This is because you want to first see if all the items in arr[1] are in arr[0], and if even one of the items in arr[1] are not in arr[0] you return false

MikeBeers
@MikeBeers
Feb 18 2016 01:10
if you look at it I can explain more
Norman Dela Cruz
@dcnr
Feb 18 2016 01:10
and when your for loop ends without returning a false, that would mean all the items in arr[1] are inside arr[0] and you then return true
@Vanhealen
Larry Simiyu
@LarrySimiyu
Feb 18 2016 01:13
Someone willing to answer a quick question on for loops?
Norman Dela Cruz
@dcnr
Feb 18 2016 01:15
@LarrySimiyu hi what about for loops?
Jonathan Mitchell
@Vanhealen
Feb 18 2016 01:18
thanks @dcnr
CamperBot
@camperbot
Feb 18 2016 01:18
:star: 648 | @dcnr | http://www.freecodecamp.com/dcnr
vanhealen sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
MikeBeers
@MikeBeers
Feb 18 2016 01:20
Looking for some help with jquery on codepen
JackeL
@jackel27
Feb 18 2016 01:21
@Blauelf my start...

var reformattedArray = cid.map(function(obj){ 
   var rObj = obj;
   rObj[obj.key] = obj.value;
   return rObj;
});
@Blauelf going to be a long night. haha
Norman Dela Cruz
@dcnr
Feb 18 2016 01:21
@MikeBeers try the main room and the FrontEnd too
Larry Simiyu
@LarrySimiyu
Feb 18 2016 01:24
@dcnr Okay so Im working on a c++ program. we ask the user to enter the lowest value and the highest value, so lets say highest 43 lowest 23, One thing the teacher does it increment by 5, which I know how to do.. but the teacher also manages to start the chart from 25 and end at 45. So basically he is able to make the chart divisible by 5. I dont know how I would manage to do that.
your help doesnt have to be in c++ I just wanna go in the correct direction
Norman Dela Cruz
@dcnr
Feb 18 2016 01:28
@LarrySimiyu and you're using for loops for this? You can set your initialization to start at the lowest and your condition to terminate at the highest. What I don't really know though is do you need it to be divisible by a certain number? If so, you might need to do some rounding or some operation
JackeL
@jackel27
Feb 18 2016 01:28
@Blauelf i think i have a good concept. Organize drawer ascending, loop through starting high, push then move on to next if remainder found ..
Larry Simiyu
@LarrySimiyu
Feb 18 2016 01:28
@dcnr instructions were to make it identical, thank you
CamperBot
@camperbot
Feb 18 2016 01:28
larrysimiyu sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 649 | @dcnr | http://www.freecodecamp.com/dcnr
Norman Dela Cruz
@dcnr
Feb 18 2016 01:29
@LarrySimiyu maybe something like
for (int i = lowest; i <= highest;  /*increment i here by some value*/)
John Roman
@jrroman
Feb 18 2016 01:46
function where(collection, source) {
  var arr = [];
  // What's in a name?
  for (var i in collection){
    var obj = collection[i];
    for (var j in obj){
      if (obj[j].hasOwnProperty(source)){
        arr.push(obj[j]);
      }
    }
  }
  return arr;
}

where([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
im a little stuck on this where art thou algorithm. I feel like im close but i could be wrong.
knnonah
@knnonah
Feb 18 2016 01:50
function repeat(str, num) {
  // repeat after me
  var zero = 0;
  var rpt = str.repeat(num);
  if(num < zero){
  return "";
 }
  else{
  return rpt;
  }
}

repeat("why", 3);
Hi all, can anyone tell me why this function will not return an empty string if the argument is a negative number?
Norman Dela Cruz
@dcnr
Feb 18 2016 01:51
@jrroman you should first check if the collection object has all of the source properties before you push, otherwise you will push in even those that only has one of the source properties
knnonah
@knnonah
Feb 18 2016 01:52
I suspect it is because "0" is not a negative number. However, making zero into a negative number doesn't help. Also, changing the second argument into a negative number throw a range error. Please advise. Thanks.
Instructions are:
Repeat a given string (first argument) num times (second argument). Return an empty string if num is a negative number.
John Roman
@jrroman
Feb 18 2016 01:56
@dcnr hmm okay.. I am returning obj[j] as null as well so i have to figure out what is going on there.
Norman Dela Cruz
@dcnr
Feb 18 2016 01:56
@knnonah you should first check if num is a valid argument for repeat before you do the repeat
@knnonah because you're getting errors and it's halting the execution
knnonah
@knnonah
Feb 18 2016 01:57
@dcnr What do you mean check if num is a valid argument? Do you if it is a number?
John Roman
@jrroman
Feb 18 2016 01:57
@dcnr and isnt that what is happening when i am running .hasOwnObject?
Norman Dela Cruz
@dcnr
Feb 18 2016 01:58
@knnonah repeat cannot accept negative numbers right? but what you do is you do str.repeat(num) without checking if num is valid (0 and above) so you're getting errors, stopping execution. Your if statement isn't being reached so it's not returning ""
Nicolas May
@hynso
Feb 18 2016 01:59
Quick question re: finding max or min values in arrays
Norman Dela Cruz
@dcnr
Feb 18 2016 01:59
@jrroman what do you mean .hasOwnObject? you mean .hasOwnProperty?
knnonah
@knnonah
Feb 18 2016 01:59
@dcnr Ah, the order in which the function needs to be corrected. Thanks.
CamperBot
@camperbot
Feb 18 2016 01:59
knnonah sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 650 | @dcnr | http://www.freecodecamp.com/dcnr
John Roman
@jrroman
Feb 18 2016 02:00
@dcnr yea sorry
Norman Dela Cruz
@dcnr
Feb 18 2016 02:00
@knnonah yes! also you don't have to do var zero = 0 :P just do (num < 0)
Nicolas May
@hynso
Feb 18 2016 02:00
For max, let's say, my approach was to set the max equal to the first array element and then to compare all the others to max using a for loop... is that about as good as it gets? Are there better approaches?
Norman Dela Cruz
@dcnr
Feb 18 2016 02:00
@jrroman it checks the object if the property is its own property and not a property inherited through prototype. You can check documents like the MDN for more info
@jrroman it returns true if it has the property and it is its own property, and false otherwise
oscar
@oscarg91
Feb 18 2016 02:05
need help with "Finding a remainder in javascript"
not sure how to writ the formula
Nicolas May
@hynso
Feb 18 2016 02:06
@oscarg91 what are you trying to find the remainder of?
Norman Dela Cruz
@dcnr
Feb 18 2016 02:06
@oscarg91 you can use the remainder operator (%) to get the remainder of the division of two numbers
lol
Nicolas May
@hynso
Feb 18 2016 02:07
@oscarg91 like the remainder of 10 divided by 3 is 1. So 10 % 3 = 1
Norman Dela Cruz
@dcnr
Feb 18 2016 02:07
new it damn latex
oscar
@oscarg91
Feb 18 2016 02:09
@hynsoSet remainder equal to the remainder of 11 divided by 3 using the remainder (%) operator.
// Only change code below this line

var remainder;
11 % 3 = 2;
not working
Nicolas May
@hynso
Feb 18 2016 02:11
var remainder = 11 % 3;
oscar
@oscarg91
Feb 18 2016 02:11
lol i feel dumb
Nicolas May
@hynso
Feb 18 2016 02:12
@oscarg91 no sweat! sometimes the cognitive overload prevents me from seeing obvious stuff, too :)
@oscarg91 and it's hard to get used to = being and assignment operator, not an equality sign
oscar
@oscarg91
Feb 18 2016 02:20
var a = 3;
var b = 17;
var c = 12;

// Only modify code below this line

var a += 12;
var b += 9;
var c += 7;
saying its wrong but instructions say to use +=
Nicolas May
@hynso
Feb 18 2016 02:21
@oscarg91 what are you trying to do?
oscar
@oscarg91
Feb 18 2016 02:22
assignment with Plus Equals
Nicolas May
@hynso
Feb 18 2016 02:22
yeah... but what do you want a to be equal to in the end?
oscar
@oscarg91
Feb 18 2016 02:22
15
CamperBot
@camperbot
Feb 18 2016 02:22

:point_right: js array prototype join [wiki]

Array.prototype.join()

The JavaScript array method .join() will combine all elements of an array into a single string.

:pencil: read more about js array prototype join on the FCC Wiki

Nicolas May
@hynso
Feb 18 2016 02:23
you don't have to redeclare the variable with var
var a = 3;    // a = 3
a += 12;      // a = 15
oscar
@oscarg91
Feb 18 2016 02:24
@hynso thanks again you are good
CamperBot
@camperbot
Feb 18 2016 02:24
oscarg91 sends brownie points to @hynso :sparkles: :thumbsup: :sparkles:
:star: 259 | @hynso | http://www.freecodecamp.com/hynso
oscar
@oscarg91
Feb 18 2016 02:24
how long have you been coding
Nicolas May
@hynso
Feb 18 2016 02:24
on and off for a couple of years
oscar
@oscarg91
Feb 18 2016 02:25
cool
so i take it you don't do this for work
Nicolas May
@hynso
Feb 18 2016 02:25
nope... but I'd like to eventually
oscar
@oscarg91
Feb 18 2016 02:26
yea me too
I'm just getting started obviously but it is very interesting
philipsiu
@philipsiu
Feb 18 2016 02:27
Hi! Can anyone help with the challenge "Title Case a Sentence"?
Nicolas May
@hynso
Feb 18 2016 02:27
oh yeah... it gets frustrating at times, but it's satisfying to push through the frustration
@philthyfill yeah... I finished that one yesterday... what's the question?
philipsiu
@philipsiu
Feb 18 2016 02:29
@hynso I've created a var to make the characters of the string lower case and then split them into an array. I'm looping through the array and trying to use charAt 0 to make each word's first character uppercase, but I'm having a hard time seeing the concept.
function titleCase(str) {
  var splitr = str.toLowerCase().split(" ");
  var splitr2 = [];
  for (var i = 0; i < splitr.length; i++) {
    splitr2.push(splitr[i][0].toUpperCase());
  }
  return splitr2;
}
titleCase("HERE IS MY HANDLE HERE IS MY SPOUT");
@hynso Here's my code so far. The result I'm getting are the charAt 0 characters changed to uppercase, but it does not display the rest of the characters.
Nicolas May
@hynso
Feb 18 2016 02:32
yeah, so you've got the first character but you've got to add the remaining
the slice function might work well for you
splitr2.push(splitr[i][0].toUpperCase() + ... )
Steven
@sgxinf
Feb 18 2016 02:34
I need a bit of help on a solution. Any one care to assist? (also how do I post my code?)
rphares
@rphares
Feb 18 2016 02:34
explain format
CamperBot
@camperbot
Feb 18 2016 02:34

:point_right: code formatting [wiki]

Inline code

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

Code Block

```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 ⏎]

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

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

rphares
@rphares
Feb 18 2016 02:34
@sgxinf :point_up:
Nicolas May
@hynso
Feb 18 2016 02:34
where the ... is, you can use slice... does that make sense?
rphares
@rphares
Feb 18 2016 02:35
(also, easiest just to paste your code and ask a Q-- people are always willing to help... just dont always know if we can till we see the question :blush: )
Steven
@sgxinf
Feb 18 2016 02:35
thanks rphares
rphares
@rphares
Feb 18 2016 02:36
anytime~
philipsiu
@philipsiu
Feb 18 2016 02:36
@hynso Lemme go research the slice function. I've looked at the hints in the wiki and it mentions to use replace with a regex.
Nicolas May
@hynso
Feb 18 2016 02:37
yeah i didn't think of regex
@philthyfill good luck!
philipsiu
@philipsiu
Feb 18 2016 02:41
@hynso I can target the first character with /[^.]/g, but I don't the regex that will replace it to uppercase.
Steven
@sgxinf
Feb 18 2016 02:42
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
  var answer = "";
  switch (checkProp) {
    case checkProp = "gift":
      return "pony";
      break;
    case checkProp = "pet":
      return "kitten";
      break;
    case checkProp = "bed":
      return "sleigh";
    default:
      return "Not Found";

  }

  return answer;
}

// Test your code by modifying these values
checkObj("pet");
So the code is complete and it works fine, but I do not beleive I used the correct method for the solution
rphares
@rphares
Feb 18 2016 02:42
@sgxinf , yep-- there is a simpler way,
instead of a switch, try using an if,
you will have just one if statement,
using .hasOwnProperty (like in the example)
Steven
@sgxinf
Feb 18 2016 02:44
@rphares would this be an if-else statement or truly just an "if"
rphares
@rphares
Feb 18 2016 02:44
and, instead of using all those specifics ("gift", "pony" "pet" etc)
stick to using checkProp
("Modify the functioncheckObj to test myObjforcheckProp." )
if else,
you need the else for not found...
but just one if (checking with .hasOwnProperty)
and one else ("Not Found")
Steven
@sgxinf
Feb 18 2016 02:46
@rphares thanks I'll give it another try
CamperBot
@camperbot
Feb 18 2016 02:46
sgxinf sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2828 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Feb 18 2016 02:53
of course! any time~
philipsiu
@philipsiu
Feb 18 2016 02:55
@hynso I just tried your method and it worked. Thanks.
CamperBot
@camperbot
Feb 18 2016 02:55
philthyfill sends brownie points to @hynso :sparkles: :thumbsup: :sparkles:
:star: 260 | @hynso | http://www.freecodecamp.com/hynso
seth dehaan
@sethxd
Feb 18 2016 03:05
Can anyone help me with the friendly date ranges bonfire? i think one of the test cases is wrong
CamperBot
@camperbot
Feb 18 2016 03:05
type bonfire name to get some info on that bonfire. And check HelpBonfires chatroom
Steven
@sgxinf
Feb 18 2016 03:06
@rphares
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

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

  return answer;
}

// Test your code by modifying these values
checkObj("gift");
seth dehaan
@sethxd
Feb 18 2016 03:06
bonfire friendly date ranges
CamperBot
@camperbot
Feb 18 2016 03:06

:fire:Bonfire: Friendly Date Ranges :link:

function friendly(str) {
  return str;
}

friendly(['2015-07-01', '2015-07-04']);

Implement a way of converting two dates into a more friendly date range that could be presented to a user.

more info:  bf details | bf links | hint

rphares
@rphares
Feb 18 2016 03:07
Awesome, @sgxinf ~
just one q--
whats that 'return answer' doing there? :wink2:
Steven
@sgxinf
Feb 18 2016 03:08
Woops!
rphares
@rphares
Feb 18 2016 03:08
:)
Norman Dela Cruz
@dcnr
Feb 18 2016 03:09
I think I'll stick to for loops first rather than methods hmm
Nicolas May
@hynso
Feb 18 2016 03:12
glad to hear you figured it out @philthyfill !
Norman Dela Cruz
@dcnr
Feb 18 2016 03:13

this is at least TWICE as fast :astonished:

function reverseString(str) {
  'use strict';

  let reversed = '';

  for (let i = str.length - 1; i >= 0; --i) {
    reversed += str[i];
  }

  return reversed;
}

than

function reverseString(str) {
  'use strict';

  return str.split('').reverse().join('');
}
Matthew Baker
@matthew-baker01
Feb 18 2016 03:20
I need some help with Accessing Objects Properties with Variables. I'm supposed to Use the playerNumber variable to lookup player 16 in testObj using bracket notation but I'm stuck.
// Setup
var testObj = {
  12: "Namath",
  16: "Montana",
  19: "Unitas"
};

// Only change code below this line;

var playerNumber = 16;       // Change this Line
var player = "Montana";   // Change this Line
Norman Dela Cruz
@dcnr
Feb 18 2016 03:23
@matthew-baker01 you can get the value from an object through its property by either using . or []. You'll have to use the [] if you are going to use variables as property name (or if the property name isn't a valid identifier, like if it's a number or if it has spaces)
var obj = {
  greeting: "Hello, world!"
};

var property = "greeting";
var result = obj[property]; // result is now Hello, world!
Casey Heath
@ExhibitArts
Feb 18 2016 03:24
Anyone willing to work on a startup project with me? I need some backend developers. Let me know if you're interested.
Norman Dela Cruz
@dcnr
Feb 18 2016 03:24
@ExhibitArts try here too https://gitter.im/FreeCodeCamp/CodingJobs
Matthew Baker
@matthew-baker01
Feb 18 2016 03:29
@dcnr Whenever I encoproate bracket notation into it, it goes wrong
rphares
@rphares
Feb 18 2016 03:31
@matthew-baker01 , maybe paste what you are trying with brackets :blush:
Matthew Baker
@matthew-baker01
Feb 18 2016 03:33
// Setup
var testObj = {
  12: "Namath",
  16: "Montana",
  19: "Unitas"
};

// Only change code below this line;

var playerNumber = 16;       // Change this Line
var player = [testObj]"Montana";   // Change this Line
I've been trying a combination of the [testObj] and [playerName] before and after "Montana" and 16
rphares
@rphares
Feb 18 2016 03:34
mm, close, but look at the order of the example @dcnr sent ya
(playerNumber is the variable you are meant to us ;) )
but the order-- both the words and brackets-- is throwing you off, i think... :blush:
Norman Dela Cruz
@dcnr
Feb 18 2016 03:36
sorry @matthew-baker01 I was away
and thanks @rphares
CamperBot
@camperbot
Feb 18 2016 03:36
dcnr sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2833 | @rphares | http://www.freecodecamp.com/rphares
Norman Dela Cruz
@dcnr
Feb 18 2016 03:37
@matthew-baker01 yeah examine the usage properly :D
rphares
@rphares
Feb 18 2016 03:37
lol, not at all, always happy to chime in if i can-- thank you for the lovely example :) @dcnr
CamperBot
@camperbot
Feb 18 2016 03:37
rphares sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 651 | @dcnr | http://www.freecodecamp.com/dcnr
Norman Dela Cruz
@dcnr
Feb 18 2016 03:37
:blush:
Matthew Baker
@matthew-baker01
Feb 18 2016 03:39
thank you both @dcnr @rphares I got it :D
CamperBot
@camperbot
Feb 18 2016 03:39
matthew-baker01 sends brownie points to @dcnr and @rphares :sparkles: :thumbsup: :sparkles:
:star: 652 | @dcnr | http://www.freecodecamp.com/dcnr
:star: 2834 | @rphares | http://www.freecodecamp.com/rphares
Guannue Bouquia
@GBArchitect
Feb 18 2016 03:39
can someone help me with the Accessing Nested Arrays in JSON lab
rphares
@rphares
Feb 18 2016 03:40
@GBArchitect , sure, can you paste your code, please :blush:
Guannue Bouquia
@GBArchitect
Feb 18 2016 03:40
var secondTree = myPlants.trees[1];
rphares
@rphares
Feb 18 2016 03:40
close, but a few things,
Guannue Bouquia
@GBArchitect
Feb 18 2016 03:40
this is the set up
ok
rphares
@rphares
Feb 18 2016 03:40
first, myPlants has two parts, right?
This message was deleted
Guannue Bouquia
@GBArchitect
Feb 18 2016 03:41
Well it has Trees and then the list
rphares
@rphares
Feb 18 2016 03:41
bigger than that--
Guannue Bouquia
@GBArchitect
Feb 18 2016 03:41
it has flowers and trees
at the highest level
rphares
@rphares
Feb 18 2016 03:41
yes, but we dont wanna call them flowers and trees,
we wanna use indexing
Guannue Bouquia
@GBArchitect
Feb 18 2016 03:42
true
rphares
@rphares
Feb 18 2016 03:42
(its in [])
so that change needs to happen to the first part, before the .
then, that will have gotten you the second part of myPlants, the part you called trees,
This message was deleted
Well it has Trees and then the list
Guannue Bouquia
@GBArchitect
Feb 18 2016 03:43
you lost me with (its in [])
rphares
@rphares
Feb 18 2016 03:43
oh, sorry,
This message was deleted
so before the .
should be either myPlants[0] or myPlants[1]
Guannue Bouquia
@GBArchitect
Feb 18 2016 03:44
oh ok
rphares
@rphares
Feb 18 2016 03:44
then after that,
Guannue Bouquia
@GBArchitect
Feb 18 2016 03:44
I think I see where you are going
rphares
@rphares
Feb 18 2016 03:44
This message was deleted
Guannue Bouquia
@GBArchitect
Feb 18 2016 03:44
let me try something
rphares
@rphares
Feb 18 2016 03:44
sure thing!
Guannue Bouquia
@GBArchitect
Feb 18 2016 03:45
nvm
rphares
@rphares
Feb 18 2016 03:45
yay! congrats, @matthew-baker01 :)
lol, what did you try, lets go from there now :)
Guannue Bouquia
@GBArchitect
Feb 18 2016 03:45
I understand myPlants[1] will call the 2nd item
I meant nvm as in it didnt work lol
rphares
@rphares
Feb 18 2016 03:46
good, so now you have myPlants[1].trees[1], right?
but,
Guannue Bouquia
@GBArchitect
Feb 18 2016 03:46
yea
rphares
@rphares
Feb 18 2016 03:46
"trees" is what you got by using myPlants[1]
the second mini-array isn't trees
look carefully-- where is the comma, where are the :[]
the index is right... but you aren't looking the right level when you say trees
Guannue Bouquia
@GBArchitect
Feb 18 2016 03:48
lol yea I`m not getting this
I understand the myPlants[1] part perfectly
rphares
@rphares
Feb 18 2016 03:49
okay, good!
but,
there is a small array in myPlants[1], right?
Guannue Bouquia
@GBArchitect
Feb 18 2016 03:49
nvm just got it lol
rphares
@rphares
Feb 18 2016 03:49
// Setup
var myPlants = [
  { 

  {
    type: "trees",
    list: [ // he starts HERE
      "fir",
      "pine",
      "birch"
    ]
  }  
];
oh, great! congrats and happy coding, @GBArchitect ~
Guannue Bouquia
@GBArchitect
Feb 18 2016 03:49
yea I figured it out
lol thanks
rphares
@rphares
Feb 18 2016 03:49
anytime~
Guannue Bouquia
@GBArchitect
Feb 18 2016 03:50
it was confusing looking at the example they gave
but I understand I should be looking to the left
rphares
@rphares
Feb 18 2016 03:50
it will get a bit more like that from now on--
Guannue Bouquia
@GBArchitect
Feb 18 2016 03:50
of the :smile:
:
rphares
@rphares
Feb 18 2016 03:50
the examples will often show you how to use the new part,
Guannue Bouquia
@GBArchitect
Feb 18 2016 03:50
I see
rphares
@rphares
Feb 18 2016 03:50
but the old stuff,
you wil; have to come up with by yourself and put it together,
for example, in this one,
you got an example of how to access a nested array
but not a reminder on accessing arrays, which you needed for the first part,
or setting it to a var,
like you needed for the whole thing...
whenever i get stuck, i read the directions for all the key words, rethink what part I'm missing, and review old lessons/mdn :blush: cause its gonna come up more and more ~
Ramon Jacinto Conanan
@pipoconanan45
Feb 18 2016 03:52
Help with the Record Collection challenge
CamperBot
@camperbot
Feb 18 2016 03:52
no wiki entry for: with the record collection challenge
rphares
@rphares
Feb 18 2016 03:53
help record collection
CamperBot
@camperbot
Feb 18 2016 03:53

:point_right: checkpoint record collection [wiki]

Checkpoint: Record Collection

Instructions

You are given a JSON object representing (a small part of) your record collection. Each album is identified by a unique id number and has several properties. Not all albums have complete information.

Write a function which takes an id, a property (prop), and a value.

For the given id in collection:

If value is non-blank (value !== ""), then update or set the value for the prop.

If the prop is "tracks" and value is non-blank, push the value onto the end of the tracks array.

If value is blank, delete that prop.

Always return the entire collection object.

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

:pencil: read more about checkpoint record collection on the FCC Wiki

rphares
@rphares
Feb 18 2016 03:53
@pipoconanan45 :point_up:
Ramon Jacinto Conanan
@pipoconanan45
Feb 18 2016 03:54
so yeah..thanks for that. i have no idea how to do that should i use if or switch?
rphares
@rphares
Feb 18 2016 03:54
if
Norman Dela Cruz
@dcnr
Feb 18 2016 03:55
@GBArchitect and it always helps to practice! for nested stuffs, it's easier to "drill down" step by step
var backpack = {
  food: {
    fruits: ['Apple', 'Persimmon', 'Gooseberry'],
    candies: ['Nougat', 'Gum', 'Toffee']
  },
  clothes: [
    'Shirt',
    'Pants',
    {
      Underpants: ['Boxers', 'Briefs', 'Thongs']
    }
  ]
};

// to get Thongs

backpack; // object
backpack.clothes // an array of strings, and an object
backpack.clothes[2] // an object with one property
backpack.clothes[2].Underpants // an array of strings
backpack.clothes[2].Underpants[2]; // the string Thongs
rphares
@rphares
Feb 18 2016 03:55
your conditionals can come directly from the instructions-- there are three if' right above us on this chat, in that hint :) @pipoconanan45
Ramon Jacinto Conanan
@pipoconanan45
Feb 18 2016 03:55
how do you post screen shots so i can show you what i did?
rphares
@rphares
Feb 18 2016 03:55
explain format
CamperBot
@camperbot
Feb 18 2016 03:55

:point_right: code formatting [wiki]

Inline code

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

Code Block

```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 ⏎]

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

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

rphares
@rphares
Feb 18 2016 03:56
(that said, I'm not super great at explaining the one, so if it isn't obvious to me, imma pass you to somebody else :pensive: there are some great people here, ill help if i can but let the vets take over if it requires a lot of whys or terms which I'm bad at...)
Ramon Jacinto Conanan
@pipoconanan45
Feb 18 2016 03:57
```function update(id, prop, value) {
if (id === collection0){
if (value !== "" && prop !== collection0.tracks){
collection[0][prop] = value;
} else if(value !== "" && prop === collection0.tracks){
collection0.tracks.push(value);
}
}
return collection;
}
rphares
@rphares
Feb 18 2016 03:57
ah, okay, a few things
the ifs can be directly from the instructions,
Sam
@SamOBry
Feb 18 2016 03:57
I need help you guys.... adding id attributes to bootstrap elements
and I do not know how to post my code
Ramon Jacinto Conanan
@pipoconanan45
Feb 18 2016 03:58
I think my main problem is accessing the objects and properties in the array.
rphares
@rphares
Feb 18 2016 03:59
If value is non-blank (value !== ""),(and the prop *isnt* tracks)
If the prop is "tracks" and value is non-blank
If value is blank
@pipoconanan45
then, yes
use brackets
no dot
Ramon Jacinto Conanan
@pipoconanan45
Feb 18 2016 03:59
aaaand did i got the ifs correctly or ??
rphares
@rphares
Feb 18 2016 04:00
(my first hint means you dont want things like collection0.tracksin your if... simplify exactly like the instructions )
Finally, you dont want [0] anywhere in there, actually.... "Write a function which takes an id, a property (prop), and a value." no indexing needed, but there is one of those guys that goes in that chain,
i think that should be enough to do some re-writing? (you may need to come back after that, but thats kinda a lot to start on :blush: )
Ramon Jacinto Conanan
@pipoconanan45
Feb 18 2016 04:03
Thank so much for entertaining my dilemma imma get back at you if I got it.
rphares
@rphares
Feb 18 2016 04:03
Sweet! Happy coding~
Alex Evans
@alex-evans
Feb 18 2016 04:06

Need a reminder about objects. If I have the following object:

var months = [
  {id: "01", name: "January"},
  {id: "02", name: "February"},
  {id: "03", name: "March"},
  {id: "04", name: "April"},
  {id: "05", name: "May"},
  {id: "06", name: "June"},
  {id: "07", name: "July"},
  {id: "08", name: "August"},
  {id: "09", name: "September"},
  {id: "10", name: "October"},
  {id: "11", name: "November"},
  {id: "12", name: "December"}
];

Is there a quick way to find the month tied to 05? Or is there a better way to build my months object? Right now I have to do this to find what name is tied to a month:

var mnth1 = months.filter(function(mnth) {
   if(mnth.id === rawDate1[1]) {
      return true;
   }
})[0].name;

And it just seems messy.

Sal
@salcamp
Feb 18 2016 04:07
@gravesmeister I am having trouble understanding this one as well. Did you find something to help you make sense of it?
Norman Dela Cruz
@dcnr
Feb 18 2016 04:08

@alcatrats instead of using that structure, why not just make it an array of strings of the months?

["January", "February", ...]

and just add one to the index, or stick with the zero base

that way you won't have to do unnecessary object allocations and stuff
Franco Zapata
@Francozt01
Feb 18 2016 04:08
@alcatrats have u tried a for loop - for (var id[X] in months) { }
Alex Evans
@alex-evans
Feb 18 2016 04:09
Makes sense @dcnr but before I give it a shot will it be messy since the months are being passed in as 01, 02, 03? I can't remember if I have to make those into a number or if js will handle that.
Norman Dela Cruz
@dcnr
Feb 18 2016 04:11
@alcatrats oh well I guess you can either subtract one if the months are passed or unshift one value so January's index start at 1 :P
@alcatrats you can also use parseInt if you know you're only dealing with "string numbers"
Alex Evans
@alex-evans
Feb 18 2016 04:11
That is one of the hints but I didn't fully understand parseInt. I'll take a closer look at that.
Sidharth Kriplani
@sidkrip
Feb 18 2016 04:12
anyone done with the Roman Numeral bonfire?
Alex Evans
@alex-evans
Feb 18 2016 04:13
Thanks @dcnr. Took a closer look at 'parseInt' and it isn't as complicated as I thought.
CamperBot
@camperbot
Feb 18 2016 04:13
alcatrats sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 653 | @dcnr | http://www.freecodecamp.com/dcnr
Sidharth Kriplani
@sidkrip
Feb 18 2016 04:14
err helo? Can anyone tell me how to approach the problem?
Norman Dela Cruz
@dcnr
Feb 18 2016 04:18
@sidkrip you can try getting hints from the wiki, but be aware that it has solutions at the bottom
wiki Roman numeral Converter
CamperBot
@camperbot
Feb 18 2016 04:18

:point_right: algorithm roman numeral converter [wiki]

Problem Explanation:

  • You will create a program that converts an integer to a roman numeral.
:pencil: read more about algorithm roman numeral converter on the FCC Wiki
Sidharth Kriplani
@sidkrip
Feb 18 2016 04:25
thanks @dcnr
CamperBot
@camperbot
Feb 18 2016 04:25
sidkrip sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 654 | @dcnr | http://www.freecodecamp.com/dcnr
Bryce Turner
@AbryceT
Feb 18 2016 04:28
I need a bit of help with the Record Collection. I finally got it to work but it was a crazy chance and I still on't understand why it works...private chat for somone to explain why this worked to me?!?!
Bueller...Bueller?
Otman Bouchari
@obouchari
Feb 18 2016 04:34
@AbryceT Sure, send a message
Greg D
@mosaic-greg
Feb 18 2016 04:37
heh coding by fluke
rphares
@rphares
Feb 18 2016 04:37
@mosaic-greg , its all i ever do...
(or more accurately, stringing the instructions and recommend reading together, without any skeleton... but same same shrug )]
Greg D
@mosaic-greg
Feb 18 2016 04:38
yep have to start somewhere
Bryce Turner
@AbryceT
Feb 18 2016 04:47
Thanks neeraj - lad
Thanks @neeraj-lad
CamperBot
@camperbot
Feb 18 2016 04:47
abrycet sends brownie points to @neeraj-lad :sparkles: :thumbsup: :sparkles:
:star: 319 | @neeraj-lad | http://www.freecodecamp.com/neeraj-lad
Neeraj Lad
@neeraj-lad
Feb 18 2016 04:48
YW
Otman Bouchari
@obouchari
Feb 18 2016 04:50
@dcnr That was an interesting story!
@dcnr @rphares Did you build the wiki viewer?
rphares
@rphares
Feb 18 2016 04:52
@obouchari ,no sorry, i havent
Ashley
@asberrie
Feb 18 2016 04:52
can anyone help me to understand the difference between dot notation and bracket notation? in reference to arrays and objects?
rphares
@rphares
Feb 18 2016 04:53
i have an article someone recommended that is mygo-to,
Otman Bouchari
@obouchari
Feb 18 2016 04:53
Ok, I'm working on it, the Wikipedia API is horrible or at least thats how I see it
rphares
@rphares
Feb 18 2016 04:53
@asberrie , that one really helped me :blush:
Ashley
@asberrie
Feb 18 2016 04:54
@rphares thanks! I'll take a look at it :)
CamperBot
@camperbot
Feb 18 2016 04:54
asberrie sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2840 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Feb 18 2016 04:54
(i forget who sent it, so i can't credit them-- owe you, mystery camper! )
anytime!
Okan
@Okandja
Feb 18 2016 05:03
Hey, need a hand again. "Modify the function abTest so that if a or b are less than 0 the function will immediately exit with a value of undefined."
<function abTest(a, b) { // Only change code below this line if (b < 0) return ; // Only change code above this line return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2)); }>
sorry

'''function abTest(a, b) {
// Only change code below this line
if (b < 0)
return ;

// Only change code above this line

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

CamperBot
@camperbot
Feb 18 2016 05:04
:bulb: to format code use backticks! ``` more info
rphares
@rphares
Feb 18 2016 05:04
close, but
first, your condition,
you want it to say
Okan
@Okandja
Feb 18 2016 05:04

```function abTest(a, b) {
// Only change code below this line
if (b < 0)
return ;

// Only change code above this line

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

i can't
rphares
@rphares
Feb 18 2016 05:04
if (a is less than zero OR b is less than zero)
so you will need to use || and you need the full condition on either side,
Okan
@Okandja
Feb 18 2016 05:05
I see
rphares
@rphares
Feb 18 2016 05:05
NOTif (a or b is less than zero)
right now, you only have b :blush:
second,
what are you supposed to return? ;)
Okan
@Okandja
Feb 18 2016 05:05
Yes, I understand, it went through
undefined
rphares
@rphares
Feb 18 2016 05:05
sweet
congrats and happy coding~
Okan
@Okandja
Feb 18 2016 05:06
Thanks @rphares , my day one homie
CamperBot
@camperbot
Feb 18 2016 05:06
okandja sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2842 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Feb 18 2016 05:06
(wow, typo city, i should not chat and eat at the same time)
anytime!
E
@efhjones
Feb 18 2016 05:08

Hi all! I'm really close on Chunky Monkey (I think) but the returned array is missing a bracket right before the second array, for example, it looks like this:

[["a", "b"],"c", "d"]

Here's my code:

function chunk(arr, size) {
  var slicedArr = [];
  var secondSlicedArr =[];
  var lastArr=[];

  for (i=0; i<size; i++){


     slicedArr.push(arr.slice(0, size));

    for (i=size; i<arr.length; i++){
      slicedArr.push(arr[i]);
    }
}return slicedArr;
}

chunk(["a", "b", "c", "d"], 2);
Not sure what to do!
Charles Chung
@chulmo
Feb 18 2016 05:11
Replace '&' with &amp ; ----> Can't seem to figure out why this code doesn't pass the test below, any insights much appreciated!
function convert(str) {
  var len = str.length -1;
  var strHolder = str;
  for (var i=0; i<=len;i++) {
    switch(str[i]){
      case "&":
        strHolder.replace("&","&amp;");
        break;
      case "<":
        strHolder.replace(str[i],"&#60");
        break;
      case ">":
        strHolder.replace(str[i], "&#62");
        break;
      case "\"":
        strHolder.replace(str[i], "&#34");
        break;
    }
  }

  return strHolder;
}

convert("Dolce & Gabbana");
eeflores
@eeflores
Feb 18 2016 05:13
@chulmo instead of "&#60 use &lt; etc
Charles Chung
@chulmo
Feb 18 2016 05:13
@eeflores how about the ampersand?
Ramon Jacinto Conanan
@pipoconanan45
Feb 18 2016 05:14
Thanks @rphares for your hel ealier.
CamperBot
@camperbot
Feb 18 2016 05:14
pipoconanan45 sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2843 | @rphares | http://www.freecodecamp.com/rphares
Norman Dela Cruz
@dcnr
Feb 18 2016 05:14
@chulmo replace does not mutate the string itself so you have to assign the new string returned by replace to something
eeflores
@eeflores
Feb 18 2016 05:14
@chulmo < => &lt;
> => &gt;
& => &amp;
\" => &quot;
rphares
@rphares
Feb 18 2016 05:14
yay, you got it? Congrats!!
Ramon Jacinto Conanan
@pipoconanan45
Feb 18 2016 05:15
Yup, thanks to you.
Charles Chung
@chulmo
Feb 18 2016 05:15
@dcnr That was it!! Thank you :) @eeflores thanks for the html char codes, looks like I was using ASCII codes instead...
CamperBot
@camperbot
Feb 18 2016 05:15
chulmo sends brownie points to @dcnr and @eeflores :sparkles: :thumbsup: :sparkles:
:star: 593 | @eeflores | http://www.freecodecamp.com/eeflores
:star: 655 | @dcnr | http://www.freecodecamp.com/dcnr
eeflores
@eeflores
Feb 18 2016 05:16
good job @chulmo
Norman Dela Cruz
@dcnr
Feb 18 2016 05:16
@chulmo few functions mutate its own object, like splice, so when in doubt check the docs :D
Bryan Gilbraith
@bryantheastronaut
Feb 18 2016 05:18
help falsy bouncer
CamperBot
@camperbot
Feb 18 2016 05:18

:point_right: algorithm falsy bouncer [wiki]

Problem Explanation:

Remove all falsy values from an array.

:pencil: read more about algorithm falsy bouncer on the FCC Wiki

Charles Chung
@chulmo
Feb 18 2016 05:19
@dcnr woohooo! javascript is awesome :)
bitgrower
@bitgrower
Feb 18 2016 05:31
@bryantheastronaut -- read the falsy bouncer "helpful hints" pages ... carefully ...
like some crazy adventure game ... thar be gold nuggest thar ...
oscar
@oscarg91
Feb 18 2016 05:44
need help
converting celsius t fahrenheit
bitgrower
@bitgrower
Feb 18 2016 05:44
got some code you can post ?
oscar
@oscarg91
Feb 18 2016 05:45
function convert(celsius) {
  // Only change code below this line
  if =
return=
  // Only change code above this line
  if ( typeof fahrenheit !== 'undefined' ) {
    return fahrenheit;
  } else {
    return 'fahrenheit not defined';
  }
}

// Change the inputs below to test your code
convert(30);
not sure how to write the test
algorithm
bitgrower
@bitgrower
Feb 18 2016 05:47
if you wrote out the conversion as an equation, how would you write it ?
oscar
@oscarg91
Feb 18 2016 05:47
fahrenheit= celsius*9/5 +32
bitgrower
@bitgrower
Feb 18 2016 05:49
okay ... so ... how would you write that in code ?
oscar
@oscarg91
Feb 18 2016 05:49
not sure lol
bitgrower
@bitgrower
Feb 18 2016 05:49
okay, break it down step by step ...
how would you set fahrenheit (the variable) to celsius (the variable, meaning, fahrenheit would now contain the same value of celsius ?)
oscar
@oscarg91
Feb 18 2016 05:52
fahrenheit=celcius?
zhouxh
@zhouxh
Feb 18 2016 05:54

Title Case a Sentence function titleCase(str) {
var arr = str.toLowerCase().split(/\s+/);
var newArr = arr.map(function(value){
var varr = value.split('');
varr0 = varr0.toUpperCase();
return varr.join('');

});
return newArr.join(' ');
}

bitgrower
@bitgrower
Feb 18 2016 05:54
well, except that you would use a semicolon to end the statement, instead of a question mark :) :) :)
JackeL
@jackel27
Feb 18 2016 05:55
@Blauelf U there
zhouxh
@zhouxh
Feb 18 2016 05:55
Title Case a Sentence There are other simple writing?
JackeL
@jackel27
Feb 18 2016 05:55
need help with something
Trying to see if a value exists in an array...
This is what I came up with..
if(correctChange.indexOf("PENNY")>0)
oscar
@oscarg91
Feb 18 2016 05:56
@bitgrower got it thanks!
CamperBot
@camperbot
Feb 18 2016 05:56
oscarg91 sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 563 | @bitgrower | http://www.freecodecamp.com/bitgrower
Markus Kiili
@Masd925
Feb 18 2016 05:57
@zhouxh varr0 is not declared. What is it?
bitgrower
@bitgrower
Feb 18 2016 05:57
all of it, @oscarg91 ???
zhouxh
@zhouxh
Feb 18 2016 05:58
varr0 = varr0.toUpperCase();
bitgrower
@bitgrower
Feb 18 2016 05:58
@jackel27 -- I feel your pain ... I am not sure you can do that ... strange things going on with quotes & strings ...
zhouxh
@zhouxh
Feb 18 2016 05:58
it's a array
[ is replaced
bitgrower
@bitgrower
Feb 18 2016 05:59
@zhouxh -- easier to help you if you post your code to get the syntax highlighting & etc ...
zhouxh
@zhouxh
Feb 18 2016 05:59
how to post my code to get the syntax highlighting
i haven't find it
bitgrower
@bitgrower
Feb 18 2016 06:00

:point_up: February 17, 2016 9:14 PM

this might help you, btw ...

for formatting

explain format
CamperBot
@camperbot
Feb 18 2016 06:00

:point_right: code formatting [wiki]

Inline code

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

Code Block

```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 ⏎]

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

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

Markus Kiili
@Masd925
Feb 18 2016 06:02
@zhouxh Your code works. You can do without splitting inside map callback if you use string operations.
zhouxh
@zhouxh
Feb 18 2016 06:03
This message was deleted
budimanfix
@budimanfix
Feb 18 2016 06:04

Hello folk, what missing here?? i couldn't runing test: function lookUp(firstName, prop){
// Only change code below this line

for (var i = 0; contacts[i]; i++){
if (contacts[i].firstName === firstName && contacts[i][prop]){
return contacts[i][prop];

} else if (contacts[i].firstName === contacts[i].hasOwnProperty(prop)){

  return "no such contact";
}
}

return "no such property";
}

zhouxh
@zhouxh
Feb 18 2016 06:04
function titleCase(str) {
  var arr  = str.toLowerCase().split(/\s+/);
  var newArr = arr.map(function(value){
     var varr =  value.split('');
    varr[0] = varr[0].toUpperCase();
    return varr.join('');

  });
  return newArr.join(' ');
}

titleCase("I'm a little tea pot");
Markus Kiili
@Masd925
Feb 18 2016 06:05
@budimanfix Change the for loop condition to i<contacts.length
zhouxh
@zhouxh
Feb 18 2016 06:05
is this a simple way?
Markus Kiili
@Masd925
Feb 18 2016 06:06
@zhouxh You can shave off some variables and use string operations:
function titleCase(str) {
  return str.split(' ').map(function(val){
    return val.charAt(0).toUpperCase() + val.substr(1).toLowerCase();
  }).join(' ');
}
zhouxh
@zhouxh
Feb 18 2016 06:06
thanks @Masd925
CamperBot
@camperbot
Feb 18 2016 06:06
zhouxh sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 989 | @masd925 | http://www.freecodecamp.com/masd925
Adi
@kiniadit
Feb 18 2016 06:09

why is this code not working?? `function bouncer(arr) {
// Don't show a false ID to this bouncer.
return arr.filter(isFalse);
}

function isFalse(value) {
return value !==0 && value !== false && value !== NaN && value !== undefined && value !== null && value !== "";
}

bouncer([false, null, 0, NaN, undefined, ""]);`

Markus Kiili
@Masd925
Feb 18 2016 06:10
@kiniadit NaN is special because NaN===NaN is false.
Adi
@kiniadit
Feb 18 2016 06:10
well I'm getting [null] as the return value
Markus Kiili
@Masd925
Feb 18 2016 06:10
Use value===value to test that value is not NaN.
It is NaN. FCC console shows it as null.
Adi
@kiniadit
Feb 18 2016 06:11
oh
so should i use isNaN()??
bitgrower
@bitgrower
Feb 18 2016 06:11
not really ...
it has some really peculiar behaviors (I was just reading about this in effective JS)
Markus Kiili
@Masd925
Feb 18 2016 06:12
@kiniadit typeof value==="number" && isNaN(value) or value!==value test for NaN.
Adi
@kiniadit
Feb 18 2016 06:12
@bitgrower interesting
@Masd925 thanks
CamperBot
@camperbot
Feb 18 2016 06:12
kiniadit sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 990 | @masd925 | http://www.freecodecamp.com/masd925
Larry Simiyu
@LarrySimiyu
Feb 18 2016 06:12
hello need some quick help with something. making a list that has ten lines, but I need the user input to be rounded up and divisible by 5.. so say they enter 43 i need the list to start at 45.. does anyone have any idea of how I can manage this.
bitgrower
@bitgrower
Feb 18 2016 06:12
yeah .. what @Masd925 said ...
work it out with paper & pencil ... @LarrySimiyu --
zhouxh
@zhouxh
Feb 18 2016 06:14
我说中文,又懂得吗
my english is not very well
JackeL
@jackel27
Feb 18 2016 06:15
UHH
my code stuck in infinite loop
Bryan Gilbraith
@bryantheastronaut
Feb 18 2016 06:17
@bitgrower thanks for the tip! It was so simple one I figured it out but drove me crazy until then
CamperBot
@camperbot
Feb 18 2016 06:17
bryantheastronaut sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 564 | @bitgrower | http://www.freecodecamp.com/bitgrower
sergioarzac
@sergioarzac
Feb 18 2016 06:20
I'm using array.join() to merge the items in an array. However, I'm trying to remove the commas when they merge. How is this done? Websites keep telling me to put a space in the (" "), but that does not do anything.
bitgrower
@bitgrower
Feb 18 2016 06:21
use the (" ") when you use split
help rooms
CamperBot
@camperbot
Feb 18 2016 06:21

:point_right: help rooms [wiki]

Help Rooms

Choose the right room for your question!

:pencil: read more about help rooms on the FCC Wiki

sergioarzac
@sergioarzac
Feb 18 2016 06:21

The following is my code:
function reverseString(str) {

var split = str.split("");
var rev = split.reverse();
var join = rev.join(" and");

return rev;
}

reverseString("hello");

wait, ignore the "and" in there, i was testing that and still didn't work
bitgrower
@bitgrower
Feb 18 2016 06:22
don't recall exactly what you need to do, but I think if you go check out the MDN page on split, it will help you ...
Markus Kiili
@Masd925
Feb 18 2016 06:26
@sergioarzac Just use .join("") and return the right variable.
sergioarzac
@sergioarzac
Feb 18 2016 06:26
OHHH wait, I'm returning the wrong var :(
Markus Kiili
@Masd925
Feb 18 2016 06:27
@sergioarzac You can also chain those operations. Code gets clearer.
sergioarzac
@sergioarzac
Feb 18 2016 06:27
How exactly does "chaining" look like?
bitgrower
@bitgrower
Feb 18 2016 06:28
yeah, LOL ... was just playing with .split & .join ... when you said ("") wasn't working I doubted myself ...
Markus Kiili
@Masd925
Feb 18 2016 06:28
return str.split("").reverse().join("");
sergioarzac
@sergioarzac
Feb 18 2016 06:29
@bitgrower haha, it's always a small thing I overlook. Thanks for the tip!
CamperBot
@camperbot
Feb 18 2016 06:29
sergioarzac sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 565 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Feb 18 2016 06:29
not to worry -- it's a malady common to all programmers ... :)
sergioarzac
@sergioarzac
Feb 18 2016 06:29
@Masd925 I love cleaner code, thanks!
CamperBot
@camperbot
Feb 18 2016 06:29
sergioarzac sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 991 | @masd925 | http://www.freecodecamp.com/masd925
bitgrower
@bitgrower
Feb 18 2016 06:29
daily reminders to keep us humble ...
Lasse
@Lasse-DBE
Feb 18 2016 06:29
hello guys !
bitgrower
@bitgrower
Feb 18 2016 06:29
hello @Lasse-DBE
Markus Kiili
@Masd925
Feb 18 2016 06:30
@Lasse-DBE Hello.
Lasse
@Lasse-DBE
Feb 18 2016 06:31
i was wondering, what coding environment do you think is optimal for a beginner to test/debug small pieces of code, ? i have been using the browser console, but thought there may be a better place
Markus Kiili
@Masd925
Feb 18 2016 06:32
@Lasse-DBE Javascript code?
Lasse
@Lasse-DBE
Feb 18 2016 06:32
yes
Markus Kiili
@Masd925
Feb 18 2016 06:32
@Lasse-DBE repl.it is one place.
zhouxh
@zhouxh
Feb 18 2016 06:32
function largestOfFour(arr) {
  // You can do this!
 var newArr  =   arr.map( function(val)
   {   
      singleVal = val.reduce( function(previousVal,currentVal){
    return previousVal> currentVal ? previousVal :currentVal; 
     });
      console.log(singleVal);
    return   singleVal;
  });

  return newArr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Return Largest Numbers in Arrays is this a simple way?
budimanfix
@budimanfix
Feb 18 2016 06:33

@Masd925 couldn't work : for (var i = 0;i < contacts.length; i++){
if (contacts[i].firstName === firstName && contacts[i][prop]){
return contacts[i][prop];

} else if (contacts[i].firstName === contacts[i].hasOwnProperty(prop)){

  return "no such contact";
}
}

return "no such property";
}

bitgrower
@bitgrower
Feb 18 2016 06:33
why are you using map @zhouxh ?
Markus Kiili
@Masd925
Feb 18 2016 06:33
@Lasse-DBE You can do performance tests on jsperf.com
@budimanfix Returning no such contact belongs after the contact loop block.
Lasse
@Lasse-DBE
Feb 18 2016 06:34
@Masd925 that seems like the place i was looking for. Thanks !
CamperBot
@camperbot
Feb 18 2016 06:34
lasse-dbe sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 992 | @masd925 | http://www.freecodecamp.com/masd925
zhouxh
@zhouxh
Feb 18 2016 06:34
iterate the array @bitgrower
bitgrower
@bitgrower
Feb 18 2016 06:35
hmmm ... maybe use filter ? ...
Lasse
@Lasse-DBE
Feb 18 2016 06:36
@Masd925 right now im just testing if my code works or not, so repl.it seems like the place to go
bitgrower
@bitgrower
Feb 18 2016 06:36
I dunno ... I understand the problem, I understand how to program it ... but I'm having trouble understand how the functional calls work here ...
Rory Avant
@roryavant8
Feb 18 2016 06:37
Hey guys. I'm on the last challenge of the intermediate level Bonfires, titled "Arguments Optional" One of the inputs for the challenge is add(2)(3)...is this even valid input for a javascript function?
Charles Chung
@chulmo
Feb 18 2016 06:37
Having some trouble with the Spinal Tap regex, any help would be much appreciated :)
function spinalCase(str) {
 return str
   .replace(/[\s\_]/g,"-")
   .replace(/([A-Z])/g, '-$1')
   .replace(/[(\-)]+/g,"-")
   .slice(1)
   .toLowerCase();
}

spinalCase('ThisIsSpinalTap');
zhouxh
@zhouxh
Feb 18 2016 06:37
filter will return a array ,but its need return a int value
Markus Kiili
@Masd925
Feb 18 2016 06:37
@Lasse-DBE The console output is also better formatted on repl.it than on FCC.
bitgrower
@bitgrower
Feb 18 2016 06:38
@zhouxh -- well overall, the problem returns an array, are we on the same wavelength ?
Markus Kiili
@Masd925
Feb 18 2016 06:38
@zhouxh .map() is the correct method.
bitgrower
@bitgrower
Feb 18 2016 06:38
LOL ... see, I knew @Masd925 would have a different opinion ... LOL ...
Lasse
@Lasse-DBE
Feb 18 2016 06:39
@Masd925 thats awesome ! i think its pretty good on FCC, but it missed an opportunity to just just it as a console, without any specific tasks
Markus Kiili
@Masd925
Feb 18 2016 06:39
@bitgrower Each array element is mapped to a number, so map is one way.
Lasse
@Lasse-DBE
Feb 18 2016 06:39
misses*
just use it*
budimanfix
@budimanfix
Feb 18 2016 06:40
@Masd925 for (var i = 0;i < contacts.length; i++){
if (contacts[i].firstName === firstName && contacts[i][prop]){
return contacts[i][prop];
return "no such contact";
bitgrower
@bitgrower
Feb 18 2016 06:40
k, thanks @Masd925
CamperBot
@camperbot
Feb 18 2016 06:40
bitgrower sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 993 | @masd925 | http://www.freecodecamp.com/masd925
Brett Felts
@brettfelts
Feb 18 2016 06:42
I'm still having some trouble with my wikipedia app.
I can't seem to get it to display any results.
Rory Avant
@roryavant8
Feb 18 2016 06:47

Here is my code for the Arguments Optional Bonfire
'''
function add() {
var arg = arguments[0];
var sum;
//console.log(arguments[0] + " and " + arguments[1]);
if(isNaN(arguments[0]) || isNaN(arguments[1]) || (arguments[1] === undefined)) {
console.log("hit");

return undefined;

}
}
'''

This is just a test for the last 3 inputs.
The last input is add(2)([3])
would my code not return undefined?

CamperBot
@camperbot
Feb 18 2016 06:47
:bulb: to format code use backticks! ``` more info
zhouxh
@zhouxh
Feb 18 2016 06:48
thanks @camperbot
CamperBot
@camperbot
Feb 18 2016 06:48
zhouxh sends brownie points to @camperbot :sparkles: :thumbsup: :sparkles:
:star: 1207 | @camperbot | http://www.freecodecamp.com/camperbot
Larry Simiyu
@LarrySimiyu
Feb 18 2016 06:49
can someone help me out with a quick problem im having.
Rory Avant
@roryavant8
Feb 18 2016 06:49
function add() {
  var arg = arguments[0];
  var sum;
  //console.log(arguments[0] + " and " + arguments[1]);
  if(isNaN(arguments[0]) || isNaN(arguments[1]) || (arguments[1] === undefined)) {
    console.log("hit");
    return undefined;

  }
}
Larry Simiyu
@LarrySimiyu
Feb 18 2016 06:50
im trying to make a table to convert gallons to liters, only problem is on the first line on the table that is when my solution works fine, but it keeps printing the same answers for the rest of the table.. so for example 5 = 10; 6 = 10; 7 = 10;
how can I solve it
Pradeep CE
@cepradeep
Feb 18 2016 06:51
@LarrySimiyu show us your code and we will try to help :)
Larry Simiyu
@LarrySimiyu
Feb 18 2016 06:52
`
what is the short cut for pasting code like guy up above @pradeepce
zhouxh
@zhouxh
Feb 18 2016 06:53

kirbyedy
@kirbyedy
Feb 18 2016 06:53
help format
CamperBot
@camperbot
Feb 18 2016 06:53

:point_right: code formatting [wiki]

Inline code

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

Code Block

```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 ⏎]

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

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

Pradeep CE
@cepradeep
Feb 18 2016 06:54
@LarrySimiyu Copy your code, and use backticks to format it. The backtick can found below Esc key on most keyboards.
wiki format
CamperBot
@camperbot
Feb 18 2016 06:54

:point_right: code formatting [wiki]

Inline code

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

Code Block

```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 ⏎]

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

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

Larry Simiyu
@LarrySimiyu
Feb 18 2016 06:55
@pradeepce just letting you know its in c++, not to much of a difference when it comes to for loops and what not
`gallon = lowestValue;
listCounter = 0;
remainderEquation = gallon % FIVE;
listStart = gallon - remainderEquation + FIVE;
    while(listCounter <= MAX_LIST) {

        liter = gallon * 3.785;
        cout << setw(4) << listStart   << setw(6) << liter << endl;
        listCounter++;
        listStart += 5;
    }
`
Vamsidhar Reddy Bada
@vamsidharBada
Feb 18 2016 06:55
function titleCase(str) {
  str = str.split(" ");
  for(var i =0;i<str.length;i++){
    str[i].toLowerCase();
    var str2=str[i].split("");
    str2[0]= str2[0].toUpperCase();
    str[i] = str2.join("");
  }
  str = str.join(" ");
  return str;
}

titleCase("I'm a little tea pot");
For "Title Case a Sentence” Challenge.
Pradeep CE
@cepradeep
Feb 18 2016 06:57
@LarrySimiyu You aren't changing your liter and gallon variables in your loop.
@vamsidhar2mp Whats the prob you're having?
Larry Simiyu
@LarrySimiyu
Feb 18 2016 07:01
@pradeepce the gallons are changing how I want them to when i run my code... but I obviously cant change liters manually because I would be changing the answer
Jorge Alfonso Zendejas Garcia
@zgjorge
Feb 18 2016 07:09
hi, I need help with this bonfire, "record collection

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

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

if (value !=="" && prop !=="tracks")
{
collection[2548].artist="";
// collection[1245].tracks="Addicted to Love";
//collection[id][prop] = value;
}
if (prop =="tracks" && value !=="")
{
// collection[id].tracks.push(value);
collection[id].tracks.push(value);
}

return collection;
}

// Alter values below to test your code
update(5439, "artist", "ABBA");
'''

CamperBot
@camperbot
Feb 18 2016 07:09
:bulb: to format code use backticks! ``` more info
Jorge Alfonso Zendejas Garcia
@zgjorge
Feb 18 2016 07:10
// Setup
var collection = {
    2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    2468: {
      album: "1999",
      artist: "Prince",
      tracks: [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    1245: {
      artist: "Robert Palmer",
      tracks: [ ]
    },
    5439: {
      album: "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

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

if (value !=="" && prop !=="tracks")
{
  collection[2548].artist="";
//  collection[1245].tracks="Addicted to Love";
//collection[id][prop] = value;
}
  if (prop =="tracks" && value !=="")
    {
    //  collection[id].tracks.push(value);
     collection[id].tracks.push(value);
    }

  return collection;
}

// Alter values below to test your code
update(5439, "artist", "ABBA");
Rory Avant
@roryavant8
Feb 18 2016 07:11
can anyone help me??
Jorge Alfonso Zendejas Garcia
@zgjorge
Feb 18 2016 07:13
// Setup
var collection = {
    2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    2468: {
      album: "1999",
      artist: "Prince",
      tracks: [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    1245: {
      artist: "Robert Palmer",
      tracks: [ ]
    },
    5439: {
      album: "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

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

if (value !=="" && prop !=="tracks")
{
  //collection[2548].artist="";
//  collection[1245].tracks="Addicted to Love";
collection[id][prop] = value;
}
  if (prop =="tracks" && value !=="")
    {
    //  collection[id].tracks.push(value);
     collection[id].tracks.push(value);
    }

  return collection;
}

// Alter values below to test your code
update(5439, "artist", "ABBA");
can some one help me? im stuck with this one
its the "record collection"

"Write a function which takes an id, a property (prop), and a value.

For the given id in collection:

If value is non-blank (value !== "") and prop is not "tracks" then update or set the value for the prop.

If the prop is "tracks" and value is non-blank, push the value onto the end of the tracks array.

If value is blank, delete that prop.

Always return the entire collection object."

someone?
budimanfix
@budimanfix
Feb 18 2016 07:16
Guys!! why this code still couldn't sucess runing test :
for (var i = 0;i < contacts.length; i++) {
if (contacts[i].firstName === firstName)
{
if (contacts[i][prop]) {
return contacts[i][prop];
}
else {
return "no such property";
}
Abhishek Kumar
@abhishekKumar1
Feb 18 2016 07:16
@zgjorge what error r u getting??
@budimanfix your code is not complete there is a third condition too read the problem
budimanfix
@budimanfix
Feb 18 2016 07:17
Jorge Alfonso Zendejas Garcia
@zgjorge
Feb 18 2016 07:17
@abhishekKumar1 oh thats true, let me try again
budimanfix
@budimanfix
Feb 18 2016 07:18
@abhishekKumar1 would you show me wich fart actually?
Jorge Alfonso Zendejas Garcia
@zgjorge
Feb 18 2016 07:19
@abhishekKumar1 thank you
CamperBot
@camperbot
Feb 18 2016 07:19
zgjorge sends brownie points to @abhishekkumar1 :sparkles: :thumbsup: :sparkles:
:star: 345 | @abhishekkumar1 | http://www.freecodecamp.com/abhishekkumar1
Abhishek Kumar
@abhishekKumar1
Feb 18 2016 07:19
@budimanfix plz no "fart" :smile: and you haven't used case "No such contact"
Jorge Alfonso Zendejas Garcia
@zgjorge
Feb 18 2016 07:20
@abhishekKumar1 it worked, I dont know why I didnt see that part, LOL I knew I had to delete something but didint read the instructions properly, thanks :D
CamperBot
@camperbot
Feb 18 2016 07:20
zgjorge sends brownie points to @abhishekkumar1 :sparkles: :thumbsup: :sparkles:
:warning: zgjorge already gave abhishekkumar1 points
Abhishek Kumar
@abhishekKumar1
Feb 18 2016 07:20
an please return "No such property" instead of "no such property"
budimanfix
@budimanfix
Feb 18 2016 07:21
@abhishekKumar1 Shadow example plz..?
Abhishek Kumar
@abhishekKumar1
Feb 18 2016 07:22
@budimanfix you have not used the case in which you should return "No such contact" read the problem again
budimanfix
@budimanfix
Feb 18 2016 07:26
@abhishekKumar1 Thank you I'm trying :+1:
CamperBot
@camperbot
Feb 18 2016 07:26
budimanfix sends brownie points to @abhishekkumar1 :sparkles: :thumbsup: :sparkles:
:star: 346 | @abhishekkumar1 | http://www.freecodecamp.com/abhishekkumar1
farisha
@farishaummimath
Feb 18 2016 07:30
need help in Stand in Line challege
Abhishek Kumar
@abhishekKumar1
Feb 18 2016 07:31
@farishaummimath paste ur code
farisha
@farishaummimath
Feb 18 2016 07:31

function queue(arr, item) {
// Your code here

return item; // Change this line
}

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

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

bitgrower
@bitgrower
Feb 18 2016 07:31
@farishaummimath -- you need to write 2 or 3 lines of code, max --
and you can find which by looking up the array functions in Mozilla Developer Network ...
Abhishek Kumar
@abhishekKumar1
Feb 18 2016 07:32
@farishaummimath you have not written anyting
bitgrower
@bitgrower
Feb 18 2016 07:32
in fact, I think it's only 2 ...
Abhishek Kumar
@abhishekKumar1
Feb 18 2016 07:32
try these it will help
help .push
CamperBot
@camperbot
Feb 18 2016 07:32

:point_right: challenge manipulate arrays with push() [wiki]

Manipulate Arrays With push()

Not only can you pop() data off of the end of an array, you can also push() data onto the end of an array.

myArray.push(["dog", 3]);

:pencil: read more about challenge manipulate arrays with push on the FCC Wiki

Abhishek Kumar
@abhishekKumar1
Feb 18 2016 07:32
help .shift
CamperBot
@camperbot
Feb 18 2016 07:32

:point_right: challenge manipulate arrays with shift() [wiki]

Manipulate Arrays With shift()

shift() removes the first element unlike pop() which removes the last.

:pencil: read more about challenge manipulate arrays with shift on the FCC Wiki

farisha
@farishaummimath
Feb 18 2016 07:33
so you neeed touse shift and push poprations
operations *
Abhishek Kumar
@abhishekKumar1
Feb 18 2016 07:33
:smile:
budimanfix
@budimanfix
Feb 18 2016 07:34
@abhishekKumar1 Example plz?
Abhishek Kumar
@abhishekKumar1
Feb 18 2016 07:34
@budimanfix example for which problem?
prakash
@srividhyaprakash
Feb 18 2016 07:35
Hi guys , I have a problem
```
function update(id, prop, value) {
  if ( value !== "" && collection.id.prop !== collection.id.tracks) {
    collection.id.prop = value;
  } else if ( collection.id.prop === collection.id.tracks && value !== "") {
    collection.id.tracks.push(value);
  } else if ( value === "") {
    delete collection.prop;
  }


  return collection;
}
```
budimanfix
@budimanfix
Feb 18 2016 07:36

@abhishekKumar1 for (var i = 0;i < contacts.length; i++) {
if (contacts[i].firstName === firstName)
{
if (contacts[i][prop]) {
return contacts[i][prop];
}
else {
return "no such contact";
}
}
}
return "no such property";

}

prakash
@srividhyaprakash
Feb 18 2016 07:36
var collection = {
    2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    2468: {
      album: "1999",
      artist: "Prince",
      tracks: [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    1245: {
      artist: "Robert Palmer",
      tracks: [ ]
    },
    5439: {
      album: "ABBA Gold"
    }
};
I am working with nested objects
could anyone help??
Abhishek Kumar
@abhishekKumar1
Feb 18 2016 07:37
@budimanfix @srividhyaprakash same problem case :smile:
Luu Nguyen
@nnluukhtn
Feb 18 2016 07:37
@srividhyaprakash what is your problem?
budimanfix
@budimanfix
Feb 18 2016 07:38
@abhishekKumar1 Toss :smile:
zhouxh
@zhouxh
Feb 18 2016 07:38
This message was deleted
prakash
@srividhyaprakash
Feb 18 2016 07:39
How do you access
the value for
say "ABBA gold"?
Abhishek Kumar
@abhishekKumar1
Feb 18 2016 07:39
@budimanfix your code seems ok what error r u getting?
Luu Nguyen
@nnluukhtn
Feb 18 2016 07:40
@srividhyaprakash you wanna get value of album right?
prakash
@srividhyaprakash
Feb 18 2016 07:40
yeah
Abhishek Kumar
@abhishekKumar1
Feb 18 2016 07:40
by the way return "No such contact" instead of "no such contact" and "No such property" instead of "no such property"
prakash
@srividhyaprakash
Feb 18 2016 07:41
suppose say we assign all the numbers to an id
Luu Nguyen
@nnluukhtn
Feb 18 2016 07:43
Maybe this will help you
$.each(collection, function(key, value) {
  console.log(value.album);
});
prakash
@srividhyaprakash
Feb 18 2016 07:43
ill try
Hemedi
@Hemedi
Feb 18 2016 07:56
help Exact Change
CamperBot
@camperbot
Feb 18 2016 07:56

:point_right: algorithm exact change [wiki]

Problem Explanation:

  • You have to create a program that will handle when the register does not have enough cash or will have no cash after the transaction. Other than that it needs to return an array of the change in the form of an array, so that will be a 2D array.
:pencil: read more about algorithm exact change on the FCC Wiki
zhouxh
@zhouxh
Feb 18 2016 07:56
help null
CamperBot
@camperbot
Feb 18 2016 07:56
no wiki entry for: null
zhouxh
@zhouxh
Feb 18 2016 07:57
help NaN
CamperBot
@camperbot
Feb 18 2016 07:57
no wiki entry for: nan
Yasin Yusuf
@YasinYA
Feb 18 2016 07:57
hey guys can anyone help me with angularjs
Nick Robson
@nickrobson
Feb 18 2016 07:57
help falsey
CamperBot
@camperbot
Feb 18 2016 07:57
no wiki entry for: falsey
Nick Robson
@nickrobson
Feb 18 2016 07:57
eck
Blauelf
@Blauelf
Feb 18 2016 07:58
find falsy
CamperBot
@camperbot
Feb 18 2016 07:58

find falsy

:zero: algorithm falsy bouncer
:one: js falsy

zhouxh
@zhouxh
Feb 18 2016 07:58
falsy is so hard
Blauelf
@Blauelf
Feb 18 2016 07:58
1
CamperBot
@camperbot
Feb 18 2016 07:58

:point_right: js falsy [wiki]

Something which evaluates to FALSE. There are only five falsey values in JavaScript:
undefined, null, NaN, 0, "" (empty string), and false of course.

See also: truthy | Truthy & Falsey blog post
:pencil: read more about js falsy on the FCC Wiki

zhouxh
@zhouxh
Feb 18 2016 07:58
thanks @Blauelf
CamperBot
@camperbot
Feb 18 2016 07:58
zhouxh sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1250 | @blauelf | http://www.freecodecamp.com/blauelf
Vantrav
@vantrav
Feb 18 2016 08:00
function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  for (var i=0;i<arr.length;i++){
    for(var j=0;j<arr[i].length;j++){
      product *= arr[i][j];
    }
  }
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
I this acceptable solution?
kirbyedy
@kirbyedy
Feb 18 2016 08:01
is it working?
Josh Fisk
@JoshFisk
Feb 18 2016 08:02
@vantrav It looks fine. You could put arr[i] in it's own variable to make it more efficient, and readable.
Something like var innerArray = arr[i]; then you could use that everywhere inside the second for loop
Vantrav
@vantrav
Feb 18 2016 08:05
@JoshFisk
like this you mean?
function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
  for (var i=0;i<arr.length;i++){
var innerArr = arr[i];
    for(var j=0;j<innerArr.length;j++){
      product *= innerArr[j];
    }
  }
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
Josh Fisk
@JoshFisk
Feb 18 2016 08:06
@vantrav Yeah, if you wanted. It is probably possible to solve this using the reduce function as well.
Vantrav
@vantrav
Feb 18 2016 08:07
yes that works too…, any other aha! solutions to it?
bitgrower
@bitgrower
Feb 18 2016 08:07
@JoshFisk -- you have background in another programming language ?
Vantrav
@vantrav
Feb 18 2016 08:07
@bitgrower no! why do you ask?
bitgrower
@bitgrower
Feb 18 2016 08:08
was asking @JoshFisk ...
Josh Fisk
@JoshFisk
Feb 18 2016 08:08
@bitgrower Mainly C#
Vantrav
@vantrav
Feb 18 2016 08:08
@JoshFisk any other aha! solutions to it? :smile:
bitgrower
@bitgrower
Feb 18 2016 08:09

yeah ... cuz I would be inclined, from my background, to give some of the advice you've given, but I've not heard those kinds of coder optimizations recommended in the JS community ... in fact,, they almost seem bent on using the fewest # of variables possible...

I could be wrong ... but it's definitely the impression I get ...

Abhishek Kumar
@abhishekKumar1
Feb 18 2016 08:09
@vantrav is your initial solution not working?
Josh Fisk
@JoshFisk
Feb 18 2016 08:10
It works, he just wants to know things
@vantrav You could learn how to use apply.
I just learned of it recently
It lets you treat an array like it's a bunch of arguments
bitgrower @bitgrower is still trying to get her brain around some of js's uniquenesses ...
bitgrower
@bitgrower
Feb 18 2016 08:11
or is that a bunch of arguments like they are an array, @JoshFisk ... at least that's how I've learned how to use it ... (about the only way, so far ... )
Josh Fisk
@JoshFisk
Feb 18 2016 08:12
I think it turns something like...([1,2,3])
Vantrav
@vantrav
Feb 18 2016 08:12
@JoshFisk indeed more readable, thanks!
CamperBot
@camperbot
Feb 18 2016 08:12
vantrav sends brownie points to @joshfisk :sparkles: :thumbsup: :sparkles:
Josh Fisk
@JoshFisk
Feb 18 2016 08:12
into (1,2,3)
CamperBot
@camperbot
Feb 18 2016 08:12
:star: 257 | @joshfisk | http://www.freecodecamp.com/joshfisk
Vantrav
@vantrav
Feb 18 2016 08:12
@abhishekKumar1
it does
Josh Fisk
@JoshFisk
Feb 18 2016 08:12
@bitgrower Try this out : ) Math.max.apply(null,[1,2,3,4,5]);
prakash
@srividhyaprakash
Feb 18 2016 08:13

@nnluukhtn i tried this ```function update(id, prop, value) {
if ((value !== "") && (collection[id][prop] !== collection[id]["tracks"])) {
collection[id][prop] = value;
} else if ((collection[id][prop] === collection[id]["tracks"]) && (value !== "")) {
collection[id]["tracks"].push(value) ;
} else if (value === "") {
delete collection[id][prop] ;
}

return collection;
}``` but no luck

bitgrower
@bitgrower
Feb 18 2016 08:13
yeah ... about the 3rd code example on the MDN shows how to turn the arguments object into an array ...
Vantrav
@vantrav
Feb 18 2016 08:13
@JoshFisk apply in this scenario?
Josh Fisk
@JoshFisk
Feb 18 2016 08:13
Apply in your loop?
Blauelf
@Blauelf
Feb 18 2016 08:14
@srividhyaprakash Triple backticks need their own line. Insert line breaks using Shift+Return where needed.
prakash
@srividhyaprakash
Feb 18 2016 08:14
function update(id, prop, value) {
  if ((value !== "") && (collection[id][prop] !== collection[id]["tracks"])) {
    collection[id][prop] = value;
  } else if ((collection[id][prop] === collection[id]["tracks"]) && (value !== "")) {
    collection[id]["tracks"].push(value) ;
  } else if (value === "") {
    delete collection[id][prop] ;
  }

  return collection;
}
ya thanks but the code doesn't run,any suggestions?
@Blauelf
Blauelf
@Blauelf
Feb 18 2016 08:15
@srividhyaprakash And prop is not "tracks" literally means that, prop !== "tracks" (no collection in the conditions)
prakash
@srividhyaprakash
Feb 18 2016 08:16
@Blauelf oh yeah thanks, but still doesnt run
CamperBot
@camperbot
Feb 18 2016 08:16
srividhyaprakash sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1251 | @blauelf | http://www.freecodecamp.com/blauelf
Blauelf
@Blauelf
Feb 18 2016 08:17
What's your code now? And are you sure you left the surrounding code intact?
prakash
@srividhyaprakash
Feb 18 2016 08:17
// Setup
var collection = {
    2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    2468: {
      album: "1999",
      artist: "Prince",
      tracks: [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    1245: {
      artist: "Robert Palmer",
      tracks: [ ]
    },
    5439: {
      album: "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function update(id, prop, value) {
  if ((value !== "") && prop !== "tracks") {
    collection[id][prop] = value;
  } else if ((prop !== "tracks") && (value !== "")) {
    collection[id]["tracks"].push(value) ;
  } else if (value === "") {
    delete collection[id][prop] ;
  }

  return collection;
}

// Alter values below to test your code
update(5439, "artist", "ABBA");
my entire code
Blauelf
@Blauelf
Feb 18 2016 08:18
You have prop !== "tracks" twice (second should be prop === "tracks")
prakash
@srividhyaprakash
Feb 18 2016 08:19
Oh , thanks a lot
bitgrower
@bitgrower
Feb 18 2016 08:19
cool, @JoshFisk ... also check out the arguments object MDN page ...
prakash
@srividhyaprakash
Feb 18 2016 08:19
got it :)
thanks @Blauelf
CamperBot
@camperbot
Feb 18 2016 08:19
srividhyaprakash sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:warning: srividhyaprakash already gave blauelf points
Josh Fisk
@JoshFisk
Feb 18 2016 08:22
I forgot one more trick you can do
for(var i in arr){
    // do something with arr[i]
}
Blauelf
@Blauelf
Feb 18 2016 08:24
@JoshFisk Don't do that with arrays.
Josh Fisk
@JoshFisk
Feb 18 2016 08:24
@Blauelf But it works...
Elior Boukhobza
@mallowigi
Feb 18 2016 08:25
I agree. Don't do that
zhouxh
@zhouxh
Feb 18 2016 08:26
why ? it's not very well?
Blauelf
@Blauelf
Feb 18 2016 08:27
@JoshFisk It kind of does, but in takes all enumerable properties of an object, inherited or not, and is probably slower than regular array by number access.
Josh Fisk
@JoshFisk
Feb 18 2016 08:27
Well
From what I can read...
Elior Boukhobza
@mallowigi
Feb 18 2016 08:27
it's not slower, but yes it takes all enumerable properties
Josh Fisk
@JoshFisk
Feb 18 2016 08:27
The main issue is, that it might not iterate the array in order
I'm not sure
It runs fine on my browser, no matter what I throw at it
Blauelf
@Blauelf
Feb 18 2016 08:30
For me, the main issue was that I enhanced Array.prototype with some nice function, and this would show up in for-in, as I accidentally created it enumerable.
Josh Fisk
@JoshFisk
Feb 18 2016 08:30
I see
Okay so if you have something like jQuery included
it might add things to array
And then that will get pulled into your loop
Elior Boukhobza
@mallowigi
Feb 18 2016 08:31
var a = [0, 1];
a.foo = 'bar';

for (var i in arr) {
  console.log(a[i])
}
this will print "0, 1, bar"
if your use for (var i of arr) of ES6 syntax, then it's okay
Blauelf
@Blauelf
Feb 18 2016 08:32
When adding some function, you can make it non-enumerable (using defineProperty), but I did not know at that time.
Josh Fisk
@JoshFisk
Feb 18 2016 08:33
I think this is the main issue
var arr = [];
arr[5]=1;
for(var i in arr){
  console.log(arr[i]);
}
With a normal loop, that runs 5 times, with the for in, that runs 1 time
JackeL
@jackel27
Feb 18 2016 08:33
@Blauelf !!!
Blauelf
@Blauelf
Feb 18 2016 08:34
It was the main issue for me. I think at some point even the "length" attribute showed up.
JackeL
@jackel27
Feb 18 2016 08:34
@Blauelf ok. I got to the hardest part
Abhishek Kumar
@abhishekKumar1
Feb 18 2016 08:35
@Blauelf can you look at this and tell me what is wrong in this code problem: no repeats please
function permAlone(str) {
  var arr=str.split("");
  var arr1=[];
  //var arr2=[];
  var length=str.length;
  var count=0;
  //arr.sort();
  function spl(arr1, arr, length,count)
  {
    //var arr2=[];
    for(i=0;i<arr.length;i++)
      {
        var flag=0;
        arr1.push(arr[i]);
        if(arr1.length<length)
          {

            arr.splice(i,1);
            //console.log(arr1);
            count+=spl(arr1,arr,length,count);            
          }
        else
        {
          for(i=0;i<length-1;i++)
          {

            if(arr1[i]==arr1[i+1])
            {
              flag=1;
              break;
            }
          }
          if(flag===0)
            count++;
        }

        //return count;
      }
    return count;
  }
  var ans =spl(arr1, arr,length,count);
  //console.log(arr);
  return ans;

}

permAlone('abccd');
Blauelf
@Blauelf
Feb 18 2016 08:35
@JoshFisk That's true, but I have switched from in-keyword to Object.keys() in most cases, at least where I am sure not to need inherited properties.
Josh Fisk
@JoshFisk
Feb 18 2016 08:35
@Blauelf Does using keys on an array work?
@Blauelf I checked, it does.
Blauelf
@Blauelf
Feb 18 2016 08:37
@JoshFisk It will still find any properties you attached, numeric or not. But that's what I used for sparse arrays. After my experience with a somewhat failed prototype enhancement :P
Elior Boukhobza
@mallowigi
Feb 18 2016 08:37
wow too much loops :x:
bonfire no repeats please
CamperBot
@camperbot
Feb 18 2016 08:38

:fire:Bonfire: No repeats please :link:

function permAlone(str) {
  return str;
}

permAlone('aab');

Return the number of total permutations of the provided string that don't have repeated consecutive letters.

more info:  bf details | bf links | hint

Josh Fisk
@JoshFisk
Feb 18 2016 08:38
@Blauelf Yeah, but I feel that is preferable in some situations. Like when you want to just jump to the indexes with values, instead of incrementing through the empty ones.
Elior Boukhobza
@mallowigi
Feb 18 2016 08:38
bf details
CamperBot
@camperbot
Feb 18 2016 08:38

:fire:Bonfire: No repeats please :link:

function permAlone(str) {
  return str;
}

permAlone('aab');
Return the number of total permutations of the provided string that don't have repeated consecutive letters.
For example, 'aab' should return 2 because it has 6 total permutations, but only 2 of them don't have the same letter (in this case 'a') repeating.
Remember to use <a href='//github.com/FreeCodeCamp/freecodecamp/wiki/How-to-get-help-when-you-get-stuck' target='_blank'>RSAP</a> if you get stuck. Try to pair program. Write your own code.
links:
zhouxh
@zhouxh
Feb 18 2016 08:44
function NumAscSort(a,b)
{
    return a-b;
}
function where(arr, num) {
  // Find my place in this sorted array.
  arr.sort(NumAscSort);
  var nnum=0;
  for(var i=0;i<arr.length;i++){
    if(arr[i]<num){
       nnum=i+1;
    }else{
      break;
    }
  }
  return nnum;
}

where([40, 60], 50);
this is for " where do i belong?"
is it suitable?
Elior Boukhobza
@mallowigi
Feb 18 2016 08:48
bf where do i belong
CamperBot
@camperbot
Feb 18 2016 08:48

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

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

where([40, 60], 50);

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

more info:  bf details | bf links | hint

Unproductive Admirer
@WinterMuting
Feb 18 2016 08:50
@theberbie - respect!
@ theberbie I mean this:
Hi all! Out of curiosity, do you ever google things for bonfires or try to figure it out by yourself? I'm at the 5th one and haven't used the mighty google yet but it takes me a few hours to figure it out" I googled 5 or 6 , and then some more
Elior Boukhobza
@mallowigi
Feb 18 2016 08:58
function where(arr, num){
  return arr.reduce(function(lowestIndex, item, i) {
    return num > item ? i : lowestIndex
  }, -1)
}
Yuvraj Adagale
@Yuvraj1989
Feb 18 2016 09:03
in (/[\W]/g,"") what [\W] means
Elior Boukhobza
@mallowigi
Feb 18 2016 09:10
not a alphanumeric character
zhouxh
@zhouxh
Feb 18 2016 09:10
thanks @mallowigi
CamperBot
@camperbot
Feb 18 2016 09:10
zhouxh sends brownie points to @mallowigi :sparkles: :thumbsup: :sparkles:
:star: 59 | @mallowigi | http://www.freecodecamp.com/mallowigi
Markus Kiili
@Masd925
Feb 18 2016 09:13
@mallowigi Works like this:
function where(arr, num) {
  return arr.reduce(function(prev, curr){
    return curr<num ? prev+1 : prev;
  },0); 
}
Stanislav
@narujkee
Feb 18 2016 09:15

Hello guys. I got stuck on "Accessing Nested Arrays in JSON". somebody can explain me where an error in my code?
/// 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

zhouxh
@zhouxh
Feb 18 2016 09:16
function rot13(str) { // LBH QVQ VG!

  var arr = new Array(0);
  for(var i=0;i<str.length;i++){
    var code= str.charCodeAt(i);
    if(code<"N".charCodeAt(0)&&code>="A".charCodeAt(0)){
       arr.push(code+13);
    }else if (code<="Z".charCodeAt(0)&&code>="N".charCodeAt(0)){
       arr.push(code-13);
    }
    else 
      arr.push(code);

  }
  var newArr = arr.map(function(val){
    var str ="";
    return  String.fromCharCode(val);
  });
  return newArr.join("");
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
this is for "Caesars Cipher" . is it suitable?
Vantrav
@vantrav
Feb 18 2016 09:18
@Yuvraj1989 see https://regex101.com/
Clara-y
@Clara-y
Feb 18 2016 09:19
@narujkee last line,you must be remove outside[],like this"var gloveBoxContents = myStorage.car.inside["glove box"];"
Stanislav
@narujkee
Feb 18 2016 09:21
@Clara-y omg... Thank you!
CamperBot
@camperbot
Feb 18 2016 09:21
narujkee sends brownie points to @clara-y :sparkles: :thumbsup: :sparkles:
:star: 223 | @clara-y | http://www.freecodecamp.com/clara-y
prakash
@srividhyaprakash
Feb 18 2016 09:22

```//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 lookUp(firstName, prop){
for (var i= 0; i < contacts.length ; i++) {
if ( contacts[i].firstName === firstName && contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
}
else if (contacts[i].firstName !== firstName) {
return "No such name";
}
else if (contacts[i].hasOwnproperty(prop) === false) {
return "No such Property";
}

}
// Only change code below this line

// Only change code above this line
}

// Change these values to test your function
lookUp("Kristian", "likes");

//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 lookUp(firstName, prop){
  for (var i= 0; i < contacts.length ; i++) {
    if ( contacts[i].firstName === firstName && contacts[i].hasOwnProperty(prop)) { 
      return contacts[i][prop];
    }
      else if (contacts[i].firstName !== firstName) {
        return "No such name";
      }
     else if (contacts[i].hasOwnproperty(prop) === false) {
      return "No such Property";
    }

  }
// Only change code below this line

// Only change code above this line
}

// Change these values to test your function
lookUp("Kristian", "likes");
guys why does this code show No such name as the o/p
?
Could someone help?
zhouxh
@zhouxh
Feb 18 2016 09:24
you should iterate all elements ,not just one
Abhishek Kumar
@abhishekKumar1
Feb 18 2016 09:24
@srividhyaprakash think about iteration1 in our loop if it didn't find the firstname in loop what it will do???
Clara-y
@Clara-y
Feb 18 2016 09:24
@narujkee you're welocome(_)
prakash
@srividhyaprakash
Feb 18 2016 09:24
it will go to i = 1?
i have a for loop for that
@zhouxh @abhishekKumar1
Clara-y
@Clara-y
Feb 18 2016 09:26
This message was deleted
Rune Bak Jacobsen
@runebakjacobsen
Feb 18 2016 09:26
This message was deleted
This message was deleted
Abhishek Kumar
@abhishekKumar1
Feb 18 2016 09:27
yeah say firstname="Kristian" then it will check contacts0.firstname=="Kristian" which is not its "Akira" so if will fail but else if will pass and it will return "No such name"
Codemzy
@codemzy
Feb 18 2016 09:28
@srividhyaprakash you are returning your else within the for loop, so it will return "No such name"; if the name doesn't match with the first item... your else needs to return after the for loop so it has chance to loop all the way through
zhouxh
@zhouxh
Feb 18 2016 09:28
This message was deleted
This message was deleted
prakash
@srividhyaprakash
Feb 18 2016 09:29
oh thanks @ zhouxh
@zhouxh
thanks @codemzy @zhouxh @abhishekKumar1
CamperBot
@camperbot
Feb 18 2016 09:30
srividhyaprakash sends brownie points to @codemzy and @zhouxh and @abhishekkumar1 :sparkles: :thumbsup: :sparkles:
:star: 618 | @codemzy | http://www.freecodecamp.com/codemzy
:star: 347 | @abhishekkumar1 | http://www.freecodecamp.com/abhishekkumar1
:star: 263 | @zhouxh | http://www.freecodecamp.com/zhouxh
Yuvraj Adagale
@Yuvraj1989
Feb 18 2016 09:41
thanks @vantrav
CamperBot
@camperbot
Feb 18 2016 09:41
yuvraj1989 sends brownie points to @vantrav :sparkles: :thumbsup: :sparkles:
:star: 243 | @vantrav | http://www.freecodecamp.com/vantrav
Eldho.S.Paul
@Eldhosajipaul
Feb 18 2016 10:16
Constructing Strings with Variables - Use two + operators to build myStr with myName inside it
can any one help me..
LL
@LL-Zhao
Feb 18 2016 10:22

function largestOfFour(arr) {
// You can do this!
var newArr=arr.map(function(item){
var newItem=item.reduce(function(a,b){
if(a>b)
return a;
else
return b;
});
return newItem;
});
return newArr;
}

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

John Deegan
@JohnDeegs
Feb 18 2016 10:26

Hey all, I'm stuck here http://www.freecodecamp.com/challenges/find-the-longest-word-in-a-string and I think I'm somewhat close. I'm trying to find the biggest word in a string.

function findLongestWord(str) {
  str.split(" ");
 var biggestString = "0";
  for (var i = 0; i < str.length; i++){
    if (str[i].length > biggestString){
      biggestString = str[i].length;
    }
  }

  return biggestString.length;
}

findLongestWord("The quick brown fox jumped over the lazy dog");

This is what I understand that I'm doing,

1 - Splitting the string into an array of elements
2 - Creating a variable biggestString which will hold the current biggest string that the loop finds at i
3 - Declaring a for loop to loop through each element in my array
4 - If the element at i that the loop finds is bigger than the current biggestString, it becomes the biggestString variable.
5 - Returning the length of the biggestString, completing the challenge.

However it just seems to be returning errors, can anyone help? :)

Markus Kiili
@Masd925
Feb 18 2016 10:31
@JohnDeegs str.split(" "); returns an array but you are not storing it to a variable.
Also, use 0 and not "0".
And return biggestString
Mauli Pandey
@pandeymauli
Feb 18 2016 10:36
hello! i am having trouble with this challenge - http://www.freecodecamp.com/challenges/golf-code
i am unable to figure out what's wrong
the code satisfies the tests
Sidharth Kriplani
@sidkrip
Feb 18 2016 10:39
code?
Mauli Pandey
@pandeymauli
Feb 18 2016 10:39
do i just copy paste it?
Sidharth Kriplani
@sidkrip
Feb 18 2016 10:39
help code format
CamperBot
@camperbot
Feb 18 2016 10:39

:point_right: code formatting [wiki]

Inline code

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

Code Block

```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 ⏎]

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

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

Sidharth Kriplani
@sidkrip
Feb 18 2016 10:40
that's how you post your code here @pandeymauli
Mauli Pandey
@pandeymauli
Feb 18 2016 10:41
backsticks?
as in backslashes?
'code'
nope.. the single quotes don't work
i think i got it
mnedzka
@mnedzka
Feb 18 2016 10:42
Hey guys!
Anyone know where I can find tutorial to create simple fight game(war card game) in Javascript/Jquery?
Mauli Pandey
@pandeymauli
Feb 18 2016 10:42

```function golfScore(par, strokes) {
// Only change code below this line
if(strokes === 1){
return "Hole-in-one!";
}
else if(strokes <= par-2){
return "Eagle";
}
else if(strokes === par-1){
return "Birdie";
}
else if(strokes === par){
return "Par";
}
else if(strokes === par+1){
return "Bogey";
}
else if(strokes === par+2){
return "Double Bogey";
}
else{
return "Go Home";
}
// Only change code above this line
}

// Change these values to test
golfScore(5, 9);

Sidharth Kriplani
@sidkrip
Feb 18 2016 10:42
the key which is on the left of "1". Press shift along with it.
Mauli Pandey
@pandeymauli
Feb 18 2016 10:42
nope! didn't work
~code power~
nah!
code
Sidharth Kriplani
@sidkrip
Feb 18 2016 10:42
you forgot to type "js" after the backticks
J Player
@Heyjp
Feb 18 2016 10:42
yoou got it
Sidharth Kriplani
@sidkrip
Feb 18 2016 10:43
function golfScore(par, strokes) {
// Only change code below this line
if(strokes === 1){
return "Hole-in-one!";
}
else if(strokes <= par-2){
return "Eagle";
}
else if(strokes === par-1){
return "Birdie";
}
else if(strokes === par){
return "Par";
}
else if(strokes === par+1){
return "Bogey";
}
else if(strokes === par+2){
return "Double Bogey";
}
else{
return "Go Home";
}
// Only change code above this line
}

// Change these values to test
golfScore(5, 9);
```
Mauli Pandey
@pandeymauli
Feb 18 2016 10:43

```js function golfScore(par, strokes) {
// Only change code below this line
if(strokes === 1){
return "Hole-in-one!";
}
else if(strokes <= par-2){
return "Eagle";
}
else if(strokes === par-1){
return "Birdie";
}
else if(strokes === par){
return "Par";
}
else if(strokes === par+1){
return "Bogey";
}
else if(strokes === par+2){
return "Double Bogey";
}
else{
return "Go Home";
}
// Only change code above this line
}

// Change these values to test
golfScore(5, 9);

dammit!
is it ` or ~?
Sidharth Kriplani
@sidkrip
Feb 18 2016 10:43
you forgot the three backticks after the code this time
this one `
Mauli Pandey
@pandeymauli
Feb 18 2016 10:43
alright

```js function golfScore(par, strokes) {
// Only change code below this line
if(strokes === 1){
return "Hole-in-one!";
}
else if(strokes <= par-2){
return "Eagle";
}
else if(strokes === par-1){
return "Birdie";
}
else if(strokes === par){
return "Par";
}
else if(strokes === par+1){
return "Bogey";
}
else if(strokes === par+2){
return "Double Bogey";
}
else{
return "Go Home";
}
// Only change code above this line
}

// Change these values to test
golfScore(5, 9);
```

nop!
what am i doing wrong?
code
the inline code works fine
function golfScore(par, strokes) {
  // Only change code below this line
  if(strokes === 1){
    return "Hole-in-one!";
  }
  else if(strokes <= par-2){
    return "Eagle";
  }
  else if(strokes === par-1){
    return "Birdie";
  }
  else if(strokes === par){
    return "Par";
  }
  else if(strokes === par+1){
    return "Bogey";
  }
  else if(strokes === par+2){
    return "Double Bogey";
  }
  else{
    return "Go Home";
  }
    // Only change code above this line
}

// Change these values to test
golfScore(5, 9);
finally!
yay!
Sidharth Kriplani
@sidkrip
Feb 18 2016 10:45
awesome. just a second
Eldho.S.Paul
@Eldhosajipaul
Feb 18 2016 10:47
Set myName to a string equal to your name and build myStr with myName between the strings "My name is " and " and I am swell!"
how to do it... can anyone help me...
Sidharth Kriplani
@sidkrip
Feb 18 2016 10:48
@pandeymauli your code is correct. The "Go Home" string is without an exclamation. It should be "Go Home!" :smile:
Mauli Pandey
@pandeymauli
Feb 18 2016 10:49
ah!
thanks @sidkrip
CamperBot
@camperbot
Feb 18 2016 10:49
pandeymauli sends brownie points to @sidkrip :sparkles: :thumbsup: :sparkles:
:star: 282 | @sidkrip | http://www.freecodecamp.com/sidkrip
Sidharth Kriplani
@sidkrip
Feb 18 2016 10:49
@Eldhosajipaul problem link and your code?
Sidharth Kriplani
@sidkrip
Feb 18 2016 10:50
and your code?
Eldho.S.Paul
@Eldhosajipaul
Feb 18 2016 10:51

// Example
var ourName = "Free Code Camp";
var ourStr = "Hello, our name is " + ourName + ", how are you?";

// Only change code below this line
var myName = "My name is " + myStr + " and I am swell!";
var myStr = "myName";

Sidharth Kriplani
@sidkrip
Feb 18 2016 10:51
// Example
var ourName = "Free Code Camp";
var ourStr = "Hello, our name is " + ourName + ", how are you?";

// Only change code below this line
var myName = "My name is " + myStr + " and I am swell!";
var myStr = "myName";
you have to set myName to a string equal to your name.
and then build myStr with myName between the strings "My name is " and " and I am swell!"
@Eldhosajipaul
Eldho.S.Paul
@Eldhosajipaul
Feb 18 2016 10:57
@sidkrip its still not working..
Moisés Man
@moigithub
Feb 18 2016 10:58
order matters...
whats the value of myStr..when it reach this line
var myName = "My name is " + myStr + " and I am swell!";
Sidharth Kriplani
@sidkrip
Feb 18 2016 10:59
@Eldhosajipaul
set myName to your name (say "ABC")
and then build myStr using the concatenation operator
("My name is "+myName+" and I am swell!";)
Eldho.S.Paul
@Eldhosajipaul
Feb 18 2016 11:02
thank you @sidkrip @moigithub .. it worked..
CamperBot
@camperbot
Feb 18 2016 11:02
eldhosajipaul sends brownie points to @sidkrip and @moigithub :sparkles: :thumbsup: :sparkles:
:star: 283 | @sidkrip | http://www.freecodecamp.com/sidkrip
:star: 638 | @moigithub | http://www.freecodecamp.com/moigithub
John Deegan
@JohnDeegs
Feb 18 2016 11:08
@Masd925 Is it not already declared as "str"? already as that's the name of the string?
Oliver Lim
@sirpompous
Feb 18 2016 11:08

@TrollCop604
Hi, im sorry but i don't understand what im doing wrong, can anyone help me? It's the missing letters challenge
function fearNotLetter(str) {
var endnum = str.length - 1;
var fstnum = str.charCodeAt(0);
var lstnum = str.charCodeAt(endnum);
var tempnum;
for(var a = 0; a <= endnum; a++) {
if(fstnum + a !== str.charCodeAt(a)) {
tempnum = fstnum + a;
}
}
if(tempnum === undefined) {
return undefined;
}
else {
return String.fromCharCode(tempnum);
}
}

fearNotLetter("abce");

Sidharth Kriplani
@sidkrip
Feb 18 2016 11:08
@TrollCop604 link ?
Oliver Lim
@sirpompous
Feb 18 2016 11:09
@sidkrip what do you mean?
Sidharth Kriplani
@sidkrip
Feb 18 2016 11:09
function fearNotLetter(str) {
var endnum = str.length - 1;
var fstnum = str.charCodeAt(0);
var lstnum = str.charCodeAt(endnum);
var tempnum;
for(var a = 0; a <= endnum; a++) {
if(fstnum + a !== str.charCodeAt(a)) {
tempnum = fstnum + a;
}
}
if(tempnum === undefined) {
return undefined;
}
else {
return String.fromCharCode(tempnum);
}
}

fearNotLetter("abce");
link to the challenge @TrollCop604
Sidharth Kriplani
@sidkrip
Feb 18 2016 11:10
oh its on the intermediate level. Cant help with it. Doing the same one
Oliver Lim
@sirpompous
Feb 18 2016 11:11
@sidkrip ah ok...
Sidharth Kriplani
@sidkrip
Feb 18 2016 11:12
oh have you doen the Roman Numeral one?
Oliver Lim
@sirpompous
Feb 18 2016 11:13
i haven't yet but it seems pretty easy enough
Sidharth Kriplani
@sidkrip
Feb 18 2016 11:14
try it out? Pair Programming?
Oliver Lim
@sirpompous
Feb 18 2016 11:14
@sidkrip sure, i'll give it a go
Sidharth Kriplani
@sidkrip
Feb 18 2016 11:14
I will look into this ^ challenge meanwhile
Markus Kiili
@Masd925
Feb 18 2016 11:19
@JohnDeegs You could use the same variable with str = str.split(" "); , but it is better to use more describing variable name like var words = str.split(" ");
Clyde
@hea-hea
Feb 18 2016 11:31
help seek and destroy
CamperBot
@camperbot
Feb 18 2016 11:31

: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

Mafalda
@otmeek
Feb 18 2016 11:31
@TrollCop604 you need to return within the if statement
and you dont need to return undefined, it automatically does if the condition doesnt execute
function fearNotLetter(str) {
  var endnum = str.length - 1;
  var fstnum = str.charCodeAt(0);
  var lstnum = str.charCodeAt(endnum);
  var tempnum;
  for(var a = 0; a <= endnum; a++) {
    if(fstnum + a !== str.charCodeAt(a)) {
      tempnum = fstnum + a;
      return String.fromCharCode(tempnum);
    }
  }


}
like this
Oliver Lim
@sirpompous
Feb 18 2016 11:33
@otmeek wow, thanks man. I really appreciate your help
Mafalda
@otmeek
Feb 18 2016 11:33
@TrollCop604 np
Oliver Lim
@sirpompous
Feb 18 2016 11:59
Does anyone have a clue why this might not work?

function convert(num) {
var arr = [];
var temparr = [];
for(var a = 0; a < num; a++) {
arr.push("I");
}
while(num >= 1000) {
for(var b = 0; b <= 999; b++) {
arr.pop();
}
arr.unshift("M");
num -= 1000;
}
while(num >= 500) {
for(var c = 0; c <= 499; c++) {
if(arr[c] == "M") {
continue;
}
else {
arr.pop();
}
arr.push("D");
}
}
while(num >= 100) {
for(var d = 0; d <= 499; d++) {
if(arr[d] == "M") {
continue;
}
else if(arr[d] == "D") {
continue;
}
else {
arr.pop();
}
arr.push("D");
}
}
while(num >= 50) {
for(var e = 0; e <= 499; e++) {
if(arr[e] == "M") {
continue;
}
else if(arr[e] == "D") {
continue;
}
else {
arr.pop();
}
arr.push("D");
}
}
while(num >= 10) {
for(var f = 0; f <= 499; f++) {
if(arr[f] == "M") {
continue;
}
else if(arr[f] == "D") {
continue;
}
else {
arr.pop();
}
arr.push("D");
}
}
return arr;
}

convert(1501);

Moisés Man
@moigithub
Feb 18 2016 12:09
wiki format
CamperBot
@camperbot
Feb 18 2016 12:09

:point_right: code formatting [wiki]

Inline code

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

Code Block

```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 ⏎]

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

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

Moisés Man
@moigithub
Feb 18 2016 12:15
@TrollCop604 can u explain what that code does ?

@TrollCop604 this part

function convert(num) {
var arr = [];
var temparr = [];
for(var a = 0; a < num; a++) {
arr.push("I");
}

lets say num= 1000

arr.push("I") num(1000) times.. so arr will have 1000 "I"'s now...
This message was deleted
This message was deleted
Moisés Man
@moigithub
Feb 18 2016 12:22
This message was deleted
Nick Robson
@nickrobson
Feb 18 2016 12:25
@TrollCop604 Here's my solution that works: https://gist.github.com/nickrobson/4ca440b041775395f864
Have a look at it, then tell me what you don't understand.
@moigithub You can't use number values, as roman numerals use digits, not values.
Nick Robson
@nickrobson
Feb 18 2016 12:30
e.g. 99 is XCIX, and not IC
JackeL
@jackel27
Feb 18 2016 12:34
assignment to read-only properties is not allowed in strict mode
Moisés Man
@moigithub
Feb 18 2016 12:34
@TrollCop604 probably u should start with the BIGGEST num first... instead of pushing I's

@TrollCop604
start with something similar to this

while(num >= 1000) {
for(var b = 0; b <= 999; b++) {
arr.pop();
}
arr.unshift("M");
num -= 1000;
}

like

while(num >= 1000) {
arr.push("M");
num -= 1000;
}
JackeL
@jackel27
Feb 18 2016 12:41
Anyone know why I get the above error?
Moisés Man
@moigithub
Feb 18 2016 12:43
cant without see the code... not good at guessing :P
@jackel27
JackeL
@jackel27
Feb 18 2016 12:43
long code
lol
okay
Tridev
@TridevGuha
Feb 18 2016 12:43
hi I want to print 7 variables in javascript output as a list on clicking a button. How to do this? thanks :)
JackeL
@jackel27
Feb 18 2016 12:44
@moigithub
function drawer(price, cash, cid) {
    var n;
    var sumCID = 0;
    var change = cash - price;
    change = change.toFixed(2);
    var correctChange = [];
    // Here is your change, ma'am.
    var penny = 0.01;
    var nickel = 0.05;
    var dime = 0.10;
    var quarter = 0.250;
    var oneDollar = 1.00;
    var fiveDollar = 5.00;
    var tenDollar = 10.00;
    var twentyDollar = 20.00;
    var hundredDollar = 100.00;
    var changeDue = cash - price;
    cid.reverse();

    function appendAmt() {
        for (x = 0; x < cid.length; x++) {
            switch (cid[x][0]) {
                case "PENNY":
                    cid[[x][0]].push(cid[x][1].toFixed(2) / penny,
                        penny);
                    break;
                case "NICKEL":
                    cid[[x][0]].push(cid[x][1].toFixed(2) / nickel,
                        nickel);
                    break;
                case "DIME":
                    cid[[x][0]].push(cid[x][1].toFixed(2) / dime, dime);
                    break;
                case "QUARTER":
                    cid[[x][0]].push(cid[x][1].toFixed(2) / quarter,
                        quarter);
                    break;
                case "ONE":
                    cid[[x][0]].push(cid[x][1].toFixed(2) / oneDollar,
                        oneDollar);
                    break;
                case "FIVE":
                    cid[[x][0]].push(cid[x][1].toFixed(2) / fiveDollar,
                        fiveDollar);
                    break;
                case "TEN":
                    cid[[x][0]].push(cid[x][1].toFixed(2) / tenDollar,
                        tenDollar);
                    break;
                case "TWENTY":
                    cid[[x][0]].push(cid[x][1].toFixed(2) /
                        twentyDollar, twentyDollar);
                    break;
                case "ONE HUNDRED":
                    cid[[x][0]].push(cid[x][1] / hundredDollar,
                        hundredDollar);
                    break;
            }
        }
    }
    appendAmt();


   sumCID = sumCID.toFixed(2);
    // function for returning bool if string found in 2d array.
       function findit(array, value) {
        var arr = array.find(function(arg1) {
            return !!~arg1.indexOf(value);
        });
        return !!(arr);
    }



    // name | totalAMT | QTY | perAMT   -< For reference of array
    // Updating CID with payment recieved... assuming the payment recieved.
    for (var x = 0; x < cid.length; x++) {
        while (cash >= cid[x][3] && cash !== 0) {
            cid[x][2] += 1;
            cid[x][1] += cid[x][3];
            cash -= cid[x][3];
        } // CID UPDATED WITH PAYMENT AMT!!!
        // update sum of CID 
        sumCID += cid[x][1];
    }



    // Give back exact change.
    // name [x][0] | totalAMT[x][1] | QTY[x][2] | perAMT[x][3]   -< For reference of array

    for (var a = 0; a < cid.length; a++) {
        while (change >= cid[a][3] && cid[a][2] > 0 && change !== 0) {
            if (findit(correctChange, (cid[a][0]))) {
                correctChange[correctChange.indexOf(cid[a][0])][1] += 1;
                change -= cid[a][3];
                change = change.toFixed(2);
            } else {
                correctChange.push(cid[a][0], cid[a][2]);
                change -= cid[a][3];
                change = change.toFixed(2);
            }
            cid[a][2] -= 1;
            cid[a][1] -= cid[a][3];
        }
    }
}
drawer(19.50, 20.00, [
    ["PENNY", 0.12],
    ["NICKEL", 0.50],
    ["DIME", 0.50],
    ["QUARTER", 0.50],
    ["ONE", 1.00],
    ["FIVE", 0],
    ["TEN", 0],
    ["TWENTY", 0],
    ["ONE HUNDRED", 0]
]);
Tridev
@TridevGuha
Feb 18 2016 12:44
as html output*
Nick Robson
@nickrobson
Feb 18 2016 12:45
@TridevGuha You can use: document.write('html here') OR $('<li>').appendTo('#list-tag')
Tridev
@TridevGuha
Feb 18 2016 12:45
hi I want to print 7 javascript variables as html output as a list calling the function,on clicking a button. How to do this? thanks :)
so can i write like this?
Nick Robson
@nickrobson
Feb 18 2016 12:46
the second method needs jQuery, though.
Alessandro Giordo
@bovas85
Feb 18 2016 12:47
palyndrome test [.,\s] this should replace only punctuation and spacing but removes my \ from the last test
Tridev
@TridevGuha
Feb 18 2016 12:47
is this valid? document.write(userfirstname, lastname, useremail,usergender,userbirthday,hometown);
within bracket those are variables
Alessandro Giordo
@bovas85
Feb 18 2016 12:48
add some spacing to the last ones
Nick Robson
@nickrobson
Feb 18 2016 12:48
@TridevGuha No. The method accepts a string.
JackeL
@jackel27
Feb 18 2016 12:48
@moigithub hope that helps.. I'll be back in 10 or so minutes..
Tridev
@TridevGuha
Feb 18 2016 12:50
@nickrobson can you please explain?
okay I google on it
Sebastian
@sebous
Feb 18 2016 12:56
Hello, does anyone know why is codepen.io rewriting my code when I'm trying to add some code into existing row or tag?
Nick Robson
@nickrobson
Feb 18 2016 13:00
@TridevGuha It's document.write("string")
No other arguments.
However, that adds to the end.
Tridev
@TridevGuha
Feb 18 2016 13:01
ah ok,
but how to print variable instead of string in html?
@nickrobson
Markus Kiili
@Masd925
Feb 18 2016 13:01
@jackel27 There might be some problems with types in your code. change = change.toFixed(2); means that change is a string.
Alessandro Giordo
@bovas85
Feb 18 2016 13:03
There's a bug with the console it will find some regex invalid
Nick Robson
@nickrobson
Feb 18 2016 13:09
@TridevGuha If you don't know how to use a variable as a string, I suggest you look into JavaScript and HTML more before asking for help.
Tridev
@TridevGuha
Feb 18 2016 13:12
ok
thanks
sigursiguros
@sigursiguros
Feb 18 2016 13:16
function convert(str) {
    str.replace(/&/g, "&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apols;");
  // &colon;&rpar;
  return str;
}

convert("Dolce & Gabbana");
HI guys, is there anything wrong with my code?
Nick Robson
@nickrobson
Feb 18 2016 13:28
@sigursiguros string#replace returns a new string -- it doesn't modify the current one.
So you need to use str = ...
or of course, just use return ...
Markus Kiili
@Masd925
Feb 18 2016 13:29
@sigursiguros Strings are immutable, so there are no methods that mutate a string. They always return a new string.
Soumitra Varindra Chakravarti
@soumitrachakravarti
Feb 18 2016 13:31
@pabowles It can be easier to just use hasOwnProperty
for (i = 0; i < contacts.length; i++) {
  if(contacts[i].firstName === firstName) {
      if(contacts[i].hasOwnProperty(prop)) {
        return contacts[i][prop];
      } else {
        return "No such property";
      }
    }
  } 
    return "No such contact";
CatNipples98
@CatNipples98
Feb 18 2016 13:35
can somene help me with ++ and --? I really need some understanding and to get it right
rphares
@rphares
Feb 18 2016 13:36
@CatNipples98 , in general, or do you have a specific q..?
CatNipples98
@CatNipples98
Feb 18 2016 13:36
in general please
sigursiguros
@sigursiguros
Feb 18 2016 13:36
thanks @nickrobson @Masd925
CamperBot
@camperbot
Feb 18 2016 13:36
sigursiguros sends brownie points to @nickrobson and @masd925 :sparkles: :thumbsup: :sparkles:
:star: 994 | @masd925 | http://www.freecodecamp.com/masd925
:star: 391 | @nickrobson | http://www.freecodecamp.com/nickrobson
Tridev
@TridevGuha
Feb 18 2016 13:36
++ means +1
and -- means -1
addition with 1 and subtraction with 1
Vantrav
@vantrav
Feb 18 2016 13:37
This message was deleted
sigursiguros
@sigursiguros
Feb 18 2016 13:39
Hi campers, may I know how does the brownie points system work? Or what is it?
rphares
@rphares
Feb 18 2016 13:40
explain brownie
CamperBot
@camperbot
Feb 18 2016 13:40

:point_right: brownie points [wiki]

The number beside your picture on Free Code Camp tells you how many Brownie Points you have.

A user profile picture next to a with Brownie Points score

There are three ways you can get Brownie Points:

  1. Complete challenges - you get one point per challenge you complete
  2. Post relevant links on Camper News - you get 1 point for posting a link, and another point for each upvote your link gets
  3. Help other campers in chat - each time you help another camper and they thank you (by typing "thanks @yourname"), you will get a point

Brownie Points help you look like the kind of person who codes a lot, shares relevant links, and helps people.

They also add to your Streak.
:pencil: read more about brownie points on the FCC Wiki

rphares
@rphares
Feb 18 2016 13:40
@sigursiguros :point_up:
sigursiguros
@sigursiguros
Feb 18 2016 13:40
wow....that's amazing. thanks @rphares
CamperBot
@camperbot
Feb 18 2016 13:40
sigursiguros sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2848 | @rphares | http://www.freecodecamp.com/rphares
sigursiguros
@sigursiguros
Feb 18 2016 13:42
There were a couple of occasions where my FCC crashed
probably due to infinite loops that I did
I tried quitting browser, clearing cookies/history, re logging it, but still not able to re access the challenge.
Is there a way to fix this?
srinivas
@srinivasdasu
Feb 18 2016 13:43
Help on inventory update
```
CamperBot
@camperbot
Feb 18 2016 13:43
no wiki entry for: on inventory update
rphares
@rphares
Feb 18 2016 13:44
explain auto
CamperBot
@camperbot
Feb 18 2016 13:44

: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

rphares
@rphares
Feb 18 2016 13:44
@sigursiguros , if you have a loop, try the above,
there is another way,
but it will clear your code, so disable auto run is the first choice when possible :blush:
srinivas
@srinivasdasu
Feb 18 2016 13:45
function inventory(arr1, arr2) {
    // All inventory must be accounted for or you're fired!
  arr2=arr2.sort(function(a,b) {
 return a[1] > b[1];
 });
 if (arr1.length===0)
   {
     return arr2;
   }
  else if(arr2.length===0)
    {
      return arr1;
    }
  else
    {
      for(var i=0;i<arr1.length;i++)
        {
          if((arr1[i][1]===arr2[i][1]))
           {
                 arr1[i][0]=arr2[i][0];
           }
           else
           {
              arr1.push(arr2[i]);
           }
        }
    }
    return arr1;
}

// Example inventory lists
var curInv = [
    [21, "Bowling Ball"],
    [2, "Dirty Sock"],
    [1, "Hair Pin"],
    [5, "Microphone"]
];

var newInv = [
    [2, "Hair Pin"],
    [3, "Half-Eaten Apple"],
    [67, "Bowling Ball"],
    [7, "Toothpaste"]
];

inventory(curInv, newInv);
sigursiguros
@sigursiguros
Feb 18 2016 13:45
wow, very helpful. Thank you @rphares
CamperBot
@camperbot
Feb 18 2016 13:45
sigursiguros sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:warning: sigursiguros already gave rphares points
rphares
@rphares
Feb 18 2016 13:45
anytime~
srinivas
@srinivasdasu
Feb 18 2016 13:46
type error: cannot read property of '1' undefined
it is throwing this error? I am wondering why it is throwing like that ? can anyone help me on that
Vantrav
@vantrav
Feb 18 2016 13:47
@rphares Hi, How are you?
Have query, what are the different appraoches to achieve the following solution, there must be more than one way to do it?
//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 lookUp(firstName, prop){
// Only change code below this line
//var list = contacts.length;
  for (var j=0, l=contacts.length; j<l; j++){

       var x = contacts[j];

    if(x.firstName === firstName){

      if (x.hasOwnProperty(prop)){

        console.log(x [prop]);

        return x [prop];

      }else return "No such property";
    }
  }return "No such contact";
// Only change code above this line
}

// Change these values to test your function
lookUp("Kristian", "likes");
rphares
@rphares
Feb 18 2016 13:49
profile lookup? haven't looked at that one in a while..
the wiki often has multiple solutions, @vantrav -- thats a good place to check after you have completed exercises :)
Markus Kiili
@Masd925
Feb 18 2016 13:50
@vantrav There is an array of objects, so you can use array iterators, but here for loop seems simple and good.