These are chat archives for FreeCodeCamp/HelpJavaScript

8th
May 2016
Andre Jensen
@andrejensen302
May 08 2016 00:00
@Chrono79 , that would explain a lot.
Christina
@cgraham74
May 08 2016 00:01
help sum all primes
CamperBot
@camperbot
May 08 2016 00:01

:point_right: algorithm sum all primes [wiki]

Explanation:

The explanation for this problem is very simple. You will generate a list of prime numbers up to the number you are given as a parameter. Then you need to add them all up and return that value. The tricky part is on generating the list of prime numbers. I suggest you find a code or a good math algorithm that you can turn into code.

:pencil: read more about algorithm sum all primes on the FCC Wiki

Diego Mayer
@Chrono79
May 08 2016 00:01
@andrejensen302 Don't you have your evaluation inverted?
Renan
@renanav
May 08 2016 00:01
@Chrono79 I didn't quite understand the usage of dot notation and bracket notation
Justin Woodward
@jwoo92
May 08 2016 00:02

function bouncer(arr) {
var falsy = [
  {id: false},
  {id: null},
  {id: 0},
  {id: ""},
  {id: undefined},
  {id: NaN}
];
  function falsyTwo(arr) {
    return arr === true;
  }

}



  var result = arr.filter();
  return result;
}

bouncer([7, "ate", "", false, 9]);
Diego Mayer
@Chrono79
May 08 2016 00:02
@renanav check that challenges again, dot notation can't be used with var names or properties whose name has one or more spaces inside
Andre Jensen
@andrejensen302
May 08 2016 00:02
@Chrono79 , I just caught that. You're right.
Johnathon Sykes
@seesykescode
May 08 2016 00:02
help diff two arrays
CamperBot
@camperbot
May 08 2016 00:02

:point_right: algorithm diff two arrays [wiki]

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

:checkered_flag: Problem Explanation:

Check two arrays and return a new array that contains only the items that are not in either of the original arrays.

Relevant Links

:pencil: read more about algorithm diff two arrays on the FCC Wiki

Norvin Burrus
@ndburrus
May 08 2016 00:03
@renanav did you get it resolved? also, why is a var/iable (variable) being used vs. value - as identified in the challenge? ref: "Write a function which takes an id, a property (prop), and a value." also, check the syntax of the statement: " id[tracks][push] (variable);
" - hint: the object table is not being used... :) the following may be useful: "Property Accessors [dot notation vs. bracket notation] - {ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors}"
Alejandro Napoles
@lexnapoles
May 08 2016 00:03
@jwoo92
function bouncer(arr) {
var falsy = function checkIfFalsy(element) {
      //Boolean transforms a value into boolean
}
  var result = arr.filter(falsy);
  return result;
Diego Mayer
@Chrono79
May 08 2016 00:03
@andrejensen302 you can return false inside your loop, return true only outside it
Some more tips: no need for a counter or converting strings to arrays
You can use indexOf with strings
Andre Jensen
@andrejensen302
May 08 2016 00:05
@Chrono79 yeah I cut out the counter after I realized it wasn't necessary.
@Chrono79 same with the .split('') I had there
Alejandro Napoles
@lexnapoles
May 08 2016 00:06
@jwoo92 If I want to see if some value is true I could try to return something like Boolean(someValue) === true or if I need to give the outer function the boolean value of the element I can return Boolean(someElement)
Justin Woodward
@jwoo92
May 08 2016 00:08
@lexnapoles it still isnt clicking for me.
Diego Mayer
@Chrono79
May 08 2016 00:09
@jwoo92 if you don't change someElement (as the example @lexnapoles gave you) you will filter all or none, you have to use a function that evaluates every element to filter it or not, depending on the element truth value
Alejandro Napoles
@lexnapoles
May 08 2016 00:15

@jwoo92 If I want to filter all numbers greater than 5 in this silly example, I could write:

function filterGreaterThanFive(arr) {
   return arr.filter(function(num) {
         return num > 5;
   });
}

You could try this with:

 [1,2,3,4,5,6,7,8].filter(function(num) {
         return num > 5;
   })

The same result as filterGreaterThanFive( [1,2,3,4,5,6,7,8])

Diego Mayer
@Chrono79
May 08 2016 00:18
This message was deleted
Norvin Burrus
@ndburrus
May 08 2016 00:20
@renanav how are you doing?
Johnathon Sykes
@seesykescode
May 08 2016 00:21
I acccidently created an infinite loop in my challenge
and i can't get it to reset before it starts running the code
is there anything I can do?
Diego Mayer
@Chrono79
May 08 2016 00:22
@johndsykes86 can happen, try opening it in another browser
or clearing cache
Johnathon Sykes
@seesykescode
May 08 2016 00:24
great! didnt know about the disabled bit to the url
Norvin Burrus
@ndburrus
May 08 2016 00:24
@johndsykes86 :+1:
Johnathon Sykes
@seesykescode
May 08 2016 00:24
Thanks @ndburrus
CamperBot
@camperbot
May 08 2016 00:24
johndsykes86 sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 329 | @ndburrus |http://www.freecodecamp.com/ndburrus
Norvin Burrus
@ndburrus
May 08 2016 00:25
@johndsykes86 My pleasure... :sparkles:
Justin Woodward
@jwoo92
May 08 2016 00:25
@lexnapoles im still not getting it, let me take a 15 min break and i will revisit the problem.
a MUCH needed 15 min break
Dominic Lobban
@alkapwn3d
May 08 2016 00:31

function convertToF(celsius) {
var fahrenheit = 9/5+32;
return fahrenheit;
}

convertToF(30);

convertToF(-30) should return a value of -22
im stuck!
Diego Mayer
@Chrono79
May 08 2016 00:32
@alkapwn3d where is celsius in your formula?
Dominic Lobban
@alkapwn3d
May 08 2016 00:32
idk!
Diego Mayer
@Chrono79
May 08 2016 00:33
@alkapwn3d The algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32.
Islam Ibakaev
@dagman
May 08 2016 00:33
hey guys do u remember a little animated guy?!
Dominic Lobban
@alkapwn3d
May 08 2016 00:33
@Chrono79 ooooooh
nope still dont get it
Travis
@dukenukethem
May 08 2016 00:34
@dagman its so cute
Lmao
Diego Mayer
@Chrono79
May 08 2016 00:35
var fahrenheit = 9/5+32; <- put celsius in here
the temperature in Celsius times 9/5, plus 32
Jaspal Sandhu
@JPizzy
May 08 2016 00:35
function falsy(val) {
  return !(val === false || val === null || val === 0 || val === "" || val === undefined || val.isNaN);
}
function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  return arr.filter(falsy);
}

bouncer([1, null, NaN, 2, undefined]);
I could use some help. I have defined a function to pass into filter, but the issue is when I run the tests the resulting array still contains 'null'. All other falsy values are removed. Any idea on whats going on?
Diego Mayer
@Chrono79
May 08 2016 00:36
@JPizzy use Boolean() instead of checking all falsy values one by one
Dominic Lobban
@alkapwn3d
May 08 2016 00:36
-30 returns 3.799999999999997
-10 returns 3.799999999999997
23.799999999999997
Johnathon Sykes
@seesykescode
May 08 2016 00:37
help roman numeral converter
CamperBot
@camperbot
May 08 2016 00:37
no wiki entry for: roman numeal converter
Dominic Lobban
@alkapwn3d
May 08 2016 00:37
you mean like this?
var fahrenheit = 9/5+32-10;
Diego Mayer
@Chrono79
May 08 2016 00:37
@alkapwn3d that's because you haven't celsius in your formula
without a var in there you'll get always the same result
Delete that -10, put celsius where it belong, read the algorithm again
Johnathon Sykes
@seesykescode
May 08 2016 00:37
help roman numeral converter
CamperBot
@camperbot
May 08 2016 00:37

:point_right: algorithm roman numeral converter [wiki]

Problem Explanation:

  • You will create a program that converts an integer to a Roman Numeral.
:pencil: read more about algorithm roman numeral converter on the FCC Wiki
Paweł Przytuła
@paprzytula
May 08 2016 00:38
this time my mutant works. I've removed ===true, changed !== -1 to=== - 1 and switched true & false.
However still don't know why the !== -1 didn't work.
function mutation(arr) {
  var lower = arr.map(function(value) {
      return value.toLowerCase();
});
var a1 = lower[1];
var b1 = a1.split('');  
var a0 = lower[0];
  for (i = 0; i < b1.length; i++) {
 if (a0.indexOf(b1[i]) === -1)
   return false;
   }
  return true;
}
mutation(["hello", "hey"]);
Pete McPherson
@StartupDino
May 08 2016 00:38
global scope and functions
help global scope and functions
CamperBot
@camperbot
May 08 2016 00:39

:point_right: challenge global scope and functions [wiki]

Challenge: Global Scope and Functions

In JavaScript, scope refers to the visibility of variables. Variables which are defined outside of a function block have Global scope. This means, they can be seen everywhere in your JavaScript code.

Variables which are used without the var keyword are automatically created in the global scope. This can create unintended consequences elsewhere in your code or when running a function again. You should always declare your variables with var.
:pencil: read more about challenge global scope and functions on the FCC Wiki

Diego Mayer
@Chrono79
May 08 2016 00:40
@paprzytula you're doing unneeded things there but the idea is if one letter of the second word isn't in the first, return false, else return true
unneeded for example is converting the second word to an array
Dominic Lobban
@alkapwn3d
May 08 2016 00:40
@Chrono79 you talk as if I know what the hell im doing lol
Alejandro Napoles
@lexnapoles
May 08 2016 00:41

@JPizzy Your code returns [1, NaN, 2]. isNaN is not a property of val, it is a function, you have to call it like any other normal function: isNaN(val) instead of val.isNaN

I would suggest if you haven't done it yet to read Boolean

