These are chat archives for FreeCodeCamp/HelpJavaScript

16th
Feb 2016
Norman Dela Cruz
@dcnr
Feb 16 2016 00:02
@BLayman if you want to do it like that with loops and not array methods, you'll have to first make sure that all of source properties are in your collection before you push the collection. You can for example just set a variable to true if all source props are in collection before you push the object in your answer array.
bentongarrett
@bentongarrett
Feb 16 2016 00:04
alright, i could use some help on "profile lookup". any tips?
    for ( i = 0; i <= contacts.length; i++) {
         if ( contacts[i] === firstName && contacts.hasOwnProperty(prop) ) {
          return contacts[i][prop];
      } else if ( contacts.hasOwnProperty(firstName) === false ) {
          return "No such contact";
      } else if ( contacts.hasOwnProperty(prop) === false ) {
          return "No such property";
      }
  }
Harsha Vamsi
@harshavamsi
Feb 16 2016 00:07

// 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) {
var test=prop;
if(value!=="" && prop!="tracks")
collection[id]={"prop":value};
else if(value!=="" && prop=="tracks")
collection.id[prop].push(value);
else
delete collection.id[prop].value;

return collection;
}

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

anyidea how to push the prop value and not the work prop?
Brett
@BLayman
Feb 16 2016 00:11
@dcnr That's right, I was thinking that only one property had to match, but looking over the instructions I think it's all of them.
@dcnr I think I may just start over using array methods, since that seems to be the easy way of doing it.
rybka02
@rybka02
Feb 16 2016 00:14
@harshavamsi Is it an array value you're trying to push?
Harsha Vamsi
@harshavamsi
Feb 16 2016 00:15
No object value.
rybka02
@rybka02
Feb 16 2016 00:16
Can only use push with arrays
you have to set the value for object
Tom Hodgkinson
@LibLogic
Feb 16 2016 00:26
can someone help me with "Sum of Odd Fibanacci's"??
Bartek
@dyczol
Feb 16 2016 00:27
@Mooli88 thanks
CamperBot
@camperbot
Feb 16 2016 00:27
dyczol sends brownie points to @mooli88 :sparkles: :thumbsup: :sparkles:
:star: 169 | @mooli88 | http://www.freecodecamp.com/mooli88
Ari Winokur
@ariwinokur
Feb 16 2016 00:27
Doing "Using Objects for Lookups" and I have no clue what it is talking about. It throws you into using lookups with no explanations
Tom Hodgkinson
@LibLogic
Feb 16 2016 00:28
var fibs = [0, 1];
function sumFibs(num) {
    if ( num === 0 ) { return }
fibs.push(fibs[fibs.length-2] + fibs[fibs.length-1]);
var fibTotals = fibs
    .filter(function(el){
    if ( el % 2 !== 0 ) { return true }
    })
    .reduce(function(all, item) {
    all += item;
    return all;
    });
    console.log(fibTotals);
    sumFibs(num-1);
}

console.log(sumFibs(4));
can console.log the answer but I can't figure out how to return it
rybka02
@rybka02
Feb 16 2016 00:33
uhm without looking at the code,. why not just return sumFibs(4);
actual,ly no
do return fibTotals;
Tom Hodgkinson
@LibLogic
Feb 16 2016 00:34
I am accumulating the value one iteration at a time, but just want to output the last iteration
that gives the wrong answer
Emanuel Quimper
@EQuimper
Feb 16 2016 00:38
function truncate(str, num) {
  // Clear out that junk in your trunk
  if(str.length > num){
    return str.slice(0, num-3) + "...";
  } else if(num > 0 && num <= 3){
      return str.slice(-num) + "...";
  } else {
    return str;
  }

}

truncate("Absolutely Longer", 2);
need help here plz
Alex N.
@N0bl3
Feb 16 2016 00:39
@EQuimper -num is not a valid statement, what do you want to do?
Emanuel Quimper
@EQuimper
Feb 16 2016 00:39
sry I change this after I put that
this is the Truncate a string
Alex N.
@N0bl3
Feb 16 2016 00:40
bf truncate
CamperBot
@camperbot
Feb 16 2016 00:40

:fire:Bonfire: Truncate a string :link:

function truncate(str, num) {
  // Clear out that junk in your trunk
  return str;
}

truncate('A-tisket a-tasket A green and yellow basket', 11);

Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a '...' ending.

more info:  bf details | bf links | hint

Alex N.
@N0bl3
Feb 16 2016 00:41
bf truncate hint
CamperBot
@camperbot
Feb 16 2016 00:41
Sorry, can't find a bonfire called truncate hint. [ Check the map? ]
Alex N.
@N0bl3
Feb 16 2016 00:41
hint
CamperBot
@camperbot
Feb 16 2016 00:41
:construction: Spoilers are only in the Bonfire's Custom Room :point_right:
rybka02
@rybka02
Feb 16 2016 00:41
im getting undefined Liba
Alex N.
@N0bl3
Feb 16 2016 00:41
@EQuimper it's because it's not about cutting three letters : look at the left of the window on the test cases
Emanuel Quimper
@EQuimper
Feb 16 2016 00:43
@N0bl3 yes but my -3 is for put the "..." into the count
Erland Lami
@Texber
Feb 16 2016 00:43
function palindrome(str) {
  // Good luck!

  str=str.toLowerCase();

  for (var i=0; i<str.length; i++) {
    str.replace(' ', '');
    str.replace(',', '');
    str.replace('.', '');

var copy=str.split('').reverse().join('');

    if (copy==str) {
  return true;
}
}

  return str;
}

palindrome("A man, a plan, a canal. Panama");
When I test the palindrome, it's not removing the space, period and comma
Please advise anyone
Emanuel Quimper
@EQuimper
Feb 16 2016 00:44
bf palindrome
CamperBot
@camperbot
Feb 16 2016 00:44

:fire:Bonfire: Check for Palindromes :link:

function palindrome(str) {
  // Good luck!
  return true;
}



palindrome("eye");

Return true if the given string is a palindrome. Otherwise, return false.

more info:  bf details | bf links | hint

