These are chat archives for FreeCodeCamp/HelpJavaScript

25th
Jan 2017
Caitie Hann
@StargazingIsis
Jan 25 2017 00:00
@Manish-Giri Thank you!
CamperBot
@camperbot
Jan 25 2017 00:00
stargazingisis sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 3943 | @manish-giri |http://www.freecodecamp.com/manish-giri
Caitie Hann
@StargazingIsis
Jan 25 2017 00:00
@Chrono79 Thank You
CamperBot
@camperbot
Jan 25 2017 00:00
stargazingisis sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 3220 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Jan 25 2017 00:00
:+1:
VilfredSikker
@VilfredSikker
Jan 25 2017 00:00

@Chrono79 I'm not sure what to do, to get the rest checked
switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
count++;
return "5 Bet";
break;
case 7:
case 8:
case 9:

  return "0 Hold";
  break;
case 10:
case "J":
case "Q":
case "K":
case "A":
  count -- ;
  return "-5 Hold";
  break;

}

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

Diego Mayer
@Chrono79
Jan 25 2017 00:00
@VilfredSikker don't return in the switch, and check what you're returning at the end, it needs some fixing
john94
@lpy1994
Jan 25 2017 00:01
thank you @Chrono79
CamperBot
@camperbot
Jan 25 2017 00:01
lpy1994 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 3221 | @chrono79 |http://www.freecodecamp.com/chrono79
Manish Giri
@Manish-Giri
Jan 25 2017 00:01
@StargazingIsis welcome
Diego Mayer
@Chrono79
Jan 25 2017 00:01
np
Stephen James
@sjames1958gm
Jan 25 2017 00:02
@WillMcLain The skeleton of the main function is written as that is the function that is called by the tests.
mouadtmd
@mouadtmd
Jan 25 2017 00:02
function palindrome(str) {
  // Good luck!
  var newstr = str.replace(/[\W_]+/g, "").toLowerCase();
  var arr = newstr.split('');
  var lastitem = arr.length  - 1;
  for(var i= 0 ; i < arr.length ; i++){
    if(arr[i] == arr[lastitem-i]){
      return true;
    }
    return false;
  }



}



palindrome("1 eye for of 1 eye.");
any hints ?
palindrome("almostomla") doesn't return true
Stephen James
@sjames1958gm
Jan 25 2017 00:02
@mouadtmd How can you return true before you check all the letters.
Diego Mayer
@Chrono79
Jan 25 2017 00:02
@mouadtmd don't return true and false inside the loop, your loop will only compare the first and last letter that way (and no others)
Stephen James
@sjames1958gm
Jan 25 2017 00:03
@mouadtmd almostomla is not a palindrome it should return false
mouadtmd
@mouadtmd
Jan 25 2017 00:04
function palindrome(str) {
  // Good luck!
  var newstr = str.replace(/[\W_]+/g, "").toLowerCase();
  var arr = newstr.split('');
  var lastitem = arr.length  - 1;
  for(var i= 0 ; i < arr.length ; i++){
    if(arr[i] == arr[lastitem-i]){
      return true;
    }

  }

return false;

}



palindrome("1 eye for of 1 eye.");
tried this one earlier
now palindrome("almostomla") returns true and palindrome("1 eye for of 1 eye."); returns true
Diego Mayer
@Chrono79
Jan 25 2017 00:05
@mouadtmd you can't say it's a palindrome until you checked all letters, but you can say it's not before that, don't you think?
mouadtmd
@mouadtmd
Jan 25 2017 00:06
@Chrono79 Thank you lol been stuck for couple of hours now
CamperBot
@camperbot
Jan 25 2017 00:06
mouadtmd sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 3222 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Jan 25 2017 00:07
:+1:
mouadtmd
@mouadtmd
Jan 25 2017 00:07
@Chrono79 is there a simpler solution to this problem ?
john94
@lpy1994
Jan 25 2017 00:07
@Chrono79 one more question
Diego Mayer
@Chrono79
Jan 25 2017 00:07
@mouadtmd you could use what you learned when reversing a string and compare string against its reversed version
hibaakel
@hibaakel
Jan 25 2017 00:08

function chunkArrayInGroups(arr, size) {
var arr1=[];
var i;
var m;
var s;
for(i=0 ;i<size;i++)
{
m= arr.slice(i);

}
arr1.push(m);
i=0;
for(i=size;i<arr.length;i++)
{
s= arr.slice(i);
}

arr1.push(s);
return arr1;
}

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

Anthony Ciacci
@ciacci1234
Jan 25 2017 00:08

Hey all! I could use some breadcrumbs. I'm currently on Seek and Destroy and in the middle of implementing a nested for loop to achieve the solution. Nested for loops can be a headache, and I would like to utilize the filter function, but I'm having trouble figuring out how to go about doing so.

I know how to use the arguments variable, and I have a basic understanding of the filter function, so I can use them together some way. How do I filter by a value that will be varying?

Jason Luboff
@JLuboff
Jan 25 2017 00:08
@mouadtmd You can complete the excercise without a loop
mouadtmd
@mouadtmd
Jan 25 2017 00:08
@Chrono79 yeah the problem with that is that the reverse statement changes the array but gonna tinker with that
@Chrono79 thanks again
CamperBot
@camperbot
Jan 25 2017 00:08
mouadtmd sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: mouadtmd already gave chrono79 points
Diego Mayer
@Chrono79
Jan 25 2017 00:09
@lpy1994 shoot
hibaakel
@hibaakel
Jan 25 2017 00:10
can any one help me?

function chunkArrayInGroups(arr, size) {
var arr1=[];
var i;
var m;
var s;
for(i=0 ;i<size;i++)
{
m= arr.slice(i);

}
arr1.push(m);
i=0;
for(i=size;i<arr.length;i++)
{
s= arr.slice(i);
}

arr1.push(s);
return arr1;
}

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

mouadtmd
@mouadtmd
Jan 25 2017 00:10
@Chrono79 saw the solution god I feel ashamed
Jason Luboff
@JLuboff
Jan 25 2017 00:12
@hibaakel Try to restructure using only one loop. Within the loop use your slice with two arguments
john94
@lpy1994
Jan 25 2017 00:12
@Chrono79 let me compose it for a while..
Dan Couper
@DanCouper
Jan 25 2017 00:13

@JLuboff it isn’t really an advanced technique, it’s more to keep you sane. It’s done because it’s impossible to keep track of more than a few things in your head at any one time, so it is much simpler to write small functions that do a single thing than it is to write big functions that do multiple things. As a rule of thumb, if your function is more than about 10 lines, it’s probably far, far too complicated. Similarly, if you have more than two levels of nesting, it’s probably far too complicated.

And yeah, it can get hard to read, because you have to work from the innermost bit outwards. Most languages either have a method of composing that reads left-to-right/top-to-bottom, e.g. this is to calculate the sum of squares up to a number (so for 5, it would be 1 squared + 2 squared + 3 squared + 4 squared + 5 squared)

Elixir

def sum_of_squares(upto) do
  1..upto
  |> Enum.map(fn v -> v * v)
  |> Enum.sum
end

or C# (using LINQ)

public class Squares
{
    private readonly int upto;

    /// ………..some other init code………….

    public int SumOfSquares()
    {
        return Enumerable.Range(1, this.upto).Select(x => x * x).Sum();
    }
}

and so on

There are a load of JS libraries that let you do it - like lodash’s _.chain function:

function sumOfSquares(upto) {
  return _.chain(_.range(upto))
                  .map(v => v ** 2)
                  .sum()
                  .value();
}
Stephen James
@sjames1958gm
Jan 25 2017 00:14
@hibaakel You only need one loop - that loop should pick size bites from the array for arr.length / size times
mouadtmd
@mouadtmd
Jan 25 2017 00:15
Can someone give me an andvice about writing code , II always look for the fat fetched solution instead of a simpler one . Is it because I'm not very familiar with the syntax?
Dan Couper
@DanCouper
Jan 25 2017 00:16
just comes with experience
don’t worry - get it working first, then make it better
after a bit you’ll remember how you improved it, and use those techniques the next few times and so on
Not really syntax-related
john94
@lpy1994
Jan 25 2017 00:17
function translatePigLatin(str) {


    var vowels = ["a", "e", "i", "o", "u"];

    if(vowels.indexOf(str.charAt(0)) > -1){
            return str + "way";
         }else if(vowels.indexOf(str.charAt(1)) > -1) {
            return str.slice(1) + str.charAt(0,2) + "ay";
         }else{
            return str.slice(2) + str.slice(0,2) + "ay";
        }

}
translatePigLatin("glove");
Jason Luboff
@JLuboff
Jan 25 2017 00:17
@DanCouper Ya true. Thanks Dan. I really do appreciate the insight and the time you took to write that out
CamperBot
@camperbot
Jan 25 2017 00:17
jluboff sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:warning: jluboff already gave dancouper points
Dan Couper
@DanCouper
Jan 25 2017 00:17
:thumbsup:
mouadtmd
@mouadtmd
Jan 25 2017 00:18
@DanCouper thanks for the advice gonna get back to work now
CamperBot
@camperbot
Jan 25 2017 00:18
mouadtmd sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 453 | @dancouper |http://www.freecodecamp.com/dancouper
john94
@lpy1994
Jan 25 2017 00:18
@Chrono79 I don’t understand
will
@williezerocool
Jan 25 2017 00:18

hi everyone, i would love some help with writing this function for the filter() method. I understand that it should run a test on every value in an array & that everything that passes the test will be stored in a new array. I understand how to access the arguments of the destroyer function, arguments[index], but i can't seem to write the right test https://www.freecodecamp.com/challenges/seek-and-destroy `function destroyer(arr) {
// testArr should run test args1 and args[2] fail
function testArr(value){

return value <= arguments[0];

}
return arr.filter(testArr);
}

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

