These are chat archives for FreeCodeCamp/HelpJavaScript

29th
Aug 2016
Ahmad alloush
@ghost1244
Aug 29 2016 00:00
can someone give the solution for (Storing Values with the Assignment Operator) please ???
thank you
Liew Xun
@damakuno
Aug 29 2016 00:01
@ghost1244 what is it that you're unsure about?
Ahmad alloush
@ghost1244
Aug 29 2016 00:02
@damakuno Every thing!!!! can you please post your code so I can copy it
???
Patrick S
@thinktwice84
Aug 29 2016 00:02
@ghost1244 It doesn't work like that.
Ahmad alloush
@ghost1244
Aug 29 2016 00:03
@thinktwice84 What do you mean
Patrick S
@thinktwice84
Aug 29 2016 00:03
We don't just post code so you can copy it. What's the point of being in a FREE code school if you want to just copy someone else's code.
Liew Xun
@damakuno
Aug 29 2016 00:03
@ghost1244 I'll just tell you how it works in simple terms, a = [value] will push the value into the variable a, if that makes sense?
Ahmad alloush
@ghost1244
Aug 29 2016 00:03
@thinktwice84 I know, I just asked him because I have seen A lot of bugs reported in this challenge
Liew Xun
@damakuno
Aug 29 2016 00:04
@ghost1244 that [value] can be another variable too
@ghost1244 you should be able to do it now
Ahmad alloush
@ghost1244
Aug 29 2016 00:04
@damakuno yes, Thank you
Liew Xun
@damakuno
Aug 29 2016 00:04
perhaps it's the wording of the question that's confusing
CamperBot
@camperbot
Aug 29 2016 00:04
ghost1244 sends brownie points to @damakuno :sparkles: :thumbsup: :sparkles:
:cookie: 43 | @damakuno |http://www.freecodecamp.com/damakuno
Liew Xun
@damakuno
Aug 29 2016 00:06
because it is a bit different to say a = [value] in english, it would be like: "assign [value] to a" instead of "assign a to [value]"
Patrick S
@thinktwice84
Aug 29 2016 00:08
@damakuno I need an extra pair of eyes on this code. Codepen is saying my syntax is incorrect, but @llamatarianism says it's right and I believe it is.
John Ngo
@johnngo
Aug 29 2016 00:08

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

// Only change code below this line
myStorage.car['inside'].glove box;
var gloveBoxContents = ""; // Change this line

can someone tell me whats wrong with line - myStorage.car['inside'].glove box;
thanks
Liew Xun
@damakuno
Aug 29 2016 00:09
@thinktwice84 oh, jQuery?
Patrick S
@thinktwice84
Aug 29 2016 00:09
yeah
Matheus
@matheus-lima92
Aug 29 2016 00:09
Hi, I'm stuck at the random quote machine challenge, I can't read the quote coming from the API. Here's the API I'm using: https://theysaidso.com/api/, and here's my code: http://codepen.io/MatheusLima92/pen/OXKgLL?editors=1010. When I use the jquery '$.getJSON' command, I can see data in the format '[object Object]', as you can check pushing the button, but I don't know how to get the quote from this. Can someone help me?
Liew Xun
@damakuno
Aug 29 2016 00:10
I assume you had the jQuery library added to codepen
hmm wait let me see
@thinktwice84 I can't seem to find anything wrong with it
Patrick S
@thinktwice84
Aug 29 2016 00:13
@damakuno Were you getting the unexpected identifier?
Nathan Hannig
@nathanhannig
Aug 29 2016 00:13
hmmm, I wonder why you can't use .push on an array that is undefined to add it's first value
Liew Xun
@damakuno
Aug 29 2016 00:14
@matheus-lima92 won't give you the exact answer, but you should be able to access the key value by using Object.Key
or Object["key"]
Patrick S
@thinktwice84
Aug 29 2016 00:15
@matheus-lima92 I've been looking at your code and I can't see where you're accessing the key values
Liew Xun
@damakuno
Aug 29 2016 00:15
@thinktwice84 he said he doesn't know how to get it didn't he?
Patrick S
@thinktwice84
Aug 29 2016 00:15
@damakuno Who, llama?
Liew Xun
@damakuno
Aug 29 2016 00:16
yeah @thinktwice84 i'm getting Unexpected identifier too
@thinktwice84 i mean @matheus-lima92
Patrick S
@thinktwice84
Aug 29 2016 00:16
Well, at least it's not just me.
Oh
@damakuno It took me awhile to figure out how to access the key values of the returned object, but he'll figure it out. @matheus-lima92 Just keep searching for example API requests using JSON. You'll soon figure out what we mean by accessing the key values.
Matheus
@matheus-lima92
Aug 29 2016 00:18
@thinktwice84 @damakuno When i try something like request[0][0], I get nothing. When I try request[0], the result is undefined
not request[0], I mean result[0]
Ken Haduch
@khaduch
Aug 29 2016 00:20
@matheus-lima92 - if you have your code output the returned JSON to the console.log using JSON.stringify(result); (using the appropriate name) you can see the structure of the data - keys, arrays, etc., and should be able to pick out the proper coding to select it. If you try and have questions - post the stringified results here for guidance
Alejandro Perez
@alejitopm90
Aug 29 2016 00:21
Where can I find some information in how can I use APIs. I really need information (more than I have in FCC) to develop the wheater challenge.
Patrick S
@thinktwice84
Aug 29 2016 00:22
@alejitopm90 Which API do you plan on using?
There's a lot in common with the different ones, but depending on which one you choose, you'll be able to access the API documentation which will give you example code to work with.
Alejandro Perez
@alejitopm90
Aug 29 2016 00:23
The "open weather API" @thinktwice84
It's just that I don't have idea how to use it. And I think that the information that brings FCC before the challenge is less than information I need. @thinktwice84
Patrick S
@thinktwice84
Aug 29 2016 00:25
Well, unfortunately that site wasn't working for me when I tried it so I went to wunderground's API. You'll need a key, but it's free to use 10 requests/min and it comes with a lot of documentation.
Nathan Hannig
@nathanhannig
Aug 29 2016 00:27
any easy way to transform an array of strings into multi-dimensional array like ["a","b"] to [["a"],["b"]] ?
Jason Holder
@stoutpanda
Aug 29 2016 00:27
If anyone runs into the same issue on Record Collection that I was, it turns out it seems to be a bug on chrome on mac os x. Exact same code worked on safari & firefox.
Alejandro Perez
@alejitopm90
Aug 29 2016 00:27
@breakpoint25 use split()
Matheus
@matheus-lima92
Aug 29 2016 00:27
@khaduch Perfect, I can see the quote at the console! Thank you very much, I'll try to update my html with it now
CamperBot
@camperbot
Aug 29 2016 00:27
matheus-lima92 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 1595 | @khaduch |http://www.freecodecamp.com/khaduch
Patrick S
@thinktwice84
Aug 29 2016 00:28
@alejitopm90 I know, I thought the same thing. You'll figure it out little by little but I think that's kind of the point of FCC. I've been on google searching for answers about 10x longer than actually coding.
Alejandro Perez
@alejitopm90
Aug 29 2016 00:29
@thinktwice84 thanks Patrcik
CamperBot
@camperbot
Aug 29 2016 00:29
alejitopm90 sends brownie points to @thinktwice84 :sparkles: :thumbsup: :sparkles:
:cookie: 270 | @thinktwice84 |http://www.freecodecamp.com/thinktwice84
John Doe
@codingisfun11
Aug 29 2016 00:31
@thinktwice84 yeah its ironic
but I am hopeful that this will pay off.
I have learned so much from this great website and I love the community.
blob
what I am googling as we speak :)
Moisés Man
@moigithub
Aug 29 2016 00:34

@codingisfun11
Instructions

declare and initialize a variable named total to 0

Patrick S
@thinktwice84
Aug 29 2016 00:34
Just about to say that
John Doe
@codingisfun11
Aug 29 2016 00:35

var Total = 0;

for (var i = 19; i < myArr.length; i++) {
myTotal += myArr[i];
}

thanks good catch Moises!
Norvin Burrus
@ndburrus
Aug 29 2016 00:36
@johnngo resolved?
John Doe
@codingisfun11
Aug 29 2016 00:37
still unresolved atm :fire:
Moisés Man
@moigithub
Aug 29 2016 00:37
myTotal should be also total
and javscript is case-sensitive .. means TOTAL , total , Total they all are different variables names
John Doe
@codingisfun11
Aug 29 2016 00:37
hello Mr.Burrus
Norvin Burrus
@ndburrus
Aug 29 2016 00:37
hi
John Doe
@codingisfun11
Aug 29 2016 00:38
i got it correct.
I agree with you Moises.
Case sensitive to the MAX!!!!!!!!
rybka02
@rybka02
Aug 29 2016 00:45
Anyone here strong JS/Jquery programmer?
Joseph Halvarson
@joehalvarson
Aug 29 2016 00:49
Hi there. I'm looking for some assistance with Profile Lookup. I think I almost have it, but it's not quite working.
Brandon
@Brandons42
Aug 29 2016 00:50
@joehalvarson Show your code.
Joseph Halvarson
@joehalvarson
Aug 29 2016 00:52
function lookUpProfile(firstName, prop){
// Only change code below this line
  for (i = 0; i <= contacts.length; i++) {
    if (firstName === contacts[i].firstName && contacts[i].hasOwnProperty(prop) === true) {
      return contacts[i].prop;
    }  else if (firstName !== contacts[i].firstName) {
    return "No such contact";
  } else if (contacts[i].hasOwnProperty(prop) === false) {
    return "No such property";
  }
}
Brandon
@Brandons42
Aug 29 2016 00:53
Are you getting any of the cases correct?
Joseph Halvarson
@joehalvarson
Aug 29 2016 00:53
Supposedly "No such contact" and "No such property" are returning correctly.
rybka02
@rybka02
Aug 29 2016 00:54
You don't define contacts
contacts.length = null
Joseph Halvarson
@joehalvarson
Aug 29 2016 00:54
@rybka02 That's defined as a series of objects within an array.
Brandon
@Brandons42
Aug 29 2016 00:54
He didn't need to, it's pre-defined in the challenge. @rybka02
Geminye
@geminye22
Aug 29 2016 00:54
Lesson 143 I need help! Convert Celsius to Fahrenheit
Brandon
@Brandons42
Aug 29 2016 00:54
This line is wrong: return contacts[i].prop;
rybka02
@rybka02
Aug 29 2016 00:55
Then he didn't post all of code
/shrug
i dont do the challenges
Joseph Halvarson
@joehalvarson
Aug 29 2016 00:55
I figured I only should post the code I wrote.
Geminye
@geminye22
Aug 29 2016 00:55
Lesson 143 I need help! Convert Celsius to Fahrenheit
Nick
@ntdd
Aug 29 2016 00:56
oh man, just finished my random quote generator, what a challenge.
rybka02
@rybka02
Aug 29 2016 00:56
post the contacts part jose
Nick
@ntdd
Aug 29 2016 00:56
@geminye22 i can try and help ya :)
Brandon
@Brandons42
Aug 29 2016 00:56
Try to find out what's wrong with this line: return contacts[i].prop;
Hint: use brackets with variables @joehalvarson
Geminye
@geminye22
Aug 29 2016 00:56
convertToF(0) should return a number
convertToF(-30) should return a value of -22
convertToF(-10) should return a value of 14
convertToF(0) should return a value of 32
convertToF(20) should return a value of 68
convertToF(30) should return a value of 86
rybka02
@rybka02
Aug 29 2016 00:56
do you know the formula gemi?
Geminye
@geminye22
Aug 29 2016 00:57
No
Moisés Man
@moigithub
Aug 29 2016 00:57
prop is variable.. NO dot notation with variables @joehalvarson
rybka02
@rybka02
Aug 29 2016 00:57
the challenge doesnt tell you how to convert F->C?
Brandon
@Brandons42
Aug 29 2016 00:57
That's what I said. @moigithub
Moisés Man
@moigithub
Aug 29 2016 00:57
yep :D @Brandons42
Brandon
@Brandons42
Aug 29 2016 00:58
@moigithub Can you help me out with Binary Agents?
rybka02
@rybka02
Aug 29 2016 00:58
function addthree(num) {
     return num + 3;
}
use same concept but with F->C formula
Joseph Halvarson
@joehalvarson
Aug 29 2016 00:59

Thank you @Brandons42 and @moigithub
When I enter

return contacts[i][prop];

I'm greeted with it returning the "Akira" "likes" from the challenge, but nothing more.

CamperBot
@camperbot
Aug 29 2016 00:59
joehalvarson sends brownie points to @brandons42 and @moigithub :sparkles: :thumbsup: :sparkles:
:cookie: 290 | @brandons42 |http://www.freecodecamp.com/brandons42
:star2: 2050 | @moigithub |http://www.freecodecamp.com/moigithub
rybka02
@rybka02
Aug 29 2016 00:59
id have to see all the code jose
  • contacts array
Moisés Man
@moigithub
Aug 29 2016 00:59
@Brandons42 u have a string with many 000110100 1001
each of those groups (separated by spce) is a binary number
u need to convert binary to decimal.. and that decimal num represent an ascii code(like 65 -- > "A" )
using String.fromCharCode(65). u can convert that numeric decimal code to a real character "A"
Geminye
@geminye22
Aug 29 2016 01:00
@rybka02 I need a function for every convertToF
rybka02
@rybka02
Aug 29 2016 01:00
no
just 1
did u see my example?
you just do addthree(numbergoeshere);
and it will run the addthree function
Joseph Halvarson
@joehalvarson
Aug 29 2016 01:02