Diego Mayer
@Chrono79
May 08 2016 00:41
@alkapwn3d ok, I've tried, do you want the code ?
Ashw
@asharhw
May 08 2016 00:42
hey guys, can anybody competent tell me why i can't get location here: http://codepen.io/asharhw/pen/WwPRVK everything seems good to me... can't get it
Dominic Lobban
@alkapwn3d
May 08 2016 00:42
yes because im not going to get it
Diego Mayer
@Chrono79
May 08 2016 00:43
var fahrenheit = celsius * 9/5+32;
the temperature in Celsius times 9/5, plus 32
it's not so hard, isn't it?
Travis
@dukenukethem
May 08 2016 00:44
```js

function repeatStringNumTimes(str, num) {
str = str.repeat(num);
return str;
}

repeatStringNumTimes("abc", -2);


function repeatStringNumTimes(str, num) {
  str = str.repeat(num);
  return str;
}

repeatStringNumTimes("abc", -2);
Ashw
@asharhw
May 08 2016 00:44
So strange, now it's working!! Here it works, but on codepen it won't!!! What is wrong?
Diego Mayer
@Chrono79
May 08 2016 00:44
@asharhw the console in Chrome says this:
getCurrentPosition() and watchPosition() are deprecated on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.
Travis
@dukenukethem
May 08 2016 00:44
so i can get my code to pass all arguments other than the last one in repeat a string
Diego Mayer
@Chrono79
May 08 2016 00:45
@dukenukethem use a loop and += operator
or put an if before your repeat and return "" if it's <0
Paweł Przytuła
@paprzytula
May 08 2016 00:46
I've removed the array and the mutant still works. thank you @Chrono79
CamperBot
@camperbot
May 08 2016 00:46
paprzytula sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 659 | @chrono79 |http://www.freecodecamp.com/chrono79
Ashw
@asharhw
May 08 2016 00:47
@Chrono79 Thanks!! I had to open codepen with https!!! -
CamperBot
@camperbot
May 08 2016 00:47
asharhw sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 660 | @chrono79 |http://www.freecodecamp.com/chrono79
Dominic Lobban
@alkapwn3d
May 08 2016 00:47
referenceerror: celcius is not defined
Paweł Przytuła
@paprzytula
May 08 2016 00:47
cookie monster:D
Dominic Lobban
@alkapwn3d
May 08 2016 00:47
now what
Diego Mayer
@Chrono79
May 08 2016 00:47
@alkapwn3d it's celsius, not celcius
Travis
@dukenukethem
May 08 2016 00:48

function repeatStringNumTimes(str, num) {

  while (str >= 0) {
    str = str.repeat(num);

  }
 return str;
}

repeatStringNumTimes("abc", 3);
Dominic Lobban
@alkapwn3d
May 08 2016 00:48
yes that
Travis
@dukenukethem
May 08 2016 00:48
this is what i've altered it to and im pretty sure im in the wrong direction
Dominic Lobban
@alkapwn3d
May 08 2016 00:48
celsius not defined
Diego Mayer
@Chrono79
May 08 2016 00:48
@dukenukethem no, as I said, loop and += or not loop and an if before
@alkapwn3d paste your whole code again
@dukenukethem also that loop could be an infinite loop
Dominic Lobban
@alkapwn3d
May 08 2016 00:49
nvm got it thx
Travis
@dukenukethem
May 08 2016 00:50
is it because it could >= ?
Diego Mayer
@Chrono79
May 08 2016 00:51
@dukenukethem str is a string and you're comparing it with a number, don't know what will result in that
I think you wanted to write num there
But again, if you use repeat, no need for the loop, just write an if and return early
The loop and using += operator to concatenate is a different solution
Travis
@dukenukethem
May 08 2016 00:52
./facedesk
I thought I had a grasp of this challenge and it's proving I don't know Jack.
Diego Mayer
@Chrono79
May 08 2016 00:56
I can show you the solution with the loop and you can fix yours
so you see both ways of doing it
Travis
@dukenukethem
May 08 2016 00:58

function repeatStringNumTimes(str, num) {
if (num === 0) {
  return str;
} else if (num > 0) {
  var newV = "";
  for (i=0; i < num; i++); {
    newV += str;
  }
  return newV;
} else {
  return "";
}

}
:D
Diego Mayer
@Chrono79
May 08 2016 00:59
@dukenukethem shorter, and repeat 0 times should return ""
function repeat(str, num) {
  var newStr = "";
  for (var i=0; i<num; i++) { newStr += str; }
  return newStr;
}
Zaw Ye Htut
@yeyezaw
May 08 2016 01:00
Could someone hint to find longest word in a string ?
Diego Mayer
@Chrono79
May 08 2016 01:00
Because repeatStringNumTimes("abc", 1) should return "abc".
help find longest word in a string
CamperBot
@camperbot
May 08 2016 01:01
no wiki entry for: find longest word in a string
Islam Ibakaev
@dagman
May 08 2016 01:01
@Chrono79
function repeatStringNumTimes(str, num) {
  return Array(num > 0 ? num + 1 : 0).join(str);
}
Diego Mayer
@Chrono79
May 08 2016 01:02
@yeyezaw you can use a loop and a var to store the length of the longest word
Travis
@dukenukethem
May 08 2016 01:03
@Chrono79 how would i make my code show 0 times if the num is 0?
Im not quite understanding your code
Zaw Ye Htut
@yeyezaw
May 08 2016 01:03
Okay, I will try @Chrono79
Diego Mayer
@Chrono79
May 08 2016 01:03
@dagman I know there are shorter ways, but I prefer easier reading when they're trying to understan what's happening there

@dukenukethem

function repeatStringNumTimes(str, num) {
if (num > 0) {
  var newV = "";
  for (i=0; i < num; i++); {
    newV += str;
  }
  return newV;
} else {
  return "";
}

}

Like this?

Travis
@dukenukethem
May 08 2016 01:05
Ohhh okay
so instead of ===
its >
?
and a for loop as well
Diego Mayer
@Chrono79
May 08 2016 01:07
@dukenukethem I've deleted your case when num === 0 and left the rest the same
I'll be afk for a while, dinner is ready
CyrilSL
@CyrilSL
May 08 2016 01:09
Hey I'm in https://www.freecodecamp.com/challenges/convert-html-entities and I have no idea where and how to start
Here is the character references https://dev.w3.org/html5/html-author/charref how should I pull this.
Travis
@dukenukethem
May 08 2016 01:11
heh; this next challenge looks insane
CyrilSL
@CyrilSL
May 08 2016 01:11
And what is RegExp I read many websites and I am still blank over this.
John KM J
@rkdmen
May 08 2016 01:14

function titleCase(str) {
var arrWords = str.split(" ");
var result = "";
for (var i=0; i<arrWords.length; i++){
var word = arrWords[i];

var firstLetter = word.charAt(0).toUpperCase();
 var lowerLetter = word.slice(1).toLowerCase()

}

var joined = firstLetter.concat(lowerLetter)
return joined;

}

hi guys..why is my code only printing out pot..I'm on Title a case sentence problem
its not printing "I'm a little tea pot"
only printing last word Pot...any help would be great, thanks
CyrilSL
@CyrilSL
May 08 2016 01:15
What challenge is this.
Send link.
CyrilSL
@CyrilSL
May 08 2016 01:18

'''function titleCase(str) {
str = str.toLowerCase().split(' ');

for(var i = 0; i < str.length; i++){
str[i] = str[i].split('');
str[i][0] = str[i][0].toUpperCase();
str[i] = str[i].join('');
}
return str.join(' ');
}
titleCase("I'm a little tea pot");

CamperBot
@camperbot
May 08 2016 01:18
:bulb: to format code use backticks! ``` more info
John KM J
@rkdmen
May 08 2016 01:19
oh wow, thank you.. @CyrilSL
CamperBot
@camperbot
May 08 2016 01:19
rkdmen sends brownie points to @cyrilsl :sparkles: :thumbsup: :sparkles:
:cookie: 289 | @cyrilsl |http://www.freecodecamp.com/cyrilsl
Renan
@renanav
May 08 2016 01:20

@Chrono79 How's this?


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

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

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

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


  return collection[id][prop];
}

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

Well, it's broken...

Diego Mayer
@Chrono79
May 08 2016 01:21

@renanav fix this

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

make sure value != "" here too
don't use dot notation with vars (id)
it's either ["tracks"] or .tracks not [tracks] (you can also use [prop])
Also, at the end, return collection; not collection[id][prop]

Bryan Castleman
@castlemaninc
May 08 2016 01:29
How do I insert a dash before the matched uppercase letter? I am using regular expressions, but can't figure that part out. I have everything else working on the 'Spinal Tap Case' challenge.
Norvin Burrus
@ndburrus
May 08 2016 01:32
@renanav it may be helpful to be consistent in the logic approach - using value/prop, value/prop, value for the decision criteria in the if/else if flow control statements! :) also, review the logic overall (the first if/else if looks good) logic - start with the first else...
Diego Mayer
@Chrono79
May 08 2016 01:32
@castlemaninc you could use a second replace + regex
Renan
@renanav
May 08 2016 01:34
@Chrono79 @ndburrus I'm still trying to understand the syntax behind "it's either ["tracks"] or .tracks not [tracks]"
This message was deleted
Diego Mayer
@Chrono79
May 08 2016 01:35
@renanav tracks is not a var so [tracks] won't work
there is a property whose name is tracks, so using bracket notation you should use it like this: ["tracks"] or using dot notation like this .tracks
Brendon
@Balvamar
May 08 2016 01:35
Hi all, I am stuck on "random quote" I do not understand How to get access to an external API. Any help or resources much appreciated 😉
Renan
@renanav
May 08 2016 01:36
what is a var here?
Diego Mayer
@Chrono79
May 08 2016 01:36
id, prop and value, your function params are all vars (variables)
Norvin Burrus
@ndburrus
May 08 2016 01:36
@renanav ok, use quotations for tracks.. the following may be useful: "Property accessors" (dot vs. bracket notation), https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors
Diego Mayer
@Chrono79
May 08 2016 01:37
@ndburrus I think it's more consistent if he uses [prop], I only mentioned the other ways of doing it so he can see all the options
prop === "tracks" by the way
Norvin Burrus
@ndburrus
May 08 2016 01:38
This message was deleted
Renan
@renanav
May 08 2016 01:39
@Chrono79 @ndburrus This link help.
Thanks
Norvin Burrus
@ndburrus
May 08 2016 01:41
@Chrono79 You're welcome.... how are you doing? can you post when you have an update?
Diego Mayer
@Chrono79
May 08 2016 01:43
@ndburrus I think you mentioned me by mistake in that last post ;)
shamieya
@shamieya
May 08 2016 01:50
feeling completely defeated with trying to use an API for the weather challenge....just sharing
Shane Murphy
@ShaneMurphy91
May 08 2016 01:52
hey can anyone help me with the switch statement?
Selecting from many options with Switch Statements
Norvin Burrus
@ndburrus
May 08 2016 01:53
@ShaneMurphy91 can you post what you've got?
Shane Murphy
@ShaneMurphy91
May 08 2016 01:56
@ndburrus its ok, I just got it working! I was using a wrong statement :worried: thanks though
CamperBot
@camperbot
May 08 2016 01:56
shanemurphy91 sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 330 | @ndburrus |http://www.freecodecamp.com/ndburrus
Diego Mayer
@Chrono79
May 08 2016 01:57
@shamieya You can prepend your url with http://crossorigin.me/ or look into jsonp if that's the problem
Norvin Burrus
@ndburrus
May 08 2016 01:57
@ShaneMurphy91 Great work! :sparkles:
Bryan Castleman
@castlemaninc
May 08 2016 02:01
@Chrono79 Not sure I get what you mean. Currently I'm chaining a bunch of replace methods to satisfy the other parts.
Diego Mayer
@Chrono79
May 08 2016 02:02
@castlemaninc show me what you have so far
Elbert Cortez
@trip16661
May 08 2016 02:02
One question with regEx
Jeff
@meankraken
May 08 2016 02:02
@shamieya I can try to help you, can you link the pen?
Diego Mayer
@Chrono79
May 08 2016 02:03
@trip16661 Do it
Bryan Castleman
@castlemaninc
May 08 2016 02:03
@Chrono79 I forget how to insert my code here. What was the trick?
Diego Mayer
@Chrono79
May 08 2016 02:03
help format
CamperBot
@camperbot
May 08 2016 02:03

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

Elbert Cortez
@trip16661
May 08 2016 02:03
i want to match foo if there like another simbol behind it like $foo
i tried looking online but all i find is lookbehind and as far as i read it cant be used in javascript
Diego Mayer
@Chrono79
May 08 2016 02:05
@trip16661 forget that comment
Elbert Cortez
@trip16661
May 08 2016 02:06
@Chrono79 y i tried but it says it dont work with it xD
Jeff
@meankraken
May 08 2016 02:06
@trip16661 can you be more specific.. what do you mean another symbol? as in any character?
Elbert Cortez
@trip16661
May 08 2016 02:06
for example foo if it has a $ before it
Jeff
@meankraken
May 08 2016 02:07
then you'd just do /\$foo/g
Elbert Cortez
@trip16661
May 08 2016 02:07
i just want foo not $
Diego Mayer
@Chrono79
May 08 2016 02:07
@trip16661 you can match $foo, and then strip $
Coy Sanders
@coymeetsworld
May 08 2016 02:08
or use lookaheads @trip16661
better way
Elbert Cortez
@trip16661
May 08 2016 02:08
so it would work if like replace it?
i mean will it keep the $
Bryan Castleman
@castlemaninc
May 08 2016 02:09
function spinalCase(str) {
  // "It's such a fine line between stupid, and clever."
  // --David St. Hubbins

  return str.replace(/ /g,'-').replace(/_/g,"-").toLowerCase();
}

spinalCase('This Is Spinal Tap');
Elbert Cortez
@trip16661
May 08 2016 02:09
cuz i still need that $
Bryan Castleman
@castlemaninc
May 08 2016 02:09
@Chrono79 see above.
Diego Mayer
@Chrono79
May 08 2016 02:10
@castlemaninc is that all? How do you manage this? spinalCase("thisIsSpinalTap") should return "this-is-spinal-tap".
I think that first, you should solve that case and later you can use a second replace
str.replace(/ /g,'-').replace(/_/g,"-")
//could be shorter this way
str.replace(/ |_/g,'-')
Elbert Cortez
@trip16661
May 08 2016 02:11
@coymeetsworld how can i use lookahead in that case?
Elbert Cortez
@trip16661
May 08 2016 02:17
@meankraken that dont work in this case \D(-\d) where i want to match( -\d)
deyvidyury
@deyvidyury
May 08 2016 02:19
Hi guys. I'm having problems with challenge Steamroller, to flatten a nested array. I'm getting the right answer, the difference is that my array don't have a space between coma and number. Does anyone know if there is a bug?
*comma
Diego Mayer
@Chrono79
May 08 2016 02:20
@deyvidyury paste your code
deyvidyury
@deyvidyury
May 08 2016 02:20

var result = [];

function steamrollArray(arr) {
flatten(arr);
return result;
}

function flatten(arr){
for(var i=0;i < arr.length; i++){
if (Array.isArray(arr[i])){
flatten(arr[i]);
} else {
result.push(arr[i]);
}
}
}

steamrollArray([1, 2, [3, [[4]]]]);

Diego Mayer
@Chrono79
May 08 2016 02:23
@deyvidyury I think the problem is you created a global var
Bryan Castleman
@castlemaninc
May 08 2016 02:23
@Chrono79 yeah I figured there was a way to make it shorter, but I didn't know how. Thanks for that. But, I still don't understand how to get thisIsSpinalTap to become hyphenated.
CamperBot
@camperbot
May 08 2016 02:23
castlemaninc sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 661 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
May 08 2016 02:24
@castlemaninc the basic problem is to solve that case, the other cases you can do replaces not so complex
deyvidyury
@deyvidyury
May 08 2016 02:24
@Chrono79 sorry, but I don't see your point
Diego Mayer
@Chrono79
May 08 2016 02:24
@deyvidyury I think the challenge is not passing because of that, the result returned is ok
Bryan Castleman
@castlemaninc
May 08 2016 02:25
@Chrono79 , okay. So, I'll figure something else out then. Thanks. I thought there was a regular expression for that. I just can't find it in any of the documentation.
CamperBot
@camperbot
May 08 2016 02:25
castlemaninc sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: castlemaninc already gave chrono79 points
deyvidyury
@deyvidyury
May 08 2016 02:25
ok. Thanks. I'll check this.
Diego Mayer
@Chrono79
May 08 2016 02:26
@castlemaninc look for regex grouping
Bryan Castleman
@castlemaninc
May 08 2016 02:27
ok
deyvidyury
@deyvidyury
May 08 2016 02:27
@Chrono79 You're right. I just got it. Thanks a lot.
CamperBot
@camperbot
May 08 2016 02:27
deyvidyury sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 662 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
May 08 2016 02:28
@deyvidyury no problem, sometimes the challenge passing or not depends on things like that
Taylor
@13xray13
May 08 2016 02:36
convert cells to fahrenheit? WTF
celsius*
Kyle W Pilkinton
@tadake
May 08 2016 02:48
hey guys i was wondering if anyone could explain what in supposed to do on Record Collection in basic javascript
Swaroop
@swaroopamir
May 08 2016 02:49
Encode the following sequence, separated by spaces:

Encode the following sequence, separated by spaces:
backslash tab tab carriage-return new-line and assign it to myStr

how to achieve solution for this?

Diego Mayer
@Chrono79
May 08 2016 02:53

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

For the given id in collection:

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

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

If value is blank, delete that prop.

Always return the entire collection object.

bitgrower
@bitgrower
May 08 2016 02:53
@tadake -- record collection is an challenge dealing with JSON objects ... well, you deal with JSON objects like the previous challenges dealing with objects show you ... so ... I would recommend reviewing the previous challenges on objects ... they will help you a lot ...
Diego Mayer
@Chrono79
May 08 2016 02:54
@swaroopamir use the values they give you in the table in the challenge description
i.e.
Encode the following sequence, separated by spaces:
tab tab and assign it to myStr
would be like this: var myStr = "\t \t";
Kyle W Pilkinton
@tadake
May 08 2016 02:54
thanks @Chrono79 @bitgrower
CamperBot
@camperbot
May 08 2016 02:54
tadake sends brownie points to @chrono79 and @bitgrower :sparkles: :thumbsup: :sparkles:
:cookie: 663 | @chrono79 |http://www.freecodecamp.com/chrono79
:star2: 1035 | @bitgrower |http://www.freecodecamp.com/bitgrower
Swaroop
@swaroopamir
May 08 2016 02:55
@Chrono79 can I use those sequences between double quotes?
Iskya
@iskya
May 08 2016 02:55
Hi.. anyone could help me? I don't know what i'm doing wrong with the Profile Lookup of the javascript?
Swaroop
@swaroopamir
May 08 2016 02:56
@Chrono79 var myStr="\b \t \t \r \n"; is this right?
Diego Mayer
@Chrono79
May 08 2016 02:56
@swaroopamir almost, \b doesn't exist
Kyle W Pilkinton
@tadake
May 08 2016 02:56
what do i set the value of prop too? @Chrono79
Diego Mayer
@Chrono79
May 08 2016 02:56
@tadake didn't understand that question, please rephrase it or show me some code
Iskya
@iskya
May 08 2016 02:58
??
Diego Mayer
@Chrono79
May 08 2016 02:58
@iskya paste your code
Kyle W Pilkinton
@tadake
May 08 2016 02:58
you said i had to update or set the value for prop and im not sure what its supposed to be @Chrono79
Iskya
@iskya
May 08 2016 02:58

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

if(contact[i].firstName == firstName && contact[i].firstName.prop == prop){
return contacts[i].prop;
}
else if (contacts[i].hasOwnProperty(prop)){
return "No such property";
}
else if(contacts[i].firstName !== firstName){
return "No such contact";
}

}

Coy Sanders
@coymeetsworld
May 08 2016 02:58
\b exists, just not the right escape sequence
Diego Mayer
@Chrono79
May 08 2016 02:58
@tadake the param value
Coy Sanders
@coymeetsworld
May 08 2016 02:58
@swaroopamir
Diego Mayer
@Chrono79
May 08 2016 02:59
@coymeetsworld I meant in that sequence, my bad
Swaroop
@swaroopamir
May 08 2016 02:59
@coymeetsworld then instead \b what should we use?
Coy Sanders
@coymeetsworld
May 08 2016 02:59
the table has it @Chrono79 its for backspace, but @swaroopamir needs backslash
Diego Mayer
@Chrono79
May 08 2016 02:59
@coymeetsworld my bad again
Coy Sanders
@coymeetsworld
May 08 2016 02:59
:)
Diego Mayer
@Chrono79
May 08 2016 03:00
@swaroopamir \\ backslash
I can see that backslash and backspace may sound similar
Coy Sanders
@coymeetsworld
May 08 2016 03:01
yeah, ive seen people have that problem before
Diego Mayer
@Chrono79
May 08 2016 03:01
@iskya a few wrong things there
don't use dot notation where you can't use it, use bracket notation
don't return "No such contact" inside your loop
check you first else if condition, I don't think it's right
your for condition is wrong too
Iskya
@iskya
May 08 2016 03:02
I'm reading you
Swaroop
@swaroopamir
May 08 2016 03:02
I used both \ and \ its not working
I used both \ and \ its not working
Coy Sanders
@coymeetsworld
May 08 2016 03:03
can you post entire thing again @swaroopamir, put them between ```
Diego Mayer
@Chrono79
May 08 2016 03:04
or between `after all it's only one line
Coy Sanders
@coymeetsworld
May 08 2016 03:04
yeah either or
Swaroop
@swaroopamir
May 08 2016 03:05
Encode the following sequence, separated by spaces: backslash tab tab carriage-return new-line and assign it to myStr
Coy Sanders
@coymeetsworld
May 08 2016 03:05
i meant your solution :)
anthonyjl92
@anthonyjl92
May 08 2016 03:05
hey guys I was wondering how to go about writing a javascript program that updates what the user inputs in real time?
for example if a user writes "hello world", the program would update that to "Hello world" where it'll capitalize the first letter in a new sentence
Swaroop
@swaroopamir
May 08 2016 03:06
var myStr="\b \t \t \r \n";
Diego Mayer
@Chrono79
May 08 2016 03:06
@anthonyjl92 you could bind the event on change of the input field
Swaroop
@swaroopamir
May 08 2016 03:06
@coymeetsworld
Coy Sanders
@coymeetsworld
May 08 2016 03:06
@swaroopamir its what we said before, \b is backspace, not backslash
look at the sequence for backslash
everything else is good
Swaroop
@swaroopamir
May 08 2016 03:08
sorry I its my fault I didn't see properly thank you @coymeetsworld
CamperBot
@camperbot
May 08 2016 03:08
:cookie: 765 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
swaroopamir sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
Dylan
@dhcodes
May 08 2016 03:08
@anthonyjl92 i sort of did that with my wikipedia viewer. I made each key entry call the function
Coy Sanders
@coymeetsworld
May 08 2016 03:08
ok np @swaroopamir, I've seen others have that problem before too
Dylan
@dhcodes
May 08 2016 03:08
so when the user types each letter it runs your function
@anthonyjl92
Swaroop
@swaroopamir
May 08 2016 03:08
@camperbot brownie point means
Coy Sanders
@coymeetsworld
May 08 2016 03:09
help brownie point
CamperBot
@camperbot
May 08 2016 03:09

:point_right: brownie points [wiki]

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

A user profile picture next to a with Brownie Points score

There are two ways you can get Brownie Points:

  1. Complete challenges - you get one point per challenge you complete
  2. Help other campers in chat - each time you help another camper and they thank you (by typing "thanks @yourname"), you will get a point

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

They also add to your Streak.

:pencil: read more about brownie points on the FCC Wiki

Dylan
@dhcodes
May 08 2016 03:09
@swaroopamir they're like kudos for helping people or completing challenges
you can give them by saying thanks and then @ a person's username
Diego Mayer
@Chrono79
May 08 2016 03:10
@swaroopamir trying to have a conversation with camperbot will dissapoint you ;)
He only reply to commands like help something or wiki something
Swaroop
@swaroopamir
May 08 2016 03:12
Thanks @coymeetsworld
CamperBot
@camperbot
May 08 2016 03:12
swaroopamir sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:warning: swaroopamir already gave coymeetsworld points
Iskya
@iskya
May 08 2016 03:12
@Chrono79 I've seen the error in the for condition, but I dont understand the rest
Dylan
@dhcodes
May 08 2016 03:12
camperbot, don't listen to @Chrono79. you can be my frined
@camperbot you the best
Diego Mayer
@Chrono79
May 08 2016 03:12
@dhcodes lol

@iskya Ok, let's review the other problems

for(var i=0; i>contacts.length; i++){
if(contact[i].firstName == firstName && contact[i].firstName.prop == prop){
return contacts[i].prop;
}
else if (contacts[i].hasOwnProperty(prop)){
return "No such property";
}
else if(contacts[i].firstName !== firstName){
return "No such contact";
}
}

don't use dot notation where you can't use it, use bracket notation <- if you use a var to refer an object property, you have to use bracket notation like this contacts[i][prop]
don't return "No such contact" inside your loop <- you have to look at all the contacts before ypu know for sure there is no such contact in there
check you first else if condition, I don't think it's right <- contacts[i].hasOwnProperty(prop) means that it has that property and you have to get the opposite to return "No such property" and also make sure that contact[i].firstName == firstName
Your first if condition is also wrong here: contact[i].firstName.prop == prop

Dylan
@dhcodes
May 08 2016 03:13
@camperbot how's it going?
anthonyjl92
@anthonyjl92
May 08 2016 03:14
@dhcodes @Chrono79 ty! for the ideas
CamperBot
@camperbot
May 08 2016 03:14
anthonyjl92 sends brownie points to @dhcodes and @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 664 | @chrono79 |http://www.freecodecamp.com/chrono79
:cookie: 751 | @dhcodes |http://www.freecodecamp.com/dhcodes
Iskya
@iskya
May 08 2016 03:19

@iskya and now : for(var i=0; i< contacts.length; i++){

if(contacts[i].firstName == firstName && contacts[i].hasOwnProperty(prop) == prop){
return contacts[i][prop];
}
else {
return "No such property";
}
}

return "No such contact";

Diego Mayer
@Chrono79
May 08 2016 03:20
@iskya you can use a nested if using in your first if this condition if(contact[i].firstName == firstName)
@iskya remember the first if (it has 2 conditions joined by the AND operator), could be false if any of the 2 conditions is false
Iskya
@iskya
May 08 2016 03:21
ohhhhhh you're right.... i didnt see it
thanx
Diego Mayer
@Chrono79
May 08 2016 03:22
no problem
Philip Warkentien II
@warkentien2
May 08 2016 03:33
Anybody else's weather API stopped working for security purposes (or other reasons)?
Diego Mayer
@Chrono79
May 08 2016 03:35
@warkentien2 If you use Chrome, yes, they've changed something that broke it after version 50
https://mobiforge.com/news-comment/no-https-then-bye-bye-geolocation-in-chrome-50
There are some workarounds, but I don't remember right now
Philip Warkentien II
@warkentien2
May 08 2016 03:37
This message was deleted
@Chrono79 that's what I thought. So I tried Mozilla but it's not working as well. Even worst, it doesn't even show an error on the console for debugging.
Diego Mayer
@Chrono79
May 08 2016 03:38
if it's a codepen paste the link
someone will complain this is not in /CodeReview
This message was deleted
This message was deleted
Diego Mayer
@Chrono79
May 08 2016 03:40
it also reported this in Chrome: {"cod":401, "message": "Invalid API key. Please see http://openweathermap.org/faq#error401 for more info."}
Ajith
@ajithvallabai
May 08 2016 03:41
is any one working on Title case a sentence algorithm now?
Diego Mayer
@Chrono79
May 08 2016 03:41
But I suspect that change in geoLocation policies is what's preventing it to work
Philip Warkentien II
@warkentien2
May 08 2016 03:41
It'll try the key first. thanks! @Chrono79
CamperBot
@camperbot
May 08 2016 03:41
warkentien2 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 665 | @chrono79 |http://www.freecodecamp.com/chrono79
Johnathon Sykes
@seesykescode
May 08 2016 03:42
help where art thou
CamperBot
@camperbot
May 08 2016 03:43

:point_right: algorithm where art thou [wiki]

Problem Explanation

Write an algorithm that will take an array for the first argument and return an array with all the objects that matches all the properties and values in the Object passed as second parameter.

:pencil: read more about algorithm where art thou on the FCC Wiki

Diego Mayer
@Chrono79
May 08 2016 03:43
@ajithvallabai No, but you can show me your code if I can help
Ajith
@ajithvallabai
May 08 2016 03:46

function titleCase(str) {
  var rx=/\-([a-z])/g;
   if(str=== str.toUpperCase()) str= str.toLowerCase();
    return str.replace(rx, function(a, b){
        return b.toUpperCase();});



}

titleCase("I'm a little tea pot");
is that correct method of usage @Chrono79
Diego Mayer
@Chrono79
May 08 2016 03:48
@ajithvallabai I'm not sure this will work: if(str=== str.toUpperCase()) str= str.toLowerCase();
These are the test cases:
titleCase("I'm a little tea pot") should return a string.
titleCase("I'm a little tea pot") should return "I'm A Little Tea Pot".
titleCase("sHoRt AnD sToUt") should return "Short And Stout".
titleCase("HERE IS MY HANDLE HERE IS MY SPOUT") should return "Here Is My Handle Here Is My Spout".
Ajith
@ajithvallabai
May 08 2016 03:49
@Chrono79 is there any other function which is simple to use.i am to not sure with that
Diego Mayer
@Chrono79
May 08 2016 03:50
@ajithvallabai first, I would lowercase the whole sentence
Ajith
@ajithvallabai
May 08 2016 03:51
okay after that
Diego Mayer
@Chrono79
May 08 2016 03:51
and easy enough, you can split using " " and titlecase every word as a concatenation of the first letter uppercased and the rest of the word
at the end you have to join the words again
Ajith
@ajithvallabai
May 08 2016 03:52
thanks @Chrono79 i will try it
CamperBot
@camperbot
May 08 2016 03:52
ajithvallabai sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 666 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
May 08 2016 03:53
I have the number of the beast now :fire:
muehehe
Johnathon Sykes
@seesykescode
May 08 2016 03:55
So it seems all of the advanced Javascript are kicking my ass.
is there something I'm missing?
lol I feel completely unprepared. LIke I know what I need to do most of the time but expressing myself in code poop emoji
wrong room :/
Joshua Swift
@joshuaswift
May 08 2016 03:59
Hey guys, so I just completed "Chunky Monkey" and I have a question about my solution
function chunkArrayInGroups(arr, size) {
var newArr = [];
while (arr.length > 0) {
newArr.push(arr.splice(0,size));
}
  return newArr;
}