`

john94
@lpy1994
Jan 25 2017 00:18
else if(vowels.indexOf(str.charAt(1)) > -1) {
why str.charAt(1)
Diego Mayer
@Chrono79
Jan 25 2017 00:19
@lpy1994 that's the same as str[1]
better use some kind of loop
for instance, string has a 3 chars consonant cluster
gonna dinner
john94
@lpy1994
Jan 25 2017 00:20
I mean what does it have to do with the second letter of the word
that “l” letter
Raymond Duckworth
@raymondxduckworth
Jan 25 2017 00:21
Hi everyone,
Can someone help me debug my code for the palindrome algorithm?
Thanks!
function palindrome(str) {
  // Remove all non-alphanumeric characters and make all characters lower-case
  var newStr = str.replace(/\W/g, "").toLowerCase();
  // Split characters into array
  newStr.split("");
  // Create loop to compare first character to last character
  var isEqual = false;
  for (var i = 0; i < newStr.length; i++) {
    if (newStr.charAt(i) === newStr.charAt(newStr.length - i)) {
      isEqual = true;
    } else {
      isEqual = false;
      return isEqual;
    }
  }
  return isEqual;
}



palindrome("eye");
Is my condition statement valid?
john94
@lpy1994
Jan 25 2017 00:22
if you get rid of this else if statement, the word “algorigthm” won’t change to “algorigthm"
algorigthmway *
Dan Couper
@DanCouper
Jan 25 2017 00:25
@raymondxduckworth /\W/g will find anything that isn’t a letter OR an underscore - \w is the same as [A-Za-z_]: \W is the negation, so same as ^[A-Za-z_]. You need to replace /\W|_/g ( non-word character OR underscore)
Randy Goldsmith
@Dueldrawer8
Jan 25 2017 00:27
function countWords(str) {
  // your code here
  var words = str.split(' ');
  var sexy = words.reduce(function(word, times){
      if(times in word){
          word[times]++;
      }
      else{
          word[times] = 1;
      }
      return word;
  }, {});
  return countWords.length > 0 ? sexy : {};
}


countWords('');
if the string is empty.. it has to return an empty object.. but its returning {'' : 1}..shouldnt the ternary operator return an empty object?
Dan Couper
@DanCouper
Jan 25 2017 00:27

@raymondxduckworth this:

var newStr = str.replace(/\W/g, "").toLowerCase();
// Split characters into array
newStr.split("”);

You are splitting into an array, but split creates a new array - newStr is still exactly the same as it was before, a string

Diego Mayer
@Chrono79
Jan 25 2017 00:27
@lpy1994 algorithm starts with a vowel, it enters the first if condition
function translatePigLatin(str) {
    var vowels = ["a", "e", "i", "o", "u"];
    if(vowels.indexOf(str.charAt(0)) > -1){
            return str + "way";
         }else if(vowels.indexOf(str.charAt(1)) > -1) {
            return str.slice(1) + str.slice(0,1) + "ay";
         }else{
            return str.slice(2) + str.slice(0,2) + "ay";  // do you see a pattern here?
        }
}
your code will fail with "string"
john94
@lpy1994
Jan 25 2017 00:29
just don’t understand the second if condition.
how “glove pass through
“l” isn’t a vowel, is it?
Diego Mayer
@Chrono79
Jan 25 2017 00:30
@lpy1994 glove is passing in the else, not the else if
Jason Luboff
@JLuboff
Jan 25 2017 00:30
@lpy1994
if(character at index 0 matches vowels){
return ...
} else if (character index 1 matches vowels)....
Dan Couper
@DanCouper
Jan 25 2017 00:31
:point_up: the else if condition is checking it is a vowel
john94
@lpy1994
Jan 25 2017 00:32
I need to go back to kindergarden..
Diego Mayer
@Chrono79
Jan 25 2017 00:32
you will when you have kids ;)
john94
@lpy1994
Jan 25 2017 00:33
@Chrono79 the else if condition is for the words such as paragraphs or california
Diego Mayer
@Chrono79
Jan 25 2017 00:33
yes
john94
@lpy1994
Jan 25 2017 00:33
glove doens’t match either condition thats why.
thanks again @Chrono79
CamperBot
@camperbot
Jan 25 2017 00:34
lpy1994 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: lpy1994 already gave chrono79 points
john94
@lpy1994
Jan 25 2017 00:34
thank you masters @JLuboff @DanCouper
CamperBot
@camperbot
Jan 25 2017 00:34
lpy1994 sends brownie points to @jluboff and @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 701 | @jluboff |http://www.freecodecamp.com/jluboff
:cookie: 454 | @dancouper |http://www.freecodecamp.com/dancouper
Stephen James
@sjames1958gm
Jan 25 2017 00:38
@Dueldrawer8 Isn't countWords your function name? if str is empty sexy should already be {}
Zacarías Samaniego
@zacmaster
Jan 25 2017 00:39
Hi everyone, someone speaks spanish?
Stephen James
@sjames1958gm
Jan 25 2017 00:39
@Chrono79 Or go back to high school math trying to help your teenage daughter - who hates math and hates the way you explain it, but don't get me started !!
Diego Mayer
@Chrono79
Jan 25 2017 00:39
@zacmaster yes
Jason Luboff
@JLuboff
Jan 25 2017 00:39
@sjames1958gm PTSD? :laughing:
Stephen James
@sjames1958gm
Jan 25 2017 00:40
@JLuboff Post teenager stress disorder ?
Zacarías Samaniego
@zacmaster
Jan 25 2017 00:40
@Chrono79 estoy trabado en el ejercicio 206
Jason Luboff
@JLuboff
Jan 25 2017 00:40
@sjames1958gm You got even more clever then me
Stephen James
@sjames1958gm
Jan 25 2017 00:42
@zacmaster Ejercicios tienen nombres y no números.
@zacmaster Google translate :)
Zacarías Samaniego
@zacmaster
Jan 25 2017 00:44
@sjames1958gm thanks, I understand english but I'm slow to write it
CamperBot
@camperbot
Jan 25 2017 00:44
zacmaster sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 5517 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Esera
@drakho
Jan 25 2017 00:44

Hi Campers.. can someone please help me out with this piece of code
function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for (var i=0; i<arr.length; i++){
for(var j =0; j<arr[i].lenght; j++){
product*=arr[i][j];
}
}
// Only change code above this line
return product;
}

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

Jason Luboff
@JLuboff
Jan 25 2017 00:45
Hello
Stephen James
@sjames1958gm
Jan 25 2017 00:46
@drakho check your second for loop - typo
Jason Luboff
@JLuboff
Jan 25 2017 00:46
@drakho You're second loop you misspelled length
Edgar Pan
@edgaryp
Jan 25 2017 00:46
Hi, I try to use just for loop to complete Diff Two Arrays task. Can anyone help why arr2.[6] \\8 is not pushed in arr3?
function diffArray(arr1, arr2) {

  var arr3 = [];

  if (arr1.length >= arr2.length) {
    for (var i = 0; i < arr1.length; i++) {
      if (arr2.indexOf(arr1[i]) == -1) {
        arr3.push(arr1[i]);
      } else if (arr1.indexOf(arr2[i]) == -1) {
        arr3.push(arr2[i]);
      }
    }
  } else {
    for (var i = 0; i < arr2.length; i++) {
      if (arr1.indexOf(arr2[i]) == -1) {
        arr3.push(arr2[i]);
      } else if (arr2.indexOf(arr1[i]) == -1) {
        arr3.push(arr1[i]);
      }
    }
  }

  console.log(arr3);
}

diffArray([1, 2, 3, 4, 5, 6, 9, 10], [2, 3, 4, 5, 6, 7, 8]);
TBS
@mjczyt
Jan 25 2017 00:47
I got the correct output but can't over the test

var lefted,sliced = [];

function chunkArrayInGroups(arr, size) {
sliced.push(arr.slice(0, size));
lefted = arr.slice(size, arr.length);
if (lefted.length === 0) {
return sliced;
} else {
return chunkArrayInGroups(lefted, size);
}
}

Jason Luboff
@JLuboff
Jan 25 2017 00:48
@mjczyt Try moving your variable declarations inside the function, FCC doesn't always like them outside
Stephen James
@sjames1958gm
Jan 25 2017 00:49
@mjczyt Move variables inside of function - FCC tests don't like globals
@edgaryp When 9 is not found from arr1 in arr2 you push it but then you go to next loop and never look at arr2[6]
Esera
@drakho
Jan 25 2017 00:50
@sjames1958gm @JLuboff thank you. AHHHHHHhhhhhhhhhhhhhhaHHHHHHHHHHHH, pacepalm im taking a 15 min break..
CamperBot
@camperbot
Jan 25 2017 00:50
drakho sends brownie points to @sjames1958gm and @jluboff :sparkles: :thumbsup: :sparkles:
:cookie: 702 | @jluboff |http://www.freecodecamp.com/jluboff
:star2: 5518 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
TBS
@mjczyt
Jan 25 2017 00:50
thanks a lot
Edgar Pan
@edgaryp
Jan 25 2017 00:50
@JLuboff @sjames1958gm you guys analyse the code so fast!!
Jason Luboff
@JLuboff
Jan 25 2017 00:51
@edgaryp Sometimes...lol
Stephen James
@sjames1958gm
Jan 25 2017 00:51
@edgaryp Often the same issue arises with practice you can spot them.
Yonatan Rojas
@MajorTom250993
Jan 25 2017 00:52
Fellow Coders, I need help with this JS challenge. When I run the code it says gloveBoxContents is undefined. Here is 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["globe box"]; // Change this line
Jason Luboff
@JLuboff
Jan 25 2017 00:52
@MajorTom250993 Whats a "globe box"?
john94
@lpy1994
Jan 25 2017 00:52
@MajorTom250993 typo
Manish Giri
@Manish-Giri
Jan 25 2017 00:52
@MajorTom250993 typo
Stephen James
@sjames1958gm
Jan 25 2017 00:52
@zacmaster What is the name of the challenge. If you have code you can post.
I can sort of read Spanish
Yonatan Rojas
@MajorTom250993
Jan 25 2017 00:53
@Manish-Giri HAHAHA! Duh! Thank you so much.
CamperBot
@camperbot
Jan 25 2017 00:53
majortom250993 sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 3946 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Jan 25 2017 00:54
@MajorTom250993 :+1:
Randy Goldsmith
@Dueldrawer8
Jan 25 2017 00:56
@sjames1958gm yes countwords is my function
mouadtmd
@mouadtmd
Jan 25 2017 00:57
@DanCouper decided gonna try to solve the problems then come back once I finish the front-end dev stuff to try to find a better solution. Thanks for your words earlier I was really starting to doubt myself .
CamperBot
@camperbot
Jan 25 2017 00:57
mouadtmd sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:warning: mouadtmd already gave dancouper points
Randy Goldsmith
@Dueldrawer8
Jan 25 2017 00:58
@sjames1958gm ah got it.. you were right thanks.. dunno why i returned the function
CamperBot
@camperbot
Jan 25 2017 00:58
dueldrawer8 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 5519 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Randy Goldsmith
@Dueldrawer8
Jan 25 2017 00:59
@sjames1958gm would you be able to explain to me the if(times in word) part?
that almost seems like it should be a for(var key in str) loop..not an if loop or is it the same thing?
Clara Mae Wells
@run-cmw
Jan 25 2017 00:59
Hi does anyone know how to combine regular expressions in a replace method? Working on Basic Algorithm Scripting Check for Palindromes. My code works - just trying to make it better.
function reverseString(str) {
  var array = str.split("");
  array = array.reverse();
  array = array.join("");
  return array;
}

function palindrome(str) {
  str = str.replace(/\s/g, ""); //replace whitespaces with nothing
  str = str.replace(/\W/g, ""); //replace nonalphanumerics (excluding _) with nothing
  str = str.replace(/\_/g, ""); //replace underscore with nothing
  //str = str.replace(/[\sW_]/g, ""); attempt at combining all replace() doesn't work 
  str = str.toLowerCase(); //Possible to do all four of these in one step?

  var reversed = reverseString(str);

  if (str == reversed) {
    return true;
  } else {
    return false;
  }
}

palindrome("eye");
Diego Mayer
@Chrono79
Jan 25 2017 01:01
@run-cmw use /[\W_]/g or /\W|_/g
Margaret
@Margaret2
Jan 25 2017 01:01
@run-cmw try \W_ and see if it works
in brackets like Chrono said
Clara Mae Wells
@run-cmw
Jan 25 2017 01:02
Thanks @Chrono79 and @Margaret2 . I'll try it.
CamperBot
@camperbot
Jan 25 2017 01:02
run-cmw sends brownie points to @chrono79 and @margaret2 :sparkles: :thumbsup: :sparkles:
:star2: 1371 | @margaret2 |http://www.freecodecamp.com/margaret2
:star2: 3223 | @chrono79 |http://www.freecodecamp.com/chrono79
Edgar Pan
@edgaryp
Jan 25 2017 01:02
@sjames1958gm thanks
CamperBot
@camperbot
Jan 25 2017 01:02
edgaryp sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 5520 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Justin Jones
@koreanjones
Jan 25 2017 01:03
Make Object Properties Private question

var Bike = function() {

// Only change code below this line.
var gear = 0;

this.setGear = function(change) {
gear += change;
};

this.getGear = function() {
return gear;
};
};

var myCar = new Car();

var myBike = new Bike();

Diego Mayer
@Chrono79
Jan 25 2017 01:03
@koreanjones gear += change; not ok, set, not increment
Clara Mae Wells
@run-cmw
Jan 25 2017 01:04
@Chrono79 It worked! So I can't combine spaces or with characters?
Diego Mayer
@Chrono79
Jan 25 2017 01:05
@run-cmw space is already included in \W
Clara Mae Wells
@run-cmw
Jan 25 2017 01:06
@Chrono79 OMG truuuueeeeee. I was thinking special characters such as $%&; rewiring brain* Thanks again!
CamperBot
@camperbot
Jan 25 2017 01:06
run-cmw sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: run-cmw already gave chrono79 points
Dan Couper
@DanCouper
Jan 25 2017 01:06
@run-cmw if you put things in square brackets, you’re saying “one of whatever is in side these brackets - [ABC] is one of A, B or C. If you add the g flag, you’re saying search globally, so it will find A, B or C anywhere. myString.replace(/[\d\s]/g, ‘hello’) would replace any digit or space character in myString with the string hello
(for example)
Justin Jones
@koreanjones
Jan 25 2017 01:08
@Chrono79 I'm confused so set as an Int?
this.setGear = function() {
gear += 1;
};
Raymond Duckworth
@raymondxduckworth
Jan 25 2017 01:08
@DanCouper Thank youuuu!!!!
CamperBot
@camperbot
Jan 25 2017 01:08
raymondxduckworth sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 455 | @dancouper |http://www.freecodecamp.com/dancouper
Diego Mayer
@Chrono79
Jan 25 2017 01:08
no, this is set = (as you already used it several times when you give a var some value) , this is increment +=
Margaret
@Margaret2
Jan 25 2017 01:08
@koreanjones set using the assignment operator =
Justin Jones
@koreanjones
Jan 25 2017 01:09
ah I see thanks guys
can explain this a bit?
Brittni Willett
@Willow606
Jan 25 2017 01:10
thanks @Manish-Giri
CamperBot
@camperbot
Jan 25 2017 01:10
:star2: 3947 | @manish-giri |http://www.freecodecamp.com/manish-giri
willow606 sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
Dan Couper
@DanCouper
Jan 25 2017 01:10
you aren’t adding anything up: if you’re in third gear, and you want to be in twelfth gear, you don’t add twelfth to third
Justin Jones
@koreanjones
Jan 25 2017 01:10
is It cause there is no increment?
Dan Couper
@DanCouper
Jan 25 2017 01:10
you switch to (set) second
Margaret
@Margaret2
Jan 25 2017 01:11
@koreanjones with setGear, they just want you to set the value of the variable
Justin Jones
@koreanjones
Jan 25 2017 01:11
how to sne brownies
send
Margaret
@Margaret2
Jan 25 2017 01:11
@koreanjones thanks <- that's how
CamperBot
@camperbot
Jan 25 2017 01:11
margaret2 sends brownie points to @koreanjones :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for koreanjones
Justin Jones
@koreanjones
Jan 25 2017 01:12
@Margaret2 thanks
CamperBot
@camperbot
Jan 25 2017 01:12
koreanjones sends brownie points to @margaret2 :sparkles: :thumbsup: :sparkles:
:star2: 1372 | @margaret2 |http://www.freecodecamp.com/margaret2
Justin Jones
@koreanjones
Jan 25 2017 01:12
@Chrono79 thanks
CamperBot
@camperbot
Jan 25 2017 01:12
koreanjones sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 3224 | @chrono79 |http://www.freecodecamp.com/chrono79
Margaret
@Margaret2
Jan 25 2017 01:12
:smile:
Randy Goldsmith
@Dueldrawer8
Jan 25 2017 01:14
function countAllCharacters(str) {
  // your code here
  var turnArray = str.split('');
  var finalCount = turnArray.reduce(function(account, counts){
      if(counts in account){
          counts[account]++;
      }
      else{
          counts[account] = 1;
      }
      return counts;
  }, {});
  return str.length > 0 ? finalCount : {};
}

countAllCharacters('banana');
wont let me use in operator
Manish Giri
@Manish-Giri
Jan 25 2017 01:14
welcome @Willow606
Diego Mayer
@Chrono79
Jan 25 2017 01:14
well, that's it for me tonight, keep coding :wave:
Randy Goldsmith
@Dueldrawer8
Jan 25 2017 01:15
nvm got it
@Chrono79 goodnight
Stephen James
@sjames1958gm
Jan 25 2017 01:19
@Chrono79 buenos noches
xdega
@xdega
Jan 25 2017 01:19

I am having a heck of a time accessing the "id" property from the following object:

{
  "profile_info": [
    {
      "id": 14,
      "display_name": "...",
      "avatar": "...",
      "about": "...",
      "users_id": 1,
      "updated_at": "...",
      "created_at": "...",
      "user": {
        "id": 1,
        "username": "...",
        "email": "..."
      }
    }
  ],
  "stream_info": [
    {
      "id": 24,
      "user": "...",
      "url": "",
      "platforms_id": 1,
      "profiles_id": 14
    }
  ]
}

I am trying to get the profile_info.id element.
The object is stored in a variable profileData and trying to access by profileData.profile_info.id but getting undefined. Any ideas?
I even tried profileData.profile_info[0].id and it still didn't work.

Branda25
@Branda25
Jan 25 2017 01:20
Hey guys I am having trouble with this Celsius to Fahrenheit section. my logic is way off haha
Ademola Adegbuyi
@ooade
Jan 25 2017 01:22
@xdega profile_info is an array so it should be profile_info[0].id
Stephen James
@sjames1958gm
Jan 25 2017 01:22
@Branda25 There should only be one line of code - are you using the celsius parameter
Manish Giri
@Manish-Giri
Jan 25 2017 01:22
@xdega json["profile_info"][0].id
xdega
@xdega
Jan 25 2017 01:23
@ooade yeah, I tried that.
Manish Giri
@Manish-Giri
Jan 25 2017 01:23
how about that?
Stephen James
@sjames1958gm
Jan 25 2017 01:23
@xdega The second one looks correct
@xdega HOw are you getting that data?
Arvind Lairenjam
@arvind00
Jan 25 2017 01:23

hi all need some of your feedbacks and suggestions on my code below:

function destroyer(arr) {
   arrRemaining = [];
  for(var i=1;i<arguments.length;i++)
  {
      arrRemaining.push(arguments[i]);
  }
   // Remove all the values
  return arr.filter(function(val){
    return !arrRemaining.includes(val);
  });
}

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

Any improvements that can be made?

Randy Goldsmith
@Dueldrawer8
Jan 25 2017 01:23
@sjames1958gm shouldnt this code produce a boolean value?
function isOddWithoutModulo(num) {
  // your code here
  return (num & 1);
}

isOddWithoutModulo(14);
Stephen James
@sjames1958gm
Jan 25 2017 01:24
@Dueldrawer8 It will return a number - you can use == 1
@arvind00 You can use this to get the array
Manish Giri
@Manish-Giri
Jan 25 2017 01:25
@xdega seems to be working here - https://jsbin.com/cuduzec/edit?js,console
Stephen James
@sjames1958gm
Jan 25 2017 01:26
@xdega Did you use $.ajax to get that data
xdega
@xdega
Jan 25 2017 01:26
hmm. yeah
Well. axios.
Jean Carlos Vinas
@BlueTigerGin
Jan 25 2017 01:26
In this challenge I'm using escape sequences in strings var myStr="\FirstLine\nSecondLine\rThirdLine\n"; I got the rest of the check except one "should have encoded text with the proper escape sequences and no spacing."
Arvind Lairenjam
@arvind00
Jan 25 2017 01:26
@sjames1958gm I didn't get what u said. Please tell me again.
xdega
@xdega
Jan 25 2017 01:26
but it is pretty close. It was a response from api
Ademola Adegbuyi
@ooade
Jan 25 2017 01:27
@xdega can u post the callback function from axios?
Branda25
@Branda25
Jan 25 2017 01:27
@sjames1958gm Oh no. I tried dedicating the variables to return the output but my thought process is not working
storbeck
@storbeck
Jan 25 2017 01:29
i was highlighted here
Stephen James
@sjames1958gm
Jan 25 2017 01:29
@arvind00 I forgot to paste var args = Array.prototype.slice.call(arguments, 1);
storbeck
@storbeck
Jan 25 2017 01:29
something about being pm'd @revisualize ?
xdega
@xdega
Jan 25 2017 01:30
this is the request I am making via axios
 axios.get( '/api/profiles/id/' + this.auth )
     .then( response => this.profileData = response.data );
Stephen James
@sjames1958gm
Jan 25 2017 01:30
@Branda25 The parameter celsius contains the value to be converted - use that and the formula to set the fahrenheit variable
Arvind Lairenjam
@arvind00
Jan 25 2017 01:30
@sjames1958gm Wao! I forgot that method. Thanks.
CamperBot
@camperbot
Jan 25 2017 01:30
arvind00 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 5521 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Ademola Adegbuyi
@ooade
Jan 25 2017 01:31
@xdega Then it will be this.profileData.profile_info[0].id
xdega
@xdega
Jan 25 2017 01:31
Tried that, and it didn't work :(
I am wondering if this is an issue with Vue 2
as it is part of a Vue component
Ademola Adegbuyi
@ooade
Jan 25 2017 01:31
@xdega remove the this binding on profileData
xdega
@xdega
Jan 25 2017 01:34
still not working :(
storbeck
@storbeck
Jan 25 2017 01:34
have you tested that you are getting a valid response?
Ademola Adegbuyi
@ooade
Jan 25 2017 01:34
This message was deleted
leruzal
@leruzal
Jan 25 2017 01:35
please anyone help here
https://www.freecodecamp.com/challenges/profile-lookup#?solution=%2F%2FSetup%0Avar%20contacts%20%3D%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Akira%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Laine%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220543236543%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Pizza%22%2C%20%22Coding%22%2C%20%22Brownie%20Points%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Harry%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Potter%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220994372684%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Hogwarts%22%2C%20%22Magic%22%2C%20%22Hagrid%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Sherlock%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Holmes%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220487345643%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Intruiging%20Cases%22%2C%20%22Violin%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Kristian%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Vos%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%22unknown%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Javascript%22%2C%20%22Gaming%22%2C%20%22Foxes%22%5D%0A%20%20%20%20%7D%2C%0A%5D%3B%0A%0A%0Afunction%20lookUp(firstName%2C%20prop)%7B%0A%2F%2F%20Only%20change%20code%20below%20this%20line%0A%20for%20(var%20x%20%3D%200%3B%20x%20%3C%20contacts.length%3B%20x%2B%2B)%7B%0A%20%20%20%20if%20(contacts%5Bx%5D.firstName%20%3D%3D%3D%20firstName)%20%7B%0A%20%20%20%20%20%20%20%20if%20(contacts%5Bx%5D.hasOwnProperty(prop))%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20contacts%5Bx%5D%5Bprop%5D%3B%0A%20%20%20%20%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20%22No%20such%20property%22%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D%0Areturn%20%22No%20such%20contact%22%3B%0A%2F%2F%20Only%20change%20code%20above%20this%20line%0A%7D%0A%0A%2F%2F%20Change%20these%20values%20to%20test%20your%20function%0AlookUp(%22Akira%22%2C%20%22likes%22)%3B%0A
i dont know why it is not working
xdega
@xdega
Jan 25 2017 01:35
yeah. I can see the valid object in vue.js developer tools. I am also able to print out the entire object.
Stephen James
@sjames1958gm
Jan 25 2017 01:36
@leruzal The function name is supposed to be lookUpProfile
storbeck
@storbeck
Jan 25 2017 01:36
try setting this.profileData to garbage data then console.log it inside the function, see if you get the same data
that will determine if you have a scope problem with this
it's also worth nothing, that after => should be wrapped in { }
without brackets it's meant to return data
which you aren't doing
Stephen James
@sjames1958gm
Jan 25 2017 01:37
@leruzal Also it appears you contacts got changed - 'Intriguing'
John Nunns
@johnnunns
Jan 25 2017 01:38
var obj = {
  key: [1000, 10, 50, 10]
};
how would I write a for loop to address the values inside the key
leruzal
@leruzal
Jan 25 2017 01:39
@sjames1958gm ty
CamperBot
@camperbot
Jan 25 2017 01:39
:star2: 5522 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
leruzal sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
Ademola Adegbuyi
@ooade
Jan 25 2017 01:39
i = 0; i < obj.key.length
storbeck
@storbeck
Jan 25 2017 01:39
@johnnunns obj.key.forEach(el => { console.log(el) })
Geist0504
@Geist0504
Jan 25 2017 01:39

var falsey = [false, null, 0,"",undefined,NaN];

function remove(val){
return falsey.indexOf(val) == -1;
}

function bouncer(arr) {
var filtered = arr.filter(remove);
return filtered;
}

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

John Nunns
@johnnunns
Jan 25 2017 01:39
ok so I have it right then..
Geist0504
@Geist0504
Jan 25 2017 01:39

var code = "formatted";
var falsey = [false, null, 0,"",undefined,NaN];

function remove(val){
return falsey.indexOf(val) == -1;
}

function bouncer(arr) {
var filtered = arr.filter(remove);
return filtered;
}

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

sorry, I can't get it to format like it appears in the window
CamperBot
@camperbot
Jan 25 2017 01:40
:bulb: to format code use backticks! ``` more info
Will McLain
@WillMcLain
Jan 25 2017 01:40