@rybka02 I appreciate you wanting to help, but don't want to clog up the feed with what's already written.

var contacts = [
{
     "firstName": "Akira",
...
     "likes": ["Pizza", "Coding", "Brownie Points"]
},
...
}
];

Is the gist of it.

rybka02
@rybka02
Aug 29 2016 01:02
ok post your code and this to a pm to me
and ill help u
i wont give answerr-- but ill help you discover the answer
David L. Whitehurst
@dlwhitehurst
Aug 29 2016 01:03
can someone point me to some explanation of this type of function structure. ```javascript
Brandon
@Brandons42
Aug 29 2016 01:04
@joehalvarson Same deal with this line: else if (firstName !== contacts[i].firstName)
Geminye
@geminye22
Aug 29 2016 01:04

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

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

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

Moisés Man
@moigithub
Aug 29 2016 01:04
@joehalvarson return exit the function...
if u follow ur code execution.. it always reach a return.. which will make ur loop only iterate 1 time
David L. Whitehurst
@dlwhitehurst
Aug 29 2016 01:04

try again ```javascript (function() {
'use strict';

angular
    .module('sandboxApp')
    .filter('capitalize', capitalize);

function capitalize() {
    return capitalizeFilter;

    function capitalizeFilter (input) {
        if (input !== null) {
            input = input.toLowerCase();
        }
        return input.substring(0, 1).toUpperCase() + input.substring(1);
    }
}

})();```

Stephen James
@sjames1958gm
Aug 29 2016 01:04
@geminye22 You need to implement the conversion formula given in the code - replace C with celsius and F with fahrenheit
David L. Whitehurst
@dlwhitehurst
Aug 29 2016 01:06
can someone provide a url that explains the (function() { .... })(); structure and why?
Moisés Man
@moigithub
Aug 29 2016 01:06
IIFE <-- @dlwhitehurst
Moisés Man
@moigithub
Aug 29 2016 01:07

function aaa (){} << define a funciton
aaa() <-- when u call the function u put a set of () at the end

soo on an IIFE u define and call the function immediatelly

David L. Whitehurst
@dlwhitehurst
Aug 29 2016 01:07
@moigithub so when Gulp adds my Angular to index.html the Chrome browser runs all these functions immediately?
Joseph Halvarson
@joehalvarson
Aug 29 2016 01:08
@moigithub I only want it to go through until the first success.
Moisés Man
@moigithub
Aug 29 2016 01:09
@joehalvarson soo if ur first contact is Akira.. what do u think would happen if u search for "Harry" ???
David L. Whitehurst
@dlwhitehurst
Aug 29 2016 01:09
@ntdd thanks!
CamperBot
@camperbot
Aug 29 2016 01:09
dlwhitehurst sends brownie points to @ntdd :sparkles: :thumbsup: :sparkles:
:cookie: 265 | @ntdd |http://www.freecodecamp.com/ntdd
Nick
@ntdd
Aug 29 2016 01:10
@dlwhitehurst welcome!
Moisés Man
@moigithub
Aug 29 2016 01:11
@dlwhitehurst IIFE structures is usually used to keep variables on local scope...
or in other words to NOT populate the global scope
Joseph Halvarson
@joehalvarson
Aug 29 2016 01:13
@moigithub I see what you mean. It's only going to look for array value 0 and because Harry is not at array value 0 it's going to return No such contact and exit rather than check for Harry at the other array values.
Moisés Man
@moigithub
Aug 29 2016 01:14
:+1:
David L. Whitehurst
@dlwhitehurst
Aug 29 2016 01:14
@moigithub for a single page web application (stemming from index.html) does the capitalize filter come in the $scope variable for when the web page wants to pipe the angular field to a capitalize filter?
rybka02
@rybka02
Aug 29 2016 01:15
@dlwhitehurst That's called a closure function
David L. Whitehurst
@dlwhitehurst
Aug 29 2016 01:15
@moigithub and I get my scope specifically from vm. and my Angular controller
rybka02
@rybka02
Aug 29 2016 01:15
the point of those functions is to separate code
say if you had two functions with same variable name
but you want both to have separate values.
you'd place them both inside a closure function
David L. Whitehurst
@dlwhitehurst
Aug 29 2016 01:17
@rybka02 thanks. I'm a Java professional that's trying to understand all this Javascript stuff and it seems that I need to learn 1) promises 2) callbacks 3) closures 4) IFFE now 5) what else? LOL ... I understand the language just not the patterns on the Javascript side
CamperBot
@camperbot
Aug 29 2016 01:17
dlwhitehurst sends brownie points to @rybka02 :sparkles: :thumbsup: :sparkles:
:cookie: 389 | @rybka02 |http://www.freecodecamp.com/rybka02
Joseph Halvarson
@joehalvarson
Aug 29 2016 01:17
Thank you @moigithub
I'll work through this to see if I can get the loop to go through all options before deciding there's no such contact or property.
CamperBot
@camperbot
Aug 29 2016 01:17
joehalvarson sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:warning: joehalvarson already gave moigithub points
Geminye
@geminye22
Aug 29 2016 01:17
@rybka02 im lost
rybka02
@rybka02
Aug 29 2016 01:18
post code gemi
Geminye
@geminye22
Aug 29 2016 01:18

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

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

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

rybka02
@rybka02
Aug 29 2016 01:18
ok so what happens is this--
All your code inside that function is ignored. Until it gets to convertToF(30)
That's when the function runs
And the # 30 becomes the variable celsius
9/5 +32 does nothing
and you return an empty variable called fahrenheit
You need to make Fahrenheit = celsius * (9/5) + 32
but it's case senistive
so don't copy what i wrote
Christian Torres
@SlickChris95
Aug 29 2016 01:30
Hello everyone I am having some great difficulty with an algorithms question. I anyone could help me understand why it is not working i would really appreciate it. The problem is called Check for Palindromes

function palindrome(str) {
// make sure that everything is turned into lowercase
// I need to modify the string by putting it into an array
// use unshift to add each of the characters to the new array and compare them
var array = [];
var len = str.length;
var mid = (str.length/2);
//this only allows numbers and letters to show up, and for the string to be lowercase
str = str.toLowerCase();
str = str.replace(/[^0-9a-zA-Z]/g, ''); // i think this is the problem

//easy case
if (len <= 1){
return true;
}
// if length is even
else if (len % 2 === 0) {
for (var i = mid; i < len; i++){
array.unshift(str[i]);
for (var j = 0; j < mid; j++){
if (array[j] === str[j] ) {
return true;
}
else {
return false;
}
}
}
}
// length is odd
else if (len % 2 !== 0) {
for ( var x = mid + 1; x < len; x++){
array.unshift(str[x]);
for(var y = 0; y < mid; y++) {
if (array[x] === str[x]) {
return true;
}
else {
return false;
}
}
}
}

else {
return false;
}

}

palindrome("eye");

rybka02
@rybka02
Aug 29 2016 01:31
there's one problem i see off the bat--
what if strlength is an odd #
your variable mid would be a decimal
Christian Torres
@SlickChris95
Aug 29 2016 01:32
@rybka02 it would round down
vaderwasframed
@vaderwasframed
Aug 29 2016 01:33
var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  }
    "artist": "Metallica",
    "title": "Enter Sandman",
    "release_year": 1992,
    "formats": [
      "CS",
      "8T",
      "LP"],
    "gold": true// Add record here
  }
];
I am not sure how you add a new album? They don't explain the syntax in the intructions
rybka02
@rybka02
Aug 29 2016 01:33
nah- it doesnt round down
Christian Torres
@SlickChris95
Aug 29 2016 01:34
really?
Moisés Man
@moigithub
Aug 29 2016 01:34
@vaderwasframed myMusic is an array of objects elemennts
elements must be separatedby comma
[{...},{...}] soo it should end like that
each objects need to have its open and closing curly brackets
rybka02
@rybka02
Aug 29 2016 01:34
myMusic[2]["artist"] = "rykba02";
vaderwasframed
@vaderwasframed
Aug 29 2016 01:35
Ahhhh I see
Thanks
Christian Torres
@SlickChris95
Aug 29 2016 01:35
@rybka02 i assumed it would round down because it is an integer
rybka02
@rybka02
Aug 29 2016 01:35
it doesnt
Christian Torres
@SlickChris95
Aug 29 2016 01:35
@rybka02 interesting, thank you for the pointers
CamperBot
@camperbot
Aug 29 2016 01:35
slickchris95 sends brownie points to @rybka02 :sparkles: :thumbsup: :sparkles:
:cookie: 391 | @rybka02 |http://www.freecodecamp.com/rybka02
Christian
@Neralizer
Aug 29 2016 01:36
can anyone help me with seek and destroy? almost finished, I think
function destroyer(arr) {
  var newarr = arr.filter(function (x) {return x !== arr[1] && x !== arr[2];});
  return newarr;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
rybka02
@rybka02
Aug 29 2016 01:36
if you want to round down use floor()
whats the directions say christian
Christian
@Neralizer
Aug 29 2016 01:36
I pass three of the five tests, but still missing two
Christian Torres
@SlickChris95
Aug 29 2016 01:36
@rybka02 ok thank you, i am new to javaScript. I am more used to working with C++
CamperBot
@camperbot
Aug 29 2016 01:36
slickchris95 sends brownie points to @rybka02 :sparkles: :thumbsup: :sparkles:
:warning: slickchris95 already gave rybka02 points
Margaret
@Margaret2
Aug 29 2016 01:37
@SlickChris95 i think you're overthinking it... what i did is reverse the string, then check if the reversed string is equal to the original string
Christian
@Neralizer
Aug 29 2016 01:37
@rybka02 the directions say that the arguments outside of the initial array must be removed from any instance in the initial array
rybka02
@rybka02
Aug 29 2016 01:37
so many ways to do it
can get string length and compare 0 index to last index
and move inward 1by1
Moisés Man
@moigithub
Aug 29 2016 01:38
@Neralizer arr is this
[1, 2, 3, 1, 2, 3]
on ur function call it gets passed 3 parameters
destroyer(
[1, 2, 3, 1, 2, 3],
2,
3);
and the function only have declared 1 argument function destroyer(arr) {
Christian
@Neralizer
Aug 29 2016 01:38
convert the arrays to strings?
@rybka02 ?
Christian Torres
@SlickChris95
Aug 29 2016 01:38
@Margaret2 hahaha that would be a lot easier
Margaret
@Margaret2
Aug 29 2016 01:38
:D
rybka02
@rybka02
Aug 29 2016 01:38
my guess is to remove 2 & 3 from array?
Stephen James
@sjames1958gm
Aug 29 2016 01:39
@Neralizer Research the link arguments in the instructions
rybka02
@rybka02
Aug 29 2016 01:39
filter() returns a value if it's true
Christian
@Neralizer
Aug 29 2016 01:40
hang on, let me stick with @rybka02
rybka02
@rybka02
Aug 29 2016 01:40
do you understand how filter works?
Brandon
@Brandons42
Aug 29 2016 01:40
function binaryAgent(str) {
  var total = 0;
  var returner = [];
  function getNumber(string) {
    var array = string.split("");
    total = 0;
    if (array[0] == "1") {
      total += 1;
    }
    if (array[1] == "1") {
      total += 2;
    }
    if (array[2] == "1") {
      total += 4;
    }
    if (array[3] == "1") {
      total += 8;
    }
    if (array[4] == "1") {
      total += 16;
    }
    if (array[5] == "1") {
      total += 32;
    }
    if (array[6] == "1") {
      total += 64;
    }
    if (array[7] == "1") {
      total += 128;
    }
    return total;
  }
  var arr = str.split(" ");
  for (q = 0; q < arr.length; q++) {
    returner.unshift(String.fromCharCode(getNumber(arr[q])));  
  }
  return returner.join("");
}
What's wrong with this? Challenge: Binary Agents
rybka02
@rybka02
Aug 29 2016 01:41
christian send me a PM and ill explain how it works
Christian
@Neralizer
Aug 29 2016 01:42
sure
Moisés Man
@moigithub
Aug 29 2016 01:42
@Brandons42 "11110000"( binary) should return 240(decimal)
test ur getNumber function
Christian
@Neralizer
Aug 29 2016 01:42
@rybka02
rybka02
@rybka02
Aug 29 2016 01:43
Hover your mouse over my picture and send me a PM
@Neralizer
Christian
@Neralizer
Aug 29 2016 01:44
I keep getting your github account
sorry I've never done this before, what do I click after I hover over your picture?
rybka02
@rybka02
Aug 29 2016 01:44
Where are you calling the first function brandon?
Brandon
@Brandons42
Aug 29 2016 01:45
@moigithub After I reversed everything (instead of
if (array[0] == "1") {
total += 1;
} it's
if (array[7] == "1") {
total += 1;
}
)
, it's 240.
But it still doesn't work.
rybka02
@rybka02
Aug 29 2016 01:46
where are you calling binaryAgent
Brandon
@Brandons42
Aug 29 2016 01:46
I just changed unshift to push and now it works.
Thanks @moigithub
CamperBot
@camperbot
Aug 29 2016 01:46
brandons42 sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 2051 | @moigithub |http://www.freecodecamp.com/moigithub
rybka02
@rybka02
Aug 29 2016 01:46
@christian i sent you a PM
look on left nav bar
Moisés Man
@moigithub
Aug 29 2016 01:46
:) @Brandons42 was gonna say that "ur string is reversed"
Stephen James
@sjames1958gm
Aug 29 2016 01:56
@Brandons42 Now that you got it working, checkout parseInt where the second parameter is base.
Jimmy Huynh
@jkchuynh829
Aug 29 2016 01:57
hello, quick question. ran into underscore.js video and was wondering if underscore.js === ES5
Jerzz
@2cool4school
Aug 29 2016 01:57
guys why cant i use this statement:
return str.fromCharCode(val);
Jimmy Huynh
@jkchuynh829
Aug 29 2016 01:58
_reduce.() === array.reduce() ? true : false;
Jerzz
@2cool4school
Aug 29 2016 01:58
i keep getting: str.fromCharCode is not a function
Jimmy Huynh
@jkchuynh829
Aug 29 2016 01:58
i thin you can only use that method on String
Margaret
@Margaret2
Aug 29 2016 01:59
@2cool4school you have to always use String.fromCharCode()
Jerzz
@2cool4school
Aug 29 2016 01:59
on a string, yes
@Margaret2 @jkchuynh829 okay thanks guys
CamperBot
@camperbot
Aug 29 2016 01:59
2cool4school sends brownie points to @margaret2 and @jkchuynh829 :sparkles: :thumbsup: :sparkles:
:cookie: 347 | @margaret2 |http://www.freecodecamp.com/margaret2
:cookie: 294 | @jkchuynh829 |http://www.freecodecamp.com/jkchuynh829
Jimmy Huynh
@jkchuynh829
Aug 29 2016 02:00
String.fromCharCode(str.charCodeAt(val))?
something like that
Stephen James
@sjames1958gm
Aug 29 2016 02:01
@jkchuynh829 underscore js was a library that provided functionality not available in js until recently - so no they are not the same
morganpierson
@morganpierson
Aug 29 2016 02:03

Can someone tell me if my solution for the "Sum all numbers in a range" intermediate algorithm scripting challenge is more or less what they are looking for? My solution passes all tests, but I feel like there is probably a more elegant way to use reduce (I am still fairly new to the reduce function):function sumAll(arr) {
arr = arr.sort(function(a, b){
return a - b;
});
var diff = (arr1 - arr[0] + 1);
return arr.reduce(function(total){
while(arr[0]<arr1){
total += (arr[0] + 1);
arr[0]++;
}
return total;
});

}

sumAll([1, 4]);

Brandon
@Brandons42
Aug 29 2016 02:08
I did it fairly similar to yours, except I didn't use .sort() or .reduce() and I used for loops instead of while loops.
@morganpierson
Jerzz
@2cool4school
Aug 29 2016 02:08
also why cant i return 'undefined'?
Stephen James
@sjames1958gm
Aug 29 2016 02:08
@morganpierson No reason to use reduce and the loop -
Jerzz
@2cool4school
Aug 29 2016 02:08

function fearNotLetter(str) {
  var val;
  for (var i=0; i<str.length; i++) {
    if (str.charCodeAt(i)+1 != str.charCodeAt(i+1)) {
      return String.fromCharCode(str.charCodeAt(i) + 1);
    }
  }
  return undefined;
}

fearNotLetter("abce");
Stephen James
@sjames1958gm
Aug 29 2016 02:08
@sjames1958gm If you constructed an array with all the values then reduce would make sense
theaabbcc
@theaabbcc
Aug 29 2016 02:09
Hey guys, I have a question, I'm on #144 and it says that "myStr should have encoded text with the proper escape sequences and no spacing. " Here is my code: var myStr = "FirstLine \n \\SecondLine\\ \rThirdLine";
Jerzz
@2cool4school
Aug 29 2016 02:09
this code returns all missing letter successfully, but if all letters are present im supposed to return defined
undefined*
Stephen James
@sjames1958gm
Aug 29 2016 02:10
@2cool4school It is likely getting an error because you go past the end of the string with charCodeAt(i+1)
Jerzz
@2cool4school
Aug 29 2016 02:10
@sjames1958gm i see, this makes sense..
Stephen James
@sjames1958gm
Aug 29 2016 02:10
@theaabbcc Remove all spaces it says
Jerzz
@2cool4school
Aug 29 2016 02:10
@sjames1958gm let me see if i cant figure something out
Brandon
@Brandons42
Aug 29 2016 02:11
help arguments optional
CamperBot
@camperbot
Aug 29 2016 02:11
no wiki entry for: arguments optional
theaabbcc
@theaabbcc
Aug 29 2016 02:11
@sjames1958gm same thing, but now it says \r and \ is missing.
Vijay
@vijayirtt59
Aug 29 2016 02:12
Hi guys how do declare a variable undefined in JS
Stephen James
@sjames1958gm
Aug 29 2016 02:12
@vijayirtt59 var x; will declare it undefined
@theaabbcc Can you put back quotes around your posted code? Markdown will hide some characters "FirstLine\n\\SecondLine\\\rThirdLine";
@Brandons42 What do you have?
Margaret
@Margaret2
Aug 29 2016 02:14
@theaabbcc it looks like you have spaces in your code, and it says no spacing
theaabbcc
@theaabbcc
Aug 29 2016 02:14
@sjames1958gm "var myStr = "FirstLine\n \\SecondLine\\ \rThirdLine";"
Vijay
@vijayirtt59
Aug 29 2016 02:14

var Bike = function() {

var gear;

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

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

// Only change code below this line.

};

var myCar = new Car();

var myBike = new Bike();
console.log(myBike.gear);
myBike.setGear(4);
myBike.getGear();

myBike.gear is returning undefined.. but i am not passing the challenge
Stephen James
@sjames1958gm
Aug 29 2016 02:15
@theaabbcc backquotes are next to 1 key
Margaret
@Margaret2
Aug 29 2016 02:15
@theaabbcc by back quotes he means these ``` put one before and one after a line of code
theaabbcc
@theaabbcc
Aug 29 2016 02:15
If I remove spacing it will even say that "\r \n and \ \ " are missing
Jerzz
@2cool4school
Aug 29 2016 02:16
@sjames1958gm Yeah thanks again man, i just added a conditional to test out of range indexes and returned undefined if that were the case
CamperBot
@camperbot
Aug 29 2016 02:16
2cool4school sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2923 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 29 2016 02:16
@2cool4school You could have changed your for loop to str < arr.length -1
Margaret
@Margaret2
Aug 29 2016 02:17
@theaabbcc
var myStr = "FirstLine\n\\SecondLine\\\rThirdLine";
Stephen James
@sjames1958gm
Aug 29 2016 02:18
@theaabbcc Try refreshing the page
Vijay
@vijayirtt59
Aug 29 2016 02:18
@sjames1958gm help me pls
Stephen James
@sjames1958gm
Aug 29 2016 02:18
@vijayirtt59 What tests is it failing?
Vijay
@vijayirtt59
Aug 29 2016 02:18