DJ
@qualitymanifest
Feb 16 2016 00:44
@Texber str = str.replace(blahblah)
@Texber also you don't need to put your replaces in a loop
Francisco Darré
@frandarre
Feb 16 2016 00:45
bf larger
CamperBot
@camperbot
Feb 16 2016 00:45
Sorry, can't find a bonfire called larger. [ Check the map? ]
Erland Lami
@Texber
Feb 16 2016 00:45
I don't follow @qualitymanifest about str = str.replace()
DJ
@qualitymanifest
Feb 16 2016 00:46
@Texber you're not assigning your str.replace to anything, so you're throwing the value that you created away. you want to assign it back to str so you're actually changing str.
Emanuel Quimper
@EQuimper
Feb 16 2016 00:46
@Texber I did that with regex
Tom Hodgkinson
@LibLogic
Feb 16 2016 00:47
Anybody here that will take a look at my code?? I want to understand what I am doing wrong. I can solve this another way but I am trying to learn about using recursive functions..But I have a glitch
Emanuel Quimper
@EQuimper
Feb 16 2016 00:47
@LibLogic can you repost ?
Tom Hodgkinson
@LibLogic
Feb 16 2016 00:47
@EQuimper absolutely
Lee Tratnyek
@kaplejon
Feb 16 2016 00:47
Looking for some guidance on Stand In Line challenge.
Erland Lami
@Texber
Feb 16 2016 00:47
@EQuimper I'm not as familiar with that method
Emanuel Quimper
@EQuimper
Feb 16 2016 00:48
@Texber regexr.com
Lee Tratnyek
@kaplejon
Feb 16 2016 00:48
function queue(arr, item) { // Your code here arr = arr.push(item); item = arr.shift(); return item; // Change this line }
Tom Hodgkinson
@LibLogic
Feb 16 2016 00:48
var fibs = [0, 1];
function sumFibs(num) {
    if ( num === 0 ) { return }
fibs.push(fibs[fibs.length-2] + fibs[fibs.length-1]);
    var fibTotals = fibs.filter(function(el){
        if ( el % 2 !== 0 ) { return true }
    }).reduce(function(all, item) {
        all += item;
        return all;
    });
console.log(fibTotals);
    sumFibs(num-1);
}

console.log(sumFibs(4));
Emanuel Quimper
@EQuimper
Feb 16 2016 00:48
@kaplejon what you have for now?
Lee Tratnyek
@kaplejon
Feb 16 2016 00:48
function queue(arr, item) {
  // Your code here
  arr = arr.push(item);
  item = arr.shift();
  return item;  // Change this line
}
Emanuel Quimper
@EQuimper
Feb 16 2016 00:49
@LibLogic which question ?
Tom Hodgkinson
@LibLogic
Feb 16 2016 00:49
I'd like to just return the final value
Casey Heath
@ExhibitArts
Feb 16 2016 00:49
If anyone is interested there is a HelpDesign room for feedback on Design :smile:
https://gitter.im/ExhibitArts/HelpDesign?utm_source=share-link&utm_medium=link&utm_campaign=share-link
Emanuel Quimper
@EQuimper
Feb 16 2016 00:49
bf stand
CamperBot
@camperbot
Feb 16 2016 00:49
Sorry, can't find a bonfire called stand. [ Check the map? ]
Emanuel Quimper
@EQuimper
Feb 16 2016 00:49
bf Stand In The Line
CamperBot
@camperbot
Feb 16 2016 00:49
Sorry, can't find a bonfire called stand in the line. [ Check the map? ]
Tom Hodgkinson
@LibLogic
Feb 16 2016 00:49
I get the right answer in the last iteration here
Alex N.
@N0bl3
Feb 16 2016 00:49
@EQuimper can you send me your code in private please? I'm doing something else at the same time. So that i can help you
Tom Hodgkinson
@LibLogic
Feb 16 2016 00:50
but I cant figure out how to return the answer on the last iteration
Lee Tratnyek
@kaplejon
Feb 16 2016 00:51
The error message I'm getting is: "TypeError: arr.shift is not a function."
Emanuel Quimper
@EQuimper
Feb 16 2016 00:51
@kaplejon you not far to the good answer but you need to have a other variable for call the shift
Lee Tratnyek
@kaplejon
Feb 16 2016 00:52
However, I've looked at the .shift function on MDN.
Brian
@sludge256
Feb 16 2016 00:52
@kaplejon It's because you're transforming your variable arr from an array into a number wtih this code
arr = arr.push(item);
Lee Tratnyek
@kaplejon
Feb 16 2016 00:52
@EQuimper Do you mean a local variable?
Emanuel Quimper
@EQuimper
Feb 16 2016 00:53
var singleItem;
  arr.push(item);
Brian
@sludge256
Feb 16 2016 00:53
.push() returns the length of the new array
Lee Tratnyek
@kaplejon
Feb 16 2016 00:53
Oh!
Okay, that makes sense.
Didn't realize .push() was returning the length.
Emanuel Quimper
@EQuimper
Feb 16 2016 00:53
and take the singleItem for singleItem=arr.shift()
Lee Tratnyek
@kaplejon
Feb 16 2016 00:54
Okay, bravo!
function queue(arr, item) {
  // Your code here
  arr.push(item);
  item = arr.shift();
  return item;  // Change this line
}
Now works!
Emanuel Quimper
@EQuimper
Feb 16 2016 00:55
yes goo job @kaplejon
Lee Tratnyek
@kaplejon
Feb 16 2016 00:55
Thanks @sludge256 and @EQuimper for your help.
CamperBot
@camperbot
Feb 16 2016 00:55
kaplejon sends brownie points to @sludge256 and @equimper :sparkles: :thumbsup: :sparkles:
:star: 260 | @equimper | http://www.freecodecamp.com/equimper
:star: 1494 | @sludge256 | http://www.freecodecamp.com/sludge256
Lee Tratnyek
@kaplejon
Feb 16 2016 00:56
I was still thinking in logic terms of doing a += operation, which didn't make sense since I was using a function with a return value, and instead storing that in my variable intended to hold an array.
Oh happy day!
Casey Heath
@ExhibitArts
Feb 16 2016 00:58
This message was deleted
Tom Hodgkinson
@LibLogic
Feb 16 2016 00:58
@EQuimper is my code beautiful if you ignore the fact that it doesn't work?? lol
Casey Heath
@ExhibitArts
Feb 16 2016 00:58
Emanuel Quimper
@EQuimper
Feb 16 2016 00:59
@LibLogic look good let me check more
Ari Winokur
@ariwinokur
Feb 16 2016 01:09
Working on "Using Objects for Lookups" and unless I am mistaken, there was never an explanation of lookups. Can someone point me in the right direction?
Emanuel Quimper
@EQuimper
Feb 16 2016 01:14
bf lookups
CamperBot
@camperbot
Feb 16 2016 01:14
Sorry, can't find a bonfire called lookups. [ Check the map? ]
Emanuel Quimper
@EQuimper
Feb 16 2016 01:14
bf Using Objects for Lookups
CamperBot
@camperbot
Feb 16 2016 01:14
Sorry, can't find a bonfire called using objects for lookups. [ Check the map? ]
Ari Winokur
@ariwinokur
Feb 16 2016 01:15
its a challenge, not a bonfire
Norman Dela Cruz
@dcnr
Feb 16 2016 01:15
@ariwinokur simplified explanation
var foo = {
  bar: "baz"
}
  1. Dot with literal property name
    var result = foo.bar;  //  result is baz
  2. Bracket with literal property name
    var result = foo["bar"]; // result is baz
  3. Bracket with variable property name
    var myProp = "bar";
    var result = foo[myProp]; // result is baz
Emanuel Quimper
@EQuimper
Feb 16 2016 01:15
yes I see
hellotojello
@hellotojello
Feb 16 2016 01:15
function repeat(str, num) {
  var stringLayout = console.log(str);
  if (num >= 0){
    return stringLayout * num;
  }
  // repeat after me
else{
  return "";
}
  }

repeat("abc", 3);
i need a hint
Emanuel Quimper
@EQuimper
Feb 16 2016 01:15
@ariwinokur just reed the example all you need his here
@ariwinokur tips when you gonna return you need to put [val]
Prithvi-A
@Prithvi-A
Feb 16 2016 01:16
This message was deleted
What is wrong with my code

var Car = function(wheels, seats, engines) {
//Change this constructor
this.wheels = 6;
this.seats = 3;
this.engines = 4;
};

//Try it out here
var myCar = new Car(4, 2, 2);

Emanuel Quimper
@EQuimper
Feb 16 2016 01:17
@Prithvi-A put your code into ``` plz
Prithvi-A
@Prithvi-A
Feb 16 2016 01:18
var Car = function(wheels, seats, engines) {
  //Change this constructor
  this.wheels = 6;
  this.seats = 3;
  this.engines = 4;
};

//Try it out here
var myCar = new Car(4, 2, 2);
Norman Dela Cruz
@dcnr
Feb 16 2016 01:18
@Prithvi-A you can edit your post by clicking the ... right of the timestamp, so you don't have to repost
Prithvi-A
@Prithvi-A
Feb 16 2016 01:19
fixed that
Norman Dela Cruz
@dcnr
Feb 16 2016 01:20
what exercise is that anyway
Ari Winokur
@ariwinokur
Feb 16 2016 01:20
@dcnr: so lookup is not actually used
^^^meaning the word lookup in the code
Norman Dela Cruz
@dcnr
Feb 16 2016 01:20
@ariwinokur well unless you make a variable named lookup I guess :P
Prithvi-A
@Prithvi-A
Feb 16 2016 01:20
Make Unique Objects by Passing Parameters to our Constructor
Emanuel Quimper
@EQuimper
Feb 16 2016 01:22
@Prithvi-A you nee to pass your argument into each of variables cause now what you passign is 4 6 2 3 2 4
Ari Winokur
@ariwinokur
Feb 16 2016 01:22
Well put @dcnr
Emanuel Quimper
@EQuimper
Feb 16 2016 01:22
@Prithvi-A example this.wheels = wheels
etc
Norman Dela Cruz
@dcnr
Feb 16 2016 01:23
@Prithvi-A you'll need to modify the car constructor function like what @EQuimper said :point_up: February 16, 2016 9:22 AM
Tom Hodgkinson
@LibLogic
Feb 16 2016 01:23
Anybody here good at recursive functions?
Ari Winokur
@ariwinokur
Feb 16 2016 01:24
@dcnr how would that work in my challenge? http://www.freecodecamp.com/challenges/using-objects-for-lookups
Norman Dela Cruz
@dcnr
Feb 16 2016 01:24
@ariwinokur read and understand the directions carefully, it's practically laid out for you :P
Alex N.
@N0bl3
Feb 16 2016 01:24
@LibLogic send your code, i like these problems :)
Tom Hodgkinson
@LibLogic
Feb 16 2016 01:25
@N0bl3 thanks
CamperBot
@camperbot
Feb 16 2016 01:25
liblogic sends brownie points to @n0bl3 :sparkles: :thumbsup: :sparkles:
:star: 157 | @n0bl3 | http://www.freecodecamp.com/n0bl3
Tom Hodgkinson
@LibLogic
Feb 16 2016 01:25
send it in private?
Emanuel Quimper
@EQuimper
Feb 16 2016 01:25
sry @LibLogic wasn't in this right now still just start
Alex N.
@N0bl3
Feb 16 2016 01:25
@LibLogic send it here , with before it and after it
Emanuel Quimper
@EQuimper
Feb 16 2016 01:26
@LibLogic that's why I don't answer
Tom Hodgkinson
@LibLogic
Feb 16 2016 01:27
This message was deleted
var fibs = [0, 1];
function sumFibs(num) {
    if ( num === 0 ) { return }
    fibs.push(fibs[fibs.length - 2] + fibs[fibs.length - 1]);
        var fibTotals = fibs.filter(function (el) {
            if (el % 2 !== 0) {
                return true
            }
        }).reduce(function (all, item) {
            all += item;
            return all;
        });
    console.log(fibTotals);
    sumFibs(num-1);
}

console.log(sumFibs(9));
I appreciate your help guys...hate to give up on this
Alex N.
@N0bl3
Feb 16 2016 01:33
@LibLogic Let's continue here :)
Ari Winokur
@ariwinokur
Feb 16 2016 01:34
@dcnr I got it finally, but the explanation was really lacking!
Alex N.
@N0bl3
Feb 16 2016 01:35
@LibLogic the problem is the way you organize your code with return statements. return breaks the sumFibs() in a way that having fibTotals variable doesn't make sense
@LibLogic to put you on the tracks, you should reorganize everything and do something like return sumFibs(num-1)
i know i always give the docs to read but these are a great way to imrove as even professionals may find new things there
Tom Hodgkinson
@LibLogic
Feb 16 2016 01:38
ok I will try reading up
Alex N.
@N0bl3
Feb 16 2016 01:38
in short: docs are LIFE :+1:
Tom Hodgkinson
@LibLogic
Feb 16 2016 01:38
I thought I understood return though..lol
Alex N.
@N0bl3
Feb 16 2016 01:40
@LibLogic have a look at a JSFiddle i did to understand recursion better (https://jsfiddle.net/Sp3cialK/mq17nhu5/)
Tom Hodgkinson
@LibLogic
Feb 16 2016 01:41
@N0bl3 thanks I'll look at that first...since I think I am using recursion wrong (I think)
CamperBot
@camperbot
Feb 16 2016 01:41
liblogic sends brownie points to @n0bl3 :sparkles: :thumbsup: :sparkles:
:warning: liblogic already gave n0bl3 points
Alex N.
@N0bl3
Feb 16 2016 01:41
@LibLogic yes it looks like you know about retun nd it is more a recursion problem :)
Tom Hodgkinson
@LibLogic
Feb 16 2016 01:42
ahh TY :)
Norman Dela Cruz
@dcnr
Feb 16 2016 01:45
@ariwinokur yeah most of the "lessons" here will be like that, you will have to do other searches about topics new to you
Mafalda
@otmeek
Feb 16 2016 01:47
i swear the advanced algorithms section starts out with the hardest exercises and then move on to much easier ones
i was struggling so hard with the first few ones
Stephen Antony
@Stephen-antony
Feb 16 2016 01:53
hello
Francisco Darré
@frandarre
Feb 16 2016 01:54
Docs love us as much as we love them?
Stephen Antony
@Stephen-antony
Feb 16 2016 01:55

function multiplyAll(arr) {
var product = 1;
// Only change code below this line
for(var i=0;i<arr.length;i++) {

for(var j=0;j<arr[i].lenght;j++)
{
    product*=arr[i][j];
}   

}

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

// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
Having trouble with this code

Norman Dela Cruz
@dcnr
Feb 16 2016 02:00
@otmeek the later ones used to be called "upper-intermediate" so I guess they were a little easier
@otmeek they got merged into advanced
@Stephen-antony typo on arr[i].lenght
Alex Evans
@alex-evans
Feb 16 2016 02:02
Missing something on the "No repeats please" and struggling to see it. I know I'm not removing any of the repeats yet but currently just trying to get all permutations. I got some help from wiki help but trying to not fully rely on it. Anyone able to point me in the right direction on what I have to keep me moving forward. Appreciate any help but otherwise I'll call it a night and look at it again tomorrow morning.
var permArr = [];
var str = "";

function perm(curPos, usedSpot, builtStr) {
  if(builtStr.length == str.length) {
    permArr.push(builtStr);
  } else {
    for(i=0; i < str.length; i++) {
      if(usedSpot.indexOf(i) < 0) {
        builtStr += str[i];
        usedSpot.push(i);
        perm(i, usedSpot, builtStr);
        usedSpot.pop();
      }
    }
  }
}

function permAlone(chkStr) {
  str = chkStr;
  perm(0,[],"");
  return permArr;
}

permAlone('aab');
Ari Winokur
@ariwinokur
Feb 16 2016 02:03
What am I doing wrong with this challenge? Testing Objects for Properties?
and clearly markdown doesn't like me
Mafalda
@otmeek
Feb 16 2016 02:03
@dcnr that makes sense
Norman Dela Cruz
@dcnr
Feb 16 2016 02:04
@alcatrats I'll just assume you have the proper algo, but with the FCC editor, never use global vars because it won't reset for the other test cases.
Cian
@ciant
Feb 16 2016 02:04
@Stephen-antony I'm currently stuck on this same waypoint
Norman Dela Cruz
@dcnr
Feb 16 2016 02:04
@alcatrats and you'll only prolly past the first one
Alex Evans
@alex-evans
Feb 16 2016 02:05
Yep only getting 'aab' currently. So no var permArr and str?
Norman Dela Cruz
@dcnr
Feb 16 2016 02:08
@alcatrats it seems like you're just returning the permutation
@alcatrats and not the total number of permutations that has no consecutive characters
Alex Evans
@alex-evans
Feb 16 2016 02:10
Right, I was just first trying to figure out how to build an array of those permutations. After I have that array I was going to pull out any that had repeating letters.
Radha Krishna Kavuluru
@champrakri
Feb 16 2016 02:10
stuck on symmetric difference
Cian
@ciant
Feb 16 2016 02:11
This message was deleted
Alex Evans
@alex-evans
Feb 16 2016 02:11
I think I see where I can head with it. Going to let it sit overnight though and dive into it tomorrow. Appreciate the input @dcnr . Thanks.
CamperBot
@camperbot
Feb 16 2016 02:11
alcatrats sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 629 | @dcnr | http://www.freecodecamp.com/dcnr
Norman Dela Cruz
@dcnr
Feb 16 2016 02:11
@alcatrats aah I see, I actually didn't bother implementing my own perm function so I can't help you with that part, I'm sorry :P
Alex Evans
@alex-evans
Feb 16 2016 02:11
No worries
Norman Dela Cruz
@dcnr
Feb 16 2016 02:11
thanks too and good luck @alcatrats
CamperBot
@camperbot
Feb 16 2016 02:11
dcnr sends brownie points to @alcatrats :sparkles: :thumbsup: :sparkles:
:star: 309 | @alcatrats | http://www.freecodecamp.com/alcatrats
Stephen Antony
@Stephen-antony
Feb 16 2016 02:11
@dcnr i havent still figured out
Norman Dela Cruz
@dcnr
Feb 16 2016 02:12
@Stephen-antony your length is misspelled in your second for loop
Radha Krishna Kavuluru
@champrakri
Feb 16 2016 02:12

function diff(arr1, arr2) {
var newArr = [];
// Same, same; but different.
var check=0;
var indexlog=0;
for(var j=0;j<arr2.length;j++)
{
check=0;
for(var i=0;i<arr1.length;i++)
{
if(arr2[j]==arr1[i])
{
check=1;
}
}
if(check===0)
{
newArr[indexlog]=arr2[j];
indexlog++;
}
}
return newArr;
}

diff([1, 2, 3, 5], [1, 2, 3, 4, 5]);

Norman Dela Cruz
@dcnr
Feb 16 2016 02:12
@Stephen-antony it should be arr[i].length NOT arr[i].lenght
Stephen Antony
@Stephen-antony
Feb 16 2016 02:12
@dcnr lol thanks , i was thinking my code was dumb for a second
CamperBot
@camperbot
Feb 16 2016 02:12
stephen-antony sends brownie points to @dcnr :sparkles: :thumbsup: :sparkles:
:star: 630 | @dcnr | http://www.freecodecamp.com/dcnr
Stephen Antony
@Stephen-antony
Feb 16 2016 02:13
damn it :{
Norman Dela Cruz
@dcnr
Feb 16 2016 02:14
@Stephen-antony eh? still getting errors?
Cian
@ciant
Feb 16 2016 02:14
@Stephen-antony That still doesn't work right? It passes test 1 but fails on the second 2. I had the exact same code
Stephen Antony
@Stephen-antony
Feb 16 2016 02:14
@ciant it's working for me now
Norman Dela Cruz
@dcnr
Feb 16 2016 02:14
oh
Stephen Antony
@Stephen-antony
Feb 16 2016 02:14
@dcnr nah , i got it done
Cian
@ciant
Feb 16 2016 02:14
okay let me compare again
Norman Dela Cruz
@dcnr
Feb 16 2016 02:15
@Stephen-antony awesome! sometimes, you'll have to reset/refresh though even though you have the right answer because of cache and stuff
Radha Krishna Kavuluru
@champrakri
Feb 16 2016 02:15
hello guys i am a starter, i have a little problem. When i copy my code here how can i get it in nice format?
Ari Winokur
@ariwinokur
Feb 16 2016 02:15
What am I doing wrong?
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

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

  return "Not Found";
  }
}

// Test your code by modifying these values
checkObj("gift");
Greg D
@mosaic-greg
Feb 16 2016 02:16
\help
CamperBot
@camperbot
Feb 16 2016 02:16

Hi, I'm CamperBot! I can help you in this chatroom :smile:

Basic Commands:

  • find TOPIC find all entries about topic. ex: find js
  • wiki TOPIC show contents of topic page
  • thanks @username send brownie points to another user
  • about @username shows info on that user
  • Algorithm BONFIRENAME info on a Algorithm

:speech_balloon: meet CamperBot in this room!

:pencil: read more about camperbot on the FCC Wiki

Moisés Man
@moigithub
Feb 16 2016 02:16
u using dot notation.. shoudl be brackets... @ariwinokur
Ari Winokur
@ariwinokur
Feb 16 2016 02:16
^^^Testing Objects for Properties
Greg D
@mosaic-greg
Feb 16 2016 02:16
find formatting
CamperBot
@camperbot
Feb 16 2016 02:16

find formatting

:zero: code formatting

Norman Dela Cruz
@dcnr
Feb 16 2016 02:16

@champrakri hi you will need to type three backticks (the key above tab, left of 1, and below esc) (shift + enter to make a new line) (paste your code) (shift + enter again) then three more backtics so it looks like this
```js

<your code pasted here>
```

Ari Winokur
@ariwinokur
Feb 16 2016 02:16
@moigithub which one? on the return nline?
Moisés Man
@moigithub
Feb 16 2016 02:17
yes
Ari Winokur
@ariwinokur
Feb 16 2016 02:17
Thanks @moigithub
CamperBot
@camperbot
Feb 16 2016 02:17
ariwinokur sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 612 | @moigithub | http://www.freecodecamp.com/moigithub
Ari Winokur
@ariwinokur
Feb 16 2016 02:17
Wondering why it matters there?
Moisés Man
@moigithub
Feb 16 2016 02:18
u only use dot notation if the name following the dot is a real property name
but chekcprop is a variable...
Radha Krishna Kavuluru
@champrakri
Feb 16 2016 02:18
I am a starter. I am stuck at symmetric difference. What's wrong in this code :) please help
function diff(arr1, arr2) {
  var newArr = [];
  // Same, same; but different.
 var check=0;
  var indexlog=0;
  for(var j=0;j<arr2.length;j++)
    {
      check=0;
    for(var i=0;i<arr1.length;i++)
      {
        if(arr2[j]==arr1[i])
          {
            check=1;
          }
      }
      if(check===0)
        {
          newArr[indexlog]=arr2[j];
          indexlog++;
        }
    }
  return newArr;
}

diff([1, 2, 3, 5], [1, 2, 3, 4, 5]);
Ari Winokur
@ariwinokur
Feb 16 2016 02:19
@moigithub so bracket is always used when variables are involved and dot when constants are involved?
Cian
@ciant
Feb 16 2016 02:19
Still unsure what I am doing wrong here in waypoint "nesting for loops"
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<[i].length; j++){
      product*=arr[i][j];
    }
  }



  // Only change code above this line
  return product;
}
Stephen Antony
@Stephen-antony
Feb 16 2016 02:20

@ciant 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].length;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]]);

Radha Krishna Kavuluru
@champrakri
Feb 16 2016 02:20
@ciant in the second for loop you have to use arr[i]
Moisés Man
@moigithub
Feb 16 2016 02:20
@ariwinokur if by "contants" u mean the object key/property name.. yes
Stephen Antony
@Stephen-antony
Feb 16 2016 02:21
@ciant arr[i].length
Moisés Man
@moigithub
Feb 16 2016 02:21
@ariwinokur but.. u can also use brackets when using property/keys.. but the difference . is u need to use quotes.... (if variables no quotes )
Cian
@ciant
Feb 16 2016 02:24
thanks @champrakri
CamperBot
@camperbot
Feb 16 2016 02:24
ciant sends brownie points to @champrakri :sparkles: :thumbsup: :sparkles:
:star: 3 | @champrakri | http://www.freecodecamp.com/champrakri
Ari Winokur
@ariwinokur
Feb 16 2016 02:25
@moigithub so in short: bracket notation is always safe (and of course you need to pay attention to quotes)
Moisés Man
@moigithub
Feb 16 2016 02:27
@ariwinokur yep :)
Ari Winokur
@ariwinokur
Feb 16 2016 02:29
Thanks @moigithub
CamperBot
@camperbot
Feb 16 2016 02:29
ariwinokur sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:warning: ariwinokur already gave moigithub points
Kevin Myrick
@aphextwin234
Feb 16 2016 02:29
does anyone know how to make an onmouseover event contain a url?
Marisol C
@Mariisun
Feb 16 2016 02:29
can anyone help me on I am a "double quoted" string inside "double quotes"?
landtyler
@landtyler
Feb 16 2016 02:30
Hey I need help on weather app. I'm trying to pull info from JSON app and printing the data pulled. It's not showing up for me. Someone help me out? http://codepen.io/imtylerland/pen/yeZQVO
Marisol C
@Mariisun
Feb 16 2016 02:31
/copy code
landtyler
@landtyler
Feb 16 2016 02:31
Just the button, don't worry about the zip code text box
Marisol C
@Mariisun
Feb 16 2016 02:31

var myStr = "I am a \"double quoted\" string inside \"double quotes\";

my code for Escaping Literal Quotes in Strings

my X: Variable myStr should equal to ("I am a "double quoted" string inside "double quotes"").
console: syntaxError: Unexpected token ILLEGAL
Cian
@ciant
Feb 16 2016 02:33
You are missing your final double quote @Mariisun
var myStr = "I am a \"double quoted\" string inside \"double quotes\"";
Marisol C
@Mariisun
Feb 16 2016 02:34
GAH! thank you @ciant
Jason
@J-Pitt
Feb 16 2016 02:36
Hey everyone, I'm stuck on module 184, stand in line, the directions are a little confusing and I dont know what I'm doing wrong. "Write a function queue which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The queue function should then return the element that was removed."
'''
CamperBot
@camperbot
Feb 16 2016 02:36
:bulb: to format code use backticks! ``` more info
Alex N.
@N0bl3
Feb 16 2016 02:36
@Mariisun I'm Alex , nice to meet you double quoted string :+1:
Jason
@J-Pitt
Feb 16 2016 02:37
where the heck are the backticks haha
```
Alex N.
@N0bl3
Feb 16 2016 02:37
@J-Pitt just copy paste haha
Jason
@J-Pitt
Feb 16 2016 02:37

```function queue(arr, item) {
// Your code here
testArr.push(1);

return testArr.shift(0); // Change this line
}

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

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

well that didnt work haha
Moisés Man
@moigithub
Feb 16 2016 02:38
@landtyler $.getJSON("api.openweathermap.org/dat
add "http://"; or "https://"; to ur url
Alex N.
@N0bl3
Feb 16 2016 02:38
@J-Pitt you have to make a line break after ``` !
Jason
@J-Pitt
Feb 16 2016 02:39
function queue(arr, item) {
  // Your code here
testArr.push(1);

  return testArr.shift(0);  // Change this line
}

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

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(queue(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
Moisés Man
@moigithub
Feb 16 2016 02:39
@J-Pitt shift dont need argument values
Jason
@J-Pitt
Feb 16 2016 02:39
ahh ha!
Alex N.
@N0bl3
Feb 16 2016 02:39
:+1:
landtyler
@landtyler
Feb 16 2016 02:39
@moigithub thanks!
CamperBot
@camperbot
Feb 16 2016 02:39
landtyler sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 613 | @moigithub | http://www.freecodecamp.com/moigithub
Jason
@J-Pitt
Feb 16 2016 02:40
I was just trying to show the argument that got dropped
Alex N.
@N0bl3
Feb 16 2016 02:40
@landtyler next time have a look at your console, you would have sen it didnt push to a normal url
@J-Pitt it is the normal behaviour of this function then you dont need to pass it an argument (https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Array/shift)
Moisés Man
@moigithub
Feb 16 2016 02:41
@J-Pitt anlso u pushing value 1.. u should use the argument provided..
Jason
@J-Pitt
Feb 16 2016 02:42
Ok thanks, @moigithub @N0bl3 , I will give it another shot!
CamperBot
@camperbot
Feb 16 2016 02:42
j-pitt sends brownie points to @moigithub and @n0bl3 :sparkles: :thumbsup: :sparkles:
:star: 614 | @moigithub | http://www.freecodecamp.com/moigithub
:star: 160 | @n0bl3 | http://www.freecodecamp.com/n0bl3
Ari Winokur
@ariwinokur
Feb 16 2016 03:22
From Record Collection challenge:
Kendra Lyndon
@KendraLyndon
Feb 16 2016 03:22
Is anyone working on the Mutations bonfire?
Ari Winokur
@ariwinokur
Feb 16 2016 03:23
// 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 (value !== "" && prop == "tracks") {
    collection[id].tracks.push(value);
  } else {
    collection[id].remove(prop);
  }

  return collection;
}

// Alter values below to test your code
update(5439, "artist", "ABBA");
^^^Record Collection challenge
something is wrong, but I'm not sure what
philipsiu
@philipsiu
Feb 16 2016 03:33
@ariwinokur I used the delete option for the last statement
xEpicDanielx
@xEpicDanielx
Feb 16 2016 03:35
Hey everyone! :)
Ari Winokur
@ariwinokur
Feb 16 2016 03:36
Thanks @philthyfill Can you help me with the difference
CamperBot
@camperbot
Feb 16 2016 03:36
ariwinokur sends brownie points to @philthyfill :sparkles: :thumbsup: :sparkles:
Ari Winokur
@ariwinokur
Feb 16 2016 03:36
?
CamperBot
@camperbot
Feb 16 2016 03:36
:warning: could not find receiver for philthyfill
Kendra Lyndon
@KendraLyndon
Feb 16 2016 03:36
Hi @xEpicDanielx !
xEpicDanielx
@xEpicDanielx
Feb 16 2016 03:36
I got about 15 minutes to kill! anyone need some help? :)
philipsiu
@philipsiu
Feb 16 2016 03:39
@ariwinokur I'm still new at this but I had a similar solution to your by rearranging the elseif statements.
@ariwinokur For the if/elseif statements, if the conditions come back true for the first statement, and you have a 'return', then that will be the end.
yoryosv
@yoryosv
Feb 16 2016 03:41
@ariwinokur first else if: what is "tracks"?
Ari Winokur
@ariwinokur
Feb 16 2016 03:46
@philthyfill I changed remove to delete but it didn't solve it
Kela
@kela7
Feb 16 2016 03:46
i need help on the counting cards problem
Chris Katzmann
@cwkatzmann
Feb 16 2016 03:47
var array = [4,5,6,7,8];
var singleVal = 0;

// Only change code below this line.

singleVal = array.reduce(function(previousVal, currentVal) {
  return previousVal + currentVal;
}, 0);
Ari Winokur
@ariwinokur
Feb 16 2016 03:47
@yoryosv it is all from the Record Collection challenge
Moisés Man
@moigithub
Feb 16 2016 03:47
wrong syntax probably.. google "delete object"
Chris Katzmann
@cwkatzmann
Feb 16 2016 03:47
what is going wrong there^
Ari Winokur
@ariwinokur
Feb 16 2016 03:47
@kela7 That one took me a while, what code do you have so far?
Kela
@kela7
Feb 16 2016 03:47
im still learning how to write the if/else statements its just not sticking with me, so i am lost on how to do this problem
Chris Katzmann
@cwkatzmann
Feb 16 2016 03:47
the instructions were unclear
Moisés Man
@moigithub
Feb 16 2016 03:48
what it want u to do ? @cwkatzmann
Chris Katzmann
@cwkatzmann
Feb 16 2016 03:48
@kela7 thats a pretty hard one. I think I used switch statements for it.
Kela
@kela7
Feb 16 2016 03:48
if(card >= 2 && card <= 6){
return 5 + "Bet";
}else if(card >=7 && card <= 9){
return -count + "Hold";
}else{
return "Change Me";
} @ariwinokur
Chris Katzmann
@cwkatzmann
Feb 16 2016 03:48
@moigithub it's supposed to add all the elements of var array into one var singleVal
Kela
@kela7
Feb 16 2016 03:48
oh really? @cwkatzmann
Ari Winokur
@ariwinokur
Feb 16 2016 03:48
@kela7 I agree with @cwkatzmann that you should be using switch statements
Kela
@kela7
Feb 16 2016 03:49
i can pretty much understand switch statements its a bit easier to do rather than doing the if/else statements
ok i will try that
yoryosv
@yoryosv
Feb 16 2016 03:49
@ariwinokur yes, i know... i'm asking why are you using it like this in the else if statment.
philipsiu
@philipsiu
Feb 16 2016 03:49
@ariwinokur Try rearranging your last two elseif statements
Moisés Man
@moigithub
Feb 16 2016 03:49
@cwkatzmann thats all the code ?? or missing something.. can u paste all plz ?
Chris Katzmann
@cwkatzmann
Feb 16 2016 03:49
@kela7 you are supposed to create a count that is based on what cards are dealt, and if the count is over a certain number, you return the count and either "bet " or "hold"
@moigithub thats the whole code, I'm doing the .reduce method challenge
Kela
@kela7
Feb 16 2016 03:51
ok i will try this again
Okan
@Okandja
Feb 16 2016 03:51
hey
I'm doing a challenge about golfing , defining strings based on the relation between par and strokes
I'm having trouble defining the code for Hole in one, since it doesn't have a relation between par and strokes
Chris Katzmann
@cwkatzmann
Feb 16 2016 03:53
@moigithub It's possible I'm missing something but the instructions seem bad then
Okan
@Okandja
Feb 16 2016 03:54
function golfScore(par, strokes) {
// Only change code below this line
if (strokes <= par -2){
return "Eagle";
}
else if (strokes <= par -1){
return "Birdie";
}
else if (strokes <= par-0){
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!";
}
else if (1, par ) {
return "Hole-in-one!";
}
cannelflow
@cannelflow
Feb 16 2016 03:55
@Okandja you are missing condition for if(strokes==1)
Chris Katzmann
@cwkatzmann
Feb 16 2016 03:56
@cannelflow good call
Okan
@Okandja
Feb 16 2016 03:56
should that be at the top?
cannelflow
@cannelflow
Feb 16 2016 03:57
@Okandja yes your first condition @cwkatzmann :+1:
Chris Katzmann
@cwkatzmann
Feb 16 2016 03:57
your last else if statement doesnt make sense
cannelflow
@cannelflow
Feb 16 2016 03:57
@cwkatzmann is right
@Okandja
Okan
@Okandja
Feb 16 2016 03:58
yeah that was me trying anything, it's gone now
It worked, thank you so much @cannelflow and @cwkatzmann
CamperBot
@camperbot
Feb 16 2016 03:59
okandja sends brownie points to @cannelflow and @cwkatzmann :sparkles: :thumbsup: :sparkles:
:star: 804 | @cannelflow | http://www.freecodecamp.com/cannelflow
:star: 251 | @cwkatzmann | http://www.freecodecamp.com/cwkatzmann
Chris Katzmann
@cwkatzmann
Feb 16 2016 04:01
youre welcome
cannelflow
@cannelflow
Feb 16 2016 04:03
@Okandja :+1:
Ari Winokur
@ariwinokur
Feb 16 2016 04:04
// 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 (value !== "" && prop == "tracks") {
    collection[id].tracks.push(value);
  } else if (value === "") {
    collection[id].delete(prop);
  }

  return collection;
}

// Alter values below to test your code
update(5439, "artist", "ABBA");
What am I doing wrong with the last condition?
philipsiu
@philipsiu
Feb 16 2016 04:05
@ariwinokur delete collection[id][prop];
Ari Winokur
@ariwinokur
Feb 16 2016 04:07
Thanks @philthyfill
CamperBot
@camperbot
Feb 16 2016 04:07
ariwinokur sends brownie points to @philthyfill :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for philthyfill
Ari Winokur
@ariwinokur
Feb 16 2016 04:07
not sure why I didn't realize that
Neeraj Lad
@neeraj-lad
Feb 16 2016 04:12
Hi there!
I am doing the Profile lookup challenge in Basic Javascript
Here is my code:
function lookUp(firstName, prop){
// Only change code below this line
  for (var i = 0; i < contacts.length; i++)
  {
    //console.log(contacts[i].firstName);
    if (contacts[i].firstName == firstName)
    {
      if (contacts[i].hasOwnProperty(prop))
        return (contacts[i][prop]);
      else
        return "No such property";
    }
    else
      return "No such contact";
  }
// Only change code above this line
}

// Change these values to test your function
lookUp("Sherlock", "address");
Laudron
@Laudron
Feb 16 2016 04:12
@neeraj-lad Alright, we have your code ... what is your question? :P
Neeraj Lad
@neeraj-lad
Feb 16 2016 04:13
My code only works for the first element in contacts.. it returns "No contact found" for others
:smile:
anthonygallina1
@anthonygallina1
Feb 16 2016 04:18
Only works for first name?
Laudron
@Laudron
Feb 16 2016 04:18

@neeraj-lad Your current code reads as:
(1) if this contact contacts[i] has the same first name as the firstName parameter then check for the wanted property
(2) Otherwise return "No such contact";

The issue is that as soon as contacts[i].firstName does not equal firstName your code returns, effectively stopping execution.

Neeraj Lad
@neeraj-lad
Feb 16 2016 04:19
@anthonygallina1 yes.. only for contacts0
@Laudron why?
anthonygallina1
@anthonygallina1
Feb 16 2016 04:19
Follow @Laudron he is leading you in the right direction
Neeraj Lad
@neeraj-lad
Feb 16 2016 04:20
@Laudron that should be the corrrect logic, right?
Laudron
@Laudron
Feb 16 2016 04:20
@neeraj-lad You should return No such contact when all contacts have been checked.
Currently you return No such contact as soon as if (contacts[i].firstName == firstName) is false

Basically your

return "No such contact";

Is in the wrong spot :P

Neeraj Lad
@neeraj-lad
Feb 16 2016 04:21
@Laudron .. aah.. yes.. got the bug :D Thanks! Will check it now!
CamperBot
@camperbot
Feb 16 2016 04:21
neeraj-lad sends brownie points to @laudron :sparkles: :thumbsup: :sparkles:
:star: 320 | @laudron | http://www.freecodecamp.com/laudron
Neeraj Lad
@neeraj-lad
Feb 16 2016 04:24
@Laudron Passed the challenge.. Thanks! (y)
CamperBot
@camperbot
Feb 16 2016 04:24
neeraj-lad sends brownie points to @laudron :sparkles: :thumbsup: :sparkles:
:warning: neeraj-lad already gave laudron points
Laudron
@Laudron
Feb 16 2016 04:25
@neeraj-lad Not a problem, you were on the right track to begin with :P
kiel barry
@kielbarry
Feb 16 2016 04:34
function where(arr, num) {
  // Find my place in this sorted array.
  arr.sort().map(
    function(val){
      if(val>num){
          return arr.indexOf(val-1);
      }                            
  });
}

where([40, 60], 50);
halp
Laudron
@Laudron
Feb 16 2016 04:35
@declanPaz What happens if val <= num? :P And what specifically do you want help with on that?
kiel barry
@kielbarry
Feb 16 2016 04:36
what i want to return is the index of the place where num is less than the next number, but higher than the place of the previous number (when passed an array of numbers)
"For example, where([1,2,3,4], 1.5) should return 1 because it is greater than 1 (index 0), but less than 2 (index 1)."
so if val <=num, do nothing and move to next value
Laudron
@Laudron
Feb 16 2016 04:38
@declanPaz Alright, first things first:
That return arr.indexOf(val-1); will only return a value if val - 1 exists in arr
Furthermore, return arr.indexOf(val-1); is inside of a .map(function(val) { }); which means that currently your function where(arr, num) does not return anything
kiel barry
@kielbarry
Feb 16 2016 04:39
thanks for response .... will take a min to think thrpugh it
i don't understand your second sentence
changed that line to "return arr.indexOf(val)-1;"
George Armstrong
@george-of-croton
Feb 16 2016 04:44
@wearenotgroot forgot to thank you last night.! i have now finished the javascript basics course! feels good :)
CamperBot
@camperbot
Feb 16 2016 04:44
george-of-croton sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 857 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
kiel barry
@kielbarry
Feb 16 2016 04:44
so, you're saying that the map function returns the result to the where function, but then the where doesn't know what to do with it?
n9exorcist
@n9exorcist
Feb 16 2016 04:44
var myMusic = [
{
"artist": "Billy Joel",
"title": "Piano Man",
"release_year": 1973,
"formats": [
"CS",
"8T",
"LP" ],
"gold": true
}
{
"artist": "Billy",
"title": "Piano",
"release_year": 1972,
"formats": [
"C",
"8",
"L" ],
}
];
Whats wrong with the code? I am getting error in 12 and 13th line, saying missing semi colon.
kiel barry
@kielbarry
Feb 16 2016 04:44
@Laudron
n9exorcist
@n9exorcist
Feb 16 2016 04:44
challenge: "Introducing JavaScript Object Notation JSON"
rphares
@rphares
Feb 16 2016 04:45
you need a comma in between the two albums, @n9exorcist
kiel barry
@kielbarry
Feb 16 2016 04:45
@n9exorcist your two main objects aren't separated by comma
rphares
@rphares
Feb 16 2016 04:45
in between the two sets of {}
greg
@wearenotgroot
Feb 16 2016 04:45
@george-of-croton YW :smile:
@george-of-croton keep at it!
kiel barry
@kielbarry
Feb 16 2016 04:45
@Laudron so, you're saying that the map function returns the result to the where function, but then the where doesn't know what to do with it?
n9exorcist
@n9exorcist
Feb 16 2016 04:45
@rphares Thank you
CamperBot
@camperbot
Feb 16 2016 04:45
n9exorcist sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2799 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Feb 16 2016 04:46
anytime~
Laudron
@Laudron
Feb 16 2016 04:46

@declanPaz About that:
The method .map( ) for arrays uses a "callback" function to create a new array that is modified by that function ...
For example:

var firstArr = [1, 4, 9];
var secondArr = firstArr.map(function(val) {
    return Math.sqrt(val);
});
// Now the secondArr = [1, 2, 3] and firstArr still = [1, 4, 9]

All this to say, the return statement inside of your map function is creating a new array, not returning a value from the function where(arr, num)

kiel barry
@kielbarry
Feb 16 2016 04:47
whats the name of that array?
Laudron
@Laudron
Feb 16 2016 04:48
@declanPaz Doesn't have one, it is temporary, you would have to assign it to a variable in order to access it by name:
var secondArr = firstArr.map(function(val) {
    return Math.sqrt(val);
});
kiel barry
@kielbarry
Feb 16 2016 04:48
ohhh so i need to save the result of map, i can't just call it
George Armstrong
@george-of-croton
Feb 16 2016 04:48

@Yuvraj1989 i think you should do it more like this

case 1 :
case 2:
case 3:
case 4:
case 5:
case 6:
 count++;
break;

then do that for the rest of the cards then use an if statement to determine if count is > 0 or =- 0 to return the current count and whether to bet or not

kiel barry
@kielbarry
Feb 16 2016 04:48
thanks @laudron ! very helpful
CamperBot
@camperbot
Feb 16 2016 04:48
declanpaz sends brownie points to @laudron :sparkles: :thumbsup: :sparkles:
:star: 321 | @laudron | http://www.freecodecamp.com/laudron
Laudron
@Laudron
Feb 16 2016 04:48
@declanPaz You can just call it, but you would need to use variables outside of the .map( ) method in order to obtain any results IF you do not "save" the results :D
Nahum T
@nahomtefera
Feb 16 2016 05:10
Hey!
I need some help trying to find the longest word
greg
@wearenotgroot
Feb 16 2016 05:11
@declanPaz tip! always read the return value of methods
Nahum T
@nahomtefera
Feb 16 2016 05:11


 function findLongestWord(str) {

  var strSep = str.split(" ");

  var lenWords = [];

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

       lenWords.push(strSep[i].length); 

       console.log(Math.max(lenWords));
   }
}

findLongestWord("The quick brown fox jumped over the lazy dog");
kiel barry
@kielbarry
Feb 16 2016 05:11
@wearenotgroot can you explain that a little?
Nahum T
@nahomtefera
Feb 16 2016 05:12
My function always gives me the length of the first word
greg
@wearenotgroot
Feb 16 2016 05:12
@declanPaz if you look at the docs it will say what the method returns
kiel barry
@kielbarry
Feb 16 2016 05:13
@nahomtefera i'm not the best, but i'd suggest assigning the length of the word to a max variable, and checking that variable to see if the next word length is bigger and should replace the variables value
greg
@wearenotgroot
Feb 16 2016 05:13
@declanPaz an exmple, array.push(item)------> will return the new length of the array
Nahum T
@nahomtefera
Feb 16 2016 05:14
@declanPaz hmmmmmm
i'm going to think about it :)
greg
@wearenotgroot
Feb 16 2016 05:14
@declanPaz or str.split() will return an array and so on
Andrea Nelson
@aerd
Feb 16 2016 05:14
function lookUp(firstName, prop){
// Only change code below this line
if (contacts.firstName === firstName && contacts.hasOwnProperty(prop) === true) {
return contacts[prop];
} else if (contacts.firstName != firstName) {
return "No such contact";
} else {
return "No such property";
}
greg
@wearenotgroot
Feb 16 2016 05:15
@declanPaz in your case the .map() returns an array of the results from the function you feed it
Andrea Nelson
@aerd
Feb 16 2016 05:15
Could someone point me in the right direction of where my code is wrong?
greg
@wearenotgroot
Feb 16 2016 05:15
@declanPaz so you need to capture that or else the result will just not what you are expecting
uriznik
@uriznik
Feb 16 2016 05:16
@aerd what does contacts.firstname refer to?
kiel barry
@kielbarry
Feb 16 2016 05:16
how to create a private convo with someone on here?
Andrea Nelson
@aerd
Feb 16 2016 05:16
which instance?
greg
@wearenotgroot
Feb 16 2016 05:17
@aerd remember .hasOwnProperty will return a boolean value so no need for comparison === true
rphares
@rphares
Feb 16 2016 05:17
you can either hover over their avatar, and click 'chat privately'
yoni chanowitz
@yonichanowitz
Feb 16 2016 05:17
thanks @SaintPeter
CamperBot
@camperbot
Feb 16 2016 05:17
yonichanowitz sends brownie points to @saintpeter :sparkles: :thumbsup: :sparkles:
:star: 2497 | @saintpeter | http://www.freecodecamp.com/saintpeter
rphares
@rphares
Feb 16 2016 05:17
or type /query@username @declanPaz
Rex Schrader
@SaintPeter
Feb 16 2016 05:17
aobut @rphares
kiel barry
@kielbarry
Feb 16 2016 05:17
@rphares thanks
CamperBot
@camperbot
Feb 16 2016 05:17
declanpaz sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2800 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Feb 16 2016 05:17
Anytime!
Rex Schrader
@SaintPeter
Feb 16 2016 05:17
@rphares Daaaaang
@rphares Nice amount of points there.
greg
@wearenotgroot
Feb 16 2016 05:18
@aerd hint! contacts is an array
rphares
@rphares
Feb 16 2016 05:18
lol, @SaintPeter
i could do the same to you, and just refer to the boards ;)
Nahum T
@nahomtefera
Feb 16 2016 05:19
After so many week I got the solution to finding the longest word!!!!
I'm so happy :D :D :D :D :D :D :D
kiel barry
@kielbarry
Feb 16 2016 05:19
post the code?
rphares
@rphares
Feb 16 2016 05:19
(but thanks, @SaintPeter ~)
CamperBot
@camperbot
Feb 16 2016 05:19
rphares sends brownie points to @saintpeter :sparkles: :thumbsup: :sparkles:
:star: 2498 | @saintpeter | http://www.freecodecamp.com/saintpeter
Nahum T
@nahomtefera
Feb 16 2016 05:19
 function findLongestWord(str) {

  var strSep = str.split(" ");

  var lenWords = [];

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

       lenWords.push(strSep[i].length); 


   }

   return Math.max.apply(Math, lenWords);

}

findLongestWord("The quick brown fox jumped over the lazy dog");
:D
kiel barry
@kielbarry
Feb 16 2016 05:20
and now i have learned something new! gonna look up apply()
Nahum T
@nahomtefera
Feb 16 2016 05:20
I have to say the truth, I don't know very well why I had to use apply
But I definetelly want to know it now that it solved my issue :D

The apply function is used to call another function, with a given context and arguments, provided as an array. The min and max functions can take an arbitrary number of input arguments: Math.max(val1, val2, ..., valN)
greg
@wearenotgroot
Feb 16 2016 05:24
@nahomtefera you know you could just have had a variable that hold the current longest length of the items in the strSep
@nahomtefera those extra function calls are just not necessary, because you already loop through the strSep. But that just me, oh well :smile:
greg
@wearenotgroot
Feb 16 2016 05:30
@nahomtefera glad you learned .apply, anyways here is a simplier approach
 function findLongestWord(str) {

  var strSep = str.split(" ");

  var lenWords = 0;

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

       if(strSep[i].length > lenWords) //<------------test the current value of lenWords againts the current item's length, updates if the currents item's lenght is greater 
       {
             lenWords = strSep[i].length;
       }


   }

   return lenWords;

}
Andrea Nelson
@aerd
Feb 16 2016 05:33
still having issues.
function lookUp(firstName, prop){
// Only change code below this line
for (var x = 0; x < contacts.length; x++){
if (contacts[x].firstName === firstName && contacts.hasOwnProperty(prop)) {
for (var y = 0; y < contacts[x].length; y++) {
return contacts[x][y]; }
} else if (contacts[x].firstName != firstName) {
return "No such contact";
} else {
return "No such property";
}
}
greg
@wearenotgroot
Feb 16 2016 05:34
@aerd that second for loop is not necessay btw
Andrea Nelson
@aerd
Feb 16 2016 05:34
I cant get it to work with just one either.
greg
@wearenotgroot
Feb 16 2016 05:34
@aerd the first for loop helps you access the items/objects at a certain index
@aerd while the prop will help you access the property values inside the array item
Andrea Nelson
@aerd
Feb 16 2016 05:36
yep, not understanding.
greg
@wearenotgroot
Feb 16 2016 05:36
@aerd
for (var x = 0; x < contacts.length; x++){
if (contacts[x].firstName === firstName && contacts.hasOwnProperty(prop)) {
for (var y = 0; y < contacts[x].length; y++) { //<----------------------remove me
return contacts[x][y]; }
} else if (contacts[x].firstName != firstName) {   //<-----------reconsider this else if
return "No such contact";
} else {
return "No such property";
}
}
Nahum T
@nahomtefera
Feb 16 2016 05:37
@wearenotgroot thanks! :D :D that gives me a better perspective
CamperBot
@camperbot
Feb 16 2016 05:37
nahomtefera sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 858 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
greg
@wearenotgroot
Feb 16 2016 05:38
@nahomtefera :+1:
Andrea Nelson
@aerd
Feb 16 2016 05:38
I already removes that one. "no such contact" and "no such propery" are coming back fine, but I am not getting this portion: if (contacts[x].firstName === firstName && contacts.hasOwnProperty(prop)) {
return contacts[prop];
*removed
greg
@wearenotgroot
Feb 16 2016 05:39
@aerd it fine you are just not accessing it properly
@aerd should be contacts[x][prop]
@aerd remember the target value you are after is dependent on the property name which is store in prop parameter
Andrea Nelson
@aerd
Feb 16 2016 05:41
could you explain that? The instructions say return "value", but property is a level up?
(prop)
greg
@wearenotgroot
Feb 16 2016 05:41
@aerd ^
Andrea Nelson
@aerd
Feb 16 2016 05:42
Maybe I am not understanding the levels properly. Thanks for your help @wearenotgroot.
CamperBot
@camperbot
Feb 16 2016 05:42
aerd sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 859 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
greg
@wearenotgroot
Feb 16 2016 05:42
@aerd ok lets look at contacts
Andrea Nelson
@aerd
Feb 16 2016 05:43
This message was deleted
greg
@wearenotgroot
Feb 16 2016 05:43
@aerd here is contacts
contacts is an array that contains objects. to access the items on the array we use index(a for loop with index)
var contacts = [
    {
        "firstName": "Akira",               //<-------------------------will be access at index 0,  contacts[0], now to access the values of a given property let's say prop="likes", you just do contacts[0][prop]-------------> will give you  ["Pizza", "Coding", "Brownie Points"]
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    },
];
Andrea Nelson
@aerd
Feb 16 2016 05:43
This message was deleted
This message was deleted
for (var x = 0; x < contacts.length; x++) which this does?
greg
@wearenotgroot
Feb 16 2016 05:46
@aerd remember contacts[x].hasOwnProperty(prop) not contacts.hasOwnProperty(prop)
@aerd remember contacts is an array and not an object
Andrea Nelson
@aerd
Feb 16 2016 05:47
that just returns the first likes array
greg
@wearenotgroot
Feb 16 2016 05:47
@aerd you need to be testing the item inside it if a certain property exist
@aerd if you try ----------> contacts[0][prop] where prop = 'lastName' you will get Laine
Andrea Nelson
@aerd
Feb 16 2016 05:48
I am lost.
greg
@wearenotgroot
Feb 16 2016 05:50

@aerd what you did wrong was

contacts.hasOwnProperty(prop) //<--------tested the array itself for property prop instead of items in it

should do

contacts[x].hasOwnProperty(prop) //<----------------testing the item on index x for property prop

just like

contacts[x].firstName //<----this is equal to contacts[x]['firstName']
Andrea Nelson
@aerd
Feb 16 2016 05:52
I tried that already, it doesn't work.
greg
@wearenotgroot
Feb 16 2016 05:53
@aerd well this is the correct test
@aerd however
@aerd you are getting the wrong result because of the else if right after the if (contacts[x].firstName === firstName && contacts[x].hasOwnProperty(prop))
@aerd this guy
} else if (contacts[x].firstName != firstName) {   //<-----------reconsider this else if
return "No such contact"; //<------rememeber what return does to the function!!!!!!
@aerd think about what happens if the first if statement is false(meaning the firstName of contact at index x is not equal to fristName)?
Andrea Nelson
@aerd
Feb 16 2016 05:59
Then why are these coming back correct?
"Bob", "number" should return "No such contact"
"Akira", "address" should return "No such property"
greg
@wearenotgroot
Feb 16 2016 06:00
@aerd post you updated code
@aerd also try with "Harry"
@aerd and see what happens
Andrea Nelson
@aerd
Feb 16 2016 06:01
for (var x = 0; x < contacts.length; x++){
if (contacts[x].firstName === firstName && contacts[x].hasOwnProperty(prop)) {
return contacts[x][prop];
} else if (contacts[x].firstName != firstName) {
return "No such contact";
} else {
return "No such property";
}
}
greg
@wearenotgroot
Feb 16 2016 06:03
@aerd try the firstName "Harry" or "Sherlock"
if you try with ->lookUp("Akira", "likes");--->you get ------>["Pizza", "Coding", "Brownie Points"]
@aerd if you try a property that doesnt exist then it will return "No such property"

@aerd what is happening is the else if

} else if (contacts[x].firstName != firstName) {   //<-----------reconsider this else if
return "No such contact"; //<------rememeber what return does to the function!!!!!!

is returning "No such contact" too early!!!!!

@aerd it nevers goes through the entire contact list after comparing the firstName of the contact at index 0
@aerd so if you tried with "Harry" as firstName(we know that Harry exist) the test never gets to examine the next contact on the list
Andrea Nelson
@aerd
Feb 16 2016 06:09
I understand it's not going through the list. That doesn't help me.
greg
@wearenotgroot
Feb 16 2016 06:09
@aerd it will, because now you can fixed the problem
@aerd first step is always to identify what the problem is
@aerd then find the solution
Michael Aubrey
@mca62511
Feb 16 2016 06:12

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

// Change these values to test your function
lookUp("Akira", "likes");
This is my solution to the Profile Lookup lesson... and it works... but I'm not super confident, and I just want to check to make sure I did this in the best way possible.
greg
@wearenotgroot
Feb 16 2016 06:12
@mca62511 looks good
@mca62511 can be improve by restructuring the if statement to be more human readable and avoid redundant tests
Andrea Nelson
@aerd
Feb 16 2016 06:16
This guy's doesn't make sense to me either.
greg
@wearenotgroot
Feb 16 2016 06:16
@aerd how long have you been stuck on this one? if you been stuck on this for a while, maybe it's time to take a break and have a fresh look at the problem
uriznik
@uriznik
Feb 16 2016 06:16
@mca62511 it could fail if a contact had a boolean property set to false and it would think there is no property
greg
@wearenotgroot
Feb 16 2016 06:17
@mca62511 oh yeah always use .hasOwnPropety to test if a given property exist or not
Michael Aubrey
@mca62511
Feb 16 2016 06:18
Thanks @wearenotgroot and @uriznik -- I don't think I've been taught .hasOwnProperty yet. or I just don't remember it, but that is useful. I think the lesson wants me to do i < contacts.length for the loop and I thought I'd just be clever by doing contacts[i][prop]
CamperBot
@camperbot
Feb 16 2016 06:18
mca62511 sends brownie points to @wearenotgroot and @uriznik :sparkles: :thumbsup: :sparkles:
:star: 285 | @uriznik | http://www.freecodecamp.com/uriznik
greg
@wearenotgroot
Feb 16 2016 06:19
@mca62511 you have used .hasOwnProperty on the previous lessons
CamperBot
@camperbot
Feb 16 2016 06:19
api offline
Michael Aubrey
@mca62511
Feb 16 2016 06:20
I don't think what I said makes sense :P
okay, then I just don't remember it, thank you
so I'd use contacts[i].hasOwnProperty(prop) ?
greg
@wearenotgroot
Feb 16 2016 06:21
@mca62511 yes
Michael Aubrey
@mca62511
Feb 16 2016 06:21
would !contacts[i].hasOwnProperty(prop) also work for "not" basically?
uriznik
@uriznik
Feb 16 2016 06:23
yes
greg
@wearenotgroot
Feb 16 2016 06:23
@mca62511 here is the challenge title where you used .hasOwnProperty : Testing Objects for Properties
Michael Aubrey
@mca62511
Feb 16 2016 06:24
Oh, thanks! I wasn't doubting you though, just doubting my memory.
I appreciate you hunting that down.
greg
@wearenotgroot
Feb 16 2016 06:24
@mca62511 np just linking relevant items
Michael Aubrey
@mca62511
Feb 16 2016 06:31
Oh boy, Regular Expressions incoming. I'm scared. :worried:
I don't have any experience with regular expressions, I've just hear people talk about them like they're the boogie man.
Michael Aubrey
@mca62511
Feb 16 2016 06:37
Actually the concept itself doesn't seem hard to grasp or anything. I guess it just much be difficult to memorize different selectors and the like?
uriznik
@uriznik
Feb 16 2016 06:38
they can get complex and get overused when the base language doesn't have other means of parsing complicated text
Michael Aubrey
@mca62511
Feb 16 2016 06:39
Ah
rootbox
@rootbox
Feb 16 2016 06:42
hi guys
simonmcho
@simonmcho
Feb 16 2016 06:44
hello
i have a quick code question
function mutation(arr) {
  var firstEntry = arr[0].toLowerCase().split("");
  var secondEntry = arr[1].toLowerCase().split("");
  var searchResult = 0;

  for (var i in secondEntry) {
    if (firstEntry.indexOf(secondEntry[i]) > -1) {
        searchResult += 0;
        }
        else {
        searchResult += 1;
        }
    if (searchResult === 0) {
      return true;
    }
    else {
      return false;
    }
  }
}

mutation(["hello", "hey"]);
Michael Aubrey
@mca62511
Feb 16 2016 06:46
@uriznik Okay, thanks. They're scary again :P
CamperBot
@camperbot
Feb 16 2016 06:46
mca62511 sends brownie points to @uriznik :sparkles: :thumbsup: :sparkles:
:warning: mca62511 already gave uriznik points
rootbox
@rootbox
Feb 16 2016 06:47
what's the brownie point?
sugarchuck
@sugarchuck
Feb 16 2016 06: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!"
  }

  return "Change Me";
  // Only change code above this line
}

// Change these values to test
golfScore(4, 4);
what am i doing wrong?
uriznik
@uriznik
Feb 16 2016 06:53
@sugarchuck do you know any other programmins languages? testing for equality may be different than you're used to
sugarchuck
@sugarchuck
Feb 16 2016 06:53
no i dont
uriznik
@uriznik
Feb 16 2016 06:54
@sugarchuck does it mostly return 'birdie'?
kirbyedy
@kirbyedy
Feb 16 2016 06:55
= means assign, == means equal
sugarchuck
@sugarchuck
Feb 16 2016 06:55
yes
kirbyedy
@kirbyedy
Feb 16 2016 06:55
so whenever you used = you were asigning the value
which is not what you want... I think :)
sugarchuck
@sugarchuck
Feb 16 2016 06:56
@kirbyedy thanks!!! i used == and it passed
CamperBot
@camperbot
Feb 16 2016 06:56
sugarchuck sends brownie points to @kirbyedy :sparkles: :thumbsup: :sparkles:
:star: 476 | @kirbyedy | http://www.freecodecamp.com/kirbyedy
kirbyedy
@kirbyedy
Feb 16 2016 06:57
also this is a bit dodgy (strokes<=1)
because you cant really hit the hole in 0 can you ? :)
sugarchuck
@sugarchuck
Feb 16 2016 06:57
yeah. youre right
kirbyedy
@kirbyedy
Feb 16 2016 06:58
test your code, write 1 in the golfscore at the bottom, see what happens
uriznik
@uriznik
Feb 16 2016 07:00
there's also a difference between == and === (strict equality), so 4 == '4' is true but 4 === '4' is false
Andrea Nelson
@aerd
Feb 16 2016 07:01
can someone tell me if I am on the right track with my else if statement? I'm not going to be able to sleep till I get this. for (var x = 0; x < contacts.length; x++){
if (contacts[x].firstName === firstName && contacts[x].hasOwnProperty(prop)) {
return contacts[x][prop];
} else if (contacts[x].hasOwnProperty(prop) && contacts[x].firstName != firstName) {
return "No such contact";
} else {
return "No such property";
}
}
rphares
@rphares
Feb 16 2016 07:02
@rootbox
explain brownie
CamperBot
@camperbot
Feb 16 2016 07:03

:point_right: brownie points [wiki]

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

A user profile picture next to a with Brownie Points score

There are three ways you can get Brownie Points:

  1. Complete challenges - you get one point per challenge you complete
  2. Post relevant links on Camper News - you get 1 point for posting a link, and another point for each upvote your link gets
  3. Help other campers in chat - each time you help another camper and they thank you (by typing "thanks @yourname"), you will get a point

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

They also add to your Streak.
:pencil: read more about brownie points on the FCC Wiki

rootbox
@rootbox
Feb 16 2016 07:04
@rphares thanks for helping me
CamperBot
@camperbot
Feb 16 2016 07:04
rootbox sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star: 2802 | @rphares | http://www.freecodecamp.com/rphares
rphares
@rphares
Feb 16 2016 07:04
anytime! Happy coding~
uriznik
@uriznik
Feb 16 2016 07:05
@aerd first if statement looks correct but the others aren't
SuhasHosamani
@SuhasHosamani
Feb 16 2016 07:05

Hi All

```
function end(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
last = str.length - 1;
lastChar = str.substr(last, 1);
if(lastChar === target){
return true;
}else{
return false;
}

}

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

kirbyedy
@kirbyedy
Feb 16 2016 07:06
:penguin: in the house, :wave:
bitgrower
@bitgrower
Feb 16 2016 07:06
hello @kirbyedy
SuhasHosamani
@SuhasHosamani
Feb 16 2016 07:06

Hi All

function end(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
 last = str.length - 1;
 lastChar = str.substr(last, 1);
  if(lastChar === target){
    return true;
  }else{
    return false;
  }

}

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

how to check for word?? i did for character its working

kirbyedy
@kirbyedy
Feb 16 2016 07:06
hey, hi, did not see you there @bitgrower
rphares
@rphares
Feb 16 2016 07:07
Aw, thanks @kirbyedy ~
CamperBot
@camperbot
Feb 16 2016 07:07
rphares sends brownie points to @kirbyedy :sparkles: :thumbsup: :sparkles:
:star: 477 | @kirbyedy | http://www.freecodecamp.com/kirbyedy
rphares
@rphares
Feb 16 2016 07:07
I'm actually heading out now, but appreciate the greeting! :)
bitgrower
@bitgrower
Feb 16 2016 07:07
lurking ... pulling my hair out a bit on Exact Change & also, unaccountably, the tribute ...
Andrea Nelson
@aerd
Feb 16 2016 07:07
i know my else if is wrong. but, i don't know the right direction.
rphares
@rphares
Feb 16 2016 07:07
(hi and ttyl, @bitgrower ! :blush: )
Vinícius
@vinicius978
Feb 16 2016 07:07
How to Iterate over Arrays with map()?
kirbyedy
@kirbyedy
Feb 16 2016 07:08
oh crap, I saw those challenges at the end, they are scary :worried:
bitgrower
@bitgrower
Feb 16 2016 07:08

2 quarters of web design (over 10 years ago), does not prepare me for bootstrap ... LOL ...

Even though I used to make all kinds of cool sales pages in html/css ...

rphares
@rphares
Feb 16 2016 07:08
lol, @kirbyedy
kirbyedy
@kirbyedy
Feb 16 2016 07:08
lol
rphares
@rphares
Feb 16 2016 07:08
@vinicius978 , can you paste your code? I'm sure someone may be able to help you :blush:
bitgrower
@bitgrower
Feb 16 2016 07:09
have a good one, @rphares ... wait, I think I'm the one who should be leaving ... it's 11pm here ...
rphares
@rphares
Feb 16 2016 07:09
Eek-- rest well!
bitgrower
@bitgrower
Feb 16 2016 07:09
@vinicius978 -- what @rphares asked ... and...what are you trying to do ...
Vinícius
@vinicius978
Feb 16 2016 07:09
Sure, I'm going to paste
Kai Schoos
@skusku
Feb 16 2016 07:09
o/
bitgrower
@bitgrower
Feb 16 2016 07:10
well I don't know which overseas you are at, but if you are in Europe, it's surely MUCH later(earlier)
SuhasHosamani
@SuhasHosamani
Feb 16 2016 07:10
Guys
bitgrower
@bitgrower
Feb 16 2016 07:10
@vinicius978 -- please follow @camperbot's instructions ...
explain format
CamperBot
@camperbot
Feb 16 2016 07:10

:point_right: code formatting [wiki]

Inline code

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

Code Block

```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 ⏎]

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

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

budimanfix
@budimanfix
Feb 16 2016 07:10

@aerd this is work but still left two task : for (var i = 0; contacts[i]; i++){
if (contacts[i].firstName === firstName && contacts[i][prop]){
return contacts[i][prop];

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

return "no such contact";
}

bitgrower
@bitgrower
Feb 16 2016 07:10
I should give a prize to the first person who follows those instructions EXACTLY ...
kirbyedy
@kirbyedy
Feb 16 2016 07:11
lol
exactly
maybe its a riddle
Abhishek Kumar
@abhishekKumar1
Feb 16 2016 07:11
haha
kirbyedy
@kirbyedy
Feb 16 2016 07:11
to see if you are a good material for programmer :D
bitgrower
@bitgrower
Feb 16 2016 07:12
@SuhasHosamani -- I recommend -- HIGHLY recommend -- you use console.log and look at intermediate values ... because I think you can figure this out without a HUGE amount of effort ... when you see the numbers, I think something might occur to you .. :)
Michael Aubrey
@mca62511
Feb 16 2016 07:12

Okay, so now I'm at Sort Arrays with .sort

I was able to complete the lesson, again, but this time I'm not sure if I really understand why or what is going on. This is what I ended up with to sort the array from largest to smallest.

var array = [1, 12, 21, 2];

// Only change code below this line.

array.sort(function(a, b) {
  return b - a;
});

The original had a - b, which made it go from smallest to largest, I changed it to b - a, and that switched it.

~~But why? I feel like I'm missing something. ~~

edit: figured it out, i think

Vinícius
@vinicius978
Feb 16 2016 07:12
var oldArray = [1,2,3,4,5];

var timesThree = oldArray.map(
  function()
{

      return oldArray += 3;

});
// Only change code below this line.

var newArray = oldArray;
Brian
@sludge256
Feb 16 2016 07:12
:dog:
dang I was too slow :(
bitgrower
@bitgrower
Feb 16 2016 07:12
@kirbyedy -- that thought has definitely occurred to me ...
hahahahahaha ...
Michael Aubrey
@mca62511
Feb 16 2016 07:13
I'll start reading this, but if anyone has an easy explanation let me know. http://www.w3schools.com/jsref/jsref_sort.asp
Vinícius
@vinicius978
Feb 16 2016 07:13
<The objective is to add 3 to every value of the oldArray>
budimanfix
@budimanfix
Feb 16 2016 07:13

@abhishekKumar1 what i miss here, two task left for this challnge : for (var i = 0; contacts[i]; i++){
if (contacts[i].firstName === firstName && contacts[i][prop]){
return contacts[i][prop];

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

return "no such contact";
}

Andrea Nelson
@aerd
Feb 16 2016 07:14
@budimanfix what?
Vinícius
@vinicius978
Feb 16 2016 07:14
@budimanfix paste your whole code
@budimanfix in the for() your variable i should go from 0 to the length of the array contacts
Michael Aubrey
@mca62511
Feb 16 2016 07:15
Okay, got it. I understand it now from reading w3schools (I think).
bitgrower
@bitgrower
Feb 16 2016 07:15
@mca62511 -- basically, if the value is negative it does one thing, if it's positive it does another ...
budimanfix
@budimanfix
Feb 16 2016 07:15
@aerd only left two task : "Bob", "number" should return "No such contact"
"Akira", "address" should return "No such property"
SuhasHosamani
@SuhasHosamani
Feb 16 2016 07:16
@bitgrower yeh got the ans
function end(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  if(target.length > 1){
    targetLast = target.length;
     last = (str.length) - targetLast;
     lastChar = str.substr(last, targetLast);
  }else{
     last = str.length - 1;
     lastChar = str.substr(last, 1);
  }

  if(lastChar === target){
    return true;
  }else{
    return false;
  }

}

end("He has to give me a new name", "name");
bitgrower
@bitgrower
Feb 16 2016 07:16
so ... figure out which one it is ... whether, if it's negative, it swaps the 2 values or positive ... :)
SuhasHosamani
@SuhasHosamani
Feb 16 2016 07:16
:smile:
@bitgrower but not sure if thats the best way.....
uriznik
@uriznik
Feb 16 2016 07:16
@aerd you have a test for firstname match and has property is true, then you need one for firstname match and has property is false
bitgrower
@bitgrower
Feb 16 2016 07:16
EXCELLENT, @SuhasHosamani ... I knew you could get this one without help ... :)
budimanfix
@budimanfix
Feb 16 2016 07:17
@vinicius978 Example plz?
bitgrower
@bitgrower
Feb 16 2016 07:17
@SuhasHosamani -- you can almost always do things better ... FIRST get the code to work ... then worry about making better ...
Abhishek Kumar
@abhishekKumar1
Feb 16 2016 07:17
@budimanfix i can't understand your elseif condition what are you trying to compare?
bitgrower @bitgrower has written some challenges 2 or 3 times as she's learned more ... :)
kirbyedy
@kirbyedy
Feb 16 2016 07:18
the answer with 38 upvotes
bitgrower
@bitgrower
Feb 16 2016 07:18
there ARE some very brief solutions ... esp if you use ES6 ... :)
budimanfix
@budimanfix
Feb 16 2016 07:18
@abhishekKumar1 I just trying and and now only left two point on task : "Bob", "number" should return "No such contact"
"Akira", "address" should return "No such property"
SuhasHosamani
@SuhasHosamani
Feb 16 2016 07:19
@bitgrower koole :+1:
bitgrower
@bitgrower
Feb 16 2016 07:19
@vinicius978 -- you need to provide your callback function with a parameter ... that parameter will be used to iterate over the values in the array ...
I think there's an example ?!?
in the challenge description ... ?
Michael Aubrey
@mca62511
Feb 16 2016 07:20

@kirbyedy @bitgrower Thanks, I appreciate it, but I do think I have it now. The equation is what it uses to decide how to sort things. It passes two values from the array into a and b. It runs the equation, and based on whether or not it returns a negative or positive it sorts it as higher or lower in the array.

I'll take a look at that answer anyway just in case.

CamperBot
@camperbot
Feb 16 2016 07:20
mca62511 sends brownie points to @kirbyedy and @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 478 | @kirbyedy | http://www.freecodecamp.com/kirbyedy
:star: 537 | @bitgrower | http://www.freecodecamp.com/bitgrower
Andrea Nelson
@aerd
Feb 16 2016 07:20
for (var x = 0; x < contacts.length; x++){
  if (contacts[x].firstName === firstName && contacts[x].hasOwnProperty(prop)) {
    return contacts[x][prop];
  } else if (contacts[x].firstName === firstName && !contacts[x][prop]) {
    return "No such contact";
  } else {
    return "No such property";
  }
}
?
budimanfix
@budimanfix
Feb 16 2016 07:21
@aerd that " !" dosn't work bro
bitgrower
@bitgrower
Feb 16 2016 07:23
awesome @mca62511 !
greg
@wearenotgroot
Feb 16 2016 07:24
@aerd read your private chat
budimanfix
@budimanfix
Feb 16 2016 07:24
@aerd erase that " ! "behind contacts and you gor 3 point right
bitgrower
@bitgrower
Feb 16 2016 07:27
@SuhasHosamani you could probably eliminate a few variables ... if you actually plot out some simple examples, as well, some other solutions may occur to you as well ... :)
Vinícius
@vinicius978
Feb 16 2016 07:42
@bitgrower @budimanfix the example is var timesFour = oldArray.map(function(val){ return val * 4; });
bitgrower
@bitgrower
Feb 16 2016 07:43
right, and, instead, you want to add 3 to each value, right ?
change 2 characters & you have the solution ... :)
Bryce Turner
@AbryceT
Feb 16 2016 07:44
@brainyfarm Unfortunately no. I am still completely stumped on it.
Ashley
@asberrie
Feb 16 2016 07:46
This message was deleted

ok, so I totally feel like I'm missing something. I'm working on Accessing Nested Arrays in JSON but keep getting the error "ReferenceError: Can't find the variable: type"
This is what I have so far:
```
// Setup
var myPlants = [
{
type: "flowers",
list: [
"rose",
"tulip",
"dandelion"
]
},
{
type: "trees",
list: [
"fir",
"pine",
"birch"
]
}
];

// Only change code below this line

var secondTree = myPlants.type1.list1; // Change this line

Bryce Turner
@AbryceT
Feb 16 2016 07:48
So here we go again.. I have been stuck on this one for four days and getting no closer to a solution. The Record Collection...help?
// 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) {
  for (collection[id].prop.value;  value !=="";)
        if (collection.prop != "tracks" && collection[prop].hasOwnProperty(value)); 
     collection.id.prop = "";
  }else if (collection.prop = "tracks" && collection[value].hasOwnProperty(value));
     collection.push([value]);
  return collection;
}