function diffArray(arr1, arr2) {
var newArr = [];
newArr = arr1.concat(arr2);
var numArr=[]; var indexArr = [];
var repeat = false;
for(var i=0;i<arr1.lenght;i++){

for(var j=0;j<arr2;j++){
  if(arr1[i]!=arr2[j] && isNotRepeated(numArr,arr2[j])){
    numArr.push(arr2[j]);
  }
}   

}

return newArr;

}//diffArray

I am getting an error that numArr is not defined. Is numArr out of scope in my example?
Geist0504
@Geist0504
Jan 25 2017 01:42
I'm having trouble with this code, for some reason it won't boot the null value from the array, but it clears all the others. Any idea why?
var falsey = [false, null, 0,"",undefined,NaN];
function remove(val){
return falsey.indexOf(val) == -1;
}
function bouncer(arr) {
var filtered = arr.filter(remove);
return filtered;
}
bouncer([false, null, 0, NaN, undefined, ""]);
storbeck
@storbeck
Jan 25 2017 01:43
@WillMcLain it is not out of scope in that example
Will McLain
@WillMcLain
Jan 25 2017 01:43
That is what I thought.
VM246 diff-two-arrays:45 Uncaught ReferenceError: numArr is not defined
at VM246 diff-two-arrays:45
storbeck
@storbeck
Jan 25 2017 01:44
but this for(var i=0;i<arr1.lenght;i++){
Will McLain
@WillMcLain
Jan 25 2017 01:44
That is what the error is....
storbeck
@storbeck
Jan 25 2017 01:44
unless you retyped it here, length is typo'd
xdega
@xdega
Jan 25 2017 01:44
@storbeck so, if I hard code an object, then I can access it ok. I guess the issue is in the returned object from the axios request.
John Nunns
@johnnunns
Jan 25 2017 01:44
I feel like i'm making this more difficult than it is, but here is the problem
storbeck
@storbeck
Jan 25 2017 01:44
yep could be @xdega
John Nunns
@johnnunns
Jan 25 2017 01:44
Write a function called "getElementsThatEqual10AtProperty".

Given an object and a key, "getElementsThatEqual10AtProperty" returns an array containing all the elements of the array located at the given key that are equal to ten.

Notes:
* If the array is empty, it should return an empty array.
* If the array contains no elements equal to 10, it should return an empty array.
* If the property at the given key is not an array, it should return an empty array.
* If there is no property at the key, it should return an empty array.

var obj = {
  key: [1000, 10, 50, 10]
};
var output = getElementsThatEqual10AtProperty(obj, 'key');
console.log(output); // --> [10, 10]

Starter Code :
function getElementsThatEqual10AtProperty(obj, key) {
  // your code here
}
my code:
function getElementsThatEqual10AtProperty(obj, key) {
  var x = []
  for(var i = 0; i < obj[key].length; i++){
  if (obj[key].hasOwnProperty === 10){
      return x[i];
  }else { 
      return  x;
  }}

}

var obj = {
  key: [1000, 10, 50, 10]
};
getElementsThatEqual10AtProperty(obj, 'key');
should be an easy one but the brain is not running super smooth today :)
storbeck
@storbeck
Jan 25 2017 01:45
that problem sounds like a good time to use filter @johnnunns
John Nunns
@johnnunns
Jan 25 2017 01:45
oh yeah!
forgot about that
Will McLain
@WillMcLain
Jan 25 2017 01:46
@storbeck Thanks. ;) This did not correct my initial problem.
CamperBot
@camperbot
Jan 25 2017 01:46
willmclain sends brownie points to @storbeck :sparkles: :thumbsup: :sparkles:
:star2: 1834 | @storbeck |http://www.freecodecamp.com/storbeck
Stephen James
@sjames1958gm
Jan 25 2017 01:46
@johnnunns You need to test if array before the loop - then filter
Ademola Adegbuyi
@ooade
Jan 25 2017 01:46
@xdega Oh! i see your issue.. You declared this.profileData outside the getter, and tried accessing this.profileData elsewhere
Ricardo G.
@Rubenricardo
Jan 25 2017 01:46
hello!
John Nunns
@johnnunns
Jan 25 2017 01:46
I'll look that up now, tell me am I headed in the right direction though with this for loop? and for the sake of knowing how to do it that way can we figure it out without filter?
Ricardo G.
@Rubenricardo
Jan 25 2017 01:46
ok i know i should do this alone, but im quite lost

function convertToF(celsius) {
var fahrenheit;
// Only change code below this line

// Only change code above this line
return fahrenheit; = 9 / 5 + 32;
}