chunkArrayInGroups(["a", "b", "c", "d"], 2);
This is my solution which passed, however I intially tried using "slice" instead of "splice" and got an infinite loop warning. Why would that be?
Just trying to understand for future reference!
Diego Mayer
@Chrono79
May 08 2016 04:01
@Joshuaswift because slice doesn't modify the original array, so arr.length stays the same = infinite loop
Description
slice does not alter. It returns a shallow copy of elements from the original array. Elements of the original array are copied into the returned array as follows:
...
The splice() method changes the content of an array by removing existing elements and/or adding new elements.
With splice you're making arr shorter with each cut and eventually exits the while loop
E YG
@laed37
May 08 2016 04:04
I think I found a bug, I'm on the "no repeats please" algorithm challenge and when I return the length of an array (the answer) it doesn't validate/accept even though it's the same number.
Joshua Swift
@joshuaswift
May 08 2016 04:05
@Chrono79 Thanks that makes sense!
CamperBot
@camperbot
May 08 2016 04:05
joshuaswift sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 667 | @chrono79 |http://www.freecodecamp.com/chrono79
Joshua Swift
@joshuaswift
May 08 2016 04:05
@laed37 Paste your code I have a feeling I got the same thing
@laed37 If i remember rightly it was because I declared a variable globally
dontchaknow
@dontchaknow
May 08 2016 04:06
Check if the predicate (second argument) is truthy on all elements of a collection (first argument). I thought this meant check if every object in the array has a certain property but apparent not. I have no idea what the question is asking of me.
what is "truthy"?
Joshua Swift
@joshuaswift
May 08 2016 04:07
@dontchaknow What challenge are you on?
dontchaknow
@dontchaknow
May 08 2016 04:07
Everything Be True
Thomas hadley
@Thadley17
May 08 2016 04:08
Can anyone explain to me what exactly we are supposed to do for the javascript lesson "Stand In Line"? I can only get 2/4 objectives complete and I don't even know why they are passing lol.
Joshua Swift
@joshuaswift
May 08 2016 04:09
E YG
@laed37
May 08 2016 04:09
@Joshuaswift yeah that is what I did:
var  array = [];

function permAlone(str) {
// does something to make array have some quantity of values, let's say 2

var answer = array.length;
return answer; // should return 2
}

permAlone(string)
Diego Mayer
@Chrono79
May 08 2016 04:09
@dontchaknow thruthy and falsy are values that evaluate to true or false
Use the Boolean() function to evaluate each value
Joshua Swift
@joshuaswift
May 08 2016 04:10
@laed37 Declare the array var inside the function and it should pass
Diego Mayer
@Chrono79
May 08 2016 04:10
@Thadley17 Paste your code
Joshua Swift
@joshuaswift
May 08 2016 04:10
@laed37 It was driving me crazy at the time too!
Anurag Lahon
@anuraglahon16
May 08 2016 04:11
how to build a website with javascript?
E YG
@laed37
May 08 2016 04:12
@Joshuaswift I don't know if that will work because my function is recursive... and it relies on updating the var globally
dontchaknow
@dontchaknow
May 08 2016 04:12
function truthCheck(collection, pre) {
    return collection.every(function(someObject){return someObject.hasOwnProperty(pre);});
}
is it asking if everything object has a certain property?
Thomas hadley
@Thadley17
May 08 2016 04:13
@Chrono79 how do we paste it in a code block again?
Diego Mayer
@Chrono79
May 08 2016 04:13
help format
CamperBot
@camperbot
May 08 2016 04:13

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

dontchaknow
@dontchaknow
May 08 2016 04:14
nvm that mozilla page you linked earlier is right
truthy means anything but false, "", NaN, etc
Thomas hadley
@Thadley17
May 08 2016 04:15
@Chrono79 ```js
Diego Mayer
@Chrono79
May 08 2016 04:16
@Thadley17 use shift+enter to do a line break, ```js should be the only thing in that line
Ajith
@ajithvallabai
May 08 2016 04:16

function titleCase(str) {
var lower=str.toLowerCase();
  var splited=lower.split(" ");
  var upper=splited.map(function(a){return a.replace(a.charAt(0),a.toUpperCase());});

        return upper.join(" ");



}

