These are chat archives for FreeCodeCamp/HelpJavaScript

1st
Mar 2016
demipixel
@demipixel
Mar 01 2016 00:00
Neat trick for remembering 0 factorial:
0!==1
Ariel
@ArielLeslie
Mar 01 2016 00:00
@johnlovespi Also, that would be an infinite loop. You are counting down from zero until you are greater than 6, which would be never
John Espinoza
@johnlovespi
Mar 01 2016 00:01
right you right
Pedro Abel Díaz Sánchez
@coderHook
Mar 01 2016 00:02
@ArielLeslie that too is really powerful, thanks! I am going to check it. I will tell you if I find the way to solve it or if I finally redo everything. Thanks!
CamperBot
@camperbot
Mar 01 2016 00:02
abel1987 sends brownie points to @arielleslie :sparkles: :thumbsup: :sparkles:
:star: 1197 | @arielleslie | http://www.freecodecamp.com/arielleslie
John Espinoza
@johnlovespi
Mar 01 2016 00:02
@demipixel this is saying 0 is not equal to 1 ?
Ariel
@ArielLeslie
Mar 01 2016 00:02
@Abel1987 Good luck! Happy coding!
A-Alex-A
@A-Alex-A
Mar 01 2016 00:03
@johnlovespi you get a number, you need to multiply it by previous numbers, 5 * 4 * 3 * 2 * 1;
! is for factorial sighn
Ariel
@ArielLeslie
Mar 01 2016 00:03
@johnlovespi 0! is equal to 1
Rami
@RNwebdk
Mar 01 2016 00:04
Okay i think im confusing myself a little here, can someone explane to me why "collectiontest" would work when collectiontest2 would give me a error saying "Cannot set property 'prop' of undefined" ? I'm trying really hard to understand the difference between bracket and dot notation.
var collection = {
    1245: {
        artist: "Robert Palmer",
        tracks: []
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));
// Only change code below this line
function update(id, prop, value) {
        var collectiontest  = collection[id][prop] = value;
        var collectiontest2 = collection.id.prop = value;
        console.log(collectiontest2);
}
    update(1245, "Style", "funkey");
Caio Oliveira
@caiodesign
Mar 01 2016 00:04
This message was deleted
A-Alex-A
@A-Alex-A
Mar 01 2016 00:05
@johnlovespi say, you need to get all previous numbers up to 1 and multiply them
John Espinoza
@johnlovespi
Mar 01 2016 00:06
(num!==1) would make sence
?
A-Alex-A
@A-Alex-A
Mar 01 2016 00:06
@johnlovespi ! is math notation, here it doen't work
Ariel
@ArielLeslie
Mar 01 2016 00:07
@RNwebdk because when you are using variable names for properties, you have to use bracket notation. In JavaScript, using dot notation will always treat the properties as literal strings
Caio Oliveira
@caiodesign
Mar 01 2016 00:07
This message was deleted
Ariel
@ArielLeslie
Mar 01 2016 00:08
@RNwebdk collectiontest2 is looking for this:
var collection = {
    id:  {
        prop: "something"
    }
}
Caio Oliveira
@caiodesign
Mar 01 2016 00:08
This message was deleted
rphares
@rphares
Mar 01 2016 00:09
@caiodesign , are you testing formatting, or do you want help with converting celsius, or...? :blush:
Rami
@RNwebdk
Mar 01 2016 00:09
@ArielLeslie That makes total since, thank you
CamperBot
@camperbot
Mar 01 2016 00:09
rnwebdk sends brownie points to @arielleslie :sparkles: :thumbsup: :sparkles:
:star: 1198 | @arielleslie | http://www.freecodecamp.com/arielleslie
Pedro Abel Díaz Sánchez
@coderHook
Mar 01 2016 00:10

@ArielLeslie here is my final solution:

function sumFibs(num) {  
  var f1 = 0;
  var f2 = 1;
  var f3 = 1;
  var sum = 1;

  for (var i = 2; i <= num; i++){ //Here we pass through every fibonacci number.

    f3 = f2 + f1;
    f1 = f2;
    f2 = f3;

    if(f3 % 2 == 1){ //Let's see if its and odd number
      if(f3 <= num){ // if it is, I have to sum until I reach the num.
        sum += f3;
      } 
    } 
  }
  return sum;
}

sumFibs(75024);

Be critic, I promised not to cry, at least not loudly... : )

A-Alex-A
@A-Alex-A
Mar 01 2016 00:11
@johnlovespi 5*4 -> 20*3 -> 60*2 may be this helps
Pedro Abel Díaz Sánchez
@coderHook
Mar 01 2016 00:12
Basically, the problem I had with that number was that I was adding a number over the limit setted, so, with this new if I check when I have to stop.
Rami
@RNwebdk
Mar 01 2016 00:12
@ArielLeslie but dos that mean that it's a good practice to use bracket notation in function ?
John Espinoza
@johnlovespi
Mar 01 2016 00:13
really not understanding this any help on how you guys understood it
basic algorithms is going to destory me
Rami
@RNwebdk
Mar 01 2016 00:16
@johnlovespi what was the quastion ?
A-Alex-A
@A-Alex-A
Mar 01 2016 00:17
@johnlovespi what's the factorial of 4?
CPowers
@C-Powers
Mar 01 2016 00:21

Hi Yall, I'm having a bit of difficulty with something, and I'm not sure why it's happening. I'm doing the JS palindrome problem, and I've got the code working fine, but there's something very strange going on with the === operator.

so here's some example code:

myStr = "Yosemite";
myStrArr=myStr.split(' ');
myArrRev = myStrArr.reverse();

now, I use an if statement to soo if myArrRev === myStrArr, and it always returns true, and actually REVERSES the non-reversed array (myStrArr). Any ideas on why this happens? Thanks!

A-Alex-A
@A-Alex-A
Mar 01 2016 00:23
@Chris-Powers reverse changes original array
Aleksander Gębicki
@Takumar
Mar 01 2016 00:25
@Chris-Powers when you want to divide word to single letters you should use empty string as separator: split("")
Tyler Moeller
@TylerMoeller
Mar 01 2016 00:25
How can I add a number like this to an array: ["TextString", 0.50]? If I use value = value.toFixed(2), it becomes a string. If I use Number(value) after that, it removes the trailing zero.
CPowers
@C-Powers
Mar 01 2016 00:25
That was a type @Takumar, sorry
Caleb Martin
@caleb272
Mar 01 2016 00:26
i didn’t know Linus Torvalds created GIT too
Aleksander Gębicki
@Takumar
Mar 01 2016 00:26
@Chris-Powers in such case, what @A-Alex-A said
CPowers
@C-Powers
Mar 01 2016 00:26
@A-Alex-A thanks, I now see what's going on. I didn't realize that it would change the original array. So, I really only need to call array.reverse(), now newArr = array.reverse()
CamperBot
@camperbot
Mar 01 2016 00:26
chris-powers sends brownie points to @a-alex-a :sparkles: :thumbsup: :sparkles:
:star: 284 | @a-alex-a | http://www.freecodecamp.com/a-alex-a
CPowers
@C-Powers
Mar 01 2016 00:26
*not
*typo
Aleksander Gębicki
@Takumar
Mar 01 2016 00:27
@Chris-Powers change your myArrRev to string again and compare result with myStr (original string)
CPowers
@C-Powers
Mar 01 2016 00:28
No, I think I can just compare the arrays and skip that extra step, I just tested it by creating a new compare array and it worked fine
But I guess that's actually just the same thing
kalmont3
@kalmont3
Mar 01 2016 00:40

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

}

// Only change code above this line

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

// Change values below to test your code
abTest(2,2);

I lost it

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

}

// Only change code above this line

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

// Change values below to test your code
abTest(2,2);