var Bike = function() {

var gear;

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

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

// Only change code below this line.

};

var myCar = new Car();

var myBike = new Bike();
myBike.setGear(4);
myBike.getGear();

how to take screenshot and upload here??
@sjames1958gm myBike.gear should remain undefined.
this test is failing
Margaret
@Margaret2
Aug 29 2016 02:21
@vijayirtt59 you can put ``` before and after your code to format it, or you will have to use a screenshot tool. On windows we have the snipping tool, but i don't know about other systems
theaabbcc
@theaabbcc
Aug 29 2016 02:21
K, I found the problem, I had an extra "\" in "\". I works now, thanks for the help guys!
3 slashes when there should be 2
Stephen James
@sjames1958gm
Aug 29 2016 02:22
@theaabbcc Should have realized that because markdown will hide one of the backslashes and yours looked right
Ken Haduch
@khaduch
Aug 29 2016 02:22
@vijayirtt59 - did you follow the instructions "Only change code below this line"?
Stephen James
@sjames1958gm
Aug 29 2016 02:23
@vijayirtt59 Weird but delete those last two test lines.
@vijayirtt59 You are setting gear and I think that is causing that error
Vijay
@vijayirtt59
Aug 29 2016 02:24
@sjames1958gm @khaduch I didn't follow the instructions "Only change code below this line"? Worked now.. Thank u guys
CamperBot
@camperbot
Aug 29 2016 02:24
vijayirtt59 sends brownie points to @sjames1958gm and @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 2924 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:star2: 1596 | @khaduch |http://www.freecodecamp.com/khaduch
Brandon
@Brandons42
Aug 29 2016 02:28
Wow, .parseInt() would've been so much easier for the binary challenge. @sjames1958gm
Thanks @sjames1958gm
CamperBot
@camperbot
Aug 29 2016 02:28
brandons42 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 2925 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Jimmy Huynh
@jkchuynh829
Aug 29 2016 02:29
@sjames1958gm ok, so underscorejs is essentially obsolete in ES5+ right?
llamatarianism
@llamatarianism
Aug 29 2016 02:33
@jkchuynh829 nah not really
I still wouldn't use it cuz it's kinda ginormous
but it still provides useful stuff
Christian Torres
@SlickChris95
Aug 29 2016 02:52
Does anyone see any obvious mistakes in my logic? This function is supposed to return the length of the longest word
Vijay
@vijayirtt59
Aug 29 2016 02:52
Struck in reverse a String
Christian Torres
@SlickChris95
Aug 29 2016 02:52

//use split to divide the sentence by white space
// compare each of the string inside of the new array
// we can use an algorithm that makes a max in comparative to the rest of the array
//return the length of the longest word
function findLongestWord(str) {

var array = [];
array = str.split(' ');
var longestWord = 0;

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

if (array[i].length > array[i + 1].length) {
  longestWord = array[i].length;
}
else {
  longestWord = array[i + 1].length;
}

}
return longestWord;
}

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

Patrick
@patricktownley
Aug 29 2016 02:55
@SlickChris95 It looks like you're comparing each word to the one directly after it - why not just compare it to the "longestWord" variable?
Vijay
@vijayirtt59
Aug 29 2016 02:55
@sjames1958gm i tried to reverse a string it shows reverse() not a function
Gang Zhao
@crumpx
Aug 29 2016 02:55
@vijayirtt59 you can only reverse an array
Vijay
@vijayirtt59
Aug 29 2016 02:56
ya i know.. i split and reversed and joined

function reverseString(str) {
return str.spilt('').reverse().join('');
}

reverseString("hello");

Christian Torres
@SlickChris95
Aug 29 2016 02:56
@patricktownley I will try it, what is the thought process for this?
Vijay
@vijayirtt59
Aug 29 2016 02:57
it works for me in console
Jaren Escueta
@jarenescueta731
Aug 29 2016 02:57

anyone good at bootstrap 3 know why my navbar links don't change background color when i use scrollspy?
here's my css statement that tries:

.navbar-default .navbar-nav li.active {
    background-color: #ea8d41;
}

they're supposed to look orange but the default gray still shows up

Gang Zhao
@crumpx
Aug 29 2016 02:57
you have a typo
:P
Patrick
@patricktownley
Aug 29 2016 02:58
@SlickChris95 Well, as you go through the array, you want to find the longest word in the array. You're effectively finding the largest of the two last numbers in the array, the way it is. Consider the case: "Potato banana a cat" - your code would return 3
Vijay
@vijayirtt59
Aug 29 2016 02:58
@crumpx u r awesome
Gang Zhao
@crumpx
Aug 29 2016 02:58
@vijayirtt59 :D
Christian Torres
@SlickChris95
Aug 29 2016 02:58
@patricktownley btw you were right thank you
CamperBot
@camperbot
Aug 29 2016 02:58
slickchris95 sends brownie points to @patricktownley :sparkles: :thumbsup: :sparkles:
:cookie: 283 | @patricktownley |http://www.freecodecamp.com/patricktownley
Christian
@Neralizer
Aug 29 2016 02:59
thanks @rybka02
CamperBot
@camperbot
Aug 29 2016 02:59
neralizer sends brownie points to @rybka02 :sparkles: :thumbsup: :sparkles:
:cookie: 392 | @rybka02 |http://www.freecodecamp.com/rybka02
Patrick
@patricktownley
Aug 29 2016 02:59
You're welcome!
Gang Zhao
@crumpx
Aug 29 2016 02:59
oh i'm on longest word also right now
Tracey Bushman
@tbushman
Aug 29 2016 02:59
@jarenescueta731 try li:active (colon)
Christian Torres
@SlickChris95
Aug 29 2016 03:00
@patricktownley that makes sense, thank you for the explanation
CamperBot
@camperbot
Aug 29 2016 03:00
slickchris95 sends brownie points to @patricktownley :sparkles: :thumbsup: :sparkles:
:warning: slickchris95 already gave patricktownley points
Jaren Escueta
@jarenescueta731
Aug 29 2016 03:01
@tbushman thx but that doesn't work either. li actually gains class="active" when the anchor tag for the link is reached in the viewport
CamperBot
@camperbot
Aug 29 2016 03:01
jarenescueta731 sends brownie points to @tbushman :sparkles: :thumbsup: :sparkles:
:cookie: 156 | @tbushman |http://www.freecodecamp.com/tbushman
Tracey Bushman
@tbushman
Aug 29 2016 03:01
ah then i don't deserve a cookie
;)
someone take my cookie
Gang Zhao
@crumpx
Aug 29 2016 03:04
compare to last one the longest word is so easy T_T
regex is a hell...
Claudio Restifo
@Marmiz
Aug 29 2016 03:06

@jarenescueta731have you tried adding !important ?
Also make sure that

Heads up! Navbar links must have resolvable id targets. For example, a <a href="#home">home</a> must correspond to something in the dom like <div >id="home"></div>.

Tracey Bushman
@tbushman
Aug 29 2016 03:06
@jarenescueta731 so are all of those classes supposed to be #ea8d41 ? (obvi ?) sorry. or just li?
Jaren Escueta
@jarenescueta731
Aug 29 2016 03:07
@Marmiz haven't tried that yet, what does it do?
@tbushman just li, it selects the li inside .navbar-nav inside .navbar-default
Claudio Restifo
@Marmiz
Aug 29 2016 03:07
@jarenescueta731 also try to address the active class as children:
.navbar-nav > .active {
}
Vijay
@vijayirtt59
Aug 29 2016 03:08

function factorialize(num) {
var count = num;
for(var i=1; i<=count; count++){
num = num * i;
}
return num;
}

factorialize(5);

This i am getting infinite loop
Gang Zhao
@crumpx
Aug 29 2016 03:10
because you're keep adding result to num
Claudio Restifo
@Marmiz
Aug 29 2016 03:10
@jarenescueta731 !important just overwrites any previous CSS declaration, it's not the best practice but it does its job :)
As mentioned before scrollspy.js require any link to have a resolvable target to work; since you see them turning gray I can assume you do ;)
Gang Zhao
@crumpx
Aug 29 2016 03:10
wait
my bad
Brandon
@Brandons42
Aug 29 2016 03:11
@vijayirtt59 You should be doing i++ instead of count++.
Gang Zhao
@crumpx
Aug 29 2016 03:11
^
Jaren Escueta
@jarenescueta731
Aug 29 2016 03:14

@Marmiz so i inspected the element in dev tools and looks like something in a less library of bootstrap is the source, i tried doing this:

.navbar-default .navbar-nav > .active {
    background-color: #ea8d41 !important;
}

but still a no go.

im gonna try just copying the selectors that less is using for it into my doc and see any change
Tracey Bushman
@tbushman
Aug 29 2016 03:17
@jarenescueta731 in the dev tools, a selected element should show tag/id/class combos so you can get specific in css...
Jaren Escueta
@jarenescueta731
Aug 29 2016 03:19

omg that did it lol, just copied what the less doc was doing:

.navbar-default .navbar-nav > .active > a, .navbar-default .navbar-nav > .active > a:focus, .navbar-default .navbar-nav > .active > a:hover {
  /* code here */
}

thx @tbushman @Marmiz

CamperBot
@camperbot
Aug 29 2016 03:19
jarenescueta731 sends brownie points to @tbushman and @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 348 | @marmiz |http://www.freecodecamp.com/marmiz
:warning: jarenescueta731 already gave tbushman points
Tracey Bushman
@tbushman
Aug 29 2016 03:20
@jarenescueta731 :thumbsup: :)
Claudio Restifo
@Marmiz
Aug 29 2016 03:21
@jarenescueta731 :+1:
Raj
@RajKumar1605
Aug 29 2016 03:24
How to create a simple vector object in javascript? Should I just store the magnitude and direction, or does the initial and terminal points of a vector also matter ?
Vijay
@vijayirtt59
Aug 29 2016 03:25
@Brandons42 thanks.. get a browne
CamperBot
@camperbot
Aug 29 2016 03:25
vijayirtt59 sends brownie points to @brandons42 :sparkles: :thumbsup: :sparkles:
:cookie: 292 | @brandons42 |http://www.freecodecamp.com/brandons42
Brandon
@Brandons42
Aug 29 2016 03:32
Can someone help me with arguments optional?
function addTogether() {
  var args = Array.from(arguments);
  if (args.length == 2) {
    if (Number.isInteger(args[0]) && Number.isInteger(args[1])) {
      return args[0] + args[1];
    }    
    return undefined;
  } else {
    // What do I put here?
  }
}
Tracey Bushman
@tbushman
Aug 29 2016 03:35

@Brandons42

return undefined;

should it go inside the else statement?

Brandon
@Brandons42
Aug 29 2016 03:36
I don't think so.
Joseph B.
@barlanj
Aug 29 2016 03:36
@Brandons42 what do you want it to do if the arguments is less than or greater than 2?
Tracey Bushman
@tbushman
Aug 29 2016 03:36
otherwise, looks like you're undoing the prev calculation
Brandon
@Brandons42
Aug 29 2016 03:37
Look at the challenge: Arguments Optional.
I can't explain it myself.
Gang Zhao
@crumpx
Aug 29 2016 03:39
function titleCase(str) {
  str = str.toLowerCase().split(' ');
  var regex= /^[\w]/;

  for (var i=0; i<str.length; i++){
    str[i] = str[i].replace(regex, str[i].split('')[0].toUpperCase());
  }

  str=str.join(' ');

  return str;
}

titleCase("I'm a little tea pot");
I think there's a prettier way right?
this code is too ugly...
David L. Whitehurst
@dlwhitehurst
Aug 29 2016 03:39
@Brandons42 it's according to how you use this function. If you are calling this in the console, you could return a message like console.log("You must supply 2 arguments"). My question is why are you not putting the arguments in the function call? e.g. addTogether(a,b);
Tracey Bushman
@tbushman
Aug 29 2016 03:39
@crumpx no it's pretty
Joseph B.
@barlanj
Aug 29 2016 03:39
@Brandons42 you need to return a function if it's not two arguments
Ian
@inhll
Aug 29 2016 03:40
I'm working on Profile Lookup (https://www.freecodecamp.com/challenges/profile-lookup)
    for (var i = 0; i < contacts.length; i++) {

      if (contacts[i]["firstName"] == firstName &&
         contacts[i].hasOwnProperty(prop)) {
        return contacts[i][prop];
      } else if (!contacts[i].hasOwnProperty(prop)) {
        return "No such property";
      } else if (contacts[i]["firstName"] != firstName) {
        return "No such contact";
      }
    }
I can't figure out what is wrong with my code :(
Gang Zhao
@crumpx
Aug 29 2016 03:40
@tbushman it's not :( I'll think harder...
Tracey Bushman
@tbushman
Aug 29 2016 03:40
@crumpx do that
Ken Haduch
@khaduch
Aug 29 2016 03:41
@Brandons42 - you need to handle the case when args.length === 1 - which is the case where you have to return a function that uses closure to "hold" the first argument until the function that you return is called to complete the addition.
Claudio Restifo
@Marmiz
Aug 29 2016 03:41
@Brandons42 well, you want to start storing the values until a second one is passed.
something like:
else{
//store first arg
 var c = args[0];
//write a function that expect a second arg
var function(arg2){
  //handle the non-numerical case
  if (arg2) ===undefined

 else{
  return c+arg2
}
}
}
Vijay
@vijayirtt59
Aug 29 2016 03:41
Plz someone help me with palindrome
YuanTianyang
@YuanTianyang
Aug 29 2016 03:41
who can help me to Counting Cards ?
Gang Zhao
@crumpx
Aug 29 2016 03:41
@inhll you're using something too advanced :P
YuanTianyang
@YuanTianyang
Aug 29 2016 03:41
I can't understand.
Counting Cards
Ian
@inhll
Aug 29 2016 03:41
@crumpx eh?
YuanTianyang
@YuanTianyang
Aug 29 2016 03:41
how to code it? Counting Cards
Patrick
@patricktownley
Aug 29 2016 03:42
@crumpx Prettier? You don't need to use regex for that one
Gang Zhao
@crumpx
Aug 29 2016 03:42
.hasOwnProperty was never used.
Ken Haduch
@khaduch
Aug 29 2016 03:42
@inhll - are some of the tests passing?
Brandon
@Brandons42
Aug 29 2016 03:42
@dlwhitehurst You'd understand why if you look at the challenge.
Ian
@inhll
Aug 29 2016 03:42
@khaduch Yep, I can get all of the tests to pass if I comment some of the code but it's not passing all at once.
Vijay
@vijayirtt59
Aug 29 2016 03:42
@crumpx i need ur help to solve palindrome
Gang Zhao
@crumpx
Aug 29 2016 03:43
@vijayirtt59 you want the code?
David L. Whitehurst
@dlwhitehurst
Aug 29 2016 03:43
@Brandons42 sorry. I'm actually doing easy challenges and keep forgetting this is tied to the challenge site. sorry
Vijay
@vijayirtt59
Aug 29 2016 03:43

function palindrome(str) {
// Good luck!
str = str.toLowerCase();
if(str === str.split('').reverse().join(''))
return true;
}

palindrome("eye");

Gang Zhao
@crumpx
Aug 29 2016 03:44
@vijayirtt59 according to the chanllenge you gotta use regex
Vijay
@vijayirtt59
Aug 29 2016 03:44
how to use replace We'll also pass strings with special symbols, such as "2A33a2", "2A3 3a2", and "2_A33#A2".
that where i am struck
Ken Haduch
@khaduch
Aug 29 2016 03:45
@inhll - you have a couple problems that I can see. First of all, maybe the biggest problem, is that you have to make sure that you can test all of the contacts before you return "No such contact" - you have that condition in the loop and that is a problem. The second thing is that you are not conditioning your return of "No such property" with the fact that you matched the firstName - you just have that as a free-standing case and it might or might not happen to pass the test, depending on the order of the contacts, the way the test is structured, etc.
Gang Zhao
@crumpx
Aug 29 2016 03:45
if you don't want my code, google for regex match non-alphanumeric characters @vijayirtt59
@patricktownley I know you don't "have" to use regex, but if i split everything and everything again and replace [0], code will be very ugly....
Ian
@inhll
Aug 29 2016 03:47
@khaduch but if I put in a condition on the no such property like this it still fails:
    for (var i = 0; i < contacts.length; i++) {

      if (contacts[i]["firstName"] == firstName &&
         contacts[i].hasOwnProperty(prop)) {
        return contacts[i][prop];
      } else if (contacts[i]["firstName"] == firstName &&
                 !contacts[i].hasOwnProperty(prop)) {
        return "No such property";
      } else if (contacts[i]["firstName"] != firstName) {
        return "No such contact";
      }
    }
It still won't get to "No such contact"
Claudio Restifo
@Marmiz
Aug 29 2016 03:47
@YuanTianyang what about counting card you don't get? :)
feel free to ask
Ken Haduch
@khaduch
Aug 29 2016 03:48
@inhll - which test is failing?
Ian
@inhll
Aug 29 2016 03:48
The first three to return a property
Boris
@Boris1011
Aug 29 2016 03:48
Help Please!!!
Doing the "Understand String Immutablitiy" and I have no what I am meant to put in!!!
Here is my code!!!
// Setup
var myStr = "Jello World";

// Only change code below this line
myStr[0] = "H"; // Fix Me
CamperBot
@camperbot
Aug 29 2016 03:48
no wiki entry for: pleasedoing the understand string immutablitiy and i have no what i am meant to put inhere is my code setupvar mystr jello world only change code below this linemystr0 h fix me
Ian
@inhll
Aug 29 2016 03:48
So if both things are true it's failing, which confuses me as it feels like it should pass.
@khaduch the if else should test "all true" >> "one true" >> "none true"
Gang Zhao
@crumpx
Aug 29 2016 03:50
function titleCase(str) {
  str = str.toLowerCase().split(' ');
  var regex= /^[\w]/;

  /*for (var i=0; i<str.length; i++){
    str[i] = str[i].replace(regex, str[i].split('')[0].toUpperCase());
  }

  str=str.join(' ');

  return str;*/

  str = str.map(function(val){
    return val.replace(regex, val.split('')[0].toUpperCase());
  }).join(' ');
   return str;
}

titleCase("I'm a little tea pot");
I think this one is prettier :D
Ken Haduch
@khaduch
Aug 29 2016 03:51
@inhll - you missed one point that I made in my previous comment - if the contact that they are searching for is not the first one in the list - what does your code do?
Vijay
@vijayirtt59
Aug 29 2016 03:52
@crumpx i need ur code for palindrome
Ian
@inhll
Aug 29 2016 03:52
@khaduch ah so I need to nest the ifs.
Tracey Bushman
@tbushman
Aug 29 2016 03:52
@Boris1011 have you tried .replace() ?
Gang Zhao
@crumpx
Aug 29 2016 03:52

function palindrome(str) {
  // Good luck!
  var pat = /[^a-zA-Z0-9]/g;
  var newStr = str.replace(pat, '').toLowerCase().split('').reverse().join('');
  str = str.replace(pat,'').toLowerCase();

  return str == newStr;
}

palindrome("not a palindrome");
@vijayirtt59
Ken Haduch
@khaduch
Aug 29 2016 03:52
@inhll - no - it's simpler than that... You cannot know if there is "no such contact" unless and until you have looked at all of the contacts. Within your for loop, if you match a contact name, you will either return the property, or "No such property". So that means that after you go through the loop and don't return one of those two things - you can do something else... after the loop...
Gang Zhao
@crumpx
Aug 29 2016 03:53
@vijayirtt59 this pat should be named something like regex..
this matches all non alphabetic chars
Vijay
@vijayirtt59
Aug 29 2016 03:54
i am not understanding this regex
Boris
@Boris1011
Aug 29 2016 03:54
@tbushman if I put that where I have myStr[0] = "H"; as in myStr[0].replace() = "H"; It then comes up with a bad assignment!?
Gang Zhao
@crumpx
Aug 29 2016 03:55
@vijayirtt59 i know it's weird...i can never understand regex
Vijay
@vijayirtt59
Aug 29 2016 03:55
is this like ^ not operator @crumpx
Gang Zhao
@crumpx
Aug 29 2016 03:55
i just google them when i need it.
^ means "not"
Gustavo Salgado
@onepointtwentyonegigawatts
Aug 29 2016 03:55
Storing Values with the Assignment Operator
// Setup
var a;
var b = 2;
// Only change code below this line
b= a;
a= 7;
b should have a value of 7?
Gang Zhao
@crumpx
Aug 29 2016 03:56
so it matches "not a-z A-z 0-9"
Tracey Bushman
@tbushman
Aug 29 2016 03:56
@Boris1011 .replace() needs two arguments
str.replace(original, replacement);
Vijay
@vijayirtt59
Aug 29 2016 03:56
got it @crumpx thank u.. here is ur brownie
CamperBot
@camperbot
Aug 29 2016 03:56
vijayirtt59 sends brownie points to @crumpx :sparkles: :thumbsup: :sparkles:
:cookie: 245 | @crumpx |http://www.freecodecamp.com/crumpx
Gang Zhao
@crumpx
Aug 29 2016 03:57
:P
opps don't look at my other codes above it's the next chanllenge. @vijayirtt59
Derock
@derock75
Aug 29 2016 03:59
Hello:) Would someone explain why phonetic.val comes out undefined here?
Ian
@inhll
Aug 29 2016 03:59
Ugh I'm an idiot. Thanks @khaduch
CamperBot
@camperbot
Aug 29 2016 03:59
inhll sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 1599 | @khaduch |http://www.freecodecamp.com/khaduch
Derock
@derock75
Aug 29 2016 03:59

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

// Only change code below this line
var phonetic = {
"alpha":"Adams",
"bravo":"Boston",
"charlie":"Chicago",
"delta":"Denver",
"echo":"Easy",
"foxtrot":"Frank"
};
window.alert (phonetic.val);
result = phonetic.val;
// Only change code above this line
return result;
}

// Change this value to test
phoneticLookup("charlie");

Boris
@Boris1011
Aug 29 2016 04:00
@tbushman so something like this then????
// Setup
var myStr = "Jello World";

// Only change code below this line
myStr.replace(myStr[0], "H"); // Fix Me
Tracey Bushman
@tbushman
Aug 29 2016 04:00
@Boris1011 might could work?
Derock
@derock75
Aug 29 2016 04:01
I don't see why phonetic.val doesn't = "Chicago" there
Gang Zhao
@crumpx
Aug 29 2016 04:01
it would work for this case but that's not how you use it xD
erick
@erickzhao
Aug 29 2016 04:02
@derock75 You need to use bracket notation
@derock75 like phonetic[val]
Derock
@derock75
Aug 29 2016 04:02
oh ok why is that?
erick
@erickzhao
Aug 29 2016 04:02
because val is a variable and dot notation takes the properties literally
Derock
@derock75
Aug 29 2016 04:02
i see
thanks
erick
@erickzhao
Aug 29 2016 04:02
np! :)
Boris
@Boris1011
Aug 29 2016 04:04
@tbushman because then I get an error saying that myStr should have a value of "Hello World!"
Michael Gee
@michaelgee22
Aug 29 2016 04:04
On the title case:
having trouble making all the other letters thats not the first one lowercase
Ken Haduch
@khaduch
Aug 29 2016 04:05
@inhll - no, it is just one of those things that catches a lot of people - I've seen it a hundred times here, at least... You just get to learn these things...
Norvin Burrus
@ndburrus
Aug 29 2016 04:06
@derock75 thi may be helpful: :sparkles:
Tracey Bushman
@tbushman
Aug 29 2016 04:06
@Boris1011 the lesson is to show you that strings are immutable. it just wants you to change the whole word as a demo
Boris
@Boris1011
Aug 29 2016 04:07
so how do I correct the myStr[0] = "H"; // Fix Me so that it equals Hello world???
Norvin Burrus
@ndburrus
Aug 29 2016 04:08
@Boris1011 :sparkles:
since we cannot change "pieces" of strings, how can we change it' value?
Boris
@Boris1011
Aug 29 2016 04:08
I really don't understand javascript!!!
Norvin Burrus
@ndburrus
Aug 29 2016 04:09
@Boris1011 sure you do... i cannot change just a letter in a string. so if i want a different word/string, how would i do it?
Boris
@Boris1011
Aug 29 2016 04:10
idk, make a new one???
Michael Gee
@michaelgee22
Aug 29 2016 04:10
how do you post a snippet of code that styles it like an image?
Norvin Burrus
@ndburrus
Aug 29 2016 04:10
@Boris1011 bingo! how can we do that? :)
Boris
@Boris1011
Aug 29 2016 04:10
help format
CamperBot
@camperbot
Aug 29 2016 04:10
no wiki entry for: format
Norvin Burrus
@ndburrus
Aug 29 2016 04:10
@michaelgee22 '''
CamperBot
@camperbot
Aug 29 2016 04:10
:bulb: to format code use backticks! ``` more info
Brandon
@Brandons42
Aug 29 2016 04:11
Are you supposed to hard code it for the numbers 2 and 3 on the challenge Arguments Optional?
Boris
@Boris1011
Aug 29 2016 04:11
@ndburrus mystr = "Hello World"; ???????
Norvin Burrus
@ndburrus
Aug 29 2016 04:12
@Boris1011 :sparkles:
you are too awesome! way to go! :+1: Run tests?
Michael Gee
@michaelgee22
Aug 29 2016 04:12
function titleCase(str) {

    var newWord;

    var titleWord = str.split(" ");

    var arr = [];

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

        var splitLetters = titleWord[i].split("");

        if( splitLetters[0] != splitLetters[0].toUpperCase() ) {

            var upperCase = splitLetters[0].toUpperCase();

            splitLetters.shift();

            splitLetters.unshift(upperCase);
        }

        for(var j = 0; j < splitLetters.length; j++) {

            if( splitLetters[j] != splitLetters[0] ) {

                //idk

            }

            newWord = splitLetters.join("");

        }

        arr.push(newWord);

    }

    var finalSent = arr.join(" ");

    console.log(finalSent);

    return finalSent;

}