its the java script challenge of farenhet
Stephen James
@sjames1958gm
Jan 25 2017 01:47
@Rubenricardo use celsius in the formula - and do the assignment between the two comments.
storbeck
@storbeck
Jan 25 2017 01:47
function convertToF(celsius) {
var fahrenheit;
// Only change code below this line
  fahrenheit = 9 / 5 + 32;
// Only change code above this line
return fahrenheit; 
}
did you intend to do that?
xdega
@xdega
Jan 25 2017 01:48
@ooade yeah. This is part of a Vue 2 component. So all the data properties are initialized separately.
Ricardo G.
@Rubenricardo
Jan 25 2017 01:48
oh
ok great it workd
@storbeck thanks
CamperBot
@camperbot
Jan 25 2017 01:48
rubenricardo sends brownie points to @storbeck :sparkles: :thumbsup: :sparkles:
:star2: 1835 | @storbeck |http://www.freecodecamp.com/storbeck
storbeck
@storbeck
Jan 25 2017 01:49
do you understand why it worked?
xdega
@xdega
Jan 25 2017 01:49
I think I may just create a new API endpoint to get the ID.
Ricardo G.
@Rubenricardo
Jan 25 2017 01:49
haha not really
storbeck
@storbeck
Jan 25 2017 01:49
before you had return fahrenheit; = 9 / 5 + 32;
Ricardo G.
@Rubenricardo
Jan 25 2017 01:49
is it because i gave an assignement to farenhetoi?
storbeck
@storbeck
Jan 25 2017 01:49
a ; is a line terminator, so you really have 2 different statements
xdega
@xdega
Jan 25 2017 01:49
I am using the object elsewhere in the application, but by iterating through. In this instance, though, I am trying to just get the id number (without iterating to find it)
storbeck
@storbeck
Jan 25 2017 01:49
return fahrenheit;
= 9 / 5 + 32;
Will McLain
@WillMcLain
Jan 25 2017 01:49
@Rubenricardo You might want to also us the incomming parameter...
storbeck
@storbeck
Jan 25 2017 01:50
it first hits return, which at that point is undefined
the second one does nothing, it would error but that line of code is never reached
you want to set the variable fahrenheit to the equation
then return that variable
Ademola Adegbuyi
@ooade
Jan 25 2017 01:50
@xdega Most likely, you'll get an undefined cos the promise was not fulfilled before attempting to use it
storbeck
@storbeck
Jan 25 2017 01:50
@Rubenricardo understand?
Ricardo G.
@Rubenricardo
Jan 25 2017 01:51
to be honest, no
storbeck
@storbeck
Jan 25 2017 01:51
ok think about it like this
Ricardo G.
@Rubenricardo
Jan 25 2017 01:51
im listening
storbeck
@storbeck
Jan 25 2017 01:51
i give you a box, you put something in the box and give it back to me
xdega
@xdega
Jan 25 2017 01:51
Yeah. Well I make the request before calling the object, but I think this is a consequence of it being a reactive data property
Ricardo G.
@Rubenricardo
Jan 25 2017 01:51
ok
storbeck
@storbeck
Jan 25 2017 01:51
that's how variables work
var fahrenheit is defining the box, making it exist
Ricardo G.
@Rubenricardo
Jan 25 2017 01:51
ahhh ok
storbeck
@storbeck
Jan 25 2017 01:51
fahrenheit = something is putting something in the box
return fahrenheit gives the box back
Ricardo G.
@Rubenricardo
Jan 25 2017 01:52
oh!!
ok ok
Will McLain
@WillMcLain
Jan 25 2017 01:52
@storbeck Great explanation!
Ricardo G.
@Rubenricardo
Jan 25 2017 01:52
haha thanks a lot mate @storbeck
CamperBot
@camperbot
Jan 25 2017 01:52
rubenricardo sends brownie points to @storbeck :sparkles: :thumbsup: :sparkles:
:warning: rubenricardo already gave storbeck points
storbeck
@storbeck
Jan 25 2017 01:52
no problem, thanks @WillMcLain
CamperBot
@camperbot
Jan 25 2017 01:52
storbeck sends brownie points to @willmclain :sparkles: :thumbsup: :sparkles:
:cookie: 263 | @willmclain |http://www.freecodecamp.com/willmclain
xdega
@xdega
Jan 25 2017 01:54
lol :smile: I had already created an API endpoint for getting the profile ID, to solve this problem. lol
I guess i just forgot about it /facepalm
storbeck
@storbeck
Jan 25 2017 01:54
i do that all the time at work
come across a problem and start solving it, then realize i already wrote this solution farther down in the file 6 months ago
xdega
@xdega
Jan 25 2017 01:56
This isn't my job.. yet. Maybe someday, though.
Randy Goldsmith
@Dueldrawer8
Jan 25 2017 01:56
anyone have any ideas about how to create a function that gets the length of a string without using the length method?
xdega
@xdega
Jan 25 2017 01:56
There's a reason I am working on personal projects, building a portfolio.
storbeck
@storbeck
Jan 25 2017 01:56
if you're already writing APIs you're well on your way
Randy Goldsmith
@Dueldrawer8
Jan 25 2017 01:56
was thinking of using a while loop but dont know what to put in for the condition lol
storbeck
@storbeck
Jan 25 2017 01:56
@Dueldrawer8 convert to an array then find the length of the array?
:)
Randy Goldsmith
@Dueldrawer8
Jan 25 2017 01:56
cant use the .length method
storbeck
@storbeck
Jan 25 2017 01:57
convert to loop, iterate over with i++, return i
Ricardo G.
@Rubenricardo
Jan 25 2017 01:57
hey @storbeck so, if I want to add something to the box and then do it again like say to make this happen: convertToF(-30) should return a value of -22 i need to figure that out as in putting in the equation that gives me that result?
Stephen James
@sjames1958gm
Jan 25 2017 01:57
@Dueldrawer8 slice until its empty?
Randy Goldsmith
@Dueldrawer8
Jan 25 2017 01:57
@storbeck good idea
@sjames1958gm yeah the hint suggest using slice but dunno how i would use that with slice
storbeck
@storbeck
Jan 25 2017 01:57
yes @Rubenricardo
Ricardo G.
@Rubenricardo
Jan 25 2017 01:57

like, setting several answers fahrenheit = 9 / 5 + 32;

fahrenheit = 30

storbeck
@storbeck
Jan 25 2017 01:58
sure, you can do that yes
Ricardo G.
@Rubenricardo
Jan 25 2017 01:58
ok, im not quite getting
Stephen James
@sjames1958gm
Jan 25 2017 01:58
i = 0; while (str != "") { str = str.slice(1); i++ }
Ricardo G.
@Rubenricardo
Jan 25 2017 01:58

function convertToF(celsius) {
var fahrenheit;
// Only change code below this line

fahrenheit = 9 / 5 + 32;

fahrenheit = 30
// Only change code above this line
return fahrenheit;
}

// Change the inputs below to test your code
convertToF(30);

convertToF(-30) should return a value of -22
convertToF(-10) should return a value of 14
the instructions above
storbeck
@storbeck
Jan 25 2017 01:58
well because the tests will change, it wont always be 30
Stephen James
@sjames1958gm
Jan 25 2017 01:58
@Rubenricardo Use celsius in the formula F = C * 9/5 + 32
storbeck
@storbeck
Jan 25 2017 01:58
that's why you need a math equation to convert it
setting fahrenheit twice overwrites the first one
Ricardo G.
@Rubenricardo
Jan 25 2017 01:59
oh ok
storbeck
@storbeck
Jan 25 2017 01:59
it replaces 9/5+32 with 30
the equation @sjames1958gm should work
C being the variable that is passed in to the function
which would need changed to the variable you are using
Randy Goldsmith
@Dueldrawer8
Jan 25 2017 02:00
@sjames1958gm ty..
CamperBot
@camperbot
Jan 25 2017 02:00
dueldrawer8 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 5523 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Randy Goldsmith
@Dueldrawer8
Jan 25 2017 02:00
@sjames1958gm thank you
CamperBot
@camperbot
Jan 25 2017 02:00
dueldrawer8 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: dueldrawer8 already gave sjames1958gm points
Stephen Jones
@Jackdus
Jan 25 2017 02:03
on counting cards I cant seem to figure out how to add the values of the cards together: I have the inputs set to 2,3,4,5,6. which should equal " 5 Bet"

var count = 0;

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

if (count>0){
return count + " Bet";
}
else if (count<=0){
return count + " Hold";
}

// Only change code above this line
}

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

Anthony Ciacci
@ciacci1234
Jan 25 2017 02:03
quick question, can you solve Seek and Destroy without a nested for loop? I've been at it for a few hours and keep coming back to a solution with a nested for loop, but I feel like there should be a more efficient way
Stephen James
@sjames1958gm
Jan 25 2017 02:04
@Jackdus you are resetting count each time - not incrementing or decrementing
Ricardo G.
@Rubenricardo
Jan 25 2017 02:04

function convertToF(celsius) {
var fahrenheit;
// Only change code below this line

fahrenheit = 9 / 5 + 32;

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

// Change the inputs below to test your code
convertToF(30);

Stephen James
@sjames1958gm
Jan 25 2017 02:04
@ciacci1234 filter
storbeck
@storbeck
Jan 25 2017 02:04
@Jackdus store the result of each return from cc in a variable and add each together, then return the result of that
Stephen Jones
@Jackdus
Jan 25 2017 02:04
ok thanks
Stephen James
@sjames1958gm
Jan 25 2017 02:04
@Rubenricardo you have F = 9/5 + 32 it should be F = C* 9/5 + 32
Ricardo G.
@Rubenricardo
Jan 25 2017 02:04
sorry, i don't get how is it that convertToF sould return me a value
Branda25
@Branda25
Jan 25 2017 02:05
thanks for the help! I finally got it haha @sjames1958gm
CamperBot
@camperbot
Jan 25 2017 02:05
branda25 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 5524 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Jan 25 2017 02:06
@Branda25 :+1:
Anthony Ciacci
@ciacci1234
Jan 25 2017 02:08
@sjames1958gm I was thinking that I'm not utilizing filter appropriately, but I'm having trouble conceptualizing filtering over a variable value. Any hints you might be able to offer?
Randy Goldsmith
@Dueldrawer8
Jan 25 2017 02:09
@sjames1958gm produces an infinite loop..
storbeck
@storbeck
Jan 25 2017 02:10
@ciacci1234 what do you have so far
Anthony Ciacci
@ciacci1234
Jan 25 2017 02:11
just reset my code :sweat_smile: I keep circling around this crazy nested for loop where I iterate over the arguments while iterating through the array
storbeck
@storbeck
Jan 25 2017 02:12
can you paste the problem again
Anthony Ciacci
@ciacci1234
Jan 25 2017 02:13

You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.

<pre><code>function destroyer(arr) {
// Remove all the values
return arr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
</code></pre>

ahh sorry, I'm still figuring out markdown :sweat_smile:
I was thinking to set up a function that I can use as the callback function in filter? EX: array.filter(myFunction), but I'm having trouble figuring out how myFunction would take into account the variable arguments
storbeck
@storbeck
Jan 25 2017 02:17
ok, so remove anything provided as an argument that matches argument 0
first things first, convert arguments to a real array, then separate out the array to match against, and the list of numbers to search for
John Nunns
@johnnunns
Jan 25 2017 02:20
var obj = {
  key: [1000, 10, 50, 10]
}
function getElementsThatEqual10AtProperty(obj, key){
for (var i = 0; i<obj[key].length; i++){
    return i
}

return i
}
getElementsThatEqual10AtProperty(obj, 'key');
why am I returning 0 here?
trying to return the values inside the key
storbeck
@storbeck
Jan 25 2017 02:20
@johnnunns because your for loop returns i, so it returns 0 as it only runs 1 time
Arvind Lairenjam
@arvind00
Jan 25 2017 02:21

Hi, I need some suggestions. Her is my code so far, I have sorted the array. Next, I am thinking if i used linear search, the performance in large array will not be optimal. Here is my code:

function getIndexToIns(arr, num) {
  // Find my place in this sorted array.
  function compareNumbers(a, b)
  {
    return a - b;
  }
  arr.sort(compareNumbers);
  // next?
  return num;
}

getIndexToIns([40, 60], 50);

Any suggestions? I am thinking of binary search.

storbeck
@storbeck
Jan 25 2017 02:22
@arvind00 you could halve them
John Nunns
@johnnunns
Jan 25 2017 02:22
so I'm using the return wrong and just returning it back into the function
storbeck
@storbeck
Jan 25 2017 02:22
if your number is more than the middle number, then you have half the numbers to look for, same with less than
then keep halving until you find the number
John Nunns
@johnnunns
Jan 25 2017 02:22
var obj = {
  key: [1000, 10, 50, 10]
}
function getElementsThatEqual10AtProperty(obj, key){
for (var i = 0; i<obj[key].length; i++){
    console.log(i)
}

}
getElementsThatEqual10AtProperty(obj, 'key');
so if I do that, I'm still just printing 0,1,2,3
Christopher McCormack
@cmccormack
Jan 25 2017 02:23
@arvind00 A binary search would be faster but only if you want to do it. The inputs given are fairly small so it's not really necessary.
storbeck
@storbeck
Jan 25 2017 02:23
@johnnunns right because you aren't returning, return will cancel the for loop and return immediately
haivuong14
@haivuong14
Jan 25 2017 02:24
Hey guys having a problem on the Javascript portion titled "Stand in Line"
Arvind Lairenjam
@arvind00
Jan 25 2017 02:24
@storbeck , @cmccormack I will consider your points.
haivuong14
@haivuong14
Jan 25 2017 02:24

'
function nextInLine(arr, item) {
// Your code here

return item; // Change this line
}

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

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

John Nunns
@johnnunns
Jan 25 2017 02:24
I just want it to print [1000, 10, 50, 10] @storbeck
storbeck
@storbeck
Jan 25 2017 02:25
why?
John Nunns
@johnnunns
Jan 25 2017 02:25
not even for the actual solution but just to make sure I'm accessing what I want to access
storbeck
@storbeck
Jan 25 2017 02:25
just print the array then, not in a for loop
Christopher McCormack
@cmccormack
Jan 25 2017 02:25
@arvind00 I don't recall if you are given the arrays in already sorted order... if not, then consider the fact you'll probably have to sort the items anyways so you're talking at least O(n log n) complexity
storbeck
@storbeck
Jan 25 2017 02:25
console.log(obj[key]);
John Nunns
@johnnunns
Jan 25 2017 02:25
I was thinking I needed a for loop to address that array inside the object @storbeck
storbeck
@storbeck
Jan 25 2017 02:25
no
that access each element, not the entire array
it will certainly be the entire array, but not in array format
John Nunns
@johnnunns
Jan 25 2017 02:26
ok with that logic can I simply obj[key].filter(blah blah)
storbeck
@storbeck
Jan 25 2017 02:26
yes
Arvind Lairenjam
@arvind00
Jan 25 2017 02:28
@cmccormack so you mean to say that the inbuilt sort(compareFunction) of array is not an optimal solution. So we can use our own sort functions ?
Anthony Ciacci
@ciacci1234
Jan 25 2017 02:29
targets = [];
for (var i = 1; i < arguments.length; i++) {
targets.push(arguments[i]);
}
Christopher McCormack
@cmccormack
Jan 25 2017 02:29
@arvind00 no not saying that, just saying you're already sorting, why not just take advantage of that so you don't have to do a search as well? Trying to give you a hint :)
Anthony Ciacci
@ciacci1234
Jan 25 2017 02:30
@storbeck so that successfully separates the array from the numbers I want to match against, but I'm still having trouble with where filter would come in
storbeck
@storbeck
Jan 25 2017 02:30
well, how can you determine if an element is in an array?
Christopher McCormack
@cmccormack
Jan 25 2017 02:30
indexOf
John Nunns
@johnnunns
Jan 25 2017 02:30
@storbeck this is how I've learned filter function, per youtube
var obj = {
  key: [1000, 10, 50, 10]
}
function getElementsThatEqual10AtProperty(obj, key){
var i = obj[key].filter(function(number) {
    return number.obj[key]=== 10
})
return i

}
getElementsThatEqual10AtProperty(obj, 'key');
is this close?
storbeck
@storbeck
Jan 25 2017 02:31
yes the idea is there
you want to return either true or false, and it will keep the true elements
John Nunns
@johnnunns
Jan 25 2017 02:31
isn't return number.obj[key] === 10 doing so?
storbeck
@storbeck
Jan 25 2017 02:32
what is number.obj[key] ?
John Nunns
@johnnunns
Jan 25 2017 02:32
tbh I'm not sure, I was a bit confused by the youtube video
storbeck
@storbeck
Jan 25 2017 02:33
you'd want to use number === 10
Arvind Lairenjam
@arvind00
Jan 25 2017 02:33
@cmccormack I have to think.
storbeck
@storbeck
Jan 25 2017 02:33
since your variable is number
function(>>number<<) { }
Christopher McCormack
@cmccormack
Jan 25 2017 02:33
number is the current value from your array @johnnunns
try removing the obj[key]
John Nunns
@johnnunns
Jan 25 2017 02:34
ok so by typing obj[key]. filter < that's the info that's being used in the argument "number"
storbeck
@storbeck
Jan 25 2017 02:34
yes
Christopher McCormack
@cmccormack
Jan 25 2017 02:35
parameter number, yes
John Nunns
@johnnunns
Jan 25 2017 02:35
gotcha
Christopher McCormack
@cmccormack
Jan 25 2017 02:35
so as the filter iterates over your array, number is equal to each value in sequence of your array
John Nunns
@johnnunns
Jan 25 2017 02:38
thanks @cmccormack @storbeck
CamperBot
@camperbot
Jan 25 2017 02:38
johnnunns sends brownie points to @cmccormack and @storbeck :sparkles: :thumbsup: :sparkles:
:cookie: 283 | @cmccormack |http://www.freecodecamp.com/cmccormack
:star2: 1836 | @storbeck |http://www.freecodecamp.com/storbeck
Christopher McCormack
@cmccormack
Jan 25 2017 02:38
np
John Nunns
@johnnunns
Jan 25 2017 02:38
any ideas why this is running fine but failing though?
  key: [10, 10, 10, 10, 100]
}

