These are chat archives for FreeCodeCamp/HelpJavaScript

9th
May 2016
antigaming
@antigaming
May 09 2016 00:01
and it should be contacts[i].firstName
Desiree
@hereonpurpose
May 09 2016 00:01
help format
CamperBot
@camperbot
May 09 2016 00:01

:point_right: code formatting [wiki]

Multi line Code

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

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

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

Single line Code

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

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

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

Chris Cullen
@123xylem
May 09 2016 00:02
Quick Question: How do i get my background Container to fill the page with color??http://codepen.io/123xylem/pen/reoPGp?editors=1100
Coy Sanders
@coymeetsworld
May 09 2016 00:11
@123xylem you're missing a semicolon in your background class
Chris Cullen
@123xylem
May 09 2016 00:11
@coymeetsworld oops yea good spot, It didnt change anything tho :)
Coy Sanders
@coymeetsworld
May 09 2016 00:12
did for me
try a different color
actually it didn't care about the semicolon, hmm strange not sure why
maybe because that's the only thing listed in class idk, but color did change for me
Desiree
@hereonpurpose
May 09 2016 00:14
I need help with one of the algorithms, 'Where do I belong'. Anyone game? I've got all but one of the tests passing and i'm stuck on it. :(
Coy Sanders
@coymeetsworld
May 09 2016 00:15
can you post your code and which test you're failing on @hereonpurpose ?
Desiree
@hereonpurpose
May 09 2016 00:16
function getIndexToIns(arr, num) {

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

var indexCheck =  lowToHigh.indexOf(arguments[1]); //checks if arg is in array
var iAmHere = 0; //inits var for arg insertion

//index of >=0 means arg is in array...
if (indexCheck >= 0){
  iAmHere = indexCheck;

//otherwise...
} else {

//need to check if it is < any num in arr, check all of arr
  for (var i = 0; i < lowToHigh.length; i++){

    if (arguments[1] > lowToHigh[i]){
  iAmHere = i + 1;
    //  return iAmHere; no
    } else {
      iAmHere = i;
    }
  } return iAmHere;//closes loop
}
return iAmHere;
//  return lowToHigh[2];
//  return indexCheck;
}

getIndexToIns([10, 20, 30, 40, 50], 35);
I'm failing the one I'm testing ^ @coymeetsworld
Coy Sanders
@coymeetsworld
May 09 2016 00:17
taking a look
Chris Cullen
@123xylem
May 09 2016 00:18
Any Idea on how to make the background expand?
Travis
@dukenukethem
May 09 2016 00:19
Hey FCC :)
Coy Sanders
@coymeetsworld
May 09 2016 00:20
think the problem is with your if/else statement in the loop @hereonpurpose
Desiree
@hereonpurpose
May 09 2016 00:21
when I put the actual numbers (35 and 40) into my 2nd if statement i get the right result though...
ok. let me try that
Coy Sanders
@coymeetsworld
May 09 2016 00:21
once you find the right place to insert the number you'll want to return
also you don't need to use arguments[1], you can just use num if you want
Desiree
@hereonpurpose
May 09 2016 00:22
oooh. nifty
Coy Sanders
@coymeetsworld
May 09 2016 00:22
:)
@123xylem if you want entire background to be a color you can use the body selector
body {
  background-color: something;
}
Dan Gallegos
@gallegos20
May 09 2016 00:24
function updateRecords(id, prop, value) {

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


  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
Desiree
@hereonpurpose
May 09 2016 00:24
@coymeetsworld lol. literally the only place i did not put a return statement!
Dan Gallegos
@gallegos20
May 09 2016 00:24
what am I doing wrong here lol
Coy Sanders
@coymeetsworld
May 09 2016 00:24
yeah but if you return in your if statement you'll need to do a little more to fix it
Stephen James
@sjames1958gm
May 09 2016 00:24
@gallegos20 Since id and prop are variables you have to use [] not . also you have to use collection as well
Desiree
@hereonpurpose
May 09 2016 00:25
Thanks! @coymeetsworld I'm glad i got help at least
CamperBot
@camperbot
May 09 2016 00:25
hereonpurpose sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:cookie: 767 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Chris Cullen
@123xylem
May 09 2016 00:25
@coymeetsworld is body an inbuilt css class?
how do I use it?
Coy Sanders
@coymeetsworld
May 09 2016 00:25
np @hereonpurpose
no you can select html tags with CSS remember? @123xylem
like you can style h2, p, etc
Desiree
@hereonpurpose
May 09 2016 00:25
I could probably clean it up some but it passed :)
Stephen James
@sjames1958gm
May 09 2016 00:25
@123xylem Body is the main content holder. <html><head></head><body></body></html>
Chris Cullen
@123xylem
May 09 2016 00:25
so Il put a body in HTML first?
Coy Sanders
@coymeetsworld
May 09 2016 00:26
normally yes @123xylem, but codepen does that for you
you don't need to put html or body tags, it assumes everything in there is body unless you specify otherwise
nice @hereonpurpose :thumbsup:
yeah been a few months since i did that one, I looked back at my code and i can clean up mine too lol @hereonpurpose
can actually do it with much fewer lines once you learn more JS, I can definitely reduce what I have
Dan Gallegos
@gallegos20
May 09 2016 00:28
@sjames1958gm Hey
Chris Cullen
@123xylem
May 09 2016 00:28
Dan Gallegos
@gallegos20
May 09 2016 00:28
@sjames1958gm how can i PM you here
Stephen James
@sjames1958gm
May 09 2016 00:29
CLick on my picture
Coy Sanders
@coymeetsworld
May 09 2016 00:29
you nested the css selectors @123xylem need to fix that
body is its own selector
Chris Cullen
@123xylem
May 09 2016 00:31
@coymeetsworld AHHH body goes at the top of Css
Coy Sanders
@coymeetsworld
May 09 2016 00:31
well doesn't have to be in an order but yeah needs to be separate, no nesting
Chris Cullen
@123xylem
May 09 2016 00:31
@coymeetsworld @sjames1958gm thanks
CamperBot
@camperbot
May 09 2016 00:31
123xylem sends brownie points to @coymeetsworld and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 1023 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:cookie: 768 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Chris Cullen
@123xylem
May 09 2016 00:31
What did you mean by nesting?
Coy Sanders
@coymeetsworld
May 09 2016 00:31
no problem @123xylem
Chris Cullen
@123xylem
May 09 2016 00:32
It wasnt in brackets of another .selector
Coy Sanders
@coymeetsworld
May 09 2016 00:32
yeah it was
.background {
  background-color: #630;

  body {
  background-color:  #630;
}
or it was missing a bracket i guess, guess however you view it
Chris Cullen
@123xylem
May 09 2016 00:32
Ah yea it was :) ....
Coy Sanders
@coymeetsworld
May 09 2016 00:32
indentation makes it look like its nested
Chris Cullen
@123xylem
May 09 2016 00:33
btw... Is my button centered when you view it... its off center to me but some ppl said its fine
Coy Sanders
@coymeetsworld
May 09 2016 00:34
its off center
Bård Stokkenes
@buurdi
May 09 2016 00:41
is javascript disabled on embed codepens?
ereinertsen
@ereinertsen
May 09 2016 00:56
I need help finishing this function which will add the number to end of the array, then remove the first element of my array. Can someone help me with my code?
Stephen James
@sjames1958gm
May 09 2016 00:57
@ereinertsen post your code
Or ask away
ereinertsen
@ereinertsen
May 09 2016 00:59
Screen Shot 2016-05-08 at 5.57.37 PM.png
I'm really lost on this one
Stephen James
@sjames1958gm
May 09 2016 01:00
You need to use arr and item. What function adds to the end of an array?
ereinertsen
@ereinertsen
May 09 2016 01:01
that is .push() correct?
Stephen James
@sjames1958gm
May 09 2016 01:01
Yes. Push needs a value to push.
ereinertsen
@ereinertsen
May 09 2016 01:05
I still can't figure out what I'm doing wrong
I tried assigning it a value but it's still incorrect
Zito Relova
@zitorelova
May 09 2016 01:10
hey guys, i'm having trouble with the title case a sentence challenge
Arnis Jaundzeikars
@SangSatori
May 09 2016 01:10
The correct usage is along the lines of arr.push(valueToBePushed) - this mutates the arr array in-place by pushing the value you just pass to it. What are you doing, @ereinertsen?
Zito Relova
@zitorelova
May 09 2016 01:11
after splitting the string into separate words how do i make all the elements lowercase?
Arnis Jaundzeikars
@SangSatori
May 09 2016 01:12
@zitorelova: What if you first make the string lowercase, then split it?
ereinertsen
@ereinertsen
May 09 2016 01:13
@SangSatori The lesson does not instruct to push a specific value. The assignment is checking for: nextInLine([], 1) should return 1
nextInLine(angular/angular.io#1192, 1) should return 2
nextInLine([5,6,7,8,9], 1) should return 5
After nextInLine(testArr, 10), testArr[4] should be 10
Zito Relova
@zitorelova
May 09 2016 01:13
@SangSatori ok after that i'd have to make the first letter of each element uppercase?

function titleCase(str) {
var lowerCase = str.toLowerCase();
var array = lowerCase.split(' ');
return array;
}

titleCase("I'm a little tea pot");

what i have so far
Arnis Jaundzeikars
@SangSatori
May 09 2016 01:16
@zitorelova: I don't remember what my solution was at the top off my head, let me see if I can get some context on this.
Nevermind, FCC website is broken at the moment.
Zito Relova
@zitorelova
May 09 2016 01:18
yeah it's down
thanks anyway @SangSatori i'll see what i can find on google
CamperBot
@camperbot
May 09 2016 01:18
zitorelova sends brownie points to @sangsatori :sparkles: :thumbsup: :sparkles:
:cookie: 323 | @sangsatori |http://www.freecodecamp.com/sangsatori
Robert Richey
@0x0936
May 09 2016 01:18
@zitorelova iterate over the elements of array. each element is a word from the split string. either change the element to hold a new word (title cased) or return a new array with title cased words (using the .map() method)
Arnis Jaundzeikars
@SangSatori
May 09 2016 01:19
Yep, I was about to suggest .map() as well.
Norvin Burrus
@ndburrus
May 09 2016 01:19
@gallegos20 which challenge is that?
Stephen James
@sjames1958gm
May 09 2016 01:23
@ereinertsen You are supposed to push the item that is passed in onto the array arr that is passed in
Ronique Ricketts
@RoniqueRicketts
May 09 2016 01:30
hey anyone else experiencing this? http://screencast.com/t/ewpmwzxcv
Christina
@cgraham74
May 09 2016 01:30
help smallest common multiple
CamperBot
@camperbot
May 09 2016 01:30

:point_right: algorithm smallest common multiple [wiki]

Explanation:

The smallest common multiple between two numbers is the smallest number that
both numbers can divide into. This concept can be extended to more than two
numbers as well.

We can first start with just finding the smallest common multiple between two
numbers. Naively, you can start writing out multiple of each number until you
write a multiple that exists from both numbers.

An example would be the numbers 3 and 4. The multiples of 3 are 3, 6, 9, 12, 15, 18, ... and the multiples of 4 are 4, 8, 12, 16, 20, .... The
first smallest number we run into in both lists is 12 so this is the smallest
common multiple between 3 and 4.

This problem can be confusing because most people look for the smallest common
multiple of just the two numbers but forget the keyword range. However, this
means that if you are given [1,5], then you have to check for the smallest
common multiple for all the numbers [1,2,3,4,5] that is evenly divisible by
all of them.

:pencil: read more about algorithm smallest common multiple on the FCC Wiki

Angelo Ryndon
@AIRyndon
May 09 2016 01:33
Hello All...I'm at Search and Destroy challenge, need help :smile: I dunno know how to use filter where the callback has parameters
I mean array.filter
Karan Bhandari
@karanbhandari
May 09 2016 01:55
React.js help needed!!!!!!!
Moisés Man
@moigithub
May 09 2016 02:05
@AIRyndon think this is better
https://www.youtube.com/watch?v=w4KF_lapbRI
Daniel
@profoundhub
May 09 2016 02:05
@karanbhandari :+1:
Moisés Man
@moigithub
May 09 2016 02:05
@karanbhandari what kind of hepl
nfozkan
@nfozkan
May 09 2016 02:11
could any one explain me, why the console keeps saying, <body onload="on_game") not defined
and what would be the possible solution to this?
henrywashere
@henrywashere
May 09 2016 02:13
need help with this exercise:
Instructions
Use the playerNumber variable to lookup player 16 in testObj using bracket notation.
// Setup
var playerNumber = 16;
var testObj = {
  12: "Namath",
  16: "Montana",
  19: "Unitas"
};

// Only change code below this line;

var player = testObj.playerNumber;
what am i doing wrong?
Norvin Burrus
@ndburrus
May 09 2016 02:15
@henrywashere where is the bracket notation? note: "using bracket notation" :)
henrywashere
@henrywashere
May 09 2016 02:16
i tried that but its saying im better off using dot operator
Peter Schussheim
@peterschussheim
May 09 2016 02:16
@henrywashere do you know what bracket notation is? I don't see you using it at all in the solution.
Aryan
@aryandua
May 09 2016 02:16
// Setup
var playerNumber = 16;
var testObj = {
  12: "Namath",
  16: "Montana",
  19: "Unitas"
};

// Only change code below this line;

var player = testObj[playerNumber];
that is the right thinkg
thing
henrywashere
@henrywashere
May 09 2016 02:17
nvm that worked lol
thanks @ndburrus @peterschussheim @aryandua
CamperBot
@camperbot
May 09 2016 02:17
henrywashere sends brownie points to @ndburrus and @peterschussheim and @aryandua :sparkles: :thumbsup: :sparkles:
api offline
api offline
api offline
Peter Schussheim
@peterschussheim
May 09 2016 02:17
No prob
Aryan
@aryandua
May 09 2016 02:18
np
Norvin Burrus
@ndburrus
May 09 2016 02:18
@henrywashere kudos to you! :+1:
Aryan
@aryandua
May 09 2016 02:18
var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  }
  // Add record here
];
how do I-
Add a new album to the myMusic JSON object. Add artist and title strings, release_year number, and a formats array of strings.
??
Norvin Burrus
@ndburrus
May 09 2016 02:19
@aryandua which challenge is this?
that
what does it mean??
Norvin Burrus
@ndburrus
May 09 2016 02:21
@aryandua alright.... this simply requires creating a record similar in format to the existing (provided) example. note: "Add a new album to the myMusic JSON object." no, i don't, sorry. this challenge is asking you to just create another rocord. use the example code for the existing record - simply add another one. be mindful of the format! specifically, it asks for: "Add artist and title strings, release_year number, and a formats array of strings." make sense? hint: just copy the existing record (the properties, essentially - or the keys in the key/value pairs), then substitute your own entries for the values.
Aryan
@aryandua
May 09 2016 02:22
so like...
typedef in c?
if you know c?
C
ok... never mind
can you show me the code
?

var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  }
  {
"artist":"Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  }
    ];
like that?
James Becker
@james-becker
May 09 2016 02:26
If anyone is interested in pairing for Random Quote Machine project please PM me
Frank XC
@tenkdayz
May 09 2016 02:26
have a problem with &#8730; (it's a sqr root sign) when I add it to a div.innerHTML it makes a the div push itself up a little bit.. padding 0 and margin 0 dont work
qeurago
@qeurago
May 09 2016 02:26

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

// Test Setup
var testArr = [5,6,7,8,9];

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

why doesnt this work
Norvin Burrus
@ndburrus
May 09 2016 02:27
@aryandua ...now, you're cooking.... now, enter your own values....
@qeurago which challenge is this?
qeurago
@qeurago
May 09 2016 02:28
stand in line
Frank XC
@tenkdayz
May 09 2016 02:28
@qeurago you didnt define testArr
Aryan
@aryandua
May 09 2016 02:29

var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  }
  {
    "artist":"Dua",
    "title": "Dua",
    "release_year": 1776,
    "formats": [ 
      "sd", 
      "67", 
      "LG" ],
    "gold": false
  }
    ];
it is still wrong
qeurago
@qeurago
May 09 2016 02:29
ah ok yeah
i just changed testArr to arr
now it works
Norvin Burrus
@ndburrus
May 09 2016 02:30
@qeurago ok, there you go...
Aryan
@aryandua
May 09 2016 02:30
@ndburrus what is wrong with my code?
Norvin Burrus
@ndburrus
May 09 2016 02:31
@qeurago moment...
Angelo Ryndon
@AIRyndon
May 09 2016 02:31
@moigithub nice vids, I'm trying to figure out a way to do the Search and Destroy exercise...still can't use the arguments object to look at each item properly. Here's what I have for now...its not passing yet.
function destroyer(arr) {
  // Remove all the values
  var optionalArgs = [];
  var newArray = [];
  var counter = 0;
  for(var i = 1; i < arguments.length; i++)
    {
      optionalArgs.push(arguments[i]);
    } 

  function removeCopies(value)
  {
    var itemCheck = true;

    itemCheck = (value !== optionalArgs[counter])?true:false;

    return itemCheck;
  }

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

      newArray = arr.filter(removeCopies);
      counter++;
    }

  return newArray;
}

destroyer([1,2,3,1,2,3],2,1);
Frank XC
@tenkdayz
May 09 2016 02:31
@aryandua comma
Norvin Burrus
@ndburrus
May 09 2016 02:32
@qeurago did you change all testArr's?
Angelo Ryndon
@AIRyndon
May 09 2016 02:32
my arr.filter puts only the latest filtered values from the arguments object
still trying to figure out how to make it work properly
Any help is much appreciated :)
Frank XC
@tenkdayz
May 09 2016 02:33
@AIRyndon what is it suppose to do?
Moisés Man
@moigithub
May 09 2016 02:35
@AIRyndon u can use indexOf on ur callback
and no need to use for/loop
Norvin Burrus
@ndburrus
May 09 2016 02:35
@qeurago it works now? if not, please post...
Angelo Ryndon
@AIRyndon
May 09 2016 02:35
supposed to remove all the duplicate elements
I'll try that
:)
Norvin Burrus
@ndburrus
May 09 2016 02:37
@aryandua are you all set?
Aryan
@aryandua
May 09 2016 02:37
nope
Norvin Burrus
@ndburrus
May 09 2016 02:38
@aryandua did you change the appropriate keys? essentially creating your own new record?
Aryan
@aryandua
May 09 2016 02:38
@tenkdayz what do you mean by comma?

var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  }
  {
    "artist":"Dua",
    "title": "Dua",
    "release_year": 1776,
    "formats": [ 
      "sd", 
      "67", 
      "LG" ],
    "gold": false
  }
    ];
thats my code right now
Frank XC
@tenkdayz
May 09 2016 02:39
```

var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  }// << needs a comma here
  {
    "artist":"Dua",
    "title": "Dua",
    "release_year": 1776,
    "formats": [ 
      "sd", 
      "67", 
      "LG" ],
    "gold": false
  }
    ];
```
Aryan
@aryandua
May 09 2016 02:40
hello?
Norvin Burrus
@ndburrus
May 09 2016 02:40
@aryandua the comment is accurate - to seperate records - a comma is needed. it was already in there, but it may have been accidently removed when the copied record was inserted. what types of formats are those (sd, 67, LG)?
Aryan
@aryandua
May 09 2016 02:41

var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  },
  {
    "artist":"Dua",
    "title": "Dua",
    "release_year": 1776,
    "formats": [ 
      "sd", 
      "67", 
      "LG" ],
    "gold":
  }
    ];
that?
its still wrong
:(
Norvin Burrus
@ndburrus
May 09 2016 02:43
@aryandua be precise - where is the value for gold?
Aryan
@aryandua
May 09 2016 02:43
oh
small mistake...
big outcome :)
my bad
thx @ndburrus
CamperBot
@camperbot
May 09 2016 02:44
:cookie: 337 | @ndburrus |http://www.freecodecamp.com/ndburrus
aryandua sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
Norvin Burrus
@ndburrus
May 09 2016 02:45
@aryandua You're top of the food chain! :sparkles:
Angelo Ryndon
@AIRyndon
May 09 2016 02:51
@moigithub Hey bro, can't figure out how to go through the arguments object without looping through them
celoos
@celoos
May 09 2016 02:52
o.- hmm back to the coding.
@AIRyndon Are you working on a challenge?
Angelo Ryndon
@AIRyndon
May 09 2016 02:53
yup...Seek and Destroy
Justin Woodward
@jwoo92
May 09 2016 02:53
@sjames1958gm i added in an else statement, would this be more of a proper format?

function bouncer(arr) {

  function falsy(element){
  var x = Boolean('false');
    if (x) {
      return element;
    } else {
      return false;
    }
  } 

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

bouncer([7, "ate", "", false, 9]);
Angelo Ryndon
@AIRyndon
May 09 2016 02:54

@jwoo92

function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  function removeFalsy(value)
  {
    var booly = Boolean(value);
    return (booly)?true:false;
  }
  return arr.filter(removeFalsy);
}

bouncer([null]);

You can write it this way bro