titleCase("I'm a liTTle teA pot");
Boris
@Boris1011
Aug 29 2016 04:12
that does not work though!? :worried: @ndburrus
Norvin Burrus
@ndburrus
Aug 29 2016 04:13
This message was deleted
Tracey Bushman
@tbushman
Aug 29 2016 04:13
@Boris1011 try refreshing the page. I went and tried it and got an error the first time
Ramesh syangtan
@rameshsyn
Aug 29 2016 04:14
@Boris1011
myStr = "Tello world";
myStr = myStr.replace(myStr[0],"H");
console.log(myStr);
Norvin Burrus
@ndburrus
Aug 29 2016 04:14
@Boris1011 mystr should be myStr :sparkles:
Tracey Bushman
@tbushman
Aug 29 2016 04:14
^
Boris
@Boris1011
Aug 29 2016 04:14

@ndburrus Understand String Immutability

// Setup
var myStr = "Jello World";

// Only change code below this line

myStr = "Hello World";
myStr[0] = "H"; // Fix Me

@tbushman I did, still doesn't work

Gang Zhao
@crumpx
Aug 29 2016 04:14
do you have to use replace with this?
Norvin Burrus
@ndburrus
Aug 29 2016 04:14
@Boris1011 :sparkles:
  • make this myStr[0] = "H"; // Fix Me go away. (the line above it accomplishes the desired assignment.)