titleCase("I'm a little tea pot");
this is not working properly for Title case algorithm
Thomas hadley
@Thadley17
May 08 2016 04:17
@Chrono79 I know the shift enter but am I even supposed to write the js after the 3 backticks?
Diego Mayer
@Chrono79
May 08 2016 04:17
@Thadley17 it's optional, it changes the colors and something else
DJ
@qualitymanifest
May 08 2016 04:17
but it does help to format it correctly
or html if you're using HTML, or css, etc
Thomas hadley
@Thadley17
May 08 2016 04:17
this probably won't work -.-
@Chrono79
function nextInLine(arr, item) {
  // Your code here
  testArr.push(item);
  testArr.shift();
  return item;  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
wow look at that. I thought it messed up before it rendered lol
DJ
@qualitymanifest
May 08 2016 04:18
:musical_note: DJ airhorn sound effect :musical_note:
Diego Mayer
@Chrono79
May 08 2016 04:18

@Thadley17 first, don't use testArr inside your function, use the param arr
Then, you have to return the item removed, and right now, you're returning the item added

var upper=splited.map(function(a){return a.replace(a.charAt(0),a.toUpperCase());});

You can't modify a like that

@ajithvallabai inside map, a is a whole word
Anurag Lahon
@anuraglahon16
May 08 2016 04:20

We'll pass you an array of two numbers. Return the sum of those two numbers and all numbers between them.

The lowest number will not always come first.

Ajith
@ajithvallabai
May 08 2016 04:20
ya i found now i need to upper case the first letter alone @Chrono79
Diego Mayer
@Chrono79
May 08 2016 04:21
@ajithvallabai you could use slice there, to get the rest of the word
Ajith
@ajithvallabai
May 08 2016 04:22
var upper=splited.map(function(a){return a.replace(a.charAt(0), a.charAt(0).toUpperCase());});
how to use slice there
but the above code worked
i modified it
dontchaknow
@dontchaknow
May 08 2016 04:23
var notTruthy = [false, 0, "", null, undefined, NaN];
console.log(notTruthy.indexOf(NaN));
Diego Mayer
@Chrono79
May 08 2016 04:23
@ajithvallabai yes, it works
dontchaknow
@dontchaknow
May 08 2016 04:23
why does this return -1? why is NaN not found?
Thomas hadley
@Thadley17
May 08 2016 04:23
@Chrono79 Ok, so It passed when I returned the item removed but I'm still confused. I don't understand how the objectives are written. Why couldn't you use the testArr variable? Isn't it global.
Diego Mayer
@Chrono79
May 08 2016 04:24
@Thadley17 you can, but it's better to use your function param, it's there for a reason
Using globals it's not the best idea when you have functions
Thomas hadley
@Thadley17
May 08 2016 04:25
@Chrono79 Ok I can get that.. I just wasn't sure what to use although, I dont get how the other ones are passing. The only thing I understand here is the adding and removing a number
Travis
@dukenukethem
May 08 2016 04:25

function truncateString(str, num) {
  // Clear out that junk in your trunk
  var trunk = '';
  if (str.length > num) {
  trunk = str.slice(0, num) + '...';
    return trunk;
  } 
  return str;
}


truncateString("A-tisket a-tasket A green and yellow basket", 11);
So far this is what I have; not sure what I'm doing wrong.
Diego Mayer
@Chrono79
May 08 2016 04:25
@dontchaknow NaN !== NaN I think
@dukenukethem where are the other conditions?
Travis
@dukenukethem
May 08 2016 04:26
Other conditions?
Diego Mayer
@Chrono79
May 08 2016 04:26
help truncate a string
CamperBot
@camperbot
May 08 2016 04:26

:point_right: algorithm truncate a string [wiki]

Explanation:

We need to reduce the length of the string or truncate it if it is longer than the given maximum lengths specified and add ... to the end. If it is not that long then we keep it as is.

:pencil: read more about algorithm truncate a string on the FCC Wiki

DJ
@qualitymanifest
May 08 2016 04:27
@ajithvallabai that works because .replace returns a new string, rather than trying to modify the string (which doesn't work due to string immutability). if you want to see the .slice() version i will show you, but you may want to try it yourself first.
Ajith
@ajithvallabai
May 08 2016 04:28
oh i will try slice function too @qualitymanifest
DJ
@qualitymanifest
May 08 2016 04:28
@ajithvallabai basically the idea with the .slice() version is to replace each word with the first letter capitalized + the rest of the string sliced after the first letter
Thomas hadley
@Thadley17
May 08 2016 04:28
@Chrono79 No where is it written for example that nextInLine([2]), 1) or that it is returning 5 so I don't know why its passing :worried:
Diego Mayer
@Chrono79
May 08 2016 04:28
@dukenukethem
However, if the given maximum string length num is less than or equal to 3, then the addition of the three dots does not add to the string length in determining the truncated string.
Travis
@dukenukethem
May 08 2016 04:28

function truncateString(str, num) {
  // Clear out that junk in your trunk
  var trunk = '';
  if (str.length > num) {
  trunk = str.slice(0, num-3) + '...';
    return trunk;
  } else if (str.length <= num) {
    trunk = str.slice(0, num) + '...';
    return trunk;
  }
  return str;
}
something like this?
nope :x
Diego Mayer
@Chrono79
May 08 2016 04:29

@Thadley17

nextInLine([], 1) should return 1
First we add 1 to the empty array, so it becomes[1], when then we remove the first item in the array we get 1 (and arr is [] again)
nextInLine([2], 1) should return 2
First we add 2 to the array, so it becomes [2,1], when then we remove the first item in the array we get 2 (and arr is [1])
nextInLine([5,6,7,8,9], 1) should return 5
First we add 1 to the array, so it becomes [5,6,7,8,9,1], when then we remove the first item in the array we get 5 (and arr is [6,7,8,9,1])
After nextInLine(testArr, 10), testArr[4] should be 10
First we add 10 to testArr ([1,2,3,4,5]), so it becomes [1,2,3,4,5,10], when then we remove the first item in the array we get 1 (and arr is [2,3,4,5,10]) and testArr[4] is 10

Try to imagine what happens inside your fucntion and you'll see how the result is returned

Thomas hadley
@Thadley17
May 08 2016 04:31
@Chrono79 Yeah, I don't understand any of that. One sec, let me open that section
dontchaknow
@dontchaknow
May 08 2016 04:32
ok I'm stumped. is there a way to check if a property field is NaN without using the isNaN() function?
Thomas hadley
@Thadley17
May 08 2016 04:33

@Chrono79


function nextInLine(arr, item) {
  // Your code here
  arr.push(item);

  return arr.shift();  // 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));

so with just this, they all pass. Why? I'm probably being retarded but I just don't get it lol

DJ
@qualitymanifest
May 08 2016 04:34
@Thadley17 you're pushing item onto the end of arr. and returning the first part of arr - arr.shift() removes the first part and tries to return it.
bitgrower
@bitgrower
May 08 2016 04:35

@dontchaknow -- yes, there is, I don't have it at my fingertips ... I think it's something like

if ( typeof MyVar == "number" && MyVar != MyVar) return true;

Travis
@dukenukethem
May 08 2016 04:35
This message was deleted
This message was deleted
bwhicks
@bwhicks
May 08 2016 04:36
@dontchaknow Is there a reason isNaN() is an issue?
Travis
@dukenukethem
May 08 2016 04:37

function truncateString(str, num) {
  // Clear out that junk in your trunk
  var trunk = '';
  if (str.length > num) {
  trunk = str.slice(0, num-3);  
    trunk += '...';
    return trunk;
  } else if (num.length <= 3) {
    trunk = str.slice(0, num);  
    trunk += '...';
    return trunk;
  }
  return str;
}


truncateString("A-", 1);
what am I doing wrong here guys?
Thomas hadley
@Thadley17
May 08 2016 04:37
@qualitymanifest I understand that... its the objectives I dont get that @Chrono79 posted above. Ahh.. nevermind. I can't explain what I don't understand properly.
dontchaknow
@dontchaknow
May 08 2016 04:39
just curious
I can worth with isNaN()
work with*
buiphuking
@buiphuking
May 08 2016 04:40
is there anyway to understand heap's algorithm on NO REPEATS PLEASE , guys? help
Diego Mayer
@Chrono79
May 08 2016 04:41
@dukenukethem evaluate num<=3 somewhere
Travis
@dukenukethem
May 08 2016 04:41
I thought I did that in my else if
omid saghatchian
@omidiu
May 08 2016 04:41
Hi guys
:)
Diego Mayer
@Chrono79
May 08 2016 04:42
I see str.length <= 3 there
Travis
@dukenukethem
May 08 2016 04:42
oh wait i should change that here too; I did catch that earlier and changed it in my actual code
would it be num.length though?>
Diego Mayer
@Chrono79
May 08 2016 04:44
@dukenukethem no, num is a number
paste your code again
Travis
@dukenukethem
May 08 2016 04:44
Okay; I'm still coming up shorthanded
do I need to create a 2nd variable for the else if?
Diego Mayer
@Chrono79
May 08 2016 04:46
@dukenukethem no need for more vars
You could do it without trunk too
Travis
@dukenukethem
May 08 2016 04:46
Okay; I'm not seeing something then.
Really? Now I feel like I'm not understanding this at all
Diego Mayer
@Chrono79
May 08 2016 04:47
@dukenukethem Paste you code and I'll tell you
Travis
@dukenukethem
May 08 2016 04:47

function truncateString(str, num) {
  // Clear out that junk in your trunk
  var trunk = '';
  if (str.length > num) 
  {
  trunk = str.slice(0, num-3);  
    trunk += '...';
    return trunk;
  }

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


truncateString("A-", 1);
DJ
@qualitymanifest
May 08 2016 04:47
@dontchaknow since you were curious - @bitgrower 's idea was correct: https://repl.it/COYw
Diego Mayer
@Chrono79
May 08 2016 04:48
@dukenukethem first, when you use nested ifs, make sure it works the way you want it to do
str.length can be greater than num and also num lesser or equal than 3 at the same time, but you did your ifs in a way it'll never reach the second part because it'll enter the first if
prashant
@findname
May 08 2016 04:49
var decimalValue = [ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ];
  var romanNumeral = [ 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I' ];
var k=0,newNum=[];
function convertToRoman(num) {
  num=num.toString().split("");      //for converting to array

  for(i=0;i<num.length;i++)
 {
   arr = num.map(function(val){ return parseInt(val, 10);});      
   if(0<decimalValue[k]<arr)         //num upto 3999
           {
                    var div=arr/decimalValue[k];          
                    var j=0;
                    while(j<3 && div>0) {                                        
                                          newNum=newNum.push(romanNumeral[k]); 
                                            j++;
                                            --div;
            }num=num.shift();}

           k++;
  }  
 return newNum;
}

convertToRoman(36);
anyone whats wrong here it is generating empty array
Travis
@dukenukethem
May 08 2016 04:49
@Chrono79 I thought I was :x .
DJ
@qualitymanifest
May 08 2016 04:50
@findname for, map, and while is too many loops. IIRC this can be done with one while loop
Diego Mayer
@Chrono79
May 08 2016 04:51

@dukenukethem

  if (num<str.length) {
    if (num<=3) {
    ...
    } else {
    ...
    }
  } else {
  ...
  }

Like this it'll work

buiphuking
@buiphuking
May 08 2016 04:52
@findname i don't know computer understand your code or not, but i don't
Travis
@dukenukethem
May 08 2016 04:54
Now I feel lost.. ha
Diego Mayer
@Chrono79
May 08 2016 04:54
@dukenukethem do you understand the logic there?
Travis
@dukenukethem
May 08 2016 04:54
Like I get how my code wasn't working
But I don't understand the if within an if
if (num<str.length) {
  if (num <= 3) {
    str.slice(0, num);
    str += '...';
    return str;
  }
}
Diego Mayer
@Chrono79
May 08 2016 04:55
@dukenukethem both conditions can be true or the first can be true and the second false
Travis
@dukenukethem
May 08 2016 04:55
This is what I've tried so far.
prashant
@findname
May 08 2016 04:55
@qualitymanifest for number upto 3999 ?
Diego Mayer
@Chrono79
May 08 2016 04:55
@dukenukethem that's not ok
Travis
@dukenukethem
May 08 2016 04:56
it's not passing any tests when I test it, or is it not to that point yet?
Diego Mayer
@Chrono79
May 08 2016 04:56
@dukenukethem slice don't modify str per se, try return str.slice(0, num)+'...';
Or the longer way would be
if (num<str.length) {
  if (num <= 3) {
    str = str.slice(0, num);
    str += '...';
    return str;
  }
}
DJ
@qualitymanifest
May 08 2016 04:57
@findname yes
Travis
@dukenukethem
May 08 2016 04:57
What's wrong with my code compared to what you just said to do
Diego Mayer
@Chrono79
May 08 2016 04:58
@dukenukethem that
Travis
@dukenukethem
May 08 2016 04:59

function truncateString(str, num) {
  // Clear out that junk in your trunk

if (num<str.length) {
  if (num <= 3) {

    return str.slice(0, num) + '...';
  }
}
}
Okay I modified it to this so far;
it'll pass the last 2 arguments now wooh.
Diego Mayer
@Chrono79
May 08 2016 04:59
@dukenukethem Note that inserting the three dots to the end will add to the string length. if num <str.length, so here is your first else
DJ
@qualitymanifest
May 08 2016 05:00
@findname i can give you some pseudocode if you like
Travis
@dukenukethem
May 08 2016 05:00
unless its less than or equal to 3
buiphuking
@buiphuking
May 08 2016 05:00
@dukenukethem
if(num <=3){}
else if(num<= str.length){}
else{}
Diego Mayer
@Chrono79
May 08 2016 05:01

function truncateString(str, num) {
  // Clear out that junk in your trunk

if (num<str.length) {
  if (num <= 3) {

    return str.slice(0, num) + '...';
  } else {
    //this here I mean
  }
}
}
prashant
@findname
May 08 2016 05:02
@qualitymanifest yeah sure
Travis
@dukenukethem
May 08 2016 05:02
wouldn't it just be return str.slice(0, num-3) + '...';
Diego Mayer
@Chrono79
May 08 2016 05:02
@dukenukethem yes, put that there
Travis
@dukenukethem
May 08 2016 05:03
Now my first two and last two pass and middle two dont ha
DJ
@qualitymanifest
May 08 2016 05:03
@findname
initiate array iterator variable
initiate empty string
while num is greater than 0
if num - current decimal is greater than 0, subtract current decimal from num and add appropriate roman numeral to string
else move on to the next part of decimal array and try again
Diego Mayer
@Chrono79
May 08 2016 05:03
@dukenukethem you have to resolve the last case, when this isn't true: if (num<str.length)
truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length) should return "A-tisket a-tasket A green and yellow basket".
It seems the same string to me ;)
Ajith
@ajithvallabai
May 08 2016 05:04
could any one help me i am stuck at largest numbers in array

function largestOfFour(arr) {
  // You can do this!
  var lar=arr.sort(function(a,b){return (a-b);}).pop();

  return lar;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
this is returning largest array i need only the numbers in particular array
Diego Mayer
@Chrono79
May 08 2016 05:05
@ajithvallabai use arr.map first
prashant
@findname
May 08 2016 05:06
thanks @qualitymanifest thats seems easy
CamperBot
@camperbot
May 08 2016 05:06
findname sends brownie points to @qualitymanifest :sparkles: :thumbsup: :sparkles:
:star2: 1154 | @qualitymanifest |http://www.freecodecamp.com/qualitymanifest
Ajith
@ajithvallabai
May 08 2016 05:06
@Chrono79 okay after that
Diego Mayer
@Chrono79
May 08 2016 05:06
@ajithvallabai inside map you can do the sort and pop
Ajith
@ajithvallabai
May 08 2016 05:07
@Chrono79 oh i vl try
prashant
@findname
May 08 2016 05:07
@buiphuking you want me to explain that
Travis
@dukenukethem
May 08 2016 05:08
I'm trying to make sense of what you're saying @Chrono79 but it's not clicking atm
Diego Mayer
@Chrono79
May 08 2016 05:08
@dukenukethem paste your code again
Travis
@dukenukethem
May 08 2016 05:08

function truncateString(str, num) {
  // Clear out that junk in your trunk

if (num<str.length) {
  if (num <= 3) {

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

}
}
Diego Mayer
@Chrono79
May 08 2016 05:09

function truncateString(str, num) {
  // Clear out that junk in your trunk

if (num<str.length) {
  if (num <= 3) {

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

} else {
  // here
}
what should you return if num isn't <str.length ?
Travis
@dukenukethem
May 08 2016 05:09
oml
str.
Diego Mayer
@Chrono79
May 08 2016 05:10
:clap:
Travis
@dukenukethem
May 08 2016 05:10
That last part gave me such a hard time;
I was putting it in the wrong bracket
buiphuking
@buiphuking
May 08 2016 05:10
@findname i spend 2 days to solve that one, and a hour to optimize , my advice is you should find the easy way to solve it, try make computer thing like a kid the first time learn roman number
nfozkan
@nfozkan
May 08 2016 05:11
Hey all!
Travis
@dukenukethem
May 08 2016 05:11
howdy @nfozkan
Diego Mayer
@Chrono79
May 08 2016 05:12
@dukenukethem an if inside another if is not something weird, it's a way of writing less, you could do it in separate ifs and put 2 expression joined with &&
nfozkan
@nfozkan
May 08 2016 05:12
good. am new to Js and kinda don't understand something, makes me question why why why
Travis
@dukenukethem
May 08 2016 05:13
That's good. @nfozkan
nfozkan
@nfozkan
May 08 2016 05:13
target = sorted_color[Math.random()*sorted_color.length];
prashant
@findname
May 08 2016 05:14
@buiphuking yeah i got looks like easy one algo , above you can see . didnt get what you mean try make computer thing like a kid the first time learn roman number
nfozkan
@nfozkan
May 08 2016 05:14
isnt Math.random for int?
Diego Mayer
@Chrono79
May 08 2016 05:14

function truncateString(str, num) {
  // Clear out that junk in your trunk

if (num<str.length && num <= 3) {
    return str.slice(0, num) + '...';
}
if (num<str.length && num > 3) {
    return str.slice(0, num-3) + '...';
} 
if (num>=str.length
  return str;
}
Travis
@dukenukethem
May 08 2016 05:14
so if im understanding this properly its looking at the if inside an if and it looks to see if one or the other is equal to their parameters, like it can be either or?
Diego Mayer
@Chrono79
May 08 2016 05:17
if the first condition is true then if the second condition is true do something, if the second condition isn't true do something else, if the first condition isn't true do another thing
That's the translation of the ifs logic in your code (not the one I posted above)
Travis
@dukenukethem
May 08 2016 05:18
oh okay
Islam Ibakaev
@dagman
May 08 2016 05:18
@dukenukethem
function truncateString(str, num) {
  return str.length > num ? str.slice(0, num < 3 ? num : num - 3) + '...': str;
}
Travis
@dukenukethem
May 08 2016 05:18
that, actually makes sense.
Robert Richey
@0x0936
May 08 2016 05:18

@nfozkan Math.random() returns a floating point number within the range of 0 - 0.999

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random

To get a whole number, call Math.floor() on the result. Math.floor(Math.random() * sorted_color.length)

Travis
@dukenukethem
May 08 2016 05:18
@dagman you keep throwing advanced code at me man that I don't understand haha.
well; I guess I kind of do...but not how you formatted
Diego Mayer
@Chrono79
May 08 2016 05:19
@dagman stop pushing their face in the water man ;)
Islam Ibakaev
@dagman
May 08 2016 05:19
sorry :worried:
Travis
@dukenukethem
May 08 2016 05:19
I'm sure a lot of the alg. could be done in a single line format like you've shown
Kevin
@KevinBruland
May 08 2016 05:20
im having trouble getting the geolocation to work on codepen, is there something I need to do other than the JS code?
Islam Ibakaev
@dagman
May 08 2016 05:20
@dukenukethem i get crazy with chunky monky :smile:
Travis
@dukenukethem
May 08 2016 05:20
chunky monky...?
Deepak Yadav
@ydeepk
May 08 2016 05:20

Hey fellas using Scroll Reveal js. Can some one help me with this

scroll reveals sequence animation code not working, why

my code:

// interval and custom config passed to reveal
window.sr = ScrollReveal();
sr.reveal('.card', { duration: 2000 }, 50);

when i remove parameter 50 which is for delay between each object as mentioned in documentation of "ScrollReveal.js" it works but all "Cards" appear at same time, I want to add delay 50. but then my "Cards " disappear.

Islam Ibakaev
@dagman
May 08 2016 05:20
function chunkArrayInGroups(arr, size) {
  return arr.length > size ? [arr.splice(0, size)].concat(chunkArrayInGroups(arr, size)) : [arr];
}
Travis
@dukenukethem
May 08 2016 05:21
hada hoodoo wah? ?
Islam Ibakaev
@dagman
May 08 2016 05:21
dont even know how i come to this one
Kevin
@KevinBruland
May 08 2016 05:22
to test it, I copied the same code from the FCC exercise explaining it... in FCC it shows me my location data... on codepen it shows me nothingt
buiphuking
@buiphuking
May 08 2016 05:22

@findname

var a = [1000, ...10, 5,1]
var b = [M.....X,V,I]

you have number = 13, you a[i] < 13 , is 10 , 10 is X, after that 13-10 = 3 a1<= 3 is 1, 1 is I , 3-1 =2 , a[i] <= 2 ....... until equal 0, and we are done

prashant
@findname
May 08 2016 05:23
@buiphuking yeah the algo is : initiate array iterator variable
initiate empty string
while num is greater than 0
if num - current decimal is greater than 0, subtract current decimal from num and add appropriate roman numeral to string
else move on to the next part of decimal array and try again
Ajith
@ajithvallabai
May 08 2016 05:23

```

function largestOfFour(arr) {

var lar=arr.map(function(a,b)
{
return a-b;
}).sort().pop();
return lar;

}

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

``` i tried this but not working @Chrono79

prashant
@findname
May 08 2016 05:24
@buiphuking but i didnt do with this algo
did you
buiphuking
@buiphuking
May 08 2016 05:25
instead of - until 0, i + until = number, i think minus id better than phus
DJ
@qualitymanifest
May 08 2016 05:26
@findname i actually retried it with the pseudocode i gave you above, and it give an infinite loop warning. i had to do if num / current decimal is greater than or equal to 1
it worked with the previous pseudocode, all the tests passed, but it kept giving the warning
Diego Mayer
@Chrono79
May 08 2016 05:26
@ajithvallabai
function largestOfFour(arr) {
var lar=arr.map(function(el)
{ return el.sort(function(a,b){return a-b}).pop()

});
return lar;
}


largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
buiphuking
@buiphuking
May 08 2016 05:27
@ajithvallabai
arr.map(function(item){
return Math.max(...item);
});
DJ
@qualitymanifest
May 08 2016 05:27
@findname btw that's not an "official" solution that's just how i did it.
Ajith
@ajithvallabai
May 08 2016 05:27
thanks @Chrono79 @buiphuking
CamperBot
@camperbot
May 08 2016 05:27
ajithvallabai sends brownie points to @chrono79 and @buiphuking :sparkles: :thumbsup: :sparkles:
:cookie: 2 | @buiphuking |http://www.freecodecamp.com/buiphuking
:cookie: 668 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
May 08 2016 05:27
@buiphuking yes, that works too, but it has the spread operator and I was trying to make his idea work
prashant
@findname
May 08 2016 05:28
ohk thanks @qualitymanifest and @buiphuking
CamperBot
@camperbot
May 08 2016 05:28
findname sends brownie points to @qualitymanifest and @buiphuking :sparkles: :thumbsup: :sparkles:
:cookie: 3 | @buiphuking |http://www.freecodecamp.com/buiphuking
:warning: findname already gave qualitymanifest points
Diego Mayer
@Chrono79
May 08 2016 05:28
@ajithvallabai spread operator is an ES6 feature
Deepak Yadav
@ydeepk
May 08 2016 05:29
why i even come here when nobody even help for FreeCodeCamp problems or other JS problems.
Travis
@dukenukethem
May 08 2016 05:29
help Chunky Monkey
CamperBot
@camperbot
May 08 2016 05:29

:point_right: algorithm chunky monkey [wiki]

Explanation

Our goal for this Algorithm is to split arr (first argument) into smaller chunks of arrays with the length provided by size (second argument). There are 4 green checks (objectives) our code needs to pass in order to complete this Algorithm:

  1. (['a', 'b', 'c', 'd'], 2) is expected to be [['a', 'b'], ['c', 'd']]
  2. ([0, 1, 2, 3, 4, 5], 3) is expected to be [[0, 1, 2], [3, 4, 5]]
  3. ([0, 1, 2, 3, 4, 5], 2) is expected to be [[0, 1], [2, 3], [4, 5]]
  4. ([0, 1, 2, 3, 4, 5], 4) is expected to be [[0, 1, 2, 3], [4, 5]]

Click More information under the Algorithm title and read the helpful links if you haven't yet.

:pencil: read more about algorithm chunky monkey on the FCC Wiki

Ajith
@ajithvallabai
May 08 2016 05:30
i think they are advanced operation @Chrono79
Robert Richey
@0x0936
May 08 2016 05:30
@buiphuking even shorter
return arr.map(item => Math.max(...item))
Diego Mayer
@Chrono79
May 08 2016 05:30
@ydeepk Don't know what are you talking about but you're free to complain all you want
Travis
@dukenukethem
May 08 2016 05:31
Am I way out of the ballpark for thinking I need a nested for loop here?
Swaroop
@swaroopamir
May 08 2016 05:32

can anyone say how to solve
In Computer Science a queue is an abstract Data Structure where items are kept in order. New items can be added at the back of the queue and old items are taken off from the front of the queue.

Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.
````

function nextInLine(arr, item) {
// Your code here
arr.push(arr);
arr.shift();
return arr.length; // Change this line
}

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

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

Diego Mayer
@Chrono79
May 08 2016 05:32
@dukenukethem you can do it with only one loop (or with more complex methods)
buiphuking
@buiphuking
May 08 2016 05:33
@0x0936 can i ask you something?
Robert Richey
@0x0936
May 08 2016 05:33
@buiphuking sure
Diego Mayer
@Chrono79
May 08 2016 05:34
@swaroopamir
all three lines are wrong:
arr.push(arr); //you don't have to push arr
arr.shift(); // you would want to store what item you've removed, that's what you have to return after all
return arr.length; // Change this line //why returning arr.length? Look at the test cases
Swaroop
@swaroopamir
May 08 2016 05:34
what actually we have to do?
@Chrono79
buiphuking
@buiphuking
May 08 2016 05:34
did you understand heap's algorithm on NO REPEATS PLEASE ? @0x0936
Robert Richey
@0x0936
May 08 2016 05:35
@buiphuking I haven't worked that challenge yet
Travis
@dukenukethem
May 08 2016 05:36
I'm drawin a blank on how to actually start this
Diego Mayer
@Chrono79
May 08 2016 05:40
@dukenukethem the easy way: use an auxiliary array, push SLICES (wink wink) of the first array in there and return the auxiliary array
Travis
@dukenukethem
May 08 2016 05:44
So upon research it can be done with a for; or while loop
Interesting.
Diego Mayer
@Chrono79
May 08 2016 05:47
@dukenukethem or recursively like @dagman showed you
Travis
@dukenukethem
May 08 2016 05:47
@Chrono79 thanks; It was a lot less code than I thought it would be.
CamperBot
@camperbot
May 08 2016 05:47
dukenukethem sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:cookie: 669 | @chrono79 |http://www.freecodecamp.com/chrono79
dontchaknow
@dontchaknow
May 08 2016 05:47
function truthCheck(collection, pre) {
    function truthy(obj) {
        if (obj[pre] === "" || obj[pre] === null || obj[pre] === false || obj[pre] === undefined || obj[pre] === 0 || isNaN(obj[pre]) === true) {
            return false;
        }
        else {
            return true;
        }
    }
    return collection.every(truthy);
}
Travis
@dukenukethem
May 08 2016 05:47

function chunkArrayInGroups(arr, size) {
 var myArray = [];
  i = 0;
  while (i < arr.length) {
  myArray.push(arr.slice(i, i += size));
  }
  return myArray;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
dontchaknow
@dontchaknow
May 08 2016 05:47
all be 2 cases fail
Travis
@dukenukethem
May 08 2016 05:47
this is what i ended up with
dontchaknow
@dontchaknow
May 08 2016 05:47
not sure why
truthCheck([{"single": "yes"}], "single") returns false but should be true.
Diego Mayer
@Chrono79
May 08 2016 05:50
@dontchaknow isNaN("yes") is true, so you're returning false
replace your if conditions for this: (!obj[pre])
Travis
@dukenukethem
May 08 2016 05:58
Holy cow; slasher flick makes it seem so much more complex than it really is
Steph
@tcapre01
May 08 2016 06:00
Hey everyone! I'm stuck at a waypoint challenge and need some suggestions
Profile Lookup #229

Here is my code:
function lookUpProfile(firstName, prop){
// Only change code below this line

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

if (contacts[i]=== false) 
  {return "No such contact";}

for (var j = 0; j<contacts[i].length; j++){
if (contacts[i][j]===false)
{return "No such property";}
else {return contacts[i][j];}
}
}

// Only change code above this line
}

Michael Karpinski
@karpimpski
May 08 2016 06:01
@tcapre01 could you clean up your formatting?
help format
CamperBot
@camperbot
May 08 2016 06:01

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

Steph
@tcapre01
May 08 2016 06:02
Sorry about that
Michael Karpinski
@karpimpski
May 08 2016 06:03
@tcapre01 no problem! it's just easier to read and help you if you format is the right way
Diego Mayer
@Chrono79
May 08 2016 06:03
bye
Steph
@tcapre01
May 08 2016 06:03
function lookUpProfile(firstName, prop){
// Only change code below this line

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

    if (contacts[i]=== false) 
      {return "No such contact";}

   for (var j = 0; j<contacts[i].length; j++){
      if (contacts[i][j]===false)
      {return "No such property";}
       else {return contacts[i][j];}
      }
  }

// Only change code above this line
}
here it is again
Fayheim
@Fayheim
May 08 2016 06:03
// Setup
var outerWear = "T-Shirt";

function myOutfit() {
  // Only change code below this line
  var myOutfit = "sweater";
  return myOutfit;
}


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

myOutfit();
am I doing this right
yelp!
Martialis39
@Martialis39
May 08 2016 06:04
@Fayheim Hey
Remind me what challenge is that?
Steph
@tcapre01
May 08 2016 06:04
I triedto do contacts[firstName] initially in my code but I kept getting an error saying that it was undefined
Martialis39
@Martialis39
May 08 2016 06:04
@tcapre01 Hey, still having an isse?
Steph
@tcapre01
May 08 2016 06:04
@Martialis39 still am!
Michael Karpinski
@karpimpski
May 08 2016 06:04
@tcapre01 okay well you're not using your parameters at all. right now you're just looping through your object and returning the first name if one exists
Martialis39
@Martialis39
May 08 2016 06:05
@tcapre01 OK, gimme a minute, im pulling up the challenge, can you describe the issue, sorry, I just jumped on :)
Steph
@tcapre01
May 08 2016 06:06
@karpimpski I was using them initially but kept getting an error returned- let me have another go at it
Michael Karpinski
@karpimpski
May 08 2016 06:06
@tcapre01 okay well think it through first, I'll help with the logic
your first parameter is firstName, and firstName is easier to handle anyway
Fayheim
@Fayheim
May 08 2016 06:06
@Martialis39 Global vs. local scope in functions
Steph
@tcapre01
May 08 2016 06:06
@Martialis39 I'm just stuck, but give me a minuteto try again
Fayheim
@Fayheim
May 08 2016 06:06
currently stuck at this
Michael Karpinski
@karpimpski
May 08 2016 06:07
@tcapre01 how could you go through your contacts to see if it contains the first name you're given?
Martialis39
@Martialis39
May 08 2016 06:07
@tcapre01 Ok, to start out with. Read the instructions very carefully. I had trouble with this, but when I literally went through line by line and did what they asked, I got it :)
@Fayheim ok, one sec!
Steph
@tcapre01
May 08 2016 06:09
@karpimpski @Martialis39 ok, starting from scratch and giving it a go
Martialis39
@Martialis39
May 08 2016 06:09
@Fayheim OK sir!
I see the issue
Fayheim
@Fayheim
May 08 2016 06:10
@Martialis39 yes!
what is it
xD
Martialis39
@Martialis39
May 08 2016 06:10
Consider this - They want to show you what happens to variables
check the names of you variables
and read the instructions very carefully :)
What exactly do you need to overwrite?
EXACTLY :D
Michael Karpinski
@karpimpski
May 08 2016 06:10
@tcapre01 again, try to check for the firstName parameter, no need to check if there really is a first name
Martialis39
@Martialis39
May 08 2016 06:12
@Fayheim also maybe start from the beginning, click Reset Code
that way you have to change less :)
@Fayheim if you are still stuck, let me know and I'll help you out
Sumeet Batheja
@bathejasumeet
May 08 2016 06:17
Hey all
Adam
@alacrity26
May 08 2016 06:18
Help $topic
CamperBot
@camperbot
May 08 2016 06:18