acgillette
@acgillette
May 09 2016 02:54
for the falsy one my function was just one line of code on the return line
Angelo Ryndon
@AIRyndon
May 09 2016 02:55
@jwoo92 or you can even remove the var x = Boolean
@jwoo92 you can just do arr.filter(Boolean) in the return statement :)
celoos
@celoos
May 09 2016 02:55
ok so the arguments object works like any other object. @AIRyndon so your object for that challenge is going to contain everything passed into the function
acgillette
@acgillette
May 09 2016 02:55
I just did
```function isFalsy(value) {
return Boolean(value);
}
and that will return true or false
Travis
@dukenukethem
May 09 2016 02:56
help Mutations
CamperBot
@camperbot
May 09 2016 02:56

:point_right: algorithm mutations [wiki]

Problem Explanation:

  • Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array..
:pencil: read more about algorithm mutations on the FCC Wiki
acgillette
@acgillette
May 09 2016 02:57
What do you need help with @dukenukethem ?
Angelo Ryndon
@AIRyndon
May 09 2016 02:57
@cellos yeah I already had that, the thing is, I can't figure out how to iterate through that arguments object to compare the first argument's content with the other ones. Here's what I have, I'm at work and can't focus on it..I'm stuck on this :smile:
function destroyer(arr) {
  // Remove all the values
  var optionalArgs = [];
  var newArray = [];
  var counter = 0;
  for(var i = 1; i < arguments.length; i++)
    {
      optionalArgs.push(arguments[i]);
    } 

  function removeCopies(value,index,array)
  {
    var itemCheck = true;


    itemCheck = (value !== optionalArgs[counter])?true:false;

    return itemCheck;
  }

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

      newArray = arr.filter(removeCopies);
      counter++;
    }

  return newArray;
}

destroyer([1,2,3,1,2,3],2,1);
acgillette
@acgillette
May 09 2016 02:57
I did that one recently so it's still fresh in my mind lol
Travis
@dukenukethem
May 09 2016 02:58
@acgillette not quite sure how to articulate what im not understanding yet
celoos
@celoos
May 09 2016 02:58
Try using indexOf @AIRyndon
Look up the use of that function
acgillette
@acgillette
May 09 2016 02:58
well is it a logic problem or a problem with code you've written?
EricOber
@EricOber
May 09 2016 02:58
hey everyone, is there anyone out there who can help me with me code?
Justin Woodward
@jwoo92
May 09 2016 02:58
@AIRyndon @acgillette thanks, i didnt realize i could simply use Boolean(value) to configure true/false.
CamperBot
@camperbot
May 09 2016 02:58
jwoo92 sends brownie points to @airyndon and @acgillette :sparkles: :thumbsup: :sparkles:
:cookie: 272 | @acgillette |http://www.freecodecamp.com/acgillette
:cookie: 272 | @airyndon |http://www.freecodecamp.com/airyndon
Travis
@dukenukethem
May 09 2016 02:59
I guess i'm not understanding how .indexOf() is relevant to this challenge
celoos
@celoos
May 09 2016 02:59
You can use indexOf to check whether the value is in the arguments object
depending how you implement it
everything depends on how you implement your solution to the challenges.
acgillette
@acgillette
May 09 2016 03:00
I actually came in here for help on Seek and Destroy as well if someone wants to take a look at my code
Rhjoo
@Rhjoo
May 09 2016 03:00
Hi, i'm stuck at Counting Cards. Any help would be appreciated.
celoos
@celoos
May 09 2016 03:00
Go ahead.
acgillette
@acgillette
May 09 2016 03:00

function destroyer(arr) {
  function toDestroy(value) {
    for (var i = 0; i < arguments.length; i++) {
      if (value == arguments[i]) {
        return false;
      }
    }
    return true;
  }

    return arr.filter(toDestroy);
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Justin Woodward
@jwoo92
May 09 2016 03:00
@dukenukethem that one was a little tricky for me.
Travis
@dukenukethem
May 09 2016 03:01
@jwoo92 I can see why.
acgillette
@acgillette
May 09 2016 03:01
@Rhjoo what are you stuck on?
celoos
@celoos
May 09 2016 03:01
Keep in mind what the object arguments contains
Rhjoo
@Rhjoo
May 09 2016 03:01
var count = 0;

function cc(card) {
  // Only change code below this line
  if (card >= 2 && card <=6) {
    count += 1;
  } else if (card >=7 && card <= 9) {
    count += 0;
  } else if (card == 10 || card == "J" || card == "Q" || card == "K" || card == "A") {
    count -= 1;
  }

  if (count > 0) {
    return count.toString() + " Hold";
  } else {
    return count.toString() + " Bet";
  }
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
Travis
@dukenukethem
May 09 2016 03:01
I'm trying to figure out more how to compare the items in the array
Justin Woodward
@jwoo92
May 09 2016 03:01
@dukenukethem the next one was tricky for me as well, but only because i didnt understand the Boolean function. youll see what i mean soon.
celoos
@celoos
May 09 2016 03:01
@acgillette the Arguments object looks like { [array], [item], [item] }
Travis
@dukenukethem
May 09 2016 03:01
that falsy one?
Justin Woodward
@jwoo92
May 09 2016 03:02
@dukenukethem yeah, but i went into it not understanding the Boolean function.
turned something simple into complicated.
Travis
@dukenukethem
May 09 2016 03:02
I'll have to look up the Boolean function
Rhjoo
@Rhjoo
May 09 2016 03:02
I get 0 Bet on the console, so I'm assuming it worked, but rest of the card sequence examples are not outputting right
Travis
@dukenukethem
May 09 2016 03:02
cause im sure ill go into it confused
Coy Sanders
@coymeetsworld
May 09 2016 03:02
@acgillette when you do arguments.length it will include the first argument, your array
acgillette
@acgillette
May 09 2016 03:02
@Rhjoo I used a switch statement for the counting cards, I think it would be more effective in this case
ohhhhhh ok. So it's a syntax issue @coymeetsworld ?
EricOber
@EricOber
May 09 2016 03:03
can someone help me with my code? Im trying the "Iterate Through an Array with a For Loop" challenge
Angelo Ryndon
@AIRyndon
May 09 2016 03:03
@acgillette we have the same problem, I wrote it like yours first time, failed, @celoos mentioned indexOf..can't read on it fully since I'm still at work :)
Coy Sanders
@coymeetsworld
May 09 2016 03:03
well not syntax more like logic error
EricOber
@EricOber
May 09 2016 03:03

// Example
var ourArr = [ 9, 10, 11, 12];
var ourTotal = 0;

for (var i = 0; i < ourArr.length; i++) {
  ourTotal += ourArr[i];
}

// Setup
var myArr = [ 2, 3, 4, 5, 6];

// Only change code below this line
var myTotal = 0;


for (var i = 0; i > myArr.length; i++) {
  myTotal += myArr[i];
}
Rhjoo
@Rhjoo
May 09 2016 03:03
@acgillette for both? I can try that
celoos
@celoos
May 09 2016 03:03
So in that challenge arguments[0] = array @acgillette
Coy Sanders
@coymeetsworld
May 09 2016 03:03
try starting at i=1
acgillette
@acgillette
May 09 2016 03:03
aahhhh ok
celoos
@celoos
May 09 2016 03:03
indexOf checks an array for the precense of a value and returns the index if it exists or -1 if it does not
Norvin Burrus
@ndburrus
May 09 2016 03:04
@Rhjoo review/check the logic...if count > 0 Hold? note: "The function will then return a string with the current count and the string "Bet" if the count is positive, "
celoos
@celoos
May 09 2016 03:05
Therefore if you move the arguments into an array you can compare the two arrays using a loop as you have planned
Travis
@dukenukethem
May 09 2016 03:05
So I want to make my strings in my array lowercase,
then use a loop to loop through each character to see if it matches up; if not returns false
celoos
@celoos
May 09 2016 03:05
Have you tried looking at .split and .toLowerCase? @dukenukethem
Travis
@dukenukethem
May 09 2016 03:06

function mutation(arr) {
  var testable = arr[1].toLowerCase;
  var compare = arr[0].toLowerCase;
  for (i=0; i< compare.length; i++);
}
this is waht i have so far
celoos
@celoos
May 09 2016 03:06
well
Coy Sanders
@coymeetsworld
May 09 2016 03:06
actually @acgillette i don't that what I said will work either
celoos
@celoos
May 09 2016 03:06
you would want the arr calls to have arr[i] within the for loop or you're not going to get all of your array checked
You'll just get arr[1] and arr[0]
Coy Sanders
@coymeetsworld
May 09 2016 03:07
arguments is different in the destroyer function than it is in the toDestroy function, you should put the arguments for destroyer in a variable, take a look at this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments
var args = Array.prototype.slice.call(arguments); specifically
then reference args inside your inner function
celoos
@celoos
May 09 2016 03:08
^ in that case, args is an array which you can check the indexOf against.
Handy function.
Justin Woodward
@jwoo92
May 09 2016 03:09
@dukenukethem looking good so far.
Rhjoo
@Rhjoo
May 09 2016 03:09
@ndburrus Thanks for catching that, I think I mixed those up. Let me try again
CamperBot
@camperbot
May 09 2016 03:09
rhjoo sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:cookie: 338 | @ndburrus |http://www.freecodecamp.com/ndburrus
Travis
@dukenukethem
May 09 2016 03:09
@celoos something like this?
for (i=0; i< testable.length; i++) {
    if (compare.indexOf(testable[i]) < 0)
      return false;
  }
celoos
@celoos
May 09 2016 03:10
that should work I think.
I'd have to run it
EricOber
@EricOber
May 09 2016 03:10
Does this code work?
Norvin Burrus
@ndburrus
May 09 2016 03:10
@Rhjoo You're world class - you're just testing us! :sparkles:
EricOber
@EricOber
May 09 2016 03:10

// Example
var ourArr = [ 9, 10, 11, 12];
var ourTotal = 0;

for (var i = 0; i < ourArr.length; i++) {
  ourTotal += ourArr[i];
}

// Setup
var myArr = [ 2, 3, 4, 5, 6];

// Only change code below this line
var myTotal = 0;


for (var i = 0; i > myArr.length; i++) {
  myTotal += myArr[i];
}
it says "total is undefined"
Coy Sanders
@coymeetsworld
May 09 2016 03:11
all but that last for loop @Am3ricanPaladin
Justin Woodward
@jwoo92
May 09 2016 03:11
@dukenukethem i had the same thing except for < 0 part.
Coy Sanders
@coymeetsworld
May 09 2016 03:11
which won't do anything
EricOber
@EricOber
May 09 2016 03:11
@coymeetsworld why is that?
Coy Sanders
@coymeetsworld
May 09 2016 03:11
because your condition is the loop goes while i > myArr.length
Travis
@dukenukethem
May 09 2016 03:11
i > myArr.llength;
acgillette
@acgillette
May 09 2016 03:11

function destroyer(arr) {
var args = Array.from(arguments);
  function toDestroy(value) {


    for (var i = 0; i < args.length; i++) {
      if (args[i] !== value) {
        return false;
      }
      }




    return true;
  }

    return arr.filter(toDestroy);
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
this is what I have now but it still doesn't work. It's returning only an empty string which leads me to believe the function is only returning false.
Travis
@dukenukethem
May 09 2016 03:11
needs to be i < myArr.length
Coy Sanders
@coymeetsworld
May 09 2016 03:11
and since i initializes at 0 and 0 is never greater than the length of anything the for loop wont run
remember i=1 acgi
@acgillette
actually better option i did was run args.shift() right after to remove the array from args
and just do i=0 if you do it that way
celoos
@celoos
May 09 2016 03:12
@acgillette try indexOf
and loop through the array, not the args
the args array = blacklist. You want to check your array against the blacklist
EricOber
@EricOber
May 09 2016 03:13
what about now?

// Example
var ourArr = [ 9, 10, 11, 12];
var ourTotal = 0;

for (var i = 0; i < ourArr.length; i++) {
  ourTotal += ourArr[i];
}

// Setup
var myArr = [ 2, 3, 4, 5, 6];

// Only change code below this line
var myTotal = 0;

for (var i = 0; i < myArr.length; i++) {
  myTotal += myArr[i];
}
celoos
@celoos
May 09 2016 03:13
You'll also want to make sure your.. ^ that
Coy Sanders
@coymeetsworld
May 09 2016 03:13
@celoos she is looping through the array, through the filter function
celoos
@celoos
May 09 2016 03:14
wow i'm lagging now ._. messages are flooding me. I didnt see the filter - thanks @coymeetsworld
CamperBot
@camperbot
May 09 2016 03:14
celoos sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:cookie: 770 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Rhjoo
@Rhjoo
May 09 2016 03:14
@ndburrus @acgillette Haha I wish I was. I reversed the Bet and Hold, as well as the first part of function, using switch statement, but still seemed to be stuck.
Travis
@dukenukethem
May 09 2016 03:14
"non boolean value" what is that?
acgillette
@acgillette
May 09 2016 03:14
oh wait duh, the arr I'm being given isn't just the initial array is it
Travis
@dukenukethem
May 09 2016 03:14
Numbers and strings?
Rhjoo
@Rhjoo
May 09 2016 03:14
var count = 0;

function cc(card) {
  // Only change code below this line
  switch (card) {
    case (card >= 2 && card <=6):
      count += 1;
      break;
    case (card >=7 && card <= 9):
      count += 0;
      break;
    case (card == 10 || card == "J" || card == "Q" || card == "K" || card == "A"):
      count -= 1;
      break;
  }

  if (count > 0) {
      return count.toString() + " Bet";
  } else {
      return count.toString() + " Hold";
  }
  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
Coy Sanders
@coymeetsworld
May 09 2016 03:15
@acgillette no arr should be that first array
acgillette
@acgillette
May 09 2016 03:15
ok so it is just the array
Coy Sanders
@coymeetsworld
May 09 2016 03:16
yeah, [1,2,3,1,2,3]
Angelo Ryndon
@AIRyndon
May 09 2016 03:16
@coymeetsworld I'm on the same challenge, search and destroy..I saved the arguments
celoos
@celoos
May 09 2016 03:16
arr is only accepting the first argument, but everything given is saved in the arguments object.
Coy Sanders
@coymeetsworld
May 09 2016 03:16
arguments is all 3 arguments, [1,2,3,1,2,3] , 2, 3
tekac
@tekac
May 09 2016 03:16
'''js
CamperBot
@camperbot
May 09 2016 03:16
:bulb: to format code use backticks! ``` more info
Angelo Ryndon
@AIRyndon
May 09 2016 03:16
just need to figure out how to go through the array
tekac
@tekac
May 09 2016 03:16
i dont have back ticks on le ipad :(
celoos
@celoos
May 09 2016 03:17
Try special characters icon in bottom left?
Travis
@dukenukethem
May 09 2016 03:17
@jwoo92 I see what you mean, I dont even know where to begin
tekac
@tekac
May 09 2016 03:17
~~~js
Coy Sanders
@coymeetsworld
May 09 2016 03:18
think your logic needs some tweaking too though @acgillette
Justin Woodward
@jwoo92
May 09 2016 03:18
@dukenukethem i spent hours on falsy. it came down to me understanding the Boolean function.
Norvin Burrus
@ndburrus
May 09 2016 03:18
@Rhjoo which test is not passing? the logic looks good...
acgillette
@acgillette
May 09 2016 03:18
yeah it does. currently commenting things out to try and root it out
Travis
@dukenukethem
May 09 2016 03:18
I just read the Boolean operators page; and im not understanding it at all
acgillette
@acgillette
May 09 2016 03:18
ugh so close to being done with the first algorithms but so far as well lol
Coy Sanders
@coymeetsworld
May 09 2016 03:19
what you're doing in your for loop is comparing the value to all the arguments
if any one of the arguments doesn't equal the value then you return false
but in reality it should be if none of them match you should return true
acgillette
@acgillette
May 09 2016 03:21
oh crap you're right, logic flaws are so obvious in hindsight hahaha
Travis
@dukenukethem
May 09 2016 03:21
So you're filtering out all Boolean expressions in this one right?
Coy Sanders
@coymeetsworld
May 09 2016 03:21
yeah haha, thats why you're getting empty arrays, if you have more than 2 destroy numbers that are different you'll never get an array w/ anything
Justin Woodward
@jwoo92
May 09 2016 03:23
@dukenukethem from what i understand, Boolean function will return anything true except for falsy statements.
Travis
@dukenukethem
May 09 2016 03:23
so its another 1 line code
Rhjoo
@Rhjoo
May 09 2016 03:23
@ndburrus Looks like everything comes out as "0 Hold" I have a feeling count is staying as 0, and has something to do with variable scope...?
Travis
@dukenukethem
May 09 2016 03:24
since Boolean is already a function I can just put it into the .filter()
I'm glad I googled Boolean function and started reading lmao
I though I was going to have to define each falsy statement.
Coy Sanders
@coymeetsworld
May 09 2016 03:25
@Rhjoo you don't need to run count.toString(), you can just put count
also not sure if you can do case/switch statements like that
the case you're looking for is a card value, not a true/false value
acgillette
@acgillette
May 09 2016 03:29
so what I thought I was doing was when I passed one of the values of the array, it would check it against args[i], and if it was equal it would return false, but if neither were equal it would return true. Do you think it would be possible to clarify what is wrong with my logic? I had fixed !== to === but it's still returning empty arrays
Norvin Burrus
@ndburrus
May 09 2016 03:30
@Rhjoo ok, moment
acgillette
@acgillette
May 09 2016 03:30

function destroyer(arr) {
var args = Array.from(arguments).shift();
  function toDestroy(value) {

    for (var i = 0; i < args.length; i++) {
      if (args[i] === value) {
        return false;
      }

    }




    return true;
  }

    return arr.filter(toDestroy);
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
rphares
@rphares
May 09 2016 03:30
@antigaming -- hey, i sent admin a message, hopefully someone will reach out! :blush: (sorry, went out for most of the day~)
Coy Sanders
@coymeetsworld
May 09 2016 03:30
sure so filter goes through the array right? first value that goes to destroy is 1
what happens when you get in the for loop @acgillette ?
acgillette
@acgillette
May 09 2016 03:31
which would be 2
it goes to the first value in the args array
rphares
@rphares
May 09 2016 03:31
(i did so assuming they hadn't sent it to you-- the report that should have been there i cant find, and the message should have been there when you logged in if it was unread, so... @antigaming :blush: )
Coy Sanders
@coymeetsworld
May 09 2016 03:32
yep good
acgillette
@acgillette
May 09 2016 03:33
and if 2 === 1 it returns false. Which i thought is what I should return for arr.filter?
Coy Sanders
@coymeetsworld
May 09 2016 03:33
if you return false it means the value is removed from the array
oh also you're starting at 0 again w/ i
you can leave it there, what i did was run args.shift(); once
acgillette
@acgillette
May 09 2016 03:34
I did that
Coy Sanders
@coymeetsworld
May 09 2016 03:34
oh i see
acgillette
@acgillette
May 09 2016 03:34
it's chained onto the end of Array.from
Coy Sanders
@coymeetsworld
May 09 2016 03:34
well wait i don't think you can do it that way
shift returns the array
or rather the item you remove
so args would be [1,2,3,1,2,3] i think
acgillette
@acgillette
May 09 2016 03:34
aw damn
Coy Sanders
@coymeetsworld
May 09 2016 03:35
ya, just call it right after
don't need to assign it to anything
acgillette
@acgillette
May 09 2016 03:35
hahaha that fixed it
Coy Sanders
@coymeetsworld
May 09 2016 03:36
yeah, didn't see that you changed the !== to === so that was all good
acgillette
@acgillette
May 09 2016 03:36
thank you again @coymeetsworld for helping me in my ignorance
CamperBot
@camperbot
May 09 2016 03:36
acgillette sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:cookie: 771 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Norvin Burrus
@ndburrus
May 09 2016 03:36
@Rhjoo i agree with @coymeetsworld it's probably best to stick to the case statement format (i haven't seen one like it is formatted in the code). also, agree that to.string isn't necessary. with those adjustments, it should be fine.... oh, you're right - it appears this always produces a count = 0.
acgillette
@acgillette
May 09 2016 03:36
again, like you've done many times
Coy Sanders
@coymeetsworld
May 09 2016 03:36
no problem lol, functional programming is tough took me a while to learn it :)
acgillette
@acgillette
May 09 2016 03:36
yeah I feel like I understand the logic pretty well but sometimes I mess up on the syntax portion
Coy Sanders
@coymeetsworld
May 09 2016 03:36
still have problems with it sometimes
acgillette
@acgillette
May 09 2016 03:37
got too into chaining functions willy nilly
Coy Sanders
@coymeetsworld
May 09 2016 03:37
yeah, one thing that's helpful for me is using console.log to debug my code
so you can see what's going on
acgillette
@acgillette
May 09 2016 03:37
makes my code so pretty tho
Coy Sanders
@coymeetsworld
May 09 2016 03:37
i nest them around and try to get what states my variables are in so i get an idea of whats going on
yeah agreed, and that's not bad if you do it the right way, makes code much more succinct
but have to be careful when you do it lol
dont get overzealous
acgillette
@acgillette
May 09 2016 03:38
I usually comment out code and return variables to fix it but I got too wrapped up in thinking my logic was bad
Coy Sanders
@coymeetsworld
May 09 2016 03:38
what was the Einstein quote? Make things as simple as possible but not simpler
Thomas Hodges
@thodges314
May 09 2016 03:38
Hello. Maybe someone can give me aide? I've sorted out how to get json from a wikipedia search but it refuses to parse:
http://codepen.io/thodges314/pen/PNVOmb
I've tested the url manually - I get good JSON formatted output
Angelo Ryndon
@AIRyndon
May 09 2016 03:39
I'm still stuck at Search and Destroy...LOL...longest for me
Norvin Burrus
@ndburrus
May 09 2016 03:39
@Rhjoo the var/iable scope is fine (the way it is - it is not an issue).... var (count should be global - outside of the function).
Coy Sanders
@coymeetsworld
May 09 2016 03:40
what do you have @AIRyndon ?
acgillette
@acgillette
May 09 2016 03:40
haha it's hard! I finally just got it
Angelo Ryndon
@AIRyndon
May 09 2016 03:41

@coymeetsworld

function destroyer(arr) {
  // Remove all the values
  var optionalArgs = [];

  for(var i = 1; i < arguments.length; i++)
    {
      optionalArgs.push(arguments[i]);
    } 

  function removeCopies(value)
  {
    for(var i = 0; i < optionalArgs.length;i++)
    {
      if (value === optionalArgs[i])
        return false;
      else
        return true;
    }

  }

  return optionalArgs;
}

This...

Rhjoo
@Rhjoo
May 09 2016 03:41
@ndburrus I wasn't sure if I was doing it right with switch statement, so I went back to if/else if route and seemed to work. I think what I did wrong first time was that I put simply "else" instead of "self if"
Angelo Ryndon
@AIRyndon
May 09 2016 03:41
I usually don't take more than 15-30 mins on these algo challenges hahaha
Coy Sanders
@coymeetsworld
May 09 2016 03:41
you will @AIRyndon lol, they get harder
Rhjoo
@Rhjoo
May 09 2016 03:41
Thanks again guys for the input
Angelo Ryndon
@AIRyndon
May 09 2016 03:41
I should've returned arr.filter there
Norvin Burrus
@ndburrus
May 09 2016 03:41
@Rhjoo you mean else if... ok, so does it parse/validate? np, anytime... :)
Angelo Ryndon
@AIRyndon
May 09 2016 03:41
forgot to edit :)...but it still fails
Coy Sanders
@coymeetsworld
May 09 2016 03:42
is that all the code?
some things are missing
acgillette
@acgillette
May 09 2016 03:42
you don't want to put the return true in an else statement
you want it outside the loop
Coy Sanders
@coymeetsworld
May 09 2016 03:42
yeah thats one thing, basically your for loop will only execute once
acgillette
@acgillette
May 09 2016 03:42
otherwise you'll exit too early
Coy Sanders
@coymeetsworld
May 09 2016 03:43
but i don't see you iterating through the array, or the filter function assuming that's what you're using
acgillette
@acgillette
May 09 2016 03:43
you're also missing some brackets I think
Angelo Ryndon
@AIRyndon
May 09 2016 03:43
got it
:smile:
just missed some edits
when I copy pasted here hehe
acgillette
@acgillette
May 09 2016 03:44
you can also just use var args = Array.from(arguments); to transfer the arguments into an array which is a bit more elegant, but that's personal taste :P
Angelo Ryndon
@AIRyndon
May 09 2016 03:44
function destroyer(arr) {
  // Remove all the values
  var optionalArgs = [];

  for(var i = 1; i < arguments.length; i++)
    {
      optionalArgs.push(arguments[i]);
    } 

  function removeCopies(value)
  {
    for(var i = 0; i < optionalArgs.length;i++)
    {
      if (value === optionalArgs[i])
        return false;
    }
    return true;

  }

  return arr.filter(removeCopies);
}

destroyer([1,2,3,1,2,3],1,2);
Did this :smile:
Coy Sanders
@coymeetsworld
May 09 2016 03:44
yeah agreed thats a better way, and chop off the first item
Rhjoo
@Rhjoo
May 09 2016 03:44
@ndburrus Oops yes I meant else if, haha. I did get rid of the toString(), thanks for pointing that out that it wasn't necessary
CamperBot
@camperbot
May 09 2016 03:44
rhjoo sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:warning: rhjoo already gave ndburrus points
Coy Sanders
@coymeetsworld
May 09 2016 03:45
looks ok to me
Angelo Ryndon
@AIRyndon
May 09 2016 03:45
Damn it I think the intermediate ones will take me hours..lol
Coy Sanders
@coymeetsworld
May 09 2016 03:45
does that work?
Angelo Ryndon
@AIRyndon
May 09 2016 03:45
yeah it does pass
Coy Sanders
@coymeetsworld
May 09 2016 03:45
ok
Angelo Ryndon
@AIRyndon
May 09 2016 03:45
looks bad though lol
Travis
@dukenukethem
May 09 2016 03:45
How the heck...do you even start Seek and Destroy
Coy Sanders
@coymeetsworld
May 09 2016 03:45
try what @acgillette said
acgillette
@acgillette
May 09 2016 03:45
haha my mutations one was like that, it was some ugly code.
Coy Sanders
@coymeetsworld
May 09 2016 03:46
you can put your arguments into an array with var args = Array.from(arguments);, then run args.shift(); after to remove the array from args
that will save you a few lines, the rest of it is about as simple as you can get
acgillette
@acgillette
May 09 2016 03:46
@dukenukethem think about what you need to build, I often like making a littlke flow chart of my logic before I even start
Coy Sanders
@coymeetsworld
May 09 2016 03:46
@dukenukethem familiarize yourself with the Array.filter() function
that will help
acgillette
@acgillette
May 09 2016 03:47
@dukenukethem so you know you need to iterate through your array and also through the arguments. You can iterate through the array with .filter()
then it's a matter of figuring out how to build the function the filter() calls
or thats how I approached it
I'm a code baby though so you should listen to @coymeetsworld more than me
Justin Woodward
@jwoo92
May 09 2016 03:48
yeah im stuck on seek and destroy too
Coy Sanders
@coymeetsworld
May 09 2016 03:48
nah that sounds good @acgillette :thumbsup: thats what I did too lol
Angelo Ryndon
@AIRyndon
May 09 2016 03:48
@jwoo92 @dukenukethem me and @acgillette just got over them
tekac
@tekac
May 09 2016 03:48

Angelo Ryndon
@AIRyndon
May 09 2016 03:48
it took me almost an hour..LOL
acgillette
@acgillette
May 09 2016 03:49
it took me way too long for what ended up being a syntax error lmao
Coy Sanders
@coymeetsworld
May 09 2016 03:49
one or two of the advanced (optional) algorithms took me a week or two :/
Angelo Ryndon
@AIRyndon
May 09 2016 03:49
jesus christ...I'm scared and excited hahaha
Travis
@dukenukethem
May 09 2016 03:49
Build a function that compares my array with a 2nd argument that will then filter out the 2nd arguments values from my array.
Coy Sanders
@coymeetsworld
May 09 2016 03:50
yeah lol i mean idk how many hours exactly, wasn't like 40 or anything but i didn't finish it in an hour thats for sure
acgillette
@acgillette
May 09 2016 03:50
no you want to compare your array with all the arguments
@dukenukethem I would look closely at the arguments documentation
I didn't at first and it caused some problems
Justin Woodward
@jwoo92
May 09 2016 03:50
hopefully i pick up on some skill before i get to those @coymeetsworld
Travis
@dukenukethem
May 09 2016 03:50
I started reading the links; maybe I shuld do it sober hue.
Coy Sanders
@coymeetsworld
May 09 2016 03:51
you will, you'll have more experience when you get there
acgillette
@acgillette
May 09 2016 03:51
the number of arguments is going to be variable so your code needs to reflect that
Coy Sanders
@coymeetsworld
May 09 2016 03:51
that would not be a bad idea @dukenukethem
tekac
@tekac
May 09 2016 03:51