function getElementsThatEqual10AtProperty(obj, key){
    var x = []

    if(obj.key.length === 0){
        return x
    }

var i = obj[key].filter(function(number) {
    return number=== 10
})
return i

}
getElementsThatEqual10AtProperty(obj, 'key');
Christopher McCormack
@cmccormack
Jan 25 2017 02:39
you're missing like all your semicolons it seems
storbeck
@storbeck
Jan 25 2017 02:39
they're not necessary
Christopher McCormack
@cmccormack
Jan 25 2017 02:40
just makes me cringe a bit
John Nunns
@johnnunns
Jan 25 2017 02:40
the if statement seems to have bugged it, but in the problem it requests return and empty array if it has no value
storbeck
@storbeck
Jan 25 2017 02:40
me too tbh
John Nunns
@johnnunns
Jan 25 2017 02:40
fixed it
storbeck
@storbeck
Jan 25 2017 02:40
you dont want an if statement
John Nunns
@johnnunns
Jan 25 2017 02:40
no need to cringe now
storbeck
@storbeck
Jan 25 2017 02:40
you want to return your statement
because you want to literally return true or false
oh wait, i didn't actually read the code
Christopher McCormack
@cmccormack
Jan 25 2017 02:41
not sure what the string 'key' is being used for here
Jason Bunnell
@jasonbunnell
Jan 25 2017 02:42
Need help. The instructions say, "FirstLine newline backslash SecondLine backslash carriage-return ThirdLine".
Tried this:
var myStr = 'FirstLine\n\SecondLine\\nThirdline'; // Change this line
but that did not work
Also tried with double quotes.
Manish Giri
@Manish-Giri
Jan 25 2017 02:42
@jasonbunnell Line
capital L
John Nunns
@johnnunns
Jan 25 2017 02:43
@cmccormack not sure either, but it doesn't run without the ' around key
Christopher McCormack
@cmccormack
Jan 25 2017 02:43
I think I see how it's being used
John Nunns
@johnnunns
Jan 25 2017 02:44
@storbeck yeah like i said the code works fine
__mifflin__
@cdrainxv
Jan 25 2017 02:44
@jasonbunnell:
Also \r for return carriage here: \\\nThirdline' not \n for newline.
Christopher McCormack
@cmccormack
Jan 25 2017 02:44
is this an FCC problem?
John Nunns
@johnnunns
Jan 25 2017 02:46
no it's not
@storbeck * If the array is empty, it should return an empty array.
  • If the array contains no elements equal to 10, it should return an empty array.
  • If the property at the given key is not an array, it should return an empty array.
  • If there is no property at the key, it should return an empty array.
var obj = {
  key: [10, 10, 10, 10, 100]
}

function getElementsThatEqual10AtProperty(obj, key){
    var x = [];


var i = obj[key].filter(function(number) {
    return number=== 10;
})
return i;

}
getElementsThatEqual10AtProperty(obj, 'key');
this code fails the bottom 2 on the list
Christopher McCormack
@cmccormack
Jan 25 2017 02:47
Where are you checking to see if the value of the key is an array?
John Nunns
@johnnunns
Jan 25 2017 02:48
No i see I need to update that
storbeck
@storbeck
Jan 25 2017 02:48
what about this
return obj[key].filter(number => number === 10) || [];
does that work?
Arvind Lairenjam
@arvind00
Jan 25 2017 02:50
@storbeck what does => do?
John Nunns
@johnnunns
Jan 25 2017 02:50
still fails the bottom 2 reqs
storbeck
@storbeck
Jan 25 2017 02:50
@arvind00 es6 style function call
Christopher McCormack
@cmccormack
Jan 25 2017 02:50
will the left side be false if it's not an array?
Arvind Lairenjam
@arvind00
Jan 25 2017 02:51
@storbeck ok. will check it out.
John Nunns
@johnnunns
Jan 25 2017 02:51
@storbeck can you write that without the es6 style function call just so I know what it looks like?
san-te
@san-te
Jan 25 2017 02:52
hello people
storbeck
@storbeck
Jan 25 2017 02:52
return obj[key].filter(function(number) {
  return number === 10;
}) || [];
san-te
@san-te
Jan 25 2017 02:52
please anyone who can help with this task

function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  skeys = Object.keys(source);
  for(var i=0; i<collection.length; i++){
    if(source[skeys[i]] == collection[i][skeys[i]]) {
      arr.push(collection[i]);
    }
  }

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

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
Christopher McCormack
@cmccormack
Jan 25 2017 02:54
Will still need to check if it's an array
John Nunns
@johnnunns
Jan 25 2017 02:54
@storbeck I imagine we need if statements stating return [] if it's not an array and if it has no property
Moisés Man
@moigithub
Jan 25 2017 02:54
@kanyin-me u cant use i varaible as index to access sKeys array.. cuz those (collection vs source) have different length
storbeck
@storbeck
Jan 25 2017 02:54
sure
John Nunns
@johnnunns
Jan 25 2017 02:54
let me take a stab at that
Christopher McCormack
@cmccormack
Jan 25 2017 02:56
can you have a key without a value? not sure I understand that last bullet point If there is no property at the key, it should return an empty array.
maybe it means if the key doesn't exist
storbeck
@storbeck
Jan 25 2017 02:57
well the function can take in a key, so if it was user-defined it's possible it wouldn't exist
Christopher McCormack
@cmccormack
Jan 25 2017 02:57
sure, ok
John Nunns
@johnnunns
Jan 25 2017 02:57
var x = []
if(obj[key].hasOwnProperty !== true){
    return x
}
not sure why that's just returning []
when key has values
Christopher McCormack
@cmccormack
Jan 25 2017 02:58
hasOwnProperty requires an argument
storbeck
@storbeck
Jan 25 2017 02:58
why not just if (!obj[key]) { return [] }
John Nunns
@johnnunns
Jan 25 2017 02:59
oh gotcha
storbeck
@storbeck
Jan 25 2017 02:59
obj[key] would be falsey if it didn't exist
John Nunns
@johnnunns
Jan 25 2017 02:59
didn't know the syntax @storbeck
Amarillia
@Amarillia
Jan 25 2017 02:59
Hi! I need some help. It's a very basic question but I need some explanation because it is not clear in my head and English is not my first language. Can somebody explain for me what does it mean parse/parsing in programming? And when I need to use e.g. parseInt for JavaScript.? I am working on the Where do I belong challenge.
Jason Bunnell
@jasonbunnell
Jan 25 2017 03:00
@cdrainxv Thanks! That worked. When should you use \n versus \r? For some reason it wanted one to be \r and the other \n but not sure I understand the difference
CamperBot
@camperbot
Jan 25 2017 03:00
jasonbunnell sends brownie points to @cdrainxv :sparkles: :thumbsup: :sparkles:
:star2: 2182 | @cdrainxv |http://www.freecodecamp.com/cdrainxv
zhekau
@zhekau
Jan 25 2017 03:00
Hi everyone! Anyone cares to help me figure out why I can't pass one of the tests in the Friendly Date Ranges challenge?
Kyle
@quesurifn
Jan 25 2017 03:00
Does anyone know why jquery would be causing issues loading the background-image url(path)
John Nunns
@johnnunns
Jan 25 2017 03:00
haha I'm so close
Coy Sanders
@coymeetsworld
Jan 25 2017 03:01
@Amarillia parse means convert a value from one type to another
Kyle
@quesurifn
Jan 25 2017 03:01
Dev tools says the error is in jquery but that doesn't make sense. its having trouble finding a path that exists....
Coy Sanders
@coymeetsworld
Jan 25 2017 03:01
for example "5" and 5 are not the same, the first is a String the other is an integer
John Nunns
@johnnunns
Jan 25 2017 03:01
ok @storbeck so that worked for 4 of 5
Coy Sanders
@coymeetsworld
Jan 25 2017 03:02
if you want to convert the "5" to 5 you would need to use parseInt
John Nunns
@johnnunns
Jan 25 2017 03:02
  • If the array is empty, it should return an empty array.
  • If the array contains no elements equal to 10, it should return an empty array.
  • If the property at the given key is not an array, it should return an empty array.
  • If there is no property at the key, it should return an empty array.
3 of 4*
1 2 4 worked
storbeck
@storbeck
Jan 25 2017 03:02
@johnnunns so now just add on to that if statement and check if it's an array
John Nunns
@johnnunns
Jan 25 2017 03:02
so here's the weird part, I added this to the equation
var obj = {
  key: [100, 10, 10]
}

function getElementsThatEqual10AtProperty(obj, key){
var x = []
if(!obj[key]){
    return x;
}else if (!obj[key].hasOwnProperty()){
    return x;
}


return obj[key].filter(number => number === 10) || [];



}
getElementsThatEqual10AtProperty(obj, 'key');
san-te
@san-te
Jan 25 2017 03:03
@moigithub i figured that. but inserting another for loop inside to iterate over the keys didn't seem to work
storbeck
@storbeck
Jan 25 2017 03:03
what's the else if for
Amarillia
@Amarillia
Jan 25 2017 03:03
@coymeetsworld Why do I need to convert the values for the Where do I belong challenge? The array seems to contains integers.
BRlau
@BRlau
Jan 25 2017 03:03
hi can anyone plz help
John Nunns
@johnnunns
Jan 25 2017 03:03
I don't know but now all 4 work
but the main req doesn't
Kevin Patel
@kevpatel7
Jan 25 2017 03:03
Hello! I'm stuck on "Stand in Line". I can't use .shift() to remove first element of array. what am I doing wrong?

function nextInLine(arr, item) {
// Your code here
var array = arr.push(item);
var modArray = array.shift();

return modArray; // Change this line
}

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

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

John Nunns
@johnnunns
Jan 25 2017 03:04
should_return_an_array_containing_all_the_elements_that_equal_10_in_the_array_located_at_key
should return an array containing all the elements equal to 10 in
BRlau
@BRlau
Jan 25 2017 03:04
how to assign processArg to processed
John Nunns
@johnnunns
Jan 25 2017 03:04
sorry the top sentence is the only one failed
zhekau
@zhekau
Jan 25 2017 03:04
@kevpatel7 change array to arr
BRlau
@BRlau
Jan 25 2017 03:04

// Example
var changed = 0;

function change(num) {
return (num + 5) / 3;
}

changed = change(10);

// Setup
var processed = 0;

function processArg(num) {
return (num + 3) / 5;
}

// Only change code below this line
processed = processArg (7);