:point_right: topic [wiki]

This is an example. You should replace topic with the thing you want to find info on.
For example:

wiki css    # find a wiki page on css
find js     # find all pages related to css

:pencil: read more about topic on the FCC Wiki

Martialis39
@Martialis39
May 08 2016 06:18
@Fayheim Hey man, did you get it?
Adam
@alacrity26
May 08 2016 06:18
Help $js
CamperBot
@camperbot
May 08 2016 06:18

:point_right: challenge accessing nested arrays in json [wiki]

Challenge: Accessing Nested Arrays in JSON

As we have seen in earlier examples, JSON objects can contain both nested objects and nested arrays. Similar to accessing nested objects, Array bracket notation can be chained to access nested arrays.

Here is an example of how to access a nested array:

```js
var ourPets = {
"cats": [
"Meowzer",
"Fluffy",
"Kit-Cat"
],
"dogs": [
"Spot",
"Bowser",
"Frankie"
]
};
ourPets.cats[1]; // "Fluffy"
:pencil: read more about challenge accessing nested arrays in json on the FCC Wiki

Sumeet Batheja
@bathejasumeet
May 08 2016 06:19
:D
anybody there?
Adam
@alacrity26
May 08 2016 06:19
Help $js
CamperBot
@camperbot
May 08 2016 06:19

:point_right: challenge accessing nested arrays in json [wiki]

Challenge: Accessing Nested Arrays in JSON

As we have seen in earlier examples, JSON objects can contain both nested objects and nested arrays. Similar to accessing nested objects, Array bracket notation can be chained to access nested arrays.

Here is an example of how to access a nested array:

```js
var ourPets = {
"cats": [
"Meowzer",
"Fluffy",
"Kit-Cat"
],
"dogs": [
"Spot",
"Bowser",
"Frankie"
]
};
ourPets.cats1; // "Fluffy"
:pencil: read more about challenge accessing nested arrays in json on the FCC Wiki