function findLongestWord(str) {
  var newArr = str.split();
  for (i = 0; i > newArr.length; i++) {
    return newArr[i].length;
  }
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Am i doing this wrong? Return the length of longest word in string
Travis
@dukenukethem
May 09 2016 03:51
i = 0 so it will never be greater than newArr.length;
Justin Woodward
@jwoo92
May 09 2016 03:52
@acgillette i was overlooking the arguments doc as well, but i see how it may be useful now.
acgillette
@acgillette
May 09 2016 03:52
also you need a way to compare the strings to figure out the longest one
right now you'll just return the length of the first string in the array
instead of the longest one
@jwoo92 yes you definitely need it!! especially look at how to make a new array that has the arguments
Justin Woodward
@jwoo92
May 09 2016 03:53
@acgillette .from :)
Travis
@dukenukethem
May 09 2016 03:53
oh god; that function
Coy Sanders
@coymeetsworld
May 09 2016 03:53
yep as @dukenukethem said @tekac, but also youre not returning the longest word in your code
Travis
@dukenukethem
May 09 2016 03:53
i forgot about that function.
acgillette
@acgillette
May 09 2016 03:53
and also that arguments[0] is going to be your array and not the first argument which caused me problems because I didn't realize it lol
Coy Sanders
@coymeetsworld
May 09 2016 03:54
@tekac your split function is wrong, you need to split on something
and also even if you got that right your for loop is just going to return the size of that array (i.e. the number of words). But you don't want that, you want the size of the largest word among the words
tekac
@tekac
May 09 2016 03:55
Thanks @coymeetsworld @-
CamperBot
@camperbot
May 09 2016 03:55
tekac sends brownie points to @coymeetsworld and @- :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for -
:cookie: 772 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Justin Woodward
@jwoo92
May 09 2016 03:56
would this be correct?
var args = arr.from(arguments);
tekac
@tekac
May 09 2016 03:56
Proper thanks to @acgillette and @dukenukethem as well
CamperBot
@camperbot
May 09 2016 03:56
tekac sends brownie points to @acgillette and @dukenukethem :sparkles: :thumbsup: :sparkles:
:cookie: 273 | @dukenukethem |http://www.freecodecamp.com/dukenukethem
:cookie: 274 | @acgillette |http://www.freecodecamp.com/acgillette
acgillette
@acgillette
May 09 2016 03:57
yeah! @jwoo92 , but you also need to remove the first element from it
because args[0] is going to be your array
Justin Woodward
@jwoo92
May 09 2016 03:58
@acgillette i better revisit .split() real quick then.
acgillette
@acgillette
May 09 2016 03:59
@coymeetsworld pointed me to shift() which would be easier I think @jwoo92
Coy Sanders
@coymeetsworld
May 09 2016 04:02
yeah shift best option, it will remove the first element in the array
Justin Woodward
@jwoo92
May 09 2016 04:02
@acgillette youre right, that makes sense. i forgot about shift. this is what i have so far.

function destroyer(arr) {
 var args = arr.from(arguments);
  args = args.shift();
acgillette
@acgillette
May 09 2016 04:03
you don't need args = @jwoo92
in fact I think that would actually make args the array anyways if I'm not mistaken
Coy Sanders
@coymeetsworld
May 09 2016 04:03
yeah not don't need, don't do :)
args.shift() returns the item youre removing from the array
Carlos Antonio
@fulvi0
May 09 2016 04:04
Hi, need a help here, why when i’m returing the variable tester i got the last value(index2) from my array.?
function titleCase(str) {
  str = str.split(' ');
  console.log(str);
  for(var i = 0; i < str.length; i++){
    var tester = str[i].charAt(0).toUpperCase() + str[i].toLowerCase().slice(1);
  }
  return tester;
}
console.log(titleCase("sHoRt AnD sToUt"));

console output:
["sHoRt", "AnD", "sToUt"]
"Stout"
acgillette
@acgillette
May 09 2016 04:04
because shift returns the first array which you're setting args too
first element of the array* rather
Coy Sanders
@coymeetsworld
May 09 2016 04:04
@fulvi0 thats because you keep overwriting tester each iteration of the loop
you want to concatenate the results together and return that
first iteration you have tester=Short, 2nd tester=And, 3rd tester=Stout, then you return tester which is just Stout
Carlos Antonio
@fulvi0
May 09 2016 04:07
@coymeetsworld mmmm ok, so i should figure out how to return the full array in a single line.
acgillette
@acgillette
May 09 2016 04:07
also remember you'll want to return it as a joined string @fulvi0
Justin Woodward
@jwoo92
May 09 2016 04:07
@acgillette that makes sense.
acgillette
@acgillette
May 09 2016 04:07
rather than just returning the array of separated words
Carlos Antonio
@fulvi0
May 09 2016 04:08
@acgillette with .join()
Coy Sanders
@coymeetsworld
May 09 2016 04:08
you need to find a way to put the results of each for loop together @fulvi0
acgillette
@acgillette
May 09 2016 04:08
Yes @fulvi0
Justin Woodward
@jwoo92
May 09 2016 04:08
im trying to figure out how .filter() plays into this.
Carlos Antonio
@fulvi0
May 09 2016 04:08
thanks @coymeetsworld && @acgillette
CamperBot
@camperbot
May 09 2016 04:08
fulvi0 sends brownie points to @coymeetsworld and @acgillette :sparkles: :thumbsup: :sparkles:
:cookie: 275 | @acgillette |http://www.freecodecamp.com/acgillette
:cookie: 773 | @coymeetsworld |http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
May 09 2016 04:08
either through concatenation, or pushing the results into an array
acgillette
@acgillette
May 09 2016 04:08
so filter allows you to iterate through an array
Carlos Antonio
@fulvi0
May 09 2016 04:08
sure
Coy Sanders
@coymeetsworld
May 09 2016 04:08
the as @acgillette if you use that array convert it into a string w/ the join method, either way
acgillette
@acgillette
May 09 2016 04:08
and filter out values which come out as "false" through the function you build
@jwoo92 then you can return a filtered array which will remove the elements you don't want from arr
I'm not sure I explained it well, but think of it was a way to both iterate and remove elements in an array
or rather to go through an array, not sure if iterate is the right word
it simplifies your code. I'm sure theres a solution to the problem you could do without it but I don't see how without making some messy code
Justin Woodward
@jwoo92
May 09 2016 04:13
@acgillette it makes sense, im trying to think on how i should build the function for .filter()
acgillette
@acgillette
May 09 2016 04:13
well think about what you want to do with the function
@jwoo92 I find it useful to draw a flow chart on paper to sort out my logic
if you get the logic part down then it's just a matter of syntax :)
thats how I like to approach it anyways
think about what conditions you want to return true or false
I hope I'm being useful and not confusing I'm not a code expert by any means and just finished this problem, but it's also pretty fresh in my mind lol
Justin Woodward
@jwoo92
May 09 2016 04:20
@acgillette did you use a for loop at all to use with the arguments created array?
acgillette
@acgillette
May 09 2016 04:20
yes :)
Justin Woodward
@jwoo92
May 09 2016 04:21
this is what i have. im not sure if i am on the right path or not.