// Alter values below to test your code
update(5439, "artist", "ABBA");
Ashley
@asberrie
Feb 16 2016 07:49

ok, so I totally feel like I'm missing something. I'm working on Accessing Nested Arrays in JSON but keep getting the error "ReferenceError: Can't find the variable: type"
This is what I have so far (the goal is: Retrieve the second tree from the variable myPlants using object dot and array bracket notation.):

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

// Only change code below this line

var secondTree = myPlants.type[1].list[1]; // Change this line

Any help would be greatly appreciated! Thanks :)

Kai Schoos
@skusku
Feb 16 2016 07:50
@asberrie so... what's inside myPlants? Keep close track of the opening parans, brackets and what have yoiu
Ashley
@asberrie
Feb 16 2016 07:52
@skusku inside myPlants is two types of plants; flowers (at index 0) and trees (at index 1) - which is why I have what I have
or that's at least how I'm understanding it (which at this point may be wrong)
Kai Schoos
@skusku
Feb 16 2016 07:54
what is myPlants, programatically speaking ? ( Object, Variable, Array...)
Michael Aubrey
@mca62511
Feb 16 2016 07:54
If I'm unsure about the appropriateness of my correct answer, is it kosher to post it here and ask as I've been doing? It's been instructive for me to receive feedback, but at the same time I don't know how appropriate it is since I'm basically posting answers.
Ashley
@asberrie
Feb 16 2016 07:54
i think it's an object (but really want to say an array)
Kai Schoos
@skusku
Feb 16 2016 07:55
[ ] <- array {} <- object
theres more to it but thats one way to see it fast
Michael Aubrey
@mca62511
Feb 16 2016 07:56

For example, I just did Reverse a String.

I came up with this

function reverseString(str) {
  return str.split("").reverse().join("");
}
reverseString("hello");

And it passes. Just wondering if this is the right way to go about it. ...but if I keep asking questions like this then it is basically giving away answers.

Kai Schoos
@skusku
Feb 16 2016 07:56
so myPlants is an .... of ... ? @asberrie
Yuvraj Adagale
@Yuvraj1989
Feb 16 2016 07:56
@asberrie var secondTree = myPlants1.list1;
try this
Ashley
@asberrie
Feb 16 2016 07:57
@skusku ok, so since it's got the [] after the assignment operator, it's an array
Kai Schoos
@skusku
Feb 16 2016 07:57
right
Yuvraj Adagale
@Yuvraj1989
Feb 16 2016 07:57
@asberrie var secondTree = myPlants1.list1;
cannelflow
@cannelflow
Feb 16 2016 07:58
@Yuvraj1989 don't just throw answer
here
try to explain it first
Bryce Turner
@AbryceT
Feb 16 2016 07:58
Any help on the record collection?
Yuvraj Adagale
@Yuvraj1989
Feb 16 2016 07:58
@cannelflow okies
cannelflow
@cannelflow
Feb 16 2016 07:58
@Yuvraj1989 :+1:
Ashley
@asberrie
Feb 16 2016 07:58

ok, so the way to access data in an array is
arrayName[indexPosition], correct?

I don't understand @Yuvraj1989 's answer anyway, so trying to understand why that's different and correct

Kai Schoos
@skusku
Feb 16 2016 07:59
@asberrie it's an array of 2 objects [{...},{...}] . An array has no properties, therefor you cant access it over properties but only over the index. So if you want the first object of the array you do myPlants[1]
Ashley
@asberrie
Feb 16 2016 07:59
BTW, thanks for everyone's help :)
Kai Schoos
@skusku
Feb 16 2016 07:59
@asberrie exactly
Spencer Kuzara
@kodaxx
Feb 16 2016 08:00
@asberrie you are correct
Yuvraj Adagale
@Yuvraj1989
Feb 16 2016 08:00
@asberrie see inside myPlants there are two objects
Spencer Kuzara
@kodaxx
Feb 16 2016 08:00
@Yuvraj1989 you gotta let her work through it lol
Ashley
@asberrie
Feb 16 2016 08:01
I was wondering why there was no square brackets (they weren't showing up correctly at first here)
Kai Schoos
@skusku
Feb 16 2016 08:01
yes ^^ gotta use the code thingy
Spencer Kuzara
@kodaxx
Feb 16 2016 08:01
Technically, coffee should be put inside the format
Thingy
Ashley
@asberrie
Feb 16 2016 08:01
ok, so it would be myPlants[1][1]?
Spencer Kuzara
@kodaxx
Feb 16 2016 08:01
Code*
Not coffee, but closely related lol
Kai Schoos
@skusku
Feb 16 2016 08:02
@asberrie not quite, you are jumping some steps
cannelflow
@cannelflow
Feb 16 2016 08:02
@mca62511 yes it is good
uriznik
@uriznik
Feb 16 2016 08:02
@AbryceT check your private chat
Michael Aubrey
@mca62511
Feb 16 2016 08:02
@cannelflow thanks
CamperBot
@camperbot
Feb 16 2016 08:02
mca62511 sends brownie points to @cannelflow :sparkles: :thumbsup: :sparkles:
:star: 807 | @cannelflow | http://www.freecodecamp.com/cannelflow
Yuvraj Adagale
@Yuvraj1989
Feb 16 2016 08:02
@asberrie these two objects in array are also arrays
Spencer Kuzara
@kodaxx
Feb 16 2016 08:02
@asberrie why not try to return myPlants1
Kai Schoos
@skusku
Feb 16 2016 08:02
nah, objects are objects and arrays are arrays @Yuvraj1989
Spencer Kuzara
@kodaxx
Feb 16 2016 08:03
And see what you get
Sorry, with the brackets of course
Kai Schoos
@skusku
Feb 16 2016 08:03
good thought @kodaxx
Ashley
@asberrie
Feb 16 2016 08:03
oh! i finally get what @Yuvraj1989 was saying
first, get the item in the first array, then using dot notation, get the item from the nested array inside that
Yuvraj Adagale
@Yuvraj1989
Feb 16 2016 08:03
@asberrie exactly
Ashley
@asberrie
Feb 16 2016 08:04
Phew! Thank you again everyone! I appreciate it! :+1: @skusku @Yuvraj1989 @kodaxx
CamperBot
@camperbot
Feb 16 2016 08:04
asberrie sends brownie points to @skusku and @yuvraj1989 and @kodaxx :sparkles: :thumbsup: :sparkles:
:star: 222 | @yuvraj1989 | http://www.freecodecamp.com/yuvraj1989
:star: 340 | @skusku | http://www.freecodecamp.com/skusku
:star: 273 | @kodaxx | http://www.freecodecamp.com/kodaxx
Spencer Kuzara
@kodaxx
Feb 16 2016 08:04
@asberrie you can think of it that way, but what you are actually doing is accessing the first object in the array and then accessing that objects nth property
Ashley
@asberrie
Feb 16 2016 08:05
@kodaxx gotcha
Spencer Kuzara
@kodaxx
Feb 16 2016 08:05
It's not technically a nested array, but an array of objects. Those objects have properties that can be accessed as well
But whatever helps you understand the concept, I suppose you should use that lol
Kai Schoos
@skusku
Feb 16 2016 08:06
@kodaxx not quite. access second entry in the array -> access property called list (which is an array) -> access second entry in list-array
Spencer Kuzara
@kodaxx
Feb 16 2016 08:06
@skusku ahh yes, thank you for the correction
CamperBot
@camperbot
Feb 16 2016 08:06
kodaxx sends brownie points to @skusku :sparkles: :thumbsup: :sparkles:
:star: 341 | @skusku | http://www.freecodecamp.com/skusku
Kai Schoos
@skusku
Feb 16 2016 08:06
this must be the most friendly place in the entire internet ^
^*
Spencer Kuzara
@kodaxx
Feb 16 2016 08:07
Because of camperbot? Lol
Kai Schoos
@skusku
Feb 16 2016 08:08
jk :)
Spencer Kuzara
@kodaxx
Feb 16 2016 08:08
Sending brownie points everywhere haha
Kai Schoos
@skusku
Feb 16 2016 08:08
haha yeah :D
Spencer Kuzara
@kodaxx
Feb 16 2016 08:10
Returning things intermediately helped me understand what was happening, so I usually recommend it to others. When a piece of it clicks for them, I have them return it and see what it says. Usually it clicks what to do next without my help lol
Not that I'm a great teacher by any means. Sometimes my English is horrible
Kai Schoos
@skusku
Feb 16 2016 08:10
@AbryceT still struggling ? You should maybe rethink what you want to do in that update function and what you are actually doing
@kodaxx your english is awesome :)
Spencer Kuzara
@kodaxx
Feb 16 2016 08:11
You really think so?
Kai Schoos
@skusku
Feb 16 2016 08:12
yep
Spencer Kuzara
@kodaxx
Feb 16 2016 08:13
Thanks, I try!
I always forget to mention MDN. I think FCC should bring it to focus earlier in the program
I think they bring it about during the basic algorithm scripting, or before the basic front end projects.
But it should be much earlier in my opinion
Kai Schoos
@skusku
Feb 16 2016 08:15
using google is a big thing :P so much good information out in the webs
Spencer Kuzara
@kodaxx
Feb 16 2016 08:15
Yes! One must be careful not to Google the exact answer, though. Lol
I mean in a very literal sense, "Free Code Camp Record Collection Challenge Answer" lol... That's a no no
Kai Schoos
@skusku
Feb 16 2016 08:16
ah yeah haha
Spencer Kuzara
@kodaxx
Feb 16 2016 08:17
Then you will remember what your teachers have always told you, "You're only cheating yourself."
greg
@wearenotgroot
Feb 16 2016 08:23
@skusku yes always consult your docs
@skusku both in health and js
:smile:
Kai Schoos
@skusku
Feb 16 2016 08:24
haha :D
Michael Aubrey
@mca62511
Feb 16 2016 08:27
This time I'm sure there's got to be a more elegant solution
function factorialize(num) {
  if (num < 0) { return "You cannot factorialize a negative number."; }
  var factors = [1];
  for (var i = 2; i <= num; i++) {
    factors.push(i);
  }
  num = factors.reduce(function(previousVal, currentVal) {
    return previousVal * currentVal;
  });
  return num;
}

factorialize(5);
kirbyedy
@kirbyedy
Feb 16 2016 08:32
I think I just initialised the variable to 1, then looped until num and each time multiplied it
greg
@wearenotgroot
Feb 16 2016 08:33
@mca62511 so sorry to bust your bubble again
@mca62511 but no need for that reduces :smile:
@mca62511 you can directly get the result on the for loop :+1:
JackeL
@jackel27
Feb 16 2016 08:34
Hi world!
CamperBot
@camperbot
Feb 16 2016 08:34

welcome to FreeCodeCamp @jackel27!

kirbyedy
@kirbyedy
Feb 16 2016 08:34
hi @jackel27
greg
@wearenotgroot
Feb 16 2016 08:34
@jackel27 Welcome!
JackeL
@jackel27
Feb 16 2016 08:34
Hi @kirbyedy
Question
what is the difference between a class and a constructor?
for example...
function Person(name,age) {
  this.name = name;
  this.age = age;
}
class... or constructor?
uriznik
@uriznik
Feb 16 2016 08:37
@mca62511 you're already doing a loop so might as well just compute it in their
greg
@wearenotgroot
Feb 16 2016 08:38
@jackel27 there really isnt a class in js per say
@jackel27 on other programming language like java and c# for instance
JackeL
@jackel27
Feb 16 2016 08:39
@wearenotgroot so confused why it even exists.. objects, classes, functions and constructors all seem to blend in...
greg
@wearenotgroot
Feb 16 2016 08:39
@jackel27 Person is considered a class
JackeL
@jackel27
Feb 16 2016 08:39
ok,
so between {} is the constructor @wearenotgroot ?
greg
@wearenotgroot
Feb 16 2016 08:39
@jackel27 and a class have a constructor inside
JackeL
@jackel27
Feb 16 2016 08:40
@wearenotgroot so with no constructor, its just a function/method?
greg
@wearenotgroot
Feb 16 2016 08:40
@jackel27 well in js there is no such thing as a class
@jackel27 so everything is just an object
greg
@wearenotgroot
Feb 16 2016 08:41
@jackel27 but in newer version of js the class keyword is introduce
JackeL
@jackel27
Feb 16 2016 08:41
@wearenotgroot okay, I'll keep that mind to get my brain mapped around this right...
@wearenotgroot ahhh.. explains mozilla then..
greg
@wearenotgroot
Feb 16 2016 08:41
@jackel27 to ease the creation of object that reresent class
@jackel27 and for the constructor it just a way to intiante/initialise variables
JackeL
@jackel27
Feb 16 2016 08:42
@wearenotgroot makes sense.. I'll just skip the new class declaration for now...
greg
@wearenotgroot
Feb 16 2016 08:42
@jackel27 :smile:
JackeL
@jackel27
Feb 16 2016 08:43
@wearenotgroot thanks. Trying to finish up codeacademy..
CamperBot
@camperbot
Feb 16 2016 08:43
jackel27 sends brownie points to @wearenotgroot :sparkles: :thumbsup: :sparkles:
:star: 862 | @wearenotgroot | http://www.freecodecamp.com/wearenotgroot
JackeL
@jackel27
Feb 16 2016 08:43
will be back here hopefully soon to finish up the rest. :)
greg
@wearenotgroot
Feb 16 2016 08:43
@jackel27 GL then
JackeL
@jackel27
Feb 16 2016 08:43
@wearenotgroot CodeAcademy is super buggy... I'll need the luck.
kirbyedy
@kirbyedy
Feb 16 2016 08:44
@jackel27 what exactly on codecademy ?
JackeL
@jackel27
Feb 16 2016 08:45
@kirbyedy well, finished html, jquery, about 95% on JS, then need to finish AngularJS, Ruby, Ruby on Rails, Rails Authentication
JackeL
@jackel27
Feb 16 2016 08:56
@kirbyedy buggy between browsers, chrome and IE switching every so often to pass some challenges
DanishKalim
@DanishKalim
Feb 16 2016 08:56
oldArray

var oldArray = [1,2,3,4,5];

// Only change code below this line.
var timesThree = oldArray.map(function(oldArray){
return oldArray + 3;
});
var newArray = oldArray;

You should add three to each value in the array.
plz help
JackeL
@jackel27
Feb 16 2016 09:01
@DanishKalim I do not think you are adding 3 to each array property
Vinícius
@vinicius978
Feb 16 2016 09:03
@DanishKalim I'm stuck on the same problem
JackeL
@jackel27
Feb 16 2016 09:03
@DanishKalim return oldArray + 3 I do not think is correct.
Vinícius
@vinicius978
Feb 16 2016 09:03
What is wrong here?
uriznik
@uriznik
Feb 16 2016 09:04
@DanishKalim map doesn't modify the original array
Vinícius
@vinicius978
Feb 16 2016 09:04
var oldArray = [1,2,3,4,5];

var addThree = oldArray.map(
  function(oldArray)
{

        return oldArray + 3;

});


var newArray = oldArray;
lol nevermind
JackeL
@jackel27
Feb 16 2016 09:05
for each iteration of the array, you return oldArray +3.
try to have a seperate line outside your function/map and output return(oldArray +3); What do you get?
Vinícius
@vinicius978
Feb 16 2016 09:05
the problem was the var newArray = addThree; and not var newArray = oldArray;
JackeL
@jackel27
Feb 16 2016 09:05
hmm
Vinícius
@vinicius978
Feb 16 2016 09:06
because map() doesn't change the original array
JackeL
@jackel27
Feb 16 2016 09:06
right
uriznik
@uriznik
Feb 16 2016 09:06
using oldArray as the function variable name will work but is confusing
Vinícius
@vinicius978
Feb 16 2016 09:06
he only change a new array
thanks anyway guys ;)
Des Dulianto
@desdulianto
Feb 16 2016 09:08
i am kind of confused trying to solve ceaser rot 13
-7 mod 26 suppose to be 17 or -9?
uriznik
@uriznik
Feb 16 2016 09:10
you could add 13 instead of subtract 13 to avoid negative numbers?
DanishKalim
@DanishKalim
Feb 16 2016 09:11
thanks @jackel27 and @vinicius978
CamperBot
@camperbot
Feb 16 2016 09:11
danishkalim sends brownie points to @jackel27 and @vinicius978 :sparkles: :thumbsup: :sparkles:
:star: 315 | @jackel27 | http://www.freecodecamp.com/jackel27
:star: 241 | @vinicius978 | http://www.freecodecamp.com/vinicius978
Des Dulianto
@desdulianto
Feb 16 2016 09:11
my logic is that for each char convert to ascii code then substract 65, so the number would be 0-25, the subtact that with 13 and then modulo 26 to get the alfabet position (A = 0, B = 1 and so on) and then add to 65
JackeL
@jackel27
Feb 16 2016 09:12
@desdulianto
Plain:   ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher:  XYZABCDEFGHIJKLMNOPQRSTUVW
Des Dulianto
@desdulianto
Feb 16 2016 09:12
var c = str.charCodeAt(i);
if (c >= 65 && c <= 90) {
  c = c - 65;
  c = 65 + ((c-13) % 26);
} 
that code run perfectly on python ^^"
i check if c is 69 then 69-65 is 4 then substract 13 is -9
uriznik
@uriznik
Feb 16 2016 09:13
% isn't the same as mod
Des Dulianto
@desdulianto
Feb 16 2016 09:13
oh
uriznik
@uriznik
Feb 16 2016 09:14
so you get different behaviour with negative numbers (can't remember exact algo), but if you keep it positive it should behave as expected
Des Dulianto
@desdulianto
Feb 16 2016 09:15
yup
haha thanks @uriznik
CamperBot
@camperbot
Feb 16 2016 09:15
desdulianto sends brownie points to @uriznik :sparkles: :thumbsup: :sparkles:
:star: 288 | @uriznik | http://www.freecodecamp.com/uriznik
DanishKalim
@DanishKalim
Feb 16 2016 09:17

var array = [4,5,6,7,8];
var singleVal = 0;

// Only change code below this line.
var singleVal = array.reduce(function(previousVal, currentVal){

  return previousVal+currentVal;

});
singleVal = array;

plz bhelp

singleVal should be equal to the sum of all items in the array variable.
Abhishek Kumar
@abhishekKumar1
Feb 16 2016 09:18
remove singleVal=array;
and return singleVal
by the way help format
help format
CamperBot
@camperbot
Feb 16 2016 09:19

:point_right: code formatting [wiki]

Inline code

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

Code Block

```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 ⏎]

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

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

DanishKalim
@DanishKalim
Feb 16 2016 09:19
@abhishekKumar1 thanks
CamperBot
@camperbot
Feb 16 2016 09:19
danishkalim sends brownie points to @abhishekkumar1 :sparkles: :thumbsup: :sparkles:
:star: 334 | @abhishekkumar1 | http://www.freecodecamp.com/abhishekkumar1
Aharon Hyman
@nachamuami
Feb 16 2016 09:20
hi people can somebody please help me with
Testing Objects for Properties
I am not sure how what it is asking me to do
kirbyedy
@kirbyedy
Feb 16 2016 09:24
@nachamuami you should check if the property inside your object exist and return it, otherwise you have to return not found
DanishKalim
@DanishKalim
Feb 16 2016 09:25

var array = [1,2,3,4,5,6,7,8,9,10];
// Only change code below this line.
array = array.filter(function(val) {
return val >= 5;
});

plz help

You should have filtered out all values from the array that are greater than 5.
Robert Uivarosi
@URobert
Feb 16 2016 09:26
@DanishKalim try <= 5 or < 6:)
Yuvraj Adagale
@Yuvraj1989
Feb 16 2016 09:26
@DanishKalim you have written val>=6
Robert Uivarosi
@URobert
Feb 16 2016 09:27
@DanishKalim you filterd out the wrong numbers
Yuvraj Adagale
@Yuvraj1989
Feb 16 2016 09:27
sorry val>=5
it should be val>5
@DanishKalim
DanishKalim
@DanishKalim
Feb 16 2016 09:28

var array = [1,2,3,4,5,6,7,8,9,10];
// Only change code below this line.
array = array.filter(function(val) {
return val >5;
});

not working

Robert Uivarosi
@URobert
Feb 16 2016 09:29
@DanishKalim see my answer from above
DanishKalim
@DanishKalim
Feb 16 2016 09:30

var array = [1,2,3,4,5,6,7,8,9,10];
// Only change code below this line.
array = array.filter(function(val) {
return val <=5;
});

not working @URobert

Marko Nikic
@MarkoN95
Feb 16 2016 09:31
Symmetric Difference
Bonfire: Symetric Difference
CamperBot
@camperbot
Feb 16 2016 09:31
Sorry, can't find a bonfire called symetric difference. [ Check the map? ]
Robert Uivarosi
@URobert
Feb 16 2016 09:31
@DanishKalim wasn't this: var array = [1,2,3,4,5,6,7,8,9,10]; called oldArray ?
Marko Nikic
@MarkoN95
Feb 16 2016 09:31
Bonfire: Symmetric Difference
CamperBot
@camperbot
Feb 16 2016 09:31

:fire:Bonfire: Symmetric Difference :link:

function sym(args) {
  return arguments;
}

sym([1, 2, 3], [5, 2, 1, 4]);

Create a function that takes two or more arrays and returns an array of the symmetric difference of the provided arrays.

more info:  bf details | bf links | hint

Marko Nikic
@MarkoN95
Feb 16 2016 09:32
hint
CamperBot
@camperbot
Feb 16 2016 09:32
:construction: Spoilers are only in the Bonfire's Custom Room :point_right:
Robert Uivarosi
@URobert
Feb 16 2016 09:32
@DanishKalim looks like you've changed some parts of the code that you shouldn't
@DanishKalim link me your code
DanishKalim
@DanishKalim
Feb 16 2016 09:36

var oldArray = [1,2,3,4,5,6,7,8,9,10];

// Only change code below this line.
array = oldarray.filter(function(val) {
return val <= 5;
});
var newArray = oldArray;

Abhishek Kumar
@abhishekKumar1
Feb 16 2016 09:38
@DanishKalim try newarray = oldarray.filter(function(val) {
return val <= 5;
});
and then return newArray not equate it to oldArray
DanishKalim
@DanishKalim
Feb 16 2016 09:40

var oldArray = [1,2,3,4,5,6,7,8,9,10];

// Only change code below this line.
newarray = oldarray.filter(function(val) {
return val <= 5;
});
return newArray ;

not working
Abhishek Kumar
@abhishekKumar1
Feb 16 2016 09:41
your variable are changing names it should be newArray and oldArray in the filter line\
DanishKalim
@DanishKalim
Feb 16 2016 09:43
not working @abhishekKumar1
Codemzy
@codemzy
Feb 16 2016 09:44
@DanishKalim try
var oldArray = [1,2,3,4,5,6,7,8,9,10];

// Only change code below this line.
var newArray = oldArray.filter(function(val) {
  return val <= 5;
});
return newArray ;
lion
@lihe6666
Feb 16 2016 09:44
good
Codemzy
@codemzy
Feb 16 2016 09:47
@DanishKalim your trying to filter out any values over 5 yeah?
DanishKalim
@DanishKalim
Feb 16 2016 09:47
yup
Codemzy
@codemzy
Feb 16 2016 09:48
@DanishKalim yeah the above code I pasted will work
@DanishKalim I just tested it in the console
DanishKalim
@DanishKalim
Feb 16 2016 09:51

var oldArray = [1,2,3,4,5,6,7,8,9,10];

// Only change code below this line.
var newArray = oldArray.filter(function(val) {
return val <= 5;
});
return newArray ;

You should have filtered out all values from the array that are greater than 5.
You should be using the filter method to remove the values from the array.

@codemzy