zhekau
@zhekau
Jan 25 2017 03:05
@kevpatel7 var modArray = arr.shift();
Coy Sanders
@coymeetsworld
Jan 25 2017 03:05
@Amarillia you don't need to convert anything
John Nunns
@johnnunns
Jan 25 2017 03:05
@storbeck got it
var obj = {
  key: [100, 10, 10]
}

function getElementsThatEqual10AtProperty(obj, key){
var x = []
if(!obj[key]){
    return x;
}else if (!Array.isArray(obj[key])){
    return x;
}


return obj[key].filter(number => number === 10) || [];



}
getElementsThatEqual10AtProperty(obj, 'key');
Coy Sanders
@coymeetsworld
Jan 25 2017 03:06
the function takes 2 parameters: an array of integers and another integer. parseInt should not be necessary
__mifflin__
@cdrainxv
Jan 25 2017 03:06
@BRlau: Remove the space b/t processArg and (7). The convention is no space between them and the test might be failing because of that space.
zhekau
@zhekau
Jan 25 2017 03:06
@kevpatel7 actually sorry. it is wrong. I gave the answer without looking
storbeck
@storbeck
Jan 25 2017 03:06
nice congrats
John Nunns
@johnnunns
Jan 25 2017 03:07
if(!obj[key]) was just checking if it even existed correct? @storbeck
Amarillia
@Amarillia
Jan 25 2017 03:07
thanks @coymeetsworld helps a lot :smile:
CamperBot
@camperbot
Jan 25 2017 03:07
amarillia sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star2: 1925 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
Jan 25 2017 03:07
np @Amarillia good luck
BRlau
@BRlau
Jan 25 2017 03:07
@cdrainxv thanks, so the space will always matter in coding?
CamperBot
@camperbot
Jan 25 2017 03:07
:star2: 2183 | @cdrainxv |http://www.freecodecamp.com/cdrainxv
brlau sends brownie points to @cdrainxv :sparkles: :thumbsup: :sparkles:
Kevin Patel
@kevpatel7
Jan 25 2017 03:07
changed modArray to modArray = arr.shift() and it worked. thx!
zhekau
@zhekau
Jan 25 2017 03:07
@kevpatel7 nice.
Anyone can help me with Friendly Date Ranges though?
I can't seem to pass one test. Probably due to the current date
__mifflin__
@cdrainxv
Jan 25 2017 03:11
@BRlau: No… it is still valid code and will be interpreted as such, but the accepted convention is functionName(arguments .. if any); when calling a function. The test to determine if your code is correct is most likely testing that it is exactly written as processArg(7)— at least in my estimation. :smile:
Joseph
@revisualize
Jan 25 2017 03:17
La la la la
Jack Phillips
@jackphillips1994
Jan 25 2017 03:18
Hey Guys i am stuck on the "Title Case a Sentence" one. I can get it to uppercase the first letter. Just having issues lower casing the rest.
Joseph
@revisualize
Jan 25 2017 03:18
@jackphillips1994 Just lowerCase the whole string. Then upperCase the first letter and concatenate the rest of the letters on.
Jack Phillips
@jackphillips1994
Jan 25 2017 03:19
@revisualize ahh that makes so much more sense now aha cheers :)
Joseph
@revisualize
Jan 25 2017 03:21
@jackphillips1994 I mean.. That's kind of what you have to do because strings are immutable.
Amarillia
@Amarillia
Jan 25 2017 03:23
Anyone can tell me how do I know if I need to use a callback function and why it is necessary?
Dylan
@dhcodes
Jan 25 2017 03:25
@Amarillia you need to use a callback function when you want another function to finish before running your callback
Dylan Hsiao
@greedylan
Jan 25 2017 03:26
this passes exercise "Arguments Optional" but I wonder if there is a better way than keep using this Number.isInteger() to check all the condition.

function addTogether() {

  arg1 = arguments[0];
  arg2 = arguments[1];

  if( arguments.length === 2 && Number.isInteger(arguments[0]) && Number.isInteger(arguments[1]) ){

    return arg1 + arg2;  

  }else if( arguments.length === 1 && Number.isInteger(arguments[0]) ){ 

    return function(x){

      if(!Number.isInteger(x)){
        return undefined;
      }

      return arg1 + x; 

    };
  }

}

addTogether(2,3);
Moisés Man
@moigithub
Jan 25 2017 03:26
typeof ?
Amarillia
@Amarillia
Jan 25 2017 03:27
@dhcodes How do I know if I need that? Sorry, still not clear...:(
Dylan
@dhcodes
Jan 25 2017 03:28
@Amarillia javascript run asynchronously meaning a file won't read top to bottom. Therefore if you need something to run in a particular order, you need to use a callback
Edgar Pan
@edgaryp
Jan 25 2017 03:28
Hi, any tips for Roman Numeral Converter?
Dylan Hsiao
@greedylan
Jan 25 2017 03:32
@edgaryp use a recursive method to print the Roman character when subtracting the equal value from regular number. But first you need two relative arrays in order to reference two sets of numbers. This exercise is hard and sorta counter intuition :)
Amarillia
@Amarillia
Jan 25 2017 03:32
@dhcodes so basically I can do it separately but this is a more efficient solution for the performance?
CoryCMyers
@CoryCMyers
Jan 25 2017 03:33

Quick question! Why does this work

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

but this does not

function mutation(arr) {
   var makeStr = arr.toLocaleString ();
      var lowCase = makeStr.toLowerCase(); 
        var splitStr = lowCase.split(',');
          if (splitStr[0].indexOf(splitStr[1]) < 0 ) {
            return false;
          } else {
            return true;
          }

}

mutation(["hello", "hey"]);
John Nunns
@johnnunns
Jan 25 2017 03:34
  return obj[key].reduce(function(a,b){
      return (b+a)/b.length;
  },{});
is this not a good way to find the average using reduce?
Moisés Man
@moigithub
Jan 25 2017 03:35
first one u checking EACH letter of "hey" inside "hello"
second one u checking the WHOLE word "hey" in "hello"
@CoryCMyers
John Nunns
@johnnunns
Jan 25 2017 03:35
tried to use the reduce problem in fcc to find the code and then divide that by what I thought was the array length
find the sum* and then divide that
CamperBot
@camperbot
Jan 25 2017 03:35
find the sum and then divide that
nothing found
Moisés Man
@moigithub
Jan 25 2017 03:36
thats all the code ?? @johnnunns
John Nunns
@johnnunns
Jan 25 2017 03:36
no not at all, just the part that's supposed to find average
Moisés Man
@moigithub
Jan 25 2017 03:36
what data have obj ? whats key ?
if u use second parameter on reduce {}
then a will have that {} as first value
soo inside ur callback u doing ( b+{} )/ {}.length
John Nunns
@johnnunns
Jan 25 2017 03:38
oh god haha that's silly! @moigithub
var obj = {
  key: [1, 2, 3]
};


function getAverageOfElementsAtProperty(obj, key) {

  var x = [];
  if(!obj[key]){
      return x;
  }else if(!Array.isArray(obj[key])){
      return x;
  }
  return obj[key].reduce(function(a,b){
      return (b+a)/b.length;
  },0);

}

getAverageOfElementsAtProperty(obj, 'key');
still returning NaN
Amarillia
@Amarillia
Jan 25 2017 03:39
thanks @dhcodes
CamperBot
@camperbot
Jan 25 2017 03:39
amarillia sends brownie points to @dhcodes :sparkles: :thumbsup: :sparkles:
:star2: 1715 | @dhcodes |http://www.freecodecamp.com/dhcodes
Edgar Pan
@edgaryp
Jan 25 2017 03:39
@greedylan I am so lost
Dylan Hsiao
@greedylan
Jan 25 2017 03:41
@edgaryp i know this one is really hard. but did you understand my hint earlier? I think the key is to use a recursive method to print the Roman character when subtracting the equal value from regular number. and let the function start it again (recursive or loop) and so it will print to the last Roman character
John Nunns
@johnnunns
Jan 25 2017 03:41
^^^ anyone see why the reduce function is not returning the average?
Moisés Man
@moigithub
Jan 25 2017 03:41
if obj[key] is this [1,2,3]
[1,2,3].reduce( (a,b)=>{ .... } ,0)
first value of a wil be 0
first value of b will be 1
soo inside ur callback u doing....
retrn (1+0)/1.length)
but numbers dont have length property
John Nunns
@johnnunns
Jan 25 2017 03:43
right.. ok
var singleVal = array.reduce(function(a,b) {
return b+a;
}, 0);
that returns the sum correctly in fcc
Moisés Man
@moigithub
Jan 25 2017 03:43
yep that will sum all values
John Nunns
@johnnunns
Jan 25 2017 03:44
that's all i'm trying to do and then (i've changed it) divide it by obj[key].length


var obj = {
  key: [1, 2, 3]
};


function getAverageOfElementsAtProperty(obj, key) {

  var x = 0;
  if(!obj[key]){
      return x;
  }else if(!Array.isArray(obj[key])){
      return x;
  }
  return obj[key].reduce(function(a,b){
      return (b+a)/obj[key].length;
  },0);

}

getAverageOfElementsAtProperty(obj, 'key');
Moisés Man
@moigithub
Jan 25 2017 03:45
u can do
totalSum= [1,2,3].reduce( (a,b)=>a+b ,0)
average = totalSum / [1,2,3].length;
.... no need to divide inside...
gorkha1985
@gorkha1985
Jan 25 2017 03:45

guyz , can some one review the below code and recommend the changes as to why the challenge is not getting cleared for me ..factorial of zero(0) function factorialize(num) {
var b= '1';
if (num ===0){
return '1';
}
else{
for(i=1;i<=num;i++) {
b =b*i;

}

 return b;

}
}
factorialize(0);

John Nunns
@johnnunns
Jan 25 2017 03:45
gotcha, so when it's not completed the reduce sum if I'm dividing inside
jamesjd54
@jamesjd54
Jan 25 2017 03:46
is profilelookup (https://www.freecodecamp.com/challenges/profile-lookup) supposed to be really really hard?
i just want to feel better about myself for my extreme struggle with this challenge
Moisés Man
@moigithub
Jan 25 2017 03:47
u not alone.. lot ppl stuck on that one @jamesjd54
jamesjd54
@jamesjd54
Jan 25 2017 03:48
just seems like it came out of nowhere, most of the javascript stuff has been pretty easy but this seems like im going to need to nest multiple loops and i really just dont know where to even start
Moisés Man
@moigithub
Jan 25 2017 03:48
thats an array of object.. u only need 1 loop.. to access each object element
jamesjd54
@jamesjd54
Jan 25 2017 03:49
ok
Moisés Man
@moigithub
Jan 25 2017 03:50
@johnnunns not sure probably can.. or maybe not :) .. but u need to check WHAT values a and b have
and how reduce method works
jamesjd54
@jamesjd54
Jan 25 2017 03:50
thank you, ill try doing it with one
Dylan Hsiao
@greedylan
Jan 25 2017 03:50
@edgaryp say you have integer 36 the Roman number for 36 is XXXVI
so you want to print the first X and subtract 10 from the integer and you are left with 26. Then print another X and subtract another 10, do it one last time so you are left with 6 and X and I and so on.
Manish Giri
@Manish-Giri
Jan 25 2017 03:50
@gorkha1985 why do you have the string '1' instead of the number 1?
Edgar Pan
@edgaryp
Jan 25 2017 03:51
@greedylan not really to be honest, I am searching an article to understand recursive method.
Kevin Anderson
@LemonStain
Jan 25 2017 03:52
Hey Folks - I figured this puzzle out, but I assume there is a simpler way. Correct me if I am wrong. Challenge: Check for Palindromes
function palindrome(str) {
  // Good luck!

  // replace any special symbols from str
  var newstr = str.replace(/[^A-Z0-9]/ig, "");

  // change newstr to lowercase
  var lowstr = newstr.toLowerCase();

  // split lowstr into array
  var splstr = lowstr.split("");

  // reverse the splstr 
  var revstr = splstr.reverse();

  // var revstr = lowstr.reverse();
  var joinstr = revstr.join("");

  // check to see if str = 
  if (lowstr == joinstr) {
    return true;
  } else {
    return false;
  }
}
palindrome("A man, a plan, a canal. Panama");
Manish Giri
@Manish-Giri
Jan 25 2017 03:52
@LemonStain you could get rid of most of the intermediate variables, by chaining functions.
like lowstr.split("").reverse().join("")
Kevin Anderson
@LemonStain
Jan 25 2017 03:53
ahh makes sense
let me try it
thanks @Manish-Giri
CamperBot
@camperbot
Jan 25 2017 03:53
lemonstain sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 3949 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Jan 25 2017 03:53
@LemonStain welcome
Clara Mae Wells
@run-cmw
Jan 25 2017 03:54
I'm stuck on Basic Algorithm Title Case A Sentence. Can anyone help?
How do I add the uppercases in my loop to the array before returning the joined string? Or am I moving in the wrong direction?
function titleCase(str) {
  var array = str.toLowerCase().split(" ");

 //How do I add the uppercases in this loop to the array before returning the joined string?
  for (i = 0; i < array.length; i++) {
    var cap = str[i].charAt(0).toUpperCase();
  }

  return array.join(" ");
}

titleCase("I'm a little tea pot");
Dylan Hsiao
@greedylan
Jan 25 2017 03:55
@edgaryp recursive is a coding concept, it operates similar to for and while loop. you can solve this exercise wtih while loop and compound assignment operators
Manish Giri
@Manish-Giri
Jan 25 2017 03:55
@run-cmw you're storing the uppercased letter in the variable cap, but then what are you doing with it?
you need a way to make the change stick.
Clara Mae Wells
@run-cmw
Jan 25 2017 03:56
I want to add the result of it (capitalized first characters) to my array. @Manish-Giri
Moisés Man
@moigithub
Jan 25 2017 03:56
u also.. need the rest of the word
ie.. from "little" u have
cap="L"
missing "ittle" @run-cmw
Manish Giri
@Manish-Giri
Jan 25 2017 03:57
@run-cmw well yeah, but you're not adding it right now.
Clara Mae Wells
@run-cmw
Jan 25 2017 03:57
Ah. Okay, thanks @moigithub . I'll figure out how to do that.
CamperBot
@camperbot
Jan 25 2017 03:57
run-cmw sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 2598 | @moigithub |http://www.freecodecamp.com/moigithub
Edgar Pan
@edgaryp
Jan 25 2017 03:57
@greedylan so you mean I need to find a way to be able to recognise 3 is tens then digit 3 times 10 so the result is 30 then loop up 30 in roman symbols. Or I am simply getting it all wrong haha lol
Clara Mae Wells
@run-cmw
Jan 25 2017 03:57
@Manish-Giri I know I'm not. That's the question in the comment on my code and on here.
Manish Giri
@Manish-Giri
Jan 25 2017 03:58
@run-cmw okay, one idea is to form the capitalized word in the loop (by concatenating the first uppercased letter with the rest of the letters) and put the word back in position i of the array.
Clara Mae Wells
@run-cmw
Jan 25 2017 03:59
Thank you @Manish-Giri
CamperBot
@camperbot
Jan 25 2017 03:59
run-cmw sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 3950 | @manish-giri |http://www.freecodecamp.com/manish-giri
Dylan Hsiao
@greedylan
Jan 25 2017 03:59
@edgaryp I not quite sure what you mean but if you can write down some number and print their Roman character you would find the logic and your next challenge is to transfer that logic into codes.
@edgaryp 36 - 10, print X
26 - 10, print X,
16 - 10, print X,
6 -5 print V,
1, print I
CoryCMyers
@CoryCMyers
Jan 25 2017 04:04
Would someone please explain this to me? I have read over the explanation pages several times, and I feel absolutely lost.
function destroyer(arr) {
  var args = Array.prototype.slice.call(arguments);
  args.splice(0, 1);
  return arr.filter(function(element) {
    return args.indexOf(element) === -1;
  });
}
Joseph
@revisualize
Jan 25 2017 04:05
@run-cmw Strings are Immutable.
Edgar Pan
@edgaryp
Jan 25 2017 04:06
@greedylan 36 - 10, print X what do you mean by that?
Dylan Hsiao
@greedylan
Jan 25 2017 04:10
@edgaryp bro lets start from the beginning ya? how do you convert a integer 36 into Roman letters?
CoryCMyers
@CoryCMyers
Jan 25 2017 04:10
@Anmar0293 You can drop in the code. Just preface and end it with three `
Anmar0293
@Anmar0293
Jan 25 2017 04:11
@CoryCMyers Sorry I didn't really get it. could you please explain more!
CoryCMyers
@CoryCMyers
Jan 25 2017 04:12
@Anmar0293 You are missing a curly bracket btw. You cna mouse over the erros to get an explanation

So like this I put three ` on a line by themselves


function testElseIf(val) {
  if (val > 10) {
  return "Bigger than 10";
} else if (val < 5) {
  return "Smaller than 5";
} else {
  return "Between 5 and 10";
}

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

The put three ` again on a line alone to end it

Anthony Ciacci
@ciacci1234
Jan 25 2017 04:14
@CoryCMyers may I ask where that solution is from?
the one on the destroyer
Anmar0293
@Anmar0293
Jan 25 2017 04:14
I took it aways but it still not working! code you please show me the correct code!?
Ogundele Olumide
@Lumexralph
Jan 25 2017 04:14
@Anmar0293 you're missing a closing } for your function
CoryCMyers
@CoryCMyers
Jan 25 2017 04:14
@ciacci1234 It is from the wiki. I could not understand the pages it offered as hints for the life of me.
Ken Haduch
@khaduch
Jan 25 2017 04:15

@revisualize :point_up: January 24, 2017 4:21 PM and @JohnnyBizzel :point_up: January 24, 2017 4:23 PM - I saw these earlier but I have been tied up. I have mixed feelings about private messages. I like the fact that it is so much easier to carry on a back and forth conversation there without intervening chat messages and long code postings coming up in between. But I don't really like just getting dragged into a private message session because it then ties you up for that, and it does miss out on the opportunity to get someone else's input on a problem. And you don't get brownie points - even though it can sometimes be an extremely lengthy session :)

But on the other hand - this chat room can be extremely difficult to navigate and find things - the search function works but it doesn't keep information sorted by chronological order, at least I'm looking at a search that is there now and it has Jan 24, Apr 29, Dec 27, etc.

I do think that it should be a mutual decision to take things to a private chat session - sometimes I will go there, see what the question is and come back to the main room to post, it usually works. I do have some good interactions in the private rooms, too, especially if it is something that takes a long time to explain. YAMMV, I guess - really a case-by-case decision that you cannot really make up front. I agree with the general comment that getting exposure to more people's knowledge is better.

Joseph
@revisualize
Jan 25 2017 04:15
WAT!?
Anmar0293
@Anmar0293
Jan 25 2017 04:16
@CoryCMyers Thanks a lot !got it
CamperBot
@camperbot
Jan 25 2017 04:16
anmar0293 sends brownie points to @corycmyers :sparkles: :thumbsup: :sparkles:
:cookie: 265 | @corycmyers |http://www.freecodecamp.com/corycmyers
Anmar0293
@Anmar0293
Jan 25 2017 04:16
@Lumexralph thanks man! much appreciated
CamperBot
@camperbot
Jan 25 2017 04:16
anmar0293 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:cookie: 847 | @lumexralph |http://www.freecodecamp.com/lumexralph
Ogundele Olumide
@Lumexralph
Jan 25 2017 04:17
@Anmar0293 :+1:
Dylan Hsiao
@greedylan
Jan 25 2017 04:17
anyone has hint for converting binary number into integer? I am at exercise "Binary Agents"
Ogundele Olumide
@Lumexralph
Jan 25 2017 04:18
@greedylan you can use a number method
Vizij
@Vizij
Jan 25 2017 04:18

@CoryCMyers

function destroyer(arr) {
  var args = Array.prototype.slice.call(arguments);  // This is complicated. It turns all your arguments into an actual array (they're not at first). It's using the Array global object to execute the slice method on all arguments (which plops each one into an array index), but because you have multiple arguments, you have to tack `.call` onto this. This interprets them as an argument list, and allows you to simply use the arguments variable here. I'll link the .call article below.
  args.splice(0, 1);  // This alters args so that your first argument (arr) is gone. Poof.
  return arr.filter(function(element) {  // Return the result of filter
    return args.indexOf(element) === -1;  // This checks every element in your array against the rest of the arguments provided. If it doesn't find that argument in your array, it stays in. Otherwise, it's cut out.
  });
}

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call

Ken Haduch
@khaduch
Jan 25 2017 04:19
@greedylan - google this: "MDN convert binary number to decimal in javascript" and look at the first link... I think that's what you want.
Dylan Hsiao
@greedylan
Jan 25 2017 04:20
@khaduch parseInt()?
Ogundele Olumide
@Lumexralph
Jan 25 2017 04:20
@greedylan yes
Ken Haduch
@khaduch
Jan 25 2017 04:21
@greedylan - read the documentation! "Read Search Ask" or is it "Search, Read, Ask" or maybe "Ask Search Read"? :) yeah, that's it - try that function.
Ogundele Olumide
@Lumexralph
Jan 25 2017 04:22
@greedylan but take note of the radix to convert to different number bases
Anthony Ciacci
@ciacci1234
Jan 25 2017 04:22
I didn't know about these challenge guides :astonished: thanks for the heads up @CoryCMyers and thanks for the explanation on destroyer @Vizij Spent all day on destroyer -_-
CamperBot
@camperbot
Jan 25 2017 04:22
ciacci1234 sends brownie points to @corycmyers and @vizij :sparkles: :thumbsup: :sparkles:
:cookie: 266 | @corycmyers |http://www.freecodecamp.com/corycmyers
:cookie: 334 | @vizij |http://www.freecodecamp.com/vizij
Dylan Hsiao
@greedylan
Jan 25 2017 04:22
@khaduch yeah I got it now "An integer between 2 and 36 that represents the radix (the base in mathematical numeral systems) of the above mentioned string."
Ken Haduch
@khaduch
Jan 25 2017 04:23
@greedylan - although it might be "fun" to make your own function to do it... I prefer parseInt()
@greedylan - also note that you end up with a character code, not the actual character, so you have to do another step to transform it to a character... one of the String methods...
Edgar Pan
@edgaryp
Jan 25 2017 04:25
@greedylan for 36, 10 + 10 + 10 + 5 + 1 so XXXVI.
Dylan Hsiao
@greedylan
Jan 25 2017 04:28
@khaduch yeah i have no problem with those String methods :)

@edgaryp yeah so you are going to write codes to execute the following process

36 - 10, print X
26 - 10, print X,
16 - 10, print X,
6 -5 print V,
1, print I

please noted the above has nothing to do with actual javascript codes

@khaduch its really hard to write my own function for binary - decimal conversion right?
Ken Haduch
@khaduch
Jan 25 2017 04:36
@greedylan - I don't think that it would be that hard - maybe it could be a fairly simple reduce function? I was giving it a little thought. But I'm signing off for now - maybe I'll try it tomorrow...
Dylan Hsiao
@greedylan
Jan 25 2017 04:37
@khaduch kk later ~
khaduch @khaduch - good night (or day) all - happy coding!
Yong Lee
@yonglee79
Jan 25 2017 04:40
Hello world!
CamperBot
@camperbot
Jan 25 2017 04:40

welcome to FreeCodeCamp @yongslee79!

Ogundele Olumide
@Lumexralph
Jan 25 2017 04:41
@khaduch take care man
@yongslee79 welcome
Yong Lee
@yonglee79
Jan 25 2017 04:41
@Lumexralph thanks
CamperBot
@camperbot
Jan 25 2017 04:41
yongslee79 sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:cookie: 848 | @lumexralph |http://www.freecodecamp.com/lumexralph
Yong Lee
@yonglee79
Jan 25 2017 04:42
gitter looks different
tommy
@tommygebru
Jan 25 2017 04:42
so I just heard about the BETA is FCC now an app i can use offline?
then i can work on it and when i get back online it can upload my challenges?
Ogundele Olumide
@Lumexralph
Jan 25 2017 04:43
@yongslee79 compared to? think the theme got changed
Matt Richards
@mattjrichards
Jan 25 2017 04:43
Can someone help me with the Word Blanks lesson? I'm not quite sure how to get started on this one.
Ogundele Olumide
@Lumexralph
Jan 25 2017 04:44
@tommygebru BETA?
@kilocycle do you know how to join a strings?
Yong Lee
@yonglee79
Jan 25 2017 04:44
@Lumexralph yes seems like it
Matt Richards
@mattjrichards
Jan 25 2017 04:44
with the + ?
Ogundele Olumide
@Lumexralph
Jan 25 2017 04:45
@kilocycle your function has 4 parameters, right.?
Matt Richards
@mattjrichards
Jan 25 2017 04:45
@Lumexralph yes. myNoun, myAdjective, myVerb, myAdverb
Ogundele Olumide
@Lumexralph
Jan 25 2017 04:45
@kilocycle join all your parameters with " " space and + the assign it to result
@kilocycle pardon my typo couldn't edit on phone
Matt Richards
@mattjrichards
Jan 25 2017 04:46
@Lumexralph ok. let me try that.
tommy
@tommygebru
Jan 25 2017 04:46
@Lumexralph yup they started beta
check your email
Ogundele Olumide
@Lumexralph
Jan 25 2017 04:47
@tommygebru interesting.... I'll look it up
CamperBot
@camperbot
Jan 25 2017 04:51
no wiki entry for: here httpswwwfreecodecampcomchallengesreturn-early-pattern-for-functionssolution0a2f2f20setup0afunction20abtesta2c20b207b0a20202f2f20only20change20code20below20this20line0a2020consolelog22a2cb203c0223b0a2020return20undefined3b0a20200a20200a20200a20200a20202f2f20only20change20code20above20this20line0a0a2020return20mathroundmathpowmathsqrta202b20mathsqrtb2c2023b0a7d0a0a2f2f20change20values20below20to20test20your20code0aabtest22c23b0a
Matt Richards
@mattjrichards
Jan 25 2017 04:52

@Lumexralph Well, I tried this, but I don't think this is going to work. Let me try something else.

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

// Your code above this line
return result;
}

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

Ogundele Olumide
@Lumexralph
Jan 25 2017 04:53
@kilocycle remove the "" around the parameters.... you turned them to a string, they're parameters
Matt Richards
@mattjrichards
Jan 25 2017 04:54
@Lumexralph ooops. ok.
Ogundele Olumide
@Lumexralph
Jan 25 2017 04:54
@kilocycle myNoun + " " +....
Matt Richards
@mattjrichards
Jan 25 2017 04:54
@Lumexralph ahhh...ok
Ogundele Olumide
@Lumexralph
Jan 25 2017 04:54
@joehesse can you paste the code here?
Ogundele Olumide
@Lumexralph
Jan 25 2017 04:56
@joehesse you need to write an if statement checking if a or b is less than 0 then you return undefined
Matt Richards
@mattjrichards
Jan 25 2017 04:58

@Lumexralph I ran this and it seems to have worked:

result = myNoun + " " + myAdjective + " " + myVerb + " " + myAdverb;

Ogundele Olumide
@Lumexralph
Jan 25 2017 04:59
@kilocycle yeah, it should
Matt Richards
@mattjrichards
Jan 25 2017 05:00
@Lumexralph the chat seems to have reformatted my code. Am I supposed to put special characters around my code when I paste it in the chat?
I had spaces in between the ""
Ogundele Olumide
@Lumexralph
Jan 25 2017 05:01
@kilocycle passed the tests, right?
rdollent
@rdollent
Jan 25 2017 05:01
can anyone help me?? :(
Matt Richards
@mattjrichards
Jan 25 2017 05:01
@Lumexralph yes, passed test
rdollent
@rdollent
Jan 25 2017 05:01
still stuck with the intermediate algorithm challenge from yesterday.
Yong Lee
@yonglee79
Jan 25 2017 05:01
@rdollent what is it
Matt Richards
@mattjrichards
Jan 25 2017 05:01
@Lumexralph thank you
CamperBot
@camperbot
Jan 25 2017 05:01
kilocycle sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:cookie: 849 | @lumexralph |http://www.freecodecamp.com/lumexralph
rdollent
@rdollent
Jan 25 2017 05:02
this: Make a function that looks through an array of objects (first argument) and returns an array of all objects that have matching property and value pairs (second argument). Each property and value pair of the source object has to be present in the object from the collection if it is to be included in the returned array.
my code:
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  var colProp = [];
  var sourceProp = Object.keys(source);
  for (var i = 0; i < collection.length;i++) {
    colProp.push(Object.keys(collection[i]));
  }
  for (i = 0; i < collection.length;i++) {
    for (var k = 0; k < colProp[i].length;k++) {
        for (var l = 0; l < sourceProp.length; l++) {
        if (collection[i][colProp[i][k]] == source[sourceProp[l]]){
//do something
       }          
    }
  }
  }
  // Only change code above this line
  return arr;
}

whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 });
Yong Lee
@yonglee79
Jan 25 2017 05:02
@rdollent what is a name of the challenge?
rdollent
@rdollent
Jan 25 2017 05:02
Wherefore art thou
my code looks at every single property of source, and compares it to every single property in collection
but, if there are 2 properties in source,,,I don't know what to do.
my test passes if I only got 1 property in source to compare to all properties in collection
Michael
@michaelsndr
Jan 25 2017 05:04
image.png
rdollent
@rdollent
Jan 25 2017 05:04
since iterating only takes one property from both at any given time. that way, the if condition being true is met then i can just extract the array from the collection
Michael
@michaelsndr
Jan 25 2017 05:04
sorry, didn't know this sends right away ..
Joseph
@revisualize
Jan 25 2017 05:04
@michaelsndr contacts is an array
rdollent
@rdollent
Jan 25 2017 05:05
but,,,if source has 2 properties, iterating for every property means I need both 2 properties to be true.
johanna
@joehesse
Jan 25 2017 05:05
@Lumexralph thanks i will try !
CamperBot
@camperbot
Jan 25 2017 05:05
joehesse sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
:cookie: 850 | @lumexralph |http://www.freecodecamp.com/lumexralph
Ogundele Olumide
@Lumexralph
Jan 25 2017 05:06
@michaelsndr just as @revisualize said contacts is an array of objects, you will be needing to loop through it to get the objects
rdollent
@rdollent
Jan 25 2017 05:06
I need to find a way so when iterating, it looks at the 2 properties from source and then look at the properties in each array in collection..but I don't know how to do that.
my function can only look at one property at a time. so, is 1st property in source == 1st property in the 1st array in collection. True? okay. iterate..
I'm lost. :(
Michael
@michaelsndr
Jan 25 2017 05:07
@rdollent @Lumexralph thank you, i will try to figure that out.
CamperBot
@camperbot
Jan 25 2017 05:07
michaelsndr sends brownie points to @rdollent and @lumexralph :sparkles: :thumbsup: :sparkles:
:cookie: 851 | @lumexralph |http://www.freecodecamp.com/lumexralph
:cookie: 292 | @rdollent |http://www.freecodecamp.com/rdollent
heroiczero
@heroiczero
Jan 25 2017 05:08
@rdollent try using hasOwnProperty() maybe if it is a object
rdollent
@rdollent
Jan 25 2017 05:08
@heroiczero can I use multiple properties in hasOwnProperty()?
Michael
@michaelsndr
Jan 25 2017 05:08
@revisualize thank you
CamperBot
@camperbot
Jan 25 2017 05:08
michaelsndr sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3099 | @revisualize |http://www.freecodecamp.com/revisualize
rdollent
@rdollent
Jan 25 2017 05:09
say, if collection[0].hasOwnProperty(Object.keys(source)) or something...
heroiczero
@heroiczero
Jan 25 2017 05:09
@rdollent Object.hasOwnProperty(key) checks if it has the property in the object and returns a true or false
Ogundele Olumide
@Lumexralph
Jan 25 2017 05:09
@rdollent you can use for..... of loop to iterate the source properties at each iteration of the for loop
sorry i mean for.... in loop
Manish Giri
@Manish-Giri
Jan 25 2017 05:10
@Lumexralph actually, for..of is a better idea for arrays, than for..in.
Ogundele Olumide
@Lumexralph
Jan 25 2017 05:11
@Manish-Giri he wants to iterate through objects
@Manish-Giri objects don't have iterator
that's why i suggested the for... in loop to pick every properties of the source object to compare @rdollent @Manish-Giri
rdollent
@rdollent
Jan 25 2017 05:13
i'll read for...of, or for...in
Manish Giri
@Manish-Giri
Jan 25 2017 05:13
okay, I thought it was for the "profile lookup" challenge..
with the contacts array..
Ogundele Olumide
@Lumexralph
Jan 25 2017 05:13
nah, it's not @Manish-Giri
Manish Giri
@Manish-Giri
Jan 25 2017 05:13
cool
rdollent
@rdollent
Jan 25 2017 05:13
if I used .hasOwnProperty(), it still looks at one property at any given time
does that mean
wait what...
Ogundele Olumide
@Lumexralph
Jan 25 2017 05:14
@rdollent yeah do that, it'll come in handy... check how to use for... in
rdollent
@rdollent
Jan 25 2017 05:15
okay let's say it returns true in the first iteration, what then?? it needs to be true for the next iteration, too, and it should remember that it was true from the last iteration
okay i'll read further
heroiczero
@heroiczero
Jan 25 2017 05:15
@rdollent i would use hasOwnProperty() usually in conditional statements
rdollent
@rdollent
Jan 25 2017 05:15
because that's what gets me. I can only do something for any single instance..
Ogundele Olumide
@Lumexralph
Jan 25 2017 05:16
@Manish-Giri Flash was asking for you yesterday though when i challenged her to a duel :wink:
heroiczero
@heroiczero
Jan 25 2017 05:16
@rdollent like your if(conditional statement){}
rdollent
@rdollent
Jan 25 2017 05:16
yea, like what i have..
Manish Giri
@Manish-Giri
Jan 25 2017 05:16
@Lumexralph lol, Flash?
rdollent
@rdollent
Jan 25 2017 05:16
if (collection[i][colProp[i][k]] == source[sourceProp[l]])
Manish Giri
@Manish-Giri
Jan 25 2017 05:16
Margaret?
heroiczero
@heroiczero
Jan 25 2017 05:16
@rdollent then use for loop to check for each element
rdollent
@rdollent
Jan 25 2017 05:17
see, if the property in the first array in collection is equal to the property in source..
@heroiczero I did, but as I said it only works if theres one property in source
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  var colProp = [];
  var sourceProp = Object.keys(source);
  for (var i = 0; i < collection.length;i++) {
    colProp.push(Object.keys(collection[i]));
  }
  for (i = 0; i < collection.length;i++) {
    for (var k = 0; k < colProp[i].length;k++) {
        for (var l = 0; l < sourceProp.length; l++) {
        if (collection[i][colProp[i][k]] == source[sourceProp[l]]){
//do something
       }          
    }
  }
  }
  // Only change code above this line
  return arr;
}

whatIsInAName([{ "a": 1, "b": 2 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }], { "a": 1, "b": 2 });
Joseph
@revisualize
Jan 25 2017 05:18
@rdollent Do objects have lengths?
rdollent
@rdollent
Jan 25 2017 05:18
it goes through all arrays in collection, and to get the property name for each array i used colProp. then I use colProp to refer to the property name of the arrays inside collection i.e. collection[i][colPropr[i][k]]
@revisualize i checked and they do
i think..
Ogundele Olumide
@Lumexralph
Jan 25 2017 05:19
@Manish-Giri yeah @Margaret2 Margaret
Joseph
@revisualize
Jan 25 2017 05:19
I'm getting frustrated with not knowing how to help on that lesson.
I'm just going to finally do it.
I got two to solve. LOL! Then I broke it.
rdollent
@rdollent
Jan 25 2017 05:22
blob
blob
i'll explain my for loop..it goes through collection (has 3 arrays), and then 2nd for loop goes through each array, and for each array goes through all properties. basically. colProp contains the properties for each of the arrays in collection. colProp would be [{a,b}, {a}, {a,b,c}]. I use that to refer to the properties in collection like collection[i][colProp[i][k]] == source[sourceProp[l]] means for ith array in collection which has property name from the kth index in the ith array in colProp..i know, weird.
wait what how did i take a screenshot wthhh
Ogundele Olumide
@Lumexralph
Jan 25 2017 05:24
@rdollent objects have length property but it won't give you the length of it's properties it'll be undefined unlike the sub-objects like Array
rdollent
@rdollent
Jan 25 2017 05:25
@Lumexralph yes it won't, thats why I have colProp
i stored the properties of each array in there
and i use it to say, collection[i].(property) == source[sourceProp]
Ogundele Olumide
@Lumexralph
Jan 25 2017 05:25
@rdollent just helping with a bit of clarity when @revisualize aked you
rdollent
@rdollent
Jan 25 2017 05:27
so my function works only if source has 1 property i can compare it to the arrays in collection,,since iteration is only one property at any given time. if it is true, then i push collection[i] (the whole array) into arr.
but with 2 properties, I'd need it so that once i iterate and it's true, I need the 2nd property to be true as well and then i can push it
but i don't know how to do that..
and it's 1 property of source comparing it to all properties in collection arrays, which means it'll return false the next iteration (say, "a" in source to {"a","b","c"} in 1st array.
so true for first iteration, false for the next two,,,
then move on to "b", which will return false for 1st iteration, then true, then false
BUT, since both "a" and "b" from source are in the 1st array, I need to extract the array anyway..
i'm lost. :(
Emily Sperry
@sperrye
Jan 25 2017 05:30

function sumFibs(num) {
var current = 1;
var previous = 0;
var count = 0;
  while (count <= num) { 
    if (current % 2 !== 0) { 
      count += current; 
    }

    current += previous; 
    previous = current - previous; 
  }

  return count;
}

sumFibs(75024);
All but that plugged in number work fine. It should return 60696 but it returns 135721
rdollent
@rdollent
Jan 25 2017 05:30
it works if I only have 1 property. once it detects true, it'll extract it right away.
Joseph
@revisualize
Jan 25 2017 05:30
OMG this is a crap show on my screen.
Emily Sperry
@sperrye
Jan 25 2017 05:31
Something to do with it being odd
rdollent
@rdollent
Jan 25 2017 05:31
but, if i need 2 properties, i need to make sure that both are true, but iteration only takes 1 property at any given time..
Joseph
@revisualize
Jan 25 2017 05:31
@sperrye :wave:
Ogundele Olumide
@Lumexralph
Jan 25 2017 05:31
@rdollent using a for.... in loop for the source object will help to iterate through all the properties of the source object
Joseph
@revisualize
Jan 25 2017 05:31
Okay Okay.. Here's what I'm doing.
Emily Sperry
@sperrye
Jan 25 2017 05:31
hey @revisualize
rdollent
@rdollent
Jan 25 2017 05:32
@Lumexralph okay i'll read up on it right now..
since it wasn't in the hint section.;;;
Joseph
@revisualize
Jan 25 2017 05:33
Here... This solves two:
function whatIsInAName(collection, source) {
  // What's in a name?
  var arr = [];
  // Only change code below this line
  // var collectionKeys = Object.keys(collection);
  var sourceKey = Object.keys(source);
  return collection.filter(function (x) { return x[sourceKey] === source[sourceKey]; });
  // Only change code above this line
  // return arr;
}

whatIsInAName([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
That solves test where there is only 1 key.
rdollent
@rdollent
Jan 25 2017 05:33
whattttt
Joseph
@revisualize
Jan 25 2017 05:33
HI!
rdollent
@rdollent
Jan 25 2017 05:34
howwwwww
Joseph
@revisualize
Jan 25 2017 05:34
Hi.
Do you even .filter() bro?
rdollent
@rdollent
Jan 25 2017 05:34
so you used [sourceKey] on collection
okay im confused. can you explain the code
Joseph
@revisualize
Jan 25 2017 05:35
Like I said.. That's what I just wrote to try and solve this test.
rdollent
@rdollent
Jan 25 2017 05:35
so you passed collection as x, but in doing so...
collection[sourceKey] detects a property?
Joseph
@revisualize
Jan 25 2017 05:36

Like... from here:

I'm getting frustrated with not knowing how to help on that lesson.
I'm just going to finally do it.

Oh look at that.. My boss just took my main IT switch offline.
I just got blasted with 27 emails.
LOL!
rdollent
@rdollent
Jan 25 2017 05:37
okay hold on can you explain the code?
Joseph
@revisualize
Jan 25 2017 05:37
Sorry. Work things.
One sec.
I have a network module down at work on one of our main switches for a whole building.
My boss just took it offline.
Okay. I'm kind of back
Wat? U want?
Let's start.
[{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }] this is an array.
It's an array of objects.
So, I looked at the instructions.
rdollent
@rdollent
Jan 25 2017 05:39
okay..
Joseph
@revisualize
Jan 25 2017 05:39
I have to keep only the ones where the source (object) property and value match.
I knew about Object.keys ... A little before this.
But.. The instructions ... I clicked the link.
rdollent
@rdollent
Jan 25 2017 05:40
huh?
Joseph
@revisualize
Jan 25 2017 05:41
Do you know what an object property is?
Michael
@michaelsndr
Jan 25 2017 05:41
hello, i am still stuck with the "profile lookup" exercise. i tried to iterate through the array to get the objects, but i can't get it to work. do you have any hints for me? thank you!
Joseph
@revisualize
Jan 25 2017 05:41
{ last: "Capulet" } An object with the property of last and that property has a value of "Capulet"