function destroyer(arr) {

  var args = arr.from(arguments);
  args.shift();

  function checkVal(val) {
    for(var i = 0; i < args.length; i++) {
    return val != args[i];    
    }
  }
  var result = arr.filter(checkVal);
  return result; 
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
acgillette
@acgillette
May 09 2016 04:21
getting closer!
but if you put return in the for loop you won't go through all the arguments
because you'll always exit the first time it goes through
Justin Woodward
@jwoo92
May 09 2016 04:22
i didnt realize i did that
acgillette
@acgillette
May 09 2016 04:22
so it'll only return val != args[0]
the way to solve it is pretty simple
Justin Woodward
@jwoo92
May 09 2016 04:24
hmm, i must be over thinking right now.
acgillette
@acgillette
May 09 2016 04:25
haha yeah I did that when I first started the algorithms, but the solution is usually simpler than you think
filter() filters out values that return false. Think about in what situation you'd want it to return false @jwoo92
and what the logic of that would be
this is why I like writing out the logic first, because usually the solution presents itself a lot more easily when I write it down
Justin Woodward
@jwoo92
May 09 2016 04:29

function destroyer(arr) {

  var args = arr.from(arguments);
  args.shift();

  function checkVal(val) {
    for(var i = 0; i < args.length; i++) {
    var x = args[i];
      if (x) {
        return false;
      } else {
        return val;
      }
    }
  }
  var result = arr.filter(checkVal);
  return result; 
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
acgillette
@acgillette
May 09 2016 04:29
still have the issue of the loop exiting too early
because of the else
also you want it to return true not val
filter only uses true or false @jwoo92
not sure why you even need the x, I just compared val to args[i]
bitgrower
@bitgrower
May 09 2016 04:32
let me try putting it another way for you @jwoo92 ... the only way out of your loop is to exit your checklist function ... you have no way of iterating thru all of the values in args ... because the VERY first time thru your for loop -- you exit via a return which RETURNS from the function ..
acgillette
@acgillette
May 09 2016 04:32
also can get rid of var result line, you can just return arr.filter on the return line. But that's an aesthetic thing
Carlos Antonio
@fulvi0
May 09 2016 04:33
if (x) {
        return false;
      } else {
        return val;
      }
@jwoo92 that part isn’t clear, what you want to get from here?
acgillette
@acgillette
May 09 2016 04:33
you want to return false if the value you're passing is equal to the argument you're comparing it too
Carlos Antonio
@fulvi0
May 09 2016 04:34
so missing some comparison, right?
acgillette
@acgillette
May 09 2016 04:34
yeah exactly. But you;re really close @jwoo92 !
bitgrower
@bitgrower
May 09 2016 04:35
LOL ... after giving him about 5 different things he needs to fix ...
acgillette
@acgillette
May 09 2016 04:36
what you're doing with (x) is just seeing if the value of x is truthy
bitgrower
@bitgrower
May 09 2016 04:36
which, since it's a number in the array, it will be !
acgillette
@acgillette
May 09 2016 04:36
so it's not the correct comparison you want to make
EricOber
@EricOber
May 09 2016 04:37
can someone help me check my code? Im getting an error message saying "total is undefined". dont know what to do ```js

// Example
var ourArr = [ 9, 10, 11, 12];
var ourTotal = 0;

for (var i = 0; i < ourArr.length; i++) {
  ourTotal += ourArr[i];
}

// Setup
var myArr = [ 2, 3, 4, 5, 6];

// Only change code below this line
var myTotal = 0;

for (var i = 0; i < myArr.length; i++) {
  myTotal += myArr[i];
}
acgillette
@acgillette
May 09 2016 04:37
haha it's headed in the right direction though @bitgrower, the structure is getting there
which challenge is this for? @Am3ricanPaladin
EricOber
@EricOber
May 09 2016 04:38
its is the iterate through an array with a for loop, challenge
bitgrower
@bitgrower
May 09 2016 04:38
well since I don't see "total" in the code you posted ... are we missing part of your code ?
EricOber
@EricOber
May 09 2016 04:39
@bitgrower @acgillette well i dont know, because theres an example right above my code
bitgrower
@bitgrower
May 09 2016 04:39
include it please ...
acgillette
@acgillette
May 09 2016 04:39
yeah you misnamed the variable
it should be total not myTotal
which is what the challenge calls for @Am3ricanPaladin
EricOber
@EricOber
May 09 2016 04:40
the example is in the top portion @bitgrower
revised code doesnt work @acgillette
acgillette
@acgillette
May 09 2016 04:40
post it?
EricOber
@EricOber
May 09 2016 04:40

// Example
var ourArr = [ 9, 10, 11, 12];
var ourTotal = 0;

for (var i = 0; i < ourArr.length; i++) {
  ourTotal += ourArr[i];
}

// Setup
var myArr = [ 2, 3, 4, 5, 6];

// Only change code below this line
var Total = 0;

for (var i = 0; i < myArr.length; i++) {
  Total += myArr[i];
}
Angelo Ryndon
@AIRyndon
May 09 2016 04:40
Javascript quirkyness on where to put a number in an array is weird...
acgillette
@acgillette
May 09 2016 04:40
lowercase it
@Am3ricanPaladin
to total, not Total
Angelo Ryndon
@AIRyndon
May 09 2016 04:40
anyone here finished Where do I belong challenge? I'm about to finish work
acgillette
@acgillette
May 09 2016 04:40
ahhhh I haven't even started on that one lol
Carlos Antonio
@fulvi0
May 09 2016 04:40
console.log(myTotal); but the output of that is 20
EricOber
@EricOber
May 09 2016 04:41
oooOOOoooo dang! @acgillette you got it. thank you
CamperBot
@camperbot
May 09 2016 04:41
am3ricanpaladin sends brownie points to @acgillette :sparkles: :thumbsup: :sparkles:
:cookie: 276 | @acgillette |http://www.freecodecamp.com/acgillette
bitgrower
@bitgrower
May 09 2016 04:41
you have an example, @AlRyndon ?
EricOber
@EricOber
May 09 2016 04:41
@bitgrower thank you as well
CamperBot
@camperbot
May 09 2016 04:41
am3ricanpaladin sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star2: 1036 | @bitgrower |http://www.freecodecamp.com/bitgrower
acgillette
@acgillette
May 09 2016 04:41
np :)
bitgrower
@bitgrower
May 09 2016 04:41
yw, @Am3ricanPaladin -- keep up the good work !
Carlos Antonio
@fulvi0
May 09 2016 04:42
:+1:
bitgrower
@bitgrower
May 09 2016 04:42
@AIRyndon -- post your code, please ?
Mahade Walid
@walidmahade
May 09 2016 04:42
thanks @/all
EricOber
@EricOber
May 09 2016 04:43
chuggin along, im trying to finish the whole curriculum and non profit work by december, i hope. i wonder how many people have completed all the lessons and non profit work so far?
Justin Woodward
@jwoo92
May 09 2016 04:43
@acgillette @fulvi0 i originally tried a comparison but the system told me it was not a correct format
acgillette
@acgillette
May 09 2016 04:44
very few, apparently because most people who get far enough into it find jobs before they finish
post the comparison you tried
@jwoo92
EricOber
@EricOber
May 09 2016 04:44
lol i heard that @acgillette
i wonder how far through it they get?
acgillette
@acgillette
May 09 2016 04:44
I'm doing it to apply to a coding program so I don't necessarily want to finish it, but I'm certainly going to see how far I can get :)
bitgrower
@bitgrower
May 09 2016 04:44
probably enough to show off some web projects ... :)
Justin Woodward
@jwoo92
May 09 2016 04:45

function destroyer(arr) {

  var args = arr.from(arguments);
  args.shift();

  function checkVal(val) {
    for(var i = 0; i < args.length; i++) {
    return val !=args[i];   
  }

  var result = arr.filter(checkVal);
  return result; 
}
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
acgillette
@acgillette
May 09 2016 04:45
ok so
EricOber
@EricOber
May 09 2016 04:45
coding program? like one of these bootcamps?
Carlos Antonio
@fulvi0
May 09 2016 04:45
@Am3ricanPaladin you should read this, More than 15,000 people responded to the 2016 New Coder Survey. Find out who they are and how they're learning to code (5 minute read): http://bit.ly/1NYpcD8
acgillette
@acgillette
May 09 2016 04:45
the problem with that comparison is more the fact that you;re exiting the loop too earlkuy
Justin Woodward
@jwoo92
May 09 2016 04:45
it is giving me a type error: arr.from is not a function.
acgillette
@acgillette
May 09 2016 04:45
early*
EricOber
@EricOber
May 09 2016 04:45
thanks @fulvi0
CamperBot
@camperbot
May 09 2016 04:45
am3ricanpaladin sends brownie points to @fulvi0 :sparkles: :thumbsup: :sparkles:
:cookie: 267 | @fulvi0 |http://www.freecodecamp.com/fulvi0
acgillette
@acgillette
May 09 2016 04:45
it's Array.from not arr.from
Justin Woodward
@jwoo92
May 09 2016 04:46
how so?
acgillette
@acgillette
May 09 2016 04:46
think of it this way: you're making a new array from the arguments
Justin Woodward
@jwoo92
May 09 2016 04:46
wouldnt it be arr.from since im pulling from my arr array?
acgillette
@acgillette
May 09 2016 04:46
you're not though
you're pulling it from arguments which is seperate
arr is an array passed to the function that comes from arguments[0]
([1, 2, 3, 1, 2, 3], 2, 3); < this line is the arguments
[1, 2, 3, 1, 2, 3] < is arr
Angelo Ryndon
@AIRyndon
May 09 2016 04:48
@bitgrower chat is lagging bro..I finished it :)
alpox
@alpox
May 09 2016 04:49

@jwoo92

for(var i = 0; i < args.length; i++) {
    return val !=args[i];   
}

you are returning here inside the for loop what makes the for loop break at the first iteration AND leaves the function immediately, so nothing after it will be executed.

acgillette
@acgillette
May 09 2016 04:49
that too @jwoo92
think of it this way
Angelo Ryndon
@AIRyndon
May 09 2016 04:49
here's the code..I kind of cheated..because Javascript's way of checking where to put stuff is weird and quirky :)

function getIndexToIns(arr, num) {
  // Find my place in this sorted array.
  var index = 0;
  function comparer(a,b)
  {
     return(a < b)? -1:(a > b)?1:0;  
  }

  arr.push(num);
  var sortedArr = arr.sort(comparer);

  for(var i = 0; i < sortedArr.length ; i++)
    {
      if(sortedArr[i] == num)
       {
        index = i;
        break;
       }       
    } 
  return index;
}

getIndexToIns([2,10],19);
acgillette
@acgillette
May 09 2016 04:49
you only want to exist the for loop if you're returning false
exit*
codecamprepo
@codecamprepo
May 09 2016 04:50
Hello people
alpox
@alpox
May 09 2016 04:51
@AIRyndon Umm... there is arr.indexOf(num)
codecamprepo
@codecamprepo
May 09 2016 04:51
can someone tell me if there is a better way to look for particular solution in this chat.. I am stuck on Record Collection challenge for some time now
acgillette
@acgillette
May 09 2016 04:51
what are you stuck on in the record collection @codecamprepo ?
alpox
@alpox
May 09 2016 04:51
@codecamprepo You can also just show your code and/or ask your question
Angelo Ryndon
@AIRyndon
May 09 2016 04:52
@alpox...yeah I always forget those methods..hate no intellisense!
hahaha
alpox
@alpox
May 09 2016 04:52
@AIRyndon MDN helps ;-)
codecamprepo
@codecamprepo
May 09 2016 04:52
This is the current logic I am trying

function updateRecords(id, prop, value) {

if (value === ""){
delete collection.id.prop;

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

return collection;
}

Angelo Ryndon
@AIRyndon
May 09 2016 04:52
One of the few reasons I love C# and VS hahaha..too lazy to read docs
alpox
@alpox
May 09 2016 04:52

@AIRyndon

function comparer(a,b) {
  return a - b;
}

may be faster? :D

codecamprepo
@codecamprepo
May 09 2016 04:52
not sure if I am wrong with syntax or logic is incorrect
alpox
@alpox
May 09 2016 04:53
@AIRyndon Yeah C# is great ^^
Angelo Ryndon
@AIRyndon
May 09 2016 04:53
@alpox does that work? lol didn't know I can write it that way
acgillette
@acgillette
May 09 2016 04:53
you're missing some comparisons @codecamprepo
rphares
@rphares
May 09 2016 04:53
to start, try using bracket notation, @codecamprepo , not dot
Angelo Ryndon
@AIRyndon
May 09 2016 04:53
@alpox thanks for the info bro
CamperBot
@camperbot
May 09 2016 04:53
airyndon sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:cookie: 648 | @alpox |http://www.freecodecamp.com/alpox
alpox
@alpox
May 09 2016 04:53
@AIRyndon I got used to looking up methods on the web because of javascript, golang etc
@AIRyndon That works ^^ You're welcome
Justin Woodward
@jwoo92
May 09 2016 04:53
looking better? if my .from is incorrect, i do not get how to pull the arguments from destroyer.

function destroyer(arr) {

  var args = arr.from(arguments);
  args.shift();

  function checkVal(val) {
    for(var i = 0; i < args.length; i++) {
    if (val !=args[i]) {
      return true;
    }  else {
      return false;
    }
  }

  var result = arr.filter(checkVal);
  return result; 
}
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
acgillette
@acgillette
May 09 2016 04:53
If value is non-blank (value !== "") AND prop is not "tracks"
rphares
@rphares
May 09 2016 04:53
not good at explaining this link helped me... https://medium.com/@prufrock123/js-dot-notation-vs-bracket-notation-797c4e34f01d#.viyno6t50 @codecamprepo
acgillette
@acgillette
May 09 2016 04:54
change var args = arr.from(arguments); to var args = Array.from(arguments);
your code is not going to work unless you do that @jwoo92
alpox
@alpox
May 09 2016 04:54
@jwoo92 You still return inside of the for loop.
acgillette
@acgillette
May 09 2016 04:54
then again, your loop is still exiting too early
alpox
@alpox
May 09 2016 04:54
@jwoo92 And break the loop through that.
acgillette
@acgillette
May 09 2016 04:55
in my solution I had one return in the loop and one outside the loop
alpox
@alpox
May 09 2016 04:55
@acgillette That is usually the right solution
rphares
@rphares
May 09 2016 04:55
for the conditions, @acgillette is correct. most take their conditions directly from the instructions, @codecamprepo , in that logical order... :blush:
alpox
@alpox
May 09 2016 04:55
Or just use indexOf :-)
rphares
@rphares
May 09 2016 04:56
(a few other lil things, too, but that should be enough to work on for a bit!)
Angelo Ryndon
@AIRyndon
May 09 2016 04:56
This Caesar Salad Challenge looks interesting..i'll get into it at home..
acgillette
@acgillette
May 09 2016 04:56
think about in what situation you'd want to break the loop and return a value
alpox
@alpox
May 09 2016 04:57
Have a good meal @AIRyndon :D
acgillette
@acgillette
May 09 2016 04:57
and in what situation you'd want to go entirely through the loop and return the other value
Justin Woodward
@jwoo92
May 09 2016 04:57

function destroyer(arr) {

  var args = Array.from(arguments);
  args.shift();

  function checkVal(val) {
    for(var i = 0; i < args.length; i++) {
    if (val !=args[i]) {
      val = true;
    }  else {
      val = false;
    } return val;
  }

  return arr.filter(checkVal);

}
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
acgillette
@acgillette
May 09 2016 04:57
val is going to keep changing as it iterates through
so when you put in two
alpox
@alpox
May 09 2016 04:58
@jwoo92 You still return in every case inside the loop :-)
Kyle Morton
@kmorton1988
May 09 2016 04:58
help diff two arrays
CamperBot
@camperbot
May 09 2016 04:58

:point_right: algorithm diff two arrays [wiki]

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

:checkered_flag: Problem Explanation:

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

Relevant Links

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

acgillette
@acgillette
May 09 2016 04:58
that's true also
here look
when it gets to for example the 2 in the arrat
array
Justin Woodward
@jwoo92
May 09 2016 04:58
i cant think of how to properly get my val compared to the argument
acgillette
@acgillette
May 09 2016 04:59
it will compare 2 to the first argument which is 2
so val will be set to false
but then it will compare it to the second argument which is 3
Justin Woodward
@jwoo92
May 09 2016 04:59
with use of the for loop with the arguments
acgillette
@acgillette
May 09 2016 04:59
and will set val to true
and then you return val true when you want it to be false so it can be filtered
also yeah the return is still in the loop, you want it out entirely
you have it close you just have it backwards
the way I saw it was
you want to break the loop and exist if the return is false. this is because once it hits false you don't need to compare it to any other arguments
and then if it never hits false just return true
alpox
@alpox
May 09 2016 05:01
@jwoo92 You have to do the following steps:
  1. Iterate through the array (done)
  2. return falsy inside the loop if you found one value which equals
  3. return truthy outside the loop for every other case (Can only be returned after all values are checked)
acgillette
@acgillette
May 09 2016 05:02
my function ended up only being four lines
alpox
@alpox
May 09 2016 05:02
I think mine was even one
Or two. With picking the right methods
Kazi Ahmed
@kaziahmed91
May 09 2016 05:03

Hello coders, i need help with a JS algorithm exercise which asks to : "Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a two-dimensional array."

What i have so far:
function chunkArrayInGroups(arr, size) {
var array = [ ];

for (var i = 0; i<size;i++){
array.push(arr.slice(0,size));
}
return array;
}

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

dontchaknow
@dontchaknow
May 09 2016 05:03
anyone having issues with rounding to the nearest hundredth? It's messing up my solution. not sure how to deal with it.
alpox
@alpox
May 09 2016 05:03
filter and indexOf can do almost the whole job
acgillette
@acgillette
May 09 2016 05:04
look at the logic in your for loop
@kaziahmed91
alpox
@alpox
May 09 2016 05:04
@kaziahmed91 especially on the parameters of your slice call
Kazi Ahmed
@kaziahmed91
May 09 2016 05:04
okey..
dontchaknow
@dontchaknow
May 09 2016 05:04
nvm found it
Kazi Ahmed
@kaziahmed91
May 09 2016 05:05
so how do i change it so that once it loops over the first part of the breaks, it jumps to the second div for the loop?
break*
acgillette
@acgillette
May 09 2016 05:05
right now you're incrementing i by one
Kazi Ahmed
@kaziahmed91
May 09 2016 05:05
ohh i see..
acgillette
@acgillette
May 09 2016 05:06
so think about what you;d want to increment it by instead
Martialis39
@Martialis39
May 09 2016 05:06
Can anyone give me a few pointers on Where Are Thou? I have some of the cases correct
but largely I have no idea what Im doing :D
function whereAreYou(collection, source) {
  // What's in a name?
  // this has proven tough. I don't really get Objects. I had the fear of Object Oriented Programming put into me years ago
  // and it still rules over my life. 
  // this solution should work for the cases where argument 2 is one key/value pair. 
  var key = Object.keys(source); // this gets the key of argument2.
  var val = source[key]; //this gets the value of argument//
  var arr = collection.filter(function(element){
    if(element.hasOwnProperty(key)){ //here I check for the key
      if(element[key] === val){ // and if I find one, I check for the value
      return element; // if they line up, that element passes the test and gets returned.
      }
    }
  });
  console.log(arr);

  return arr;
}

whereAreYou([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
acgillette
@acgillette
May 09 2016 05:07
and when you set the second parameter on slice you're slicing at wherever size it, when you want the value of i plus size
Martialis39
@Martialis39
May 09 2016 05:07
this passes the first two cases :)
Justin Woodward
@jwoo92
May 09 2016 05:07
i know this is wrong current due to system error, but am i on the right track?

function destroyer(arr) {

  var args = Array.from(arguments);
  args.shift();

  function checkVal(val) {
    for(var i = 0; i < args.length; i++) {
   if (val = args[i]) {
     return false;
   }
    } return val;
  }

  return arr.filter(checkVal);


}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
codecamprepo
@codecamprepo
May 09 2016 05:07
@rphares how do I access id using bracket notations ? since I cant assign it to variable
alpox
@alpox
May 09 2016 05:08
@jwoo92 val = args[i] This is an assignment. You compare with == or === for strict comparison
Martialis39
@Martialis39
May 09 2016 05:08
@jwoo92 seems to me
acgillette
@acgillette
May 09 2016 05:08
also you want to return true not val
filter only takes true or false
Justin Woodward
@jwoo92
May 09 2016 05:08
@alpox cant believe i didnt see that lol
alpox
@alpox
May 09 2016 05:08
This message was deleted
Martialis39
@Martialis39
May 09 2016 05:09
you are not passing anything to checkVal
acgillette
@acgillette
May 09 2016 05:09
@jwoo92 I think if you fix those two things it should work!
Justin Woodward
@jwoo92
May 09 2016 05:09
@acgillette @alpox thanks guys i finally got it
CamperBot
@camperbot
May 09 2016 05:09
jwoo92 sends brownie points to @acgillette and @alpox :sparkles: :thumbsup: :sparkles:
:cookie: 649 | @alpox |http://www.freecodecamp.com/alpox
:cookie: 277 | @acgillette |http://www.freecodecamp.com/acgillette
acgillette
@acgillette
May 09 2016 05:09
:) yaaaayyyy gj!
alpox
@alpox
May 09 2016 05:10
@jwoo92 Gratulations! :D just hope you never get a zero element in the arguments list :D
Justin Woodward
@jwoo92
May 09 2016 05:10
my final code:

function destroyer(arr) {

  var args = Array.from(arguments);
  args.shift();

  function checkVal(val) {
    for(var i = 0; i < args.length; i++) {
   if (val == args[i]) {
     return false;
   }
    } return true;
  }

  return arr.filter(checkVal);


}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
acgillette
@acgillette
May 09 2016 05:10
helping you helped me understand the challenge a lot better haha
alpox
@alpox
May 09 2016 05:10
Ah okay looks good now
Justin Woodward
@jwoo92
May 09 2016 05:13
thanks again im going to bed now, i have to be up in 5 hours. ill be back on tomorrow evening.
dontchaknow
@dontchaknow
May 09 2016 05:15
function checkCashRegister(price, cash, cid) {
  var change = cash - price;
  var startingCID = 0;

  for(var k = 0; k < cid.length; k++){
    startingCID += cid[k][1];
  }

    if (change === startingCID){
    return "Closed";
  }

  var currencyDenominations = [0.01, 0.05, 0.1, 0.25, 1, 5, 10, 20, 100];
  var currencyDenomStr = ["PENNY", "NICKEL", "DIME", "QUARTER", "ONE", "FIVE", "TEN", "TWENTY", "ONE HUNDRED"];
  var exactChange = [];

  var startingCashRegister = Array.from(cid); 
  for (var i = startingCashRegister.length - 1; i >= 0; i--){
    if (change >= startingCashRegister[i][1]){
      change -= startingCashRegister[i][1];
      exactChange.push(startingCashRegister[i]);
    }
    else{
      var qty = Math.floor(change / currencyDenominations[i]);
      var toSubtract = qty * currencyDenominations[i];
      change -= toSubtract;
      exactChange.push([currencyDenomStr[i], toSubtract]);
    }
  }

  if(change > 0){
    return "Insufficient Funds";
  }

  return exactChange.filter(function(num){if(num[1] !== 0){return num;}});

}
i can't pass because of rounding
rounding by a penny lol
Markus Kiili
@Masd925
May 09 2016 05:16
@dontchaknow You can use pennies so you stay in safe integers or use some margin of error on comparisons like delta=0.000001.
dontchaknow
@dontchaknow
May 09 2016 05:18
the problem is I'm not sure where the rounding fell off by a penny.
Marc Schöni
@marcschoeni
May 09 2016 05:22
tanks @boris-in-london Thanks a lot
CamperBot
@camperbot
May 09 2016 05:22
marcschoeni sends brownie points to @boris-in-london :sparkles: :thumbsup: :sparkles:
:cookie: 333 | @boris-in-london |http://www.freecodecamp.com/boris-in-london
Josh Nelsson-Smith
@Svensk-Xavier
May 09 2016 05:26
Howdy all, Im just attempting the validate US telephone numbers challenge, but as Im not from the US, I'm struggling to identify some of the rules. I dont want to google too hard as it may reveal the regex and I dont want to cheat :smile:
For instance, why is this not a valid number? 1 456 789 4444
Whoops, my mistake, got that backwards :worried:
Martialis39
@Martialis39
May 09 2016 05:32
@Svensk-Xavier did you get it ?
Why isnt that a valid number?
The tests show something similar as true
Travis
@dukenukethem
May 09 2016 05:40
in @jwoo92 's code I don't understand var args = Array.from(arguments); specifically Array.from(arguments);
could anyone give me something to read to help me better understand?
nvm google is my friend.
Markus Kiili
@Masd925
May 09 2016 05:51
@dukenukethem It does the same as Array.prototype.slice.call(arguments). It turns array-like object arguments into an array.
@dukenukethem Array.from is ES6 syntax, so browser support is poor.
Josh Nelsson-Smith
@Svensk-Xavier
May 09 2016 05:52
@Martialis39 Yeah I realised I copied the wrong number, but I just solved it then. Always the case, the moment you ask, you figure it out XD
Dan Couper
@DanCouper
May 09 2016 05:52
@jwoo92 you can get rid of the var args and the args.shift() by adding an extra argument to the function - i.e. function destroyer(arr, ...args). Then args is an actual array of 0+ length containing only the things you need, no need to use shift()
Travis
@dukenukethem
May 09 2016 05:55
hes offline @DanCouper
Ade
@hello-ade
May 09 2016 06:02

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


  // Your code above this line
  return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly", "cat", "little", "hit", "slowly");
Hello friends, can anybody help me with this code. I am not quite sure what should i do with this code.
Samuel Cupidon
@Zerazera
May 09 2016 06:05
@hello-ade What are you trying to do? What have you tried, and how is it going wrong?
Ade
@hello-ade
May 09 2016 06:16
@Zerazera I am trying to build a Mad Libs word game but i don't know where to start, can you give me a pointer where to start
cannelflow
@cannelflow
May 09 2016 06:26
@hello-ade myNoun, myAdjective, myVerb, myAdverb are variable so remove "" from them
@hello-ade and give spacing like A +" "+ B so that there should be spacing between value of A & B
and at bottem it is like wordBlanks("dog", "big", "ran", "quickly");
wordBlanks("cat","little","hit","slowly"); on original challange
dheerajahuja000
@dheerajahuja000
May 09 2016 06:30
i am retreiving folder and files from HDFS using jquery....and i want to add a folder image to folder and file image to the files
how can i do that? how to differentiate between directory and files?
dheerajahuja000
@dheerajahuja000
May 09 2016 06:33
@cannelflow i think u misunderstood a bit... i am able to get all files and folder as a text but i want to add image to that
folder image to directory and file image to files
Marc Schöni
@marcschoeni
May 09 2016 06:33
anyone an idea why the new quote button not go? http://codepen.io/mschoeni/pen/YqJwqJ
Ade
@hello-ade
May 09 2016 06:33
@cannelflow Thanks very much, it's worked
CamperBot
@camperbot
May 09 2016 06:33
hello-ade sends brownie points to @cannelflow :sparkles: :thumbsup: :sparkles:
:star2: 1137 | @cannelflow |http://www.freecodecamp.com/cannelflow
kirbyedy
@kirbyedy
May 09 2016 06:36
@marcschoeni I dont see you calling the quote function on button click
Marc Schöni
@marcschoeni
May 09 2016 06:38
@kirbyedy when i do its fail xD i think i learn that i will never be a json master^^ thanks @kirbyedy
CamperBot
@camperbot
May 09 2016 06:38
marcschoeni sends brownie points to @kirbyedy :sparkles: :thumbsup: :sparkles:
:cookie: 971 | @kirbyedy |http://www.freecodecamp.com/kirbyedy
Robert Richey
@0x0936
May 09 2016 06:49
@marcschoeni consider giving your New Quote button an id, to make it easier to select. Then add a click event and call getQuote() within the click event's callback.
daniel akerley
@darkSkiesUniverse
May 09 2016 07:03

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

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


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

// Change this value to test
phoneticLookup("charlie");
var lookup is not being used but can't seem to think of how I'm supposed to use it so object can search it and return result.
Coryphaeus
@cvdeby
May 09 2016 07:04
$("#test").on('test.test', function () {
  alert('test passed');
});
$("#test").trigger('test.test');

This method works properly, I was set an event's listener and then fired the event. But how can I trigger before listener was set like this

$("#test").trigger('test.test');
$("#test").on('test.test', function () {
  alert('test didn\'t passed');
});

I found just one way to make it - timeout/interval/animation, but it is not right way I think, because if client browser will work very slowly - it'll crash(but actually it happens pretty infrequently). So here is an example

setTimout( function () {
  $("#test").trigger('test.test');
}, 1000);
$("#test").on('test.test', function () {
  alert('test passed');
});

This method works properly and I didn't found any problems with him, but It is not right method. Does somebody know which method will work properly and logically?

rphares
@rphares
May 09 2016 07:05
hiya, @darkSkiesUniverse ! this one is pretty common,
lets check out the example!
their table is called var alpha and they want to get what is associated with 2 , so they write alpha[2]
your table is called var lookup and you want to get what is associated with val, so you could write...? @darkSkiesUniverse
then.... that would be how to get the associated string, but not to return it...
you would need to store that in what you will return. Since you are going to return result (it is below the 'do not change' line), you will probably want to set result to object[key] like in the above example, @darkSkiesUniverse :blush:
daniel akerley
@darkSkiesUniverse
May 09 2016 07:08
ah i see, thank you rphares!
rphares
@rphares
May 09 2016 07:08
anytime! Happy coding~
96street
@96street
May 09 2016 07:10
How come my 'blur' function isn't working?
Chandi
@jkchandra
May 09 2016 07:15
Hi, is it possible to check for NaN as NaN itself?
Markus Kiili
@Masd925
May 09 2016 07:17
@jkchandra val!==val tests for NaN.
Chandi
@jkchandra
May 09 2016 07:17

'''

function bouncer(arr) {
function falseFilter (val) {
if (val === "" || val === false || val === null || val === 0 || val === undefined || val === NaN) {
return false;
}
return true;
}
var newArray = arr.filter(falseFilter);

return newArray;
}

bouncer([7, "ate", "", false, 9, NaN]);

'''

CamperBot
@camperbot
May 09 2016 07:17
:bulb: to format code use backticks! ``` more info
Chandi
@jkchandra
May 09 2016 07:17

function bouncer(arr) {
  function falseFilter (val) {
    if (val === "" || val === false || val === null || val === 0 || val === undefined || val === NaN) {
      return false;
    }
    return true;
  }
  var newArray = arr.filter(falseFilter);

  return newArray;
}

bouncer([7, "ate", "", false, 9, NaN]);
my bad
@Masd925 hi markus, but if u want to check if its literally NaN?
Mateusz Szymański
@matszym
May 09 2016 07:19
@jkchandra
function isNaN(val){
return val !== val;
}
Markus Kiili
@Masd925
May 09 2016 07:19
@jkchandra NaN is special value because NaN===NaN is false. To test if val is NaN you can use val!==valor typeof val === "number" && isNaN(val)
Chandi
@jkchandra
May 09 2016 07:21
OHHH so to test we must check if the value is not equal to itself. if its not means its NaN? i see isee . thanks alot for your help! @Masd925 @matszym
CamperBot
@camperbot
May 09 2016 07:21
jkchandra sends brownie points to @masd925 and @matszym :sparkles: :thumbsup: :sparkles:
:cookie: 60 | @matszym |http://www.freecodecamp.com/matszym
:star2: 1442 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
May 09 2016 07:22
@jkchandra Yes. val===NaN is false for any value of val. Therefore you must have a special test for variable being NaN.
Coryphaeus
@cvdeby
May 09 2016 07:23
When you're requesting help, your issue is becoming clear even without the help)
impossiblesingh
@impossiblesingh
May 09 2016 07:25
blob
rphares
@rphares
May 09 2016 07:26
hiya, @impossiblesingh -- undefined is a special value
"undefined" is just a string ;)
Anurag Lahon
@anuraglahon16
May 09 2016 07:32
hey how to build the quote machine
Ajith
@ajithvallabai
May 09 2016 07:38
could anyone help me in seek and destroy i am stuck

function destroyer(arr,a,b,c) {
  // Remove all the values
  var des=[];
  var i;
for( i=0;i<arr.length;i++)
  {
    if(arr[i]!==a || arr[i]!==b || arr[i]!==c)
      {
        des=arr[i].push();
      }
  }
  return des;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
@jkchandra simply return the arr it would pass all the test cases
Markus Kiili
@Masd925
May 09 2016 07:40
@ajithvallabai You are not supposed to add parameters to the function.
Chandi
@jkchandra
May 09 2016 07:41
@ajithvallabai yeah solved that thanks ahha. maybe you could use arguments[0],arguments1 etc instead of a,b,c
CamperBot
@camperbot
May 09 2016 07:41
jkchandra sends brownie points to @ajithvallabai :sparkles: :thumbsup: :sparkles:
:cookie: 277 | @ajithvallabai |http://www.freecodecamp.com/ajithvallabai
Ajith
@ajithvallabai
May 09 2016 07:41
but its not returning the other values if i am not adding parameters @Masd925
Markus Kiili
@Masd925
May 09 2016 07:42
@ajithvallabai You have to use the arguments object for those extra arguments. That way you can respond to any number of passed arguments.
Ajith
@ajithvallabai
May 09 2016 07:42
oh i will try it @Masd925 @jkchandra thanks
CamperBot
@camperbot
May 09 2016 07:42
ajithvallabai sends brownie points to @masd925 and @jkchandra :sparkles: :thumbsup: :sparkles:
:cookie: 264 | @jkchandra |http://www.freecodecamp.com/jkchandra
:star2: 1443 | @masd925 |http://www.freecodecamp.com/masd925
Angelo Ryndon
@AIRyndon
May 09 2016 07:57
Weee! I answered the Caesar Cipher fairly quickly..Happy :smile:

function rot13(str) 
{ // LBH QVQ VG!

  var message = "";

  for(var i = 0; i < str.length; i++)
  {
    var x = str.charAt(i).charCodeAt();

    if(x < 65 || x > 90)
      {
        message += String.fromCharCode(x);
      }
    else if(x > 77)
      {
       message += String.fromCharCode(x - 13);
      }
    else if(x <= 77)
      {
       message += String.fromCharCode(x + 13);
      }
  }

  return message;
}

// Change the inputs below to test
rot13("SERR PBQR PNZC");
Coy Sanders
@coymeetsworld
May 09 2016 08:03
nice
Ajith
@ajithvallabai
May 09 2016 08:05
@Masd925 @jkchandra i changed it but there is some mistake in it

function destroyer(arr) {
  // Remove all the values
  var des=[];
  var i;

for( i=0;i<arguments[0].length;i++)
  {
    if(arguments[0][i]!==arguments[1] || arguments[0][i]!==arguments[2] || arguments[0][i]!==arguments[3])
      {
        des=arguments[0][i].push();
      }
    return des;
  }

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Anurag Lahon
@anuraglahon16
May 09 2016 08:11
@coymeetsworld how we write js in codepen .....how we link it with css n html
Robert Richey
@0x0936
May 09 2016 08:12
if your browser supports ES6, you can modify the arr parameter` to be a REST parameter
'use strict';
function destroyer(...args) {  
  // args is an array of arguments,
  // unlike the arguments object which is only array-like
  const arr = args[0];
  const destroy = args.slice(1);
}
Ajith
@ajithvallabai
May 09 2016 08:13
thanks @0x0936
CamperBot
@camperbot
May 09 2016 08:13
ajithvallabai sends brownie points to @0x0936 :sparkles: :thumbsup: :sparkles:
:star2: 1307 | @0x0936 |http://www.freecodecamp.com/0x0936
Laura Stephenson
@lauralstephenson
May 09 2016 08:14
Okay, I give up. I've tried looking up the bug for the Local Scope and Function Test. I've tried removing both console.logs and the comments as well. What am I doing wrong>
rphares
@rphares
May 09 2016 08:15
@anuraglahon16 , in codepen every part-- html, css, and JS-- has its own section. codepen will do most of the work for you-- you write it as normal- and dont worry about putting in a <script> section, just put it in the JS section and codepen will do the rest~
@lauralstephenson , loads of people get stuck on that one-
Laura Stephenson
@lauralstephenson
May 09 2016 08:15
Oh, and I am refreshing the screen too.
rphares
@rphares
May 09 2016 08:15
could you please paste what you think it should be here? (you only need to delete one console.log if i recall...)
Laura Stephenson
@lauralstephenson
May 09 2016 08:15
Boinging head on wall.
rphares
@rphares
May 09 2016 08:16
lol, paste what you are trying and we'll talk through it :blush:
Anurag Lahon
@anuraglahon16
May 09 2016 08:16
@rphares ohh
Laura Stephenson
@lauralstephenson
May 09 2016 08:17
Here is the Waypoint code:

function myLocalScope() {
'use strict';

console.log(myVar);
}
myLocalScope();

// Run and check the console
// myVar is not defined outside of myLocalScope
console.log(myVar);

// Now remove the console log line to pass the test

Dan Couper
@DanCouper
May 09 2016 08:17
@0x0936 Note that the browser doesn't need to support it, FCC tests already do. And it you add the line /* jshint esversion:6 */ at the top of the code input, it won't show as an error. Also, pedantic, but it's rest, not REST parameters, REST has a specific meaning
Laura Stephenson
@lauralstephenson
May 09 2016 08:17
I removed the bottom one and the comment.
Then I removed the top one and the comment. Then I removed both.
rphares
@rphares
May 09 2016 08:17
okay, thats the original more or less-- you need to remove the one below the comments AND
you need a var
inside the function
you are telling it to console.log myVar,
but you haven't declared that yet...
Laura Stephenson
@lauralstephenson
May 09 2016 08:18
I tried adding console.log (myVar); but it doesn't work.
rphares
@rphares
May 09 2016 08:19
thats not what you need,
you can declare a var like this:
var example = "something"
czovzov
@czovzov
May 09 2016 08:19
hello
rphares
@rphares
May 09 2016 08:19
you need that for whatever you are trying to console.log @lauralstephenson
so, in this case... var myVar = "whatever you want"; for example,
and, because the point is for it to be local
it should be inside the function. if it is outside, it'll be global... thats not what you want :blush:
once you declare him (with var) inside the function, try refreshing and running tests again. Make sure the console.log in the comments is gone too--
the point is that if there is a console.log (or anything) using what you declare inside the function, they cant get to it. its local, only in there, so only things inside the function can get to it....
Laura Stephenson
@lauralstephenson
May 09 2016 08:22
OK, here's the code I just tried that didn't work:
Robert Richey
@0x0936
May 09 2016 08:22
@DanCouper I appreciate the correction. Made me look up the difference between REST and rest. All code runs in the browser, so the user's browser will need to support ES6 - kind of a moot point with modern browsers supporting most of ES6 now
Anurag Lahon
@anuraglahon16
May 09 2016 08:22
@rphares for(var name in collection) what is the meaning of this line
Laura Stephenson
@lauralstephenson
May 09 2016 08:22

function myLocalScope() {
'use strict';
myVar='Something';
console.log(myVar);

}
myLocalScope();

rphares
@rphares
May 09 2016 08:22
you need the var keyword @lauralstephenson
the first time you declare anything, you need var something = "whatever";
on your third line, myVar='Something'; should start with var
Laura Stephenson
@lauralstephenson
May 09 2016 08:23
Thanks @rphares ! Was banging my head there!
CamperBot
@camperbot
May 09 2016 08:23
lauralstephenson sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star2: 4405 | @rphares |http://www.freecodecamp.com/rphares
rphares
@rphares
May 09 2016 08:24
@anuraglahon16 , lease ask the room or main chat, I'm not good at explaining things, just hinting at challenges :blush:
Anytime! Happy coding, @lauralstephenson ! :blush:
Laura Stephenson
@lauralstephenson
May 09 2016 08:24
Thanks! Onto the next challenge!
Dan Couper
@DanCouper
May 09 2016 08:25
@0x0936 FCC has set up the test framework Mocha to accept ES2015 syntax for the tests, which are processed server-side, it should work regardless...
Robert Richey
@0x0936
May 09 2016 08:27
@DanCouper that's news to me! thanks :)
CamperBot
@camperbot
May 09 2016 08:27
0x0936 sends brownie points to @dancouper :sparkles: :thumbsup: :sparkles:
:cookie: 52 | @dancouper |http://www.freecodecamp.com/dancouper
Robert Richey
@0x0936
May 09 2016 08:30
and to get rid of all ES6 related warnings/errors, in addition to adding the jshint comment at the top, also needed to wrap all the code in an IIFE to have 'use strict' global to the challenge function, to avoid the warning about using a rest parameter
/* jshint esversion:6 */
(function() {
  'use strict';
  function destroyer(...args) {  
    // stuff    
  }
  destroyer([1, 2, 3, 1, 2, 3], 2, 3);
})();
Azamat
@Azamat-Altai
May 09 2016 08:32
hi guys my code seems correct but not working any idea. I am trying to find the longest word in the array
function findLongestWord(str) {
   var arr = str.split(" ");
  var longest = 0;
  for(var i=0;i<arr.length;i++){
    if(arr[i].length>longest){
      arr[i].length = longest;
    }

  }
   return longest;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
kirbyedy
@kirbyedy
May 09 2016 08:34
how about swapping this line: arr[i].length = longest;
longest = ...
Azamat
@Azamat-Altai
May 09 2016 08:35
ow i didn't think that changing places matter thanks @kirbyedy
CamperBot
@camperbot
May 09 2016 08:35
azamat-altai sends brownie points to @kirbyedy :sparkles: :thumbsup: :sparkles:
:cookie: 974 | @kirbyedy |http://www.freecodecamp.com/kirbyedy
Azamat
@Azamat-Altai
May 09 2016 08:37
in this case i assigned arr[i].length to 0 right?
Anurag Lahon
@anuraglahon16
May 09 2016 08:42
for (var key in source) what does it mean
Dan Couper
@DanCouper
May 09 2016 08:42
@Azamat-Altai longest = array[i].length. You need to assign the value you want to the variable. Currently, you’re setting the value at i in the array to 0 instead.
Ajith
@ajithvallabai
May 09 2016 08:47
is this correct method of coding but it passed all the test cases for algorithm:where do i belong

function getIndexToIns(arr, num) {
  // Find my place in this sorted array.
  var des=[];
  for(i=0;i<arguments[0].length;i++)
    {
      if(arguments[0][i]<arguments[1])
        {
          des.push(arguments[0][i]);
        }

    }

  return des.length;
}

getIndexToIns([10, 20, 30, 40, 50], 30);
Abdulkarim Eskandar
@iskandar992
May 09 2016 08:48
hi everyone

function sumAll(arr) {
  var sum = 0;
  arr = arr.sort();
  var min = arr[0];
  var max = arr[arr.length-1];
  var myArray = [];


 for(var i = min; i <= max ; i++)
   {
     myArray.push(i); 
   }
   sum = myArray.reduce(function(previousValue, currentValue, currentIndex, myArray) {
  return previousValue + currentValue;
});

  return sum;

}

sumAll([10, 5]);
its not working on all cases
on the case mentioned at the bottom [5,10] it seems not to enter the for loop at all
?
Dany Din
@danydin
May 09 2016 08:50
hey first lesson in ajva need help
Do not change code above the line
a should have a value of 7
b should have a value of 7
a should be assigned to b with =
wat to write? thanks !
Markus Kiili
@Masd925
May 09 2016 08:51
@iskandar992 Default sort is not numerical sort. You need a callback function on sort.
rphares
@rphares
May 09 2016 08:51
could you please paste what you are trying, @danydin ?
Dany Din
@danydin
May 09 2016 08:52
@rphares I don't know how to post here pic but the code they provide me is

// Setup
var a;
var b = 2;

// Only change code below this line

Instructions
Assign the value 7 to variable a.

Assign the contents of a to variable b.

rphares
@rphares
May 09 2016 08:52
so, see how they have var b = 2; up top?
that is assigning the value 2 to variable b
so, to assign the value 7 to variable a, what could you write?
@danydin
Abdulkarim Eskandar
@iskandar992
May 09 2016 08:53
@Masd925 i totally forgot about that :worried: thnx anyway :D
CamperBot
@camperbot
May 09 2016 08:53
iskandar992 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 1444 | @masd925 |http://www.freecodecamp.com/masd925
Dany Din
@danydin
May 09 2016 08:53
@rphares var a = 7;
rphares
@rphares
May 09 2016 08:54
good-- with one small change,
Dany Din
@danydin
May 09 2016 08:54
with sapces
spaces*
rphares
@rphares
May 09 2016 08:54
that will work, but you only need to use var the first time,
Robert Richey
@0x0936
May 09 2016 08:54
@iskandar992 .sort() needs a custom function to sort numbers. it's default behavior is lexical sorting. This will give you an array of numbers sorted in ascending order.
arr.sort(function(a, b) {
  return a - b;
});
rphares
@rphares
May 09 2016 08:54
so you can actually just write a = 7; below the line for that part, @danydin
for the second one,
lets say i gav