Michael Gee
@michaelgee22
Aug 29 2016 04:15
having trouble make all other letters lowercase for title case if anyone can help me out in the code i posted above
Gang Zhao
@crumpx
Aug 29 2016 04:15
looks like just split it and replace [0] with "H"
Boris
@Boris1011
Aug 29 2016 04:15
@ndburrus THANKYOU!!!!! :smile:
CamperBot
@camperbot
Aug 29 2016 04:15
boris1011 sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:star2: 1955 | @ndburrus |http://www.freecodecamp.com/ndburrus
Gang Zhao
@crumpx
Aug 29 2016 04:15
@michaelgee22 wanna see my code?
Brandon
@Brandons42
Aug 29 2016 04:15
@ndburrus Are you supposed to hard code it for the numbers 2 and 3 on the challenge Arguments Optional?
Michael Gee
@michaelgee22
Aug 29 2016 04:15
@crumpx sure
Norvin Burrus
@ndburrus
Aug 29 2016 04:15
@Boris1011 you're very welcome! super job! a pleasure! :palm_tree:
Gang Zhao
@crumpx
Aug 29 2016 04:16
function titleCase(str) {
  str = str.toLowerCase().split(' ');
  var regex= /^[\w]/;

  /*for (var i=0; i<str.length; i++){
    str[i] = str[i].replace(regex, str[i].split('')[0].toUpperCase());
  }

  str=str.join(' ');

  return str;*/

  return str.map(function(val){
    return val.replace(regex, val.split('')[0].toUpperCase());
  }).join(' ');
   //return str;
}

titleCase("I'm a little tea pot");
@michaelgee22
Norvin Burrus
@ndburrus
Aug 29 2016 04:16
@Brandons42 i haven't looked at that one yet :worried:
Gang Zhao
@crumpx
Aug 29 2016 04:16
2 ways to do it, i commented out the first one because i think the second one is prettier.
Michael Gee
@michaelgee22
Aug 29 2016 04:17
@crumpx thank you!
CamperBot
@camperbot
Aug 29 2016 04:17
michaelgee22 sends brownie points to @crumpx :sparkles: :thumbsup: :sparkles:
:cookie: 247 | @crumpx |http://www.freecodecamp.com/crumpx
Stephiroth
@Stephiroth
Aug 29 2016 04:17
var myStr = "FirstLine\n\"\SecondLine\\rThirdLine""
Guys what's going on please
is this not the right sequence
Gang Zhao
@crumpx
Aug 29 2016 04:19
var myStr = "FirstLine\n\"\SecondLine\\rThirdLine"
is that what you want?
Stephiroth
@Stephiroth
Aug 29 2016 04:20
I'm failing to see how that's different than what I have :/
Gang Zhao
@crumpx
Aug 29 2016 04:20
first of all you have 2 " s
and you are missing ; at the end
Norvin Burrus
@ndburrus
Aug 29 2016 04:20
This message was deleted
@Stephiroth we need to take the given string, here:
"FirstLine newline backslash SecondLine backslash carriage-return ThirdLine" (ignore the spacing) and carefully replace the appropriate text (bold words) with the escape coding (use the Code/Output chart)...
  • only one set of quotes is needed.
Stephiroth
@Stephiroth
Aug 29 2016 04:22
Trying again...
Gang Zhao
@crumpx
Aug 29 2016 04:22
oh so, var myStr = "\n\/ ///\r";
black fonts
ignore me :P
Stephiroth
@Stephiroth
Aug 29 2016 04:23
ahhh wow okay so this works
var myStr = "FirstLine\n\"\SecondLine\\rThirdLine""
Thank you so much
sorry its var myStr = "FirstLine\n\\SecondLine\\rThirdLine";
kunal
@kunal47
Aug 29 2016 04:23

// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

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

// Test your code by modifying these values
checkObj("gift");

plz help
Gang Zhao
@crumpx
Aug 29 2016 04:24
guys use ``` to post codes
kunal
@kunal47
Aug 29 2016 04:26
got it
Stephiroth
@Stephiroth
Aug 29 2016 04:26
Gang Zhao Thanks
Gang Zhao
@crumpx
Aug 29 2016 04:26
oh no problem. :)
cuongss98
@cuongss98
Aug 29 2016 04:32

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

results[n] = largestNumber;

}

return results;
}
I dont understand " results[n] " mean to do what...someone here explain it to me please ,

?
cuongss98
@cuongss98
Aug 29 2016 04:35
yes sir
Tracey Bushman
@tbushman
Aug 29 2016 04:35
@cuongss98 once you have pushed values to the results array, [n] is the index, or position, within the results array []
Gang Zhao
@crumpx
Aug 29 2016 04:35
you should use array.map and array.reduce that you learn in previously challenges to try to resolve this :D
array.map will operate on every elements in an array
Vitalii Danylov
@vitaliidanylov
Aug 29 2016 04:36
Hi everyone! WHo can give me useful piece of advice, what's wrong with my code? Thank you in advance!
var nominals = {
  "ONE HUNDRED": [100.00],
  "TWENTY": [20.00],
  "TEN": [10.00],
  "FIVE": [5.00],
  "ONE": [1.00],
  "QUARTER": [0.25],
  "DIME": [0.10],
  "NICKEL": [0.05],
  "PENNY": [0.01]
};

function checkCashRegister(price, cash, cid) {
  var change_arr = [];
  var change = cash - price;
  var money = cid.reduce(function(sum,actual){
    return sum+=actual[1];
  },0.0);

  //exceptions
  if(money < change){
    return "Insufficient Funds";
  } else if(money === change){
    return "Closed";
  }

  cid = cid.reverse();

  cid.map(function(item){
    nominals[item[0]].push(item[1]);
  });


  for(var i in nominals){
      var sum = 0.0;
      if(change > nominals[i][0] && nominals[i][0] !== 0){
          while(nominals[i][1] >= nominals[i][0]){
              nominals[i][1] -= nominals[i][0];
              change -= nominals[i][0];
              sum += nominals[i][0];
              change = Math.round(change*100)/100;

              if (change === 0 || change < nominals[i][0]){
                  break;
              }
          }

          change_arr.push([i,sum]);
      }
  }

  if(money > change && change !== 0){
    return "Insufficient Funds";
  }

  return change_arr;
}

// Example cash-in-drawer array:
// [["PENNY", 1.01],
// ["NICKEL", 2.05],
// ["DIME", 3.10],
// ["QUARTER", 4.25],
// ["ONE", 90.00],
// ["FIVE", 55.00],
// ["TEN", 20.00],
// ["TWENTY", 60.00],
// ["ONE HUNDRED", 100.00]]

checkCashRegister(19.50, 20.00, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.10], ["QUARTER", 4.25], ["ONE", 90.00], ["FIVE", 55.00], ["TEN", 20.00], ["TWENTY", 60.00], ["ONE HUNDRED", 100.00]]);
Tracey Bushman
@tbushman
Aug 29 2016 04:39
@vitaliidanylov one thing .. a for ( i in ...) statement always needs var i = 0; declared first ...
Vitalii Danylov
@vitaliidanylov
Aug 29 2016 04:41
@tbushman you mean outsisde??
Tracey Bushman
@tbushman
Aug 29 2016 04:41
@vitaliidanylov si
@vitaliidanylov that's all i've got
Vitalii Danylov
@vitaliidanylov
Aug 29 2016 04:42
@tbushman what is the difference?
Tracey Bushman
@tbushman
Aug 29 2016 04:43
@vitaliidanylov I think there's an explainer on stackexchange on it .. I read it once and got in the habit
Vitalii Danylov
@vitaliidanylov
Aug 29 2016 04:43
@tbushman
var obj = {a:1, b:2, c:3};

for (var prop in obj) {
  console.log("obj." + prop + " = " + obj[prop]);
}

// Выведет:
// "obj.a = 1"
// "obj.b = 2"
// "obj.c = 3"
official documentation
Gang Zhao
@crumpx
Aug 29 2016 04:44
@tbushman that's not true.
Tracey Bushman
@tbushman
Aug 29 2016 04:44
@vitaliidanylov cool
alrighty
Gang Zhao
@crumpx
Aug 29 2016 04:44
var nominals = {
  "ONE HUNDRED": [100.00],
  "TWENTY": [20.00],
  "TEN": [10.00],
  "FIVE": [5.00],
  "ONE": [1.00],
  "QUARTER": [0.25],
  "DIME": [0.10],
  "NICKEL": [0.05],
  "PENNY": [0.01]
};

var s='';

for (var i in nominals) {
  s += nominals[i] + ' _ ';
}
will work.
Vitalii Danylov
@vitaliidanylov
Aug 29 2016 04:45
@tbushman I think you have about some specific situaltion, where it would be useful, because var - refers to global scope
Tracey Bushman
@tbushman
Aug 29 2016 04:45
@vitaliidanylov I think it was for incrementing like for (i in arr) or whatev. Sorr
Derock
@derock75
Aug 29 2016 04:45

// Setup
var myPlants = [
{
type: "flowers",
list: [
"rose",
"tulip",
"dandelion"
]
},
{
type: "trees",
list: [
"fir",
"pine",
"birch"
]
}
];

// Only change code below this line

var secondTree = myPlants.type.trees.list1; // Change this line

sorry thought i could edit that before I sent

Vitalii Danylov
@vitaliidanylov
Aug 29 2016 04:46
@tbushman yeap, something with let
its es6
Derock
@derock75
Aug 29 2016 04:46
but it says cannot read property 'trees' of undefined
and list1 is list1
its in brackets, rather
Vitalii Danylov
@vitaliidanylov
Aug 29 2016 04:48
@derock75 trees is a value of property type
@crumpx thnks
Derock
@derock75
Aug 29 2016 04:48
ok thanks Vitalii doah
hmm but doing type 1 doesn't work either
Vitalii Danylov
@vitaliidanylov
Aug 29 2016 04:51
@derock75 you can refer to an element of the array through arr[element]
Greg Duncan
@GregatGit
Aug 29 2016 04:51
@derock75 trees are not a property - but a value
Derock
@derock75
Aug 29 2016 04:51
so I should do type[trees] ?
that's not working, either
type["trees"]
Greg Duncan
@GregatGit
Aug 29 2016 04:52
@derock75 what do you want secondTree to eqaul?
Derock
@derock75
Aug 29 2016 04:53
pine
Vitalii Danylov
@vitaliidanylov
Aug 29 2016 04:53
@derock75 look carefully on what is myPlants is
sean9
@sean9
Aug 29 2016 04:53
is there a key combination to tidy up the spacing in the code?
Greg Duncan
@GregatGit
Aug 29 2016 04:54
@derock75 so var secondTree = myPlants[1]. that is your starting point
Derock
@derock75
Aug 29 2016 04:54
ok i think I see now
Greg Duncan
@GregatGit
Aug 29 2016 04:55
@derock75 that give you the entire second object
Vitalii Danylov
@vitaliidanylov
Aug 29 2016 04:55
@derock75 you have got array of objects, each object contains two properties
Derock
@derock75
Aug 29 2016 04:55
right... thank you
Vitalii Danylov
@vitaliidanylov
Aug 29 2016 04:56
@derock75 not at all
Derock
@derock75
Aug 29 2016 04:56
huh?
Greg Duncan
@GregatGit
Aug 29 2016 04:56
@derock75 and do not use either 'type' or 'trees'
Derock
@derock75
Aug 29 2016 04:56
I got it now Greg, thanks
Sergie Marienhof
@marienhof
Aug 29 2016 04:57
i don't understand what should I do. Please help me
Derock
@derock75
Aug 29 2016 04:58
What do you mean by "not at all" Vitalii?
Gang Zhao
@crumpx
Aug 29 2016 04:59
@marienhof use result += ....
Ryan Apolinar
@ryanapolinar
Aug 29 2016 04:59

Hi, for this function, users is a list of strings, and stream and channel are objects. The console.log statement here keeps telling me that the result is undefined. Here's the code:

function buildCells(users, stream, channel){

    var result = "";

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

        var name = users[i];
        console.log(channel[name]);
}

And here is my Codepen

Vitalii Danylov
@vitaliidanylov
Aug 29 2016 05:00
@derock75 Not at all. You are welcome)
gitgenie
@gitgenie
Aug 29 2016 05:00
hey guys
Derock
@derock75
Aug 29 2016 05:01
ahh ok
gitgenie
@gitgenie
Aug 29 2016 05:01
can someone help me with no repeats challenge
here is my code

function permAlone(str) {
    var arr = str.split(''), permutations = [], uniqueArray =[], re = /(.)\1+/g;   
    function getPerm(arr,n){   
        var localArr = arr.slice(0);
        var i;
        var swap;
        var temp; 
        if(n==1){
            permutations.push(localArr.join(""));
            return;
        }
        for(i=0;i<n;i++){
            getPerm(localArr,n-1);    
            swap = (n%2 ? i: 0);
            temp = localArr[swap];
            localArr[swap] = localArr[n-1];
            localArr[n-1] = temp;    
        }
    }    
   getPerm(arr,arr.length);
   uniqueArray  = permutations.filter(function(item){return !item.match(re); });
   return uniqueArray .length;
}
permAlone('aabb');
Sergie Marienhof
@marienhof
Aug 29 2016 05:02
@crumpx I still don't get it
Tracey Bushman
@tbushman
Aug 29 2016 05:02
@ryanapolinar I think channel[] needs an index in the brackets.. try that and see what logs
Gang Zhao
@crumpx
Aug 29 2016 05:03
@marienhof just add every parameters together
Tracey Bushman
@tbushman
Aug 29 2016 05:03
@ryanapolinar actually, are you missing a } at the end?
Gang Zhao
@crumpx
Aug 29 2016 05:04
and separate them with a comma
Ryan Apolinar
@ryanapolinar
Aug 29 2016 05:04
Yeah, I realized that after I copy and pasted the code here, disregard the bracket syntax errors here
@tbushman
Gang Zhao
@crumpx
Aug 29 2016 05:07
no sorry i confused you, don't use +=
gitgenie
@gitgenie
Aug 29 2016 05:07
can some one please tell me why is my code failing for few instances
like 'abfdefa'
DJ
@qualitymanifest
Aug 29 2016 05:07
@crumpx there's nothing wrong with the +=
Gang Zhao
@crumpx
Aug 29 2016 05:08
like result = arg1 + ' , ' + arg2 + ' , ' + arg3 + ' , ' + arg4;
DJ
@qualitymanifest
Aug 29 2016 05:08
@marienhof to concatenate you need to use + not ,. and on line 5, since result is already declared, don't use var in front of it
Gang Zhao
@crumpx
Aug 29 2016 05:09
@qualitymanifest but you don't have to use += in a one line addition. especially when result is empty to start with.
DJ
@qualitymanifest
Aug 29 2016 05:10
@crumpx result is initialized as an empty string so you can definitely += to it
Gang Zhao
@crumpx
Aug 29 2016 05:11
@qualitymanifest maybe read the requirement: wordBlanks("","","","") should return a string. wordBlanks("dog", "big", "ran", "quickly") should contain all of the passed in words separated by non-word characters (and any additional words in your madlib). wordBlanks("cat", "little", "hit", "slowly") should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).
Ryan Apolinar
@ryanapolinar
Aug 29 2016 05:11

Is there a way to save the JSON object you get from $.getJSON? Trying something like this:

var channelData;
$.getJSON(makeURL("channels", user), function(data){
            channelData = data;
        });

But Google tells me getJSON calls are asynchronous and such, and I can't figure out their solutions, which is why I'm trying to save the entire object to a variable

Gang Zhao
@crumpx
Aug 29 2016 05:11
wordBlanks("","","","") should return a string.
wordBlanks("dog", "big", "ran", "quickly") should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).
wordBlanks("cat", "little", "hit", "slowly") should contain all of the passed in words separated by non-word characters (and any additional words in your madlib).
you need to have a ',' to separate these words.
DJ
@qualitymanifest
Aug 29 2016 05:12
@crumpx yeah, i'm not sure i get your point there. you told him not to use +=, all i was saying was that using += is not a problem
yes, you do have to separate the words with a non-word character.
Gang Zhao
@crumpx
Aug 29 2016 05:13
@qualitymanifest because result was empty to start with.
it's not live or death :P
Markus Kiili
@Masd925
Aug 29 2016 05:14
@ryanapolinar You can do that, but remember that the callback function is executed later when the request succeeds.
Joseph
@revisualize
Aug 29 2016 05:25
@crumpx You need a , to separate the parameters.
Gang Zhao
@crumpx
Aug 29 2016 05:26
@revisualize i got that :)
Joseph
@revisualize
Aug 29 2016 05:26

Come on people .. Word blanks is just string concatenation.

var h = "Hello";
var w = "World";
h+w; // Outputs "HelloWorld";

You just need to figure out how to add a space between the variables.

Gang Zhao
@crumpx
Aug 29 2016 05:28
some people are very beginning it might not seem obvious to them :)
Stephiroth
@Stephiroth
Aug 29 2016 05:34
my memory sucks. How do I remove the first element of an array
array.pop() <- It's not that one but the other one
I think
Markus Kiili
@Masd925
Aug 29 2016 05:35
@Stephiroth .shift()
Boring
@boringer
Aug 29 2016 05:35
array.shift()
Stephiroth
@Stephiroth
Aug 29 2016 05:36
YES. Thanks @Boring @Masd925
CamperBot
@camperbot
Aug 29 2016 05:36
:warning: could not find receiver for boring
stephiroth sends brownie points to @boring and @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2386 | @masd925 |http://www.freecodecamp.com/masd925
Norvin Burrus
@ndburrus
Aug 29 2016 05:37
@Stephiroth this may be helpful: :sparkles:
Markus Kiili
@Masd925
Aug 29 2016 05:37
Boring
@boringer
Aug 29 2016 05:39
What's brownie points?
Norvin Burrus
@ndburrus
Aug 29 2016 05:39
@boringer :sparkles:
What should I do in this lesson?
Markus Kiili
@Masd925
Aug 29 2016 05:40
@Sohan2infoSec Test parameters value and prop and access collection on if blocks. Give tracks property some special love.
Boring
@boringer
Aug 29 2016 05:41
Oh no, you gave the point to the wrong guy. @Stephiroth
Sohan2infoSec
@Sohan2infoSec
Aug 29 2016 05:42
@Masd925 k, I just get confused about the instruction :D.
Markus Kiili
@Masd925
Aug 29 2016 05:43
@boringer No he didn't. Thanks for your concern on brownie point dilutation.
CamperBot
@camperbot
Aug 29 2016 05:43
masd925 sends brownie points to @boringer :sparkles: :thumbsup: :sparkles:
:cookie: 7 | @boringer |http://www.freecodecamp.com/boringer
Gang Zhao
@crumpx
Aug 29 2016 05:45
what can i do with brownies?
Markus Kiili
@Masd925
Aug 29 2016 05:46
@crumpx Nothing too much. People will believe what you say better if you have a ton of brownies.
Gang Zhao
@crumpx
Aug 29 2016 05:47
i see
thanks
Sohan2infoSec
@Sohan2infoSec
Aug 29 2016 05:48
@Masd925 What type of error is this?
Screen Shot 2016-08-29 at 12.47.44.png
Boring
@boringer
Aug 29 2016 05:49
TypeError
Norvin Burrus
@ndburrus
Aug 29 2016 05:49
@boringer lol :)
Markus Kiili
@Masd925
Aug 29 2016 05:49
@Sohan2infoSec You try to access property key "id" which doesn't exists and it returns undefined. Then you access property hasOwnProperty of undefined, which gives an error.
Gang Zhao
@crumpx
Aug 29 2016 05:49
you're trying to access a property that is not there.
Norvin Burrus
@ndburrus
Aug 29 2016 05:50
@crumpx :sparkles:
murtuza347
@murtuza347
Aug 29 2016 05:50
hello
Markus Kiili
@Masd925
Aug 29 2016 05:50
@Sohan2infoSec
The dot notation only works if the property key string is a valid JS identifier (for example "12" and "lives left" are not) and you write the key after the dot: var cat={clothes:"pants", "lives left":3}; cat.clothes; //returns "pants". Bracket notation works with keys that can be arbitrary strings cat["lives left"]; //returns 3, variables var key="clothes"; cat[key]; //returns "pants", or expressions cat["lives"+" "+"left"]; //returns 3.
murtuza347
@murtuza347
Aug 29 2016 05:50
can we search by exercise number incase someone has already provided answers to question about that particular exercise?
Norvin Burrus
@ndburrus
Aug 29 2016 05:50
@Sohan2infoSec this may be helpful: :sparkles:
Markus Kiili
@Masd925
Aug 29 2016 05:51
@murtuza347 There are no exercise numbers, only names.
murtuza347
@murtuza347
Aug 29 2016 05:53
blob
i am doing number 204
Sohan2infoSec
@Sohan2infoSec
Aug 29 2016 05:53
I understand about the “Dot” and “Bracket Notation”, just wondering how to evaluate whether the Object has that property or not in order to add that one.
@ndburrus @Masd925
Markus Kiili
@Masd925
Aug 29 2016 05:53
@murtuza347 That is your brownie point total.
Sohan2infoSec
@Sohan2infoSec
Aug 29 2016 05:53
Screen Shot 2016-08-29 at 12.53.32.png
Gang Zhao
@crumpx
Aug 29 2016 05:54
from your address bar
Norvin Burrus
@ndburrus
Aug 29 2016 05:54
This message was deleted
Sohan2infoSec
@Sohan2infoSec
Aug 29 2016 05:55
If the “id” doesn’t have the “prop”, so I will add the new “prop” into the Object.
murtuza347
@murtuza347
Aug 29 2016 05:55
@masda925 thanks.
CamperBot
@camperbot
Aug 29 2016 05:55
murtuza347 sends brownie points to @masda925 :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for masda925
Norvin Burrus
@ndburrus
Aug 29 2016 05:55
@Sohan2infoSec if it is a variable, or has a space within the name, use bracket notation.
murtuza347
@murtuza347
Aug 29 2016 05:55
i am doing this exercise but cannot seem to get to test the property correctly
Sohan2infoSec
@Sohan2infoSec
Aug 29 2016 05:55
Screen Shot 2016-08-29 at 12.49.07.png
murtuza347
@murtuza347
Aug 29 2016 05:55

// Setup
var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

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

// Test your code by modifying these values
checkObj("gift");

Sohan2infoSec
@Sohan2infoSec
Aug 29 2016 05:56
@murtuza347 Why do you Return “checkProp”?
murtuza347
@murtuza347
Aug 29 2016 05:56
because they wanted the property returned
Sohan2infoSec
@Sohan2infoSec
Aug 29 2016 05:56
It should be a value in that “checkProp” property.
Norvin Burrus
@ndburrus
Aug 29 2016 05:56
@murtuza347 :sparkles:
  • the code returns the input variable.
  • we want to return a value based on a condition. or, a value, based on a key (within a key/value pair).
Sohan2infoSec
@Sohan2infoSec
Aug 29 2016 05:57
Not that Property name.
murtuza347
@murtuza347
Aug 29 2016 05:57
what should i be returning?
Sohan2infoSec
@Sohan2infoSec
Aug 29 2016 05:58
You should access into the “Value” of that “Property”.
Markus Kiili
@Masd925
Aug 29 2016 05:58
@murtuza347 Access the property value with syntax obj[key] and return it.
murtuza347
@murtuza347
Aug 29 2016 05:58
ok thank you everyone i will try that
Sohan2infoSec
@Sohan2infoSec
Aug 29 2016 05:59
Wei, help me with my problem :)).
@Masd925 @ndburrus
Boring
@boringer
Aug 29 2016 05:59
What's your problem?
Norvin Burrus
@ndburrus
Aug 29 2016 05:59
@Sohan2infoSec lol @ next in picture :)
Sohan2infoSec
@Sohan2infoSec
Aug 29 2016 06:00
The instruction of “https://www.freecodecamp.com/challenges/record-collection” told me that "If prop is "tracks" but the album doesn't have a "tracks" property, create an empty array before adding the new value to the album's corresponding property."
Norvin Burrus
@ndburrus
Aug 29 2016 06:01
@Sohan2infoSec :sparkles:
things we like: :)
  • if statement/s
  • .hasOwnProperty method/s
Sohan2infoSec
@Sohan2infoSec
Aug 29 2016 06:01
@ndburrus haha, yeah, first idea in my head.
Markus Kiili
@Masd925
Aug 29 2016 06:02
@Sohan2infoSec You should make tests on value and prop and only do hasOwnProperty check on the case of prop being tracks and value non-empty.
Sohan2infoSec
@Sohan2infoSec
Aug 29 2016 06:04
@Masd925 when I run this, the error (that I showed you) appears. So which Line of code is wrong?
Boring
@boringer
Aug 29 2016 06:05
Change . to [] operator. @Sohan2infoSec
Markus Kiili
@Masd925
Aug 29 2016 06:06
@Sohan2infoSec There is only one line that doesn't have an error, so put it to trash and start out again. Start making tests on value and prop as told on the instructions.
The first one could be if (value !=="" && prop!=="tracks")
Sohan2infoSec
@Sohan2infoSec
Aug 29 2016 06:07
@Masd925 k, I’m trying
Gang Zhao
@crumpx
Aug 29 2016 06:08
first thing to check here is to make sure value is not == ""
Markus Kiili
@Masd925
Aug 29 2016 06:08
There will be three such cases. Then on one case only you need to make an additional property existence test.
Gang Zhao
@crumpx
Aug 29 2016 06:08
because you can return immediately when value == ""
to save time.
"If value is empty (""), delete the given prop property from the album." to delete the prob and return.
Sohan2infoSec
@Sohan2infoSec
Aug 29 2016 06:11
@Masd925 but how to test “the album doesn’t have "tracks”?”, I mean if we want to access into the prop of album, we need to type “collection.some_id.hasOwnProperty(“tracks”)?
@crumpx I’m a little bit confused, so I will read ur instruction later.
Markus Kiili
@Masd925
Aug 29 2016 06:12
@Sohan2infoSec The id is passed on the function call and stored on parameter id, so use it to access the particular record collection[id].hasOwnP...
Gang Zhao
@crumpx
Aug 29 2016 06:16
i never thought to check if the collection has id lol
hasOwnProperty wasn't introduce to me, seem useful.
Sohan2infoSec
@Sohan2infoSec
Aug 29 2016 06:17
@Masd925 but why you told me that "You try to access property key "id" which doesn't exists and it returns undefined."
Markus Kiili
@Masd925
Aug 29 2016 06:18
@Sohan2infoSec collection.id was wrong and collection[id] is correct.
When the key is in a variable, you need to use bracket notation.
Boring
@boringer
Aug 29 2016 06:19
Yeah, I told you.
Sohan2infoSec
@Sohan2infoSec
Aug 29 2016 06:20
@Masd925 @boringer Yeah, thx for enlighten me again. Just get confused last time.
CamperBot
@camperbot
Aug 29 2016 06:20
sohan2infosec sends brownie points to @masd925 and @boringer :sparkles: :thumbsup: :sparkles:
:cookie: 12 | @boringer |http://www.freecodecamp.com/boringer
:star2: 2387 | @masd925 |http://www.freecodecamp.com/masd925
Gang Zhao
@crumpx
Aug 29 2016 06:22
good night
r2d2
@UsamaHameed
Aug 29 2016 06:23
Nothing teaches JS script execution context like the pomodoro clock :(
Ughhh
Boring
@boringer
Aug 29 2016 06:23
@crumpx You Chinese?
Gang Zhao
@crumpx
Aug 29 2016 06:24
@boringer yes
Boring
@boringer
Aug 29 2016 06:24
Me too
Gang Zhao
@crumpx
Aug 29 2016 06:24
:D
gotta go to bed like 10 mins ago. see ya.
Boring
@boringer
Aug 29 2016 06:25
Nighty night
Pericles
@periman2
Aug 29 2016 06:26
hello there people !
I have a question about a challenge
I solved the challenge but not with the functions that I was supposed to use I think
Boring
@boringer
Aug 29 2016 06:27
What question?
Pericles
@periman2
Aug 29 2016 06:27
well in Spinal Tap Case
I used match, join, and toLowerCase chained to solve the challenge
I didn't use replace because I couldn't figure out a one liner that does so
is there a solution with a one liner that solves this challenge using replace ?
Markus Kiili
@Masd925
Aug 29 2016 06:29
@periman2 You don't have to use the functions on helpful links.
Pericles
@periman2
Aug 29 2016 06:29
I know I don't I'm just curious
if it's faster with replace or not
Sohan2infoSec
@Sohan2infoSec
Aug 29 2016 06:29
@crumpx thx u too. Good Night.
CamperBot
@camperbot
Aug 29 2016 06:29
sohan2infosec sends brownie points to @crumpx :sparkles: :thumbsup: :sparkles:
:cookie: 251 | @crumpx |http://www.freecodecamp.com/crumpx
RD
@Ruchi-Dixit
Aug 29 2016 06:33
i m stuck at Record Collection, from where i can get help
Markus Kiili
@Masd925
Aug 29 2016 06:33
@Ruchi-Dixit Here.
RD
@Ruchi-Dixit
Aug 29 2016 06:33
thanks
but how can i find the issue or original code (may be)
This message was deleted
Markus Kiili
@Masd925
Aug 29 2016 06:35
Post your code here if you have a problem with your code.
RD
@Ruchi-Dixit
Aug 29 2016 06:40

// 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) {

return collection;
}

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

i couldn't figure out it properly, what i have to do in it,and how ....

Markus Kiili
@Masd925
Aug 29 2016 06:40
Test parameters value and prop and access collection on if blocks. Give tracks property some special attention.
RD
@Ruchi-Dixit
Aug 29 2016 06:42
okk, thanks @Masd925 will try ...
CamperBot
@camperbot
Aug 29 2016 06:42
ruchi-dixit sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 2388 | @masd925 |http://www.freecodecamp.com/masd925
Pericles
@periman2
Aug 29 2016 06:44
@boringer omg thanks for this but it's definitely not faster!
CamperBot
@camperbot
Aug 29 2016 06:44
periman2 sends brownie points to @boringer :sparkles: :thumbsup: :sparkles:
:cookie: 14 | @boringer |http://www.freecodecamp.com/boringer
Boring
@boringer
Aug 29 2016 06:46
It's just for fun
Gang Zhao
@crumpx
Aug 29 2016 06:46
I feel like it's cheating:p
Pericles
@periman2
Aug 29 2016 06:46
and for some reason this replaced my solution now ... please give code not links
Boring
@boringer
Aug 29 2016 06:47
But it works :)
jadczakd
@jadczakd
Aug 29 2016 06:48

Guys, I am trying to wrap my head around the Seek and Destroy.
As of now I have the following


function destroyer(arr) {
  var remove = [];
  for(var i = 1 ; i<arguments.length; i++)
    remove.push(arguments[i]);
  return remove;
  }

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

Now the question is how do I use filter() to remove REMOVE from ARR?
Do I need to write a separate function?

Markus Kiili
@Masd925
Aug 29 2016 06:49
@jadczakd Do return arr.filter(function(val) {...}); and return true from the callback function for those arr elements val you like filter to keep.
So you use remove and val to cook up the return value of the callback.
Pericles
@periman2
Aug 29 2016 06:51
@boringer it works yeah. but really look : return str.match(/[A-Z][a-z]+|[a-z]+/g).join(" ").replace(/ +/g, "-").toLowerCase()
jadczakd
@jadczakd
Aug 29 2016 06:51
@Masd925 Sorry but I still don't follow. Where is the val coming from and what is it actually?
Gang Zhao
@crumpx
Aug 29 2016 06:51
I think we can first turn caps into - and then turn everything non alphabetical into -
Pericles
@periman2
Aug 29 2016 06:51
why would they even suggest replace to this problem
Gang Zhao
@crumpx
Aug 29 2016 06:51
Yours is like callback hell :p
Es6 style
Markus Kiili
@Masd925
Aug 29 2016 06:52
@jadczakd You pass a function to filter that tells it how to filter one arbitrary arr element. Filter automatically iterates arr (under the hood) and passes each element into the callback (as val) and keeps those elements that return true.
Pericles
@periman2
Aug 29 2016 06:52
@crumpx functional programming is supposed to be a good thing no ?
Gang Zhao
@crumpx
Aug 29 2016 06:53
I like yours better
@boring's too much calls :p
Boring
@boringer
Aug 29 2016 06:54
@periman2 Yours is nice, mine is just for fun
Never mind
Pericles
@periman2
Aug 29 2016 06:55
no @boringer yours is nice too
Boring
@boringer
Aug 29 2016 06:56
So what's the problem confusing you?
jadczakd
@jadczakd
Aug 29 2016 06:56
@Masd925 or I can indexOf to check if the items to delete are in the array, correct? It would be easier I think as it will throw a -1 if it doesn't find it.
Markus Kiili
@Masd925
Aug 29 2016 06:57
@jadczakd Using indexOf inside the callback is the best way now that you have an array of arguments.
jadczakd
@jadczakd
Aug 29 2016 06:58
@Masd925 I get the idea now, execution is another case though. Could you take a look here?
function destroyer(arr) {
  var remove = [];
  for(var i = 1 ; i<arguments.length; i++)
    remove.push(arguments[i]);
  return arr.filter(function(mysteriousArgument){
                    return arr.indexOf(mysteriousArgument)===-1;
                    });
Andrew Kay
@andrewjkay
Aug 29 2016 06:59
I'm working on the Truncate a String exercise, and it isn't near finished but I can't figure out why this for loop keeps giving me an error
Boring
@boringer
Aug 29 2016 06:59
@jadczakd Or use Array.prototype.includes in ES 6 :)
Markus Kiili
@Masd925
Aug 29 2016 06:59
@jadczakd Check whether the callback parameter (arr element being iterated by filter) is found on remove.
Andrew Kay
@andrewjkay
Aug 29 2016 06:59
function truncateString(str, num) {
  var newLen = [];
  for(i=0,i<num;i++) {
    newLen = newLen.push(str);
  }
  console.log(newLen);
}

truncateString("A-tisket a-tasket A green and yellow basket", 11);
Pericles
@periman2
Aug 29 2016 06:59
@boringer I want to see if using replace it's possible to do it in one line like I did .
only replace not match
Andrew Kay
@andrewjkay
Aug 29 2016 07:00
should be newLen.push(str[i]);
Gang Zhao
@crumpx
Aug 29 2016 07:01
I will try that one tomorrow, just don't know how to insert a - before caps
But I'll get it:)
Markus Kiili
@Masd925
Aug 29 2016 07:02
@jadczakd A better name for the callback parameter is elem because it is the arr element being iterated.
jadczakd
@jadczakd
Aug 29 2016 07:02
@boringer I haven't had the pleasure with that yet. Well not anything but let and const :) @Masd925 I think I still can't
Markus Kiili
@Masd925
Aug 29 2016 07:03
@jadczakd Change the callback parameter name to elem and inside callback check if elem is not found on remove.
jadczakd
@jadczakd
Aug 29 2016 07:03
@Masd925 Therein my poblem lies. I can't wrap my head around that. Is is an element of the array becaus I am using filter? Hence no name I put there it will just be every single element of the arrray filtered?
Markus Kiili
@Masd925
Aug 29 2016 07:04
@jadczakd Filter will take that function you pass and use it to filter the elements. Filter passes each arr element into the callback as val and keeps those that return true.
jadczakd
@jadczakd
Aug 29 2016 07:05

@Masd925 Bam! It works. But I still need a follow-up on that.


function destroyer(arr) {
  var remove = [];
  for(var i = 1 ; i<arguments.length; i++)
    remove.push(arguments[i]);

  return arr.filter(function(elem){
    return remove.indexOf(elem) === -1;
  });

}

OK. I think I understand what I've done here. So I basically tell it to compare the whole array with what is in the remove array. Since I compare it that way, if something doesn't show up in the remove array, it will result in -1 / false and filter will only add those elements to the new return? Is that roughly correct?

Markus Kiili
@Masd925
Aug 29 2016 07:07
@jadczakd On call destroyer([1, 2, 3, 1, 2, 3], 2, 3); filter will pass each of those elements 1,2,3,1,2,3 into the callback and get return values true,false,false,true,false,false so it will keep only the one's and return [1,1].
RD
@Ruchi-Dixit
Aug 29 2016 07:09
hi , here is edited code please check
"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(prop!=="tracks"&& value!==""){
collectionCopy[id].artist=value;
}else if(prop==="tracks"&& value===""){
collectionCopy[id].tracks=[];

}else if(prop==="tracks"&& value!==""){
tracks.push(value);
}

return collectionCopy;
}

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

Boring
@boringer
Aug 29 2016 07:10
@jadczakd Use [].slice.call(arguments, 1) to simplify the arguments loop
jadczakd
@jadczakd
Aug 29 2016 07:10

@Masd925

return remove.indexOf(elem) === -1;

this is perfectly confusing, as I state myself that it equals false, but it's sort of a condition for "TRUE" for the filter()?

Holy cow this is confusing.
Markus Kiili
@Masd925
Aug 29 2016 07:11
@jadczakd That is true if elem (arr element) is not found on remove (array of arguments).
jadczakd
@jadczakd
Aug 29 2016 07:12
@Masd925 I sort of understand why it works, but for me it still sounds a bit like saying false = true. Welcome to the Matrix
@boringer What is this sorcery?
Markus Kiili
@Masd925
Aug 29 2016 07:12
@jadczakd You should look at simpler examples of filter usage on MDN filter page.
@jadczakd That slicing does the same as your for loop. Actually slicing arguments has some browser optimization problems, so there is nothing wrong with your for loop solution there.
Tracey Bushman
@tbushman
Aug 29 2016 07:14
@andrewjkay you don't need 'newLen =' on line four
Darth Skywalker
@adityaparab
Aug 29 2016 07:14
@jadczakd : the === or == (or any logical operator, for that matter) evaluates to either true or false. so remove.indexOf(elem) === -1; will evalueate to true if elem doesn't exist in your remove and false if it doesn't.
Darth Skywalker
@adityaparab
Aug 29 2016 07:15
and then you return the result of evaluation (true or false)
jadczakd
@jadczakd
Aug 29 2016 07:17
@adityaparab @Masd925 @boringer Thanks guys. I think I will leave the call for another sitting. This was exhausting. I do understand that, just when I think about that it's hard for me to expain it to myself. But now I have arrived at this : So this filter is basically asking if the assignment in the function is lying. If it's then it keeps it! haha, cause it's after the good of them.
CamperBot
@camperbot
Aug 29 2016 07:17
jadczakd sends brownie points to @adityaparab and @masd925 and @boringer :sparkles: :thumbsup: :sparkles:
:cookie: 15 | @boringer |http://www.freecodecamp.com/boringer
:cookie: 638 | @adityaparab |http://www.freecodecamp.com/adityaparab
:star2: 2389 | @masd925 |http://www.freecodecamp.com/masd925
Boring
@boringer
Aug 29 2016 07:19
filter, map, forEach are good functions for iterating, enjoy them
Markus Kiili
@Masd925
Aug 29 2016 07:21
@boringer It is surprising how rarely forEach is the ticket though. Usually there is some better method available for the job.
Boring
@boringer
Aug 29 2016 07:24
Excuse me, what does "rarely" mean? I don't speak English well.
Markus Kiili
@Masd925
Aug 29 2016 07:25
@boringer I just mean that you don't actually use forEach too much in actual coding because there is usually some better method to use.
Boring
@boringer
Aug 29 2016 07:28
forEach is good, so long as you use it correctly.
Mark Todd
@Knochenmark
Aug 29 2016 07:29
i agree with @Masd925 the list should rather include reduce instead of forEach
Boring
@boringer
Aug 29 2016 07:30
forEach is for each, so it can't break a loop, that's its defect.
reduce is amazing, I agree.
Cyantext
@Cyantext
Aug 29 2016 07:30
hello, I am stuck on the Mad Libs challenge mostly because I dont understand what my solution is lacking. Here's my code http://i.imgur.com/IEBdEnV.png
if anyone could help id really appreciate it
sorry for the huge embed
it's interesting because when you look at the goals at the bottom left there are 2 goals worded identically and I have one of them correct while the other is wrong
Mark Todd
@Knochenmark
Aug 29 2016 07:33
@Cyantext you overwrite the passed parameter
Alexander Domikov
@AlexanderDom
Aug 29 2016 07:33
@Cyantext you define already values of myNoun, myAdjective, etc. arguments from test function add nothing
Mark Todd
@Knochenmark
Aug 29 2016 07:33
@Cyantext just use myNoun and such as they come in
Cyantext
@Cyantext
Aug 29 2016 07:34
that makes a lot of sense thanks so much
RD
@Ruchi-Dixit
Aug 29 2016 07:34
"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(prop!=="tracks"&& value!==""){
collectionCopy[id].artist=value;
}else if(prop==="tracks"&& collectionCopy[id].tracks===""){
collectionCopy[id].tracks=[];

}else if(prop==="tracks"&& value!==""){
collectionCopy[id][prop].push(value);
}else if(value===""){
delete collectionCopy[id].prop;
}

return collectionCopy;
}

// Alter values below to test your code
updateRecords(5439, "tracks", "take a chance");

Boring
@boringer
Aug 29 2016 07:34
Don't hardcode.
RD
@Ruchi-Dixit
Aug 29 2016 07:34
here is my edited code please check...
Ciprian
@Cipriot
Aug 29 2016 07:34
help
Chris Cullen
@123xylem
Aug 29 2016 07:37
http://codepen.io/123xylem/pen/JKqYZY?editors=0011
Please help why does my prompt function get overridden by the .boxclick function beneath it?
Boring
@boringer
Aug 29 2016 07:39
I've been here for a few hours reading English which I'm not good at, I'm gonna take a break, see you next time.
Cyantext
@Cyantext
Aug 29 2016 07:41
thanks for your help
Tracey Bushman
@tbushman
Aug 29 2016 07:52
@123xylem briefly looking to notice you have two instances of $('.box').on('click'.. which may confuse the computer
Mark Todd
@Knochenmark
Aug 29 2016 07:55
@123xylem in general, its not a good pattern to multiply the handlers. you might just want to have 1 click handler that handles the clicks for each of the 9 boxes instead of 9 handlers
Chris Cullen
@123xylem
Aug 29 2016 07:56
@Knochenmark @tbushman ty for suggestions... Right now I am optimizing the thing i made already... its turned into a mistake though as I cant get it to work again
CamperBot
@camperbot
Aug 29 2016 07:56
:cookie: 159 | @tbushman |http://www.freecodecamp.com/tbushman
123xylem sends brownie points to @knochenmark and @tbushman :sparkles: :thumbsup: :sparkles:
:cookie: 460 | @knochenmark |http://www.freecodecamp.com/knochenmark
Chris Cullen
@123xylem
Aug 29 2016 07:57
It used to b 400 lines of code
but it semi worked..now its short and I cant even get my if else to console.log
Mark Todd
@Knochenmark
Aug 29 2016 07:57
iam sure you can further reduce the code
Jayesh Bhatia
@Jay-20
Aug 29 2016 07:57
Instead of ths: if(prop!=="tracks"&& value!==""){
collectionCopy[id].artist=value;
} it should be: if(prop!=="tracks" &&value!==""){ collectionCopy[id][prop]=value; } similarly dont use the name directly instead use the parameters passed to the function like 'prop'
Chris Cullen
@123xylem
Aug 29 2016 07:57
$(document).ready(function() {
  user = prompt("Choose X or O", "Choose Wisely!");
  if(user == "X"||"x"){
    userX = true;
    userText = "X".css("color", "red");
    console.log(user);
  }
  else{
    userO = true;
    userText = "O".css("color", "blue");
        console.log(user);

  }
That doesnt even console.log
I have no idea why not
Jayesh Bhatia
@Jay-20
Aug 29 2016 07:57
@Ruchi-Dixit
Tracey Bushman
@tbushman
Aug 29 2016 08:00
@123xylem if you use a combo of id and class for the box clicks, you could do $('#box').on('click'... and use if .hasClass to handle different cases within one function
greg
@wearenotgroot
Aug 29 2016 08:00
@123xylem alwasy check the dev console for error
Chris Cullen
@123xylem
Aug 29 2016 08:01
@wearenotgroot i am using codepen console
greg
@wearenotgroot
Aug 29 2016 08:01
@123xylem right now it is complaining about X not having .css()
@123xylem isnt "X" just a string? so you cant use .css
Ciprian
@Cipriot
Aug 29 2016 08:02
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

// Only change code below this line.
var myData = myArray[0][0];
greg
@wearenotgroot
Aug 29 2016 08:02
@123xylem use your browsers dev console(press F12)
Ciprian
@Cipriot
Aug 29 2016 08:02
myData should be equal to 8.
Boring
@boringer
Aug 29 2016 08:04
myArray[2][1]
Chris Cullen
@123xylem
Aug 29 2016 08:10
@wearenotgroot @wearenotgroot thanks that did help greg
CamperBot
@camperbot
Aug 29 2016 08:10
123xylem sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star2: 1497 | @wearenotgroot |http://www.freecodecamp.com/wearenotgroot
Boring
@boringer
Aug 29 2016 08:11
What does "greg" mean?
greg
@wearenotgroot
Aug 29 2016 08:14
@boringer greg derive from gregoros(Greek) meaning watchful or alert
Ciprian
@Cipriot
Aug 29 2016 08:15
@boringer THX
CamperBot
@camperbot
Aug 29 2016 08:15
cipriot sends brownie points to @boringer :sparkles: :thumbsup: :sparkles:
:cookie: 29 | @boringer |http://www.freecodecamp.com/boringer
Chandrahas P
@Chan11
Aug 29 2016 08:15

function sym(args) {
 var newArr = [];
  console.log(arguments[0][1]);
  var newargs = Array.prototype.slice.call(arguments);
  newargs.reduce(k);
  function k(arr1,arr2) {
  for (var i = 0; i < arr1.length; i++) {
    if (arr2.indexOf(arr1[i]) === -1 && newArr.indexOf(arr1[i])===-1){
       newArr.push(arr1[i]);
    }
  }
  for (var j = 0; j < arr2.length; j++) {
    if (arr1.indexOf(arr2[j]) === -1 && newArr.indexOf(arr2[j])===-1){ 
      newArr.push(arr2[j]);
    }
  }
  return newArr;
 // return newArr;
  }
}
sym([1, 2, 5], [2, 3, 5], [3, 4, 5]);
pls help, it must return [1, 4, 5] ,symmetric difference
Boring
@boringer
Aug 29 2016 08:18
@wearenotgroot Thanks, I don't get it though. :smile:
CamperBot
@camperbot
Aug 29 2016 08:18
boringer sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star2: 1498 | @wearenotgroot |http://www.freecodecamp.com/wearenotgroot
greg
@wearenotgroot
Aug 29 2016 08:18
@boringer didnt you ask what my named meant? or did I misunderstood something?
Boring