Yungmi Kim
@YungmiKim
May 08 2016 06:31
hi there ~
I can't solve this problem

var a = 3;
var b = 17;
var c = 12;

// Only modify code below this line

a = a + 12;
b = 9 + b;
c = c + 7;

and next?
kirbyedy
@kirbyedy
May 08 2016 06:32
@YungmiKim and what should you do ?
Yungmi Kim
@YungmiKim
May 08 2016 06:32
how to use the += operator?
var a +=3;
var b +=17;
var c =+12;
something misunderstanding about =+
prashant
@findname
May 08 2016 06:34
anyone why it is giving potential infinite loop err
function convertToRoman(num) {
 var decimalValue = [ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ];
  var romanNumeral = [ 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I' ];
var newar=[];
var i;
while(num>=1){
if(num>decimalValue[i])  {
    num=num-decimalValue[i];
    newar=newar.push(romanNumeral[i]);        
  }
else {

i++;  

}}

  return newar;
}

convertToRoman(36);
kirbyedy
@kirbyedy
May 08 2016 06:35
@YungmiKim a += 12
Yungmi Kim
@YungmiKim
May 08 2016 06:40
a += 12;
b += 9 ;
c += 7;
I solve the problem!!
kirbyedy
@kirbyedy
May 08 2016 06:41
:thumbsup:
Yungmi Kim
@YungmiKim
May 08 2016 06:41
thanks! kirbyedy!!
I just starter as JS..
I have to get it
Ajith
@ajithvallabai
May 08 2016 06:44
could anyone help me

function confirmEnding(str, target) {

  var sliced=str.slice(-1);

  return sliced===target;
}

confirmEnding("Bastian", "n");
i could not test a ending word for a sentence
confirmEnding("He has to give me a new name", "name") should return true.
this doesnt work for it what should i do?'
buiphuking
@buiphuking
May 08 2016 06:45
@findname i = ?
prashant
@findname
May 08 2016 06:47
oh @buiphuking thanks did i used push arr wrongly it says its not a functioin
CamperBot
@camperbot
May 08 2016 06:47
findname sends brownie points to @buiphuking :sparkles: :thumbsup: :sparkles:
:cookie: 4 | @buiphuking |http://www.freecodecamp.com/buiphuking
buiphuking
@buiphuking
May 08 2016 06:48
@ajithvallabai
if(str.slice(-target.length) === target){return true}
else{return false};
Steph
@tcapre01
May 08 2016 06:49
Okay so @Martialis39 @karpimpski am I going about this the right way?
function lookUpProfile(firstName, prop){
// Only change code below this line
  for (var i = 0; i<contacts.length; i++) { 
    if (contacts[i] == firstName) {
      for (var j = 0; i<contacts[i].length; j++) {
      if (contacts[i][j] ==prop){
        return contacts[i][j];
      }
buiphuking
@buiphuking
May 08 2016 06:49
@findname
push first, after that minus
Steph
@tcapre01
May 08 2016 06:50
so far javascript has been way more difficult for me than CSS or HTML
Ajith
@ajithvallabai
May 08 2016 06:50
thanks @buiphuking is there any other method than this?
CamperBot
@camperbot
May 08 2016 06:50
ajithvallabai sends brownie points to @buiphuking :sparkles: :thumbsup: :sparkles:
:cookie: 5 | @buiphuking |http://www.freecodecamp.com/buiphuking
Martialis39
@Martialis39
May 08 2016 06:50
@tcapre01 Dont worry, Javascript is much more similar to traditional "programming" languages than HTML
let me see
buiphuking
@buiphuking
May 08 2016 06:52
@ajithvallabai use for
Martialis39
@Martialis39
May 08 2016 06:52
@tcapre01 Ok, about firstName. You need to check if 'firstName' (the argument) is actually a firstName in the object.
currently, you are check if the object is firstName (contact[i] === firstName)
Steph
@tcapre01
May 08 2016 06:53
@Martialis39 I'm still not doing that?
Martialis39
@Martialis39
May 08 2016 06:53
can you think of a way how you can access the objects firstname?
firstName*
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
lets say this is our object.
how do you get to "Akira"
Steph
@tcapre01
May 08 2016 06:54
the firstName would just be contacts[0] in this case, is that correct?
Martialis39
@Martialis39
May 08 2016 06:54
you are half way there in your solution
contacts [0] is the WHOLE thing
we just need the firstName from 0
Steph
@tcapre01
May 08 2016 06:54
each of it is not an array?
Martialis39
@Martialis39
May 08 2016 06:55
no, contacts is an array of objects
Steph
@tcapre01
May 08 2016 06:55
or....then contacts[0][0]?
Martialis39
@Martialis39
May 08 2016 06:55
so with contacts [0]
yes, but in that case not 0, but
.firstName :)
buiphuking
@buiphuking
May 08 2016 06:55
contacts[0].firstname , i think so
Martialis39
@Martialis39
May 08 2016 06:55
exactly!
Steph
@tcapre01
May 08 2016 06:55
why would it be .firstname and not another [0] in this case?
Ajith
@ajithvallabai
May 08 2016 06:55

@buiphuking i didnt think about using the length of the target how do u think like that spontaneously
```

function confirmEnding(str, target) {

var arr=str.split(' ').join('');
var last= str.slice(-target.length);
return last===target;

}

confirmEnding("He has to give me a new name", "me");

Martialis39
@Martialis39
May 08 2016 06:56
because to access the values in objects
@tcapre01
we need to use their "key"
not their index
the firstName is the key in this case
Ajith
@ajithvallabai
May 08 2016 06:56
i tried this

function confirmEnding(str, target) {

  var arr=str.split(' ').join('');
 var last= str.slice(-target.length);
 return last===target;




}

confirmEnding("He has to give me a new name", "me");
Martialis39
@Martialis39
May 08 2016 06:56
and "Akira"
Ajith
@ajithvallabai
May 08 2016 06:56
this to works
Martialis39
@Martialis39
May 08 2016 06:56
is the value its associated with.
together they are the key value pair.
Steph
@tcapre01
May 08 2016 06:56
@Martialis39 right okay! then I just need to add the .firstName onto the contacts[i] I initially had first
Martialis39
@Martialis39
May 08 2016 06:57
exactly!
Michael Karpinski
@karpimpski
May 08 2016 06:57
@tcapre01 since firstName contains a string it's like checking contacts[0]["Akira"]
Martialis39
@Martialis39
May 08 2016 06:57
Then we, if it still doesnt work, we can have a look at the next step :) @tcapre01
Mateusz Szymański
@matszym
May 08 2016 06:57
@karpimpski no
Steph
@tcapre01
May 08 2016 06:58
@Martialis39 okay, I'll keep going. Javascript is going to be quite the challenge for me... :D
Martialis39
@Martialis39
May 08 2016 06:59
@tcapre01 dont worry, objects IMO are the most difficult part in pure Javascript :)
buiphuking
@buiphuking
May 08 2016 06:59
@ajithvallabai because i'm stuck with my exercise so i spent time to optimize my algorithm
Martialis39
@Martialis39
May 08 2016 06:59
but its about getting into the correct headspace
power through it and wait for it to click @tcapre01
Ajith
@ajithvallabai
May 08 2016 06:59
@buiphuking :smile:
Michael Karpinski
@karpimpski
May 08 2016 07:00
@matszym in this case yes. contacts[0].firstName is the same thing as contacts[0]["Akira"] if the first name is Akira
buiphuking
@buiphuking
May 08 2016 07:01
@ajithvallabai
my code
{return str.slice(-target.length) === target ?  true :  false;}
Mateusz Szymański
@matszym
May 08 2016 07:02

@karpimpski its not.

contacts[0]["Akira"]

is equal to

contacts[0].Akira
Markus Kiili
@Masd925
May 08 2016 07:03
@buiphuking You can simplify it by:
function confirmEnding(str, target) {
  return str.slice(-target.length)===target;
}
Michael Karpinski
@karpimpski
May 08 2016 07:03
@matszym and using that variable to check if it exists is the same thing as your example and it works perfectly fine. it's what I did to solve it
Mateusz Szymański
@matszym
May 08 2016 07:07

@karpimpski I dont understand what do you mean by "that variable" you didnt propose to use variable, you was lookking up object property with bracket notation with string .

Thre is no error if you try to access non existing property on object, you just get undefined. ou were getting undefined in return when you accesed property Akira

buiphuking
@buiphuking
May 08 2016 07:07
@Masd925 thanks!
CamperBot
@camperbot
May 08 2016 07:07
buiphuking sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1439 | @masd925 |http://www.freecodecamp.com/masd925
Michael Karpinski
@karpimpski
May 08 2016 07:09
@matszym the firstName variable. you can use my example to check if a property exists and be returned a true or false variable. that's what I did
Ajith
@ajithvallabai
May 08 2016 07:09
great :smile:
:+1:

```
function repeatStringNumTimes(str, num) {
if(num>0)

return str.repeat(num);
else return "";
// repeat after me

}

repeatStringNumTimes("abc", 3);
``` could this be made more simple for "repeat a string"

function repeatStringNumTimes(str, num) {
  if(num>0)

  return str.repeat(num);
  else return "";
  // repeat after me

}

repeatStringNumTimes("abc", 3);
@buiphuking
Michael Karpinski
@karpimpski
May 08 2016 07:11
@ajithvallabai ternary operators can simplify else statements
Ajith
@ajithvallabai
May 08 2016 07:12
@karpimpski :+1:
Mateusz Szymański
@matszym
May 08 2016 07:13
@karpimpski Post the code. I dont belive you did in the solution what you said here.
Nepherius
@Nepherius
May 08 2016 07:14
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  case 1:
    answer = 'alpha';
    break;
  case 2:
    answer = 'beta';
    break;
  case 3:
    answer = 'gamma';
    break;
  case 4:
    answer = 'delta';
    break;


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

// Change this value to test
caseInSwitch(1);
What am I doing wrong here ?
Michael Karpinski
@karpimpski
May 08 2016 07:14
@matszym I can show you tomorrow, but I'm currently in bed. of course I could be wrong, but I specifically remember this project because I tried simplifying my if statements with! using this problem
I'll be happy to post tomorrow
Anurag Lahon
@anuraglahon16
May 08 2016 07:15
how to make a quote machine???
buiphuking
@buiphuking
May 08 2016 07:15
@ajithvallabai
return num >0 ? str.repeat(num) : "";
Greg Duncan
@GregatGit
May 08 2016 07:16
@ajithvallabai Nice function - i think you only really need the one line tho return str.repeat(num); because it is only going to repeat it num times
Mateusz Szymański
@matszym
May 08 2016 07:16
@karpimpski no point, tommorow you will deny you said:
contacts[0].firstName is the same thing as contacts[0]["Akira"] if the first name is Akira
Michael Karpinski
@karpimpski
May 08 2016 07:17
@matszym not sure why you're so mad and I won't. if I'm wrong I'm wrong, it's really not that big of a deal. I'm pretty sure I used it that way, but if I didn't there's really no need to get so agitated about this
Ajith
@ajithvallabai
May 08 2016 07:18

@GregatGit @karpimpski

function repeatStringNumTimes(str, num) {

  return num>0?str.repeat(num):"";

}

repeatStringNumTimes("abc", 3);

this works i think thanks

CamperBot
@camperbot
May 08 2016 07:18
ajithvallabai sends brownie points to @gregatgit and @karpimpski :sparkles: :thumbsup: :sparkles:
:cookie: 360 | @karpimpski |http://www.freecodecamp.com/karpimpski
:cookie: 451 | @gregatgit |http://www.freecodecamp.com/gregatgit
Michael Karpinski
@karpimpski
May 08 2016 07:19
@ajithvallabai if that doesn't work move the return statements to each of your options and away from your condition
Steph
@tcapre01
May 08 2016 07:19

@Martialis39 okay so, I've gotten here so far.

function lookUpProfile(firstName, prop){
// Only change code below this line
  for (var i = 0; i<contacts.length; i++) { 
    if (contacts[i].firstName == firstName && contacts[i].prop === true) {
        return contacts[i].prop;
      }

if I don't include the && contacts....etc part it will return the firstName if I ask it to...and yet if I try and include the prop it doesn't return anything. Should I separate them?

Mateusz Szymański
@matszym
May 08 2016 07:19
@karpimpski I'm not mad, its just not the same. We had discusion about possible sollution, and we are in disagrement. I would like to see the code you are claming, and if it behaves in they way you presented with above statement. I'm far from anger.
Markus Kiili
@Masd925
May 08 2016 07:19
@ajithvallabai You can also solve it without the ES6 .repeat() method by using recursion:
function repeat(str, num) {
  return num>0 ? str+repeat(str,num-1) : "";   
}
Michael Karpinski
@karpimpski
May 08 2016 07:20
@matszym okay, then no need to accuse me of a lie that I haven't made about something we'll both forget in an hour
Ajith
@ajithvallabai
May 08 2016 07:21
@karpimpski it works . @Masd925 thanks
CamperBot
@camperbot
May 08 2016 07:21
ajithvallabai sends brownie points to @karpimpski and @masd925 :sparkles: :thumbsup: :sparkles:
:warning: ajithvallabai already gave karpimpski points
:star2: 1440 | @masd925 |http://www.freecodecamp.com/masd925
Greg Duncan
@GregatGit
May 08 2016 07:22
@matszym @karpimpski Just a heads up - I think there is a bug in the FreeCodeCamp on that challenge - I completed that one before but now it shows up that it doesn't pass the test - i tried it on www.repl.it and it did
Mateusz Szymański
@matszym
May 08 2016 07:22
@karpimpski I'm sorry, I didnt comunicate well. I didnt think you are laying. I think you are wrong, and your code does something slighty diferent than what you are saying. Sorry it sounded like I'm acusing you of laying, that wasnt my intention
Chris Cullen
@123xylem
May 08 2016 07:22
How do I turn a js variable into something with an ID that can be selected ?
function myFunction() {

  var name = "";
  var quote = "";

  for (i = Math.floor((Math.random() * 15) + 1); i < arr.length; i++) {

    quote = arr[i][0];
    name = arr[i][1];
     $("#quotebox").text(quote);
    $("#namebox").text(name);
console.log(quote);
console.log(name);
    return;
Michael Karpinski
@karpimpski
May 08 2016 07:23
@tcapre01 you don't need the === true. if you leave that out it will return true or false either way
Chris Cullen
@123xylem
May 08 2016 07:23
eg I want quote and Name to have IDs
Markus Kiili
@Masd925
May 08 2016 07:23
@GregatGit Check the function name.
Michael Karpinski
@karpimpski
May 08 2016 07:23
@GregatGit thanks, I'm
CamperBot
@camperbot
May 08 2016 07:23
karpimpski sends brownie points to @gregatgit :sparkles: :thumbsup: :sparkles:
:cookie: 452 | @gregatgit |http://www.freecodecamp.com/gregatgit
Michael Karpinski
@karpimpski
May 08 2016 07:23
I'll check it out tomorrow and compare
Martialis39
@Martialis39
May 08 2016 07:23
@tcapre01 Hey
It might be because its getting confused after the &&. Im a bit in a hurry so I cant have a look at exactly what its doing
Michael Karpinski
@karpimpski
May 08 2016 07:24
@matszym no big deal, like I said I'll check it out tomorrow and see if it was a bug, if I'm right, or I remembered wrong
Martialis39
@Martialis39
May 08 2016 07:24
but I recommend you use a separate if thats nested after the first and read up on .hasOwnProperty :)
Mateusz Szymański
@matszym
May 08 2016 07:24
@karpimpski What is your fcc profile name?
Michael Karpinski
@karpimpski
May 08 2016 07:25
@matszym the same as this one
Martialis39
@Martialis39
May 08 2016 07:25
@Martialis39 ill be back in about 3 hours, leave me a PM if you have questions :)
Steph
@tcapre01
May 08 2016 07:25
@Martialis39 @karpimpski thanks!! I have to go myself right now, but thank you for walking me step by step through this so far :D :D I'm realy appreciative
CamperBot
@camperbot
May 08 2016 07:25
tcapre01 sends brownie points to @martialis39 and @karpimpski :sparkles: :thumbsup: :sparkles:
:cookie: 311 | @martialis39 |http://www.freecodecamp.com/martialis39
:cookie: 361 | @karpimpski |http://www.freecodecamp.com/karpimpski
Michael Karpinski
@karpimpski
May 08 2016 07:26
@matszym looking at Steph's, I may be thinking of the way I implemented the prop and not the name, but got them confused
Martialis39
@Martialis39
May 08 2016 07:27
@tcapre01 absolutely no problem sir, enjoy the rest of your day ;)
buiphuking
@buiphuking
May 08 2016 07:28
heap's algorithm , no repeat please, who understand, plz open me eyes
Eldar Tinjić
@EldarT90
May 08 2016 07:28
what is the best free tutorial on net for node js ?
Greg Duncan
@GregatGit
May 08 2016 07:29
@Masd925 What should the function name be?
Steph
@tcapre01
May 08 2016 07:31
@Martialis39 also before i go- I JUST FIGURED THE FIRST PART OUT. I just need to do the "no such contact/property" bits now. Thanks again!
CamperBot
@camperbot
May 08 2016 07:31
tcapre01 sends brownie points to @martialis39 :sparkles: :thumbsup: :sparkles:
:warning: tcapre01 already gave martialis39 points
Markus Kiili
@Masd925
May 08 2016 07:32
@GregatGit The same as in the tests. Sometimes they change the function names and old solutions don't work anymore.
Greg Duncan
@GregatGit
May 08 2016 07:33
@Masd925 thanks - you were right - it went from lookup to lookUpProfile
CamperBot
@camperbot
May 08 2016 07:33
gregatgit sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1441 | @masd925 |http://www.freecodecamp.com/masd925
Michael Karpinski
@karpimpski
May 08 2016 07:33
@matszym I'm heading to bed, but definitely get back to me about that. sorry if I was wrong, I didn't have my code in front of me and I'm tired. 'night everyone!
Mateusz Szymański
@matszym
May 08 2016 07:36

@karpimpski

    if(contacts[x].firstName == firstName){
      if(contacts[x][prop]){
        return contacts[x][prop];
      }

In your solution you access names with just dot notation

contacts[0].firstName

You didnt implement anything like

contacts[0]["Akira"]

neither with variable

contacts[0][variableHoldingName]

With is fine, nice and simple solution, but its different than what you said before

contacts[0].firstName is the same thing as contacts[0]["Akira"] if the first name is Akira

I'm letting it go. I think you just misspoke it. Goodnigh

Ajith
@ajithvallabai
May 08 2016 07:48
how could i optimise this code

function truncateString(str, num) {
  // Clear out that junk in your trunk
  if (num>=str.length)
    return str;
  else if(num<3)
    return str.slice(0,num)+"...";
  else{
  var strng=str.slice(0,num-3)+"...";
  return strng;}


}

truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length);
these are test cases
truncateString("A-tisket a-tasket A green and yellow basket", 11) should return "A-tisket...".
truncateString("Peter Piper picked a peck of pickled peppers", 14) should return "Peter Piper...".
truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length) should return "A-tisket a-tasket A green and yellow basket".
truncateString("A-tisket a-tasket A green and yellow basket", "A-tisket a-tasket A green and yellow basket".length + 2) should return "A-tisket a-tasket A green and yellow basket".
truncateString("A-", 1) should return "A...".
truncateString("Absolutely Longer", 2) should return "Ab...".
buiphuking
@buiphuking
May 08 2016 08:10
@ajithvallabai
 return num <= 2 ? str.slice(0, num)  + "..." : num < str.length ? str.slice(0, num -3) +"..." : str;
Ajith
@ajithvallabai
May 08 2016 08:11
could any one help with chunky monkey

function chunkArrayInGroups(arr, size) {


  var sliced=arr.map(function(c){return c.slice(0,size);}).push();


  return sliced;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
you used ternary operator is there any other which is simple @buiphuking
buiphuking
@buiphuking
May 08 2016 08:13
@ajithvallabai chunky monkey should use loop
Ajith
@ajithvallabai
May 08 2016 08:13
but i have used map isnt that enough
buiphuking
@buiphuking
May 08 2016 08:14
@ajithvallabai map go to every item at the same time, you couldn't slice 2 item
Ajith
@ajithvallabai
May 08 2016 08:15
oh so i need to use another function with in it
function chunkArrayInGroups(arr, size) {

  var sliced=arr.map(function(c){
    return c.slice(function(a){return a;});}).push();
  return sliced;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
is it right method or could i shift to for loop @buiphuking
i dont know how to use slice here
Travis
@dukenukethem
May 08 2016 08:19
@ajithvallabai you could even use a while loop :x dunno if thats giving away too much
buiphuking
@buiphuking
May 08 2016 08:20
@ajithvallabai you need to slice 2 item (size =2) , use loop
Ajith
@ajithvallabai
May 08 2016 08:22
i think that would be better @dukenukethem
@buiphuking its hard in this method i will go with for or while loop
buiphuking
@buiphuking
May 08 2016 08:25
for use when you know how many time var i run,
while when you don't know that,
this case you can use both, but while is the better choose
Ajith
@ajithvallabai
May 08 2016 08:26
thanks @buiphuking
CamperBot
@camperbot
May 08 2016 08:26
ajithvallabai sends brownie points to @buiphuking :sparkles: :thumbsup: :sparkles:
:cookie: 6 | @buiphuking |http://www.freecodecamp.com/buiphuking
Evgueni
@Redoras
May 08 2016 08:27
Need some help with a code but not sure how to show the code here?
Ajith
@ajithvallabai
May 08 2016 08:28
help format
CamperBot
@camperbot
May 08 2016 08:28

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

Evgueni
@Redoras
May 08 2016 08:30

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

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

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

Nope that didn't work well...
Ajith
@ajithvallabai
May 08 2016 08:32
use the key above your tab key @Redoras
press it three time and then enter (`)
then press ctrl+/ and then enter
Taulut Hossain Washi
@WASHINPI
May 08 2016 08:33
thanks @washinpi
CamperBot
@camperbot
May 08 2016 08:33
sorry washinpi, you can't send brownie points to yourself! :sparkles: :sparkles:
Taulut Hossain Washi
@WASHINPI
May 08 2016 08:33
sorry guys am just checking
João Castanho
@joaocastanho
May 08 2016 08:41
Hello. Anyone knows how to scrap information from Linkedin and Instagram?
Reshab Das
@reshab48
May 08 2016 08:43

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

For the given id in collection:

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

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

If value is blank, delete that prop.

ca any 1 help me with writing the if statements
Ajith
@ajithvallabai
May 08 2016 08:44
post u r code
@reshab48
Reshab Das
@reshab48
May 08 2016 08:45

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

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

return collection;
}

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

@ajithvallabai
can u help me with this?
Ajith
@ajithvallabai
May 08 2016 08:49
try using collection[id][prop] and assigning vale to it
Reshab Das
@reshab48
May 08 2016 08:49
assign with push?
it says cannot read property 'push' of undefined
Ajith
@ajithvallabai
May 08 2016 08:51
i too had the same problem but i assgned value to it then it was rectified
access with brackets
Reshab Das
@reshab48
May 08 2016 08:51
how do i assign a value?
Ajith
@ajithvallabai
May 08 2016 08:51
collection[id][prop]=value;
Reshab Das
@reshab48
May 08 2016 08:51
ok
it worked thnx
Ajith
@ajithvallabai
May 08 2016 08:55
could any one help me with chunky monkey

function chunkArrayInGroups(arr, size) {

  var i,sliced;
  var words= arr.join('');

 for(i=0;i<=size;i++)
  {
    sliced=words.slice(0,size);
   return sliced.split('');


  }


}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
Zoher Ali
@Zoher-ali
May 08 2016 08:58
hey can any1 plz tell me in my calculator project why "CE" is not working?
buiphuking
@buiphuking
May 08 2016 08:58

@ajithvallabai

var sliced = [];

slice(.... , ......) , read slice method

Zoher Ali
@Zoher-ali
May 08 2016 08:59
function clear(){
        document.getElementById("txt").value = document.getElementById("txt").value.slice(-1);
}
"txt" is id of text box
Ajith
@ajithvallabai
May 08 2016 09:01
@buiphuking how to store it in an array?
sliced[0]=words.slice(0,size);
is this right
buiphuking
@buiphuking
May 08 2016 09:04
@ajithvallabai
sliced.push(arr.slice(.....,.....))
`
Coryphaeus
@cvdeby
May 08 2016 09:05
Is there somebody' pretty good familiar with jQuery?
I have a question, Is it bad for performance to use .animate() function each one second?
Ajith
@ajithvallabai
May 08 2016 09:06
for(i=0;i<=size;i++)
  {
   return sliced.push(arr.slice(0,size));
  }
@buiphuking is this right
buiphuking
@buiphuking
May 08 2016 09:08
@ajithvallabai how you know i <= size, are you sure about that?
Paweł Przytuła
@paprzytula
May 08 2016 09:08
i'd rather go for (i, i+size)
buiphuking
@buiphuking
May 08 2016 09:08
and slice (0, size) result is (a, b) and (a,b) (a,b)
Ajith
@ajithvallabai
May 08 2016 09:09
ya its wrong :worried:
Paweł Przytuła
@paprzytula
May 08 2016 09:10
and increment i +=size, because you want to chunk elements by size, not by i
Ajith
@ajithvallabai
May 08 2016 09:11
@paprzytula i will try it
Paweł Przytuła
@paprzytula
May 08 2016 09:12
@ajithvallabai about slice - you want to cut on i+size distances, not only at 0 index.
SBeard
@etacalpha
May 08 2016 09:30
Can someone tell me why this is generating correct response but not passing? js var largestNumber=[]; function largestOfFour(arr) { // You can do this! for (var i = 0; i<arr.length; i++){ largestNumber.push(Math.max.apply(null,arr[i])); } return largestNumber; }
Vivek
@vivek28111992
May 08 2016 09:38
hi , I am solving recursion , but I am getting complier error , though I am getting answer
function processData(input) {
    //Enter your code here
    var ans=1;
    for(var i = input;i >= 1; i--){
        ans = ans * i;  
    }
     console.log(ans);
}
Paweł Przytuła
@paprzytula
May 08 2016 09:41
@vivek28111992 maybe just change console.log into return?