can you help me
???
Jonah Chason
@lemmydog
Mar 01 2016 00:44
Has anyone completed the Record Collection challenge that can help me out?
demipixel
@demipixel
Mar 01 2016 00:46
sure @lemmydog what's up
Jonah Chason
@lemmydog
Mar 01 2016 00:54
It is asking me to create an if/else statment inside a function that updates a JSON object. The function uses arguments- one number and two strings. Can I get away with using the parameters in dot notation, just like I am adding values to a regular object?
Jonah Chason
@lemmydog
Mar 01 2016 00:59
// Setup
var collection = {
    2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    2468: {
      album: "1999",
      artist: "Prince",
      tracks: [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    1245: {
      artist: "Robert Palmer",
      tracks: [ ]
    },
    5439: {
      album: "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function update(id, prop, value) {
  if((value !== "")&&(prop !=="tracks")){
   collection.id.prop.value;
  }else if(prop==="tracks"||value!==""){
    collection.id.prop.push(value);
  }
  return collection;
}
// Alter values below to test your code
update(5439, "artist", "ABBA");
@demipixel I up loaded my code if you are still around. :)
Moisés Man
@moigithub
Mar 01 2016 01:02
@lemmydog u can use dot notation ONLY if whtaever follow the DOT is a real key name of that object...
but id and prop are variables.. so.. u need to use brackets
Jonah Chason
@lemmydog
Mar 01 2016 01:04
@moigithub Not sure how that would look. Would they be nested brackets? collection[id[prop[value]]]?
Moisés Man
@moigithub
Mar 01 2016 01:05
no nested.. just one next to the other
obj[a][b][c]
cuz.. obj[a] will return a object
firstObj=obj[a];
then
firstObj[b] will return another obj
secondObj = firstObj[b]
so its the same as obj[a][b]
Jonah Chason
@lemmydog
Mar 01 2016 01:09
So is the obj[a][b] a short hand version of do I need to set them in steps (firstObj=obj[a] / secondObj=firstObj[b]) ?
Moisés Man
@moigithub
Mar 01 2016 01:22
best way to find out is trying..n test whats difference btw both :P
food time :) bbl
Jonah Chason
@lemmydog
Mar 01 2016 01:24
@moigithub thanks for help
CamperBot
@camperbot
Mar 01 2016 01:24
lemmydog sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 691 | @moigithub | http://www.freecodecamp.com/moigithub
matthew3454
@matthew3454
Mar 01 2016 01:29
Why doesn't this work?:

function truncate(str, num) {

if(str.length > num){
str = str.slice(0,num-3);
str += "...";
}
return str;
}
truncate('A-tisket a-tasket A green and yellow basket', 11);

function truncate(str, num) {

  if(str.length > num){
    str = str.slice(0,num-3);
    str += "...";
  }
  return str;
}
truncate('A-tisket a-tasket A green and yellow basket', 11);
Colm Bowden
@colmbowden
Mar 01 2016 01:30

Hi folks, I just completed the "Profile Lookup" challange and I'm wondering if there is a better solution then the one I used, that doesn't involve me knowing the contact names and their position in the array?

'''

'''
//check if prop is a property of contacts
'''
CamperBot
@camperbot
Mar 01 2016 01:31
:bulb: to format code use backticks! ``` more info
Colm Bowden
@colmbowden
Mar 01 2016 01:33
function lookUp(firstName, prop){
// Only change code below this line

  //check if firstName is an contacts name

  //declare variables
  var test = "";
  var result = "";

  switch (firstName){

    case "Kristian":

      //check if prop is a property of contacts

       test = contacts[3].hasOwnProperty(prop);


        //return property 

       if (test === true) {

          result = contacts[3][prop];
          return result;

        } 

        else {
          return "No such property";
        }
      break;

    case "Sherlock":

      //check if prop is a property of contacts

       test = contacts[2].hasOwnProperty(prop);


        //return property 

       if (test === true) {

         result = contacts[2][prop];
          return result;

        } 

        else {
          return "No such property";
        }
      break;

    case "Harry":


          test = contacts[1].hasOwnProperty(prop);



       if (test === true) {

         result = contacts[1][prop];
          return result;

        } 

        else {
          return "No such property";
        }
      break;

    case "Akira":


          test = contacts[0].hasOwnProperty(prop);


       if (test === true) {


         result = contacts[0][prop];
          return result;

        } 

        else {
          return "No such property";
        }
      break;




      default:

      return "No such contact";
  }



// Only change code above this line
}
Brian
@sludge256
Mar 01 2016 01:36
@colmbowden You certainly chose a unique way of going about it
here's the wiki solution
for (var x = 0; x < contacts.length; x++){
    if (contacts[x].firstName === firstName) {
        if (contacts[x][prop]) {
            return contacts[x][prop];
        } else {
            return "No such property";
        }
    }
}
return "No such contact";
Colm Bowden
@colmbowden
Mar 01 2016 01:38
@sludge256 I tried a solution very similar to that at first but I couldn't get it to work properly
@sludge256 Thanks, i knew there was a much simpiler solution, thats why I asked!
CamperBot
@camperbot
Mar 01 2016 01:39
colmbowden sends brownie points to @sludge256 :sparkles: :thumbsup: :sparkles:
:star: 1718 | @sludge256 | http://www.freecodecamp.com/sludge256
Brian
@sludge256
Mar 01 2016 01:39
A common mistake people have with that solution is having return "No such contact"; within their for loop
which would end their function after the first loop
since it's the same as only looking at the first person in the list
saying there's no match and that whoever you're looking for doesn't exist
when the logic is you can only know that the contact does not exist AFTER you've looking through the entire list
demipixel
@demipixel
Mar 01 2016 01:41
@sludge256 I find it interesting that people have issues on the same few problems. Does this mean it's just a more difficult concept to grasp or should we help them a bit in the problem?
Brian
@sludge256
Mar 01 2016 01:43
Mmm it's definitely an interesting issue.
demipixel
@demipixel
Mar 01 2016 01:44
In the 4 days that I've been here (a little less), I've seen this "contact" thing come up several times
Brian
@sludge256
Mar 01 2016 01:44
I think part of it is people haven't gotten used to thinking about how a computer would solve the problem.
demipixel
@demipixel
Mar 01 2016 01:44
Perhaps we need to include a tutorial that contains info of:
var obj = {
  "hello": 4,
  "puppy": 6
}
var hello = "puppy";

obj.hello == 4;
obj["hello"] == 4
obj[hello] == 6
I've seen this chunk of code help many people before
Brian
@sludge256
Mar 01 2016 01:45
Well there lessons on bracket and dot notation
matthew3454
@matthew3454
Mar 01 2016 01:45
Can someone pretty please help me with my code?
Brian
@sludge256
Mar 01 2016 01:45
Keep in mind you never hear from the people who do understand and learned the concepts from the lessons
demipixel
@demipixel
Mar 01 2016 01:45
Yeah
@sludge256 true true
@matthew3454 Yo, what's up?
matthew3454
@matthew3454
Mar 01 2016 01:46
this bad boy:
function truncate(str, num) {

  if(str.length > num){
    str = str.slice(0,num-3);
    str += "...";
  }
  return str;
}
truncate('A-tisket a-tasket A green and yellow basket', 11);
demipixel
@demipixel
Mar 01 2016 01:46
@sludge256 Perhaps we should have a counter that shows that X amount of people completed this lesson today
@sludge256 So we can see "Oh, 20 people completed lesson X but only 10 people finished X+1, maybe X+1 is harder or too hard"
@matthew3454 I imagine you're having difficulty passing all the test cases?
There are a lot of edge cases in that problem haha
Emma Clark
@sapphirestone
Mar 01 2016 01:48

hey guys have any of you done the golf code waypoint? I'm having issues with my code <function golfScore(par, strokes) {
// Only change code below this line

if (strokes == 1) {
return "Hole-in-one";
}
else if (strokes<=par -2){
return "Eagle";
}
else if (strokes <= par -1){
return "Birdie";
}
else if (strokes == par ) {
return "Par";
}
else if (strokes == par+1 ) {
return "Bogey";
}
else if (strokes == par+2) {
return "Double Bogey";
}
else if (strokes >= par+3) {
return "Go Home";
}

// Only change code above this line
}

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

demipixel
@demipixel
Mar 01 2016 01:48
@sapphirestone
help format
CamperBot
@camperbot
Mar 01 2016 01:48

: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

Colm Bowden
@colmbowden
Mar 01 2016 01:48
@sludge256 @demipixel Its certainly a step up in difficulty from the previous challenges but thats probably a good thing as it really gets you to think about what you are doing. Ultimately I think I had problems with the bracket and dot notation that caused my first attempts to not work but I still managed to learn alot working out a working, if inefficent solution and I now understand the wiki solution better
Brian
@sludge256
Mar 01 2016 01:49
The analytics would be an interesting solution
demipixel
@demipixel
Mar 01 2016 01:49
@colmbowden I think it would be really cool if we could see how many unique people were completing lessons for the first time on each day, either as raw data or even in graphs
Brian
@sludge256
Mar 01 2016 01:49
Should the challenges always be that easy though?
demipixel
@demipixel
Mar 01 2016 01:50
Well
One thing we really SHOULD do is have "help" do something other than link here
Brian
@sludge256
Mar 01 2016 01:50
There is also this
algorithm profile lookup
hmm
that was supposed to do something
demipixel
@demipixel
Mar 01 2016 01:50
It would be 10x more useful to say "Okay, here are some things that can help you"
Brian
@sludge256
Mar 01 2016 01:51
help profile lookup
CamperBot
@camperbot
Mar 01 2016 01:51

:point_right: checkpoint profile lookup [wiki]

Checkpoint: Profile Lookup

Instructions

We have an array of objects representing different people in our contacts lists.

A lookUp function that takes firstName and a property (prop) as arguments has been pre-written for you.

The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.

If both are true, then return the "value" of that property.

If firstName does not correspond to any contacts then return "No such contact"

If prop does not correspond to any valid properties then return "No such property"

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

:pencil: read more about checkpoint profile lookup on the FCC Wiki

Brian
@sludge256
Mar 01 2016 01:51
hint
CamperBot
@camperbot
Mar 01 2016 01:51
:construction: Spoilers are only in the Bonfire's Custom Room :point_right:
matthew3454
@matthew3454
Mar 01 2016 01:51
@demipixel yes curses!!
Emma Clark
@sapphirestone
Mar 01 2016 01:51
<
function golfScore(par, strokes) {
  // Only change code below this line

  if (strokes == 1) {
    return "Hole-in-one"; 
  }
  else if (strokes<=par -2){
    return "Eagle";
  }
  else if (strokes <= par -1){
    return "Birdie";
  }
  else if (strokes == par ) {
    return "Par";
  }
  else if (strokes == par+1 ) {
    return "Bogey";
  }
  else if (strokes == par+2) {
    return "Double Bogey";
  }
  else if (strokes >= par+3) {
    return "Go Home";
  }

  // Only change code above this line
}

// Change these values to test
golfScore(5, 4);>
Brian
@sludge256
Mar 01 2016 01:51
well that didn't go where I wanted it to :angry:
Colm Bowden
@colmbowden
Mar 01 2016 01:51
@demipixel @sludge256 As someone who is learning it can be frustrating in more difficult challenges but being "spoon fed" the solutions wont help people actually learn either
Morgan Tuttle
@mtuttle2
Mar 01 2016 01:52
@sapphirestone make sure you include the “!” in the strings that require it
demipixel
@demipixel
Mar 01 2016 01:52
  • Think about the problem in english. Then convert your english explanation of your program into code
  • Try console.log() in different sections to test stuff.
  • If you think a specific part of your code isn't working, try narrowing that part down. Add some console.log or return to see if you can figure out if something is not what you expect it
  • If you've tried these and you can't figure it out without some help, the people at the help chatroom would be happy to help :)
Morgan Tuttle
@mtuttle2
Mar 01 2016 01:52
“Hole-in-one!"
demipixel
@demipixel
Mar 01 2016 01:53
That would be better for when you click on "help"
Emma Clark
@sapphirestone
Mar 01 2016 01:53
ok ill try that. I'm not sure if I have troubles with the javascript or just string spelling errors
demipixel
@demipixel
Mar 01 2016 01:53
Also include "read documentation/google functions you don't know"
Morgan Tuttle
@mtuttle2
Mar 01 2016 01:53
the code is fine, just your spelling error in the string
Brian
@sludge256
Mar 01 2016 01:53
I think this used to be linked
demipixel
@demipixel
Mar 01 2016 01:53
I would still love to see the analytics, though. Once we do start grabbing data, there's endless possibilities
Brian
@sludge256
Mar 01 2016 01:54
I don't recall if it was the help button that did it though
demipixel
@demipixel
Mar 01 2016 01:54
@sludge256 A beginner-ish coder told me that it was really useful to think of a program in english instead of coding and we were wondering why FCC didn't explain that
It makes sense that that sort of thing can't appear in a challenge, though
@matthew3454 Any ideas how to solve it? :P
Brian
@sludge256
Mar 01 2016 01:55
Yea psuedo code is nice
demipixel
@demipixel
Mar 01 2016 01:55
@matthew3454 Some of the edge cases are explained in the description that you just haven't read. Maybe the "If the num is less than or equal to 3..." part? ;)
@sludge256 Meh, pseudo code or just english words
Something other than "resort to help from other people", ya know?
Also, people might be embarrassed to ask others for help
Emma Clark
@sapphirestone
Mar 01 2016 01:56
Thanks guys so much!
Morgan Tuttle
@mtuttle2
Mar 01 2016 01:56
No problem
Brian
@sludge256
Mar 01 2016 01:58
I think we could port the bot functionality from the algo section to include a few other lessons
since you can do this
algorithm reverse a string
ok i guess not
bf reverse a string
CamperBot
@camperbot
Mar 01 2016 01:59

:fire:Bonfire: Reverse a String :link:

function reverseString(str) {
  return str;
}

reverseString('hello');

Reverse the provided string.

more info:  bf details | bf links | hint

Brian
@sludge256
Mar 01 2016 01:59
hint
CamperBot
@camperbot
Mar 01 2016 01:59
:construction: Spoilers are only in the Bonfire's Custom Room :point_right:
Brian
@sludge256
Mar 01 2016 01:59
then you can request automated hints in the custom room
matthew3454
@matthew3454
Mar 01 2016 01:59
@demipixel thanks
CamperBot
@camperbot
Mar 01 2016 01:59
matthew3454 sends brownie points to @demipixel :sparkles: :thumbsup: :sparkles:
:star: 129 | @demipixel | http://www.freecodecamp.com/demipixel
Brian
@sludge256
Mar 01 2016 02:03
You could also see what the Data Science "team" thinks about it
demipixel
@demipixel
Mar 01 2016 02:04
@matthew3454 np :)

@sludge256

then you can request automated hints in the custom room

I think that's missing the point a bit

Brian
@sludge256
Mar 01 2016 02:06
It was more in regards to being too shy to ask a human for help
demipixel
@demipixel
Mar 01 2016 02:06
Ah
However that still involves chat, so if they don't use the chatroom, they may not know about it
Also, when they're not FCC, they won't have those resources
So if they don't know how to think through a problem, they'll struggle :/
James Minkler
@Hook1169
Mar 01 2016 02:07
Anyone recently worked on the "Nesting forLoops" challenge?
Jacob Schumer
@jacobschumer
Mar 01 2016 02:07
Can anyone tell me if this is an appropriate form for an API call? I've been trying to test it but if it's doing anything it doesn't trigger any alerts I try. I've tried getJSON, postJSON and just get and post.
$(document).ready(function(){
  $("#trigger").on("click", function(){
  var api = "http://api.forismatic.com/api/1.0/";    $.post(api,{
    method: "getQuote",
    format: "JSON",
    lang: "en",},function(json, status){
      var html = "";
     if (status == "success") {
       alert("success");
     }
    else {
      alert("fail");
    }
    })
bitgrower
@bitgrower
Mar 01 2016 02:08
:point_up: February 29, 2016 5:44 PM bitgrower approves of @demipixel's message ... :)
Brian
@sludge256
Mar 01 2016 02:08
General programming concepts are being covered/worked on in our video lessons
demipixel
@demipixel
Mar 01 2016 02:09
@Hook1169 what's up?
Brian
@sludge256
Mar 01 2016 02:09
Would you propose that more guidance be provided on those specific lessons though?
demipixel
@demipixel
Mar 01 2016 02:10
I don't know. Lessons need to introduce and use concepts, and some may be more difficult than others
I think *they should have a variety of resources to choose from for help, however.
James Minkler
@Hook1169
Mar 01 2016 02:10
I am just wondering what people read about to understand the challenge. I believe i understand how to run through a nested for loop, but to then multiply the values in the sub-array has me stumped
Brian
@sludge256
Mar 01 2016 02:11
There is also a wiki button on the navbar
although the new wiki version isn't all inclusive
demipixel
@demipixel
Mar 01 2016 02:11
bf Nested
CamperBot
@camperbot
Mar 01 2016 02:11
Sorry, can't find a bonfire called nested. [ Check the map? ]
Brian
@sludge256
Mar 01 2016 02:11
bf only applies to the stuff in the algorithm sections
CamperBot
@camperbot
Mar 01 2016 02:11
Sorry, can't find a bonfire called only applies to the stuff in the algorithm sections. [ Check the map? ]
Brian
@sludge256
Mar 01 2016 02:12
which is why I mentioned extending that functionality earlier
although you can do help nested
help nested
CamperBot
@camperbot
Mar 01 2016 02:12

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

Challenge: Accessing Nested Arrays in JSON

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

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

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

demipixel
@demipixel
Mar 01 2016 02:12
@Hook1169 Okay, so you can start by making the loops
Brian
@sludge256
Mar 01 2016 02:12
and get a link from that
demipixel
@demipixel
Mar 01 2016 02:12
@Hook1169 Simplify the problem. How would you multiply all values in a 1D array?
Brian
@sludge256
Mar 01 2016 02:12
some of the articles are pretty sparse though
James Minkler
@Hook1169
Mar 01 2016 02:12
Yes I did do that.
Brian
@sludge256
Mar 01 2016 02:13
but you can contribute to it on https://github.com/FreeCodeCamp/wiki
James Minkler
@Hook1169
Mar 01 2016 02:13
Multiple a declared variable against [i]
demipixel
@demipixel
Mar 01 2016 02:13
Okay
So now how for a 2D
James Minkler
@Hook1169
Mar 01 2016 02:14
That is where i seem to 'bork up' ... :) I tried to use my variable * [j] but does not seem to be accurate
i am using 'j' for my 2D
demipixel
@demipixel
Mar 01 2016 02:15
So you're doing arr[j]?
James Minkler
@Hook1169
Mar 01 2016 02:16
Oh good point. I should be using 'i' then i think
demipixel
@demipixel
Mar 01 2016 02:16
@Hook1169 Look at the left side bar on how to access a value in a 2D array ;)
James Minkler
@Hook1169
Mar 01 2016 02:16
' product *= arr[i];'
is what i have
demipixel
@demipixel
Mar 01 2016 02:17
@Hook1169 What does the code on the left sidebar do?
The code example of a nested loop
James Minkler
@Hook1169
Mar 01 2016 02:17
Oh i see, [i][j]
thanks @demipixel
CamperBot
@camperbot
Mar 01 2016 02:19
hook1169 sends brownie points to @demipixel :sparkles: :thumbsup: :sparkles:
:star: 130 | @demipixel | http://www.freecodecamp.com/demipixel
James Minkler
@Hook1169
Mar 01 2016 02:19
I think i am closer, much closer
bitgrower
@bitgrower
Mar 01 2016 02:19

@sludge256 A beginner-ish coder told me that it was really useful to think of a program in english instead of coding and we were wondering why FCC didn't explain that

As I've often said ... that screen really encourages people to start coding first, and it's the one of very few complaints I have about FCC ... people should be taught to do this ... maybe have a space for them to re-write the instructions ... maybe even give them a template ...
Program Specifications:
Input (what am I given, and what format is it in)?
Output (what am I to return, and what format is it in)?

Path: (what's my plan for transforming input to output ... what data structures, algos, functions might be helpful?
(with some suggestions provided here, like we do with the helpful hints)

Brian
@sludge256
Mar 01 2016 02:23
@SainitPeter :point_up: We're discussing common mistakes that people make and how to go about identifying the common issues (analytics?) and how to address them. Be it more guidance in the instructions, more visible resources besides the help chats, etc
(I know the DataSci guys are working with identification to some extent)
@bitgrower @demipixel feel free to chime in if I forgot something
demipixel
@demipixel
Mar 01 2016 02:24
That about summed it up
Also don't forget that we're translating, so we if we're able to translate extra "help" resources we add
Then people can use that if everyone in chat only speaks English
James Minkler
@Hook1169
Mar 01 2016 02:28
js
function multiplyAll(arr) {
  var product = 1;
  // Only change code below this line
    for (var i = 0; i < arr.length; i++) {
    for ( var j = 0; j < arr[i]; j++){
     product *= arr[i][j];
    }
  }
  // Only change code above this line
  return product;
}

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
bitgrower
@bitgrower
Mar 01 2016 02:28
yeah, it is interesting, @demipixel -- because the problems people have the most trouble with can also vary over time a bit ... I mean, when I started on gitter, we had more people having problems with Seek & Destroy ...
James Minkler
@Hook1169
Mar 01 2016 02:28
Am i completely off base?
demipixel
@demipixel
Mar 01 2016 02:28
@Hook1169 You have arr[i]
bitgrower
@bitgrower
Mar 01 2016 02:28
looks pretty close, @Hook1169 -- how does it do in your test cases ...
demipixel
@demipixel
Mar 01 2016 02:28
I think you meant arr[i].length
James Minkler
@Hook1169
Mar 01 2016 02:28
Maybe i need to read more at MDN on arrays
uhh test cases?
they all come back red
demipixel
@demipixel
Mar 01 2016 02:29
You're doing j < arr[i] but arr[i] is an array, not a number
Brian
@sludge256
Mar 01 2016 02:29
It was chaos when Profile Lookup was released ;)
bitgrower
@bitgrower
Mar 01 2016 02:29

@bitgrower @demipixel feel free to chime in if I forgot something

Also, having people express the problem in English will also (hopefully) encourage them to comment their code ... :) bitgrower says, gently ...

James Minkler
@Hook1169
Mar 01 2016 02:29
but doesn't that proved the index of the sub array?
demipixel
@demipixel
Mar 01 2016 02:30
@Hook1169 You can only do num < num
Right now you're doing num < array
James Minkler
@Hook1169
Mar 01 2016 02:30
oh but i didnt .length
demipixel
@demipixel
Mar 01 2016 02:30
yep
James Minkler
@Hook1169
Mar 01 2016 02:30
ok
demipixel
@demipixel
Mar 01 2016 02:30
As for analytics... challenge completion is only one
bitgrower
@bitgrower
Mar 01 2016 02:30
good eye, @demipixel
James Minkler
@Hook1169
Mar 01 2016 02:31
Thank you SOO very much @demipixel for sticking with me through that.. I appreciate your paitence.
CamperBot
@camperbot
Mar 01 2016 02:31
hook1169 sends brownie points to @demipixel :sparkles: :thumbsup: :sparkles:
demipixel
@demipixel
Mar 01 2016 02:31
We could get analytics on how much people actually click on links on the left sidebar (if we need to make them more visible or encourage people to click on them more)
bitgrower
@bitgrower
Mar 01 2016 02:31
I think analytics would be interesting for the community, as well ... :)
CamperBot
@camperbot
Mar 01 2016 02:31
:warning: hook1169 already gave demipixel points
demipixel
@demipixel
Mar 01 2016 02:31
@Hook1169 np
Also we could do analytics for time between starting the problem and typing code. This might give us an idea of how much people just start without reading anything
James Minkler
@Hook1169
Mar 01 2016 02:32
I try to read MDN and any discussion in Wiki before asking anything
demipixel
@demipixel
Mar 01 2016 02:32
Also, once we get some of this feedback, if there's enough people using FCC (idk if there is), we might do some AB testing
@Hook1169 It's np. Also try and see if you can understand errors on the left console :)
bitgrower
@bitgrower
Mar 01 2016 02:33
@Hook1169 -- do you try writing things out ?
James Minkler
@Hook1169
Mar 01 2016 02:33
On my white board i try to do psuedo code
bitgrower
@bitgrower
Mar 01 2016 02:34
did you see my format, above ? I'd be curious to know if that would help you ...
James Minkler
@Hook1169
Mar 01 2016 02:34
or at least highlight what things i need to do to get a result
let me scroll up
bitgrower
@bitgrower
Mar 01 2016 02:35
3 basic things a piece of code typically needs to do ...
receive input
return output
transform input into output (sometimes additionally producing "side effects")
Tony
@Rogers187
Mar 01 2016 02:35

Not sure what I'm doing wrong. The directions are confusing me... `` var string = "Split me into an array";
var array = [];

// Only change code below this line.

array = string.split('spaces');`
```

bitgrower
@bitgrower
Mar 01 2016 02:36
@Rogers187 -- put a literal space inbetween those quotes, my friend ...
demipixel
@demipixel
Mar 01 2016 02:36
help format
CamperBot
@camperbot
Mar 01 2016 02:36

: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

Tony
@Rogers187
Mar 01 2016 02:36
Challenge is Split Strings with split
bitgrower
@bitgrower
Mar 01 2016 02:38
did you see my comment, @Rogers187 ?
Tony
@Rogers187
Mar 01 2016 02:38
@bitgrower Thanks.
CamperBot
@camperbot
Mar 01 2016 02:38
rogers187 sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 675 | @bitgrower | http://www.freecodecamp.com/bitgrower
Tony
@Rogers187
Mar 01 2016 02:38
@bitgrower yep would of never thought that.
bitgrower
@bitgrower
Mar 01 2016 02:40
@Rogers187 -- also checking out the string.split() page on Mozilla Developer Network would (and will) have helped you ...
hmmm...that's another thing that might be interesting, @sludge256 -- have "related" challenges ... so, for instance, give coders the challenge of splitting a string at various different parts ... little exercises all about using split ... not anything big ... but something which permits some useful repetition ...
on the above challenge ... the coder never actually sees what the new array looks like, either (unless they use console.log ... that might be nice ... :)
Andrew Charlebois
@andrewchar
Mar 01 2016 02:49
so im doing Roman Numeral Converter and i feel if i google something about it it will just show me a solution how to do it lol
demipixel
@demipixel
Mar 01 2016 02:51
@andrewchar Well, do you have a question about how to do something javascript in general?
Andrew Charlebois
@andrewchar
Mar 01 2016 02:52
just trying to figure out what i should use to make associations between numbers and roman numerals
demipixel
@demipixel
Mar 01 2016 02:53
Well, start by thinking about your problem in english instead of code
Let's say we have the number 2063
How would you start by making that into roman numerals?
Andrew Charlebois
@andrewchar
Mar 01 2016 02:54
i started by just making a bunch of variables
6 of them
bitgrower
@bitgrower
Mar 01 2016 02:54
@andrewchar --- not to worry, it won't -- it will just give you the definition of what the roman numerals look like ... at least I certainly didn't stumble across anything I used in my solution ...
@andrewchar ... without code ... say, arithmetically ...
demipixel
@demipixel
Mar 01 2016 02:56
HOLY CRAP
bitgrower
@bitgrower
Mar 01 2016 02:56
what, @demipixel ?!?
demipixel
@demipixel
Mar 01 2016 02:56
BIG TF2 UPDATE
GAAAHHHHHH
bitgrower
@bitgrower
Mar 01 2016 02:57
what's TF2 ?
demipixel
@demipixel
Mar 01 2016 02:57
Team Fortress 2
Free Multiplayer FPS Video Game
bitgrower
@bitgrower
Mar 01 2016 02:57
MOOG ?
demipixel
@demipixel
Mar 01 2016 02:57
?
bitgrower
@bitgrower
Mar 01 2016 02:57
nvm ...
Tony
@Rogers187
Mar 01 2016 02:58
@bitgrower gonna have to check that out
bitgrower
@bitgrower
Mar 01 2016 02:58
@andrewchar ... let's start with a simpler problem ... how would you translate 4 into roman numerals ?
Andrew Charlebois
@andrewchar
Mar 01 2016 02:58
you asking for the numeral as in IV or how to in code
Brian
@sludge256
Mar 01 2016 02:59
I haven't gotten on hat simulator in months

wut

Updated The Bounty Hat, Treasure Hat, and Hat of Undeniable Wealth and Respect to be tradable

bitgrower
@bitgrower
Mar 01 2016 02:59
LOL ... what do you have to do to get from the number to the roman numeral ?
demipixel
@demipixel
Mar 01 2016 03:00
@sludge256 That's.... weird
I guess it's tradable until midnight that night
Brian
@sludge256
Mar 01 2016 03:00
I wonder why they enabled it
demipixel
@demipixel
Mar 01 2016 03:00
@sludge256 Eh, share it with friends or something, idk
bitgrower
@bitgrower
Mar 01 2016 03:00
is this all TF2 talk ?
demipixel
@demipixel
Mar 01 2016 03:00
This message was deleted
Brian
@sludge256
Mar 01 2016 03:00
No JS
;)
demipixel
@demipixel
Mar 01 2016 03:00
Wait
Brian
@sludge256
Mar 01 2016 03:00
shh the :cop: might hear us
demipixel
@demipixel
Mar 01 2016 03:00
JS talk
:police_car:
bitgrower
@bitgrower
Mar 01 2016 03:01
I like saying this in here ... so much fun ... "get a room" ... :) :) :)
@andrewchar ... as far as I know there's not any hidden trick in doing the roman numeral challenge ... it's simply a matter of translation ... and how do you construct that translation ... .
demipixel
@demipixel
Mar 01 2016 03:03
@bitgrower lol i did the roman numeral golf challenge
bitgrower
@bitgrower
Mar 01 2016 03:03
I have no doubt, @demipixel ... some day I'll be a hotshot like you ... but I'm not there yet ... :)
demipixel
@demipixel
Mar 01 2016 03:03
259 characters
I KNOW it can be less, but I haven't had the time
bitgrower
@bitgrower
Mar 01 2016 03:04
my perfectionism impulses have gone into doing software quality assurance, I'm afraid ... I like stuff that works, is usable, is re-usable, is buildable upon ...
I understand the appeal ... it's just not a strong one for me ... :)
..but ... I can recommend the most excellent essays of one Jon Bentley, whose JACM columns were compiled into books .... one "Programming Pearls", another "Writing Efficient Programs" ...
demipixel
@demipixel
Mar 01 2016 03:08
289 characters to hardcode roman numerals
var convert=n=>({2:'II',3:'III',4:'IV',5:'V',9:'IX',12:'XII',16:'XVI',29:'XXIX',44:'XLIV',45:'XLV',68:'LXVIII',83:'LXXXIII',97:'XCVII',99:'XCIX',500:'D',501:'DI',649:'DCXLIX',798:'DCCXCVIII',891:'DCCCXCI',1000:'M',1004:'MIV',1006:'MVI',1023:'MXXIII',2014:'MMXIV',3999:'MMMCMXCIX'})[n];
So technically my golf version is shorter :D
bitgrower
@bitgrower
Mar 01 2016 03:08
cool ...
there are definitely cool things to learn from your golf challenges ... :) I'm just not there .. and it makes me feel left out ...
Andrew Charlebois
@andrewchar
Mar 01 2016 03:09
heh
bitgrower
@bitgrower
Mar 01 2016 03:10
how ya doin' @andrewchar ?
Andrew Charlebois
@andrewchar
Mar 01 2016 03:10
see that brick wall?
zackluckyf
@zackluckyf
Mar 01 2016 03:10
@DavidWeedmark I did figure it out it actually was really easy
function getMonth(m){
    var month = ["January", "February", "March", "April", "May" ,"June" ,"July" ,"August" ,"September", "October", "November", "December"];
    return month[m-1];
  }
Andrew Charlebois
@andrewchar
Mar 01 2016 03:10
im infront of it
this challenge is not meant to type out every symbol they give and give that a varible is it
variable*
David Weedmark
@DavidWeedmark
Mar 01 2016 03:11
@zackluckyf nice!
bitgrower
@bitgrower
Mar 01 2016 03:14
@andrewchar -- there is a very easy way to make a data set into addressable entities, though ...
Andrew Charlebois
@andrewchar
Mar 01 2016 03:14
objects..
bitgrower
@bitgrower
Mar 01 2016 03:14
or ?
Andrew Charlebois
@andrewchar
Mar 01 2016 03:14
arrays
bitgrower
@bitgrower
Mar 01 2016 03:15
yep
Andrew Charlebois
@andrewchar
Mar 01 2016 03:15
you serious
bitgrower
@bitgrower
Mar 01 2016 03:15
now, my preference is arrays, but that's probably just because I'm more comfortable with them ...
Andrew Charlebois
@andrewchar
Mar 01 2016 03:15
i was thinking, it cant be that easy, that seems like cheating
bitgrower
@bitgrower
Mar 01 2016 03:15
LOL ... well, the artistry is how you design the arrays, how big you make them and what you put into them ...
Andrew Charlebois
@andrewchar
Mar 01 2016 03:16
ok wait a minute
so i dont have to do nothing special like
make this and have it be able to convert ANY number to roman numeral
just the numbers in their test?1
i think i am overthinking this
lol
bitgrower
@bitgrower
Mar 01 2016 03:17
years ago I applied for a programming job ... they gave me a "coding test" ... I didn't have to return it the next day ... .but they wanted me to supply answers ... they gave me an assembly language instruction set, a problem and then asked me to solve it 4 different ways: 1. optimize time; 2. optimizing memory; 3. something halfway between 1 & 2 4. freestyle --- just another way I'd like to solve the problem ...
(oh yeah, i got the job ... i was the first jr programmer they'd hired in the dept ... )
david
@pfr-77
Mar 01 2016 03:18
hey, I've got a Q about for loops
bitgrower
@bitgrower
Mar 01 2016 03:19
@andrewchar -- if you know how to convert 5000 into a V with a bar over it ... knock yourself out ... but I satisfied myself with numbers up to ... 3000? I think ?
what's your question @pfr-77
Andrew Charlebois
@andrewchar
Mar 01 2016 03:19
@bitgrower 3000 :O
david
@pfr-77
Mar 01 2016 03:19
all right well
first of all I found this neat code visualizer over at http://pythontutor.com/
bitgrower
@bitgrower
Mar 01 2016 03:20
well I don't think 4000 thousand, because I think it would have been one of those things like IV ...
yep -- I know that site very welll ... .
david
@pfr-77
Mar 01 2016 03:20
so I was running through some of my stuff there and I noticed I got an error during one and it turns out that I didn't have var in the conditions
for (var i = 1) etc
but everything is fine on this web site
so I'm wondering how necessary it is and if it's a problem here or what
bitgrower
@bitgrower
Mar 01 2016 03:21
yeah, it def likes var on your loop variables, or it won't run them ....
it's EXTREMELY good practice ...
david
@pfr-77
Mar 01 2016 03:21
heh I'll be sure to try and remember
the codecademy lab doesn't have an issue with not using var either
bitgrower
@bitgrower
Mar 01 2016 03:22
in your web dev projects you may find js code from many different contributors ... how many people do you think use "i" as a loop variable ?
Ahmedur Rahman Shovon
@arsho
Mar 01 2016 03:22
there is a new feature for loop variable called "let"
bitgrower
@bitgrower
Mar 01 2016 03:22
yes, in ES6
but doing web dev, it's helpful to know how to code in non es6 versions, because of the varying browser support ...
anyway ... @pfr-77 -- so, if you use the variable named i ... who knows what trouble you may be borrowing -- or creating -- for some other piece of code ?
global variables are generally frowned upon in other languages ... but they don't have the challenge of having a name collision with another piece of code ...
Gagandeep Singh
@Guggu
Mar 01 2016 03:37
hey fcc guys, can anyone help me on this code

function pair(str) {
// Return each strand as an array of two elements, the original and the pair.
var pair = [];

// Function to check with strand to pair.
var search = function(char) {
switch (char) {
case 'A':
pair.push(['A', 'T']);
break;
case 'T':
pair.push(['T', 'A']);
break;
case 'C':
pair.push(['C', 'G']);
break;
case 'G':
pair.push(['G', 'C']);
break;
}
};

// Loops through the input and pair.
console.log(char);
for (var i = 0; i < str.length; i++) {
search(str[i]);
}

return pair;
}

pair("ATCGA");

Garrett
@grrttmrtn
Mar 01 2016 03:38
I can't get anywhere on the nesting for loops challenge
apklip
@apklip
Mar 01 2016 03:38

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

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

return collection;
}

// Alter values below to test your code
update(1245, "tracks", "Addicted to Love")

My script does almost everything right
but turns the tracks array into a string
Gagandeep Singh
@Guggu
Mar 01 2016 03:39
ReferenceError: 'char' is undefined this error shows in my code
apklip
@apklip
Mar 01 2016 03:40
@Guggu Try console.log(char());
Gagandeep Singh
@Guggu
Mar 01 2016 03:41
image.png
apklip
@apklip
Mar 01 2016 03:41
wait
bitgrower
@bitgrower
Mar 01 2016 03:41
hi all ... can you see if you can pass this first essential challenge ... posting your code with syntax coloring ? here's how
explain format
CamperBot
@camperbot
Mar 01 2016 03:41

: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

Gagandeep Singh
@Guggu
Mar 01 2016 03:41
image.png
image.png
image.png
apklip
@apklip
Mar 01 2016 03:41
@Guggu You might want to give your function a name?
I'm not that far in.
But I have a few years with js
months*
You can't just log char in the console.
James Fraser
@wulfgarpro
Mar 01 2016 03:42
If I have a digraph with cycles and I want to get all paths from A to B with <= x stops, and A can equal B; what is the simplest algorithm I can use?
apklip
@apklip
Mar 01 2016 03:42
You have to call a function and give it a parameter
Stephanie
@spogburn
Mar 01 2016 03:42
hello, i was wondering if someone here can help me iterate through an array that has multiple identical elements and get it to stop at the last of those elements instead of the first one. I am really new to JS I just started about 6 weeks ago, I am doing a coding challenge and I am stuck at this point.
Here is an example: say the array is integers:
var sumArray = [ 12, 19, 69, 44, 36, 69 ];
how do I get the last 69 (because the position is important) rather than the first one.
bitgrower
@bitgrower
Mar 01 2016 03:44
for (i = 0; i < sumArray.length); i++) {
console.log(sumArray[i]);
}
Gagandeep Singh
@Guggu
Mar 01 2016 03:44
@DarkPigeons still it not works...
bitgrower
@bitgrower
Mar 01 2016 03:45
or ... are you looking for the last of the elements which has at least one other in the array, @spogburn ?
Stephanie
@spogburn
Mar 01 2016 03:45
ok @bitgrower i wasn't clear
In this case, I'm searching for the largest number
it's 69 in this example, but really could be anything
but when there are two 69s, I want to find the position of the last one
I want to find the last largest number, and then be able to identify its position
bitgrower
@bitgrower
Mar 01 2016 03:46
okay .. what do you think you need to do to do that ?
Stephanie
@spogburn
Mar 01 2016 03:46
so, yeah, the last of the elements which has at least one other could do it
bitgrower
@bitgrower
Mar 01 2016 03:46
break it down ... how would you find the largest number in the array ?
Stephanie
@spogburn
Mar 01 2016 03:47
I was hoping I could iterate backwards through the array looking for hte largest one
but that doest not seem to work
bitgrower
@bitgrower
Mar 01 2016 03:47
break it down, solve one piece of the puzzle at a time ... how would you find the largest number in the array ?
Stephanie
@spogburn
Mar 01 2016 03:47
I can find the largest one. I set a variable called largest, then look for if it is larger than the array item at location i (sumArray[i]. then I can log that or save it
bitgrower
@bitgrower
Mar 01 2016 03:48
cool ... so .. how would you save the position ?
Stephanie
@spogburn
Mar 01 2016 03:48

Here is that code: var largest = sumArray[0]; //declares a variable, largest, sets value to the first element in sumArray

for (k = 0; k < sumArray.length; k++) {
if (sumArray[k] > largest){ //tests to see as it loops to see if an item at "k" position in sumArray is greater than the value of largest
largest = sumArray[k] //assigns sumArray[k] to largest if it is in fact greater than the earlier value of largest
}

Gagandeep Singh
@Guggu
Mar 01 2016 03:48
thanks @DarkPigeons I m just removed the console.log and now it works
CamperBot
@camperbot
Mar 01 2016 03:48
guggu sends brownie points to @darkpigeons :sparkles: :thumbsup: :sparkles:
bitgrower
@bitgrower
Mar 01 2016 03:48
:point_up: February 29, 2016 7:48 PM ????
CamperBot
@camperbot
Mar 01 2016 03:48
:star: 225 | @darkpigeons | http://www.freecodecamp.com/darkpigeons
Stephanie
@spogburn
Mar 01 2016 03:48
I think that is where I am stuck. You can use sumArray.indexOf to find position, right?
Adam
@simplyadamg
Mar 01 2016 03:48
Hello hello!
Emily
@Ellestial
Mar 01 2016 03:49
hello!
bitgrower
@bitgrower
Mar 01 2016 03:49
what represents the position in the array in the loop ?
Adam
@simplyadamg
Mar 01 2016 03:49
Anyone want to give me some reflection on the search and destroy algorithm challenge?
Eric
@eti313
Mar 01 2016 03:49
hello
bitgrower
@bitgrower
Mar 01 2016 03:49
hello @Ellestial , @simplyadamg
Adam
@simplyadamg
Mar 01 2016 03:49
I was a little high, and I solved it... But I think I tricked the computer into beliveing I had the right answer when I was really lying.
To the computer
=)
bitgrower
@bitgrower
Mar 01 2016 03:49
ha ... not possible ...
Adam
@simplyadamg
Mar 01 2016 03:50
I lied to the computer and now I'm hanging my head in shame =(
function destroyer(var1,var2,var3,var4){
    function callbackFct(var1){
        if(var1 === var2 || var1 === var3 || var1 === var4){
            return false;
        }else{
            return true;
        }


        }

    var arr = var1.filter(callbackFct)
    console.log(arr)
    return(arr)
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3)
Eric
@eti313
Mar 01 2016 03:50
@simplyadamg seek and destroy?
Adam
@simplyadamg
Mar 01 2016 03:50
yes
Stephanie
@spogburn
Mar 01 2016 03:50
@bitgrower in the loop, k represents the position
bitgrower
@bitgrower
Mar 01 2016 03:50
@simplyadamg -- what you HAVEN'T done is made a general solution ... :)
Adam
@simplyadamg
Mar 01 2016 03:51
No I guess I made a specific solution.
Eric
@eti313
Mar 01 2016 03:51
because I'm a street walking cheetah
with a heart full of napalm
Adam
@simplyadamg
Mar 01 2016 03:51
for the specific tests mentioned in the challenge =P
bitgrower
@bitgrower
Mar 01 2016 03:51
okay ... so ... I'm guessing you could save that off somewhere, eh @spogburn ?
Stephanie
@spogburn
Mar 01 2016 03:53
@bitgrower so like in a variable called "position", save the position of the "largest" variable at location k in the array when it gets to that point
Adam
@simplyadamg
Mar 01 2016 03:53
the callback function for filter takes the parameters (value,index,array) right? Does that have something to do with the right answer?
bitgrower
@bitgrower
Mar 01 2016 03:54
@spogburn ... yep ...
Stephanie
@spogburn
Mar 01 2016 03:54
I think, though, I have a problem which is that the variable I am calling "largest" never actually becomes that last 69 (in the example)
bitgrower
@bitgrower
Mar 01 2016 03:54
change the conditional, and it will ...
Stephanie
@spogburn
Mar 01 2016 03:54
I did put a <= and that did not seem to work :(
I mean >=
bitgrower
@bitgrower
Mar 01 2016 03:55
it should ...
apklip
@apklip
Mar 01 2016 03:55
No problem @Guggu
Stephanie
@spogburn
Mar 01 2016 03:55
cuz I console.log the position of "largest" and it never gets past position 2
let me try again....
bitgrower
@bitgrower
Mar 01 2016 03:56
hmmm how could you never get past position 2 if you're finding the largest number in the array ...
Stephanie
@spogburn
Mar 01 2016 03:56
well cuz right now the largest number is in the second position
i mean, if i move the largest number to the 3 and 6 position, it will never get past position 3
bitgrower
@bitgrower
Mar 01 2016 03:57
but you don't know that until you look thru all the elements, right ?
I can't find the largest number in an array of 10 elements without looking at all 10 ...
Stephanie
@spogburn
Mar 01 2016 03:58
yeah, it checks the next element to see if it is greater than or equal to the element at its current position.
it checks each element
bitgrower
@bitgrower
Mar 01 2016 03:58
you should have all the pieces ...
Stephanie
@spogburn
Mar 01 2016 03:58
but it is never assigned to the last one it is also equal to, which I don't understand
bitgrower
@bitgrower
Mar 01 2016 03:58
it should ...
post your code as it is now ...
Stephanie
@spogburn
Mar 01 2016 03:59

var sumArray = [ 12, 19, 44, 69, 36, 69 ];

var largest = sumArray[0]; //declares a variable, largest, sets value to the first element in sumArray
var position;

for (k = 0; k < sumArray.length; k++) {
if (sumArray[k] >= largest){ //tests to see as it loops to see if an item at "k" position in sumArray is greater than the value of largest
largest = sumArray[k] //assigns sumArray[k] to largest if it is in fact greater than the earlier value of largest
position = sumArray.indexOf(largest)

}

console.log(position)

}

it logs: 0, 1, 2, 3, 3, 3
i feel there is some basic logic i am somehow missing out on it's driving me crazy
bitgrower
@bitgrower
Mar 01 2016 04:01
well ... you need to save the values once to a variable you can collect (return) outside of your loop ...
Stephanie
@spogburn
Mar 01 2016 04:01
i mean, I understand the logic the computer is thinking. It's thinking - hey, the one in position k IS greater than or equal to, so I will stay that one.
Moisés Man
@moigithub
Mar 01 2016 04:03
indexOf pick the first item it finds.. n return its index
Stephanie
@spogburn
Mar 01 2016 04:04
ok @bitgrower I am not totally sure I get it, but I will try to think about that
bitgrower
@bitgrower
Mar 01 2016 04:04
position = sumArray.indexOf(largest) .... well ... @moitgithub -- in this instance, but he could prime it ...
Johnathon Sykes
@seesykescode
Mar 01 2016 04:04
can I ask about jquery here?
Moisés Man
@moigithub
Mar 01 2016 04:04
but it is never assigned to the last one it is also equal to, which I don't understand
bitgrower
@bitgrower
Mar 01 2016 04:04
I believe indexOf also takes parameter where you start searching ...
@spogburn ... don't use indexOf ... just save the position off ... just save k
to position ...
Moisés Man
@moigithub
Mar 01 2016 04:05
if u want the last index (searching the same element, u got two 69 )
u can use lastIndexOf()
Stephanie
@spogburn
Mar 01 2016 04:06
I can't guarantee that 69 will be the last one
I want the last largest number. It could be the fifth number, it could be the 25th number @moigithub
the array is just an example
and I don't want to sort it, because position matters
Moisés Man
@moigithub
Mar 01 2016 04:06
well.. ur current code IS extracting the largest
Stephanie
@spogburn
Mar 01 2016 04:07
not the LAST largest
and I know that, because of logging the position
Moisés Man
@moigithub
Mar 01 2016 04:07
u no need position variable at all.. u already storing ur largest num on "largest" variable
bitgrower
@bitgrower
Mar 01 2016 04:07
oooh ... i like that, @moitgithub ...
the lastIndexOf
Stephanie
@spogburn
Mar 01 2016 04:08
right, but in the bigger picture, I actually just need to know the position of the last largest number in the array. I don't care what the number is or anything. I care where it is.
bitgrower
@bitgrower
Mar 01 2016 04:08
I do recall passing it by one day ... but didn't think a lot about it ...
Donald
@codescout811
Mar 01 2016 04:09
can anyone help me in Convert Celsius to Fahrenheit.
bitgrower
@bitgrower
Mar 01 2016 04:09
@spogburn ... go back and read what I said ... don't use indexOf at all ... just use this code ... position =k;
Stephanie
@spogburn
Mar 01 2016 04:09
position = k, ok @bitgrower
yoni chanowitz
@yonichanowitz
Mar 01 2016 04:09
DESPERATELY NEED HELP!!!
Stephanie
@spogburn
Mar 01 2016 04:09
Thanks
yoni chanowitz
@yonichanowitz
Mar 01 2016 04:10
in Seekand Destroy,
why ismy code not working??!!??
function destroyer(arr) {
  // Remove all the values
  var a = [];
 for(var i  = 0 ; i < arguments.length  ; i++){
   a.push(arguments[i +1]);
 }
  function b(ary){
    for (var i = 0; i < ary.length; i++){
      for(var j = 0; j < a.length; j++ ){
    if(ary[i] !== a[j]) {return ary[i];
        }
      }
     }
   }return arr.filter(b);
}

destroyer([3, 5, 1, 2, 2], 2, 3, 5);
bitgrower
@bitgrower
Mar 01 2016 04:10
you are welcome ... now ... truly thank me by making sure you understand it ... pythontutor.com/javascript.html can help you ...
Eric
@eti313
Mar 01 2016 04:10
@codescout811 I'll give it a try
Catalin Scripcariu
@CatalinScr
Mar 01 2016 04:10
help Validate US Telephone Numbers
CamperBot
@camperbot
Mar 01 2016 04:10

:point_right: algorithm validate us telephone numbers [wiki]

Problem Explanation:

  • The task is not that hard to understand, implementing it is the hardest part. You have a to validate an US phone number. This means there is a certain amount of numbers required, while you don't need to put the country code, you will still need the area code and use one of the few formats allowed.
:pencil: read more about algorithm validate us telephone numbers on the FCC Wiki
Stephanie
@spogburn
Mar 01 2016 04:10
oh sweet @bitgrower I think I'm getting it now
Eric
@eti313
Mar 01 2016 04:10
The algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32.
bitgrower
@bitgrower
Mar 01 2016 04:11
@spogburn ... sweet, simple, direct
@eti313 ... go to google and type convert celsius to Fahrenheit ... :)
Eric
@eti313
Mar 01 2016 04:13
@codescout811 The algorithm to convert from Celsius to Fahrenheit is the temperature in Celsius times 9/5, plus 32.
@bitgrower was helping codescout811
bitgrower
@bitgrower
Mar 01 2016 04:14
ahhhh ... okay .. many apologies ...
Eric
@eti313
Mar 01 2016 04:14
s'alright
Moisés Man
@moigithub
Mar 01 2016 04:14
@yonichanowitz
what this code does ?
 var a = [];
for(var i  = 0 ; i < arguments.length  ; i++){
   a.push(arguments[i +1]);
 }
Donald
@codescout811
Mar 01 2016 04:15
@eti313 I can't figure out how to start...
Eric
@eti313
Mar 01 2016 04:16
@codescout811 you've got the celsius variable, right?
Donald
@codescout811
Mar 01 2016 04:16
convert(-30) should return a value of -22
convert(-10) should return a value of 14
convert(0) should return a value of 32
convert(20) should return a value of 68
convert(30) should return a value of 86
Marek Slabicki
@thaniri
Mar 01 2016 04:16

having trouble with the everything be true challenge:

function every(collection, pre) {

  var booleanHolder = true; //in place of having return values in the loop

  for(var i = 0; i < collection.length; i++){
    if(collection[i].hasOwnProperty(pre) !== null){ //if collection[i] has the property: sex != null set true
      booleanHolder = true;
    }
    else if(!collection[i].hasOwnProperty(pre)){ //if collection[i] doesn't have a property: sex set false
      booleanHolder = false;
    } 
  }
  return booleanHolder;


}

every([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");

When I test this, the program thinks that every object within the array has the property given in arguments[1] however collection[1] does not have the property sex. I'm using a variable to hold the truth value because my code terminates if I have a return statement within the loop.
The challenge is obviously not complete yet

basically my question is, why on the second iteration of the loop, does it think that Dipsy has a sex
when the object has no sex property
Eric
@eti313
Mar 01 2016 04:17
@codescout811 they already gave you
function convert(celsius) {
Moisés Man
@moigithub
Mar 01 2016 04:17
@thaniri hasOwnProperty method return a boolean value (true or false) so it will never be null
Eric
@eti313
Mar 01 2016 04:18
@codescout811 so the celsius variable is the temperature in celsius (-30, -10, etc)
Marek Slabicki
@thaniri
Mar 01 2016 04:19
okay, fixed that bit
Eric
@eti313
Mar 01 2016 04:19
@codescout811 with me so far?
Marek Slabicki
@thaniri
Mar 01 2016 04:19
but the program still thinks dipsy has a sex
Moisés Man
@moigithub
Mar 01 2016 04:20
@thaniri because on every iteration it does.. it replace the value of "booleanHolder" variable...
so when its "Dispy" turn.. it becomes false... but on next iteration.. "Laa-Laa" turn... u replacing booleanHolder to true.. n so on
at the end.. only the last "collectoin element" will stay on "booleanHolder"
Marek Slabicki
@thaniri
Mar 01 2016 04:21
ahh im so dumb lol >>
thanks @moigithub
CamperBot
@camperbot
Mar 01 2016 04:21
thaniri sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 692 | @moigithub | http://www.freecodecamp.com/moigithub
Moisés Man
@moigithub
Mar 01 2016 04:21
soooo in this case.. probably returning earlier.. will help
Donald
@codescout811
Mar 01 2016 04:22
@eti313 I'm working on it....organizing my thoughts...thanks.
CamperBot
@camperbot
Mar 01 2016 04:22
codescout811 sends brownie points to @eti313 :sparkles: :thumbsup: :sparkles:
:star: 281 | @eti313 | http://www.freecodecamp.com/eti313
Eric
@eti313
Mar 01 2016 04:22
@codescout811 welcome!
and i'm out
yoni chanowitz
@yonichanowitz
Mar 01 2016 04:28
i will pay someone to help me
please
Robert Richey
@0x0936
Mar 01 2016 04:28
would anyone have any idea why a variable's typeof would be number, but when logged is NaN?
yoni chanowitz
@yonichanowitz
Mar 01 2016 04:28
anyone
Robert Richey
@0x0936
Mar 01 2016 04:29
progressBarWidth += step * delta    
console.log(typeof(step), typeof(delta), typeof(progressBarWidth), progressBarWidth) // number number number NaN
James Beem
@beem812
Mar 01 2016 04:31
what's the deal with this madlibs question, they don't explain what the expected end result is at all
read the top comment
Thomas Mullen
@t-mullen
Mar 01 2016 04:36
@beem812 The result just needs to be in the order that makes grammatical sense
Robert Richey
@0x0936
Mar 01 2016 04:38
@thaniri thanks - that article helped me to figure out the problem :+1: :)
CamperBot
@camperbot
Mar 01 2016 04:38
0x0936 sends brownie points to @thaniri :sparkles: :thumbsup: :sparkles:
:star: 180 | @thaniri | http://www.freecodecamp.com/thaniri
Marek Slabicki
@thaniri
Mar 01 2016 04:41

sorry to bother again about the everything be true challenge:

function every(collection, pre) {

  var booleanHolder = true;

  for(var i = 0; i < collection.length; i++){
    if(!collection[i].hasOwnProperty(pre)){
      booleanHolder =  false;
      break;
    }
    else if(collection[i][pre] === 0){
      booleanHolder = false;
      break;
    }
    else if(collection[i][pre] === null){
      booleanHolder = false;
      break;
    }
    else if(collection[i][pre] === ""){
      booleanHolder = false;
      break;
    }
    else if(collection[i][pre] === undefined){
      booleanHolder = false;
      break;
    }
    else if(collection[i][pre] === NaN){ // how do I deal with NaN?
      booleanHolder = false;
      break;
    }
  }
  return booleanHolder;


}

every([{"single": ""}, {"single": "double"}], "single");

In this example, I can't use any comparison operators with NaN, how can i deal with NaN in this case?

if I try:

 else if(isNaN(collection[i][pre])){
      booleanHolder = false;
      break;
    }

then in the case that (pre) is a string, that solution breaks

Is there a way for me to do isNaN(thenumber) && pre != aString?

Nick Robson
@nickrobson
Mar 01 2016 04:46
@thaniri Remember, you can use !val which will be true when val is falsey.
Marek Slabicki
@thaniri
Mar 01 2016 04:47
if I do !isNaN(val) i'll run into the exact same issue
Brian van Vlymen
@arduino731
Mar 01 2016 04:48
is looking ok in javascript
 else if( card == 10 || "J" || "Q" || "K" || "A" ){
    count -= count + -1;
    return count + " Hold"; 
  }
Robert Richey
@0x0936
Mar 01 2016 04:49
@thaniri for that algo, I implemented the following pseudo code
for every object in collection
  get object's keys and check if pre is in keys and that object[pre] is truthy
bitgrower
@bitgrower
Mar 01 2016 04:50
@arduino731 -- you can't do an or statement that way ...
Brian van Vlymen
@arduino731
Mar 01 2016 04:50
or
```
else if( card == 10 || card == "J" || card == "Q" || card == "K" ||card == "A" ){
count -= count + -1;
return count + " Hold";
}
Marek Slabicki
@thaniri
Mar 01 2016 04:50
second example syntax was better
bitgrower
@bitgrower
Mar 01 2016 04:50
yep!!!
and better yet ... use ===
Marek Slabicki
@thaniri
Mar 01 2016 04:51
i've looked at a couple of examples like that @0x0936, there was even a basic algorithm with the same issue im running into but it looks like witchcraft to me, I want to know how to check the truthiness of NaN if it's even possible
bitgrower
@bitgrower
Mar 01 2016 04:52
@thaniri -- try either eloquent js or you don't know javascript ...
well, if anyone is ever wondering
bitgrower
@bitgrower
Mar 01 2016 04:53

let's see ... I guess you could say ...

if ( typeof myVar === number && myVar !== myVar )

Robert Richey
@0x0936
Mar 01 2016 04:53
@thaniri that's fair, but if you change your mind and want to come over to the dark side, the three methods I used in my solution are .every(), .keys(), and .indexOf()
Marek Slabicki
@thaniri
Mar 01 2016 04:53
the syntax to make sure isNaN() only compares to numbers, is Number.isNaN();
bitgrower
@bitgrower
Mar 01 2016 04:54
hmm ...
Michael Poutre
@M1kep
Mar 01 2016 04:54
QUick question guys
Brian van Vlymen
@arduino731
Mar 01 2016 04:54

not sure wont pass the challenges on basic javascript its called counting cards http://www.freecodecamp.com/challenges/counting-cards
```
var count = 0;

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

// return "Change Me";
// 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');

Marek Slabicki
@thaniri
Mar 01 2016 04:54
here's the complete solution if anyone wants to look at it: http://www.freecodecamp.com/challenges/everything-be-true#?solution=function%20every(collection%2C%20pre)%20%7B%0A%20%20%0A%20%20var%20booleanHolder%20%3D%20true%3B%0A%20%20%0A%20%20for(var%20i%20%3D%200%3B%20i%20%3C%20collection.length%3B%20i%2B%2B)%7B%0A%20%20%20%20if(!collection%5Bi%5D.hasOwnProperty(pre))%7B%0A%20%20%20%20%20%20booleanHolder%20%3D%20%20false%3B%0A%20%20%20%20%20%20break%3B%0A%20%20%20%20%7D%0A%20%20%20%20else%20if(collection%5Bi%5D%5Bpre%5D%20%3D%3D%3D%200)%7B%0A%20%20%20%20%20%20booleanHolder%20%3D%20false%3B%0A%20%20%20%20%20%20break%3B%0A%20%20%20%20%7D%0A%20%20%20%20else%20if(collection%5Bi%5D%5Bpre%5D%20%3D%3D%3D%20null)%7B%0A%20%20%20%20%20%20booleanHolder%20%3D%20false%3B%0A%20%20%20%20%20%20break%3B%0A%20%20%20%20%7D%0A%20%20%20%20else%20if(collection%5Bi%5D%5Bpre%5D%20%3D%3D%3D%20%22%22)%7B%0A%20%20%20%20%20%20booleanHolder%20%3D%20false%3B%0A%20%20%20%20%20%20break%3B%0A%20%20%20%20%7D%0A%20%20%20%20else%20if(collection%5Bi%5D%5Bpre%5D%20%3D%3D%3D%20undefined)%7B%0A%20%20%20%20%20%20booleanHolder%20%3D%20false%3B%0A%20%20%20%20%20%20break%3B%0A%20%20%20%20%7D%0A%20%20%20%20else%20if(Number.isNaN(collection%5Bi%5D%5Bpre%5D))%7B%0A%20%20%20%20%20%20booleanHolder%20%3D%20false%3B%0A%20%20%20%20%20%20break%3B%0A%20%20%20%20%7D%0A%20%20%7D%0A%20%20return%20booleanHolder%3B%0A%0A%20%20%0A%7D%0A%0Aevery(%5B%7B%22single%22%3A%20%22%22%7D%2C%20%7B%22single%22%3A%20%22double%22%7D%5D%2C%20%22single%22)%3B%0A
bitgrower
@bitgrower
Mar 01 2016 04:54
which challenge are you discussing @thaniri, @0x0936 ?
Marek Slabicki
@thaniri
Mar 01 2016 04:55
click the link @bitgrower
bitgrower
@bitgrower
Mar 01 2016 04:55
LOL ...we were typing simultaneously ...
Marek Slabicki
@thaniri
Mar 01 2016 04:57
oh god my code solves it in 33 steps, and 0x0936's solves it in 19...
Robert Richey
@0x0936
Mar 01 2016 04:59
19? my solution is 4 lines inside the every function
Michael Poutre
@M1kep
Mar 01 2016 04:59
What challenge?
Marek Slabicki
@thaniri
Mar 01 2016 04:59
yours takes 19 steps, mine 33
Robert Richey
@0x0936
Mar 01 2016 04:59
gotcha
Marek Slabicki
@thaniri
Mar 01 2016 05:00
my code will execute (a.length * 6) + 3 times
i think my math is off
in any case im a bad coder and should feel bad
:P
Robert Richey
@0x0936
Mar 01 2016 05:01
no, you're not and you shouldn't
I'm stuck on trying to update a progress bar over time - been failing hard for a couple hours now
Marek Slabicki
@thaniri
Mar 01 2016 05:04
whats it measuring the progress of?
bitgrower
@bitgrower
Mar 01 2016 05:06
@thaniri -- which test case ?
Marek Slabicki
@thaniri
Mar 01 2016 05:06
the first one
first provided one
every([{"user": "Tinky-Winky", "sex": "male"}, {"user": "Dipsy", "sex": "male"}, {"user": "Laa-Laa", "sex": "female"}, {"user": "Po", "sex": "female"}], "sex");
bitgrower
@bitgrower
Mar 01 2016 05:08
ah, the one in your link ... ?
mine's 7 ... :)
oh wait, tha'ts not the first one ...
that's the one in your link ...
for the first one, mine is 17 ...
bitgrower @bitgrower had a lightbulb moment .... .hasOwnProperty is to Objects similarly to indexOf is to Arrays ...
Robert Richey
@0x0936
Mar 01 2016 05:12

@thaniri time between ajax requests for a new random quote

http://codepen.io/RobertRichey/pen/VaYbNB?editors=1010

bitgrower
@bitgrower
Mar 01 2016 05:13

@arduino731 ... I think you got a case of operator madness on this line:

count -= count + -1;

you only need 1 operator here ... you've got ... 3?
Brian van Vlymen
@arduino731
Mar 01 2016 05:15
@bitgrower hmm
bitgrower
@bitgrower
Mar 01 2016 05:16
count += count + 0; <-- here you have 2 ... you only need 1 ...
in fact ... um....what's the point of adding 0 ?
Marek Slabicki
@thaniri
Mar 01 2016 05:18
@0x0936 i wouldnt try a progress bar at first
i'd make a css animation of a circle or something travelling across the div, make the length of this animation the time in seconds between ajax requests
then reset the animation as soon as the ajax request is complete
since you have the timer between ajax requests, but you dont account for the time of the reuqest itself
if ii got that working, THEN i'd try to make a progress bar animation
bitgrower
@bitgrower
Mar 01 2016 05:19
I think there are some jquery progress bars out there ...
@arduino731 -- you are also missing a part of the code requirements, which is to return the count number plus "Bet" or "Hold" depending on the value of count ...
Robert Richey
@0x0936
Mar 01 2016 05:23

@thaniri the progress bar doesn't start until the ajax has finished, the the progress bar is reset each time getQuote is called

// ... ajax above
.then(([ res ]) => {
  const { content } = res
  $('#target').html(content)
  frame = animationFrame()
})

but, your feedback is appreciated. It's probably time to go back to basics again and slowly build - making sure at each step the timing is correct

bitgrower
@bitgrower
Mar 01 2016 05:24
um ... color me dumb ... what is the .then syntax about ?
Michael Poutre
@M1kep
Mar 01 2016 05:24
OMG my code is geting horrendus
Robert Richey
@0x0936
Mar 01 2016 05:25
@bitgrower it's like doSomething().then(allDoneWithSomething, nowWhat?)
bitgrower
@bitgrower
Mar 01 2016 05:26
well @M1kep -- you can't make an omelette without breaking a few eggs ...
Michael Poutre
@M1kep
Mar 01 2016 05:26
Maybe someboyd here can see the issue, it never gets to the second array containing "b" it just does the a and then moves onto the next test case
var runs = 0;
var depth = 0;
function steamroller(arr) {
  newArray = [];
  runs++;
  depth++;
  if(runs > 100) {
    console.log("Breaking!");
    throw new Error("Something went badly wrong!");
  }
  console.log("Before for loop array at depth of: ", depth);
  console.log(arr);
  for(arrayIndex = 0; arrayIndex < arr.length; arrayIndex++) {
    console.log("Index: ", arrayIndex, "Of array: ");
    console.log(arr);
    console.log(arr[arrayIndex]);
    if(Array.isArray(arr[arrayIndex]) && arr.length !== 0) {
      console.log("^Is an array");

      console.log("CALLING STEAMROLLER AGAIN! At Depth " , depth + 1);
      newArray = newArray.concat(steamroller(arr[arrayIndex]));
    } else {
      newArray = newArray.concat(arr[arrayIndex]);
    }
  }
  console.log("EXITING STEAMROLLER! Of Depth", depth);
  return newArray;
}
console.log("CALLING STEAMROLLER FIRST TIME");
steamroller([[["a"]], [["b"]]]);
bitgrower @bitgrower feels like she's seen a greatly humbling piece of js stuff now ... ran into .then on a page comparing some ES6 syntax to CoffeeScript ... and I was WAY out of my depth on that one!
Michael Poutre
@M1kep
Mar 01 2016 05:27
Uhm I didnt say that @bitgrower
Micah
@michamata
Mar 01 2016 05:27

var myVar = 87;

// Only change code below this line
myVar = myVar ++;

David Bruskin
@kidimi
Mar 01 2016 05:27

var Bike = function() {

  // Only change code below this line.

    var gear;

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

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

};


var myBike = new Bike();
Micah
@michamata
Mar 01 2016 05:28
Any idea why my code is still 87 instead of 88?
David Bruskin
@kidimi
Mar 01 2016 05:28
"Modify the Bike constructor to have a private property called gear and two public methods called getGear and setGear to get and set that value."
Abhishek Kumar
@abhishekKumar1
Mar 01 2016 05:28
@michamata try myVar++ only
bitgrower
@bitgrower
Mar 01 2016 05:28
This message was deleted
Michael Poutre
@M1kep
Mar 01 2016 05:28
@michamata don't set myVar to myVar++
myVar++ Increments after it is evaluated
bitgrower
@bitgrower
Mar 01 2016 05:28
^^^^better answer
@M1kep -- the problem is is that you are resetting your newArray variable to [] each time, I think ...
Michael Poutre
@M1kep
Mar 01 2016 05:30
Well the newArray variable is reset in its own scope I belive
cause I recall steamroller
Cause it passes this test
steamroller([1, 2, [3, [[4]]]])
bitgrower
@bitgrower
Mar 01 2016 05:31
ahhh ... okay ...
Michael Poutre
@M1kep
Mar 01 2016 05:31
I got it to pass the excercise but I didnt feel complete cause I just hardcoded the depth
I want it to work on any depth
Robert Richey
@0x0936
Mar 01 2016 05:32
@thaniri o.m.g. thanks again. turns out my setTimeout was outside the ajax call. I still have another issue to deal with, but fixing this part now has the progress bar starting correctly
CamperBot
@camperbot
Mar 01 2016 05:32
0x0936 sends brownie points to @thaniri :sparkles: :thumbsup: :sparkles:
:warning: 0x0936 already gave thaniri points
bitgrower
@bitgrower
Mar 01 2016 05:32
so ... how do you exit your recursion ?
my understanding of recursion is ... you need to check for exiting the recursion loop before you do any recalls of your function ... otherwise you'll end up in an infinite loop
anthonygallina1
@anthonygallina1
Mar 01 2016 05:35
Make Object Properties Private
---------------------------------

/*var Car = function() {
  // this is a private variable
  var speed = 10;

  // these are public methods
  this.accelerate = function(change) {
    speed += change;
  };

  this.decelerate = function() {
    speed -= 5;
  };

  this.getSpeed = function() {
    return speed;
  };
};
*/
var Bike = function() {
 // this is a private variable
  var gear = 4;

  // these are public methods

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

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

//var myCar = new Car();

var myBike = new Bike();
myBike.setGear(2);
How do I get the commented out code to run?
Michael Poutre
@M1kep
Mar 01 2016 05:36
@bitgrower when this isnt true:
if(Array.isArray(arr[arrayIndex]) && arr.length !== 0)
it doesnt recall t5he function
Currently test three is crashing itm but i'm more worried about the first test not working
bitgrower
@bitgrower
Mar 01 2016 05:36
okay ....
Michael Poutre
@M1kep
Mar 01 2016 05:37
is for
ttrhats what the if(runs > 100) {
console.log("Breaking!");
throw new Error("Something went badly wrong!");
}
bitgrower
@bitgrower
Mar 01 2016 05:37
oh, I thought that was the 1st case that you had working ... :)
Michael Poutre
@M1kep
Mar 01 2016 05:37
oh no no
bitgrower
@bitgrower
Mar 01 2016 05:37
or is it you have it working, but you hard-coded the depth ?
Michael Poutre
@M1kep
Mar 01 2016 05:37
My first working case is steamroller1
uno momento
var runs = 0;
var depth = 0;
function steamroller1(arr) {
  newArray = [];
  for(x = 0; x < arr.length; x++) {
    if(Array.isArray(arr[x])) {
      for(y = 0; y < arr[x].length; y++) {
        if(Array.isArray(arr[x][y])) {
          for(z = 0; z < arr[x][y].length; z++) {
           newArray = newArray.concat(arr[x][y][z]);
          }
        } else {
          newArray = newArray.concat(arr[x][y]);
        }
      }
    } else {
      newArray = newArray.concat(arr[x]);
    }
  }
  return newArray;
}
function steamroller(arr) {
  newArray = [];
  runs++;
  depth++;
  length = arr.length;
  if(runs > 100) {
    console.log("Breaking!");
    throw new Error("Something went badly wrong!");
  }
  console.log("Before for loop array at depth of: ", depth);
  console.log(arr);
  for(arrayIndex = 0; arrayIndex < length; arrayIndex++) {
    console.log("arrayIndex", "length");
    console.log(arrayIndex, length);
    console.log("Index: ", arrayIndex, "Of array: ");
    console.log(arr);
    console.log(arr[arrayIndex]);
    if(Array.isArray(arr[arrayIndex]) && arr.length !== 0) {
      console.log("^Is an array");

      console.log("CALLING STEAMROLLER AGAIN! At Depth " , depth + 1);
      newArray = newArray.concat(steamroller(arr[arrayIndex]));
    } else {
      newArray = newArray.concat(arr[arrayIndex]);
    }
  }
  console.log("EXITING STEAMROLLER! Of Depth", depth);
  depth--;
  return newArray;
}
console.log("CALLING STEAMROLLER FIRST TIME");
steamroller([[["a"]], [["b"]]]);
steamroller1
is the working version
only works up to 3 or 4 deep or whatever was needed to pass the tests
@anthonygallina1 remove the
*/
two of them
yoni chanowitz
@yonichanowitz
Mar 01 2016 05:39
thanks @Rafase282
CamperBot
@camperbot
Mar 01 2016 05:39
yonichanowitz sends brownie points to @rafase282 :sparkles: :thumbsup: :sparkles:
:star: 1026 | @rafase282 | http://www.freecodecamp.com/rafase282
anthonygallina1
@anthonygallina1
Mar 01 2016 05:40
@M1kep :) yes but on that tut page how do I get the code to run, doesnt seems too. I did the comments myself while trying to de bug
bitgrower
@bitgrower
Mar 01 2016 05:40
okay ... your if statement is going to be false and recurse if EITHER Array.isArray is false or arr.length !== 0 ... this seems a bit tricky for the exit condition ...
anthonygallina1
@anthonygallina1
Mar 01 2016 05:41
thank you @M1kep
CamperBot
@camperbot
Mar 01 2016 05:41
anthonygallina1 sends brownie points to @m1kep :sparkles: :thumbsup: :sparkles:
:star: 310 | @m1kep | http://www.freecodecamp.com/m1kep
bitgrower
@bitgrower
Mar 01 2016 05:41
y'all are gettin' too smart ... :)
Michael Poutre
@M1kep
Mar 01 2016 05:41
@anthonygallina1 ahhh lol, whats the link to the page? Or is on fcc? If the latter then whats the challeng name
anthonygallina1
@anthonygallina1
Mar 01 2016 05:42
@M1kep Make Object Properties Private
Michael Poutre
@M1kep
Mar 01 2016 05:43
And what exactly is the issue?
anthonygallina1
@anthonygallina1
Mar 01 2016 05:44
@M1kep well the example code should run as it is a working example?
@M1kep Was wondering how to get the FCC code to run on that page.
Robert Richey
@0x0936
Mar 01 2016 05:46
:dog:
Michael Poutre
@M1kep
Mar 01 2016 05:46
So I uncommentd it all(Except the real commesnts) and it still runs... Ohhhh so you uncomment the three comments, and if you want to use there functions they'd work
The code you linked me to passes
anthonygallina1
@anthonygallina1
Mar 01 2016 05:47
@M1kep comment out my code and try it
@M1kep thought maybe I was doing some thing wrong
Michael Poutre
@M1kep
Mar 01 2016 05:49
Ahhh so you want to see the output on the left of the FCC Code?
Or some sort of visual indicator?
anthonygallina1
@anthonygallina1
Mar 01 2016 05:50
Yes was having a hard time understanding the example Just scraped that and wrote my own But is it a working example in the terminal?
Michael Poutre
@M1kep
Mar 01 2016 05:53
Ya, so the example they provide works, if you wanted to use/see what it doesn you'd need to do soemthing like.....
anthonygallina1
@anthonygallina1
Mar 01 2016 05:54
@M1kep Thank you very very much :)
CamperBot
@camperbot
Mar 01 2016 05:54
anthonygallina1 sends brownie points to @m1kep :sparkles: :thumbsup: :sparkles:
:warning: anthonygallina1 already gave m1kep points
Michael Poutre
@M1kep
Mar 01 2016 05:55
No problemo :D FCC's "console" output is kinda wierd
bitgrower
@bitgrower
Mar 01 2016 06:04
@M1kep -- if your "item" is no longer an Array, shouldn't you be pushing the item onto NewArrray ?
Michael Poutre
@M1kep
Mar 01 2016 06:05
The else branch concats it with the "newArray"
Robert Richey
@0x0936
Mar 01 2016 06:05
a real frustrating thing I learned about Bootstrap's progress bar, is that it has a 0.6s transition effect. not a big deal unless that progress bar is meant to keep resetting with each cycle. transition: none; will save you some trouble.
bitgrower
@bitgrower
Mar 01 2016 06:08
but concat is for concatenating two arrays together, I thought ... hmmmm ...
Tony
@Rogers187
Mar 01 2016 06:08
So can I ask the guys or gals that have been doing this for awhile a question. So I'm a noob and have never done this type of work before. Can anyone tell me what would be the best way for me to get a career in the field?
Just would like an idea of where to start....
bitgrower
@bitgrower
Mar 01 2016 06:10
be passionate about code would help ... be a team player ... be good at what you do ... be reliable ....
Sumeet Batheja
@bathejasumeet
Mar 01 2016 06:11
@Rogers187 , there are a lot of things you can build your career in this field, what are you interested in doing in this field?
bitgrower
@bitgrower
Mar 01 2016 06:12
okay ... had to review .concat, @M1kep ... thanks !
CamperBot
@camperbot
Mar 01 2016 06:12
bitgrower sends brownie points to @m1kep :sparkles: :thumbsup: :sparkles:
:star: 311 | @m1kep | http://www.freecodecamp.com/m1kep
bitgrower
@bitgrower
Mar 01 2016 06:13

I could be mistaken ... but I think you may be having problems with the length variable ... because things are changing size ? I know I had trouble with that on one challenge ...

and I see you are grabbing the value at each iteration ... so it's relatively static ....

Tony
@Rogers187
Mar 01 2016 06:14
@bathejasumeet I'm not really set on one thing. But web design or something. Just not sure how I could get paid. Cause I have NO experience at all. FCC is the only thing I've done. So it's not like I can walk in some where and get a job.
bitgrower
@bitgrower
Mar 01 2016 06:15
@Rogers187 -- that's one of the reasons why FCC has you do projects ...
...so you have a portfolio ...
Michael Poutre
@M1kep
Mar 01 2016 06:15
@bitgrower i've about given up on this lol, i've got ir passing but this is strarint to annoy me again. I think its the arrayIndex variable isnt local
Sumeet Batheja
@bathejasumeet
Mar 01 2016 06:16
@Rogers187 be underpaid and do work, but start early so that you can fail fast and realize what you don't want to do
Tony
@Rogers187
Mar 01 2016 06:16
@bitgrower and I get that. So are there places out there that take chances on such little work??
bitgrower
@bitgrower
Mar 01 2016 06:16
uhhhhh .... maybe nonprofits ?
Sumeet Batheja
@bathejasumeet
Mar 01 2016 06:16
@Rogers187 startups hire people who are willing to work at less pay
you will get more exposure to different kinds of work at startups than at nonprofits
bitgrower
@bitgrower
Mar 01 2016 06:17
let me say something about job hunting ... if you view yourseslf as a commodity, so will potential employers ... you need to be able to have the confidence to show that you can solve problems ...
..to stand out ...
...something that sets you apart ...
Sumeet Batheja
@bathejasumeet
Mar 01 2016 06:18
@bitgrower . I agree on this one
bitgrower
@bitgrower
Mar 01 2016 06:19
and.... be clear ... very few programming jobs are 9-5 ...
Tony
@Rogers187
Mar 01 2016 06:19
@bitgrower That is one thing I do have going for me I don't like to fail.
bitgrower
@bitgrower
Mar 01 2016 06:20
how are you finding the challenges, @Rogers187 ... ?
Tony
@Rogers187
Mar 01 2016 06:21
@bitgrower some I get real easy. But some of them I don't think they explain real well what they are asking use to do. But I can search and find what they are wanting. Just takes me a little longer.
bitgrower
@bitgrower
Mar 01 2016 06:22
okay ... so ... do you find that ... frustrating ... infuriating ... fun ... ?
Tony
@Rogers187
Mar 01 2016 06:23
@bitgrower ummm some times it's frustrating then I get it then I get excited.
bitgrower
@bitgrower
Mar 01 2016 06:24
I guess what I'm trying to get at is ... if you never got paid a dime for programming, would you do it at all ?
Tony
@Rogers187
Mar 01 2016 06:26
Oh yeah
i think this is the first time I've ever got off work and went home and instead of turning on the tv. I turn on my laptop and start coding.
bitgrower
@bitgrower
Mar 01 2016 06:28
...LOL cool ... and discovered you didn't quite get as much sleep as you should have because you were coding ?
there are no end of places where software skills are needed ... and that's only going to get bigger over time ...
Robert Richey
@0x0936
Mar 01 2016 06:29

@thaniri I wanted to show you the finished project - you were a big help, and I appreciate it. thanks!

http://codepen.io/RobertRichey/pen/VaYbNB

CamperBot
@camperbot
Mar 01 2016 06:29
0x0936 sends brownie points to @thaniri :sparkles: :thumbsup: :sparkles:
:star: 182 | @thaniri | http://www.freecodecamp.com/thaniri
bitgrower
@bitgrower
Mar 01 2016 06:30
I am so tickled to know you guys ... :)
very cool, @0x0936 ...
love the animations ...
bitgrower @bitgrower is a wee bit jealous ... :)
Charles Chung
@chulmo
Mar 01 2016 06:31
Can anyone recommend a good way to preload .wav files so they play instantly without delay when triggered?
Robert Richey
@0x0936
Mar 01 2016 06:31
@bitgrower thanks :+1: :)
CamperBot
@camperbot
Mar 01 2016 06:31
0x0936 sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 676 | @bitgrower | http://www.freecodecamp.com/bitgrower
Tony
@Rogers187
Mar 01 2016 06:32
@bitgrower lol well let's put it this way. I have to be at work at 3pm and I live an hour from my job. I didn't get to bed last night till 10am cause I wasn't paying attention to the clock.
bitgrower
@bitgrower
Mar 01 2016 06:32
is that from the design quotes site ?
Robert Richey
@0x0936
Mar 01 2016 06:33
yep
bitgrower
@bitgrower
Mar 01 2016 06:36

@Rogers187 -- get competence, show value, be reliable, personable ... like @bathejasumeet -- there are a lot of different kinds of software jobs ...

...when it comes to jobs, there are so many ways of attacking getting jobs ... that if you strategically decide on a job you want ... there's probably a way for you to get it ... unless you have something that doesn't clear in a background check ...

a co-worker of mine used to regularly apply for, and GET jobs he had no background in ... but when he got the interview ... he would go buy EVERY book (this is kinda pre-web) on the topic that pertained to the job he was interviewing for ... and he got a lot of those jobs ....
the problem of the person hiring someone to do a job is ... a lot of the people who come thru are "looking for "a" job" ... but if you can show that the job you are interviewing for is YOUR dream job ... you'll stand out ... :)
Tony
@Rogers187
Mar 01 2016 06:40
@bitgrower wow ok. Are there any resources u could point me to that u like. That YouTube pages to watch web sites to read any thing? And I don't always have to use codePen to build do I?
bitgrower
@bitgrower
Mar 01 2016 06:40
and there are sooo many resources available on the web about finding out about companies and what it's like to work there, etc ... show a real interest in the company, their mission and what they do ... you'll stand out ...
Tony
@Rogers187
Mar 01 2016 06:43
@bitgrower I mean to be better at coding...
Michael Poutre
@M1kep
Mar 01 2016 06:44
F*** it, I'm done with this stupid challenge.
bitgrower
@bitgrower
Mar 01 2016 06:44
let me think about it , @Rogers187 .. it's kind gettin' to be my bed time and I was sick over the weekend ...
@M1kep -- I'm sorry .... :(
They are kind of old ... but I love the books by Jon Bentley ... which were complilations of his columns in the Journal Of the Association for Computing Machinery (JACM) ... Programming Pearls, Writing Efficient Programs ...
I'm not sure what's as popular among the software folks ... but I'd learn something about agile project management ...
for javascript itself ... there are some great resources on this list ...
help js resources
Tony
@Rogers187
Mar 01 2016 06:49
@M1kep thanks @bitgrower thank you too
CamperBot
@camperbot
Mar 01 2016 06:49
rogers187 sends brownie points to @m1kep and @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 677 | @bitgrower | http://www.freecodecamp.com/bitgrower
:star: 312 | @m1kep | http://www.freecodecamp.com/m1kep
bitgrower
@bitgrower
Mar 01 2016 06:49
there's some interesting comments by the author of "Learn Python the Hard Way" ... about programmers being nothing special ... but then he also contradictorily talks about how programmers are special ...
Tony
@Rogers187
Mar 01 2016 06:49
Lol
bitgrower
@bitgrower
Mar 01 2016 06:49
find some of the leaders in the particular area you are interested in and read them
CamperBot
@camperbot
Mar 01 2016 06:49
find some of the leaders in the particular area you are interested in and read them
nothing found
bitgrower
@bitgrower
Mar 01 2016 06:50
learn python the hard way is free on the web ... btw ...
I think the comments are like at the beginning of the course and then at the end ...
Tony
@Rogers187
Mar 01 2016 06:50
Ok will look into that
bitgrower
@bitgrower
Mar 01 2016 06:50
but there are some salient comments about you being able to do things others will consider magic ...
...but hang on ... w/ Obama's "everybody code" initiative ... you may have whatever is the gen that follows millenials nipping at your feet ... :) :) :)
...but, could also open the doors for a lot more teachers of code, too ... :)
find conferences of groups that interest you -- so many conferences put their stuff up online for free ...
CamperBot
@camperbot
Mar 01 2016 06:52
find conferences of groups that interest you -- so many conferences put their stuff up online for free
nothing found
bitgrower
@bitgrower
Mar 01 2016 06:52
google i/o, f8, WordCamp, defcon ... list goes on and on ...
Tony
@Rogers187
Mar 01 2016 06:54
Big help. Get to feeling better
bitgrower
@bitgrower
Mar 01 2016 06:54
oh, and, btw -- for js -- I like this --> Udemy - Javascript Understanding the Weird Parts (first 3.5 hrs) ... I bought the udemy course (look around udemy is always having $10 coupons, so you can get the course for $10) ...
didn't care much for the functional programming thing ... but I need to try it again ... LOL ...
thank you, @Rogers187 ...
CamperBot
@camperbot
Mar 01 2016 06:55
bitgrower sends brownie points to @rogers187 :sparkles: :thumbsup: :sparkles:
:star: 256 | @rogers187 | http://www.freecodecamp.com/rogers187
bitgrower
@bitgrower
Mar 01 2016 06:55
have a good evening ...
Tony
@Rogers187
Mar 01 2016 06:55
You too
Marina
@chandra90
Mar 01 2016 06:57
Hello! Please help!
yoni chanowitz
@yonichanowitz
Mar 01 2016 06:57
@chandra90 we are here to help
Marina
@chandra90
Mar 01 2016 06:58
var processed = 2;
function process(num) {
}
The task "Assignment with a Returned Value". I can not do the second part of the task :"You should assign process to processed".
Marina
@chandra90
Mar 01 2016 07:03
@yonichanowitz :point_up: 1 Марта 2016 г., 09:58
yoni chanowitz
@yonichanowitz
Mar 01 2016 07:04
@chandra90 , you need to re-asign processed. declare it again after the function, and give it the value of the function with what you need
Marina
@chandra90
Mar 01 2016 07:04
@yonichanowitz emm can you explain it in code?
yoni chanowitz
@yonichanowitz
Mar 01 2016 07:05
var processed = processs(something);
but afterthe function
kirbyedy
@kirbyedy
Mar 01 2016 07:06
shouldn`t that be just a simple assign ?
and the sign for assign is =
yoni chanowitz
@yonichanowitz
Mar 01 2016 07:07

@chandra90 , you can write

var processed = "whatever";

and give it new values as many times as you want, and the last assignment will be the one that lasts

Marina
@chandra90
Mar 01 2016 07:08
@yonichanowitz but I have already written var processed = 2;
kirbyedy
@kirbyedy
Mar 01 2016 07:08
I dont think you need a variable here
just a simple assign
something = something else
yoni chanowitz
@yonichanowitz
Mar 01 2016 07:09
@chandra90 , exactly! now do it again AFTER the function, but this time with a function as a value
niharika77
@niharika77
Mar 01 2016 07:09
Encode the following sequence, separated by spaces:
backslash tab tab carriage-return new-line and assign it to myStr !!! what i need to do in this?? got stuck
yoni chanowitz
@yonichanowitz
Mar 01 2016 07:10
@chandra90 @kirbyedy is right, i just find it easier to understandwhen you use a new variable
Marina
@chandra90
Mar 01 2016 07:10
@niharika77 What task is it?
kirbyedy
@kirbyedy
Mar 01 2016 07:10
@niharika77 follow the table on the left in the description
yoni chanowitz
@yonichanowitz
Mar 01 2016 07:12
@niharika77 . backslash as a symbol is / its asking you for symbols
niharika77
@niharika77
Mar 01 2016 07:13
@kirbyedy escape sequences in tsrings
kirbyedy
@kirbyedy
Mar 01 2016 07:18
I know, and you have the table on the left in the description
so just follow whats asked, and type the symbols in one line, thats it
Marina
@chandra90
Mar 01 2016 07:27
@yonichanowitz THANKS!
CamperBot
@camperbot
Mar 01 2016 07:27
chandra90 sends brownie points to @yonichanowitz :sparkles: :thumbsup: :sparkles:
:star: 273 | @yonichanowitz | http://www.freecodecamp.com/yonichanowitz
ichirped
@ichirped
Mar 01 2016 07:35
@bitgrower can you see where I went wrong in this Pig Latin soln?
function translate(str) {
  var strArr = str.split('');
  var vowels = ['a', 'e', 'i', 'o', 'u'];

  for(var i=0; i<vowels.length; i++){
    if(strArr.indexOf(vowels[i]) === 0){
      strArr.push('way');
      break;
    }
    else if(strArr.indexOf(vowels[i]) > 0){
      var rem = strArr.splice(0, strArr.indexOf(vowels[i]));
      strArr.push(rem + 'ay');
      break;
    }
  }


  return strArr.join('');
}
I can't get this translate("glove") should return "oveglay". to pass
everythin else works
demipixel
@demipixel
Mar 01 2016 07:52
@ichirped Because unfortunately you have to check for all consonants before the first vowel
Luke Mroz
@lukemroz
Mar 01 2016 07:52
hey
demipixel
@demipixel
Mar 01 2016 07:52
aloha
Luke Mroz
@lukemroz
Mar 01 2016 07:52
Could use a little guidance
in the Where art Though exercise in intermediate scripting, we are supposed to use the Object.keys() method in trying to compare objects
Its not clear to me how to do that
Vadim Grigorov
@Chichavl
Mar 01 2016 07:54

Hi, I am stuck on Pairwise Bonfire, I cannot pass pairwise([0, 0, 0, 0, 1, 1], 1) should return 10 test case.
Here is my code

function pairwise(arr, arg) {
  var arrOfUsedIndexes = [];
  return arr.reduce(function(previousValue, currentValue, currentIndex, array) {
    // position of second 
    var position = arr.indexOf(arg - currentValue, currentIndex+1);
    if (arrOfUsedIndexes.indexOf(position) != -1) {
      var i = position + 1;
      while (arr.indexOf(arg - currentValue, i) != -1 || i < arr.length || arrOfUsedIndexes.indexOf(i) != -1){
        position = i;
        i += 1;
      }
    }


    if (position != -1 && arrOfUsedIndexes.indexOf(currentIndex) == -1) {
      arrOfUsedIndexes.push(position);
      return previousValue + currentIndex + position;
    }
    else {
      return previousValue + 0;
    }
  }, 0);
}

pairwise([0, 0, 0, 0, 1, 1], 1);

When I debug I see that arrOfUsedIndexes always empty, can anyone say why?

demipixel
@demipixel
Mar 01 2016 07:54
bf Where art
CamperBot
@camperbot
Mar 01 2016 07:54

:fire:Bonfire: Where art thou :link:

function where(collection, source) {
  var arr = [];
  // What's in a name?
  return arr;
}

where([{ first: 'Romeo', last: 'Montague' }, { first: 'Mercutio', last: null }, { first: 'Tybalt', last: 'Capulet' }], { last: 'Capulet' });

Make a function that looks through a list (first argument) and returns an array of all objects that have equivalent property values (second argument).

more info:  bf details | bf links | hint

demipixel
@demipixel
Mar 01 2016 07:54
@lukemroz Well do you know what Object.keys() does, let's start there
bf pairwise
CamperBot
@camperbot
Mar 01 2016 07:54

:fire:Bonfire: Pairwise :link:

function pairwise(arr, arg) {
  return arg;
}

pairwise([1,4,2,3,0,5], 7);

Return the sum of all indices of elements of 'arr' that can be paired with one other element to form a sum that equals the value in the second argument 'arg'. If multiple sums are possible, return the smallest sum. Once an element has been used, it cannot be reused to pair with another.

more info:  bf details | bf links | hint

Luke Mroz
@lukemroz
Mar 01 2016 07:55
the keys return the properties of the object
demipixel
@demipixel
Mar 01 2016 07:55
@Chichavl That should return 9 actually
@lukemroz The keys are the properties, those are interchangable words :P
Object.keys(obj) just gets an array of the keys
Luke Mroz
@lukemroz
Mar 01 2016 07:55
the keys method returns the properties
yup
demipixel
@demipixel
Mar 01 2016 07:55
Alright, so
Well, do you have any code so far? Have you tried explaining the problem in english words? Any ideas where to go? :P
Luke Mroz
@lukemroz
Mar 01 2016 07:56
i think my problem is im not using the loop correctly

var arr = [];
var keys = Object.keys(source);

for (keys in collection) {
if (collection.hasOwnProperty(source[keys])) {
arr.push(source[keys]);
}
console.log(arr);
return arr;

demipixel
@demipixel
Mar 01 2016 07:57
@lukemroz
help format
CamperBot
@camperbot
Mar 01 2016 07:57

: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

Luke Mroz
@lukemroz
Mar 01 2016 07:57
'''js
CamperBot
@camperbot
Mar 01 2016 07:57
:bulb: to format code use backticks! ``` more info
HaiderJaan
@HaiderJaan
Mar 01 2016 08:02

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

// Your code above this line
return result;
}

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

demipixel
@demipixel
Mar 01 2016 08:02
@HaiderJaan What's up?
alpox
@alpox
Mar 01 2016 08:03
@lukemroz yes you have problems there. You should declare a new variable for the key in the for - for(var key in collection.
Where btw. Do you think you declared the variable source?
HaiderJaan
@HaiderJaan
Mar 01 2016 08:06

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

// Your code above this line
return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");
<!-- why this code is not running -->

alpox
@alpox
Mar 01 2016 08:06
And you dont need to assign Object.keys first. You could use Object.keys() for retrieving the keys first for iterating though them the normal for(var i = 0; i < Object.keys(collection); i++) { way or you use the more recommended way you have chosen with
demipixel
@demipixel
Mar 01 2016 08:07
@HaiderJaan It is. Result is "" so it returns ""
alpox
@alpox
Mar 01 2016 08:07
for(var key in collection) which does basically nothing else than iterating through each key and assign it to the variable key
HaiderJaan
@HaiderJaan
Mar 01 2016 08:13
@demipixel i don't know what is it saying and what i have to do ?
Zach
@Moose1551
Mar 01 2016 08:13

Hello, all. Can anyone explain to me how I'm supposed to assign "process" to "processed"? I'm completely at a loss.

js```

// Example
var changed = 0;

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

changed = change(10);

// Setup
var processed = 0;

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

// Only change code below this line

processed+=2;
```

demipixel
@demipixel
Mar 01 2016 08:13
@HaiderJaan You have to attach each word to each other
example "dog big ran quickly"
HaiderJaan
@HaiderJaan
Mar 01 2016 08:16
demipixel and also store in some variable ???
demipixel
@demipixel
Mar 01 2016 08:16
Nope, just return it
Why the need for all the ? it seems like a lot of added work lol
alpox
@alpox
Mar 01 2016 08:18
@demipixel the questionmark is a lot of added work? O.o
Zach
@Moose1551
Mar 01 2016 08:19
// Example
var changed = 0;

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

changed = change(10);

// Setup
var processed = 0;

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

// Only change code below this line

processed+=2;
demipixel
@demipixel
Mar 01 2016 08:19
@alpox Yeah
Don't ????? you????? think???????
alpox
@alpox
Mar 01 2016 08:20
@demipixel there were only three that takes about half a second :-D
Zach
@Moose1551
Mar 01 2016 08:20
Any hints on how to assign "process" to "processed" on the above code?
alpox
@alpox
Mar 01 2016 08:21
@Moose1551 i dont know the challenge but assigning process to processed sounds bit wrong
@Moose1551 i guess you have to call process and assign its return value to process!
Zach
@Moose1551
Mar 01 2016 08:23
@alpox, yeah I'm pretty confused also. How do you call process?
like this?: "var process = processed;"
kirbyedy
@kirbyedy
Mar 01 2016 08:25
no need for var
alpox
@alpox
Mar 01 2016 08:25
@Moose1551 just above the line // Setup is an example ;-)
kirbyedy
@kirbyedy
Mar 01 2016 08:25
I think we have been through this
Zach
@Moose1551
Mar 01 2016 08:27
I figured as much. When the challenges say
"//Only change code below this line" is that supposed to be taken literal?
kirbyedy
@kirbyedy
Mar 01 2016 08:28
yes, than you change the code ONLY below that line
Zach
@Moose1551
Mar 01 2016 08:35
Got it.
// Example
var changed = 0;

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

changed = change(10);

// Setup
var processed = 0;

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

// Only change code below this line

var processed = 0;

function process(num) {
  return (num + 2) / 4.5;
}

processed = process(7);
Thanks, fellas.
Pedro Figueiredo
@pedronfigueiredo
Mar 01 2016 09:02
Hi, I am having problems with my Tic Tac Toe AI project… I think the code is a little bit too big and I find it hard to manage it… Can anyone help me get it back from the dead?
demipixel
@demipixel
Mar 01 2016 09:09
@pedronfigueiredo It's late so people might not be here, but before I go to bed, here are few tips:
  • Think about the problem in English. Type what you plan is going to happen and slowly convert it to code.
  • Lots of console.log()s. You'll need to test a lot to find out what variable(s) have unexpected values
  • Don't be afraid to google. If you don't know what a function does or how to do something in JS, google it :)
  • Split your program into functions. Then you can test individual functions to make sure they work as expected
    Good luck!
buuug7
@buuug7
Mar 01 2016 09:17
how to remove all non-alphanumeric characters in a string use String.replace();
alpox
@alpox
Mar 01 2016 09:21
@buuug7 Take a look at the MDN ressources for Regex expressions
buuug7
@buuug7
Mar 01 2016 09:25
@alpox no full understand
Dave Melia
@Dave-Melia
Mar 01 2016 09:29
Hey guys, quick question regarding switch statements
If I return a case, do I need to use break since it's absolete?
or is it good practice to leave it in?
Abhishek Kumar
@abhishekKumar1
Mar 01 2016 09:44
@Dave-Melia if you don't use break statement all the cases after the implied test case will also implement till compiler finds a break or the switch ends
Dave Melia
@Dave-Melia
Mar 01 2016 09:45
@abhishekKumar1 Not if you use a return statement it doesn't. Return will bring you out of the switch statement and out of the function all together
Abhishek Kumar
@abhishekKumar1
Mar 01 2016 09:45
if you are using return then it's ok
Dave Melia
@Dave-Melia
Mar 01 2016 09:46
My question was, should they be left in or not if they're never gonna run?
Abhishek Kumar
@abhishekKumar1
Mar 01 2016 09:46
you can leave them
but it is more appropriate to use return less number of times
Gabriel Dennis Parangan
@gparangan
Mar 01 2016 09:50
Hi guys. I need help on Return Early Pattern for Functions. I just don't get it what to modify
NonstopDRE
@NonstopDRE
Mar 01 2016 09:56
Hi guys I need help on Assignment with a returned Value
Dave Melia
@Dave-Melia
Mar 01 2016 09:56
@NonstopDRE What are you stuck with?
NonstopDRE
@NonstopDRE
Mar 01 2016 09:56
@Dave-Melia figuring out the solution
Dave Melia
@Dave-Melia
Mar 01 2016 09:57
@gparangan I'm on that one as we speak. Let me take a crack at it
Gabriel Dennis Parangan
@gparangan
Mar 01 2016 09:57
Still finding out as well I don't get it
Dave Melia
@Dave-Melia
Mar 01 2016 09:59
@NonstopDRE ahh it's easy
@NonstopDRE Essentially, you have a variable called processed which is initiated as 0
Rami
@RNwebdk
Mar 01 2016 10:00
Can someone please help, i'm stuck on the record Collection, it's updating the artist even though i'm telling it not to.
// Setup
var collection = {
    2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    2468: {
      album: "1999",
      artist: "Prince",
      tracks: [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    1245: {
      artist: "Robert Palmer",
      tracks: [ ]
    },
    5439: {
      album: "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

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

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

  return collection;
}

// Alter values below to test your code
update(2548, "artist", "");
Dave Melia
@Dave-Melia
Mar 01 2016 10:01
@NonstopDRE you need to assign the function process() to the variable
for example
var myVar = 0; <--- this is initilized
myVar = myFunc(x)
the function runs, returns the value, and assigns it to myVar
@gparangan It's easy, I just did it with an if statement if that helps?
sethnejame
@sethnejame
Mar 01 2016 10:05
Hey all
I'm on the counting cards lesson and a little stuck
Does it look like I'm heading in the right direction here?
var count = 0;

function cc(card) {
  // Only change code below this line
  var count = 0;

  switch(card) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count = count +1;
      break;
    case 7:
    case 8:
    case 9:
      count = count + 0;
      break;
    case 10:
    case "J":
    case "Q":
    case "K":
    case "A":
      count = count -1;
  }

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

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2, 3, 4, 5, 6);
Markus Kiili
@Masd925
Mar 01 2016 10:05
@RNwebdk The first if should check the parameters value and prop. Whether value is not empty and prop is not "tracks".
Dave Melia
@Dave-Melia
Mar 01 2016 10:05
@gparangan in pseudo-code ... if a is less than 0 or if b is less than 0 then return undefined
Rami
@RNwebdk
Mar 01 2016 10:09
@sethnejame remove the 7,8,9 from you switch
sethnejame
@sethnejame
Mar 01 2016 10:09
That makes sense
@RNwebdk however the cases won't add all the cards together :(
It will only do per card
Not a combination of them all
Rami
@RNwebdk
Mar 01 2016 10:11
thats what i was thinking when i was doing it, but it's not the case. You are only telling it to count up or down depending on the card, not adding thme together
sethnejame
@sethnejame
Mar 01 2016 10:12
@RNwebdk right. . .but they are supposed to be added together
wouldn't that be the count = count +1; then? or do i need to put it under every case per card
so it stacks
Rami
@RNwebdk
Mar 01 2016 10:14
no, your switch is okay now, if you removed the 7,8,9
Dave Melia
@Dave-Melia
Mar 01 2016 10:14
@gparangan You there?
Rami
@RNwebdk
Mar 01 2016 10:14
your if statements should look like this
 if(count <= 0){
    return count + " Hold";
  }
  else{
    return count + " Bet";
  }
sethnejame
@sethnejame
Mar 01 2016 10:15
@RNwebdk the following is supposed to return "5 Bet" but it's only returning "1 Bet"
var count = 0;

function cc(card) {
  // Only change code below this line
  var count = 0;

  switch(card) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count = count +1;
      break;
    case 10: